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

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

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