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 |
#endif |
29 |
|
30 |
/* This is ridiculously simple using ImageMagick. Without it, it would |
31 |
be quite somewhat harder - it will be left for later on */ |
32 |
|
33 |
static void gen_paint_data_section(FILE *of, psiconv_paint_data_section sec, |
34 |
const char *dest) |
35 |
{ |
36 |
#if IMAGEMAGICK |
37 |
ImageInfo image_info; |
38 |
Image *image; |
39 |
|
40 |
image = CreateImage(sec->xsize,sec->ysize,sec->red,sec->green, |
41 |
sec->blue,NULL); |
42 |
GetImageInfo(&image_info); |
43 |
image_info.file = of; |
44 |
strcpy(image->magick, dest); |
45 |
WriteImage(&image_info,image); |
46 |
#endif |
47 |
} |
48 |
|
49 |
static int psiconv_gen_image_mbm(FILE *of, psiconv_mbm_f f, const char *dest) |
50 |
{ |
51 |
psiconv_paint_data_section section; |
52 |
#if IMAGEMAGICK |
53 |
MagickInfo *mi = GetMagickInfo(dest); |
54 |
#endif |
55 |
if (psiconv_list_length(f->sections) == 1) { |
56 |
section = psiconv_list_get(f->sections,0); |
57 |
gen_paint_data_section(of,section,dest); |
58 |
return 0; |
59 |
#if IMAGEMAGICK |
60 |
} else if ((mi->adjoin) && (psiconv_list_length(f->sections) >= 1)) { |
61 |
/* Not yet supported... */ |
62 |
return -1; |
63 |
#endif |
64 |
} else |
65 |
return -1; |
66 |
} |
67 |
|
68 |
static void psiconv_gen_image_sketch(FILE *of, psiconv_sketch_f f, |
69 |
const char * dest) |
70 |
{ |
71 |
gen_paint_data_section(of,f->sketch_sec->picture,dest); |
72 |
} |
73 |
|
74 |
static int psiconv_gen_image(FILE * of, const psiconv_file file, |
75 |
const char *dest) |
76 |
{ |
77 |
if (file->type == psiconv_mbm_file) |
78 |
return psiconv_gen_image_mbm(of,(psiconv_mbm_f) file->file,dest); |
79 |
else if (file->type == psiconv_sketch_file) { |
80 |
psiconv_gen_image_sketch(of,(psiconv_sketch_f) file->file,dest); |
81 |
return 0; |
82 |
} else |
83 |
return -1; |
84 |
} |
85 |
|
86 |
void init_image(void) |
87 |
{ |
88 |
struct psiconv_fileformat ff; |
89 |
#if IMAGEMAGICK |
90 |
MagickInfo *mi; |
91 |
ff.output = psiconv_gen_image; |
92 |
for (mi = GetMagickInfo(NULL); mi ; mi = mi->next) { |
93 |
if (mi->encoder) { |
94 |
ff.name = strdup(mi->tag); |
95 |
ff.description = strdup(mi->description); |
96 |
psiconv_list_add(fileformat_list,&ff); |
97 |
} |
98 |
} |
99 |
#endif |
100 |
} |
101 |
|