# HG changeset patch # User Matti Hamalainen # Date 1526084905 -10800 # Node ID acad4974dc093030553cedf82ebfb47d1584dfd6 # Parent 907160399b24ba6407861c5f48586715c3aa27ee Use the DMGrowBuf push/pop functionality to better implement the stacked generic encoding of c64 bitmap formats. diff -r 907160399b24 -r acad4974dc09 tools/lib64gfx.c --- 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: