/[public]/psiconv/trunk/program/psiconv/gen_image.c
ViewVC logotype

Diff of /psiconv/trunk/program/psiconv/gen_image.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 40 Revision 193
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 "psiconv.h"
23#include <string.h> 24#include <string.h>
24#include "psiconv.h" 25#include <stdlib.h>
25 26
26#if IMAGEMAGICK 27#ifdef IMAGEMAGICK
28#include "magick-aux.h"
27#include <magick/magick.h> 29#include <magick/magick.h>
28#endif 30#endif
29 31
32#ifdef DMALLOC
33#include "dmalloc.h"
34#endif
35
36static Image *get_paint_data_section(psiconv_paint_data_section sec);
37static void image_to_list(psiconv_list list,Image *image,const char *dest);
38static void gen_image_list(const psiconv_config config,psiconv_list list,
39 const psiconv_list sections, const char *dest);
40static void gen_clipart(const psiconv_config config,psiconv_list list,
41 const psiconv_clipart_f f, const char *dest);
42static void gen_mbm(const psiconv_config config,psiconv_list list,
43 const psiconv_mbm_f f, const char *dest);
44static void gen_sketch(const psiconv_config config,psiconv_list list,
45 const psiconv_sketch_f f, const char *dest);
46static int gen_image(psiconv_config config, psiconv_list list,
47 const psiconv_file file, const char *dest,
48 const encoding encoding_type);
49
30/* This is ridiculously simple using ImageMagick. Without it, it would 50/* This is ridiculously simple using ImageMagick. Without it, it would
31 be quite somewhat harder - it will be left for later on */ 51 be quite somewhat harder - it will be left for later on.
52 Note that we ignore any errors. Dangerous... */
32 53
33static Image *get_paint_data_section(psiconv_paint_data_section sec) 54Image *get_paint_data_section(psiconv_paint_data_section sec)
34{ 55{
35 Image *image; 56 Image *image;
36 image = CreateImage(sec->xsize,sec->ysize,sec->red,sec->green, 57 float *pixel, *p, *red, *green, *blue;
37 sec->blue,NULL); 58 int x,y;
59 ExceptionInfo exc;
60
61 GetExceptionInfo(&exc);
62 red = sec->red;
63 green = sec->green;
64 blue = sec->blue;
65 p = pixel = malloc(sec->xsize * sec->ysize * 3 * sizeof(float));
66 for (y = 0; y < sec->ysize; y++) {
67 for (x = 0; x < sec->xsize; x++) {
68 *p++ = *red++;
69 *p++ = *green++;
70 *p++ = *blue++;
71 }
72 }
73
74 image = ConstituteImage(sec->xsize,sec->ysize,"RGB",FloatPixel,pixel,&exc);
75 if (! image || (exc.severity != UndefinedException)) {
76 MagickError(exc.severity,exc.reason,exc.description);
77 exit(1);
78 }
79 free(pixel);
80
81 DestroyExceptionInfo(&exc);
82
38 return image; 83 return image;
39} 84}
40 85
41 86
42static int psiconv_gen_image_mbm(FILE *of, psiconv_mbm_f f, const char *dest) 87void image_to_list(psiconv_list list,Image *image,const char *dest)
43{ 88{
44#if IMAGEMAGICK 89 ImageInfo *image_info;
90 ExceptionInfo exc;
91 size_t length;
92 char *data;
93 int i;
94
95 strcpy(image->magick,dest);
96 image_info = CloneImageInfo(NULL);
97 GetExceptionInfo(&exc);
98 data = ImageToBlob(image_info,image,&length,&exc);
99 if (!data || (exc.severity != UndefinedException)) {
100 MagickError(exc.severity,exc.reason,exc.description);
101 exit(1);
102 }
103 for (i = 0; i < length; i++) {
104 if (psiconv_list_add(list,data+i)) {
105 fprintf(stderr,"Out of memory error");
106 exit(1);
107 }
108 }
109 DestroyExceptionInfo(&exc);
110 DestroyImageInfo(image_info);
111}
112
113void gen_image_list(const psiconv_config config,psiconv_list list,
114 const psiconv_list sections, const char *dest)
115{
45 psiconv_paint_data_section section; 116 psiconv_paint_data_section section;
46 MagickInfo *mi = GetMagickInfo(dest); 117 const MagickInfo *mi;
47 ImageInfo image_info; 118 ImageInfo *image_info;
48 Image *image = NULL; 119 Image *image = NULL;
49 Image *last_image = NULL; 120 Image *last_image = NULL;
50 Image *this_image; 121 Image *this_image, *images;
122 ExceptionInfo exc;
51 int i; 123 int i;
124
125 GetExceptionInfo(&exc);
126 mi = GetMagickInfo(dest,&exc);
127 if (!mi || (exc.severity != UndefinedException)) {
128 MagickError(exc.severity,exc.reason,exc.description);
129 exit(1);
52 130 }
131
53 if ((psiconv_list_length(f->sections) < 1) || 132 if ((psiconv_list_length(sections) < 1) ||
54 ((psiconv_list_length(f->sections)) > 1 && ! (mi->adjoin))) 133 ((psiconv_list_length(sections)) > 1 && ! (mi->adjoin))) {
55#endif 134 fprintf(stderr,"This image type supports only one image\n");
56 return -1; 135 exit(1);
57#if IMAGEMAGICK 136 }
137
58 for (i = 0; i < psiconv_list_length(f->sections); i++) { 138 for (i = 0; i < psiconv_list_length(sections); i++) {
59 section = psiconv_list_get(f->sections,i); 139 if (!(section = psiconv_list_get(sections,i))) {
140 fprintf(stderr,"Internal data structures corrupted\n");
141 exit(1);
142 }
60 this_image = get_paint_data_section(section); 143 this_image = get_paint_data_section(section);
61 if (! image) { 144 if (! image) {
62 image = this_image; 145 image = this_image;
63 last_image = image;
64 } else { 146 } else {
65 last_image->next=this_image; 147 last_image->next=this_image;
66 this_image->previous=last_image; 148 this_image->previous=last_image;
67 this_image->scene=i; 149 }
68 last_image=this_image; 150 last_image = this_image;
69 } 151 }
152
153 image_info = CloneImageInfo(NULL);
154 if (image->next) {
155 images = CoalesceImages(image,&exc);
156 if (!images || (exc.severity != UndefinedException)) {
157 MagickError(exc.severity,exc.reason,exc.description);
158 exit(1);
70 } 159 }
160 } else
161 images = image;
71 162
163 image_to_list(list,image,dest);
164
165 DestroyExceptionInfo(&exc);
72 GetImageInfo(&image_info); 166 DestroyImageInfo(image_info);
73 image_info.file = of; 167 if (image != images)
74 strcpy(image->magick, dest); 168 DestroyImages(image);
75 image_info.adjoin=1; 169 DestroyImages(images);
76 WriteImage(&image_info,image);
77 return 0;
78#endif
79} 170}
80 171
81static void psiconv_gen_image_sketch(FILE *of, psiconv_sketch_f f, 172void gen_clipart(const psiconv_config config,psiconv_list list,
82 const char *dest) 173 const psiconv_clipart_f f, const char *dest)
83{ 174{
84#if IMAGEMAGICK 175 int i;
85 ImageInfo image_info; 176 psiconv_list sections;
177 psiconv_clipart_section section;
178
179 if (!(sections = psiconv_list_new(sizeof(*section->picture)))) {
180 fprintf(stderr,"Out of memory error\n");
181 exit(1);
182 }
183 for (i = 0; i < psiconv_list_length(f->sections); i ++) {
184 if (!(section = psiconv_list_get(f->sections,i))) {
185 fprintf(stderr,"Internal data structures corrupted\n");
186 exit(1);
187 }
188 if ((psiconv_list_add(sections,section->picture))) {
189 fprintf(stderr,"Out of memory error\n");
190 exit(1);
191 }
192 }
193 gen_image_list(config,list,sections,dest);
194 psiconv_list_free(sections);
195}
196
197void gen_mbm(const psiconv_config config,psiconv_list list,
198 const psiconv_mbm_f f, const char *dest)
199{
200 gen_image_list(config,list,f->sections,dest);
201}
202
203
204void gen_sketch(const psiconv_config config,psiconv_list list,
205 const psiconv_sketch_f f, const char *dest)
206{
86 Image *image; 207 Image *image;
87 208
88 image = get_paint_data_section(f->sketch_sec->picture); 209 image = get_paint_data_section(f->sketch_sec->picture);
89 GetImageInfo(&image_info); 210 image_to_list(list,image,dest);
90 image_info.file = of; 211 DestroyImage(image);
91 strcpy(image->magick, dest);
92 WriteImage(&image_info,image);
93#endif
94} 212}
95 213
96static int psiconv_gen_image(FILE * of, const psiconv_file file, 214
97 const char *dest) 215int gen_image(psiconv_config config, psiconv_list list,
216 const psiconv_file file, const char *dest,
217 const encoding encoding_type)
98{ 218{
99 if (file->type == psiconv_mbm_file) 219 if (file->type == psiconv_mbm_file)
100 return psiconv_gen_image_mbm(of,(psiconv_mbm_f) file->file,dest); 220 gen_mbm(config,list,(psiconv_mbm_f) file->file,dest);
221 else if (file->type == psiconv_clipart_file)
222 gen_clipart(config,list,
223 (psiconv_clipart_f) file->file,dest);
224 else
101 else if (file->type == psiconv_sketch_file) { 225 if (file->type == psiconv_sketch_file) {
102 psiconv_gen_image_sketch(of,(psiconv_sketch_f) file->file,dest); 226 gen_sketch(config, list,(psiconv_sketch_f) file->file,dest);
103 return 0;
104 } else 227 } else
105 return -1; 228 return -1;
229 return 0;
106} 230}
107 231
108void init_image(void) 232void init_image(void)
109{ 233{
110 struct psiconv_fileformat ff; 234 struct fileformat_s ff;
111#if IMAGEMAGICK 235#if IMAGEMAGICK
112 MagickInfo *mi; 236 const MagickInfo *mi;
113 ff.output = psiconv_gen_image; 237 ff.output = gen_image;
114 for (mi = GetMagickInfo(NULL); mi ; mi = mi->next) { 238 for (mi = GetMagickFileList(); mi ; mi = mi->next) {
115 if (mi->encoder) { 239 if (mi->encoder) {
116 ff.name = strdup(mi->tag); 240 ff.name = strdup(mi->name);
117 ff.description = strdup(mi->description); 241 ff.description = strdup(mi->description);
242 ff.supported_format = FORMAT_CLIPART_SINGLE | FORMAT_MBM_SINGLE |
243 FORMAT_SKETCH;
244 if (mi->adjoin)
245 ff.supported_format |= FORMAT_MBM_MULTIPLE | FORMAT_CLIPART_MULTIPLE;
118 psiconv_list_add(fileformat_list,&ff); 246 psiconv_list_add(fileformat_list,&ff);
119 } 247 }
120 } 248 }
121#endif 249#endif
122} 250}

Legend:
Removed from v.40  
changed lines
  Added in v.193

frodo@frodo.looijaard.name
ViewVC Help
Powered by ViewVC 1.1.26