# HG changeset patch # User Matti Hamalainen # Date 1529674458 -10800 # Node ID 843d3a593f056f2a26a5a56076cf73f818e3a972 # Parent ce1a734b016f8166f7d408ba6bb9287afe0ef2bf Implement write support for Black Mail FLI Designer packed format. diff -r ce1a734b016f -r 843d3a593f05 tools/lib64fmts.c --- 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] },