# HG changeset patch # User Matti Hamalainen # Date 1528538869 -10800 # Node ID 83f50e43120664d04d7311d39c4fa2cd21ca940b # Parent b4992d9f72fe176e306ca730f00d18c7d4f91e68 Implement support for ECI packed format. diff -r b4992d9f72fe -r 83f50e431206 tools/lib64fmts.c --- a/tools/lib64fmts.c Sat Jun 09 13:05:22 2018 +0300 +++ b/tools/lib64fmts.c Sat Jun 09 13:07:49 2018 +0300 @@ -761,7 +761,7 @@ } -static int fmtECIConvertBMP2Image(DMImage *dst, const DMC64Image *src, const DMC64ImageFormat *fmt) +static int fmtConvertECIBMP2Image(DMImage *dst, const DMC64Image *src, const DMC64ImageFormat *fmt) { if (!dmSetMixedColorC64Palette(dst)) return DMERR_MALLOC; @@ -770,6 +770,38 @@ } +static int fmtProbeECIPacked(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) +{ + // XXX TODO: Perhaps count statistics about used byte values + // and compare to value in buf[2] which is the RLE marker + if (len > 128 && dmCompareAddr16(buf, 0, fmt->addr)) + return DM_PROBE_SCORE_AVG; + else + return DM_PROBE_SCORE_FALSE; +} + + +static int fmtDecodeECIPacked(DMC64Image *img, const DMGrowBuf *buf, const DMC64ImageFormat *fmt) +{ + int res; + DMGrowBuf tmp; + DMGrowBuf mem; + DMCompParams cfg; + + cfg.func = fmt->name; + cfg.type = DM_COMP_RLE_MARKER; + cfg.flags = DM_RLE_BYTE_RUNS | DM_RLE_ORDER_1; + cfg.rleMarkerB = buf->data[0]; + + if ((res = dmDecodeGenericRLEAlloc( + &mem, dmGrowBufCreateFromOffs(&tmp, buf, 1), &cfg)) == DMERR_OK) + res = dmC64DecodeGenericBMP(img, &mem, fmt); + + dmGrowBufFree(&mem); + return res; +} + + // // Helper macros for defining screen ram layouts // common for FLI type foramts @@ -857,6 +889,15 @@ { DO_DEC_FUNC , 0 , 0x0000, 0, 0, fmtTruePaintGetLaceType, NULL }, { DO_LAST , 0 , 0 , 0, 0, NULL, NULL }, }, + + { // #7: ECI Graphic Editor Hires FLI + { DO_COPY , DS_BITMAP_RAM , 0x0000, 0, 0, NULL, NULL }, + DEF_SCREEN_RAMS_8(0x2000, 0, 0x400), + { DO_COPY , DS_BITMAP_RAM , 0x4000, 1, 0, NULL, NULL }, + DEF_SCREEN_RAMS_8(0x6000, 8, 0x400), + { DO_DEC_FUNC , 0 , 0 , 0, 0, fmtECIGetLaceType, NULL }, + { DO_LAST , 0 , 0 , 0, 0, NULL, NULL }, + }, }; @@ -1183,17 +1224,21 @@ C64_SCR_CH_WIDTH, C64_SCR_CH_HEIGHT, NULL, NULL, NULL, - fmtECIConvertBMP2Image, NULL, + fmtConvertECIBMP2Image, NULL, fmtGetPixelECI, - { - { DO_COPY , DS_BITMAP_RAM , 0x0000, 0, 0, NULL, NULL }, - DEF_SCREEN_RAMS_8(0x2000, 0, 0x400), - { DO_COPY , DS_BITMAP_RAM , 0x4000, 1, 0, NULL, NULL }, - DEF_SCREEN_RAMS_8(0x6000, 8, 0x400), - { DO_DEC_FUNC , 0 , 0 , 0, 0, fmtECIGetLaceType, NULL }, - { DO_LAST , 0 , 0 , 0, 0, NULL, NULL }, - }, - NULL + { }, &dmC64CommonFormatOps[7] + }, + + { + D64_FMT_HIRES | D64_FMT_FLI, + "ecp", "ECI Graphic Editor 1.0 (packed)", 0x4000, 0, DM_FMT_RD, + C64_SCR_WIDTH, C64_SCR_HEIGHT, + C64_SCR_CH_WIDTH, C64_SCR_CH_HEIGHT, + fmtProbeECIPacked, + fmtDecodeECIPacked, NULL, + fmtConvertECIBMP2Image, NULL, + fmtGetPixelECI, + { }, &dmC64CommonFormatOps[7] }, {