… | |
… | |
19 | |
19 | |
20 | #include "config.h" |
20 | #include "config.h" |
21 | #include "data.h" |
21 | #include "data.h" |
22 | #include "gen.h" |
22 | #include "gen.h" |
23 | #include <string.h> |
23 | #include <string.h> |
|
|
24 | #include "psiconv.h" |
24 | |
25 | |
25 | #if IMAGEMAGICK |
26 | #if IMAGEMAGICK |
26 | #include <magick/magick.h> |
27 | #include <magick/magick.h> |
27 | #endif |
28 | #endif |
28 | |
29 | |
29 | /* This is ridiculously simple using ImageMagick. Without it, it would |
30 | /* This is ridiculously simple using ImageMagick. Without it, it would |
30 | be somewhat more hard - it will be left for later on */ |
31 | be quite somewhat harder - it will be left for later on */ |
31 | |
32 | |
32 | static void gen_paint_data_section(FILE *of, psiconv_paint_data_section sec) |
33 | static Image *get_paint_data_section(psiconv_paint_data_section sec) |
|
|
34 | { |
|
|
35 | Image *image; |
|
|
36 | image = CreateImage(sec->xsize,sec->ysize,sec->red,sec->green, |
|
|
37 | sec->blue,NULL); |
|
|
38 | return image; |
|
|
39 | } |
|
|
40 | |
|
|
41 | |
|
|
42 | static int psiconv_gen_image_mbm(FILE *of, psiconv_mbm_f f, const char *dest) |
|
|
43 | { |
|
|
44 | #if IMAGEMAGICK |
|
|
45 | psiconv_paint_data_section section; |
|
|
46 | MagickInfo *mi = GetMagickInfo(dest); |
|
|
47 | ImageInfo image_info; |
|
|
48 | Image *image = NULL; |
|
|
49 | Image *last_image = NULL; |
|
|
50 | Image *this_image; |
|
|
51 | int i; |
|
|
52 | |
|
|
53 | if ((psiconv_list_length(f->sections) < 1) || |
|
|
54 | ((psiconv_list_length(f->sections)) > 1 && ! (mi->adjoin))) |
|
|
55 | #endif |
|
|
56 | return -1; |
|
|
57 | #if IMAGEMAGICK |
|
|
58 | for (i = 0; i < psiconv_list_length(f->sections); i++) { |
|
|
59 | section = psiconv_list_get(f->sections,i); |
|
|
60 | this_image = get_paint_data_section(section); |
|
|
61 | if (! image) { |
|
|
62 | image = this_image; |
|
|
63 | last_image = image; |
|
|
64 | } else { |
|
|
65 | last_image->next=this_image; |
|
|
66 | this_image->previous=last_image; |
|
|
67 | this_image->scene=i; |
|
|
68 | last_image=this_image; |
|
|
69 | } |
|
|
70 | } |
|
|
71 | |
|
|
72 | GetImageInfo(&image_info); |
|
|
73 | image_info.file = of; |
|
|
74 | strcpy(image->magick, dest); |
|
|
75 | image_info.adjoin=1; |
|
|
76 | WriteImage(&image_info,image); |
|
|
77 | return 0; |
|
|
78 | #endif |
|
|
79 | } |
|
|
80 | |
|
|
81 | static void psiconv_gen_image_sketch(FILE *of, psiconv_sketch_f f, |
|
|
82 | const char *dest) |
33 | { |
83 | { |
34 | #if IMAGEMAGICK |
84 | #if IMAGEMAGICK |
35 | ImageInfo image_info; |
85 | ImageInfo image_info; |
36 | Image *image; |
86 | Image *image; |
37 | |
87 | |
38 | image = CreateImage(sec->xsize,sec->ysize,sec->red,sec->green, |
88 | image = get_paint_data_section(f->sketch_sec->picture); |
39 | sec->blue,NULL); |
|
|
40 | GetImageInfo(&image_info); |
89 | GetImageInfo(&image_info); |
41 | image_info.file = of; |
90 | image_info.file = of; |
42 | strcpy(image->filename, "bmp:test.bmp"); |
91 | strcpy(image->magick, dest); |
43 | WriteImage(&image_info,image); |
92 | WriteImage(&image_info,image); |
44 | #endif |
93 | #endif |
45 | } |
94 | } |
46 | |
95 | |
47 | static void psiconv_gen_image_mbm(FILE *of, psiconv_mbm_f f) |
96 | static int psiconv_gen_image(FILE * of, const psiconv_file file, |
|
|
97 | const char *dest) |
48 | { |
98 | { |
49 | psiconv_paint_data_section section; |
99 | if (file->type == psiconv_mbm_file) |
50 | if (psiconv_list_length(f->sections) >= 1) { |
100 | return psiconv_gen_image_mbm(of,(psiconv_mbm_f) file->file,dest); |
51 | section = psiconv_list_get(f->sections,0); |
101 | else if (file->type == psiconv_sketch_file) { |
52 | gen_paint_data_section(of,section); |
102 | psiconv_gen_image_sketch(of,(psiconv_sketch_f) file->file,dest); |
53 | } |
103 | return 0; |
|
|
104 | } else |
|
|
105 | return -1; |
54 | } |
106 | } |
55 | |
107 | |
56 | static void psiconv_gen_image_sketch(FILE *of, psiconv_sketch_f f) |
108 | void init_image(void) |
57 | { |
109 | { |
58 | gen_paint_data_section(of,f->sketch_sec->picture); |
110 | struct psiconv_fileformat ff; |
|
|
111 | #if IMAGEMAGICK |
|
|
112 | MagickInfo *mi; |
|
|
113 | ff.output = psiconv_gen_image; |
|
|
114 | for (mi = GetMagickInfo(NULL); mi ; mi = mi->next) { |
|
|
115 | if (mi->encoder) { |
|
|
116 | ff.name = strdup(mi->tag); |
|
|
117 | ff.description = strdup(mi->description); |
|
|
118 | psiconv_list_add(fileformat_list,&ff); |
|
|
119 | } |
|
|
120 | } |
|
|
121 | #endif |
59 | } |
122 | } |
60 | |
123 | |
61 | void psiconv_gen_image(FILE * of, psiconv_file file) |
|
|
62 | { |
|
|
63 | if (file->type == psiconv_mbm_file) |
|
|
64 | psiconv_gen_image_mbm(of,(psiconv_mbm_f) file->file); |
|
|
65 | else if (file->type == psiconv_sketch_file) |
|
|
66 | psiconv_gen_image_sketch(of,(psiconv_sketch_f) file->file); |
|
|
67 | } |
|
|
68 | |
|
|