/[public]/psiconv/trunk/lib/psiconv/parse_image.c
ViewVC logotype

Diff of /psiconv/trunk/lib/psiconv/parse_image.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 97 Revision 163
22 22
23#include <stdlib.h> 23#include <stdlib.h>
24 24
25#include "parse_routines.h" 25#include "parse_routines.h"
26#include "error.h" 26#include "error.h"
27
28#ifdef DMALLOC
29#include <dmalloc.h>
30#endif
31
27 32
28int psiconv_parse_jumptable_section(const psiconv_buffer buf,int lev, 33int psiconv_parse_jumptable_section(const psiconv_buffer buf,int lev,
29 psiconv_u32 off, int *length, 34 psiconv_u32 off, int *length,
30 psiconv_jumptable_section *result) 35 psiconv_jumptable_section *result)
31{ 36{
382 else 387 else
383 return res; 388 return res;
384} 389}
385 390
386int psiconv_parse_sketch_section(const psiconv_buffer buf, int lev, 391int psiconv_parse_sketch_section(const psiconv_buffer buf, int lev,
387 psiconv_u32 off, int *length, int is_object, 392 psiconv_u32 off, int *length,
388 psiconv_sketch_section *result) 393 psiconv_sketch_section *result)
389{ 394{
390 int res=0; 395 int res=0;
391 int len=0; 396 int len=0;
392 psiconv_u32 temp; 397 psiconv_u32 temp;
393 int leng; 398 int leng;
394 int i;
395 399
396 psiconv_progress(lev+1,off,"Going to read the sketch section"); 400 psiconv_progress(lev+1,off,"Going to read the sketch section");
397 if (!(*result = malloc(sizeof(**result)))) 401 if (!(*result = malloc(sizeof(**result))))
398 goto ERROR1; 402 goto ERROR1;
399 403
400 if (!is_object) {
401 psiconv_progress(lev+2,off+len,"Going to read the form hor. size");
402 (*result)->form_xsize = psiconv_read_u16(buf,lev+2,off + len,&res);
403 if (res)
404 goto ERROR2;
405 psiconv_debug(lev+2,off+len,"Form hor. size: %04x",
406 (*result)->form_xsize);
407 len += 0x02;
408 psiconv_progress(lev+2,off+len,"Going to read the form ver. size");
409 (*result)->form_ysize = psiconv_read_u16(buf,lev+2,off + len,&res);
410 if (res)
411 goto ERROR2;
412 psiconv_debug(lev+2,off+len,"Form ver. size: %04x",
413 (*result)->form_ysize);
414 len += 0x02;
415 psiconv_progress(lev+2,off+len,"Going to read the picture hor. offset");
416 (*result)->picture_x_offset = psiconv_read_u16(buf,lev+2,off + len,&res);
417 if (res)
418 goto ERROR2;
419 psiconv_debug(lev+2,off+len,"Picture hor. offset: %04x",
420 (*result)->picture_x_offset);
421 len += 0x02;
422 psiconv_progress(lev+2,off+len,"Going to read the picture ver. offset");
423 (*result)->picture_y_offset = psiconv_read_u16(buf,lev+2,off + len,&res);
424 if (res)
425 goto ERROR2;
426 psiconv_debug(lev+2,off+len,"Picture ver. offset: %04x",
427 (*result)->picture_y_offset);
428 len += 0x02;
429 psiconv_progress(lev+2,off+len,"Going to skip 5 words of zeros");
430 for (i = 0; i < 5; i++) {
431 temp = psiconv_read_u16(buf,lev+2,off+len,&res);
432 if (res)
433 goto ERROR2;
434 if (temp != 0) {
435 psiconv_warn(lev+2,off+len,
436 "Unexpected value in sketch section preamble (ignored)");
437 psiconv_debug(lev+2,off+len,"Word %d: Read %04x, expected %04x",i,
438 temp,0);
439 }
440 off += 0x02;
441 }
442 } else {
443 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");
444 (*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);
445 if (res) 406 if (res)
446 goto ERROR2; 407 goto ERROR2;
447 psiconv_debug(lev+2,off+len,"Displayed hor. size: %04x", 408 psiconv_debug(lev+2,off+len,"Displayed hor. size: %04x",
448 (*result)->picture_xsize); 409 (*result)->displayed_xsize);
449 len += 0x02; 410 len += 0x02;
450 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");
451 (*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);
452 if (res) 413 if (res)
453 goto ERROR2; 414 goto ERROR2;
454 psiconv_debug(lev+2,off+len,"Displayed ver. size: %04x", 415 psiconv_debug(lev+2,off+len,"Displayed ver. size: %04x",
455 (*result)->picture_ysize); 416 (*result)->displayed_ysize);
456 len += 0x02; 417 len += 0x02;
457 418
458 psiconv_progress(lev+2,off+len,"Going to skip 2 words of zeros");
459 for (i = 0; i < 2; i++) {
460 temp = psiconv_read_u16(buf,lev+2,off+len,&res);
461 if (res)
462 goto ERROR2;
463 if (temp != 0) {
464 psiconv_warn(lev+2,off+len,
465 "Unexpected value in sketch section preamble (ignored)");
466 psiconv_debug(lev+2,off+len,"Word %d: Read %04x, expected %04x",i,
467 temp,0);
468 }
469 off += 0x02;
470 }
471 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");
472 (*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);
473 if (res) 422 if (res)
474 goto ERROR2; 423 goto ERROR2;
475 psiconv_debug(lev+2,off+len,"Picture hor. offset: %04x", 424 psiconv_debug(lev+2,off+len,"Data hor. offset: %04x",
476 (*result)->picture_x_offset); 425 (*result)->picture_data_x_offset);
477 len += 0x02; 426 len += 0x02;
478 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");
479 (*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);
480 if (res) 430 if (res)
481 goto ERROR2; 431 goto ERROR2;
482 psiconv_debug(lev+2,off+len,"Picture ver. offset: %04x", 432 psiconv_debug(lev+2,off+len,"Data ver. offset: %04x",
483 (*result)->picture_y_offset); 433 (*result)->picture_data_y_offset);
484 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
485 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");
486 (*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);
487 if (res) 455 if (res)
488 goto ERROR2; 456 goto ERROR2;
489 psiconv_debug(lev+2,off+len,"Form hor. size: %04x", 457 psiconv_debug(lev+2,off+len,"Form hor. size: %04x",
490 (*result)->form_xsize); 458 (*result)->form_xsize);
491 len += 0x02; 459 len += 0x02;
492 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");
493 (*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);
494 if (res) 462 if (res)
495 goto ERROR2; 463 goto ERROR2;
496 psiconv_debug(lev+2,off+len,"Form ver. size: %04x", 464 psiconv_debug(lev+2,off+len,"Form ver. size: %04x",
497 (*result)->form_ysize); 465 (*result)->form_ysize);
498 len += 0x02; 466 len += 0x02;
467
499 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");
500 temp = psiconv_read_u16(buf,lev+2,off+len,&res); 469 temp = psiconv_read_u16(buf,lev+2,off+len,&res);
501 if (res) 470 if (res)
502 goto ERROR2; 471 goto ERROR2;
503 if (temp != 0) { 472 if (temp != 0) {
504 psiconv_warn(lev+2,off+len, 473 psiconv_warn(lev+2,off+len,
505 "Unexpected value in sketch section preamble (ignored)"); 474 "Unexpected value in sketch section preamble (ignored)");
506 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);
507 } 477 }
508 off += 0x02; 478 off += 0x02;
509 }
510 479
511 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");
512 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,
513 &((*result)->picture)))) 482 &((*result)->picture))))
514 goto ERROR2; 483 goto ERROR2;
515 off += leng; 484 off += leng;
516 if (!is_object) {
517 (*result)->picture_xsize = (*result)->picture->xsize;
518 (*result)->picture_ysize = (*result)->picture->ysize;
519 }
520 485
521 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");
522 (*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;
523 if (res) 488 if (res)
524 goto ERROR3; 489 goto ERROR3;
535 500
536 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");
537 temp = psiconv_read_u32(buf,lev+2,off + len,&res); 502 temp = psiconv_read_u32(buf,lev+2,off + len,&res);
538 if (res) 503 if (res)
539 goto ERROR3; 504 goto ERROR3;
540 (*result)->cut_left = (temp * 6.0) / (*result)->picture_xsize; 505 (*result)->cut_left = (temp * 6.0) / (*result)->displayed_xsize;
541 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",
542 temp,(*result)->cut_left); 507 temp,(*result)->cut_left);
543 len += 0x04; 508 len += 0x04;
544 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");
545 temp = psiconv_read_u32(buf,lev+2,off + len,&res); 510 temp = psiconv_read_u32(buf,lev+2,off + len,&res);
546 if (res) 511 if (res)
547 goto ERROR3; 512 goto ERROR3;
548 (*result)->cut_right = (temp * 6.0) / (*result)->picture_xsize; 513 (*result)->cut_right = (temp * 6.0) / (*result)->displayed_xsize;
549 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",
550 temp,(*result)->cut_right); 515 temp,(*result)->cut_right);
551 len += 0x04; 516 len += 0x04;
552 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");
553 temp = psiconv_read_u32(buf,lev+2,off + len,&res); 518 temp = psiconv_read_u32(buf,lev+2,off + len,&res);
554 if (res) 519 if (res)
555 goto ERROR3; 520 goto ERROR3;
556 (*result)->cut_top = (temp * 6.0) / (*result)->picture_ysize; 521 (*result)->cut_top = (temp * 6.0) / (*result)->displayed_ysize;
557 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",
558 temp,(*result)->cut_top); 523 temp,(*result)->cut_top);
559 len += 0x04; 524 len += 0x04;
560 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");
561 temp = psiconv_read_u32(buf,lev+2,off + len,&res); 526 temp = psiconv_read_u32(buf,lev+2,off + len,&res);
562 if (res) 527 if (res)
563 goto ERROR3; 528 goto ERROR3;
564 (*result)->cut_bottom = (temp * 6.0) / (*result)->picture_ysize; 529 (*result)->cut_bottom = (temp * 6.0) / (*result)->displayed_ysize;
565 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",
566 temp,(*result)->cut_bottom); 531 temp,(*result)->cut_bottom);
567 len += 0x04; 532 len += 0x04;
568 533
569 if (length) 534 if (length)

Legend:
Removed from v.97  
changed lines
  Added in v.163

frodo@frodo.looijaard.name
ViewVC Help
Powered by ViewVC 1.1.26