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