… | |
… | |
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/magick.h> |
27 | #include <magick/magick.h> |
28 | #endif |
|
|
29 | |
28 | |
30 | /* This is ridiculously simple using ImageMagick. Without it, it would |
29 | /* This is ridiculously simple using ImageMagick. Without it, it would |
31 | be quite somewhat harder - it will be left for later on */ |
30 | be quite somewhat harder - it will be left for later on. |
|
|
31 | Note that we ignore any errors. Dangerous... */ |
32 | |
32 | |
33 | static Image *get_paint_data_section(psiconv_paint_data_section sec) |
33 | static Image *get_paint_data_section(psiconv_paint_data_section sec) |
34 | { |
34 | { |
35 | Image *image; |
35 | Image *image; |
36 | image = CreateImage(sec->xsize,sec->ysize,sec->red,sec->green, |
36 | float *pixel, *p, *red, *green, *blue; |
37 | sec->blue,NULL); |
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 | |
38 | return image; |
56 | return image; |
39 | } |
57 | } |
40 | |
58 | |
|
|
59 | #endif |
|
|
60 | |
|
|
61 | static int psiconv_gen_image_clipart(FILE *of, psiconv_clipart_f f, |
|
|
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 | } |
|
|
91 | |
|
|
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 | } |
41 | |
100 | |
42 | static int psiconv_gen_image_mbm(FILE *of, psiconv_mbm_f f, const char *dest) |
101 | static int psiconv_gen_image_mbm(FILE *of, psiconv_mbm_f f, const char *dest) |
43 | { |
102 | { |
44 | #if IMAGEMAGICK |
103 | #if IMAGEMAGICK |
45 | psiconv_paint_data_section section; |
104 | psiconv_paint_data_section section; |
… | |
… | |
54 | ((psiconv_list_length(f->sections)) > 1 && ! (mi->adjoin))) |
113 | ((psiconv_list_length(f->sections)) > 1 && ! (mi->adjoin))) |
55 | #endif |
114 | #endif |
56 | return -1; |
115 | return -1; |
57 | #if IMAGEMAGICK |
116 | #if IMAGEMAGICK |
58 | for (i = 0; i < psiconv_list_length(f->sections); i++) { |
117 | for (i = 0; i < psiconv_list_length(f->sections); i++) { |
59 | section = psiconv_list_get(f->sections,0); |
118 | section = psiconv_list_get(f->sections,i); |
60 | this_image = get_paint_data_section(section); |
119 | this_image = get_paint_data_section(section); |
61 | if (! image) { |
120 | if (! image) { |
62 | image = image; |
121 | image = this_image; |
63 | last_image = image; |
122 | last_image = image; |
64 | } else { |
123 | } else { |
65 | last_image->next=this_image; |
124 | last_image->next=this_image; |
66 | this_image->previous=last_image; |
125 | this_image->previous=last_image; |
|
|
126 | this_image->scene=i; |
|
|
127 | last_image=this_image; |
67 | } |
128 | } |
68 | } |
129 | } |
69 | |
130 | |
70 | GetImageInfo(&image_info); |
131 | GetImageInfo(&image_info); |
71 | image_info.file = of; |
132 | image_info.file = of; |
72 | strcpy(image->magick, dest); |
133 | strcpy(image->magick, dest); |
|
|
134 | image_info.adjoin=1; |
73 | WriteImage(&image_info,image); |
135 | WriteImage(&image_info,image); |
74 | return 0; |
136 | return 0; |
75 | #endif |
137 | #endif |
76 | } |
138 | } |
77 | |
139 | |
… | |
… | |
93 | static int psiconv_gen_image(FILE * of, const psiconv_file file, |
155 | static int psiconv_gen_image(FILE * of, const psiconv_file file, |
94 | const char *dest) |
156 | const char *dest) |
95 | { |
157 | { |
96 | if (file->type == psiconv_mbm_file) |
158 | if (file->type == psiconv_mbm_file) |
97 | return psiconv_gen_image_mbm(of,(psiconv_mbm_f) file->file,dest); |
159 | return psiconv_gen_image_mbm(of,(psiconv_mbm_f) file->file,dest); |
|
|
160 | if (file->type == psiconv_clipart_file) |
|
|
161 | return psiconv_gen_image_clipart(of,(psiconv_clipart_f) file->file,dest); |
98 | else if (file->type == psiconv_sketch_file) { |
162 | else if (file->type == psiconv_sketch_file) { |
99 | psiconv_gen_image_sketch(of,(psiconv_sketch_f) file->file,dest); |
163 | psiconv_gen_image_sketch(of,(psiconv_sketch_f) file->file,dest); |
100 | return 0; |
164 | return 0; |
101 | } else |
165 | } else |
102 | return -1; |
166 | return -1; |