/[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 147
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 <string.h> 23#include <string.h>
24#include "psiconv.h" 24#include "psiconv.h"
25 25
26#if IMAGEMAGICK 26#ifdef IMAGEMAGICK
27#include "magick-aux.h" 27#include "magick-aux.h"
28#include <magick/magick.h> 28#include <magick/magick.h>
29
30#ifdef DMALLOC
31#include "dmalloc.h"
32#endif
29 33
30static void set_filename(char *dest,const char *type, const char *name) 34static void set_filename(char *dest,const char *type, const char *name)
31{ 35{
32 int len; 36 int len;
33 strcpy(dest,type); 37 strcpy(dest,type);
57 *p++ = *red++; 61 *p++ = *red++;
58 *p++ = *green++; 62 *p++ = *green++;
59 *p++ = *blue++; 63 *p++ = *blue++;
60 } 64 }
61 } 65 }
66
62 image = ConstituteImage(sec->xsize,sec->ysize,"RGB",FloatPixel,pixel,&exc); 67 image = ConstituteImage(sec->xsize,sec->ysize,"RGB",FloatPixel,pixel,&exc);
63 if (! image) { 68 if (! image) {
64 MagickError(exc.severity,exc.message,exc.qualifier); 69 MagickError(exc.severity,exc.reason,exc.description);
65 } 70 }
66 free(pixel); 71 free(pixel);
67 72
68 return image; 73 return image;
69} 74}
73static int psiconv_gen_image_clipart(const char *filename, psiconv_clipart_f f, 78static int psiconv_gen_image_clipart(const char *filename, psiconv_clipart_f f,
74 const char *dest) 79 const char *dest)
75{ 80{
76#if IMAGEMAGICK 81#if IMAGEMAGICK
77 psiconv_clipart_section section; 82 psiconv_clipart_section section;
78 MagickInfo *mi = GetMagickInfo(dest); 83 const MagickInfo *mi;
79 ImageInfo *image_info; 84 ImageInfo *image_info;
80 Image *image = NULL; 85 Image *image = NULL;
81 Image *last_image = NULL; 86 Image *last_image = NULL;
82 Image *this_image, *images; 87 Image *this_image, *images;
83 ExceptionInfo exc; 88 ExceptionInfo exc;
84 int i; 89 int i;
85 unsigned int status; 90 unsigned int status;
91
92 GetExceptionInfo(&exc);
93 if (!(mi = GetMagickInfo(dest,&exc)))
94 return -1;
86 95
87 if ((psiconv_list_length(f->sections) < 1) || 96 if ((psiconv_list_length(f->sections) < 1) ||
88 ((psiconv_list_length(f->sections)) > 1 && ! (mi->adjoin))) 97 ((psiconv_list_length(f->sections)) > 1 && ! (mi->adjoin)))
89#endif 98#endif
90 return -1; 99 return -1;
99 this_image->previous=last_image; 108 this_image->previous=last_image;
100 } 109 }
101 last_image = this_image; 110 last_image = this_image;
102 } 111 }
103 112
104 GetExceptionInfo(&exc);
105 image_info = CloneImageInfo(NULL); 113 image_info = CloneImageInfo(NULL);
106 set_filename(image->filename,dest,filename); 114 set_filename(image->filename,dest,filename);
115 if (image->next)
107 images = CoalesceImages(image,&exc); 116 images = CoalesceImages(image,&exc);
117 else
118 images = image;
108 if (! images) 119 if (! images)
109 CatchImageException(image); 120 CatchImageException(image);
110 121
111 status = WriteImage(image_info,images); 122 status = WriteImage(image_info,images);
112 if (!status) 123 if (!status)
113 CatchImageException(images); 124 CatchImageException(images);
114 DestroyImageInfo(image_info); 125 DestroyImageInfo(image_info);
126 if (image != images)
115 DestroyImages(image); 127 DestroyImages(image);
116 DestroyImages(images); 128 DestroyImages(images);
117 return 0; 129 return 0;
118#endif 130#endif
119} 131}
120 132
121static int psiconv_gen_image_mbm(const char *filename, psiconv_mbm_f f, 133static int psiconv_gen_image_mbm(const char *filename, psiconv_mbm_f f,
122 const char *dest) 134 const char *dest)
123{ 135{
136
124#if IMAGEMAGICK 137#if IMAGEMAGICK
125 psiconv_paint_data_section section; 138 psiconv_paint_data_section section;
126 MagickInfo *mi = GetMagickInfo(dest); 139 const MagickInfo *mi;
127 ImageInfo *image_info; 140 ImageInfo *image_info;
128 Image *image = NULL; 141 Image *image = NULL;
129 Image *last_image = NULL; 142 Image *last_image = NULL;
130 Image *this_image, *images; 143 Image *this_image, *images;
131 ExceptionInfo exc; 144 ExceptionInfo exc;
132 int i; 145 int i;
133 unsigned int status; 146 unsigned int status;
134 147
148 GetExceptionInfo(&exc);
149 if (!(mi = GetMagickInfo(dest,&exc)))
150 return -1;
151
135 if ((psiconv_list_length(f->sections) < 1) || 152 if ((psiconv_list_length(f->sections) < 1) ||
136 ((psiconv_list_length(f->sections)) > 1 && ! (mi->adjoin))) 153 ((psiconv_list_length(f->sections)) > 1 && ! (mi->adjoin)))
137#endif 154#endif
138 return -1; 155 return -1;
139#if IMAGEMAGICK 156#if IMAGEMAGICK
157
140 for (i = 0; i < psiconv_list_length(f->sections); i++) { 158 for (i = 0; i < psiconv_list_length(f->sections); i++) {
141 section = psiconv_list_get(f->sections,i); 159 section = psiconv_list_get(f->sections,i);
142 this_image = get_paint_data_section(section); 160 this_image = get_paint_data_section(section);
143 if (! image) { 161 if (! image) {
144 image = this_image; 162 image = this_image;
145 this_image->scene=1;
146 } else { 163 } else {
147 last_image->next=this_image; 164 last_image->next=this_image;
148 this_image->previous=last_image; 165 this_image->previous=last_image;
149 } 166 }
150 last_image = this_image; 167 last_image = this_image;
151 } 168 }
152 169
153 GetExceptionInfo(&exc);
154 image_info = CloneImageInfo(NULL); 170 image_info = CloneImageInfo(NULL);
155 set_filename(image->filename,dest,filename); 171 set_filename(image->filename,dest,filename);
172 if (image->next)
156 images = CoalesceImages(image,&exc); 173 images = CoalesceImages(image,&exc);
174 else
175 images = image;
157 if (! images) 176 if (! images)
158 CatchImageException(image); 177 CatchImageException(image);
159 178
160 status = WriteImage(image_info,images); 179 status = WriteImage(image_info,images);
161 if (!status) 180 if (!status)
162 CatchImageException(images); 181 CatchImageException(images);
163 DestroyImageInfo(image_info); 182 DestroyImageInfo(image_info);
183 if (image != images)
164 DestroyImages(image); 184 DestroyImages(image);
165 DestroyImages(images); 185 DestroyImages(images);
166 return 0; 186 return 0;
167#endif 187#endif
168} 188}
169 189
182 DestroyImage(image); 202 DestroyImage(image);
183#endif 203#endif
184} 204}
185 205
186static int psiconv_gen_image(const char * filename, const psiconv_file file, 206static int psiconv_gen_image(const char * filename, const psiconv_file file,
187 const char *dest) 207 const char *dest,
208 const psiconv_encoding encoding_type)
209 /* Here the encoding_type is a dummy */
188{ 210{
189 if (file->type == psiconv_mbm_file) 211 if (file->type == psiconv_mbm_file)
190 psiconv_gen_image_mbm(filename,(psiconv_mbm_f) file->file,dest); 212 psiconv_gen_image_mbm(filename,(psiconv_mbm_f) file->file,dest);
191 if (file->type == psiconv_clipart_file) 213 else if (file->type == psiconv_clipart_file)
192 psiconv_gen_image_clipart(filename,(psiconv_clipart_f) file->file,dest); 214 psiconv_gen_image_clipart(filename,(psiconv_clipart_f) file->file,dest);
193 else if (file->type == psiconv_sketch_file) { 215 else if (file->type == psiconv_sketch_file) {
194 psiconv_gen_image_sketch(filename,(psiconv_sketch_f) file->file,dest); 216 psiconv_gen_image_sketch(filename,(psiconv_sketch_f) file->file,dest);
195 } else 217 } else
196 return -1; 218 return -1;
199 221
200void init_image(void) 222void init_image(void)
201{ 223{
202 struct psiconv_fileformat_s ff; 224 struct psiconv_fileformat_s ff;
203#if IMAGEMAGICK 225#if IMAGEMAGICK
204 MagickInfo *mi; 226 const MagickInfo *mi;
205 ff.output = psiconv_gen_image; 227 ff.output = psiconv_gen_image;
206 for (mi = GetMagickFileList(); mi ; mi = mi->next) { 228 for (mi = GetMagickFileList(); mi ; mi = mi->next) {
207 if (mi->encoder) { 229 if (mi->encoder) {
208 ff.name = strdup(mi->tag); 230 ff.name = strdup(mi->name);
209 ff.description = strdup(mi->description); 231 ff.description = strdup(mi->description);
210 psiconv_list_add(fileformat_list,&ff); 232 psiconv_list_add(fileformat_list,&ff);
211 } 233 }
212 } 234 }
213#endif 235#endif

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

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