changeset 1776:aa427e68e114

Theoretically fix Gun Paint format writing.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 12 Jun 2018 17:56:35 +0300
parents 4e4d54135baf
children a7f9e12bcd9b
files tools/lib64fmts.c
diffstat 1 files changed, 18 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/tools/lib64fmts.c	Tue Jun 12 17:12:48 2018 +0300
+++ b/tools/lib64fmts.c	Tue Jun 12 17:56:35 2018 +0300
@@ -251,17 +251,32 @@
 }
 
 
+static const char *fmtGunPaintMagicID = "GUNPAINT (JZ) ";
+#define fmtGunPaintMagicLen   (14)
+#define fmtGunPaintMagicOffs  (0x3e8)
+
 static int fmtProbeGunPaint(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt)
 {
     if (len > 0x400 &&
         dmCompareAddr16(buf, 0, fmt->addr) &&
-        memcmp(buf + 0x3ea, "GUNPAINT (JZ) ", 14) == 0)
+        memcmp(buf + fmtGunPaintMagicOffs + 2, fmtGunPaintMagicID, fmtGunPaintMagicLen) == 0)
         return DM_PROBE_SCORE_MAX;
 
     return DM_PROBE_SCORE_FALSE;
 }
 
 
+static BOOL fmtEncodeGunPaint(const DMC64EncDecOp *op, DMGrowBuf *buf,
+    const DMC64Image *img, const DMC64ImageFormat *fmt)
+{
+    (void) op;
+    (void) img;
+    (void) fmt;
+    memcpy(buf->data + fmtGunPaintMagicOffs, fmtGunPaintMagicID, fmtGunPaintMagicLen);
+    return TRUE;
+}
+
+
 static int fmtProbeAmicaPaintPacked(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt)
 {
     size_t i, n;
@@ -1501,7 +1516,7 @@
     },
 
     {
-        "gun", "GunPaint (unpacked)", 0x4000, 0, DM_FMT_RD,
+        "gun", "GunPaint (unpacked)", 0x4000, 0, DM_FMT_RDWR,
         fmtProbeGunPaint,
         NULL, NULL,
         {
@@ -1519,6 +1534,7 @@
                 { DO_COPY     , DS_BITMAP_RAM  , 0x6400, 1,  0, NULL, NULL },
                 { DO_COPY     , DS_EXTRA_DATA  , 0x47e8, 1,  20, NULL, NULL },
                 { DO_DEC_FUNC , 0              , 0x2742, 0,  1, fmtTruePaintGetLaceType, NULL },
+                { DO_ENC_FUNC , 0              , fmtGunPaintMagicOffs, 0, fmtGunPaintMagicLen, NULL, fmtEncodeGunPaint },
                 { DO_LAST     , 0              , 0     , 0,  0, NULL, NULL },
             }
         },