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