--- psiconv/trunk/lib/psiconv/generate_image.c 2003/12/02 19:47:47 176 +++ psiconv/tags/rel-0-9-9/lib/psiconv/generate_image.c 2014/10/29 09:17:54 357 @@ -1,7 +1,6 @@ /* - generate_image.c - Part of psiconv, a PSION 5 file formats converter - Copyright (c) 1999, 2000 Frodo Looijaard + Copyright (c) 1999-2014 Frodo Looijaard This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -24,22 +23,12 @@ #include "generate_routines.h" #include "error.h" #include "list.h" +#include "image.h" #ifdef DMALLOC #include #endif -typedef psiconv_list psiconv_pixel_bytes; /* psiconv_u8 */ - -typedef psiconv_list psiconv_pixel_ints; /* of psiconv_u32 */ - -typedef struct psiconv_pixel_float_s -{ - psiconv_u32 length; - float *red; - float *green; - float *blue; -} psiconv_pixel_floats_t; static int psiconv_collect_pixel_data(psiconv_pixel_ints *pixels, int xsize,int ysize, @@ -47,7 +36,7 @@ int colordepth,int color, int redbits,int greenbits,int bluebits, const psiconv_pixel_floats_t palet); -static int psiconv_pixel_data_to_bytes(const psiconv_config config, +static int psiconv_pixel_data_to_bytes(const psiconv_config config,int lev, psiconv_pixel_bytes *bytes, int xsize, int ysize, const psiconv_pixel_ints pixels, int colordepth); @@ -64,258 +53,8 @@ const psiconv_pixel_bytes plain_bytes, psiconv_pixel_bytes *encoded_bytes); -#define PALET_NONE_LEN 0 - -psiconv_pixel_floats_t palet_none = - { - PALET_NONE_LEN, - NULL, - NULL, - NULL - }; - -#define PALET_COLOR_4_LEN 16 -float palet_color_4_red[PALET_COLOR_4_LEN] = - { 0x00/256.0, 0x55/256.0, 0x80/256.0, 0x80/256.0, /* 0x00 */ - 0x00/256.0, 0xff/256.0, 0x00/256.0, 0xff/256.0, /* 0x04 */ - 0xff/256.0, 0x00/256.0, 0x00/256.0, 0x80/256.0, /* 0x08 */ - 0x00/256.0, 0x00/256.0, 0xaa/256.0, 0xff/256.0 /* 0x0c */ - }; - -float palet_color_4_green[PALET_COLOR_4_LEN] = - { 0x00/256.0, 0x55/256.0, 0x00/256.0, 0x80/256.0, /* 0x00 */ - 0x80/256.0, 0x00/256.0, 0xff/256.0, 0xff/256.0, /* 0x04 */ - 0x00/256.0, 0xff/256.0, 0xff/256.0, 0x00/256.0, /* 0x08 */ - 0x00/256.0, 0x80/256.0, 0xaa/256.0, 0xff/256.0 /* 0x0c */ - }; - -float palet_color_4_blue[PALET_COLOR_4_LEN] = - { 0x00/256.0, 0x55/256.0, 0x00/256.0, 0x00/256.0, /* 0x00 */ - 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x04 */ - 0xff/256.0, 0x00/256.0, 0xff/256.0, 0x80/256.0, /* 0x08 */ - 0x80/256.0, 0x80/256.0, 0xaa/256.0, 0xff/256.0 /* 0x0c */ - }; - -psiconv_pixel_floats_t palet_color_4 = - { - PALET_COLOR_4_LEN, - palet_color_4_red, - palet_color_4_green, - palet_color_4_blue, - }; - -#define PALET_COLOR_8_LEN 256 -float palet_color_8_red[PALET_COLOR_8_LEN] = - { 0x00/256.0, 0x33/256.0, 0x66/256.0, 0x99/256.0, /* 0x00 */ - 0xcc/256.0, 0xff/256.0, 0x00/256.0, 0x33/256.0, /* 0x04 */ - 0x66/256.0, 0x99/256.0, 0xcc/256.0, 0xff/256.0, /* 0x08 */ - 0x00/256.0, 0x33/256.0, 0x66/256.0, 0x99/256.0, /* 0x0c */ - 0xcc/256.0, 0xff/256.0, 0x00/256.0, 0x33/256.0, /* 0x10 */ - 0x66/256.0, 0x99/256.0, 0xcc/256.0, 0xff/256.0, /* 0x14 */ - 0x00/256.0, 0x33/256.0, 0x66/256.0, 0x99/256.0, /* 0x18 */ - 0xcc/256.0, 0xff/256.0, 0x00/256.0, 0x33/256.0, /* 0x1c */ - 0x66/256.0, 0x99/256.0, 0xcc/256.0, 0xff/256.0, /* 0x20 */ - 0x00/256.0, 0x33/256.0, 0x66/256.0, 0x99/256.0, /* 0x24 */ - 0xcc/256.0, 0xff/256.0, 0x00/256.0, 0x33/256.0, /* 0x28 */ - 0x66/256.0, 0x99/256.0, 0xcc/256.0, 0xff/256.0, /* 0x2c */ - 0x00/256.0, 0x33/256.0, 0x66/256.0, 0x99/256.0, /* 0x30 */ - 0xcc/256.0, 0xff/256.0, 0x00/256.0, 0x33/256.0, /* 0x34 */ - 0x66/256.0, 0x99/256.0, 0xcc/256.0, 0xff/256.0, /* 0x38 */ - 0x00/256.0, 0x33/256.0, 0x66/256.0, 0x99/256.0, /* 0x3c */ - 0xcc/256.0, 0xff/256.0, 0x00/256.0, 0x33/256.0, /* 0x40 */ - 0x66/256.0, 0x99/256.0, 0xcc/256.0, 0xff/256.0, /* 0x44 */ - 0x00/256.0, 0x33/256.0, 0x66/256.0, 0x99/256.0, /* 0x48 */ - 0xcc/256.0, 0xff/256.0, 0x00/256.0, 0x33/256.0, /* 0x4c */ - 0x66/256.0, 0x99/256.0, 0xcc/256.0, 0xff/256.0, /* 0x50 */ - 0x00/256.0, 0x33/256.0, 0x66/256.0, 0x99/256.0, /* 0x54 */ - 0xcc/256.0, 0xff/256.0, 0x00/256.0, 0x33/256.0, /* 0x58 */ - 0x66/256.0, 0x99/256.0, 0xcc/256.0, 0xff/256.0, /* 0x5c */ - 0x00/256.0, 0x33/256.0, 0x66/256.0, 0x99/256.0, /* 0x60 */ - 0xcc/256.0, 0xff/256.0, 0x00/256.0, 0x33/256.0, /* 0x64 */ - 0x66/256.0, 0x99/256.0, 0xcc/256.0, 0xff/256.0, /* 0x68 */ - 0x11/256.0, 0x22/256.0, 0x44/256.0, 0x55/256.0, /* 0x6c */ - 0x77/256.0, 0x11/256.0, 0x22/256.0, 0x44/256.0, /* 0x70 */ - 0x55/256.0, 0x77/256.0, 0x00/256.0, 0x00/256.0, /* 0x74 */ - 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x78 */ - 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x7c */ - 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x80 */ - 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x84 */ - 0x00/256.0, 0x00/256.0, 0x88/256.0, 0xaa/256.0, /* 0x88 */ - 0xbb/256.0, 0xdd/256.0, 0xee/256.0, 0x88/256.0, /* 0x8c */ - 0xaa/256.0, 0xbb/256.0, 0xdd/256.0, 0xee/256.0, /* 0x90 */ - 0x00/256.0, 0x33/256.0, 0x66/256.0, 0x99/256.0, /* 0x94 */ - 0xcc/256.0, 0xff/256.0, 0x00/256.0, 0x33/256.0, /* 0x98 */ - 0x66/256.0, 0x99/256.0, 0xcc/256.0, 0xff/256.0, /* 0x9c */ - 0x00/256.0, 0x33/256.0, 0x66/256.0, 0x99/256.0, /* 0xa0 */ - 0xcc/256.0, 0xff/256.0, 0x00/256.0, 0x33/256.0, /* 0xa4 */ - 0x66/256.0, 0x99/256.0, 0xcc/256.0, 0xff/256.0, /* 0xa8 */ - 0x00/256.0, 0x33/256.0, 0x66/256.0, 0x99/256.0, /* 0xac */ - 0xcc/256.0, 0xff/256.0, 0x00/256.0, 0x33/256.0, /* 0xb0 */ - 0x66/256.0, 0x99/256.0, 0xcc/256.0, 0xff/256.0, /* 0xb4 */ - 0x00/256.0, 0x33/256.0, 0x66/256.0, 0x99/256.0, /* 0xb8 */ - 0xcc/256.0, 0xff/256.0, 0x00/256.0, 0x33/256.0, /* 0xbc */ - 0x66/256.0, 0x99/256.0, 0xcc/256.0, 0xff/256.0, /* 0xc0 */ - 0x00/256.0, 0x33/256.0, 0x66/256.0, 0x99/256.0, /* 0xc4 */ - 0xcc/256.0, 0xff/256.0, 0x00/256.0, 0x33/256.0, /* 0xc8 */ - 0x66/256.0, 0x99/256.0, 0xcc/256.0, 0xff/256.0, /* 0xcc */ - 0x00/256.0, 0x33/256.0, 0x66/256.0, 0x99/256.0, /* 0xd0 */ - 0xcc/256.0, 0xff/256.0, 0x00/256.0, 0x33/256.0, /* 0xd4 */ - 0x66/256.0, 0x99/256.0, 0xcc/256.0, 0xff/256.0, /* 0xd8 */ - 0x00/256.0, 0x33/256.0, 0x66/256.0, 0x99/256.0, /* 0xdc */ - 0xcc/256.0, 0xff/256.0, 0x00/256.0, 0x33/256.0, /* 0xe0 */ - 0x66/256.0, 0x99/256.0, 0xcc/256.0, 0xff/256.0, /* 0xe4 */ - 0x00/256.0, 0x33/256.0, 0x66/256.0, 0x99/256.0, /* 0xe8 */ - 0xcc/256.0, 0xff/256.0, 0x00/256.0, 0x33/256.0, /* 0xec */ - 0x66/256.0, 0x99/256.0, 0xcc/256.0, 0xff/256.0, /* 0xf0 */ - 0x00/256.0, 0x33/256.0, 0x66/256.0, 0x99/256.0, /* 0xf4 */ - 0xcc/256.0, 0xff/256.0, 0x00/256.0, 0x33/256.0, /* 0xf8 */ - 0x66/256.0, 0x99/256.0, 0xcc/256.0, 0xff/256.0 /* 0xfc */ - }; - -float palet_color_8_green[PALET_COLOR_8_LEN] = - { 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x00 */ - 0x00/256.0, 0x00/256.0, 0x33/256.0, 0x33/256.0, /* 0x04 */ - 0x33/256.0, 0x33/256.0, 0x33/256.0, 0x33/256.0, /* 0x08 */ - 0x66/256.0, 0x66/256.0, 0x66/256.0, 0x66/256.0, /* 0x0c */ - 0x66/256.0, 0x66/256.0, 0x99/256.0, 0x99/256.0, /* 0x10 */ - 0x99/256.0, 0x99/256.0, 0x99/256.0, 0x99/256.0, /* 0x14 */ - 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, /* 0x18 */ - 0xcc/256.0, 0xcc/256.0, 0xff/256.0, 0xff/256.0, /* 0x1c */ - 0xff/256.0, 0xff/256.0, 0xff/256.0, 0xff/256.0, /* 0x20 */ - 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x24 */ - 0x00/256.0, 0x00/256.0, 0x33/256.0, 0x33/256.0, /* 0x28 */ - 0x33/256.0, 0x33/256.0, 0x33/256.0, 0x33/256.0, /* 0x2c */ - 0x66/256.0, 0x66/256.0, 0x66/256.0, 0x66/256.0, /* 0x30 */ - 0x66/256.0, 0x66/256.0, 0x99/256.0, 0x99/256.0, /* 0x34 */ - 0x99/256.0, 0x99/256.0, 0x99/256.0, 0x99/256.0, /* 0x38 */ - 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, /* 0x3c */ - 0xcc/256.0, 0xcc/256.0, 0xff/256.0, 0xff/256.0, /* 0x40 */ - 0xff/256.0, 0xff/256.0, 0xff/256.0, 0xff/256.0, /* 0x44 */ - 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x48 */ - 0x00/256.0, 0x00/256.0, 0x33/256.0, 0x33/256.0, /* 0x4c */ - 0x33/256.0, 0x33/256.0, 0x33/256.0, 0x33/256.0, /* 0x50 */ - 0x66/256.0, 0x66/256.0, 0x66/256.0, 0x66/256.0, /* 0x54 */ - 0x66/256.0, 0x66/256.0, 0x99/256.0, 0x99/256.0, /* 0x58 */ - 0x99/256.0, 0x99/256.0, 0x99/256.0, 0x99/256.0, /* 0x5c */ - 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, /* 0x60 */ - 0xcc/256.0, 0xcc/256.0, 0xff/256.0, 0xff/256.0, /* 0x64 */ - 0xff/256.0, 0xff/256.0, 0xff/256.0, 0xff/256.0, /* 0x68 */ - 0x11/256.0, 0x22/256.0, 0x44/256.0, 0x55/256.0, /* 0x6c */ - 0x77/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x70 */ - 0x00/256.0, 0x00/256.0, 0x11/256.0, 0x22/256.0, /* 0x74 */ - 0x44/256.0, 0x55/256.0, 0x77/256.0, 0x00/256.0, /* 0x78 */ - 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x7c */ - 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x80 */ - 0x00/256.0, 0x88/256.0, 0xaa/256.0, 0xbb/256.0, /* 0x84 */ - 0xdd/256.0, 0xee/256.0, 0x00/256.0, 0x00/256.0, /* 0x88 */ - 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x88/256.0, /* 0x8c */ - 0xaa/256.0, 0xbb/256.0, 0xdd/256.0, 0xee/256.0, /* 0x90 */ - 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x94 */ - 0x00/256.0, 0x00/256.0, 0x33/256.0, 0x33/256.0, /* 0x98 */ - 0x33/256.0, 0x33/256.0, 0x33/256.0, 0x33/256.0, /* 0x9c */ - 0x66/256.0, 0x66/256.0, 0x66/256.0, 0x66/256.0, /* 0xa0 */ - 0x66/256.0, 0x66/256.0, 0x99/256.0, 0x99/256.0, /* 0xa4 */ - 0x99/256.0, 0x99/256.0, 0x99/256.0, 0x99/256.0, /* 0xa8 */ - 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, /* 0xac */ - 0xcc/256.0, 0xcc/256.0, 0xff/256.0, 0xff/256.0, /* 0xb0 */ - 0xff/256.0, 0xff/256.0, 0xff/256.0, 0xff/256.0, /* 0xb4 */ - 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0xb8 */ - 0x00/256.0, 0x00/256.0, 0x33/256.0, 0x33/256.0, /* 0xbc */ - 0x33/256.0, 0x33/256.0, 0x33/256.0, 0x33/256.0, /* 0xc0 */ - 0x66/256.0, 0x66/256.0, 0x66/256.0, 0x66/256.0, /* 0xc4 */ - 0x66/256.0, 0x66/256.0, 0x99/256.0, 0x99/256.0, /* 0xc8 */ - 0x99/256.0, 0x99/256.0, 0x99/256.0, 0x99/256.0, /* 0xcc */ - 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, /* 0xd0 */ - 0xcc/256.0, 0xcc/256.0, 0xff/256.0, 0xff/256.0, /* 0xd4 */ - 0xff/256.0, 0xff/256.0, 0xff/256.0, 0xff/256.0, /* 0xd8 */ - 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0xdc */ - 0x00/256.0, 0x00/256.0, 0x33/256.0, 0x33/256.0, /* 0xe0 */ - 0x33/256.0, 0x33/256.0, 0x33/256.0, 0x33/256.0, /* 0xe4 */ - 0x66/256.0, 0x66/256.0, 0x66/256.0, 0x66/256.0, /* 0xe8 */ - 0x66/256.0, 0x66/256.0, 0x99/256.0, 0x99/256.0, /* 0xec */ - 0x99/256.0, 0x99/256.0, 0x99/256.0, 0x99/256.0, /* 0xf0 */ - 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, /* 0xf4 */ - 0xcc/256.0, 0xcc/256.0, 0xff/256.0, 0xff/256.0, /* 0xf8 */ - 0xff/256.0, 0xff/256.0, 0xff/256.0, 0xff/256.0, /* 0xfc */ - }; - -float palet_color_8_blue[PALET_COLOR_8_LEN] = - { 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x00 */ - 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x04 */ - 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x08 */ - 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x0c */ - 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x10 */ - 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x14 */ - 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x18 */ - 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x1c */ - 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x20 */ - 0x33/256.0, 0x33/256.0, 0x33/256.0, 0x33/256.0, /* 0x24 */ - 0x33/256.0, 0x33/256.0, 0x33/256.0, 0x33/256.0, /* 0x28 */ - 0x33/256.0, 0x33/256.0, 0x33/256.0, 0x33/256.0, /* 0x2c */ - 0x33/256.0, 0x33/256.0, 0x33/256.0, 0x33/256.0, /* 0x30 */ - 0x33/256.0, 0x33/256.0, 0x33/256.0, 0x33/256.0, /* 0x34 */ - 0x33/256.0, 0x33/256.0, 0x33/256.0, 0x33/256.0, /* 0x38 */ - 0x33/256.0, 0x33/256.0, 0x33/256.0, 0x33/256.0, /* 0x3c */ - 0x33/256.0, 0x33/256.0, 0x33/256.0, 0x33/256.0, /* 0x40 */ - 0x33/256.0, 0x33/256.0, 0x33/256.0, 0x33/256.0, /* 0x44 */ - 0x66/256.0, 0x66/256.0, 0x66/256.0, 0x66/256.0, /* 0x48 */ - 0x66/256.0, 0x66/256.0, 0x66/256.0, 0x66/256.0, /* 0x4c */ - 0x66/256.0, 0x66/256.0, 0x66/256.0, 0x66/256.0, /* 0x50 */ - 0x66/256.0, 0x66/256.0, 0x66/256.0, 0x66/256.0, /* 0x54 */ - 0x66/256.0, 0x66/256.0, 0x66/256.0, 0x66/256.0, /* 0x58 */ - 0x66/256.0, 0x66/256.0, 0x66/256.0, 0x66/256.0, /* 0x5c */ - 0x66/256.0, 0x66/256.0, 0x66/256.0, 0x66/256.0, /* 0x60 */ - 0x66/256.0, 0x66/256.0, 0x66/256.0, 0x66/256.0, /* 0x64 */ - 0x66/256.0, 0x66/256.0, 0x66/256.0, 0x66/256.0, /* 0x68 */ - 0x11/256.0, 0x22/256.0, 0x44/256.0, 0x55/256.0, /* 0x6c */ - 0x77/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x70 */ - 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x74 */ - 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x11/256.0, /* 0x78 */ - 0x22/256.0, 0x44/256.0, 0x55/256.0, 0x77/256.0, /* 0x7c */ - 0x88/256.0, 0xaa/256.0, 0xbb/256.0, 0xdd/256.0, /* 0x80 */ - 0xee/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x84 */ - 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x88 */ - 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x88/256.0, /* 0x8c */ - 0xaa/256.0, 0xbb/256.0, 0xdd/256.0, 0xee/256.0, /* 0x90 */ - 0x99/256.0, 0x99/256.0, 0x99/256.0, 0x99/256.0, /* 0x94 */ - 0x99/256.0, 0x99/256.0, 0x99/256.0, 0x99/256.0, /* 0x98 */ - 0x99/256.0, 0x99/256.0, 0x99/256.0, 0x99/256.0, /* 0x9c */ - 0x99/256.0, 0x99/256.0, 0x99/256.0, 0x99/256.0, /* 0xa0 */ - 0x99/256.0, 0x99/256.0, 0x99/256.0, 0x99/256.0, /* 0xa4 */ - 0x99/256.0, 0x99/256.0, 0x99/256.0, 0x99/256.0, /* 0xa8 */ - 0x99/256.0, 0x99/256.0, 0x99/256.0, 0x99/256.0, /* 0xac */ - 0x99/256.0, 0x99/256.0, 0x99/256.0, 0x99/256.0, /* 0xb0 */ - 0x99/256.0, 0x99/256.0, 0x99/256.0, 0x99/256.0, /* 0xb4 */ - 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, /* 0xb8 */ - 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, /* 0xbc */ - 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, /* 0xc0 */ - 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, /* 0xc4 */ - 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, /* 0xc8 */ - 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, /* 0xcc */ - 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, /* 0xd0 */ - 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, /* 0xd4 */ - 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, /* 0xd8 */ - 0xff/256.0, 0xff/256.0, 0xff/256.0, 0xff/256.0, /* 0xdc */ - 0xff/256.0, 0xff/256.0, 0xff/256.0, 0xff/256.0, /* 0xe0 */ - 0xff/256.0, 0xff/256.0, 0xff/256.0, 0xff/256.0, /* 0xe4 */ - 0xff/256.0, 0xff/256.0, 0xff/256.0, 0xff/256.0, /* 0xe8 */ - 0xff/256.0, 0xff/256.0, 0xff/256.0, 0xff/256.0, /* 0xec */ - 0xff/256.0, 0xff/256.0, 0xff/256.0, 0xff/256.0, /* 0xf0 */ - 0xff/256.0, 0xff/256.0, 0xff/256.0, 0xff/256.0, /* 0xf4 */ - 0xff/256.0, 0xff/256.0, 0xff/256.0, 0xff/256.0, /* 0xf8 */ - 0xff/256.0, 0xff/256.0, 0xff/256.0, 0xff/256.0, /* 0xfc */ - }; - -psiconv_pixel_floats_t palet_color_8 = - { - PALET_COLOR_8_LEN, - palet_color_8_red, - palet_color_8_green, - palet_color_8_blue, - }; - int psiconv_write_paint_data_section(const psiconv_config config, - psiconv_buffer buf, + psiconv_buffer buf, int lev, const psiconv_paint_data_section value, int is_clipart) { @@ -325,12 +64,14 @@ psiconv_list bytes,bytes_rle; psiconv_u8 *byteptr,encoding; + psiconv_progress(config,lev,0,"Writing paint data section"); + /* First, we check whether we can cope with the current configuration. If not, we stop at once */ if ((config->colordepth != 2) && (config->colordepth != 4) && (config->colordepth != 8) && (config->colordepth != 12) && (config->colordepth != 16) && (config->colordepth != 24)) { - psiconv_warn(config,0,psiconv_buffer_length(buf), + psiconv_error(config,lev,0, "Unsupported color depth (%d); try 2, 4, 8, 16 or 24", config->colordepth); res = -PSICONV_E_GENERATE; @@ -340,7 +81,7 @@ if ((config->color) && (config->bluebits || config->redbits || config->greenbits) && (config->bluebits+config->redbits+config->greenbits!=config->colordepth)) { - psiconv_warn(config,0,psiconv_buffer_length(buf), + psiconv_error(config,lev,0, "Sum of red (%d), green (%d) and blue (%d) bits should be " "equal to the color depth (%d)", config->redbits,config->greenbits,config->bluebits, @@ -352,7 +93,7 @@ if (config->color && !(config->redbits || config->greenbits || config->bluebits) && (config->colordepth != 4) && (config->colordepth != 8)) { - psiconv_warn(config,0,psiconv_buffer_length(buf), + psiconv_error(config,lev,0, "Current color depth (%d) has no palet associated with it", config->colordepth); res = -PSICONV_E_GENERATE; @@ -360,12 +101,12 @@ } if (config->color || (config->colordepth != 2)) - psiconv_warn(config,0,psiconv_buffer_length(buf), + psiconv_warn(config,lev,0, "All image types except 2-bit greyscale are experimental!"); if (!value) { - psiconv_warn(config,0,psiconv_buffer_length(buf),"Null paint data section"); + psiconv_error(config,lev,0,"Null paint data section"); res = -PSICONV_E_GENERATE; goto ERROR1; } @@ -375,25 +116,30 @@ floats.blue = value->blue; floats.length = value->xsize * value->ysize; - palet = palet_none; - if ((config->color) && (config->redbits == 0) && (config->greenbits == 0) &&\ + palet = psiconv_palet_none; + if ((config->color) && (config->redbits == 0) && (config->greenbits == 0) && (config->bluebits == 0)) switch (config->colordepth) { - case 4: palet = palet_color_4; break; - case 8: palet = palet_color_8; break; - default: palet = palet_none; break; + case 4: palet = psiconv_palet_color_4; break; + case 8: palet = psiconv_palet_color_8; break; + default: palet = psiconv_palet_none; break; } if ((res = psiconv_collect_pixel_data(&ints,value->xsize, value->ysize,floats, config->colordepth,config->color, config->redbits,config->greenbits, - config->bluebits,palet))) + config->bluebits,palet))) { + psiconv_error(config,lev,0,"Error collecting pixel data"); goto ERROR1; + } - if ((res = psiconv_pixel_data_to_bytes(config,&bytes,value->xsize,value->ysize, - ints,config->colordepth))) + if ((res = psiconv_pixel_data_to_bytes(config,lev+1,&bytes,value->xsize, + value->ysize,ints, + config->colordepth))) { + psiconv_error(config,lev,0,"Error translating pixel data to bytes"); goto ERROR2; + } switch (config->colordepth) { @@ -401,23 +147,31 @@ case 4: case 8: encoding = 0x01; - if ((res = psiconv_encode_rle8(config,bytes,&bytes_rle))) + if ((res = psiconv_encode_rle8(config,bytes,&bytes_rle))) { + psiconv_error(config,lev,0,"Error encoding RLE8"); goto ERROR3; + } break; case 12: encoding = 0x02; - if ((res = psiconv_encode_rle12(config,bytes,&bytes_rle))) + if ((res = psiconv_encode_rle12(config,bytes,&bytes_rle))) { + psiconv_error(config,lev,0,"Error encoding RLE12"); goto ERROR3; + } break; case 16: encoding = 0x03; - if ((res = psiconv_encode_rle16(config,bytes,&bytes_rle))) + if ((res = psiconv_encode_rle16(config,bytes,&bytes_rle))) { + psiconv_error(config,lev,0,"Error encoding RLE16"); goto ERROR3; + } break; case 24: encoding = 0x04; - if ((res = psiconv_encode_rle24(config,bytes,&bytes_rle))) + if ((res = psiconv_encode_rle24(config,bytes,&bytes_rle))) { + psiconv_error(config,lev,0,"Error encoding RLE24"); goto ERROR3; + } break; default: encoding = 0x00; @@ -432,38 +186,38 @@ } } - if ((res = psiconv_write_u32(config,buf, + if ((res = psiconv_write_u32(config,buf,lev+1, 0x28+psiconv_list_length(bytes)))) goto ERROR3; - if ((res = psiconv_write_u32(config,buf,0x28))) + if ((res = psiconv_write_u32(config,buf,lev+1,0x28))) goto ERROR3; - if ((res = psiconv_write_u32(config,buf,value->xsize))) + if ((res = psiconv_write_u32(config,buf,lev+1,value->xsize))) goto ERROR3; - if ((res = psiconv_write_u32(config,buf,value->ysize))) + if ((res = psiconv_write_u32(config,buf,lev+1,value->ysize))) goto ERROR3; - if ((res = psiconv_write_length(config,buf,value->pic_xsize))) + if ((res = psiconv_write_length(config,buf,lev+1,value->pic_xsize))) goto ERROR3; - if ((res = psiconv_write_length(config,buf,value->pic_ysize))) + if ((res = psiconv_write_length(config,buf,lev+1,value->pic_ysize))) goto ERROR3; colordepth = config->colordepth; - if ((res = psiconv_write_u32(config,buf,colordepth))) + if ((res = psiconv_write_u32(config,buf,lev+1,colordepth))) goto ERROR3; - if ((res = psiconv_write_u32(config,buf,(config->color?1:0)))) + if ((res = psiconv_write_u32(config,buf,lev+1,(config->color?1:0)))) goto ERROR3; - if ((res = psiconv_write_u32(config,buf,0))) + if ((res = psiconv_write_u32(config,buf,lev+1,0))) goto ERROR3; - if ((res = psiconv_write_u32(config,buf,encoding))) + if ((res = psiconv_write_u32(config,buf,lev+1,encoding))) goto ERROR3; if (is_clipart) { - if ((res = psiconv_write_u32(config,buf,0xffffffff))) + if ((res = psiconv_write_u32(config,buf,lev+1,0xffffffff))) goto ERROR3; - if ((res = psiconv_write_u32(config,buf,0x00000044))) + if ((res = psiconv_write_u32(config,buf,lev+1,0x00000044))) goto ERROR3; } for (i = 0; i < psiconv_list_length(bytes); i++) { if (!(byteptr = psiconv_list_get(bytes,i))) goto ERROR3; - if ((res = psiconv_write_u8(config,buf,*byteptr))) + if ((res = psiconv_write_u8(config,buf,lev+1,*byteptr))) goto ERROR3; } @@ -472,6 +226,10 @@ ERROR2: psiconv_list_free(ints); ERROR1: + if (res) + psiconv_error(config,lev,0,"Writing of paint data section failed"); + else + psiconv_progress(config,lev,0,"End of paint data section"); return res; } @@ -508,7 +266,7 @@ << bluebits) + ((psiconv_u32) (p_blue * (1 << bluebits) + 0.5)); else - pixel = (p_red + p_green + p_blue)/3.0 * (1 << colordepth); + pixel = (0.212671 * p_red + 0.715160 * p_green + 0.072169 * p_blue) * ((1 << colordepth) * 0.999); } else { dist = 4; /* Max distance is 3, so this is safe */ pixel = -1; @@ -534,7 +292,7 @@ return res; } -int psiconv_pixel_data_to_bytes(const psiconv_config config, +int psiconv_pixel_data_to_bytes(const psiconv_config config,int lev, psiconv_pixel_bytes *bytes, int xsize, int ysize, const psiconv_pixel_ints pixels, int colordepth) @@ -549,17 +307,17 @@ if (!bytes) { - psiconv_warn(config,0,0,"NULL pixel data"); + psiconv_error(config,lev,0,"NULL pixel data"); res = -PSICONV_E_GENERATE; goto ERROR1; } if (!pixels) { - psiconv_warn(config,0,0,"NULL pixel data"); + psiconv_error(config,lev,0,"NULL pixel data"); res = -PSICONV_E_GENERATE; goto ERROR1; } if (psiconv_list_length(pixels) != xsize * ysize) { - psiconv_warn(config,0,0,"Pixel number is not correct"); + psiconv_error(config,lev,0,"Pixel number is not correct"); res = -PSICONV_E_GENERATE; goto ERROR1; } @@ -576,7 +334,7 @@ outputbytenr = 0; for (x = 0; x < xsize; x++) { if (!(pixelptr = psiconv_list_get(pixels,y*xsize+x))) { - psiconv_warn(config,0,0,"Massive internal corruption"); + psiconv_error(config,lev,0,"Data structure corruption"); res = -PSICONV_E_NOMEM; goto ERROR2; } @@ -657,9 +415,9 @@ goto ERROR2; i +=2; } else if (*next == *entry) { - len = 0; + len = 1; while ((*next == *entry) && - (i+len + 1 < psiconv_list_length(plain_bytes)) && + (i+len + 2 < psiconv_list_length(plain_bytes)) && len < 0x80) { len ++; if (!(next = psiconv_list_get(plain_bytes,i+len))) { @@ -1079,116 +837,126 @@ int psiconv_write_sketch_section(const psiconv_config config, - psiconv_buffer buf, + psiconv_buffer buf, int lev, const psiconv_sketch_section value) { int res; + psiconv_progress(config,lev,0,"Writing sketch section"); if (!value) { - psiconv_warn(config,0,0,"NULL sketch section"); + psiconv_error(config,lev,0,"NULL sketch section"); res = -PSICONV_E_GENERATE; goto ERROR1; } - if ((res = psiconv_write_u16(config,buf,value->displayed_xsize))) + if ((res = psiconv_write_u16(config,buf,lev+1,value->displayed_xsize))) goto ERROR1; - if ((res = psiconv_write_u16(config,buf,value->displayed_ysize))) + if ((res = psiconv_write_u16(config,buf,lev+1,value->displayed_ysize))) goto ERROR1; - if ((res = psiconv_write_u16(config,buf,value->picture_data_x_offset))) + if ((res = psiconv_write_u16(config,buf,lev+1,value->picture_data_x_offset))) goto ERROR1; - if ((res = psiconv_write_u16(config,buf,value->picture_data_y_offset))) + if ((res = psiconv_write_u16(config,buf,lev+1,value->picture_data_y_offset))) goto ERROR1; - if ((res = psiconv_write_u16(config,buf,value->displayed_size_x_offset))) + if ((res = psiconv_write_u16(config,buf,lev+1,value->displayed_size_x_offset))) goto ERROR1; - if ((res = psiconv_write_u16(config,buf,value->displayed_size_y_offset))) + if ((res = psiconv_write_u16(config,buf,lev+1,value->displayed_size_y_offset))) goto ERROR1; - if ((res = psiconv_write_u16(config,buf,value->form_xsize))) + if ((res = psiconv_write_u16(config,buf,lev+1,value->form_xsize))) goto ERROR1; - if ((res = psiconv_write_u16(config,buf,value->form_ysize))) + if ((res = psiconv_write_u16(config,buf,lev+1,value->form_ysize))) goto ERROR1; - if ((res = psiconv_write_u16(config,buf,0x0000))) + if ((res = psiconv_write_u16(config,buf,lev+1,0x0000))) goto ERROR1; - if ((res = psiconv_write_paint_data_section(config,buf,value->picture,0))) + if ((res = psiconv_write_paint_data_section(config,buf,lev+1,value->picture,0))) goto ERROR1; - if ((res = psiconv_write_u16(config,buf,value->magnification_x * 0x03e8))) + if ((res = psiconv_write_u16(config,buf,lev+1,value->magnification_x * 0x03e8))) goto ERROR1; - if ((res = psiconv_write_u16(config,buf,value->magnification_y * 0x03e8))) + if ((res = psiconv_write_u16(config,buf,lev+1,value->magnification_y * 0x03e8))) goto ERROR1; - if ((res = psiconv_write_u32(config,buf,value->cut_left * 0x0c * + if ((res = psiconv_write_u32(config,buf,lev+1,value->cut_left * 0x0c * value->displayed_xsize))) goto ERROR1; - if ((res = psiconv_write_u32(config,buf,value->cut_right * 0x0c * + if ((res = psiconv_write_u32(config,buf,lev+1,value->cut_right * 0x0c * value->displayed_xsize))) goto ERROR1; - if ((res = psiconv_write_u32(config,buf,value->cut_top * 0x0c * + if ((res = psiconv_write_u32(config,buf,lev+1,value->cut_top * 0x0c * value->displayed_ysize))) goto ERROR1; - if ((res = psiconv_write_u32(config,buf,value->cut_bottom * 0x0c * + if ((res = psiconv_write_u32(config,buf,lev+1,value->cut_bottom * 0x0c * value->displayed_ysize))) goto ERROR1; ERROR1: + if (res) + psiconv_error(config,lev,0,"Writing of sketch section failed"); + else + psiconv_progress(config,lev,0,"End of sketch section"); return res; } int psiconv_write_clipart_section(const psiconv_config config, - psiconv_buffer buf, + psiconv_buffer buf, int lev, const psiconv_clipart_section value) { int res; - + psiconv_progress(config,lev,0,"Writing clipart section"); if (!value) { - psiconv_warn(config,0,psiconv_buffer_length(buf), - "NULL Clipart Section"); + psiconv_error(config,lev,0, "NULL Clipart Section"); res = -PSICONV_E_GENERATE; goto ERROR; } - if ((res = psiconv_write_u32(config,buf,PSICONV_ID_CLIPART_ITEM))) + if ((res = psiconv_write_u32(config,buf,lev+1,PSICONV_ID_CLIPART_ITEM))) goto ERROR; - if ((res = psiconv_write_u32(config,buf,0x00000002))) + if ((res = psiconv_write_u32(config,buf,lev+1,0x00000002))) goto ERROR; - if ((res = psiconv_write_u32(config,buf,0x00000000))) + if ((res = psiconv_write_u32(config,buf,lev+1,0x00000000))) goto ERROR; - if ((res = psiconv_write_u32(config,buf,0x00000000))) + if ((res = psiconv_write_u32(config,buf,lev+1,0x00000000))) goto ERROR; - if ((res = psiconv_write_u32(config,buf,0x0000000C))) + if ((res = psiconv_write_u32(config,buf,lev+1,0x0000000C))) goto ERROR; - if ((res = psiconv_write_paint_data_section(config,buf,value->picture,1))) + if ((res = psiconv_write_paint_data_section(config,buf,lev+1,value->picture,1))) goto ERROR; ERROR: + if (res) + psiconv_error(config,lev,0,"Writing of clipart section failed"); + else + psiconv_progress(config,lev,0,"End of clipart section"); return res; } int psiconv_write_jumptable_section(const psiconv_config config, - psiconv_buffer buf, + psiconv_buffer buf, int lev, const psiconv_jumptable_section value) { int res,i; psiconv_u32 *offset_ptr; + psiconv_progress(config,lev,0,"Writing jumptable section"); if (!value) { - psiconv_warn(config,0,psiconv_buffer_length(buf), - "NULL Jumptable Section"); + psiconv_error(config,lev,0,"NULL Jumptable Section"); res = -PSICONV_E_GENERATE; goto ERROR; } - if ((res = psiconv_write_u32(config,buf,psiconv_list_length(value)))) + if ((res = psiconv_write_u32(config,buf,lev+1,psiconv_list_length(value)))) goto ERROR; for (i = 0; i < psiconv_list_length(value); i++) { if (!(offset_ptr = psiconv_list_get(value,i))) { - psiconv_warn(config,0,psiconv_buffer_length(buf), - "Massive memory corruption"); + psiconv_error(config,lev,0,"Massive memory corruption"); res = -PSICONV_E_NOMEM; goto ERROR; } - if ((res = psiconv_write_offset(config,buf,*offset_ptr))) + if ((res = psiconv_write_offset(config,buf,lev+1,*offset_ptr))) goto ERROR; } ERROR: + if (res) + psiconv_error(config,lev,0,"Writing of jumptable section failed"); + else + psiconv_progress(config,lev,0,"End of jumptable section"); return res; } -