/[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 52 - (hide annotations)
Wed Oct 4 19:02:04 2000 UTC (23 years, 5 months ago) by frodo
File MIME type: text/plain
File size: 5021 byte(s)
(Frodo) Now finally ImageMagick 5 works correctly.

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     #include "data.h"
22     #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     /* This is ridiculously simple using ImageMagick. Without it, it would
31 frodo 49 be quite somewhat harder - it will be left for later on.
32     Note that we ignore any errors. Dangerous... */
33 frodo 32
34 frodo 39 static Image *get_paint_data_section(psiconv_paint_data_section sec)
35 frodo 32 {
36     Image *image;
37 frodo 49 float *pixel, *p, *red, *green, *blue;
38     int x,y;
39     ExceptionInfo *exc;
40    
41     GetExceptionInfo(exc);
42     red = sec->red;
43     green = sec->green;
44     blue = sec->blue;
45     p = pixel = malloc(sec->xsize * sec->ysize * 3 * sizeof(float));
46     for (y = 0; y < sec->ysize; y++) {
47     for (x = 0; x < sec->xsize; x++) {
48     *p++ = *red++;
49     *p++ = *green++;
50     *p++ = *blue++;
51     }
52     }
53     image = ConstituteImage(sec->xsize,sec->ysize,"RGB",FloatPixel,pixel,exc);
54     free(pixel);
55     DestroyExceptionInfo(exc);
56    
57 frodo 39 return image;
58 frodo 32 }
59    
60 frodo 48 #endif
61 frodo 39
62 frodo 44 static int psiconv_gen_image_clipart(FILE *of, psiconv_clipart_f f,
63     const char *dest)
64     {
65     #if IMAGEMAGICK
66     psiconv_clipart_section section;
67     MagickInfo *mi = GetMagickInfo(dest);
68     ImageInfo image_info;
69     Image *image = NULL;
70     Image *last_image = NULL;
71     Image *this_image;
72     int i;
73    
74     if ((psiconv_list_length(f->sections) < 1) ||
75     ((psiconv_list_length(f->sections)) > 1 && ! (mi->adjoin)))
76     #endif
77     return -1;
78     #if IMAGEMAGICK
79     for (i = 0; i < psiconv_list_length(f->sections); i++) {
80     section = psiconv_list_get(f->sections,i);
81     this_image = get_paint_data_section(section->picture);
82     if (! image) {
83     image = this_image;
84     last_image = image;
85     } else {
86     last_image->next=this_image;
87     this_image->previous=last_image;
88     this_image->scene=i;
89     last_image=this_image;
90     }
91     }
92    
93     GetImageInfo(&image_info);
94     image_info.file = of;
95     strcpy(image->magick, dest);
96     image_info.adjoin=1;
97     WriteImage(&image_info,image);
98     return 0;
99     #endif
100     }
101    
102 frodo 38 static int psiconv_gen_image_mbm(FILE *of, psiconv_mbm_f f, const char *dest)
103 frodo 32 {
104 frodo 39 #if IMAGEMAGICK
105 frodo 32 psiconv_paint_data_section section;
106 frodo 38 MagickInfo *mi = GetMagickInfo(dest);
107 frodo 39 ImageInfo image_info;
108     Image *image = NULL;
109     Image *last_image = NULL;
110     Image *this_image;
111     int i;
112    
113     if ((psiconv_list_length(f->sections) < 1) ||
114     ((psiconv_list_length(f->sections)) > 1 && ! (mi->adjoin)))
115 frodo 38 #endif
116 frodo 39 return -1;
117     #if IMAGEMAGICK
118     for (i = 0; i < psiconv_list_length(f->sections); i++) {
119 frodo 40 section = psiconv_list_get(f->sections,i);
120 frodo 39 this_image = get_paint_data_section(section);
121     if (! image) {
122 frodo 40 image = this_image;
123 frodo 39 last_image = image;
124     } else {
125     last_image->next=this_image;
126     this_image->previous=last_image;
127 frodo 40 this_image->scene=i;
128     last_image=this_image;
129 frodo 39 }
130     }
131 frodo 40
132 frodo 39 GetImageInfo(&image_info);
133     image_info.file = of;
134     strcpy(image->magick, dest);
135 frodo 40 image_info.adjoin=1;
136 frodo 39 WriteImage(&image_info,image);
137     return 0;
138 frodo 38 #endif
139 frodo 32 }
140    
141 frodo 39 static void psiconv_gen_image_sketch(FILE *of, psiconv_sketch_f f,
142     const char *dest)
143 frodo 32 {
144 frodo 39 #if IMAGEMAGICK
145     ImageInfo image_info;
146     Image *image;
147    
148     image = get_paint_data_section(f->sketch_sec->picture);
149     GetImageInfo(&image_info);
150     image_info.file = of;
151     strcpy(image->magick, dest);
152     WriteImage(&image_info,image);
153     #endif
154 frodo 32 }
155    
156 frodo 34 static int psiconv_gen_image(FILE * of, const psiconv_file file,
157     const char *dest)
158 frodo 32 {
159 frodo 38 if (file->type == psiconv_mbm_file)
160     return psiconv_gen_image_mbm(of,(psiconv_mbm_f) file->file,dest);
161 frodo 44 if (file->type == psiconv_clipart_file)
162     return psiconv_gen_image_clipart(of,(psiconv_clipart_f) file->file,dest);
163 frodo 38 else if (file->type == psiconv_sketch_file) {
164 frodo 34 psiconv_gen_image_sketch(of,(psiconv_sketch_f) file->file,dest);
165     return 0;
166     } else
167     return -1;
168 frodo 32 }
169    
170 frodo 34 void init_image(void)
171     {
172     struct psiconv_fileformat ff;
173     #if IMAGEMAGICK
174     MagickInfo *mi;
175     ff.output = psiconv_gen_image;
176 frodo 52 for (mi = GetMagickFileList(); mi ; mi = mi->next) {
177 frodo 34 if (mi->encoder) {
178     ff.name = strdup(mi->tag);
179     ff.description = strdup(mi->description);
180     psiconv_list_add(fileformat_list,&ff);
181     }
182     }
183     #endif
184     }
185    

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