Mercurial > hg > dmlib
diff tools/lib64fmts.c @ 1505:3265175b24d2
Change the passing of RLE compression/decompression parameters to be in a dedicated struct.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 11 May 2018 20:18:14 +0300 |
parents | c7b9ef56319b |
children | 4068d87ca884 |
line wrap: on
line diff
--- a/tools/lib64fmts.c Fri May 11 07:50:18 2018 +0300 +++ b/tools/lib64fmts.c Fri May 11 20:18:14 2018 +0300 @@ -52,8 +52,12 @@ { int res; DMGrowBuf mem; + DMCompParams cfg; - if ((res = dmDecodeGenericRLEAlloc(&mem, buf + 0x0e, buf + len, *(buf + 0x0d), 0, 0, DM_RLE_MARKER)) != DMERR_OK) + cfg.type = DM_COMP_RLE_MARKER; + cfg.rleMarker = *(buf + 0x0d); + + if ((res = dmDecodeGenericRLEAlloc(&mem, buf + 0x0e, buf + len, &cfg)) != DMERR_OK) goto out; res = dmC64DecodeGenericBMP(img, mem.data, mem.len, fmt); @@ -68,7 +72,7 @@ { int res; DMGrowBuf tmp; - Uint8 rleMarker; + DMCompParams cfg; const char *magicID = (fmt->type & D64_FMT_ILACE) ? "DRAZLACE! 1.0" : "DRAZPAINT 2.0"; // Encode the data to temp buffer @@ -76,20 +80,22 @@ goto out; // Analyze the data .. - dmGenericRLEAnalyze(&tmp, &rleMarker, DM_RLE_MARKER); - rleMarker = 0xff; + dmGenericRLEAnalyze(&tmp, &cfg.rleMarker, DM_COMP_RLE_MARKER); + cfg.rleMarker = 0xff; // Add the header bits if (!dmGrowBufPut(buf, magicID, strlen(magicID)) || - !dmGrowBufPutU8(buf, rleMarker)) + !dmGrowBufPutU8(buf, cfg.rleMarker)) { res = DMERR_MALLOC; goto out; } // And now RLE compress the data to the existing buffer - res = dmEncodeGenericRLE(buf, tmp.data, tmp.data + tmp.len, - rleMarker, 3, 255, DM_RLE_MARKER); + cfg.type = DM_COMP_RLE_MARKER; + cfg.rleMinCount = 3; + cfg.rleMaxCount = 255; + res = dmEncodeGenericRLE(buf, tmp.data, tmp.data + tmp.len, &cfg); out: dmGrowBufFree(&tmp); @@ -159,6 +165,7 @@ { int res; DMGrowBuf mem, tmp; + DMCompParams cfg; // Amica Paint apparently is broken and stores one byte less than it should // so we need to do some crappy buffer expansion here .. @@ -170,7 +177,10 @@ tmp.data[tmp.len++] = 0; // Now do an RLE decode on the enlarged buffer - if ((res = dmDecodeGenericRLE(&mem, tmp.data, tmp.data + tmp.len, 0xC2, 0, 0, DM_RLE_MARKER)) != DMERR_OK) + cfg.type = DM_COMP_RLE_MARKER; + cfg.rleMarker = 0xC2; + + if ((res = dmDecodeGenericRLE(&mem, tmp.data, tmp.data + tmp.len, &cfg)) != DMERR_OK) goto out; // And finally decode to bitmap struct @@ -289,9 +299,13 @@ { int res; DMGrowBuf mem; + DMCompParams cfg; + dmGrowBufInit(&mem); - if ((res = dmDecodeGenericRLE(&mem, buf + FUNPAINT2_HEADER_SIZE, buf + len, *(buf + 15), 0, 0, DM_RLE_MARKER)) != DMERR_OK) + cfg.type = DM_COMP_RLE_MARKER; + cfg.rleMarker = *(buf + 15); + if ((res = dmDecodeGenericRLE(&mem, buf + FUNPAINT2_HEADER_SIZE, buf + len, &cfg)) != DMERR_OK) goto out; res = dmC64DecodeGenericBMP(img, mem.data, mem.len, fmt); @@ -317,27 +331,29 @@ { int res; DMGrowBuf tmp; - Uint8 rleMarker; + DMCompParams cfg; // Encode the data to temp buffer if ((res = dmC64EncodeGenericBMP(TRUE, &tmp, img, fmt)) != DMERR_OK) goto out; // Analyze the data .. - dmGenericRLEAnalyze(&tmp, &rleMarker, DM_RLE_MARKER); - rleMarker = 0xff; + dmGenericRLEAnalyze(&tmp, &cfg.rleMarker, DM_COMP_RLE_MARKER); + cfg.rleMarker = 0xff; // Add the header bits if (!dmGrowBufPut(buf, fmtFunPaint2MagicID, strlen(fmtFunPaint2MagicID)) || - !dmGrowBufPutU8(buf, rleMarker)) + !dmGrowBufPutU8(buf, cfg.rleMarker)) { res = DMERR_MALLOC; goto out; } // And now RLE compress the data to the existing buffer - res = dmEncodeGenericRLE(buf, tmp.data, tmp.data + tmp.len, - rleMarker, 3, 255, DM_RLE_MARKER); + cfg.type = DM_COMP_RLE_MARKER; + cfg.rleMinCount = 3; + cfg.rleMaxCount = 255; + res = dmEncodeGenericRLE(buf, tmp.data, tmp.data + tmp.len, &cfg); out: dmGrowBufFree(&tmp);