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