# HG changeset patch # User Matti Hamalainen # Date 1526194273 -10800 # Node ID fb60abb09a654efbe69558ea2d21be2b0bf6f534 # Parent 632f1dbc83eb2705a5ed4634193b09e66589728d Add support for packed Koala Painter files, though without probing now. diff -r 632f1dbc83eb -r fb60abb09a65 tools/lib64fmts.c --- 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,