--- psiconv/trunk/lib/psiconv/parse_image.c 1999/12/03 23:13:55 42 +++ psiconv/trunk/lib/psiconv/parse_image.c 2000/12/13 16:30:21 63 @@ -1,6 +1,6 @@ /* parse_image.c - Part of psiconv, a PSION 5 file formats converter - Copyright (c) 1999 Frodo Looijaard + Copyright (c) 1999, 2000 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 @@ -92,7 +92,7 @@ int psiconv_parse_paint_data_section(const psiconv_buffer buf,int lev, - psiconv_u32 off, int *length, + psiconv_u32 off, int *length,int isclipart, psiconv_paint_data_section *result) { int res = 0; @@ -178,12 +178,38 @@ compression = 1; } psiconv_debug(lev+2,off+len,"Compression: %s",compression?"RLE":"none"); + len += 4; + + if (isclipart) { + psiconv_progress(lev+2,off+len,"Going to read an unknown long"); + temp = psiconv_read_u32(buf,lev+2,off+len); + if (temp != 0xffffffff) { + psiconv_warn(lev+2,off+len, + "Paint data section prologue has unknown values"); + psiconv_debug(lev+2,off+len, + "offset %02x: read %08x, expected %08x",i,temp, 0xffffffff); + res = -1; + } + len += 4; + psiconv_progress(lev+2,off+len,"Going to read a second unknown long"); + temp = psiconv_read_u32(buf,lev+2,off+len); + if (temp != 0x44) { + psiconv_warn(lev+2,off+len, + "Paint data section prologue has unknown values"); + psiconv_debug(lev+2,off+len, + "offset %02x: read %08x, expected %08x",i,temp, 0x44); + res = -1; + } + len += 4; + } (*result)->red = malloc(sizeof(float) * picsize); (*result)->green = malloc(sizeof(float) * picsize); (*result)->blue = malloc(sizeof(float) * picsize); len = offset; datasize = size - len; + if (isclipart) + len += 8; psiconv_progress(lev+2,off+len,"Going to read the pixel data"); pixelnr = 0; @@ -395,7 +421,7 @@ } psiconv_progress(lev+2,off+len,"Going to read the picture data"); - res |= psiconv_parse_paint_data_section(buf,lev+2,off+len,&leng, + res |= psiconv_parse_paint_data_section(buf,lev+2,off+len,&leng,0, &((*result)->picture)); off += leng; if (!is_object) { @@ -448,3 +474,87 @@ return res; } + +int psiconv_parse_clipart_section(const psiconv_buffer buf,int lev, + psiconv_u32 off, int *length, + psiconv_clipart_section *result) +{ + int res=0; + int len=0; + int leng; + psiconv_u32 temp; + + psiconv_progress(lev+1,off+len,"Going to read the clipart section"); + *result = malloc(sizeof(**result)); + + psiconv_progress(lev+2,off+len,"Going to read the section ID"); + temp = psiconv_read_u32(buf,lev+2,off+len); + if (temp != PSICONV_ID_CLIPART_ITEM) { + psiconv_warn(lev+2,off+len, + "Unexpected value in clipart section preamble"); + psiconv_debug(lev+2,off+len,"Read %08x, expected %08x",temp, + PSICONV_ID_CLIPART_ITEM); + res = -1; + } else + psiconv_debug(lev+2,off+len,"Clipart ID: %08x", temp); + off += 4; + + psiconv_progress(lev+2,off+len,"Going to read an unknown long"); + temp = psiconv_read_u32(buf,lev+2,off+len); + if (temp != 0x02) { + psiconv_warn(lev+2,off+len, + "Unexpected value in clipart section preamble"); + psiconv_debug(lev+2,off+len,"Read %08x, expected %08x",temp, + 0x02); + res = -1; + } else + psiconv_debug(lev+2,off+len,"First unknown long: %08x", temp); + off += 4; + + psiconv_progress(lev+2,off+len,"Going to read a second unknown long"); + temp = psiconv_read_u32(buf,lev+2,off+len); + if (temp != 0) { + psiconv_warn(lev+2,off+len, + "Unexpected value in clipart section preamble"); + psiconv_debug(lev+2,off+len,"Read %08x, expected %08x",temp, 0); + res = -1; + } else + psiconv_debug(lev+2,off+len,"Second unknown long: %08x", temp); + off += 4; + + psiconv_progress(lev+2,off+len,"Going to read a third unknown long"); + temp = psiconv_read_u32(buf,lev+2,off+len); + if (temp != 0) { + psiconv_warn(lev+2,off+len, + "Unexpected value in clipart section preamble"); + psiconv_debug(lev+2,off+len,"Read %08x, expected %08x",temp, 0); + res = -1; + } else + psiconv_debug(lev+2,off+len,"Third unknown long: %08x", temp); + off += 4; + + psiconv_progress(lev+2,off+len,"Going to read a fourth unknown long"); + temp = psiconv_read_u32(buf,lev+2,off+len); + if ((temp != 0x0c) && (temp != 0x08)) { + psiconv_warn(lev+2,off+len, + "Unexpected value in clipart section preamble"); + psiconv_debug(lev+2,off+len,"Read %08x, expected %08x or %08x",temp, + 0x0c, 0x08); + res = -1; + } else + psiconv_debug(lev+2,off+len,"Fourth unknown long: %08x", temp); + off += 4; + + psiconv_progress(lev+2,off+len,"Going to read the Paint Data Section"); + res |= psiconv_parse_paint_data_section(buf,lev+2,off+len,&leng,1, + &((*result)->picture)); + len += leng; + + if (length) + *length = len; + + psiconv_progress(lev,off+len-1, + "End of clipart section (total length: %08x)", len); + + return res; +}