changeset 1578:fb60abb09a65

Add support for packed Koala Painter files, though without probing now.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 13 May 2018 09:51:13 +0300
parents 632f1dbc83eb
children 4288b21e97b9
files tools/lib64fmts.c
diffstat 1 files changed, 60 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/tools/lib64fmts.c	Sun May 13 09:50:13 2018 +0300
+++ b/tools/lib64fmts.c	Sun May 13 09:51:13 2018 +0300
@@ -31,6 +31,49 @@
 };
 
 
+
+static int fmtDecodeKoalaPaintPacked(DMC64Image *img, const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt)
+{
+    int res;
+    DMGrowBuf mem;
+    DMCompParams cfg;
+
+    cfg.type = DM_COMP_RLE_MARKER2;
+    cfg.rleMarker = 0xfe;
+    if ((res = dmDecodeGenericRLEAlloc(&mem, buf, buf + len, &cfg)) != DMERR_OK)
+        goto out;
+
+    res = dmC64DecodeGenericBMP(img, mem.data, mem.len, fmt);
+
+out:
+    dmGrowBufFree(&mem);
+    return res;
+}
+
+
+static int fmtEncodeKoalaPaintPacked(DMGrowBuf *buf, const DMC64Image *img, const DMC64ImageFormat *fmt)
+{
+    int res;
+    DMGrowBuf tmp;
+    DMCompParams cfg;
+
+    // Encode the data to temp buffer
+    if ((res = dmC64EncodeGenericBMP(TRUE, &tmp, img, fmt)) != DMERR_OK)
+        goto out;
+
+    // And now RLE compress the data to the existing buffer
+    cfg.type = DM_COMP_RLE_MARKER2;
+    cfg.rleMarker = 0xfe;
+    cfg.rleMinCount = 3;
+    cfg.rleMaxCount = 255;
+    res = dmEncodeGenericRLE(buf, tmp.data, tmp.data + tmp.len, &cfg);
+
+out:
+    dmGrowBufFree(&tmp);
+    return res;
+}
+
+
 static int fmtProbeDrazPaint20Packed(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt)
 {
     const char *ident = (const char *) buf + 2;
@@ -632,6 +675,23 @@
     },
 
     {
+        D64_FMT_MC, "klp", "Koala Paint (packed)", 0x6000, 0, DM_FMT_RDWR,
+        C64_SCR_WIDTH / 2, C64_SCR_HEIGHT,
+        C64_SCR_CH_WIDTH , C64_SCR_CH_HEIGHT,
+        NULL,
+        fmtDecodeKoalaPaintPacked, fmtEncodeKoalaPaintPacked,
+        NULL, NULL,
+        NULL,
+        {
+            { DT_BITMAP,       0x0000, 0,  0, NULL, NULL },
+            { DT_SCREEN_RAM,   0x1f40, 0,  0, NULL, NULL },
+            { DT_COLOR_RAM,    0x2328, 0,  0, NULL, NULL },
+            { DT_COLOR_REG,    0x270f, 0,  DC_BGCOL, NULL, NULL },
+            { DT_LAST,         0,      0,  0, NULL, NULL },
+        }
+    },
+
+    {
         D64_FMT_MC, "aas", "Advanced Art Studio (unpacked)", 0x2000, 10018, DM_FMT_RDWR,
         C64_SCR_WIDTH / 2, C64_SCR_HEIGHT,
         C64_SCR_CH_WIDTH , C64_SCR_CH_HEIGHT,