--- psiconv/trunk/lib/psiconv/parse_image.c 1999/10/28 21:23:57 23 +++ psiconv/trunk/lib/psiconv/parse_image.c 1999/10/29 21:14:58 24 @@ -242,3 +242,160 @@ } + + +int psiconv_parse_sketch_section(const psiconv_buffer buf, int lev, + psiconv_u32 off, int *length, int is_object, + psiconv_sketch_section *result) +{ + int res=0; + int len=0; + psiconv_u32 temp; + int leng; + int i; + + psiconv_progress(lev+1,off,"Going to read the sketch section"); + *result = malloc(sizeof(**result)); + + if (!is_object) { + psiconv_progress(lev+2,off+len,"Going to read the form hor. size"); + (*result)->form_xsize = psiconv_read_u16(buf,lev+2,off + len); + psiconv_debug(lev+2,off+len,"Form hor. size: %04x", + (*result)->form_xsize); + len += 0x02; + psiconv_progress(lev+2,off+len,"Going to read the form ver. size"); + (*result)->form_ysize = psiconv_read_u16(buf,lev+2,off + len); + psiconv_debug(lev+2,off+len,"Form ver. size: %04x", + (*result)->form_ysize); + len += 0x02; + psiconv_progress(lev+2,off+len,"Going to read the picture hor. offset"); + (*result)->picture_x_offset = psiconv_read_u16(buf,lev+2,off + len); + psiconv_debug(lev+2,off+len,"Picture hor. offset: %04x", + (*result)->picture_x_offset); + len += 0x02; + psiconv_progress(lev+2,off+len,"Going to read the picture ver. offset"); + (*result)->picture_y_offset = psiconv_read_u16(buf,lev+2,off + len); + psiconv_debug(lev+2,off+len,"Picture ver. offset: %04x", + (*result)->picture_y_offset); + len += 0x02; + psiconv_progress(lev+2,off+len,"Going to skip 5 words of zeros"); + for (i = 0; i < 5; i++) { + temp = psiconv_read_u16(buf,lev+2,off+len); + if (temp != 0) { + psiconv_warn(lev+2,off+len, + "Unexpected value in sketch section preamble"); + psiconv_debug(lev+2,off+len,"Word %d: Read %04x, expected %04x",i, + temp,0); + res = -1; + } + off += 0x02; + } + } else { + psiconv_progress(lev+2,off+len,"Going to read the displayed hor. size"); + (*result)->picture_xsize = psiconv_read_u16(buf,lev+2,off + len); + psiconv_debug(lev+2,off+len,"Displayed hor. size: %04x", + (*result)->picture_xsize); + len += 0x02; + psiconv_progress(lev+2,off+len,"Going to read the displayed ver. size"); + (*result)->picture_ysize = psiconv_read_u16(buf,lev+2,off + len); + psiconv_debug(lev+2,off+len,"Displayed ver. size: %04x", + (*result)->picture_ysize); + len += 0x02; + + psiconv_progress(lev+2,off+len,"Going to skip 2 words of zeros"); + for (i = 0; i < 2; i++) { + temp = psiconv_read_u16(buf,lev+2,off+len); + if (temp != 0) { + psiconv_warn(lev+2,off+len, + "Unexpected value in sketch section preamble"); + psiconv_debug(lev+2,off+len,"Word %d: Read %04x, expected %04x",i, + temp,0); + res = -1; + } + off += 0x02; + } + psiconv_progress(lev+2,off+len,"Going to read the picture hor. offset"); + (*result)->picture_x_offset = psiconv_read_u16(buf,lev+2,off + len); + psiconv_debug(lev+2,off+len,"Picture hor. offset: %04x", + (*result)->picture_x_offset); + len += 0x02; + psiconv_progress(lev+2,off+len,"Going to read the picture ver. offset"); + (*result)->picture_y_offset = psiconv_read_u16(buf,lev+2,off + len); + psiconv_debug(lev+2,off+len,"Picture ver. offset: %04x", + (*result)->picture_y_offset); + len += 0x02; + psiconv_progress(lev+2,off+len,"Going to read the form hor. size"); + (*result)->form_xsize = psiconv_read_u16(buf,lev+2,off + len); + psiconv_debug(lev+2,off+len,"Form hor. size: %04x", + (*result)->form_xsize); + len += 0x02; + psiconv_progress(lev+2,off+len,"Going to read the form ver. size"); + (*result)->form_ysize = psiconv_read_u16(buf,lev+2,off + len); + psiconv_debug(lev+2,off+len,"Form ver. size: %04x", + (*result)->form_ysize); + len += 0x02; + psiconv_progress(lev+2,off+len,"Going to skip 1 zero word"); + temp = psiconv_read_u16(buf,lev+2,off+len); + if (temp != 0) { + psiconv_warn(lev+2,off+len, + "Unexpected value in sketch section preamble"); + psiconv_debug(lev+2,off+len,"Read %04x, expected %04x",i, temp,0); + res = -1; + } + off += 0x02; + } + + psiconv_progress(lev+2,off+len,"Going to read the picture data"); + res |= psiconv_parse_paint_data_section(buf,lev+2,off+len,&leng, + &((*result)->picture)); + off += leng; + if (!is_object) { + (*result)->picture_xsize = (*result)->picture->xsize; + (*result)->picture_ysize = (*result)->picture->ysize; + } + + psiconv_progress(lev+2,off+len,"Going to read the hor. magnification"); + (*result)->magnification_x = psiconv_read_u16(buf,lev+2,off + len) / 1000.0; + psiconv_debug(lev+2,off+len,"Form hor. magnification: %f", + (*result)->magnification_x); + len += 0x02; + psiconv_progress(lev+2,off+len,"Going to read the ver. magnification"); + (*result)->magnification_y = psiconv_read_u16(buf,lev+2,off + len) / 1000.0; + psiconv_debug(lev+2,off+len,"Form ver. magnification: %f", + (*result)->magnification_y); + len += 0x02; + + psiconv_progress(lev+2,off+len,"Going to read the left cut"); + temp = psiconv_read_u32(buf,lev+2,off + len); + (*result)->cut_left = (temp * 6.0) / (*result)->picture_xsize; + psiconv_debug(lev+2,off+len,"Left cut: raw %08x, real: %f", + temp,(*result)->cut_left); + len += 0x04; + psiconv_progress(lev+2,off+len,"Going to read the right cut"); + temp = psiconv_read_u32(buf,lev+2,off + len); + (*result)->cut_right = (temp * 6.0) / (*result)->picture_xsize; + psiconv_debug(lev+2,off+len,"Right cut: raw %08x, real: %f", + temp,(*result)->cut_right); + len += 0x04; + psiconv_progress(lev+2,off+len,"Going to read the top cut"); + temp = psiconv_read_u32(buf,lev+2,off + len); + (*result)->cut_top = (temp * 6.0) / (*result)->picture_ysize; + psiconv_debug(lev+2,off+len,"Top cut: raw %08x, real: %f", + temp,(*result)->cut_top); + len += 0x04; + psiconv_progress(lev+2,off+len,"Going to read the bottom cut"); + temp = psiconv_read_u32(buf,lev+2,off + len); + (*result)->cut_bottom = (temp * 6.0) / (*result)->picture_ysize; + psiconv_debug(lev+2,off+len,"Bottom cut: raw %08x, real: %f", + temp,(*result)->cut_bottom); + len += 0x04; + + if (length) + *length = len; + + psiconv_progress(lev,off+len-1, + "End of sketch section (total length: %08x)", len); + + return res; +} +