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

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

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