comparison tools/lib64gfx.c @ 1933:c5a46cb4cce5

Change DMC64ImageFormat parameter of dmC64GetSubjectSize() and dmC64GetOpSubjectSize() to DMC64ImageCommonFormat.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 28 Jun 2018 18:55:21 +0300
parents 410679d2fe8a
children d9a0a4bccf5d
comparison
equal deleted inserted replaced
1932:10e82be38b8b 1933:c5a46cb4cce5
765 765
766 return DMERR_OK; 766 return DMERR_OK;
767 } 767 }
768 768
769 769
770 size_t dmC64GetSubjectSize(const int subject, const DMC64ImageFormat *fmt) 770 size_t dmC64GetSubjectSize(const int subject, const DMC64ImageCommonFormat *fmt)
771 { 771 {
772 switch (subject) 772 switch (subject)
773 { 773 {
774 case DS_SCREEN_RAM: 774 case DS_SCREEN_RAM:
775 case DS_COLOR_RAM: 775 case DS_COLOR_RAM:
776 return fmt->format->chHeight * fmt->format->chWidth; 776 return fmt->chHeight * fmt->chWidth;
777 break; 777 break;
778 778
779 case DS_BITMAP_RAM: 779 case DS_BITMAP_RAM:
780 return fmt->format->chHeight * fmt->format->chWidth * 8; 780 return fmt->chHeight * fmt->chWidth * 8;
781 break; 781 break;
782 782
783 case DS_CHAR_DATA: 783 case DS_CHAR_DATA:
784 return C64_MAX_CHARS * C64_CHR_SIZE; 784 return C64_MAX_CHARS * C64_CHR_SIZE;
785 break; 785 break;
799 break; 799 break;
800 } 800 }
801 } 801 }
802 802
803 803
804 size_t dmC64GetOpSubjectSize(const DMC64EncDecOp *op, const DMC64ImageFormat *fmt) 804 size_t dmC64GetOpSubjectSize(const DMC64EncDecOp *op, const DMC64ImageCommonFormat *fmt)
805 { 805 {
806 size_t size = dmC64GetSubjectSize(op->subject, fmt); 806 size_t size = dmC64GetSubjectSize(op->subject, fmt);
807 807
808 // If the operator specified size is larger, use it. 808 // If the operator specified size is larger, use it.
809 if (op->size > size) 809 if (op->size > size)
886 // Check operation validity 886 // Check operation validity
887 if ((res = dmC64SanityCheckEncDecOp(i, op, img)) != DMERR_OK) 887 if ((res = dmC64SanityCheckEncDecOp(i, op, img)) != DMERR_OK)
888 return res; 888 return res;
889 889
890 // Is the operation inside the bounds? 890 // Is the operation inside the bounds?
891 size = dmC64GetOpSubjectSize(op, fmt); 891 size = dmC64GetOpSubjectSize(op, fmt->format);
892 if (op->type == DO_COPY && op->offs + size > buf->len + 1) 892 if (op->type == DO_COPY && op->offs + size > buf->len + 1)
893 { 893 {
894 return dmError(DMERR_INVALID_DATA, 894 return dmError(DMERR_INVALID_DATA,
895 "Decode SRC out of bounds, op #%d type=%d, subj=%s, offs=%d ($%04x), " 895 "Decode SRC out of bounds, op #%d type=%d, subj=%s, offs=%d ($%04x), "
896 "bank=%d, size=%d ($%04x) @ %d ($%04x)\n", 896 "bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
1091 // Check operation validity 1091 // Check operation validity
1092 if ((res = dmC64SanityCheckEncDecOp(i, op, img)) != DMERR_OK) 1092 if ((res = dmC64SanityCheckEncDecOp(i, op, img)) != DMERR_OK)
1093 goto err; 1093 goto err;
1094 1094
1095 // Do we need to reallocate some more space? 1095 // Do we need to reallocate some more space?
1096 size = dmC64GetOpSubjectSize(op, fmt); 1096 size = dmC64GetOpSubjectSize(op, fmt->format);
1097 chksize = buf->offs + op->offs + size; 1097 chksize = buf->offs + op->offs + size;
1098 if (!dmGrowBufCheckGrow(buf, chksize)) 1098 if (!dmGrowBufCheckGrow(buf, chksize))
1099 { 1099 {
1100 res = dmError(DMERR_MALLOC, 1100 res = dmError(DMERR_MALLOC,
1101 "Could not re-allocate %d bytes of memory for C64 image encoding buffer.\n", 1101 "Could not re-allocate %d bytes of memory for C64 image encoding buffer.\n",