changeset 2522:27271f2afa7c

Clean up the SupeRes decoder a bit.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 15 May 2020 03:23:59 +0300
parents b19535da15e9
children 22d2cfeed831
files tools/lib64fmts.c
diffstat 1 files changed, 30 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/tools/lib64fmts.c	Fri May 15 03:06:48 2020 +0300
+++ b/tools/lib64fmts.c	Fri May 15 03:23:59 2020 +0300
@@ -109,6 +109,30 @@
 }
 
 
+static int fmtDecodeSupeRes24_25(DMSupeResCtx *ctx, Uint8 tmp)
+{
+    if (tmp == 0x24)
+    {
+        ctx->dbyte = 0xff;
+    }
+    else
+    {
+        if (tmp == 0x25)
+        {
+            int res;
+            if ((res = fmtSupeResGetByte(ctx, &tmp, 9)) != DMERR_OK)
+                return res;
+
+            tmp = (0x26 + tmp) & 0xff;
+        }
+
+        ctx->dbyte = tmp - 0x26;
+    }
+
+    return DMERR_OK;
+}
+
+
 static int fmtDecodeSupeResByte(DMSupeResCtx *ctx)
 {
     Uint8 tmp;
@@ -123,13 +147,7 @@
     {
         // ????
         ctx->offs = 0xffff;
-        return DMERR_OK;
-    }
-    else
-    if (tmp == 0x24)
-    {
-        ctx->dbyte = 0xff;
-        return DMERR_OK;
+        goto out;
     }
     else
     if (tmp == 0x20)
@@ -139,26 +157,10 @@
 
         ctx->repcount = tmp - 0x26;
 
-        if ((res = fmtSupeResGetByte(ctx, &tmp, 3)) != DMERR_OK)
+        if ((res = fmtSupeResGetByte(ctx, &tmp, 3)) != DMERR_OK ||
+            (res = fmtDecodeSupeRes24_25(ctx, tmp)) != DMERR_OK)
             goto out;
 
-        if (tmp == 0x24)
-        {
-            ctx->dbyte = 0xff;
-        }
-        else
-        {
-            if (tmp == 0x25)
-            {
-                if ((res = fmtSupeResGetByte(ctx, &tmp, 4)) != DMERR_OK)
-                    goto out;
-
-                tmp = (0x26 + tmp) & 0xff;
-            }
-
-            ctx->dbyte = tmp - 0x26;
-        }
-
         for (int cnt = 0; cnt < ctx->repcount; cnt++)
         {
             ctx->dstBuf[ctx->offs++] = ctx->dbyte;
@@ -175,17 +177,8 @@
     }
     else
     {
-        if (tmp == 0x25)
-        {
-            if ((res = fmtSupeResGetByte(ctx, &tmp, 9)) != DMERR_OK)
-                goto out;
-
-            tmp = (0x26 + tmp) & 0xff;
-        }
-
-        ctx->dbyte = tmp - 0x26;
-
-        return DMERR_OK;
+        res = fmtDecodeSupeRes24_25(ctx, tmp);
+        goto out;
     }
 
     goto lcont;
@@ -224,7 +217,7 @@
     int res;
 
     memset(&ctx, 0, sizeof(ctx));
-    ctx.dstSize = 0x4000;
+    ctx.dstSize = 0x3000;
 
     // As we need to modify the offs, etc. but not the data,
     // we will just make a shallow copy of the DMGrowBuf struct