--- psiconv/trunk/lib/psiconv/parse_image.c 2003/12/13 18:23:16 179 +++ psiconv/trunk/lib/psiconv/parse_image.c 2004/02/25 20:56:43 230 @@ -1,6 +1,6 @@ /* parse_image.c - Part of psiconv, a PSION 5 file formats converter - Copyright (c) 1999, 2000 Frodo Looijaard + Copyright (c) 1999-2004 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 @@ -30,6 +30,9 @@ #include #endif +/* Extreme debugging info */ +#undef LOUD + static int psiconv_decode_rle8 (const psiconv_config config, int lev, psiconv_u32 off, const psiconv_pixel_bytes encoded, @@ -109,7 +112,7 @@ ERROR2: psiconv_list_free(*result); ERROR1: - psiconv_warn(config,lev+1,off,"Reading of Jumptable Section failed"); + psiconv_error(config,lev+1,off,"Reading of Jumptable Section failed"); if (length) *length = 0; if (!res) @@ -153,7 +156,7 @@ if (res) goto ERROR3; if (offset != 0x28) { - psiconv_warn(config,lev+2,off+len, + psiconv_error(config,lev+2,off+len, "Paint data section data offset has unexpected value"); psiconv_debug(config,lev+2,off+len, "Data offset: read %08x, expected %08x",offset,0x28); @@ -279,9 +282,11 @@ psiconv_progress(config,lev+2,off+len,"Going to read the pixel data"); for (i = 0; i < datasize; i++) { byte = psiconv_read_u8(config,buf,lev+2,off+len+i,&res); +#ifdef LOUD psiconv_debug(config,lev+2,off+len+i, "Pixel byte %04x of %04x has value %02x", i,datasize,byte); +#endif if (res) goto ERROR3; psiconv_list_add(bytes,&byte); @@ -362,7 +367,7 @@ ERROR2: free(*result); ERROR1: - psiconv_warn(config,lev+1,off,"Reading of Paint Data Section failed"); + psiconv_error(config,lev+1,off,"Reading of Paint Data Section failed"); if (length) *length = 0; if (!res) @@ -527,7 +532,7 @@ ERROR2: free (*result); ERROR1: - psiconv_warn(config,lev+1,off,"Reading of Sketch Section failed"); + psiconv_error(config,lev+1,off,"Reading of Sketch Section failed"); if (length) *length = 0; if (!res) @@ -630,7 +635,7 @@ ERROR2: free (*result); ERROR1: - psiconv_warn(config,lev+1,off,"Reading of Font failed"); + psiconv_error(config,lev+1,off,"Reading of Font failed"); if (length) *length = 0; if (!res) @@ -652,32 +657,46 @@ goto ERROR1; for (i = 0; i < psiconv_list_length(encoded);) { +#ifdef LOUD psiconv_progress(config,lev+2,off,"Going to read marker byte at %04x",i); +#endif if (!(marker = psiconv_list_get(encoded,i))) goto ERROR2; +#ifdef LOUD psiconv_debug(config,lev+2,off,"Marker byte: %02x",*marker); +#endif if (*marker < 0x80) { +#ifdef LOUD psiconv_debug(config,lev+2,off,"Marker: repeat value byte %02x times", - *marker+1); + *marker+1); */ psiconv_progress(config,lev+2,off,"Going to read value byte at %04x",i+1); +#endif if (!(value = psiconv_list_get(encoded,i+1))) goto ERROR2; - psiconv_debug(config,lev+2,off,"Value byte: %02x",*value); +#ifdef LOUD + psiconv_debug(config,lev+2,off,"Value byte: %02x",*value); psiconv_progress(config,lev+2,off,"Adding %02x pixels %02x", *marker+1,*value); +#endif for (j = 0; j < *marker + 1; j++) if ((res = psiconv_list_add(*decoded,value))) goto ERROR2; i += 2; } else { +#ifdef LOUD psiconv_debug(config,lev+2,off,"Marker: %02x value bytes follow", 0x100 - *marker); +#endif for (j = 0; j < (0x100 - *marker); j++) { +#ifdef LOUD psiconv_progress(config,lev+2,off,"Going to read value byte at %04x", i+j+1); +#endif if (!(value = psiconv_list_get(encoded,i+j+1))) goto ERROR2; - psiconv_debug(config,lev+2,off,"Value: %02x",*value); +#ifdef LOUD + psiconv_debug(config,lev+2,off,"Value: %02x",*value); +#endif if ((res = psiconv_list_add(*decoded,value))) goto ERROR2; } @@ -691,7 +710,7 @@ ERROR2: psiconv_list_free(*decoded); ERROR1: - psiconv_warn(config,lev+1,off,"Decoding of RLE8 failed"); + psiconv_error(config,lev+1,off,"Decoding of RLE8 failed"); if (!res) return -PSICONV_E_NOMEM; else @@ -734,7 +753,7 @@ ERROR2: psiconv_list_free(*decoded); ERROR1: - psiconv_warn(config,lev+1,off,"Decoding of RLE12 failed"); + psiconv_error(config,lev+1,off,"Decoding of RLE12 failed"); if (!res) return -PSICONV_E_NOMEM; else @@ -800,7 +819,7 @@ ERROR2: psiconv_list_free(*decoded); ERROR1: - psiconv_warn(config,lev+1,off,"Decoding of RLE16 failed"); + psiconv_error(config,lev+1,off,"Decoding of RLE16 failed"); if (!res) return -PSICONV_E_NOMEM; else @@ -870,7 +889,7 @@ ERROR2: psiconv_list_free(*decoded); ERROR1: - psiconv_warn(config,lev+1,off,"Decoding of RLE24 failed"); + psiconv_error(config,lev+1,off,"Decoding of RLE24 failed"); if (!res) return -PSICONV_E_NOMEM; else @@ -901,17 +920,23 @@ input = 0; ibits = 0; for (x= 0; x < xsize; x++) { +#ifdef LOUD psiconv_progress(config,lev+2,off, "Processing pixel at (x,y) = (%04x,%04x)",x,y); +#endif output = 0; obits = 0; while (obits < colordepth) { if (ibits == 0) { +#ifdef LOUD psiconv_progress(config,lev+3,off, "Going to read byte %08x",nr); +#endif if (!(ientry = psiconv_list_get(bytes,nr))) goto ERROR2; +#ifdef LOUD psiconv_debug(config,lev+3,off,"Byte value: %02x",*ientry); +#endif input = *ientry; ibits = 8; nr ++; @@ -923,7 +948,9 @@ ibits -= bits; obits += bits; } +#ifdef LOUD psiconv_debug(config,lev+2,off,"Pixel value: %08x",output); +#endif if ((res = psiconv_list_add(*pixels,&output))) goto ERROR2; } @@ -937,7 +964,7 @@ ERROR2: psiconv_list_free(*pixels); ERROR1: - psiconv_warn(config,lev+1,off,"Converting bytes to pixels failed"); + psiconv_error(config,lev+1,off,"Converting bytes to pixels failed"); if (!res) return -PSICONV_E_NOMEM; else @@ -971,7 +998,9 @@ for (i = 0; i < psiconv_list_length(pixels); i++) { if (!(pixel = psiconv_list_get(pixels,i))) goto ERROR4; +#ifdef LOUD psiconv_progress(config,lev+2,off, "Handling pixel %04x (%04x)",i,*pixel); +#endif if (!palet.length) { if (color) { (*floats).blue[i] = ((float) (*pixel & ((1 << bluebits) - 1))) / @@ -998,8 +1027,10 @@ (*floats).blue[i] = palet.blue[*pixel]; } } +#ifdef LOUD psiconv_debug(config,lev+2,off, "Pixel: Red (%f), green (%f), blue (%f)", (*floats).red[i],(*floats).green[i],(*floats).blue[i]); +#endif } psiconv_progress(config,lev+1,off,"Finished converting pixels to floats"); return 0; @@ -1011,7 +1042,7 @@ ERROR2: free((*floats).red); ERROR1: - psiconv_warn(config,lev+1,off,"Converting pixels to floats failed"); + psiconv_error(config,lev+1,off,"Converting pixels to floats failed"); if (!res) return -PSICONV_E_NOMEM; else