changeset 2168:b4f4251eaaae

Improve probing resiliency of Cosmos Designs and ECI formats, and try to improve avoiding misprobes of other formats as ECI packed.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 11 Jun 2019 05:46:11 +0300
parents 9d362ea1a606
children 271850d7dd9b
files tools/lib64fmts.c
diffstat 1 files changed, 35 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/tools/lib64fmts.c	Tue Jun 11 05:45:13 2019 +0300
+++ b/tools/lib64fmts.c	Tue Jun 11 05:46:11 2019 +0300
@@ -981,7 +981,14 @@
 
         // Unpacked variant
         if (fmt->size != 0 && fmt->size == buf->len)
-            return DM_PROBE_SCORE_GOOD;
+        {
+            // In the unpacked format the first 0x40 bytes should be 0xff
+            for (size_t offs = 2; offs < 0x42; offs++)
+                if (buf->data[offs] != 0xff)
+                    return DM_PROBE_SCORE_GOOD;
+
+            return DM_PROBE_SCORE_MAX;
+        }
     }
 
     return DM_PROBE_SCORE_FALSE;
@@ -1399,29 +1406,35 @@
 
 static int fmtProbeECIPacked(const DMGrowBuf *buf, const DMC64ImageFormat *fmt)
 {
-    size_t i, n;
-
-    // XXX TODO: Perhaps count statistics about used byte values
-    // and compare to value in buf[2] which is the RLE marker
-    if (buf->len < 128 ||
-        !dmCompareAddr16(buf, 0, fmt->addr) ||
-        // Try to avoid misprobe of Crest Hires FLI Designer and Cosmos Design format
-        buf->len == 16386 || buf->len == 16385 ||
+    int score = DM_PROBE_SCORE_FALSE;
+
+    if (buf->len > 128 &&
+        dmCompareAddr16(buf, 0, fmt->addr))
+    {
+        size_t i, n;
+
+        // Count statistics about used byte values and compare to
+        // value in buf[2] which is the RLE marker
+        for (n = 0, i = 3; i < buf->len; i++)
+            if (buf->data[i] == buf->data[2]) n++;
+
+        if (n > 50)
+            score = DM_PROBE_SCORE_GOOD;
+        else
+        if (n > 25)
+            score = DM_PROBE_SCORE_AVG;
+        else
+        if (n > 10)
+            score = DM_PROBE_SCORE_MAYBE;
+    }
+
+    if (// Try to avoid misprobe of Crest Hires FLI Designer and Cosmos Design format
+        buf->len == 16386 ||
         // Face Painter
         buf->len == 10004)
-        return DM_PROBE_SCORE_FALSE;
-
-    for (n = 0, i = 3; i < buf->len; i++)
-        if (buf->data[i] == buf->data[2]) n++;
-
-    if (n > 50)
-        return DM_PROBE_SCORE_GOOD;
-    if (n > 25)
-        return DM_PROBE_SCORE_AVG;
-    if (n > 10)
-        return DM_PROBE_SCORE_MAYBE;
-
-    return DM_PROBE_SCORE_FALSE;
+        score /= 3;
+
+    return score;
 }