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