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

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

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