/[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 142 - (hide annotations)
Tue Jan 29 18:38:38 2002 UTC (22 years, 2 months ago) by frodo
File MIME type: text/plain
File size: 6149 byte(s)
(Frodo) DMALLOC support

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

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