# HG changeset patch # User Matti Hamalainen # Date 1526009335 -10800 # Node ID ee01fdec1a7b9f983a580cc1c8c3791cb57337ba # Parent 5c46004dad1577dc19aa702d0c768be53aaf4e1d Implement rudimentary support for writing RLE compressed DrazPaint 1.4/2.0 and DrazLace 1.0 files. diff -r 5c46004dad15 -r ee01fdec1a7b tools/lib64gfx.c --- 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, {