# HG changeset patch # User Matti Hamalainen # Date 1525978010 -10800 # Node ID bc75be0546fc9e0c0acbb5d11c4aeb04b0cc4c6b # Parent 88845f95e79114e459ecf8302e55e2e4012eae12 More work on RLE decoder/encoder changes. diff -r 88845f95e791 -r bc75be0546fc tools/lib64gfx.c --- a/tools/lib64gfx.c Thu May 10 21:29:52 2018 +0300 +++ b/tools/lib64gfx.c Thu May 10 21:46:50 2018 +0300 @@ -225,12 +225,17 @@ } -static int dmDecodeGenericRLE(DMGrowBuf *dst, const Uint8 *src, const Uint8 *srcEnd, const Uint8 rleMarker, const Uint8 rleMask, const int rleType) +static int dmDecodeGenericRLE(DMGrowBuf *dst, const Uint8 *src, const Uint8 *srcEnd, + const Uint8 rleMarker, const Uint8 rleMask1, const Uint8 rleMask2, const int rleType) { int res; if ((res = dmGrowBufAlloc(dst, BUF_SIZE_INITIAL, BUF_SIZE_GROW)) != DMERR_OK) + { + dmError(res, + "Could not allocate RLE decoding buffer.\n"); goto err; + } // Perform RLE decode while (src < srcEnd) @@ -245,8 +250,7 @@ { if (srcEnd - src < 2) { - res = dmError(DMERR_INVALID_DATA, - "Foobar: %d\n", srcEnd - src); + res = DMERR_INVALID_DATA; goto err; } cnt = *src++; @@ -255,16 +259,16 @@ break; case DM_RLE_MASK: - if ((c & rleMask) == rleMarker) + if ((c & rleMask1) == rleMarker) { if (srcEnd - src < 1) { - res = dmError(DMERR_INVALID_DATA, - "foobar2\n"); + res = DMERR_INVALID_DATA; goto err; } + // XXX TODO actually we probably want another mask here - cnt = c & (0xff ^ rleMask); + cnt = c & rleMask2; c = *src++; } break; @@ -274,8 +278,7 @@ { if (!dmGrowBufPutU8(dst, c)) { - res = dmError(DMERR_MALLOC, - "bazzooo\n"); + res = DMERR_MALLOC; goto err; } } @@ -292,12 +295,17 @@ } -static int dmEncodeGenericRLE(DMGrowBuf *dst, const Uint8 *src, const Uint8 *srcEnd, const Uint8 rleMarker) +static int dmEncodeGenericRLE(DMGrowBuf *dst, const Uint8 *src, const Uint8 *srcEnd, + const Uint8 rleMarker, const Uint8 rleMask1, const Uint8 rleMask2, const int rleType) { (void) dst; (void) src; (void) srcEnd; (void) rleMarker; + (void) rleMask1; + (void) rleMask2; + (void) rleType; + return DMERR_OK; } @@ -368,7 +376,7 @@ int res; DMGrowBuf mem; - if ((res = dmDecodeGenericRLE(&mem, buf + 0x0e, buf + len, *(buf + 0x0d), 0, DM_RLE_MARKER)) != DMERR_OK) + if ((res = dmDecodeGenericRLE(&mem, buf + 0x0e, buf + len, *(buf + 0x0d), 0, 0, DM_RLE_MARKER)) != DMERR_OK) goto out; res = dmC64DecodeGenericBMP(img, mem.data, mem.len, fmt); @@ -450,7 +458,7 @@ 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, DM_RLE_MARKER)) != DMERR_OK) + if ((res = dmDecodeGenericRLE(&mem, tmp.data, tmp.data + tmp.len, 0xC2, 0, 0, DM_RLE_MARKER)) != DMERR_OK) goto out; // And finally decode to bitmap struct @@ -567,7 +575,7 @@ DMGrowBuf mem; dmGrowBufInit(&mem); - if ((res = dmDecodeGenericRLE(&mem, buf + FUNPAINT2_HEADER_SIZE, buf + len, *(buf + 15), 0, DM_RLE_MARKER)) != DMERR_OK) + if ((res = dmDecodeGenericRLE(&mem, buf + FUNPAINT2_HEADER_SIZE, buf + len, *(buf + 15), 0, 0, DM_RLE_MARKER)) != DMERR_OK) goto out; res = dmC64DecodeGenericBMP(img, mem.data, mem.len, fmt);