Mercurial > hg > dmlib
diff tools/lib64fmts.c @ 1663:8ae32df3c184
Add support for BDP5 format encoding.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 30 May 2018 17:22:27 +0300 |
parents | 34d7c708649e |
children | 0022e1a428ca |
line wrap: on
line diff
--- a/tools/lib64fmts.c Wed May 30 17:22:01 2018 +0300 +++ b/tools/lib64fmts.c Wed May 30 17:22:27 2018 +0300 @@ -227,6 +227,44 @@ } +static int fmtEncodeBDP5Packed(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; + + // Analyze and setup RLE + cfg.type = DM_COMP_RLE_MARKER; + cfg.flags = DM_RLE_BYTE_RUNS | DM_RLE_WORD_RUNS | DM_RLE_ORDER_1; + cfg.rleMinCountB = 3; + cfg.rleMaxCountB = 255; + cfg.rleMinCountW = 256; + cfg.rleMaxCountW = 1024; + + dmGenericRLEAnalyze(tmp.data, tmp.len, &cfg); + + // Add the header bits + if (!dmGrowBufPut(buf, fmtBDP5MagicID, strlen(fmtBDP5MagicID)) || + !dmGrowBufPutU8(buf, cfg.rleMarkerB) || + !dmGrowBufPutU8(buf, cfg.rleMarkerW)) + { + res = DMERR_MALLOC; + goto out; + } + + // And now RLE compress the data to the existing buffer + res = dmEncodeGenericRLE(buf, tmp.data, tmp.data + tmp.len, &cfg); + +out: + dmGrowBufFree(&tmp); + return res; +} + + static int fmtProbeGunPaint(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) { if (len > 0x400 &&