/[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 138 - (hide annotations)
Tue Jan 22 21:22:55 2002 UTC (22 years, 2 months ago) by frodo
File MIME type: text/plain
File size: 6102 byte(s)
(Frodo) Update for newest ImageMagick

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

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