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

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

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