Mercurial > hg > dmlib
changeset 1497:ee01fdec1a7b
Implement rudimentary support for writing RLE compressed DrazPaint 1.4/2.0 and DrazLace 1.0 files.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 11 May 2018 06:28:55 +0300 |
parents | 5c46004dad15 |
children | 9217fcc727e8 |
files | tools/lib64gfx.c |
diffstat | 1 files changed, 38 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/tools/lib64gfx.c Fri May 11 06:27:53 2018 +0300 +++ b/tools/lib64gfx.c Fri May 11 06:28:55 2018 +0300 @@ -514,6 +514,42 @@ } +static int fmtEncodeDrazPaintPacked(DMGrowBuf *buf, const DMC64Image *img, const DMC64ImageFormat *fmt) +{ + int res; + DMGrowBuf tmp; + Uint8 rleMarker; + const char *magicID = (fmt->type & D64_FMT_ILACE) ? "DRAZLACE! 1.0" : "DRAZPAINT 2.0"; + + // Encode the data to temp buffer + if ((res = dmC64EncodeGenericBMP(&tmp, img, fmt)) != DMERR_OK) + goto out; + + // Analyze the data .. + rleMarker = 0xff; + + // Allocate the output buffer + if ((res = dmGrowBufAlloc(buf, tmp.len + BUF_SIZE_GROW, BUF_SIZE_GROW)) != DMERR_OK) + goto out; + + // Add the header bits + if (!dmGrowBufPut(buf, magicID, strlen(magicID)) || + !dmGrowBufPutU8(buf, rleMarker)) + { + res = DMERR_MALLOC; + goto out; + } + + // And now RLE compress it to the existing buffer + res = dmEncodeGenericRLE(buf, tmp.data, tmp.data + tmp.len, + rleMarker, 3, 255, DM_RLE_MARKER); + +out: + dmGrowBufFree(&tmp); + return res; +} + + static int fmtProbeDrazLace10Packed(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) { if (len > 22 && @@ -841,7 +877,7 @@ C64_SCR_WIDTH / 2, C64_SCR_HEIGHT, C64_SCR_CH_WIDTH , C64_SCR_CH_HEIGHT, fmtProbeDrazPaint20Packed, - fmtDecodeDrazPaintPacked, fmtEncodeStub, + fmtDecodeDrazPaintPacked, fmtEncodeDrazPaintPacked, NULL, NULL, NULL, { @@ -875,7 +911,7 @@ C64_SCR_WIDTH , C64_SCR_HEIGHT, C64_SCR_CH_WIDTH, C64_SCR_CH_HEIGHT, fmtProbeDrazLace10Packed, - fmtDecodeDrazPaintPacked, fmtEncodeStub, + fmtDecodeDrazPaintPacked, fmtEncodeDrazPaintPacked, NULL, NULL, NULL, {