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

Legend:
Removed from v.40  
changed lines
  Added in v.66

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