/[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 44 Revision 56
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>
28#endif 29
30static 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}
29 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.
41 Note that we ignore any errors. Dangerous... */
32 42
33static Image *get_paint_data_section(psiconv_paint_data_section sec) 43static Image *get_paint_data_section(psiconv_paint_data_section sec)
34{ 44{
35 Image *image; 45 Image *image;
36 image = CreateImage(sec->xsize,sec->ysize,sec->red,sec->green, 46 float *pixel, *p, *red, *green, *blue;
37 sec->blue,NULL); 47 int x,y;
48 ExceptionInfo exc;
49
50 GetExceptionInfo(&exc);
51 red = sec->red;
52 green = sec->green;
53 blue = sec->blue;
54 p = pixel = malloc(sec->xsize * sec->ysize * 3 * sizeof(float));
55 for (y = 0; y < sec->ysize; y++) {
56 for (x = 0; x < sec->xsize; x++) {
57 *p++ = *red++;
58 *p++ = *green++;
59 *p++ = *blue++;
60 }
61 }
62 image = ConstituteImage(sec->xsize,sec->ysize,"RGB",FloatPixel,pixel,&exc);
63 if (! image) {
64 MagickError(exc.severity,exc.message,exc.qualifier);
65 }
66 free(pixel);
67
38 return image; 68 return image;
39} 69}
40 70
71#endif
41 72
42static int psiconv_gen_image_clipart(FILE *of, psiconv_clipart_f f, 73static int psiconv_gen_image_clipart(const char *filename, psiconv_clipart_f f,
43 const char *dest) 74 const char *dest)
44{ 75{
45#if IMAGEMAGICK 76#if IMAGEMAGICK
46 psiconv_clipart_section section; 77 psiconv_clipart_section section;
47 MagickInfo *mi = GetMagickInfo(dest); 78 MagickInfo *mi = GetMagickInfo(dest);
48 ImageInfo image_info; 79 ImageInfo *image_info;
49 Image *image = NULL; 80 Image *image = NULL;
50 Image *last_image = NULL; 81 Image *last_image = NULL;
51 Image *this_image; 82 Image *this_image, *images;
83 ExceptionInfo exc;
52 int i; 84 int i;
85 unsigned int status;
53 86
54 if ((psiconv_list_length(f->sections) < 1) || 87 if ((psiconv_list_length(f->sections) < 1) ||
55 ((psiconv_list_length(f->sections)) > 1 && ! (mi->adjoin))) 88 ((psiconv_list_length(f->sections)) > 1 && ! (mi->adjoin)))
56#endif 89#endif
57 return -1; 90 return -1;
59 for (i = 0; i < psiconv_list_length(f->sections); i++) { 92 for (i = 0; i < psiconv_list_length(f->sections); i++) {
60 section = psiconv_list_get(f->sections,i); 93 section = psiconv_list_get(f->sections,i);
61 this_image = get_paint_data_section(section->picture); 94 this_image = get_paint_data_section(section->picture);
62 if (! image) { 95 if (! image) {
63 image = this_image; 96 image = this_image;
64 last_image = image;
65 } else { 97 } else {
66 last_image->next=this_image; 98 last_image->next=this_image;
67 this_image->previous=last_image; 99 this_image->previous=last_image;
68 this_image->scene=i; 100 }
69 last_image=this_image; 101 last_image = this_image;
70 } 102 }
71 }
72 103
104 GetExceptionInfo(&exc);
105 image_info = CloneImageInfo(NULL);
106 set_filename(image->filename,dest,filename);
107 images = CoalesceImages(image,&exc);
108 if (! images)
109 CatchImageException(image);
110
111 status = WriteImage(image_info,images);
112 if (!status)
113 CatchImageException(images);
73 GetImageInfo(&image_info); 114 DestroyImageInfo(image_info);
74 image_info.file = of; 115 DestroyImages(image);
75 strcpy(image->magick, dest); 116 DestroyImages(images);
76 image_info.adjoin=1;
77 WriteImage(&image_info,image);
78 return 0; 117 return 0;
79#endif 118#endif
80} 119}
81 120
82static int psiconv_gen_image_mbm(FILE *of, psiconv_mbm_f f, const char *dest) 121static int psiconv_gen_image_mbm(const char *filename, psiconv_mbm_f f,
122 const char *dest)
83{ 123{
84#if IMAGEMAGICK 124#if IMAGEMAGICK
85 psiconv_paint_data_section section; 125 psiconv_paint_data_section section;
86 MagickInfo *mi = GetMagickInfo(dest); 126 MagickInfo *mi = GetMagickInfo(dest);
87 ImageInfo image_info; 127 ImageInfo *image_info;
88 Image *image = NULL; 128 Image *image = NULL;
89 Image *last_image = NULL; 129 Image *last_image = NULL;
90 Image *this_image; 130 Image *this_image, *images;
131 ExceptionInfo exc;
91 int i; 132 int i;
133 unsigned int status;
92 134
93 if ((psiconv_list_length(f->sections) < 1) || 135 if ((psiconv_list_length(f->sections) < 1) ||
94 ((psiconv_list_length(f->sections)) > 1 && ! (mi->adjoin))) 136 ((psiconv_list_length(f->sections)) > 1 && ! (mi->adjoin)))
95#endif 137#endif
96 return -1; 138 return -1;
98 for (i = 0; i < psiconv_list_length(f->sections); i++) { 140 for (i = 0; i < psiconv_list_length(f->sections); i++) {
99 section = psiconv_list_get(f->sections,i); 141 section = psiconv_list_get(f->sections,i);
100 this_image = get_paint_data_section(section); 142 this_image = get_paint_data_section(section);
101 if (! image) { 143 if (! image) {
102 image = this_image; 144 image = this_image;
103 last_image = image; 145 this_image->scene=1;
104 } else { 146 } else {
105 last_image->next=this_image; 147 last_image->next=this_image;
106 this_image->previous=last_image; 148 this_image->previous=last_image;
107 this_image->scene=i; 149 }
108 last_image=this_image; 150 last_image = this_image;
109 } 151 }
110 }
111 152
153 GetExceptionInfo(&exc);
154 image_info = CloneImageInfo(NULL);
155 set_filename(image->filename,dest,filename);
156 images = CoalesceImages(image,&exc);
157 if (! images)
158 CatchImageException(image);
159
160 status = WriteImage(image_info,images);
161 if (!status)
162 CatchImageException(images);
112 GetImageInfo(&image_info); 163 DestroyImageInfo(image_info);
113 image_info.file = of; 164 DestroyImages(image);
114 strcpy(image->magick, dest); 165 DestroyImages(images);
115 image_info.adjoin=1;
116 WriteImage(&image_info,image);
117 return 0; 166 return 0;
118#endif 167#endif
119} 168}
120 169
121static void psiconv_gen_image_sketch(FILE *of, psiconv_sketch_f f, 170static void psiconv_gen_image_sketch(const char *filename, psiconv_sketch_f f,
122 const char *dest) 171 const char *dest)
123{ 172{
124#if IMAGEMAGICK 173#if IMAGEMAGICK
125 ImageInfo image_info; 174 ImageInfo *image_info;
126 Image *image; 175 Image *image;
127 176
128 image = get_paint_data_section(f->sketch_sec->picture); 177 image = get_paint_data_section(f->sketch_sec->picture);
129 GetImageInfo(&image_info); 178 image_info = CloneImageInfo(NULL);
130 image_info.file = of; 179 set_filename(image->filename,dest,filename);
131 strcpy(image->magick, dest);
132 WriteImage(&image_info,image); 180 WriteImage(image_info,image);
181 DestroyImageInfo(image_info);
182 DestroyImage(image);
133#endif 183#endif
134} 184}
135 185
136static int psiconv_gen_image(FILE * of, const psiconv_file file, 186static int psiconv_gen_image(const char * filename, const psiconv_file file,
137 const char *dest) 187 const char *dest)
138{ 188{
139 if (file->type == psiconv_mbm_file) 189 if (file->type == psiconv_mbm_file)
140 return psiconv_gen_image_mbm(of,(psiconv_mbm_f) file->file,dest); 190 psiconv_gen_image_mbm(filename,(psiconv_mbm_f) file->file,dest);
141 if (file->type == psiconv_clipart_file) 191 if (file->type == psiconv_clipart_file)
142 return psiconv_gen_image_clipart(of,(psiconv_clipart_f) file->file,dest); 192 psiconv_gen_image_clipart(filename,(psiconv_clipart_f) file->file,dest);
143 else if (file->type == psiconv_sketch_file) { 193 else if (file->type == psiconv_sketch_file) {
144 psiconv_gen_image_sketch(of,(psiconv_sketch_f) file->file,dest); 194 psiconv_gen_image_sketch(filename,(psiconv_sketch_f) file->file,dest);
145 return 0;
146 } else 195 } else
147 return -1; 196 return -1;
197 return 0;
148} 198}
149 199
150void init_image(void) 200void init_image(void)
151{ 201{
152 struct psiconv_fileformat ff; 202 struct psiconv_fileformat_s ff;
153#if IMAGEMAGICK 203#if IMAGEMAGICK
154 MagickInfo *mi; 204 MagickInfo *mi;
155 ff.output = psiconv_gen_image; 205 ff.output = psiconv_gen_image;
156 for (mi = GetMagickInfo(NULL); mi ; mi = mi->next) { 206 for (mi = GetMagickFileList(); mi ; mi = mi->next) {
157 if (mi->encoder) { 207 if (mi->encoder) {
158 ff.name = strdup(mi->tag); 208 ff.name = strdup(mi->tag);
159 ff.description = strdup(mi->description); 209 ff.description = strdup(mi->description);
160 psiconv_list_add(fileformat_list,&ff); 210 psiconv_list_add(fileformat_list,&ff);
161 } 211 }

Legend:
Removed from v.44  
changed lines
  Added in v.56

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