changeset 1369:3a94c0e8297f

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 24 Sep 2017 13:13:04 +0300
parents 95e416830490
children 53358cc2f9ff
files tools/lib64gfx.c
diffstat 1 files changed, 37 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/tools/lib64gfx.c	Sat Sep 23 01:26:31 2017 +0300
+++ b/tools/lib64gfx.c	Sun Sep 24 13:13:04 2017 +0300
@@ -180,23 +180,6 @@
 }
 
 
-static int fmtProbeDrazPaint20Packed(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt)
-{
-    const char *ident = (const char *) buf + 2;
-
-    if (len > 22 &&
-        dmCompareAddr16(buf, 0, fmt->addr) &&
-        strncmp(ident, "DRAZPAINT ", 10) == 0 &&
-        ident[11] == '.' && (
-        (ident[10] == '1' && ident[12] == '4') ||
-        (ident[10] == '2' && ident[12] == '0')
-        ))
-        return DM_PROBE_SCORE_MAX;
-
-    return DM_PROBE_SCORE_FALSE;
-}
-
-
 static int dmDecodeGenericRLE(Uint8 **mem, Uint8 **pdstEnd, const Uint8 *src, const Uint8 *srcEnd, const Uint8 rleMarker)
 {
     Uint8 *dst, *dstEnd;
@@ -227,6 +210,32 @@
 }
 
 
+static BOOL fmtSetFLIType(DMC64Image *img, const struct _DMC64EncDecOp *op, const Uint8 *buf, const size_t len)
+{
+    (void) buf;
+    (void) len;
+    img->fliType = op->bank;
+    return TRUE;
+}
+
+
+static int fmtProbeDrazPaint20Packed(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt)
+{
+    const char *ident = (const char *) buf + 2;
+
+    if (len > 22 &&
+        dmCompareAddr16(buf, 0, fmt->addr) &&
+        strncmp(ident, "DRAZPAINT ", 10) == 0 &&
+        ident[11] == '.' && (
+        (ident[10] == '1' && ident[12] == '4') ||
+        (ident[10] == '2' && ident[12] == '0')
+        ))
+        return DM_PROBE_SCORE_MAX;
+
+    return DM_PROBE_SCORE_FALSE;
+}
+
+
 static int fmtDecodeDrazPaintPacked(DMC64Image *img, const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt)
 {
     int res;
@@ -285,6 +294,7 @@
         return DM_PROBE_SCORE_AVG;
     if (n > 10)
         return DM_PROBE_SCORE_MAYBE;
+
     return DM_PROBE_SCORE_FALSE;
 }
 
@@ -317,18 +327,11 @@
 }
 
 
-static BOOL fmtSetFLIType(DMC64Image *img, const struct _DMC64EncDecOp *op, const Uint8 *buf, const size_t len)
-{
-    (void) buf;
-    (void) len;
-    img->fliType = op->bank;
-    return TRUE;
-}
-
+#define XX2_MIN_SIZE 4000
 
 static int fmtProbeFormatXX2(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt)
 {
-    if (len >= 4000 && len <= 4008 &&
+    if (len >= XX2_MIN_SIZE && len <= XX2_MIN_SIZE + 8 &&
         dmCompareAddr16(buf, 0, fmt->addr))
         return DM_PROBE_SCORE_MAYBE;
 
@@ -339,8 +342,11 @@
 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 there is only data for less than XX2_MIN_SIZE bytes,
+    // allocate a buffer of that size and copy data there.
+    // Otherwise allocate len bytes.
+    size_t nlen = len < XX2_MIN_SIZE ? XX2_MIN_SIZE : len;
+    Uint8 *mem = dmMalloc0(nlen);
     if (mem == NULL)
         return DMERR_MALLOC;
 
@@ -354,6 +360,9 @@
 
 
 
+//
+// Array with data for supported formats
+//
 const DMC64ImageFormat dmC64ImageFormats[] =
 {
     {