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

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

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