changeset 1573:86373ac0861a

Implement another RLE variant, with different ordering of marker, count and data bytes.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 13 May 2018 09:08:18 +0300
parents 4643cd757c0b
children 0b0870a216e9
files tools/lib64fmts.c tools/lib64gfx.c tools/lib64gfx.h
diffstat 3 files changed, 45 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/tools/lib64fmts.c	Sun May 13 08:23:58 2018 +0300
+++ b/tools/lib64fmts.c	Sun May 13 09:08:18 2018 +0300
@@ -54,7 +54,7 @@
     DMGrowBuf mem;
     DMCompParams cfg;
 
-    cfg.type = DM_COMP_RLE_MARKER;
+    cfg.type = DM_COMP_RLE_MARKER1;
     cfg.rleMarker = *(buf + 0x0d);
 
     if ((res = dmDecodeGenericRLEAlloc(&mem, buf + 0x0e, buf + len, &cfg)) != DMERR_OK)
@@ -80,7 +80,7 @@
         goto out;
 
     // Analyze the data ..
-    dmGenericRLEAnalyze(&tmp, &cfg.rleMarker, DM_COMP_RLE_MARKER);
+    dmGenericRLEAnalyze(&tmp, &cfg.rleMarker, DM_COMP_RLE_MARKER1);
 
     // Add the header bits
     if (!dmGrowBufPut(buf, magicID, strlen(magicID)) ||
@@ -91,7 +91,7 @@
     }
 
     // And now RLE compress the data to the existing buffer
-    cfg.type = DM_COMP_RLE_MARKER;
+    cfg.type = DM_COMP_RLE_MARKER1;
     cfg.rleMinCount = 3;
     cfg.rleMaxCount = 255;
     res = dmEncodeGenericRLE(buf, tmp.data, tmp.data + tmp.len, &cfg);
@@ -184,7 +184,7 @@
     tmp.len = len + 1;
 
     // Now do an RLE decode on the enlarged buffer
-    cfg.type = DM_COMP_RLE_MARKER;
+    cfg.type = DM_COMP_RLE_MARKER1;
     cfg.rleMarker = 0xC2;
     if ((res = dmDecodeGenericRLEAlloc(&mem, tmp.data, tmp.data + tmp.len, &cfg)) != DMERR_OK)
         goto out;
@@ -210,7 +210,7 @@
         goto out;
 
     // And now RLE compress the data to the existing buffer
-    cfg.type = DM_COMP_RLE_MARKER;
+    cfg.type = DM_COMP_RLE_MARKER1;
     cfg.rleMarker = 0xC2;
     cfg.rleMinCount = 3;
     cfg.rleMaxCount = 255;
@@ -330,7 +330,7 @@
     DMGrowBuf mem;
     DMCompParams cfg;
 
-    cfg.type = DM_COMP_RLE_MARKER;
+    cfg.type = DM_COMP_RLE_MARKER1;
     cfg.rleMarker = *(buf + 15);
     if ((res = dmDecodeGenericRLEAlloc(&mem, buf + FUNPAINT2_HEADER_SIZE, buf + len, &cfg)) != DMERR_OK)
         goto out;
@@ -365,7 +365,7 @@
         goto out;
 
     // Analyze the data ..
-    dmGenericRLEAnalyze(&tmp, &cfg.rleMarker, DM_COMP_RLE_MARKER);
+    dmGenericRLEAnalyze(&tmp, &cfg.rleMarker, DM_COMP_RLE_MARKER1);
 
     // Add the header bits
     if (!dmGrowBufPut(buf, fmtFunPaint2MagicID, strlen(fmtFunPaint2MagicID)) ||
@@ -376,7 +376,7 @@
     }
 
     // And now RLE compress the data to the existing buffer
-    cfg.type = DM_COMP_RLE_MARKER;
+    cfg.type = DM_COMP_RLE_MARKER1;
     cfg.rleMinCount = 3;
     cfg.rleMaxCount = 255;
     res = dmEncodeGenericRLE(buf, tmp.data, tmp.data + tmp.len, &cfg);
--- a/tools/lib64gfx.c	Sun May 13 08:23:58 2018 +0300
+++ b/tools/lib64gfx.c	Sun May 13 09:08:18 2018 +0300
@@ -256,7 +256,7 @@
         stats[buf->data[offs]]++;
 
     // According to compression type ..
-    if (rleType == DM_COMP_RLE_MARKER)
+    if (rleType == DM_COMP_RLE_MARKER1 || rleType == DM_COMP_RLE_MARKER2)
     {
         size_t selected = 0,
             smallest = buf->len;
@@ -292,7 +292,8 @@
 
         switch (cfg->type)
         {
-            case DM_COMP_RLE_MARKER:
+            case DM_COMP_RLE_MARKER1:
+            case DM_COMP_RLE_MARKER2:
                 // A simple marker byte RLE variant: [Marker] [count] [data]
                 if (data == cfg->rleMarker)
                 {
@@ -301,8 +302,19 @@
                         res = DMERR_INVALID_DATA;
                         goto err;
                     }
-                    count = *src++;
-                    data = *src++;
+
+                    switch (cfg->type)
+                    {
+                        case DM_COMP_RLE_MARKER1:
+                            count = *src++;
+                            data = *src++;
+                            break;
+
+                        case DM_COMP_RLE_MARKER2:
+                            data = *src++;
+                            count = *src++;
+                            break;
+                    }
                 }
                 break;
 
@@ -356,14 +368,28 @@
 
     switch (cfg->type)
     {
-        case DM_COMP_RLE_MARKER:
+        case DM_COMP_RLE_MARKER1:
+        case DM_COMP_RLE_MARKER2:
             if (count >= cfg->rleMinCount || data == cfg->rleMarker)
             {
                 // A simple marker byte RLE variant: [Marker] [count] [data]
-                if (!dmGrowBufPutU8(dst, cfg->rleMarker) ||
-                    !dmGrowBufPutU8(dst, count) ||
-                    !dmGrowBufPutU8(dst, data))
+                if (!dmGrowBufPutU8(dst, cfg->rleMarker))
                     return FALSE;
+
+                switch (cfg->type)
+                {
+                    case DM_COMP_RLE_MARKER1:
+                        if (!dmGrowBufPutU8(dst, count) ||
+                            !dmGrowBufPutU8(dst, data))
+                            return FALSE;
+                        break;
+
+                    case DM_COMP_RLE_MARKER2:
+                        if (!dmGrowBufPutU8(dst, data) ||
+                            !dmGrowBufPutU8(dst, count))
+                            return FALSE;
+                        break;
+                }
             }
             else
                 copyOnly = TRUE;
--- a/tools/lib64gfx.h	Sun May 13 08:23:58 2018 +0300
+++ b/tools/lib64gfx.h	Sun May 13 09:08:18 2018 +0300
@@ -198,8 +198,9 @@
 } DMC64ImageFormat;
 
 
-#define DM_COMP_RLE_MARKER    1
-#define DM_COMP_RLE_MASK      2
+#define DM_COMP_RLE_MARKER1   1
+#define DM_COMP_RLE_MARKER2   2
+#define DM_COMP_RLE_MASK      3
 
 
 typedef struct