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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 34 Revision 147
16 * along with this program; if not, write to the Free Software 16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */ 18 */
19 19
20#include "config.h" 20#include "config.h"
21#include "data.h" 21#include "psiconv/data.h"
22#include "gen.h" 22#include "gen.h"
23#include <string.h> 23#include <string.h>
24#include "psiconv.h" 24#include "psiconv.h"
25 25
26#if IMAGEMAGICK 26#ifdef IMAGEMAGICK
27#include "magick-aux.h"
27#include <magick/magick.h> 28#include <magick/magick.h>
29
30#ifdef DMALLOC
31#include "dmalloc.h"
28#endif 32#endif
33
34static void set_filename(char *dest,const char *type, const char *name)
35{
36 int len;
37 strcpy(dest,type);
38 len = strlen(dest);
39 dest[len] = ':';
40 strcpy(dest + len + 1,name);
41}
29 42
30/* This is ridiculously simple using ImageMagick. Without it, it would 43/* This is ridiculously simple using ImageMagick. Without it, it would
31 be quite somewhat harder - it will be left for later on */ 44 be quite somewhat harder - it will be left for later on.
45 Note that we ignore any errors. Dangerous... */
32 46
33static void gen_paint_data_section(FILE *of, psiconv_paint_data_section sec, 47static Image *get_paint_data_section(psiconv_paint_data_section sec)
48{
49 Image *image;
50 float *pixel, *p, *red, *green, *blue;
51 int x,y;
52 ExceptionInfo exc;
53
54 GetExceptionInfo(&exc);
55 red = sec->red;
56 green = sec->green;
57 blue = sec->blue;
58 p = pixel = malloc(sec->xsize * sec->ysize * 3 * sizeof(float));
59 for (y = 0; y < sec->ysize; y++) {
60 for (x = 0; x < sec->xsize; x++) {
61 *p++ = *red++;
62 *p++ = *green++;
63 *p++ = *blue++;
64 }
65 }
66
67 image = ConstituteImage(sec->xsize,sec->ysize,"RGB",FloatPixel,pixel,&exc);
68 if (! image) {
69 MagickError(exc.severity,exc.reason,exc.description);
70 }
71 free(pixel);
72
73 return image;
74}
75
76#endif
77
78static int psiconv_gen_image_clipart(const char *filename, psiconv_clipart_f f,
34 const char *dest) 79 const char *dest)
35{ 80{
36#if IMAGEMAGICK 81#if IMAGEMAGICK
82 psiconv_clipart_section section;
83 const MagickInfo *mi;
37 ImageInfo image_info; 84 ImageInfo *image_info;
85 Image *image = NULL;
86 Image *last_image = NULL;
87 Image *this_image, *images;
88 ExceptionInfo exc;
89 int i;
90 unsigned int status;
91
92 GetExceptionInfo(&exc);
93 if (!(mi = GetMagickInfo(dest,&exc)))
94 return -1;
95
96 if ((psiconv_list_length(f->sections) < 1) ||
97 ((psiconv_list_length(f->sections)) > 1 && ! (mi->adjoin)))
98#endif
99 return -1;
100#if IMAGEMAGICK
101 for (i = 0; i < psiconv_list_length(f->sections); i++) {
102 section = psiconv_list_get(f->sections,i);
103 this_image = get_paint_data_section(section->picture);
104 if (! image) {
105 image = this_image;
106 } else {
107 last_image->next=this_image;
108 this_image->previous=last_image;
109 }
110 last_image = this_image;
111 }
112
113 image_info = CloneImageInfo(NULL);
114 set_filename(image->filename,dest,filename);
115 if (image->next)
116 images = CoalesceImages(image,&exc);
117 else
118 images = image;
119 if (! images)
120 CatchImageException(image);
121
122 status = WriteImage(image_info,images);
123 if (!status)
124 CatchImageException(images);
125 DestroyImageInfo(image_info);
126 if (image != images)
127 DestroyImages(image);
128 DestroyImages(images);
129 return 0;
130#endif
131}
132
133static int psiconv_gen_image_mbm(const char *filename, psiconv_mbm_f f,
134 const char *dest)
135{
136
137#if IMAGEMAGICK
138 psiconv_paint_data_section section;
139 const MagickInfo *mi;
140 ImageInfo *image_info;
141 Image *image = NULL;
142 Image *last_image = NULL;
143 Image *this_image, *images;
144 ExceptionInfo exc;
145 int i;
146 unsigned int status;
147
148 GetExceptionInfo(&exc);
149 if (!(mi = GetMagickInfo(dest,&exc)))
150 return -1;
151
152 if ((psiconv_list_length(f->sections) < 1) ||
153 ((psiconv_list_length(f->sections)) > 1 && ! (mi->adjoin)))
154#endif
155 return -1;
156#if IMAGEMAGICK
157
158 for (i = 0; i < psiconv_list_length(f->sections); i++) {
159 section = psiconv_list_get(f->sections,i);
160 this_image = get_paint_data_section(section);
161 if (! image) {
162 image = this_image;
163 } else {
164 last_image->next=this_image;
165 this_image->previous=last_image;
166 }
167 last_image = this_image;
168 }
169
170 image_info = CloneImageInfo(NULL);
171 set_filename(image->filename,dest,filename);
172 if (image->next)
173 images = CoalesceImages(image,&exc);
174 else
175 images = image;
176 if (! images)
177 CatchImageException(image);
178
179 status = WriteImage(image_info,images);
180 if (!status)
181 CatchImageException(images);
182 DestroyImageInfo(image_info);
183 if (image != images)
184 DestroyImages(image);
185 DestroyImages(images);
186 return 0;
187#endif
188}
189
190static void psiconv_gen_image_sketch(const char *filename, psiconv_sketch_f f,
191 const char *dest)
192{
193#if IMAGEMAGICK
194 ImageInfo *image_info;
38 Image *image; 195 Image *image;
39 196
40 image = CreateImage(sec->xsize,sec->ysize,sec->red,sec->green, 197 image = get_paint_data_section(f->sketch_sec->picture);
41 sec->blue,NULL); 198 image_info = CloneImageInfo(NULL);
42 GetImageInfo(&image_info); 199 set_filename(image->filename,dest,filename);
43 image_info.file = of;
44 strcpy(image->magick, dest);
45 WriteImage(&image_info,image); 200 WriteImage(image_info,image);
201 DestroyImageInfo(image_info);
202 DestroyImage(image);
46#endif 203#endif
47} 204}
48 205
49static void psiconv_gen_image_mbm(FILE *of, psiconv_mbm_f f, const char *dest)
50{
51 psiconv_paint_data_section section;
52 if (psiconv_list_length(f->sections) >= 1) {
53 section = psiconv_list_get(f->sections,0);
54 gen_paint_data_section(of,section,dest);
55 }
56}
57
58static void psiconv_gen_image_sketch(FILE *of, psiconv_sketch_f f,
59 const char * dest)
60{
61 gen_paint_data_section(of,f->sketch_sec->picture,dest);
62}
63
64static int psiconv_gen_image(FILE * of, const psiconv_file file, 206static int psiconv_gen_image(const char * filename, const psiconv_file file,
65 const char *dest) 207 const char *dest,
208 const psiconv_encoding encoding_type)
209 /* Here the encoding_type is a dummy */
66{ 210{
67 if (file->type == psiconv_mbm_file) { 211 if (file->type == psiconv_mbm_file)
68 psiconv_gen_image_mbm(of,(psiconv_mbm_f) file->file,dest); 212 psiconv_gen_image_mbm(filename,(psiconv_mbm_f) file->file,dest);
69 return 0; 213 else if (file->type == psiconv_clipart_file)
214 psiconv_gen_image_clipart(filename,(psiconv_clipart_f) file->file,dest);
70 } else if (file->type == psiconv_sketch_file) { 215 else if (file->type == psiconv_sketch_file) {
71 psiconv_gen_image_sketch(of,(psiconv_sketch_f) file->file,dest); 216 psiconv_gen_image_sketch(filename,(psiconv_sketch_f) file->file,dest);
72 return 0;
73 } else 217 } else
74 return -1; 218 return -1;
219 return 0;
75} 220}
76 221
77void init_image(void) 222void init_image(void)
78{ 223{
79 struct psiconv_fileformat ff; 224 struct psiconv_fileformat_s ff;
80#if IMAGEMAGICK 225#if IMAGEMAGICK
81 MagickInfo *mi; 226 const MagickInfo *mi;
82 ff.output = psiconv_gen_image; 227 ff.output = psiconv_gen_image;
83 for (mi = GetMagickInfo(NULL); mi ; mi = mi->next) { 228 for (mi = GetMagickFileList(); mi ; mi = mi->next) {
84 if (mi->encoder) { 229 if (mi->encoder) {
85 ff.name = strdup(mi->tag); 230 ff.name = strdup(mi->name);
86 ff.description = strdup(mi->description); 231 ff.description = strdup(mi->description);
87 psiconv_list_add(fileformat_list,&ff); 232 psiconv_list_add(fileformat_list,&ff);
88 } 233 }
89 } 234 }
90#endif 235#endif

Legend:
Removed from v.34  
changed lines
  Added in v.147

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