# HG changeset patch # User Matti Hamalainen # Date 1527690147 -10800 # Node ID 8ae32df3c184ca640b661cb83c42eed43b8855f0 # Parent 34d7c708649e7a28feea16f36aa4e8132dbe49dc Add support for BDP5 format encoding. diff -r 34d7c708649e -r 8ae32df3c184 tools/lib64fmts.c --- 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 &&