changeset 1832:843d3a593f05

Implement write support for Black Mail FLI Designer packed format.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 22 Jun 2018 16:34:18 +0300
parents ce1a734b016f
children 19d4f76e003d
files tools/lib64fmts.c
diffstat 1 files changed, 45 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/tools/lib64fmts.c	Fri Jun 22 16:33:27 2018 +0300
+++ b/tools/lib64fmts.c	Fri Jun 22 16:34:18 2018 +0300
@@ -438,6 +438,49 @@
 }
 
 
+static int fmtEncodeBlackMailFLIPacked(DMGrowBuf *buf, const DMC64Image *img, const DMC64ImageFormat *fmt)
+{
+    int res;
+    DMGrowBuf tmp1, tmp2;
+    DMCompParams cfg;
+
+    dmGrowBufInit(&tmp1);
+    dmGrowBufInit(&tmp2);
+
+    // Encode the data to temp buffer
+    if ((res = dmC64EncodeGenericBMP(TRUE, &tmp1, img, fmt)) != DMERR_OK)
+        goto out;
+
+    // And now RLE compress the data to the existing buffer
+    cfg.func         = fmt->name;
+    cfg.type         = DM_COMP_RLE_MARKER;
+    cfg.flags        = DM_RLE_BYTE_RUNS | DM_RLE_ORDER_1 | DM_RLE_ZERO_COUNT_MAX |
+                       DM_RLE_BACKWARDS_INPUT | DM_RLE_BACKWARDS_OUTPUT;
+    cfg.rleMinCountB = 3;
+    cfg.rleMaxCountB = 256; // this format allows 256 byte runs with ZERO_COUNT_MAX
+
+    dmGenericRLEAnalyze(&tmp1, &cfg);
+
+    if ((res = dmEncodeGenericRLEAlloc(&tmp2, &tmp1, &cfg)) != DMERR_OK)
+        goto out;
+
+    // Now, finally we must put in the header etc.
+    if (!dmGrowBufPutU8(buf, cfg.rleMarkerB) ||
+        !dmGrowBufPutU16LE(buf, fmt->addr + tmp2.len + 4) ||
+        !dmGrowBufPutU16LE(buf, 0x7f3f) ||
+        !dmGrowBufPut(buf, tmp2.data, tmp2.len))
+    {
+        res = DMERR_MALLOC;
+        goto out;
+    }
+
+out:
+    dmGrowBufFree(&tmp1);
+    dmGrowBufFree(&tmp2);
+    return res;
+}
+
+
 static Uint8 fmtGetPixelBlackMailFLI(
     const DMC64Image *img, const int bmoffs, const int scroffs,
     const int shift, const int bitmap, const int rasterX, const int rasterY)
@@ -1535,9 +1578,9 @@
     },
 
     {
-        "bmlp", "Black Mail FLI (packed)", 0x38f0, 0, DM_FMT_RD,
+        "bmlp", "Black Mail FLI (packed)", 0x38f0, 0, DM_FMT_RDWR,
         fmtProbeBlackMailFLIPacked,
-        fmtDecodeBlackMailFLIPacked, NULL,
+        fmtDecodeBlackMailFLIPacked, fmtEncodeBlackMailFLIPacked,
         { }, &dmC64CommonFormats[1]
     },