Mercurial > hg > dmlib
diff tools/lib64gfx.c @ 1505:3265175b24d2
Change the passing of RLE compression/decompression parameters to be in a dedicated struct.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 11 May 2018 20:18:14 +0300 |
parents | c7b9ef56319b |
children | 4fd4e7a00db4 |
line wrap: on
line diff
--- a/tools/lib64gfx.c Fri May 11 07:50:18 2018 +0300 +++ b/tools/lib64gfx.c Fri May 11 20:18:14 2018 +0300 @@ -248,8 +248,7 @@ } -int dmDecodeGenericRLE(DMGrowBuf *dst, const Uint8 *src, const Uint8 *srcEnd, - const Uint8 rleMarker, const Uint8 rleMask1, const Uint8 rleMask2, const int rleType) +int dmDecodeGenericRLE(DMGrowBuf *dst, const Uint8 *src, const Uint8 *srcEnd, const DMCompParams *cfg) { int res; @@ -262,11 +261,11 @@ Uint8 data = *src++; int count = 1; - switch (rleType) + switch (cfg->type) { - case DM_RLE_MARKER: + case DM_COMP_RLE_MARKER: // A simple marker byte RLE variant: [Marker] [count] [data] - if (data == rleMarker) + if (data == cfg->rleMarker) { if (srcEnd - src < 2) { @@ -278,10 +277,10 @@ } break; - case DM_RLE_MASK: + case DM_COMP_RLE_MASK: // Mask marker RLE: usually high bit(s) of byte mark RLE sequence // and the lower bits contain the count: [Mask + count] [data] - if ((data & rleMask1) == rleMarker) + if ((data & cfg->rleMask1) == cfg->rleMarker) { if (srcEnd - src < 1) { @@ -289,7 +288,7 @@ goto err; } - count = data & rleMask2; + count = data & cfg->rleMask2; data = *src++; } break; @@ -312,27 +311,27 @@ } -int dmDecodeGenericRLEAlloc(DMGrowBuf *dst, const Uint8 *src, const Uint8 *srcEnd, - const Uint8 rleMarker, const Uint8 rleMask1, const Uint8 rleMask2, const int rleType) +int dmDecodeGenericRLEAlloc(DMGrowBuf *dst, const Uint8 *src, const Uint8 *srcEnd, const DMCompParams *cfg) { int res; if ((res = dmGrowBufAlloc(dst, BUF_SIZE_INITIAL, BUF_SIZE_GROW)) != DMERR_OK) return res; - return dmDecodeGenericRLE(dst, src, srcEnd, rleMarker, rleMask1, rleMask2, rleType); + return dmDecodeGenericRLE(dst, src, srcEnd, cfg); } -static BOOL dmEncodeGenericRLESequence(DMGrowBuf *dst, const Uint8 data, Uint8 count, const Uint8 rleMarker, const Uint8 rleMinCount, const int rleType) +static BOOL dmEncodeGenericRLESequence(DMGrowBuf *dst, const Uint8 data, Uint8 count, const DMCompParams *cfg) { BOOL copyOnly = FALSE; - switch (rleType) + + switch (cfg->type) { - case DM_RLE_MARKER: - if (count >= rleMinCount || data == rleMarker) + case DM_COMP_RLE_MARKER: + if (count >= cfg->rleMinCount || data == cfg->rleMarker) { // A simple marker byte RLE variant: [Marker] [count] [data] - if (!dmGrowBufPutU8(dst, rleMarker) || + if (!dmGrowBufPutU8(dst, cfg->rleMarker) || !dmGrowBufPutU8(dst, count) || !dmGrowBufPutU8(dst, data)) return FALSE; @@ -341,12 +340,12 @@ copyOnly = TRUE; break; - case DM_RLE_MASK: - if (count >= rleMinCount || (data & rleMarker) == rleMarker) + case DM_COMP_RLE_MASK: + if (count >= cfg->rleMinCount || (data & cfg->rleMarker) == cfg->rleMarker) { // Mask marker RLE: usually high bit(s) of byte mark RLE sequence // and the lower bits contain the count: [Mask + count] [data] - if (!dmGrowBufPutU8(dst, rleMarker | count) || + if (!dmGrowBufPutU8(dst, cfg->rleMarker | count) || !dmGrowBufPutU8(dst, data)) return FALSE; } @@ -368,20 +367,22 @@ } -int dmEncodeGenericRLE(DMGrowBuf *dst, const Uint8 *src, const Uint8 *srcEnd, - const Uint8 rleMarker, const Uint8 rleMinCount, const Uint8 rleMaxCount, const int rleType) +int dmEncodeGenericRLE(DMGrowBuf *dst, const Uint8 *src, const Uint8 *srcEnd, const DMCompParams *cfg) { int res; + fprintf(stderr, "encrle: len=%d, rleMarker=%02x, rleMinCount=%d, rleMaxCount=%d, type=%d\n", + srcEnd - src, cfg->rleMarker, cfg->rleMinCount, cfg->rleMaxCount, cfg->type); + // Perform RLE encoding int count = 0, prev; while (src < srcEnd) { Uint8 data = *src++; - if (data != prev || count >= rleMaxCount) + if (data != prev || count >= cfg->rleMaxCount) { - if (!dmEncodeGenericRLESequence(dst, prev, count, rleMarker, rleMinCount, rleType)) + if (!dmEncodeGenericRLESequence(dst, prev, count, cfg)) { res = dmError(DMERR_MALLOC, "Could reallocate memory for RLE encoding buffer.\n"); @@ -403,14 +404,13 @@ } -int dmEncodeGenericRLEAlloc(DMGrowBuf *dst, const Uint8 *src, const Uint8 *srcEnd, - const Uint8 rleMarker, const Uint8 rleMinCount, const Uint8 rleMaxCount, const int rleType) +int dmEncodeGenericRLEAlloc(DMGrowBuf *dst, const Uint8 *src, const Uint8 *srcEnd, const DMCompParams *cfg) { int res; if ((res = dmGrowBufAlloc(dst, BUF_SIZE_INITIAL, BUF_SIZE_GROW)) != DMERR_OK) return res; - return dmEncodeGenericRLE(dst, src, srcEnd, rleMarker, rleMinCount, rleMaxCount, rleType); + return dmEncodeGenericRLE(dst, src, srcEnd, cfg); }