--- psiconv/trunk/program/psiconv/gen_image.c 1999/11/30 00:24:35 32 +++ psiconv/trunk/program/psiconv/gen_image.c 2000/02/04 20:33:51 48 @@ -21,48 +21,145 @@ #include "data.h" #include "gen.h" #include +#include "psiconv.h" #if IMAGEMAGICK #include -#endif /* This is ridiculously simple using ImageMagick. Without it, it would - be somewhat more hard - it will be left for later on */ + be quite somewhat harder - it will be left for later on */ -static void gen_paint_data_section(FILE *of, psiconv_paint_data_section sec) +static Image *get_paint_data_section(psiconv_paint_data_section sec) { -#if IMAGEMAGICK - ImageInfo image_info; Image *image; - image = CreateImage(sec->xsize,sec->ysize,sec->red,sec->green, sec->blue,NULL); + return image; +} + +#endif + +static int psiconv_gen_image_clipart(FILE *of, psiconv_clipart_f f, + const char *dest) +{ +#if IMAGEMAGICK + psiconv_clipart_section section; + MagickInfo *mi = GetMagickInfo(dest); + ImageInfo image_info; + Image *image = NULL; + Image *last_image = NULL; + Image *this_image; + int i; + + if ((psiconv_list_length(f->sections) < 1) || + ((psiconv_list_length(f->sections)) > 1 && ! (mi->adjoin))) +#endif + return -1; +#if IMAGEMAGICK + for (i = 0; i < psiconv_list_length(f->sections); i++) { + section = psiconv_list_get(f->sections,i); + this_image = get_paint_data_section(section->picture); + if (! image) { + image = this_image; + last_image = image; + } else { + last_image->next=this_image; + this_image->previous=last_image; + this_image->scene=i; + last_image=this_image; + } + } + GetImageInfo(&image_info); image_info.file = of; - strcpy(image->filename, "bmp:test.bmp"); + strcpy(image->magick, dest); + image_info.adjoin=1; WriteImage(&image_info,image); + return 0; #endif } -static void psiconv_gen_image_mbm(FILE *of, psiconv_mbm_f f) +static int psiconv_gen_image_mbm(FILE *of, psiconv_mbm_f f, const char *dest) { +#if IMAGEMAGICK psiconv_paint_data_section section; - if (psiconv_list_length(f->sections) >= 1) { - section = psiconv_list_get(f->sections,0); - gen_paint_data_section(of,section); + MagickInfo *mi = GetMagickInfo(dest); + ImageInfo image_info; + Image *image = NULL; + Image *last_image = NULL; + Image *this_image; + int i; + + if ((psiconv_list_length(f->sections) < 1) || + ((psiconv_list_length(f->sections)) > 1 && ! (mi->adjoin))) +#endif + return -1; +#if IMAGEMAGICK + for (i = 0; i < psiconv_list_length(f->sections); i++) { + section = psiconv_list_get(f->sections,i); + this_image = get_paint_data_section(section); + if (! image) { + image = this_image; + last_image = image; + } else { + last_image->next=this_image; + this_image->previous=last_image; + this_image->scene=i; + last_image=this_image; + } } + + GetImageInfo(&image_info); + image_info.file = of; + strcpy(image->magick, dest); + image_info.adjoin=1; + WriteImage(&image_info,image); + return 0; +#endif } -static void psiconv_gen_image_sketch(FILE *of, psiconv_sketch_f f) +static void psiconv_gen_image_sketch(FILE *of, psiconv_sketch_f f, + const char *dest) { - gen_paint_data_section(of,f->sketch_sec->picture); +#if IMAGEMAGICK + ImageInfo image_info; + Image *image; + + image = get_paint_data_section(f->sketch_sec->picture); + GetImageInfo(&image_info); + image_info.file = of; + strcpy(image->magick, dest); + WriteImage(&image_info,image); +#endif } -void psiconv_gen_image(FILE * of, psiconv_file file) +static int psiconv_gen_image(FILE * of, const psiconv_file file, + const char *dest) { - if (file->type == psiconv_mbm_file) - psiconv_gen_image_mbm(of,(psiconv_mbm_f) file->file); - else if (file->type == psiconv_sketch_file) - psiconv_gen_image_sketch(of,(psiconv_sketch_f) file->file); + if (file->type == psiconv_mbm_file) + return psiconv_gen_image_mbm(of,(psiconv_mbm_f) file->file,dest); + if (file->type == psiconv_clipart_file) + return psiconv_gen_image_clipart(of,(psiconv_clipart_f) file->file,dest); + else if (file->type == psiconv_sketch_file) { + psiconv_gen_image_sketch(of,(psiconv_sketch_f) file->file,dest); + return 0; + } else + return -1; +} + +void init_image(void) +{ + struct psiconv_fileformat ff; +#if IMAGEMAGICK + MagickInfo *mi; + ff.output = psiconv_gen_image; + for (mi = GetMagickInfo(NULL); mi ; mi = mi->next) { + if (mi->encoder) { + ff.name = strdup(mi->tag); + ff.description = strdup(mi->description); + psiconv_list_add(fileformat_list,&ff); + } + } +#endif }