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 |
53 |
image = ConstituteImage(sec->xsize,sec->ysize,"RGB",FloatPixel,pixel,&exc); |
63 |
|
|
if (! image) { |
64 |
|
|
MagickError(exc.severity,exc.message,exc.qualifier); |
65 |
|
|
} |
66 |
frodo |
49 |
free(pixel); |
67 |
|
|
|
68 |
frodo |
39 |
return image; |
69 |
frodo |
32 |
} |
70 |
|
|
|
71 |
frodo |
48 |
#endif |
72 |
frodo |
39 |
|
73 |
frodo |
53 |
static int psiconv_gen_image_clipart(const char *filename, psiconv_clipart_f f, |
74 |
frodo |
44 |
const char *dest) |
75 |
|
|
{ |
76 |
|
|
#if IMAGEMAGICK |
77 |
|
|
psiconv_clipart_section section; |
78 |
|
|
MagickInfo *mi = GetMagickInfo(dest); |
79 |
frodo |
53 |
ImageInfo *image_info; |
80 |
frodo |
44 |
Image *image = NULL; |
81 |
|
|
Image *last_image = NULL; |
82 |
frodo |
53 |
Image *this_image, *images; |
83 |
|
|
ExceptionInfo exc; |
84 |
frodo |
44 |
int i; |
85 |
frodo |
53 |
unsigned int status; |
86 |
frodo |
44 |
|
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 |
frodo |
53 |
last_image = this_image; |
102 |
frodo |
44 |
} |
103 |
|
|
|
104 |
frodo |
53 |
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 |
frodo |
44 |
return 0; |
118 |
|
|
#endif |
119 |
|
|
} |
120 |
|
|
|
121 |
frodo |
53 |
static int psiconv_gen_image_mbm(const char *filename, psiconv_mbm_f f, |
122 |
|
|
const char *dest) |
123 |
frodo |
32 |
{ |
124 |
frodo |
39 |
#if IMAGEMAGICK |
125 |
frodo |
32 |
psiconv_paint_data_section section; |
126 |
frodo |
38 |
MagickInfo *mi = GetMagickInfo(dest); |
127 |
frodo |
53 |
ImageInfo *image_info; |
128 |
frodo |
39 |
Image *image = NULL; |
129 |
|
|
Image *last_image = NULL; |
130 |
frodo |
53 |
Image *this_image, *images; |
131 |
|
|
ExceptionInfo exc; |
132 |
frodo |
39 |
int i; |
133 |
frodo |
53 |
unsigned int status; |
134 |
frodo |
39 |
|
135 |
|
|
if ((psiconv_list_length(f->sections) < 1) || |
136 |
|
|
((psiconv_list_length(f->sections)) > 1 && ! (mi->adjoin))) |
137 |
frodo |
38 |
#endif |
138 |
frodo |
39 |
return -1; |
139 |
|
|
#if IMAGEMAGICK |
140 |
|
|
for (i = 0; i < psiconv_list_length(f->sections); i++) { |
141 |
frodo |
40 |
section = psiconv_list_get(f->sections,i); |
142 |
frodo |
39 |
this_image = get_paint_data_section(section); |
143 |
|
|
if (! image) { |
144 |
frodo |
40 |
image = this_image; |
145 |
frodo |
53 |
this_image->scene=1; |
146 |
frodo |
39 |
} else { |
147 |
|
|
last_image->next=this_image; |
148 |
|
|
this_image->previous=last_image; |
149 |
|
|
} |
150 |
frodo |
53 |
last_image = this_image; |
151 |
frodo |
39 |
} |
152 |
frodo |
40 |
|
153 |
frodo |
53 |
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 |
frodo |
39 |
return 0; |
167 |
frodo |
38 |
#endif |
168 |
frodo |
32 |
} |
169 |
|
|
|
170 |
frodo |
53 |
static void psiconv_gen_image_sketch(const char *filename, psiconv_sketch_f f, |
171 |
frodo |
39 |
const char *dest) |
172 |
frodo |
32 |
{ |
173 |
frodo |
39 |
#if IMAGEMAGICK |
174 |
frodo |
53 |
ImageInfo *image_info; |
175 |
frodo |
39 |
Image *image; |
176 |
|
|
|
177 |
|
|
image = get_paint_data_section(f->sketch_sec->picture); |
178 |
frodo |
53 |
image_info = CloneImageInfo(NULL); |
179 |
|
|
set_filename(image->filename,dest,filename); |
180 |
|
|
WriteImage(image_info,image); |
181 |
|
|
DestroyImageInfo(image_info); |
182 |
|
|
DestroyImage(image); |
183 |
frodo |
39 |
#endif |
184 |
frodo |
32 |
} |
185 |
|
|
|
186 |
frodo |
53 |
static int psiconv_gen_image(const char * filename, const psiconv_file file, |
187 |
frodo |
34 |
const char *dest) |
188 |
frodo |
32 |
{ |
189 |
frodo |
38 |
if (file->type == psiconv_mbm_file) |
190 |
frodo |
53 |
psiconv_gen_image_mbm(filename,(psiconv_mbm_f) file->file,dest); |
191 |
frodo |
44 |
if (file->type == psiconv_clipart_file) |
192 |
frodo |
53 |
psiconv_gen_image_clipart(filename,(psiconv_clipart_f) file->file,dest); |
193 |
frodo |
38 |
else if (file->type == psiconv_sketch_file) { |
194 |
frodo |
53 |
psiconv_gen_image_sketch(filename,(psiconv_sketch_f) file->file,dest); |
195 |
frodo |
34 |
} else |
196 |
|
|
return -1; |
197 |
frodo |
53 |
return 0; |
198 |
frodo |
32 |
} |
199 |
|
|
|
200 |
frodo |
34 |
void init_image(void) |
201 |
|
|
{ |
202 |
frodo |
56 |
struct psiconv_fileformat_s ff; |
203 |
frodo |
34 |
#if IMAGEMAGICK |
204 |
|
|
MagickInfo *mi; |
205 |
|
|
ff.output = psiconv_gen_image; |
206 |
frodo |
52 |
for (mi = GetMagickFileList(); mi ; mi = mi->next) { |
207 |
frodo |
34 |
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 |
|
|
|