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

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

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