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

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

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