changeset 2068:e4dc8fbaa5ad

Improve IFF probing.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 05 Dec 2018 13:38:53 +0200
parents 430c010d97c1
children 83a3d05b5c1d
files tools/libgfx.c tools/libgfx.h
diffstat 2 files changed, 29 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/tools/libgfx.c	Wed Dec 05 13:33:45 2018 +0200
+++ b/tools/libgfx.c	Wed Dec 05 13:38:53 2018 +0200
@@ -1505,13 +1505,11 @@
 } DMIFF;
 
 
-static int fmtProbeIFF(const Uint8 *buf, const size_t len)
+static int fmtProbeIFF(const Uint8 *buf, const size_t len, const Uint32 id)
 {
     if (len > 32 &&
-        DM_BE32_TO_NATIVE(*(Uint32 *) (buf + 0)) == IFF_ID_FORM && (
-        DM_BE32_TO_NATIVE(*(Uint32 *) (buf + 8)) == IFF_ID_ILBM ||
-        DM_BE32_TO_NATIVE(*(Uint32 *) (buf + 8)) == IFF_ID_PBM ||
-        DM_BE32_TO_NATIVE(*(Uint32 *) (buf + 8)) == IFF_ID_ACBM))
+        DM_BE32_TO_NATIVE(*(Uint32 *) (buf + 0)) == IFF_ID_FORM &&
+        DM_BE32_TO_NATIVE(*(Uint32 *) (buf + 8)) == id)
     {
         if (DM_BE32_TO_NATIVE(*(Uint32 *) (buf + 12)) == IFF_ID_BMHD)
             return DM_PROBE_SCORE_MAX;
@@ -1523,6 +1521,24 @@
 }
 
 
+static int fmtProbeIFF_ILBM(const Uint8 *buf, const size_t len)
+{
+    return fmtProbeIFF(buf, len, IFF_ID_ILBM);
+}
+
+
+static int fmtProbeIFF_PBM(const Uint8 *buf, const size_t len)
+{
+    return fmtProbeIFF(buf, len, IFF_ID_PBM);
+}
+
+
+static int fmtProbeIFF_ACBM(const Uint8 *buf, const size_t len)
+{
+    return fmtProbeIFF(buf, len, IFF_ID_ACBM);
+}
+
+
 static void dmMakeIFFChunkIDStr(DMIFFChunk *chunk)
 {
     chunk->idStr[0] = (chunk->id >> 24) & 0xff;
@@ -2430,13 +2446,17 @@
     {
         "lbm", "IFF ILBM (interleaved/old DP)",
         DM_IMGFMT_IFF_ILBM, DM_FMT_RDWR,
-        fmtProbeIFF, dmReadIFFImage, dmWriteIFFImage,
+        fmtProbeIFF_ILBM, dmReadIFFImage, dmWriteIFFImage,
     },
     {
         "pbm", "IFF PBM (DP2e)",
         DM_IMGFMT_IFF_PBM, DM_FMT_RDWR,
-        fmtProbeIFF, dmReadIFFImage, dmWriteIFFImage,
-        fmtProbeIFF, dmReadIFFImage, dmWriteIFFImage,
+        fmtProbeIFF_PBM, dmReadIFFImage, dmWriteIFFImage,
+    },
+    {
+        "acbm", "IFF ACBM (Amiga Basic)",
+        DM_IMGFMT_IFF_ACBM, DM_FMT_RDWR,
+        fmtProbeIFF_ACBM, dmReadIFFImage, dmWriteIFFImage,
     },
     {
         "raw", "Plain bitplaned (planar or non-planar) RAW",
--- a/tools/libgfx.h	Wed Dec 05 13:33:45 2018 +0200
+++ b/tools/libgfx.h	Wed Dec 05 13:38:53 2018 +0200
@@ -24,6 +24,7 @@
     DM_IMGFMT_PCX,
     DM_IMGFMT_IFF_ILBM,
     DM_IMGFMT_IFF_PBM,
+    DM_IMGFMT_IFF_ACBM,
     DM_IMGFMT_RAW,
     DM_IMGFMT_ARAW,
     DM_IMGFMT_CDUMP,