… | |
… | |
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-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 | } |
|
|
62 | |
53 | 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.message,exc.qualifier); |
|
|
66 | } |
54 | free(pixel); |
67 | free(pixel); |
55 | DestroyExceptionInfo(exc); |
|
|
56 | |
68 | |
57 | return image; |
69 | return image; |
58 | } |
70 | } |
59 | |
71 | |
60 | #endif |
72 | #endif |
61 | |
73 | |
62 | 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, |
63 | const char *dest) |
75 | const char *dest) |
64 | { |
76 | { |
65 | #if IMAGEMAGICK |
77 | #if IMAGEMAGICK |
66 | psiconv_clipart_section section; |
78 | psiconv_clipart_section section; |
67 | MagickInfo *mi = GetMagickInfo(dest); |
79 | MagickInfo *mi = GetMagickInfo(dest); |
68 | ImageInfo image_info; |
80 | ImageInfo *image_info; |
69 | Image *image = NULL; |
81 | Image *image = NULL; |
70 | Image *last_image = NULL; |
82 | Image *last_image = NULL; |
71 | Image *this_image; |
83 | Image *this_image, *images; |
|
|
84 | ExceptionInfo exc; |
72 | int i; |
85 | int i; |
|
|
86 | unsigned int status; |
73 | |
87 | |
74 | if ((psiconv_list_length(f->sections) < 1) || |
88 | if ((psiconv_list_length(f->sections) < 1) || |
75 | ((psiconv_list_length(f->sections)) > 1 && ! (mi->adjoin))) |
89 | ((psiconv_list_length(f->sections)) > 1 && ! (mi->adjoin))) |
76 | #endif |
90 | #endif |
77 | return -1; |
91 | return -1; |
… | |
… | |
79 | for (i = 0; i < psiconv_list_length(f->sections); i++) { |
93 | for (i = 0; i < psiconv_list_length(f->sections); i++) { |
80 | section = psiconv_list_get(f->sections,i); |
94 | section = psiconv_list_get(f->sections,i); |
81 | this_image = get_paint_data_section(section->picture); |
95 | this_image = get_paint_data_section(section->picture); |
82 | if (! image) { |
96 | if (! image) { |
83 | image = this_image; |
97 | image = this_image; |
84 | last_image = image; |
|
|
85 | } else { |
98 | } else { |
86 | last_image->next=this_image; |
99 | last_image->next=this_image; |
87 | this_image->previous=last_image; |
100 | this_image->previous=last_image; |
88 | this_image->scene=i; |
101 | } |
89 | last_image=this_image; |
102 | last_image = this_image; |
90 | } |
103 | } |
91 | } |
|
|
92 | |
104 | |
|
|
105 | GetExceptionInfo(&exc); |
|
|
106 | image_info = CloneImageInfo(NULL); |
|
|
107 | set_filename(image->filename,dest,filename); |
|
|
108 | if (image->next) |
|
|
109 | images = CoalesceImages(image,&exc); |
|
|
110 | else |
|
|
111 | images = image; |
|
|
112 | if (! images) |
|
|
113 | CatchImageException(image); |
|
|
114 | |
|
|
115 | status = WriteImage(image_info,images); |
|
|
116 | if (!status) |
|
|
117 | CatchImageException(images); |
93 | GetImageInfo(&image_info); |
118 | DestroyImageInfo(image_info); |
94 | image_info.file = of; |
119 | if (image != images) |
95 | strcpy(image->magick, dest); |
120 | DestroyImages(image); |
96 | image_info.adjoin=1; |
121 | DestroyImages(images); |
97 | WriteImage(&image_info,image); |
|
|
98 | return 0; |
122 | return 0; |
99 | #endif |
123 | #endif |
100 | } |
124 | } |
101 | |
125 | |
102 | static int psiconv_gen_image_mbm(FILE *of, psiconv_mbm_f f, const char *dest) |
126 | static int psiconv_gen_image_mbm(const char *filename, psiconv_mbm_f f, |
|
|
127 | const char *dest) |
103 | { |
128 | { |
|
|
129 | |
104 | #if IMAGEMAGICK |
130 | #if IMAGEMAGICK |
105 | psiconv_paint_data_section section; |
131 | psiconv_paint_data_section section; |
106 | MagickInfo *mi = GetMagickInfo(dest); |
132 | MagickInfo *mi = GetMagickInfo(dest); |
107 | ImageInfo image_info; |
133 | ImageInfo *image_info; |
108 | Image *image = NULL; |
134 | Image *image = NULL; |
109 | Image *last_image = NULL; |
135 | Image *last_image = NULL; |
110 | Image *this_image; |
136 | Image *this_image, *images; |
|
|
137 | ExceptionInfo exc; |
111 | int i; |
138 | int i; |
112 | |
139 | unsigned int status; |
|
|
140 | |
113 | if ((psiconv_list_length(f->sections) < 1) || |
141 | if ((psiconv_list_length(f->sections) < 1) || |
114 | ((psiconv_list_length(f->sections)) > 1 && ! (mi->adjoin))) |
142 | ((psiconv_list_length(f->sections)) > 1 && ! (mi->adjoin))) |
115 | #endif |
143 | #endif |
116 | return -1; |
144 | return -1; |
117 | #if IMAGEMAGICK |
145 | #if IMAGEMAGICK |
|
|
146 | |
118 | for (i = 0; i < psiconv_list_length(f->sections); i++) { |
147 | for (i = 0; i < psiconv_list_length(f->sections); i++) { |
119 | section = psiconv_list_get(f->sections,i); |
148 | section = psiconv_list_get(f->sections,i); |
120 | this_image = get_paint_data_section(section); |
149 | this_image = get_paint_data_section(section); |
121 | if (! image) { |
150 | if (! image) { |
122 | image = this_image; |
151 | image = this_image; |
123 | last_image = image; |
|
|
124 | } else { |
152 | } else { |
125 | last_image->next=this_image; |
153 | last_image->next=this_image; |
126 | this_image->previous=last_image; |
154 | this_image->previous=last_image; |
127 | this_image->scene=i; |
155 | } |
128 | last_image=this_image; |
156 | last_image = this_image; |
129 | } |
157 | } |
130 | } |
|
|
131 | |
158 | |
|
|
159 | GetExceptionInfo(&exc); |
|
|
160 | image_info = CloneImageInfo(NULL); |
|
|
161 | set_filename(image->filename,dest,filename); |
|
|
162 | if (image->next) |
|
|
163 | images = CoalesceImages(image,&exc); |
|
|
164 | else |
|
|
165 | images = image; |
|
|
166 | if (! images) |
|
|
167 | CatchImageException(image); |
|
|
168 | |
|
|
169 | status = WriteImage(image_info,images); |
|
|
170 | if (!status) |
|
|
171 | CatchImageException(images); |
132 | GetImageInfo(&image_info); |
172 | DestroyImageInfo(image_info); |
133 | image_info.file = of; |
173 | if (image != images) |
134 | strcpy(image->magick, dest); |
174 | DestroyImages(image); |
135 | image_info.adjoin=1; |
175 | DestroyImages(images); |
136 | WriteImage(&image_info,image); |
|
|
137 | return 0; |
176 | return 0; |
138 | #endif |
177 | #endif |
139 | } |
178 | } |
140 | |
179 | |
141 | static void psiconv_gen_image_sketch(FILE *of, psiconv_sketch_f f, |
180 | static void psiconv_gen_image_sketch(const char *filename, psiconv_sketch_f f, |
142 | const char *dest) |
181 | const char *dest) |
143 | { |
182 | { |
144 | #if IMAGEMAGICK |
183 | #if IMAGEMAGICK |
145 | ImageInfo image_info; |
184 | ImageInfo *image_info; |
146 | Image *image; |
185 | Image *image; |
147 | |
186 | |
148 | image = get_paint_data_section(f->sketch_sec->picture); |
187 | image = get_paint_data_section(f->sketch_sec->picture); |
149 | GetImageInfo(&image_info); |
188 | image_info = CloneImageInfo(NULL); |
150 | image_info.file = of; |
189 | set_filename(image->filename,dest,filename); |
151 | strcpy(image->magick, dest); |
|
|
152 | WriteImage(&image_info,image); |
190 | WriteImage(image_info,image); |
|
|
191 | DestroyImageInfo(image_info); |
|
|
192 | DestroyImage(image); |
153 | #endif |
193 | #endif |
154 | } |
194 | } |
155 | |
195 | |
156 | static int psiconv_gen_image(FILE * of, const psiconv_file file, |
196 | static int psiconv_gen_image(const char * filename, const psiconv_file file, |
157 | const char *dest) |
197 | const char *dest) |
158 | { |
198 | { |
159 | if (file->type == psiconv_mbm_file) |
199 | if (file->type == psiconv_mbm_file) |
160 | return psiconv_gen_image_mbm(of,(psiconv_mbm_f) file->file,dest); |
200 | psiconv_gen_image_mbm(filename,(psiconv_mbm_f) file->file,dest); |
161 | if (file->type == psiconv_clipart_file) |
201 | else if (file->type == psiconv_clipart_file) |
162 | return psiconv_gen_image_clipart(of,(psiconv_clipart_f) file->file,dest); |
202 | psiconv_gen_image_clipart(filename,(psiconv_clipart_f) file->file,dest); |
163 | else if (file->type == psiconv_sketch_file) { |
203 | else if (file->type == psiconv_sketch_file) { |
164 | psiconv_gen_image_sketch(of,(psiconv_sketch_f) file->file,dest); |
204 | psiconv_gen_image_sketch(filename,(psiconv_sketch_f) file->file,dest); |
165 | return 0; |
|
|
166 | } else |
205 | } else |
167 | return -1; |
206 | return -1; |
|
|
207 | return 0; |
168 | } |
208 | } |
169 | |
209 | |
170 | void init_image(void) |
210 | void init_image(void) |
171 | { |
211 | { |
172 | struct psiconv_fileformat ff; |
212 | struct psiconv_fileformat_s ff; |
173 | #if IMAGEMAGICK |
213 | #if IMAGEMAGICK |
174 | MagickInfo *mi; |
214 | MagickInfo *mi; |
175 | ff.output = psiconv_gen_image; |
215 | ff.output = psiconv_gen_image; |
176 | for (mi = GetMagickFileList(); mi ; mi = mi->next) { |
216 | for (mi = GetMagickFileList(); mi ; mi = mi->next) { |
177 | if (mi->encoder) { |
217 | if (mi->encoder) { |