… | |
… | |
25 | |
25 | |
26 | #if IMAGEMAGICK |
26 | #if IMAGEMAGICK |
27 | #include "magick-aux.h" |
27 | #include "magick-aux.h" |
28 | #include <magick/magick.h> |
28 | #include <magick/magick.h> |
29 | |
29 | |
|
|
30 | static void set_filename(char *dest,const char *type, const char *name) |
|
|
31 | { |
|
|
32 | int len; |
|
|
33 | strcpy(dest,type); |
|
|
34 | len = strlen(dest); |
|
|
35 | dest[len] = ':'; |
|
|
36 | strcpy(dest + len + 1,name); |
|
|
37 | } |
|
|
38 | |
30 | /* This is ridiculously simple using ImageMagick. Without it, it would |
39 | /* This is ridiculously simple using ImageMagick. Without it, it would |
31 | be quite somewhat harder - it will be left for later on. |
40 | be quite somewhat harder - it will be left for later on. |
32 | Note that we ignore any errors. Dangerous... */ |
41 | Note that we ignore any errors. Dangerous... */ |
33 | |
42 | |
34 | static Image *get_paint_data_section(psiconv_paint_data_section sec) |
43 | static Image *get_paint_data_section(psiconv_paint_data_section sec) |
35 | { |
44 | { |
36 | Image *image; |
45 | Image *image; |
37 | float *pixel, *p, *red, *green, *blue; |
46 | float *pixel, *p, *red, *green, *blue; |
38 | int x,y; |
47 | int x,y; |
39 | ExceptionInfo *exc; |
48 | ExceptionInfo exc; |
40 | |
49 | |
41 | GetExceptionInfo(exc); |
50 | GetExceptionInfo(&exc); |
42 | red = sec->red; |
51 | red = sec->red; |
43 | green = sec->green; |
52 | green = sec->green; |
44 | blue = sec->blue; |
53 | blue = sec->blue; |
45 | p = pixel = malloc(sec->xsize * sec->ysize * 3 * sizeof(float)); |
54 | p = pixel = malloc(sec->xsize * sec->ysize * 3 * sizeof(float)); |
46 | for (y = 0; y < sec->ysize; y++) { |
55 | for (y = 0; y < sec->ysize; y++) { |
… | |
… | |
48 | *p++ = *red++; |
57 | *p++ = *red++; |
49 | *p++ = *green++; |
58 | *p++ = *green++; |
50 | *p++ = *blue++; |
59 | *p++ = *blue++; |
51 | } |
60 | } |
52 | } |
61 | } |
53 | image = ConstituteImage(sec->xsize,sec->ysize,"RGB",FloatPixel,pixel,exc); |
62 | image = ConstituteImage(sec->xsize,sec->ysize,"RGB",FloatPixel,pixel,&exc); |
|
|
63 | if (! image) { |
|
|
64 | MagickError(exc.severity,exc.message,exc.qualifier); |
|
|
65 | } |
54 | free(pixel); |
66 | free(pixel); |
55 | DestroyExceptionInfo(exc); |
|
|
56 | |
67 | |
57 | return image; |
68 | return image; |
58 | } |
69 | } |
59 | |
70 | |
60 | #endif |
71 | #endif |
61 | |
72 | |
62 | static int psiconv_gen_image_clipart(FILE *of, psiconv_clipart_f f, |
73 | static int psiconv_gen_image_clipart(const char *filename, psiconv_clipart_f f, |
63 | const char *dest) |
74 | const char *dest) |
64 | { |
75 | { |
65 | #if IMAGEMAGICK |
76 | #if IMAGEMAGICK |
66 | psiconv_clipart_section section; |
77 | psiconv_clipart_section section; |
67 | MagickInfo *mi = GetMagickInfo(dest); |
78 | MagickInfo *mi = GetMagickInfo(dest); |
68 | ImageInfo image_info; |
79 | ImageInfo *image_info; |
69 | Image *image = NULL; |
80 | Image *image = NULL; |
70 | Image *last_image = NULL; |
81 | Image *last_image = NULL; |
71 | Image *this_image; |
82 | Image *this_image, *images; |
|
|
83 | ExceptionInfo exc; |
72 | int i; |
84 | int i; |
|
|
85 | unsigned int status; |
73 | |
86 | |
74 | if ((psiconv_list_length(f->sections) < 1) || |
87 | if ((psiconv_list_length(f->sections) < 1) || |
75 | ((psiconv_list_length(f->sections)) > 1 && ! (mi->adjoin))) |
88 | ((psiconv_list_length(f->sections)) > 1 && ! (mi->adjoin))) |
76 | #endif |
89 | #endif |
77 | return -1; |
90 | return -1; |
… | |
… | |
79 | for (i = 0; i < psiconv_list_length(f->sections); i++) { |
92 | for (i = 0; i < psiconv_list_length(f->sections); i++) { |
80 | section = psiconv_list_get(f->sections,i); |
93 | section = psiconv_list_get(f->sections,i); |
81 | this_image = get_paint_data_section(section->picture); |
94 | this_image = get_paint_data_section(section->picture); |
82 | if (! image) { |
95 | if (! image) { |
83 | image = this_image; |
96 | image = this_image; |
84 | last_image = image; |
|
|
85 | } else { |
97 | } else { |
86 | last_image->next=this_image; |
98 | last_image->next=this_image; |
87 | this_image->previous=last_image; |
99 | this_image->previous=last_image; |
88 | this_image->scene=i; |
100 | } |
89 | last_image=this_image; |
101 | last_image = this_image; |
90 | } |
102 | } |
91 | } |
|
|
92 | |
103 | |
|
|
104 | GetExceptionInfo(&exc); |
|
|
105 | image_info = CloneImageInfo(NULL); |
|
|
106 | set_filename(image->filename,dest,filename); |
|
|
107 | images = CoalesceImages(image,&exc); |
|
|
108 | if (! images) |
|
|
109 | CatchImageException(image); |
|
|
110 | |
|
|
111 | status = WriteImage(image_info,images); |
|
|
112 | if (!status) |
|
|
113 | CatchImageException(images); |
93 | GetImageInfo(&image_info); |
114 | DestroyImageInfo(image_info); |
94 | image_info.file = of; |
115 | DestroyImages(image); |
95 | strcpy(image->magick, dest); |
116 | DestroyImages(images); |
96 | image_info.adjoin=1; |
|
|
97 | WriteImage(&image_info,image); |
|
|
98 | return 0; |
117 | return 0; |
99 | #endif |
118 | #endif |
100 | } |
119 | } |
101 | |
120 | |
102 | static int psiconv_gen_image_mbm(FILE *of, psiconv_mbm_f f, const char *dest) |
121 | static int psiconv_gen_image_mbm(const char *filename, psiconv_mbm_f f, |
|
|
122 | const char *dest) |
103 | { |
123 | { |
104 | #if IMAGEMAGICK |
124 | #if IMAGEMAGICK |
105 | psiconv_paint_data_section section; |
125 | psiconv_paint_data_section section; |
106 | MagickInfo *mi = GetMagickInfo(dest); |
126 | MagickInfo *mi = GetMagickInfo(dest); |
107 | ImageInfo image_info; |
127 | ImageInfo *image_info; |
108 | Image *image = NULL; |
128 | Image *image = NULL; |
109 | Image *last_image = NULL; |
129 | Image *last_image = NULL; |
110 | Image *this_image; |
130 | Image *this_image, *images; |
|
|
131 | ExceptionInfo exc; |
111 | int i; |
132 | int i; |
|
|
133 | unsigned int status; |
112 | |
134 | |
113 | if ((psiconv_list_length(f->sections) < 1) || |
135 | if ((psiconv_list_length(f->sections) < 1) || |
114 | ((psiconv_list_length(f->sections)) > 1 && ! (mi->adjoin))) |
136 | ((psiconv_list_length(f->sections)) > 1 && ! (mi->adjoin))) |
115 | #endif |
137 | #endif |
116 | return -1; |
138 | return -1; |
… | |
… | |
118 | for (i = 0; i < psiconv_list_length(f->sections); i++) { |
140 | for (i = 0; i < psiconv_list_length(f->sections); i++) { |
119 | section = psiconv_list_get(f->sections,i); |
141 | section = psiconv_list_get(f->sections,i); |
120 | this_image = get_paint_data_section(section); |
142 | this_image = get_paint_data_section(section); |
121 | if (! image) { |
143 | if (! image) { |
122 | image = this_image; |
144 | image = this_image; |
123 | last_image = image; |
145 | this_image->scene=1; |
124 | } else { |
146 | } else { |
125 | last_image->next=this_image; |
147 | last_image->next=this_image; |
126 | this_image->previous=last_image; |
148 | this_image->previous=last_image; |
127 | this_image->scene=i; |
149 | } |
128 | last_image=this_image; |
150 | last_image = this_image; |
129 | } |
151 | } |
130 | } |
|
|
131 | |
152 | |
|
|
153 | GetExceptionInfo(&exc); |
|
|
154 | image_info = CloneImageInfo(NULL); |
|
|
155 | set_filename(image->filename,dest,filename); |
|
|
156 | images = CoalesceImages(image,&exc); |
|
|
157 | if (! images) |
|
|
158 | CatchImageException(image); |
|
|
159 | |
|
|
160 | status = WriteImage(image_info,images); |
|
|
161 | if (!status) |
|
|
162 | CatchImageException(images); |
132 | GetImageInfo(&image_info); |
163 | DestroyImageInfo(image_info); |
133 | image_info.file = of; |
164 | DestroyImages(image); |
134 | strcpy(image->magick, dest); |
165 | DestroyImages(images); |
135 | image_info.adjoin=1; |
|
|
136 | WriteImage(&image_info,image); |
|
|
137 | return 0; |
166 | return 0; |
138 | #endif |
167 | #endif |
139 | } |
168 | } |
140 | |
169 | |
141 | static void psiconv_gen_image_sketch(FILE *of, psiconv_sketch_f f, |
170 | static void psiconv_gen_image_sketch(const char *filename, psiconv_sketch_f f, |
142 | const char *dest) |
171 | const char *dest) |
143 | { |
172 | { |
144 | #if IMAGEMAGICK |
173 | #if IMAGEMAGICK |
145 | ImageInfo image_info; |
174 | ImageInfo *image_info; |
146 | Image *image; |
175 | Image *image; |
147 | |
176 | |
148 | image = get_paint_data_section(f->sketch_sec->picture); |
177 | image = get_paint_data_section(f->sketch_sec->picture); |
149 | GetImageInfo(&image_info); |
178 | image_info = CloneImageInfo(NULL); |
150 | image_info.file = of; |
179 | set_filename(image->filename,dest,filename); |
151 | strcpy(image->magick, dest); |
|
|
152 | WriteImage(&image_info,image); |
180 | WriteImage(image_info,image); |
|
|
181 | DestroyImageInfo(image_info); |
|
|
182 | DestroyImage(image); |
153 | #endif |
183 | #endif |
154 | } |
184 | } |
155 | |
185 | |
156 | static int psiconv_gen_image(FILE * of, const psiconv_file file, |
186 | static int psiconv_gen_image(const char * filename, const psiconv_file file, |
157 | const char *dest) |
187 | const char *dest) |
158 | { |
188 | { |
159 | if (file->type == psiconv_mbm_file) |
189 | if (file->type == psiconv_mbm_file) |
160 | return psiconv_gen_image_mbm(of,(psiconv_mbm_f) file->file,dest); |
190 | psiconv_gen_image_mbm(filename,(psiconv_mbm_f) file->file,dest); |
161 | if (file->type == psiconv_clipart_file) |
191 | if (file->type == psiconv_clipart_file) |
162 | return psiconv_gen_image_clipart(of,(psiconv_clipart_f) file->file,dest); |
192 | psiconv_gen_image_clipart(filename,(psiconv_clipart_f) file->file,dest); |
163 | else if (file->type == psiconv_sketch_file) { |
193 | else if (file->type == psiconv_sketch_file) { |
164 | psiconv_gen_image_sketch(of,(psiconv_sketch_f) file->file,dest); |
194 | psiconv_gen_image_sketch(filename,(psiconv_sketch_f) file->file,dest); |
165 | return 0; |
|
|
166 | } else |
195 | } else |
167 | return -1; |
196 | return -1; |
|
|
197 | return 0; |
168 | } |
198 | } |
169 | |
199 | |
170 | void init_image(void) |
200 | void init_image(void) |
171 | { |
201 | { |
172 | struct psiconv_fileformat ff; |
202 | struct psiconv_fileformat ff; |