comparison tools/lib64gfx.c @ 1697:1036b0dcccb5

Refactor DMGrowBuf so that there can be buffers that grow "backwards". This also removes some support functions like the buffer state push/pop.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 05 Jun 2018 12:55:17 +0300
parents 09adf5328510
children a0986cfd6f9d
comparison
equal deleted inserted replaced
1696:cf0fddd4bf52 1697:1036b0dcccb5
903 "Could not allocate %d bytes of memory for C64 image encoding buffer.\n", 903 "Could not allocate %d bytes of memory for C64 image encoding buffer.\n",
904 fmt->size); 904 fmt->size);
905 goto err; 905 goto err;
906 } 906 }
907 907
908 dmGrowBufPush(buf); 908 if (buf->backwards)
909 {
910 dmError(DMERR_INVALID_DATA,
911 "Buffer specified for dmC64EncodeGenericBMP() is in backwards mode, which is not supported.\n");
912 goto err;
913 }
909 914
910 // Perform encoding 915 // Perform encoding
911 for (int i = 0; i < D64_MAX_ENCDEC_OPS; i++) 916 for (int i = 0; i < D64_MAX_ENCDEC_OPS; i++)
912 { 917 {
913 const DMC64EncDecOp *op = fmtGetEncDecOp(fmt, i); 918 const DMC64EncDecOp *op = fmtGetEncDecOp(fmt, i);
933 i, op->type, op->offs, op->offs, op->bank, size, size, op->size, op->size); 938 i, op->type, op->offs, op->offs, op->bank, size, size, op->size, op->size);
934 goto err; 939 goto err;
935 } 940 }
936 941
937 // Do we need to reallocate some more space? 942 // Do we need to reallocate some more space?
938 chksize = op->offs + size; 943 chksize = buf->offs + op->offs + size;
939 if (!dmGrowBufCheckGrow(buf, chksize)) 944 if (!dmGrowBufCheckGrow(buf, chksize))
940 { 945 {
941 res = dmError(DMERR_MALLOC, 946 res = dmError(DMERR_MALLOC,
942 "Could not re-allocate %d bytes of memory for C64 image encoding buffer.\n", 947 "Could not re-allocate %d bytes of memory for C64 image encoding buffer.\n",
943 chksize); 948 chksize);
946 951
947 if (chksize > buf->len) 952 if (chksize > buf->len)
948 buf->len = chksize; 953 buf->len = chksize;
949 954
950 // Perform operation 955 // Perform operation
951 Uint8 *dst; 956 Uint8 *dst = buf->data + buf->offs + op->offs;
952 dst = buf->data + op->offs;
953 switch (op->type) 957 switch (op->type)
954 { 958 {
955 case DO_COPY: 959 case DO_COPY:
956 case DO_SET_MEM: 960 case DO_SET_MEM:
957 case DO_SET_OP: 961 case DO_SET_OP:
1058 } 1062 }
1059 break; 1063 break;
1060 } 1064 }
1061 } 1065 }
1062 1066
1063 dmGrowBufPop(buf);
1064
1065 res = DMERR_OK; 1067 res = DMERR_OK;
1066 1068
1067 err: 1069 err:
1068 return res; 1070 return res;
1069 } 1071 }