/[public]/psiconv/trunk/program/psiconv/gen_image.c
ViewVC logotype

Annotation of /psiconv/trunk/program/psiconv/gen_image.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 249 - (hide annotations)
Thu Apr 29 19:40:59 2004 UTC (19 years, 11 months ago) by frodo
File MIME type: text/plain
File size: 7429 byte(s)
(Frodo) Solaris build fixes

  * gen_image fixes (didn't I do these before?!?)
  * Building shared libs

1 frodo 32 /*
2     * gen_image.c - Part of psiconv, a PSION 5 file formats converter
3 frodo 196 * Copyright (c) 1999-2004 Frodo Looijaard <frodol@dds.nl>
4 frodo 32 *
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
7     * the Free Software Foundation; either version 2 of the License, or
8     * (at your option) any later version.
9     *
10     * This program is distributed in the hope that it will be useful,
11     * but WITHOUT ANY WARRANTY; without even the implied warranty of
12     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13     * GNU General Public License for more details.
14     *
15     * You should have received a copy of the GNU General Public License
16     * along with this program; if not, write to the Free Software
17     * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18     */
19    
20     #include "config.h"
21 frodo 58 #include "psiconv/data.h"
22 frodo 32 #include "gen.h"
23 frodo 187 #include "psiconv.h"
24 frodo 32 #include <string.h>
25 frodo 187 #include <stdlib.h>
26 frodo 32
27 frodo 142 #ifdef IMAGEMAGICK
28 frodo 52 #include "magick-aux.h"
29 frodo 32 #include <magick/magick.h>
30 frodo 187 #endif
31 frodo 32
32 frodo 142 #ifdef DMALLOC
33     #include "dmalloc.h"
34     #endif
35    
36 frodo 249 #ifdef IMAGEMAGICK
37 frodo 192 static Image *get_paint_data_section(psiconv_paint_data_section sec);
38     static void image_to_list(psiconv_list list,Image *image,const char *dest);
39     static void gen_image_list(const psiconv_config config,psiconv_list list,
40     const psiconv_list sections, const char *dest);
41     static void gen_clipart(const psiconv_config config,psiconv_list list,
42     const psiconv_clipart_f f, const char *dest);
43     static void gen_mbm(const psiconv_config config,psiconv_list list,
44     const psiconv_mbm_f f, const char *dest);
45     static void gen_sketch(const psiconv_config config,psiconv_list list,
46     const psiconv_sketch_f f, const char *dest);
47 frodo 193 static int gen_image(psiconv_config config, psiconv_list list,
48     const psiconv_file file, const char *dest,
49     const encoding encoding_type);
50 frodo 192
51 frodo 32 /* This is ridiculously simple using ImageMagick. Without it, it would
52 frodo 49 be quite somewhat harder - it will be left for later on.
53     Note that we ignore any errors. Dangerous... */
54 frodo 32
55 frodo 192 Image *get_paint_data_section(psiconv_paint_data_section sec)
56 frodo 32 {
57     Image *image;
58 frodo 49 float *pixel, *p, *red, *green, *blue;
59     int x,y;
60 frodo 53 ExceptionInfo exc;
61 frodo 49
62 frodo 53 GetExceptionInfo(&exc);
63 frodo 49 red = sec->red;
64     green = sec->green;
65     blue = sec->blue;
66     p = pixel = malloc(sec->xsize * sec->ysize * 3 * sizeof(float));
67     for (y = 0; y < sec->ysize; y++) {
68     for (x = 0; x < sec->xsize; x++) {
69     *p++ = *red++;
70     *p++ = *green++;
71     *p++ = *blue++;
72     }
73     }
74 frodo 66
75 frodo 53 image = ConstituteImage(sec->xsize,sec->ysize,"RGB",FloatPixel,pixel,&exc);
76 frodo 187 if (! image || (exc.severity != UndefinedException)) {
77 frodo 118 MagickError(exc.severity,exc.reason,exc.description);
78 frodo 187 exit(1);
79 frodo 53 }
80 frodo 49 free(pixel);
81    
82 frodo 187 DestroyExceptionInfo(&exc);
83    
84 frodo 39 return image;
85 frodo 32 }
86    
87 frodo 39
88 frodo 192 void image_to_list(psiconv_list list,Image *image,const char *dest)
89 frodo 44 {
90 frodo 53 ImageInfo *image_info;
91     ExceptionInfo exc;
92 frodo 187 size_t length;
93     char *data;
94 frodo 44 int i;
95 frodo 187
96     strcpy(image->magick,dest);
97     image_info = CloneImageInfo(NULL);
98 frodo 118 GetExceptionInfo(&exc);
99 frodo 187 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 frodo 44 }
109     }
110 frodo 187 DestroyExceptionInfo(&exc);
111 frodo 53 DestroyImageInfo(image_info);
112 frodo 44 }
113    
114 frodo 192 void gen_image_list(const psiconv_config config,psiconv_list list,
115 frodo 187 const psiconv_list sections, const char *dest)
116 frodo 32 {
117     psiconv_paint_data_section section;
118 frodo 138 const MagickInfo *mi;
119 frodo 53 ImageInfo *image_info;
120 frodo 39 Image *image = NULL;
121     Image *last_image = NULL;
122 frodo 53 Image *this_image, *images;
123     ExceptionInfo exc;
124 frodo 39 int i;
125 frodo 66
126 frodo 118 GetExceptionInfo(&exc);
127 frodo 187 mi = GetMagickInfo(dest,&exc);
128     if (!mi || (exc.severity != UndefinedException)) {
129     MagickError(exc.severity,exc.reason,exc.description);
130     exit(1);
131     }
132 frodo 118
133 frodo 187 if ((psiconv_list_length(sections) < 1) ||
134     ((psiconv_list_length(sections)) > 1 && ! (mi->adjoin))) {
135     fprintf(stderr,"This image type supports only one image\n");
136     exit(1);
137     }
138    
139     for (i = 0; i < psiconv_list_length(sections); i++) {
140     if (!(section = psiconv_list_get(sections,i))) {
141     fprintf(stderr,"Internal data structures corrupted\n");
142     exit(1);
143     }
144 frodo 39 this_image = get_paint_data_section(section);
145     if (! image) {
146 frodo 40 image = this_image;
147 frodo 39 } else {
148     last_image->next=this_image;
149     this_image->previous=last_image;
150     }
151 frodo 53 last_image = this_image;
152 frodo 39 }
153 frodo 40
154 frodo 53 image_info = CloneImageInfo(NULL);
155 frodo 187 if (image->next) {
156 frodo 66 images = CoalesceImages(image,&exc);
157 frodo 187 if (!images || (exc.severity != UndefinedException)) {
158     MagickError(exc.severity,exc.reason,exc.description);
159     exit(1);
160     }
161     } else
162 frodo 66 images = image;
163 frodo 53
164 frodo 187 image_to_list(list,image,dest);
165    
166     DestroyExceptionInfo(&exc);
167 frodo 53 DestroyImageInfo(image_info);
168 frodo 66 if (image != images)
169     DestroyImages(image);
170 frodo 53 DestroyImages(images);
171 frodo 32 }
172    
173 frodo 192 void gen_clipart(const psiconv_config config,psiconv_list list,
174 frodo 187 const psiconv_clipart_f f, const char *dest)
175 frodo 32 {
176 frodo 187 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);
183     }
184     for (i = 0; i < psiconv_list_length(f->sections); i ++) {
185     if (!(section = psiconv_list_get(f->sections,i))) {
186     fprintf(stderr,"Internal data structures corrupted\n");
187     exit(1);
188     }
189     if ((psiconv_list_add(sections,section->picture))) {
190     fprintf(stderr,"Out of memory error\n");
191     exit(1);
192     }
193     }
194     gen_image_list(config,list,sections,dest);
195     psiconv_list_free(sections);
196     }
197    
198 frodo 192 void gen_mbm(const psiconv_config config,psiconv_list list,
199 frodo 187 const psiconv_mbm_f f, const char *dest)
200     {
201     gen_image_list(config,list,f->sections,dest);
202     }
203    
204    
205 frodo 192 void gen_sketch(const psiconv_config config,psiconv_list list,
206 frodo 187 const psiconv_sketch_f f, const char *dest)
207     {
208 frodo 39 Image *image;
209    
210     image = get_paint_data_section(f->sketch_sec->picture);
211 frodo 187 image_to_list(list,image,dest);
212 frodo 53 DestroyImage(image);
213 frodo 32 }
214    
215 frodo 187
216 frodo 193 int gen_image(psiconv_config config, psiconv_list list,
217 frodo 187 const psiconv_file file, const char *dest,
218     const encoding encoding_type)
219 frodo 32 {
220 frodo 38 if (file->type == psiconv_mbm_file)
221 frodo 192 gen_mbm(config,list,(psiconv_mbm_f) file->file,dest);
222 frodo 66 else if (file->type == psiconv_clipart_file)
223 frodo 192 gen_clipart(config,list,
224 frodo 187 (psiconv_clipart_f) file->file,dest);
225     else
226     if (file->type == psiconv_sketch_file) {
227 frodo 192 gen_sketch(config, list,(psiconv_sketch_f) file->file,dest);
228 frodo 34 } else
229     return -1;
230 frodo 53 return 0;
231 frodo 32 }
232    
233 frodo 249 #endif
234    
235 frodo 34 void init_image(void)
236     {
237 frodo 187 struct fileformat_s ff;
238 frodo 34 #if IMAGEMAGICK
239 frodo 138 const MagickInfo *mi;
240 frodo 187 ff.output = gen_image;
241 frodo 52 for (mi = GetMagickFileList(); mi ; mi = mi->next) {
242 frodo 34 if (mi->encoder) {
243 frodo 138 ff.name = strdup(mi->name);
244 frodo 34 ff.description = strdup(mi->description);
245 frodo 192 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;
249 frodo 34 psiconv_list_add(fileformat_list,&ff);
250     }
251     }
252     #endif
253     }
254    

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