comparison tools/lib64gfx.c @ 927:db495f421242

Change dmC64DefaultSizes[] array into a function instead.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 25 Feb 2015 15:36:07 +0200
parents 23b14d62bf67
children 2270d7f3af77
comparison
equal deleted inserted replaced
926:3132868d1548 927:db495f421242
51 { 0x6C, 0x5E, 0xB5, 0xff }, 51 { 0x6C, 0x5E, 0xB5, 0xff },
52 { 0x95, 0x95, 0x95, 0xff }, 52 { 0x95, 0x95, 0x95, 0xff },
53 }; 53 };
54 54
55 55
56 const size_t dmC64DefaultSizes[DT_LAST] =
57 {
58 C64_SCR_COLOR_SIZE,
59 C64_SCR_BITMAP_SIZE,
60 C64_SCR_SCREEN_SIZE,
61 1,
62 0,
63 C64_SCR_EXTRADATA,
64 0,
65 0,
66 C64_MAX_CHARS * C64_CHR_HEIGHT * C64_CHR_WIDTH,
67 0
68 };
69
70
71 #define DM_GET_ADDR_LO(addr) ((addr) & 0xff) 56 #define DM_GET_ADDR_LO(addr) ((addr) & 0xff)
72 #define DM_GET_ADDR_HI(addr) (((addr) >> 8) & 0xff) 57 #define DM_GET_ADDR_HI(addr) (((addr) >> 8) & 0xff)
73 58
74 59
75 static BOOL dmCompareAddr16(const Uint8 *buf, const size_t offs, const Uint16 addr) 60 static BOOL dmCompareAddr16(const Uint8 *buf, const size_t offs, const Uint16 addr)
638 623
639 return DMERR_OK; 624 return DMERR_OK;
640 } 625 }
641 626
642 627
628 static int dmC64GetOpSize(const DMC64EncDecOp *op, const DMC64ImageFormat *fmt)
629 {
630 if (op->size != 0)
631 return op->size;
632
633 switch (op->type)
634 {
635 case DT_SCREEN_RAM:
636 return C64_SCREEN_SIZE;
637
638 case DT_COLOR_RAM:
639 return C64_COLOR_SIZE;
640
641 case DT_BITMAP:
642 return C64_BITMAP_SIZE;
643
644 case DT_EXTRADATA:
645 return C64_SCR_EXTRADATA;
646
647 case DT_CHAR_DATA:
648 return C64_MAX_CHARS * C64_CHR_HEIGHT * C64_CHR_WIDTH;
649
650 case DT_COLOR_REG:
651 return 1;
652
653 default:
654 return 0;
655 }
656 }
657
658
643 int dmC64DecodeGenericBMP(DMC64Image *img, const Uint8 *buf, 659 int dmC64DecodeGenericBMP(DMC64Image *img, const Uint8 *buf,
644 const size_t len, const DMC64ImageFormat *fmt) 660 const size_t len, const DMC64ImageFormat *fmt)
645 { 661 {
646 int i; 662 int i;
647 663
669 // Check operation validity 685 // Check operation validity
670 if ((res = dmC64SanityCheckEncDecOp(i, op)) != DMERR_OK) 686 if ((res = dmC64SanityCheckEncDecOp(i, op)) != DMERR_OK)
671 return res; 687 return res;
672 688
673 // Check size 689 // Check size
674 size = (op->size == 0) ? dmC64DefaultSizes[op->type] : op->size; 690 size = dmC64GetOpSize(op, fmt);
675 691
676 // Do we need to reallocate some more space? 692 // Do we need to reallocate some more space?
677 if (op->offs + size > len) 693 if (op->offs + size > len)
678 { 694 {
679 dmError("Decode out of bounds, op #%d type=%d, offs=%d ($%04x), " 695 dmError("Decode out of bounds, op #%d type=%d, offs=%d ($%04x), "
813 // Check operation validity 829 // Check operation validity
814 if ((res = dmC64SanityCheckEncDecOp(i, op)) != DMERR_OK) 830 if ((res = dmC64SanityCheckEncDecOp(i, op)) != DMERR_OK)
815 goto error; 831 goto error;
816 832
817 // Check size 833 // Check size
818 size = (op->size == 0) ? dmC64DefaultSizes[op->type] : op->size; 834 size = dmC64GetOpSize(op, fmt);
819 835
820 // Do we need to reallocate some more space? 836 // Do we need to reallocate some more space?
821 if (2 + op->offs + size > allocated) 837 if (2 + op->offs + size > allocated)
822 { 838 {
823 size_t diff = allocated - (op->offs + size + 2), 839 size_t diff = allocated - (op->offs + size + 2),