# HG changeset patch # User Matti Hamalainen # Date 1528284664 -10800 # Node ID 0a9110b4d0362ea1cdebfe27e998ace40223e236 # Parent 1f4ed247763d4de270157b29aac4c726df59f204 Add few RLE helper functions. diff -r 1f4ed247763d -r 0a9110b4d036 tools/lib64gfx.c --- a/tools/lib64gfx.c Wed Jun 06 14:29:05 2018 +0300 +++ b/tools/lib64gfx.c Wed Jun 06 14:31:04 2018 +0300 @@ -327,7 +327,7 @@ } -static void dmSetupRLEBuffers(DMGrowBuf *dst, DMGrowBuf *src, const DMCompParams *cfg) +void dmSetupRLEBuffers(DMGrowBuf *dst, DMGrowBuf *src, const DMCompParams *cfg) { if (cfg->flags & DM_RLE_BACKWARDS_INPUT) { @@ -340,6 +340,30 @@ dst->backwards = TRUE; dst->offs = dst->size - 1; } +void dmFinishRLEBuffers(DMGrowBuf *dst, DMGrowBuf *src, const DMCompParams *cfg) +{ + if (cfg->flags & DM_RLE_BACKWARDS_OUTPUT) + { + memmove(dst->data, dst->data + dst->offs, dst->len); + dst->offs = 0; + } +} + + +int dmGenericRLEOutputRun(DMGrowBuf *dst, const DMCompParams *cfg, const Uint8 data, const unsigned int count) +{ + unsigned int scount; + for (scount = count; scount; scount--) + { + if (!dmGrowBufPutU8(dst, data)) + { + return dmError(DMERR_MALLOC, + "%s: RLE: Could not output RLE run %d x 0x%02x @ " + "offs=0x%" DM_PRIx_SIZE_T ", size=0x%" DM_PRIx_SIZE_T ".\n", + cfg->func, count, data, dst->offs, dst->size); + } + } + return DMERR_OK; } diff -r 1f4ed247763d -r 0a9110b4d036 tools/lib64gfx.h --- a/tools/lib64gfx.h Wed Jun 06 14:29:05 2018 +0300 +++ b/tools/lib64gfx.h Wed Jun 06 14:31:04 2018 +0300 @@ -310,6 +310,9 @@ void dmGenericRLEAnalyze(const DMGrowBuf *buf, DMCompParams *cfg); +void dmSetupRLEBuffers(DMGrowBuf *dst, DMGrowBuf *src, const DMCompParams *cfg); +void dmFinishRLEBuffers(DMGrowBuf *dst, DMGrowBuf *src, const DMCompParams *cfg); +int dmGenericRLEOutputRun(DMGrowBuf *dst, const DMCompParams *cfg, const Uint8 data, const unsigned int count); int dmDecodeGenericRLE(DMGrowBuf *dst, const DMGrowBuf *src, const DMCompParams *cfg); int dmDecodeGenericRLEAlloc(DMGrowBuf *dst, const DMGrowBuf *src, const DMCompParams *cfg);