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

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

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