changeset 943:8eacbc38b043

Add kludge to allow more lax handling of the "unknown" $2000 format.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 25 Feb 2015 23:35:04 +0200
parents 38cad00b41dd
children c62bb4028cf0
files tools/lib64gfx.c
diffstat 1 files changed, 30 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/tools/lib64gfx.c	Wed Feb 25 22:14:03 2015 +0200
+++ b/tools/lib64gfx.c	Wed Feb 25 23:35:04 2015 +0200
@@ -328,6 +328,34 @@
 }
 
 
+static int fmtProbeFormatXX2(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt)
+{
+    if (len >= 4000 && len <= 4008 &&
+        dmCompareAddr16(buf, 0, fmt->addr))
+        return DM_PROBE_SCORE_MAYBE;
+
+    return DM_PROBE_SCORE_FALSE;
+}
+
+
+static int fmtDecodeFormatXX2(DMC64Image *img, const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt)
+{
+    int res;
+    size_t nlen = len < 4000 ? 4000 : len;
+    Uint8 *mem = dmMalloc(nlen);
+    if (mem == NULL)
+        return DMERR_MALLOC;
+
+    memcpy(mem, buf, len);
+    res = dmC64DecodeGenericBMP(img, mem, nlen, fmt);
+
+    dmFree(mem);
+    return res;
+}
+
+
+
+
 const DMC64ImageFormat dmC64ImageFormats[] =
 {
     {
@@ -579,10 +607,10 @@
 #define XX2_BSIZE      (XX2_SIZE * 8)
 
     {
-        D64_FMT_MC, "xx2", "Unknown $2000 format (unpacked)", 0x2000, 4002,
+        D64_FMT_MC, "xx2", "Unknown $2000 format (unpacked)", 0x2000, 0,
         XX2_WIDTH_CH * 4, XX2_HEIGHT_CH * 8,
         XX2_WIDTH_CH    , XX2_HEIGHT_CH,
-        NULL, NULL,
+        fmtProbeFormatXX2, fmtDecodeFormatXX2,
         NULL, NULL, NULL,
         4,
         {