/[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 192 - (hide annotations)
Mon Feb 2 20:43:04 2004 UTC (20 years, 2 months ago) by frodo
File MIME type: text/plain
File size: 7239 byte(s)
(Frodo) Psiconv program update
  * Created html4 target
  * Update of xhtml target (print entities if ASCII, and others)
  * Made everything static that should not be exported
  * Renamed stuff to xhtml were appropriate
  * The fileformat data does now contain the supported Psion files to convert
  * This is also printed in the help text
  * ENCODING_ASCII_HTML introduced (only used internally)
  * Replaced debug, silent, verbose options with noise option
  * Default targets are XHTML and TIFF

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

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