changeset 1713:0a9110b4d036

Add few RLE helper functions.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 06 Jun 2018 14:31:04 +0300
parents 1f4ed247763d
children 95317672ff00
files tools/lib64gfx.c tools/lib64gfx.h
diffstat 2 files changed, 28 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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;
 }
 
 
--- 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);