changeset 1534:acad4974dc09

Use the DMGrowBuf push/pop functionality to better implement the stacked generic encoding of c64 bitmap formats.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 12 May 2018 03:28:25 +0300
parents 907160399b24
children 2f7ff28ea56e
files tools/lib64gfx.c
diffstat 1 files changed, 5 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/tools/lib64gfx.c	Sat May 12 03:26:14 2018 +0300
+++ b/tools/lib64gfx.c	Sat May 12 03:28:25 2018 +0300
@@ -676,7 +676,6 @@
 int dmC64EncodeGenericBMP(const BOOL allocate, DMGrowBuf *buf, const DMC64Image *img, const DMC64ImageFormat *fmt)
 {
     int res = DMERR_OK;
-    size_t boffs;
 
     if (img == NULL || fmt == NULL)
         return DMERR_NULLPTR;
@@ -690,7 +689,7 @@
         goto err;
     }
 
-    boffs = buf->len;
+    dmGrowBufPush(buf);
 
     // Perform encoding
     for (int i = 0; i < D64_MAX_ENCDEC_OPS; i++)
@@ -717,7 +716,7 @@
         }
 
         // Do we need to reallocate some more space?
-        chksize = op->offs + size + boffs;
+        chksize = op->offs + size;
         if (!dmGrowBufCheckGrow(buf, chksize))
         {
             res = dmError(DMERR_MALLOC,
@@ -730,7 +729,7 @@
             buf->len = chksize;
 
         // Perform operation
-        Uint8 *dst = buf->data + boffs + op->offs;
+        Uint8 *dst = buf->data + op->offs;
         switch (op->type)
         {
             case DT_COLOR_RAM:   memcpy(dst, img->color[op->bank], size); break;
@@ -796,6 +795,8 @@
         }
     }
 
+    dmGrowBufPop(buf);
+
     res = DMERR_OK;
 
 err: