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

Legend:
Removed from v.49  
changed lines
  Added in v.187

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