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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 53 - (show annotations)
Sat Oct 21 00:49:13 2000 UTC (19 years, 1 month ago) by frodo
File MIME type: text/plain
File size: 5877 byte(s)
(Frodo) YES! Fixed everything - ImageMagick should now finally work!

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

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