/[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 39 Revision 52
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 29
30/* This is ridiculously simple using ImageMagick. Without it, it would 30/* This is ridiculously simple using ImageMagick. Without it, it would
31 be quite somewhat harder - it will be left for later on */ 31 be quite somewhat harder - it will be left for later on.
32 Note that we ignore any errors. Dangerous... */
32 33
33static Image *get_paint_data_section(psiconv_paint_data_section sec) 34static Image *get_paint_data_section(psiconv_paint_data_section sec)
34{ 35{
35 Image *image; 36 Image *image;
36 image = CreateImage(sec->xsize,sec->ysize,sec->red,sec->green, 37 float *pixel, *p, *red, *green, *blue;
37 sec->blue,NULL); 38 int x,y;
39 ExceptionInfo *exc;
40
41 GetExceptionInfo(exc);
42 red = sec->red;
43 green = sec->green;
44 blue = sec->blue;
45 p = pixel = malloc(sec->xsize * sec->ysize * 3 * sizeof(float));
46 for (y = 0; y < sec->ysize; y++) {
47 for (x = 0; x < sec->xsize; x++) {
48 *p++ = *red++;
49 *p++ = *green++;
50 *p++ = *blue++;
51 }
52 }
53 image = ConstituteImage(sec->xsize,sec->ysize,"RGB",FloatPixel,pixel,exc);
54 free(pixel);
55 DestroyExceptionInfo(exc);
56
38 return image; 57 return image;
39} 58}
40 59
60#endif
61
62static int psiconv_gen_image_clipart(FILE *of, psiconv_clipart_f f,
63 const char *dest)
64{
65#if IMAGEMAGICK
66 psiconv_clipart_section section;
67 MagickInfo *mi = GetMagickInfo(dest);
68 ImageInfo image_info;
69 Image *image = NULL;
70 Image *last_image = NULL;
71 Image *this_image;
72 int i;
73
74 if ((psiconv_list_length(f->sections) < 1) ||
75 ((psiconv_list_length(f->sections)) > 1 && ! (mi->adjoin)))
76#endif
77 return -1;
78#if IMAGEMAGICK
79 for (i = 0; i < psiconv_list_length(f->sections); i++) {
80 section = psiconv_list_get(f->sections,i);
81 this_image = get_paint_data_section(section->picture);
82 if (! image) {
83 image = this_image;
84 last_image = image;
85 } else {
86 last_image->next=this_image;
87 this_image->previous=last_image;
88 this_image->scene=i;
89 last_image=this_image;
90 }
91 }
92
93 GetImageInfo(&image_info);
94 image_info.file = of;
95 strcpy(image->magick, dest);
96 image_info.adjoin=1;
97 WriteImage(&image_info,image);
98 return 0;
99#endif
100}
41 101
42static int psiconv_gen_image_mbm(FILE *of, psiconv_mbm_f f, const char *dest) 102static int psiconv_gen_image_mbm(FILE *of, psiconv_mbm_f f, const char *dest)
43{ 103{
44#if IMAGEMAGICK 104#if IMAGEMAGICK
45 psiconv_paint_data_section section; 105 psiconv_paint_data_section section;
54 ((psiconv_list_length(f->sections)) > 1 && ! (mi->adjoin))) 114 ((psiconv_list_length(f->sections)) > 1 && ! (mi->adjoin)))
55#endif 115#endif
56 return -1; 116 return -1;
57#if IMAGEMAGICK 117#if IMAGEMAGICK
58 for (i = 0; i < psiconv_list_length(f->sections); i++) { 118 for (i = 0; i < psiconv_list_length(f->sections); i++) {
59 section = psiconv_list_get(f->sections,0); 119 section = psiconv_list_get(f->sections,i);
60 this_image = get_paint_data_section(section); 120 this_image = get_paint_data_section(section);
61 if (! image) { 121 if (! image) {
62 image = image; 122 image = this_image;
63 last_image = image; 123 last_image = image;
64 } else { 124 } else {
65 last_image->next=this_image; 125 last_image->next=this_image;
66 this_image->previous=last_image; 126 this_image->previous=last_image;
127 this_image->scene=i;
128 last_image=this_image;
67 } 129 }
68 } 130 }
69 131
70 GetImageInfo(&image_info); 132 GetImageInfo(&image_info);
71 image_info.file = of; 133 image_info.file = of;
72 strcpy(image->magick, dest); 134 strcpy(image->magick, dest);
135 image_info.adjoin=1;
73 WriteImage(&image_info,image); 136 WriteImage(&image_info,image);
74 return 0; 137 return 0;
75#endif 138#endif
76} 139}
77 140
93static int psiconv_gen_image(FILE * of, const psiconv_file file, 156static int psiconv_gen_image(FILE * of, const psiconv_file file,
94 const char *dest) 157 const char *dest)
95{ 158{
96 if (file->type == psiconv_mbm_file) 159 if (file->type == psiconv_mbm_file)
97 return psiconv_gen_image_mbm(of,(psiconv_mbm_f) file->file,dest); 160 return psiconv_gen_image_mbm(of,(psiconv_mbm_f) file->file,dest);
161 if (file->type == psiconv_clipart_file)
162 return psiconv_gen_image_clipart(of,(psiconv_clipart_f) file->file,dest);
98 else if (file->type == psiconv_sketch_file) { 163 else if (file->type == psiconv_sketch_file) {
99 psiconv_gen_image_sketch(of,(psiconv_sketch_f) file->file,dest); 164 psiconv_gen_image_sketch(of,(psiconv_sketch_f) file->file,dest);
100 return 0; 165 return 0;
101 } else 166 } else
102 return -1; 167 return -1;
106{ 171{
107 struct psiconv_fileformat ff; 172 struct psiconv_fileformat ff;
108#if IMAGEMAGICK 173#if IMAGEMAGICK
109 MagickInfo *mi; 174 MagickInfo *mi;
110 ff.output = psiconv_gen_image; 175 ff.output = psiconv_gen_image;
111 for (mi = GetMagickInfo(NULL); mi ; mi = mi->next) { 176 for (mi = GetMagickFileList(); mi ; mi = mi->next) {
112 if (mi->encoder) { 177 if (mi->encoder) {
113 ff.name = strdup(mi->tag); 178 ff.name = strdup(mi->tag);
114 ff.description = strdup(mi->description); 179 ff.description = strdup(mi->description);
115 psiconv_list_add(fileformat_list,&ff); 180 psiconv_list_add(fileformat_list,&ff);
116 } 181 }

Legend:
Removed from v.39  
changed lines
  Added in v.52

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