… | |
… | |
387 | else |
387 | else |
388 | return res; |
388 | return res; |
389 | } |
389 | } |
390 | |
390 | |
391 | int psiconv_parse_sketch_section(const psiconv_buffer buf, int lev, |
391 | int psiconv_parse_sketch_section(const psiconv_buffer buf, int lev, |
392 | psiconv_u32 off, int *length, int is_object, |
392 | psiconv_u32 off, int *length, |
393 | psiconv_sketch_section *result) |
393 | psiconv_sketch_section *result) |
394 | { |
394 | { |
395 | int res=0; |
395 | int res=0; |
396 | int len=0; |
396 | int len=0; |
397 | psiconv_u32 temp; |
397 | psiconv_u32 temp; |
398 | int leng; |
398 | int leng; |
399 | int i; |
|
|
400 | |
399 | |
401 | psiconv_progress(lev+1,off,"Going to read the sketch section"); |
400 | psiconv_progress(lev+1,off,"Going to read the sketch section"); |
402 | if (!(*result = malloc(sizeof(**result)))) |
401 | if (!(*result = malloc(sizeof(**result)))) |
403 | goto ERROR1; |
402 | goto ERROR1; |
404 | |
403 | |
405 | if (!is_object) { |
|
|
406 | psiconv_progress(lev+2,off+len,"Going to read the form hor. size"); |
|
|
407 | (*result)->form_xsize = psiconv_read_u16(buf,lev+2,off + len,&res); |
|
|
408 | if (res) |
|
|
409 | goto ERROR2; |
|
|
410 | psiconv_debug(lev+2,off+len,"Form hor. size: %04x", |
|
|
411 | (*result)->form_xsize); |
|
|
412 | len += 0x02; |
|
|
413 | psiconv_progress(lev+2,off+len,"Going to read the form ver. size"); |
|
|
414 | (*result)->form_ysize = psiconv_read_u16(buf,lev+2,off + len,&res); |
|
|
415 | if (res) |
|
|
416 | goto ERROR2; |
|
|
417 | psiconv_debug(lev+2,off+len,"Form ver. size: %04x", |
|
|
418 | (*result)->form_ysize); |
|
|
419 | len += 0x02; |
|
|
420 | psiconv_progress(lev+2,off+len,"Going to read the picture hor. offset"); |
|
|
421 | (*result)->picture_x_offset = psiconv_read_u16(buf,lev+2,off + len,&res); |
|
|
422 | if (res) |
|
|
423 | goto ERROR2; |
|
|
424 | psiconv_debug(lev+2,off+len,"Picture hor. offset: %04x", |
|
|
425 | (*result)->picture_x_offset); |
|
|
426 | len += 0x02; |
|
|
427 | psiconv_progress(lev+2,off+len,"Going to read the picture ver. offset"); |
|
|
428 | (*result)->picture_y_offset = psiconv_read_u16(buf,lev+2,off + len,&res); |
|
|
429 | if (res) |
|
|
430 | goto ERROR2; |
|
|
431 | psiconv_debug(lev+2,off+len,"Picture ver. offset: %04x", |
|
|
432 | (*result)->picture_y_offset); |
|
|
433 | len += 0x02; |
|
|
434 | psiconv_progress(lev+2,off+len,"Going to skip 5 words of zeros"); |
|
|
435 | for (i = 0; i < 5; i++) { |
|
|
436 | temp = psiconv_read_u16(buf,lev+2,off+len,&res); |
|
|
437 | if (res) |
|
|
438 | goto ERROR2; |
|
|
439 | if (temp != 0) { |
|
|
440 | psiconv_warn(lev+2,off+len, |
|
|
441 | "Unexpected value in sketch section preamble (ignored)"); |
|
|
442 | psiconv_debug(lev+2,off+len,"Word %d: Read %04x, expected %04x",i, |
|
|
443 | temp,0); |
|
|
444 | } |
|
|
445 | off += 0x02; |
|
|
446 | } |
|
|
447 | } else { |
|
|
448 | psiconv_progress(lev+2,off+len,"Going to read the displayed hor. size"); |
404 | psiconv_progress(lev+2,off+len,"Going to read the displayed hor. size"); |
449 | (*result)->picture_xsize = psiconv_read_u16(buf,lev+2,off + len,&res); |
405 | (*result)->displayed_xsize = psiconv_read_u16(buf,lev+2,off + len,&res); |
450 | if (res) |
406 | if (res) |
451 | goto ERROR2; |
407 | goto ERROR2; |
452 | psiconv_debug(lev+2,off+len,"Displayed hor. size: %04x", |
408 | psiconv_debug(lev+2,off+len,"Displayed hor. size: %04x", |
453 | (*result)->picture_xsize); |
409 | (*result)->displayed_xsize); |
454 | len += 0x02; |
410 | len += 0x02; |
455 | psiconv_progress(lev+2,off+len,"Going to read the displayed ver. size"); |
411 | psiconv_progress(lev+2,off+len,"Going to read displayed ver. size"); |
456 | (*result)->picture_ysize = psiconv_read_u16(buf,lev+2,off + len,&res); |
412 | (*result)->displayed_ysize = psiconv_read_u16(buf,lev+2,off + len,&res); |
457 | if (res) |
413 | if (res) |
458 | goto ERROR2; |
414 | goto ERROR2; |
459 | psiconv_debug(lev+2,off+len,"Displayed ver. size: %04x", |
415 | psiconv_debug(lev+2,off+len,"Displayed ver. size: %04x", |
460 | (*result)->picture_ysize); |
416 | (*result)->displayed_ysize); |
461 | len += 0x02; |
417 | len += 0x02; |
462 | |
418 | |
463 | psiconv_progress(lev+2,off+len,"Going to skip 2 words of zeros"); |
|
|
464 | for (i = 0; i < 2; i++) { |
|
|
465 | temp = psiconv_read_u16(buf,lev+2,off+len,&res); |
|
|
466 | if (res) |
|
|
467 | goto ERROR2; |
|
|
468 | if (temp != 0) { |
|
|
469 | psiconv_warn(lev+2,off+len, |
|
|
470 | "Unexpected value in sketch section preamble (ignored)"); |
|
|
471 | psiconv_debug(lev+2,off+len,"Word %d: Read %04x, expected %04x",i, |
|
|
472 | temp,0); |
|
|
473 | } |
|
|
474 | off += 0x02; |
|
|
475 | } |
|
|
476 | psiconv_progress(lev+2,off+len,"Going to read the picture hor. offset"); |
419 | psiconv_progress(lev+2,off+len,"Going to read the data hor. offset"); |
477 | (*result)->picture_x_offset = psiconv_read_u16(buf,lev+2,off + len,&res); |
420 | (*result)->picture_data_x_offset = psiconv_read_u16(buf,lev+2,off + len, |
|
|
421 | &res); |
478 | if (res) |
422 | if (res) |
479 | goto ERROR2; |
423 | goto ERROR2; |
480 | psiconv_debug(lev+2,off+len,"Picture hor. offset: %04x", |
424 | psiconv_debug(lev+2,off+len,"Data hor. offset: %04x", |
481 | (*result)->picture_x_offset); |
425 | (*result)->picture_data_x_offset); |
482 | len += 0x02; |
426 | len += 0x02; |
483 | psiconv_progress(lev+2,off+len,"Going to read the picture ver. offset"); |
427 | psiconv_progress(lev+2,off+len,"Going to read the data ver. offset"); |
484 | (*result)->picture_y_offset = psiconv_read_u16(buf,lev+2,off + len,&res); |
428 | (*result)->picture_data_y_offset = psiconv_read_u16(buf,lev+2,off + len, |
|
|
429 | &res); |
485 | if (res) |
430 | if (res) |
486 | goto ERROR2; |
431 | goto ERROR2; |
487 | psiconv_debug(lev+2,off+len,"Picture ver. offset: %04x", |
432 | psiconv_debug(lev+2,off+len,"Data ver. offset: %04x", |
488 | (*result)->picture_y_offset); |
433 | (*result)->picture_data_y_offset); |
489 | len += 0x02; |
434 | len += 0x02; |
|
|
435 | |
|
|
436 | psiconv_progress(lev+2,off+len,"Going to read the displayed hor. offset"); |
|
|
437 | (*result)->displayed_size_x_offset = psiconv_read_u16(buf,lev+2,off + len, |
|
|
438 | &res); |
|
|
439 | if (res) |
|
|
440 | goto ERROR2; |
|
|
441 | psiconv_debug(lev+2,off+len,"Displayed hor. offset: %04x", |
|
|
442 | (*result)->displayed_size_x_offset); |
|
|
443 | len += 0x02; |
|
|
444 | psiconv_progress(lev+2,off+len,"Going to read the displayed ver. offset"); |
|
|
445 | (*result)->displayed_size_y_offset = psiconv_read_u16(buf,lev+2,off + len, |
|
|
446 | &res); |
|
|
447 | if (res) |
|
|
448 | goto ERROR2; |
|
|
449 | psiconv_debug(lev+2,off+len,"Displayed ver. offset: %04x", |
|
|
450 | (*result)->displayed_size_y_offset); |
|
|
451 | len += 0x02; |
|
|
452 | |
490 | psiconv_progress(lev+2,off+len,"Going to read the form hor. size"); |
453 | psiconv_progress(lev+2,off+len,"Going to read the form hor. size"); |
491 | (*result)->form_xsize = psiconv_read_u16(buf,lev+2,off + len,&res); |
454 | (*result)->form_xsize = psiconv_read_u16(buf,lev+2,off + len,&res); |
492 | if (res) |
455 | if (res) |
493 | goto ERROR2; |
456 | goto ERROR2; |
494 | psiconv_debug(lev+2,off+len,"Form hor. size: %04x", |
457 | psiconv_debug(lev+2,off+len,"Form hor. size: %04x", |
495 | (*result)->form_xsize); |
458 | (*result)->form_xsize); |
496 | len += 0x02; |
459 | len += 0x02; |
497 | psiconv_progress(lev+2,off+len,"Going to read the form ver. size"); |
460 | psiconv_progress(lev+2,off+len,"Going to read form ver. size"); |
498 | (*result)->form_ysize = psiconv_read_u16(buf,lev+2,off + len,&res); |
461 | (*result)->form_ysize = psiconv_read_u16(buf,lev+2,off + len,&res); |
499 | if (res) |
462 | if (res) |
500 | goto ERROR2; |
463 | goto ERROR2; |
501 | psiconv_debug(lev+2,off+len,"Form ver. size: %04x", |
464 | psiconv_debug(lev+2,off+len,"Form ver. size: %04x", |
502 | (*result)->form_ysize); |
465 | (*result)->form_ysize); |
503 | len += 0x02; |
466 | len += 0x02; |
|
|
467 | |
504 | psiconv_progress(lev+2,off+len,"Going to skip 1 zero word"); |
468 | psiconv_progress(lev+2,off+len,"Going to skip 1 word of zeros"); |
505 | temp = psiconv_read_u16(buf,lev+2,off+len,&res); |
469 | temp = psiconv_read_u16(buf,lev+2,off+len,&res); |
506 | if (res) |
470 | if (res) |
507 | goto ERROR2; |
471 | goto ERROR2; |
508 | if (temp != 0) { |
472 | if (temp != 0) { |
509 | psiconv_warn(lev+2,off+len, |
473 | psiconv_warn(lev+2,off+len, |
510 | "Unexpected value in sketch section preamble (ignored)"); |
474 | "Unexpected value in sketch section preamble (ignored)"); |
511 | psiconv_debug(lev+2,off+len,"Read %04x, expected %04x",i, temp,0); |
475 | psiconv_debug(lev+2,off+len,"Read %04x, expected %04x", |
|
|
476 | temp,0); |
512 | } |
477 | } |
513 | off += 0x02; |
478 | off += 0x02; |
514 | } |
|
|
515 | |
479 | |
516 | psiconv_progress(lev+2,off+len,"Going to read the picture data"); |
480 | psiconv_progress(lev+2,off+len,"Going to read the picture data"); |
517 | if ((res = psiconv_parse_paint_data_section(buf,lev+2,off+len,&leng,0, |
481 | if ((res = psiconv_parse_paint_data_section(buf,lev+2,off+len,&leng,0, |
518 | &((*result)->picture)))) |
482 | &((*result)->picture)))) |
519 | goto ERROR2; |
483 | goto ERROR2; |
520 | off += leng; |
484 | off += leng; |
521 | if (!is_object) { |
|
|
522 | (*result)->picture_xsize = (*result)->picture->xsize; |
|
|
523 | (*result)->picture_ysize = (*result)->picture->ysize; |
|
|
524 | } |
|
|
525 | |
485 | |
526 | psiconv_progress(lev+2,off+len,"Going to read the hor. magnification"); |
486 | psiconv_progress(lev+2,off+len,"Going to read the hor. magnification"); |
527 | (*result)->magnification_x = psiconv_read_u16(buf,lev+2,off+len,&res)/1000.0; |
487 | (*result)->magnification_x = psiconv_read_u16(buf,lev+2,off+len,&res)/1000.0; |
528 | if (res) |
488 | if (res) |
529 | goto ERROR3; |
489 | goto ERROR3; |
… | |
… | |
540 | |
500 | |
541 | psiconv_progress(lev+2,off+len,"Going to read the left cut"); |
501 | psiconv_progress(lev+2,off+len,"Going to read the left cut"); |
542 | temp = psiconv_read_u32(buf,lev+2,off + len,&res); |
502 | temp = psiconv_read_u32(buf,lev+2,off + len,&res); |
543 | if (res) |
503 | if (res) |
544 | goto ERROR3; |
504 | goto ERROR3; |
545 | (*result)->cut_left = (temp * 6.0) / (*result)->picture_xsize; |
505 | (*result)->cut_left = (temp * 6.0) / (*result)->displayed_xsize; |
546 | psiconv_debug(lev+2,off+len,"Left cut: raw %08x, real: %f", |
506 | psiconv_debug(lev+2,off+len,"Left cut: raw %08x, real: %f", |
547 | temp,(*result)->cut_left); |
507 | temp,(*result)->cut_left); |
548 | len += 0x04; |
508 | len += 0x04; |
549 | psiconv_progress(lev+2,off+len,"Going to read the right cut"); |
509 | psiconv_progress(lev+2,off+len,"Going to read the right cut"); |
550 | temp = psiconv_read_u32(buf,lev+2,off + len,&res); |
510 | temp = psiconv_read_u32(buf,lev+2,off + len,&res); |
551 | if (res) |
511 | if (res) |
552 | goto ERROR3; |
512 | goto ERROR3; |
553 | (*result)->cut_right = (temp * 6.0) / (*result)->picture_xsize; |
513 | (*result)->cut_right = (temp * 6.0) / (*result)->displayed_xsize; |
554 | psiconv_debug(lev+2,off+len,"Right cut: raw %08x, real: %f", |
514 | psiconv_debug(lev+2,off+len,"Right cut: raw %08x, real: %f", |
555 | temp,(*result)->cut_right); |
515 | temp,(*result)->cut_right); |
556 | len += 0x04; |
516 | len += 0x04; |
557 | psiconv_progress(lev+2,off+len,"Going to read the top cut"); |
517 | psiconv_progress(lev+2,off+len,"Going to read the top cut"); |
558 | temp = psiconv_read_u32(buf,lev+2,off + len,&res); |
518 | temp = psiconv_read_u32(buf,lev+2,off + len,&res); |
559 | if (res) |
519 | if (res) |
560 | goto ERROR3; |
520 | goto ERROR3; |
561 | (*result)->cut_top = (temp * 6.0) / (*result)->picture_ysize; |
521 | (*result)->cut_top = (temp * 6.0) / (*result)->displayed_ysize; |
562 | psiconv_debug(lev+2,off+len,"Top cut: raw %08x, real: %f", |
522 | psiconv_debug(lev+2,off+len,"Top cut: raw %08x, real: %f", |
563 | temp,(*result)->cut_top); |
523 | temp,(*result)->cut_top); |
564 | len += 0x04; |
524 | len += 0x04; |
565 | psiconv_progress(lev+2,off+len,"Going to read the bottom cut"); |
525 | psiconv_progress(lev+2,off+len,"Going to read the bottom cut"); |
566 | temp = psiconv_read_u32(buf,lev+2,off + len,&res); |
526 | temp = psiconv_read_u32(buf,lev+2,off + len,&res); |
567 | if (res) |
527 | if (res) |
568 | goto ERROR3; |
528 | goto ERROR3; |
569 | (*result)->cut_bottom = (temp * 6.0) / (*result)->picture_ysize; |
529 | (*result)->cut_bottom = (temp * 6.0) / (*result)->displayed_ysize; |
570 | psiconv_debug(lev+2,off+len,"Bottom cut: raw %08x, real: %f", |
530 | psiconv_debug(lev+2,off+len,"Bottom cut: raw %08x, real: %f", |
571 | temp,(*result)->cut_bottom); |
531 | temp,(*result)->cut_bottom); |
572 | len += 0x04; |
532 | len += 0x04; |
573 | |
533 | |
574 | if (length) |
534 | if (length) |