… | |
… | |
21 | #include <stdlib.h> |
21 | #include <stdlib.h> |
22 | |
22 | |
23 | #include "data.h" |
23 | #include "data.h" |
24 | #include "parse_routines.h" |
24 | #include "parse_routines.h" |
25 | |
25 | |
26 | int psiconv_parse_mbm_jumptable_section(const psiconv_buffer buf,int lev, |
26 | int psiconv_parse_jumptable_section(const psiconv_buffer buf,int lev, |
27 | psiconv_u32 off, int *length, |
27 | psiconv_u32 off, int *length, |
28 | psiconv_mbm_jumptable_section *result) |
28 | psiconv_jumptable_section *result) |
29 | { |
29 | { |
30 | int res = 0; |
30 | int res = 0; |
31 | int len = 0; |
31 | int len = 0; |
32 | psiconv_u32 listlen,temp; |
32 | psiconv_u32 listlen,temp; |
33 | int i; |
33 | int i; |
34 | |
34 | |
35 | psiconv_progress(lev+1,off+len,"Going to read the mbm jumptable section"); |
35 | psiconv_progress(lev+1,off+len,"Going to read the jumptable section"); |
36 | (*result) = psiconv_list_new(sizeof(psiconv_u32)); |
36 | (*result) = psiconv_list_new(sizeof(psiconv_u32)); |
37 | |
37 | |
38 | psiconv_progress(lev+2,off+len,"Going to read the list length"); |
38 | psiconv_progress(lev+2,off+len,"Going to read the list length"); |
39 | listlen = psiconv_read_u32(buf,lev+2,off+len); |
39 | listlen = psiconv_read_u32(buf,lev+2,off+len); |
40 | psiconv_debug(lev+2,off+len,"List length: %08x",listlen); |
40 | psiconv_debug(lev+2,off+len,"List length: %08x",listlen); |
… | |
… | |
49 | } |
49 | } |
50 | |
50 | |
51 | if (length) |
51 | if (length) |
52 | *length = len; |
52 | *length = len; |
53 | |
53 | |
54 | psiconv_progress(lev+1,off+len-1,"End of mbm jumptable section " |
54 | psiconv_progress(lev+1,off+len-1,"End of jumptable section " |
55 | "(total length: %08x)", len); |
55 | "(total length: %08x)", len); |
56 | |
56 | |
57 | return res; |
57 | return res; |
58 | } |
58 | } |
59 | |
59 | |
… | |
… | |
90 | return 0; |
90 | return 0; |
91 | } |
91 | } |
92 | |
92 | |
93 | |
93 | |
94 | int psiconv_parse_paint_data_section(const psiconv_buffer buf,int lev, |
94 | int psiconv_parse_paint_data_section(const psiconv_buffer buf,int lev, |
95 | psiconv_u32 off, int *length, |
95 | psiconv_u32 off, int *length,int isclipart, |
96 | psiconv_paint_data_section *result) |
96 | psiconv_paint_data_section *result) |
97 | { |
97 | { |
98 | int res = 0; |
98 | int res = 0; |
99 | int len = 0; |
99 | int len = 0; |
100 | int read_err = 0; |
100 | int read_err = 0; |
… | |
… | |
176 | "compression type, assuming RLE"); |
176 | "compression type, assuming RLE"); |
177 | psiconv_debug(lev+2,off+len,"Read compression type %d",compression); |
177 | psiconv_debug(lev+2,off+len,"Read compression type %d",compression); |
178 | compression = 1; |
178 | compression = 1; |
179 | } |
179 | } |
180 | psiconv_debug(lev+2,off+len,"Compression: %s",compression?"RLE":"none"); |
180 | psiconv_debug(lev+2,off+len,"Compression: %s",compression?"RLE":"none"); |
|
|
181 | len += 4; |
|
|
182 | |
|
|
183 | if (isclipart) { |
|
|
184 | psiconv_progress(lev+2,off+len,"Going to read an unknown long"); |
|
|
185 | temp = psiconv_read_u32(buf,lev+2,off+len); |
|
|
186 | if (temp != 0xffffffff) { |
|
|
187 | psiconv_warn(lev+2,off+len, |
|
|
188 | "Paint data section prologue has unknown values"); |
|
|
189 | psiconv_debug(lev+2,off+len, |
|
|
190 | "offset %02x: read %08x, expected %08x",i,temp, 0xffffffff); |
|
|
191 | res = -1; |
|
|
192 | } |
|
|
193 | len += 4; |
|
|
194 | psiconv_progress(lev+2,off+len,"Going to read a second unknown long"); |
|
|
195 | temp = psiconv_read_u32(buf,lev+2,off+len); |
|
|
196 | if (temp != 0x44) { |
|
|
197 | psiconv_warn(lev+2,off+len, |
|
|
198 | "Paint data section prologue has unknown values"); |
|
|
199 | psiconv_debug(lev+2,off+len, |
|
|
200 | "offset %02x: read %08x, expected %08x",i,temp, 0x44); |
|
|
201 | res = -1; |
|
|
202 | } |
|
|
203 | len += 4; |
|
|
204 | } |
181 | |
205 | |
182 | (*result)->red = malloc(sizeof(float) * picsize); |
206 | (*result)->red = malloc(sizeof(float) * picsize); |
183 | (*result)->green = malloc(sizeof(float) * picsize); |
207 | (*result)->green = malloc(sizeof(float) * picsize); |
184 | (*result)->blue = malloc(sizeof(float) * picsize); |
208 | (*result)->blue = malloc(sizeof(float) * picsize); |
185 | len = offset; |
209 | len = offset; |
186 | datasize = size - len; |
210 | datasize = size - len; |
|
|
211 | if (isclipart) |
|
|
212 | len += 8; |
187 | |
213 | |
188 | psiconv_progress(lev+2,off+len,"Going to read the pixel data"); |
214 | psiconv_progress(lev+2,off+len,"Going to read the pixel data"); |
189 | pixelnr = 0; |
215 | pixelnr = 0; |
190 | datanr = 0; |
216 | datanr = 0; |
191 | if (!compression) { |
217 | if (!compression) { |
… | |
… | |
393 | } |
419 | } |
394 | off += 0x02; |
420 | off += 0x02; |
395 | } |
421 | } |
396 | |
422 | |
397 | psiconv_progress(lev+2,off+len,"Going to read the picture data"); |
423 | psiconv_progress(lev+2,off+len,"Going to read the picture data"); |
398 | res |= psiconv_parse_paint_data_section(buf,lev+2,off+len,&leng, |
424 | res |= psiconv_parse_paint_data_section(buf,lev+2,off+len,&leng,0, |
399 | &((*result)->picture)); |
425 | &((*result)->picture)); |
400 | off += leng; |
426 | off += leng; |
401 | if (!is_object) { |
427 | if (!is_object) { |
402 | (*result)->picture_xsize = (*result)->picture->xsize; |
428 | (*result)->picture_xsize = (*result)->picture->xsize; |
403 | (*result)->picture_ysize = (*result)->picture->ysize; |
429 | (*result)->picture_ysize = (*result)->picture->ysize; |
… | |
… | |
446 | "End of sketch section (total length: %08x)", len); |
472 | "End of sketch section (total length: %08x)", len); |
447 | |
473 | |
448 | return res; |
474 | return res; |
449 | } |
475 | } |
450 | |
476 | |
|
|
477 | |
|
|
478 | int psiconv_parse_clipart_section(const psiconv_buffer buf,int lev, |
|
|
479 | psiconv_u32 off, int *length, |
|
|
480 | psiconv_clipart_section *result) |
|
|
481 | { |
|
|
482 | int res=0; |
|
|
483 | int len=0; |
|
|
484 | int leng; |
|
|
485 | psiconv_u32 temp; |
|
|
486 | |
|
|
487 | psiconv_progress(lev+1,off+len,"Going to read the clipart section"); |
|
|
488 | *result = malloc(sizeof(**result)); |
|
|
489 | |
|
|
490 | psiconv_progress(lev+2,off+len,"Going to read the section ID"); |
|
|
491 | temp = psiconv_read_u32(buf,lev+2,off+len); |
|
|
492 | if (temp != PSICONV_ID_CLIPART_ITEM) { |
|
|
493 | psiconv_warn(lev+2,off+len, |
|
|
494 | "Unexpected value in clipart section preamble"); |
|
|
495 | psiconv_debug(lev+2,off+len,"Read %08x, expected %08x",temp, |
|
|
496 | PSICONV_ID_CLIPART_ITEM); |
|
|
497 | res = -1; |
|
|
498 | } else |
|
|
499 | psiconv_debug(lev+2,off+len,"Clipart ID: %08x", temp); |
|
|
500 | off += 4; |
|
|
501 | |
|
|
502 | psiconv_progress(lev+2,off+len,"Going to read an unknown long"); |
|
|
503 | temp = psiconv_read_u32(buf,lev+2,off+len); |
|
|
504 | if (temp != 0x02) { |
|
|
505 | psiconv_warn(lev+2,off+len, |
|
|
506 | "Unexpected value in clipart section preamble"); |
|
|
507 | psiconv_debug(lev+2,off+len,"Read %08x, expected %08x",temp, |
|
|
508 | 0x02); |
|
|
509 | res = -1; |
|
|
510 | } else |
|
|
511 | psiconv_debug(lev+2,off+len,"First unknown long: %08x", temp); |
|
|
512 | off += 4; |
|
|
513 | |
|
|
514 | psiconv_progress(lev+2,off+len,"Going to read a second unknown long"); |
|
|
515 | temp = psiconv_read_u32(buf,lev+2,off+len); |
|
|
516 | if (temp != 0) { |
|
|
517 | psiconv_warn(lev+2,off+len, |
|
|
518 | "Unexpected value in clipart section preamble"); |
|
|
519 | psiconv_debug(lev+2,off+len,"Read %08x, expected %08x",temp, 0); |
|
|
520 | res = -1; |
|
|
521 | } else |
|
|
522 | psiconv_debug(lev+2,off+len,"Second unknown long: %08x", temp); |
|
|
523 | off += 4; |
|
|
524 | |
|
|
525 | psiconv_progress(lev+2,off+len,"Going to read a third unknown long"); |
|
|
526 | temp = psiconv_read_u32(buf,lev+2,off+len); |
|
|
527 | if (temp != 0) { |
|
|
528 | psiconv_warn(lev+2,off+len, |
|
|
529 | "Unexpected value in clipart section preamble"); |
|
|
530 | psiconv_debug(lev+2,off+len,"Read %08x, expected %08x",temp, 0); |
|
|
531 | res = -1; |
|
|
532 | } else |
|
|
533 | psiconv_debug(lev+2,off+len,"Third unknown long: %08x", temp); |
|
|
534 | off += 4; |
|
|
535 | |
|
|
536 | psiconv_progress(lev+2,off+len,"Going to read a fourth unknown long"); |
|
|
537 | temp = psiconv_read_u32(buf,lev+2,off+len); |
|
|
538 | if ((temp != 0x0c) && (temp != 0x08)) { |
|
|
539 | psiconv_warn(lev+2,off+len, |
|
|
540 | "Unexpected value in clipart section preamble"); |
|
|
541 | psiconv_debug(lev+2,off+len,"Read %08x, expected %08x or %08x",temp, |
|
|
542 | 0x0c, 0x08); |
|
|
543 | res = -1; |
|
|
544 | } else |
|
|
545 | psiconv_debug(lev+2,off+len,"Fourth unknown long: %08x", temp); |
|
|
546 | off += 4; |
|
|
547 | |
|
|
548 | psiconv_progress(lev+2,off+len,"Going to read the Paint Data Section"); |
|
|
549 | res |= psiconv_parse_paint_data_section(buf,lev+2,off+len,&leng,1, |
|
|
550 | &((*result)->picture)); |
|
|
551 | len += leng; |
|
|
552 | |
|
|
553 | if (length) |
|
|
554 | *length = len; |
|
|
555 | |
|
|
556 | psiconv_progress(lev,off+len-1, |
|
|
557 | "End of clipart section (total length: %08x)", len); |
|
|
558 | |
|
|
559 | return res; |
|
|
560 | } |