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

Legend:
Removed from v.52  
changed lines
  Added in v.142

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