# HG changeset patch # User Matti Hamalainen # Date 1700920578 -7200 # Node ID 92909caccc9ebfe37d5081b6564103dfc77b5b01 # Parent f5f03c5d9fd57b44f492ca481fe572b103737560 Rename various compression related internal constants. diff -r f5f03c5d9fd5 -r 92909caccc9e tools/lib64fmts.c --- a/tools/lib64fmts.c Sat Nov 25 06:06:18 2023 +0200 +++ b/tools/lib64fmts.c Sat Nov 25 15:56:18 2023 +0200 @@ -666,8 +666,8 @@ DMCompParams cfg; cfg.func = fmt->name; - cfg.type = DM_COMP_RLE_MARKER; - cfg.flags = DM_RLE_BYTE_RUNS | DM_RLE_ORDER_2; + cfg.type = DM_COMP_TYPE_RLE_MARKER; + cfg.flags = DM_COMP_RLE_BYTE_RUNS | DM_COMP_RLE_ORDER_2; cfg.rleMarkerB = fmt->extra; if ((res = dmDecodeGenericRLEAlloc(&mem, buf, &cfg)) != DMERR_OK) @@ -693,8 +693,8 @@ // And now RLE compress the data to the existing buffer cfg.func = fmt->name; - cfg.type = DM_COMP_RLE_MARKER; - cfg.flags = DM_RLE_BYTE_RUNS | DM_RLE_ORDER_2; + cfg.type = DM_COMP_TYPE_RLE_MARKER; + cfg.flags = DM_COMP_RLE_BYTE_RUNS | DM_COMP_RLE_ORDER_2; cfg.rleMarkerB = fmt->extra; cfg.rleMinCountB = 4; cfg.rleMaxCountB = 255; @@ -729,8 +729,8 @@ DMCompParams cfg; cfg.func = fmt->name; - cfg.type = DM_COMP_RLE_MARKER; - cfg.flags = DM_RLE_BYTE_RUNS | DM_RLE_ORDER_1; + cfg.type = DM_COMP_TYPE_RLE_MARKER; + cfg.flags = DM_COMP_RLE_BYTE_RUNS | DM_COMP_RLE_ORDER_1; cfg.rleMarkerB = buf->data[0x0d]; if ((res = dmDecodeGenericRLEAlloc(&mem, @@ -758,8 +758,8 @@ // Analyze and setup RLE cfg.func = fmt->name; - cfg.type = DM_COMP_RLE_MARKER; - cfg.flags = DM_RLE_BYTE_RUNS | DM_RLE_ORDER_1; + cfg.type = DM_COMP_TYPE_RLE_MARKER; + cfg.flags = DM_COMP_RLE_BYTE_RUNS | DM_COMP_RLE_ORDER_1; cfg.rleMinCountB = 4; cfg.rleMaxCountB = 255; @@ -846,8 +846,8 @@ DMCompParams cfg; cfg.func = fmt->name; - cfg.type = DM_COMP_RLE_MARKER; - cfg.flags = DM_RLE_BYTE_RUNS | DM_RLE_WORD_RUNS | DM_RLE_ORDER_1; + cfg.type = DM_COMP_TYPE_RLE_MARKER; + cfg.flags = DM_COMP_RLE_BYTE_RUNS | DM_COMP_RLE_WORD_RUNS | DM_COMP_RLE_ORDER_1; cfg.rleMarkerB = buf->data[8]; cfg.rleMarkerW = buf->data[9]; @@ -883,8 +883,8 @@ // Analyze and setup RLE cfg.func = fmt->name; - cfg.type = DM_COMP_RLE_MARKER; - cfg.flags = DM_RLE_BYTE_RUNS | DM_RLE_WORD_RUNS | DM_RLE_ORDER_1; + cfg.type = DM_COMP_TYPE_RLE_MARKER; + cfg.flags = DM_COMP_RLE_BYTE_RUNS | DM_COMP_RLE_WORD_RUNS | DM_COMP_RLE_ORDER_1; cfg.rleMinCountB = 4; cfg.rleMaxCountB = 255; cfg.rleMinCountW = 256; @@ -983,8 +983,8 @@ // Now do an RLE decode on the enlarged buffer cfg.func = fmt->name; - cfg.type = DM_COMP_RLE_MARKER; - cfg.flags = DM_RLE_BYTE_RUNS | DM_RLE_ORDER_1; + cfg.type = DM_COMP_TYPE_RLE_MARKER; + cfg.flags = DM_COMP_RLE_BYTE_RUNS | DM_COMP_RLE_ORDER_1; cfg.rleMarkerB = 0xC2; if ((res = dmDecodeGenericRLEAlloc(&mem, &tmp, &cfg)) != DMERR_OK) @@ -1012,8 +1012,8 @@ // And now RLE compress the data to the existing buffer cfg.func = fmt->name; - cfg.type = DM_COMP_RLE_MARKER; - cfg.flags = DM_RLE_BYTE_RUNS | DM_RLE_ORDER_1; + cfg.type = DM_COMP_TYPE_RLE_MARKER; + cfg.flags = DM_COMP_RLE_BYTE_RUNS | DM_COMP_RLE_ORDER_1; cfg.rleMarkerB = 0xC2; cfg.rleMinCountB = 4; cfg.rleMaxCountB = 255; @@ -1067,9 +1067,9 @@ DMCompParams cfg; cfg.func = fmt->name; - cfg.type = DM_COMP_RLE_MARKER; - cfg.flags = DM_RLE_BYTE_RUNS | DM_RLE_ORDER_1 | DM_RLE_ZERO_COUNT_MAX | - DM_RLE_BACKWARDS_INPUT | DM_RLE_BACKWARDS_OUTPUT | DM_OUT_CROP_END; + cfg.type = DM_COMP_TYPE_RLE_MARKER; + cfg.flags = DM_COMP_RLE_BYTE_RUNS | DM_COMP_RLE_ORDER_1 | DM_COMP_RLE_ZERO_COUNT_MAX | + DM_COMP_INPUT_BACKWARDS | DM_COMP_OUTPUT_BACKWARDS | DM_COMP_OUTPUT_CROP_END; cfg.rleMarkerB = psrc->data[0]; cfg.cropOutLen = 0x4442 - 2; // Crop to unpacked size - load address @@ -1102,9 +1102,9 @@ // And now RLE compress the data to the existing buffer cfg.func = fmt->name; - cfg.type = DM_COMP_RLE_MARKER; - cfg.flags = DM_RLE_BYTE_RUNS | DM_RLE_ORDER_1 | DM_RLE_ZERO_COUNT_MAX | - DM_RLE_BACKWARDS_INPUT | DM_RLE_BACKWARDS_OUTPUT; + cfg.type = DM_COMP_TYPE_RLE_MARKER; + cfg.flags = DM_COMP_RLE_BYTE_RUNS | DM_COMP_RLE_ORDER_1 | DM_COMP_RLE_ZERO_COUNT_MAX | + DM_COMP_INPUT_BACKWARDS | DM_COMP_OUTPUT_BACKWARDS; cfg.rleMinCountB = 4; cfg.rleMaxCountB = 256; // this format allows 256 byte runs with ZERO_COUNT_MAX @@ -1208,8 +1208,8 @@ // 1b7e-67e8 decoded by original depacker // 1c00-67e8 is the actual area used tho cfg.func = fmt->name; - cfg.type = DM_COMP_RLE_MARKER; - cfg.flags = DM_RLE_BACKWARDS_OUTPUT | DM_RLE_BACKWARDS_INPUT | DM_OUT_CROP_END; + cfg.type = DM_COMP_TYPE_RLE_MARKER; + cfg.flags = DM_COMP_OUTPUT_BACKWARDS | DM_COMP_INPUT_BACKWARDS | DM_COMP_OUTPUT_CROP_END; cfg.rleMarkerB = 0xfe; cfg.cropOutLen = 0x67e8 - 0x1c00; @@ -1674,8 +1674,8 @@ DMCompParams cfg; cfg.func = fmt->name; - cfg.type = DM_COMP_RLE_MARKER; - cfg.flags = DM_RLE_BYTE_RUNS | DM_RLE_ORDER_1; + cfg.type = DM_COMP_TYPE_RLE_MARKER; + cfg.flags = DM_COMP_RLE_BYTE_RUNS | DM_COMP_RLE_ORDER_1; cfg.rleMarkerB = buf->data[15]; dmGrowBufCopyOffs(&tmp, buf, fmtFunPaint2_Header_Size, 1); @@ -1721,8 +1721,8 @@ // Analyze and setup RLE cfg.func = fmt->name; - cfg.type = DM_COMP_RLE_MARKER; - cfg.flags = DM_RLE_BYTE_RUNS | DM_RLE_ORDER_1; + cfg.type = DM_COMP_TYPE_RLE_MARKER; + cfg.flags = DM_COMP_RLE_BYTE_RUNS | DM_COMP_RLE_ORDER_1; cfg.rleMinCountB = 4; cfg.rleMaxCountB = 255; @@ -1869,8 +1869,8 @@ // However, as a difference to the uncompressed files, only the data of the // 96 pixels wide area (4 sprite widths) x 168 tall is saved. cfg.func = fmt->name; - cfg.type = DM_COMP_RLE_MARKER; - cfg.flags = DM_RLE_BYTE_RUNS | DM_RLE_ORDER_1 | DM_RLE_ZERO_COUNT_MAX; + cfg.type = DM_COMP_TYPE_RLE_MARKER; + cfg.flags = DM_COMP_RLE_BYTE_RUNS | DM_COMP_RLE_ORDER_1 | DM_COMP_RLE_ZERO_COUNT_MAX; cfg.rleMarkerB = buf->data[0]; if ((res = dmDecodeGenericRLEAlloc( @@ -2153,8 +2153,8 @@ DMCompParams cfg; cfg.func = fmt->name; - cfg.type = DM_COMP_RLE_MARKER; - cfg.flags = DM_RLE_BYTE_RUNS | DM_RLE_ORDER_1; + cfg.type = DM_COMP_TYPE_RLE_MARKER; + cfg.flags = DM_COMP_RLE_BYTE_RUNS | DM_COMP_RLE_ORDER_1; cfg.rleMarkerB = buf->data[0]; if ((res = dmDecodeGenericRLEAlloc( @@ -2178,8 +2178,8 @@ // Analyze and setup RLE cfg.func = fmt->name; - cfg.type = DM_COMP_RLE_MARKER; - cfg.flags = DM_RLE_BYTE_RUNS | DM_RLE_ORDER_1; + cfg.type = DM_COMP_TYPE_RLE_MARKER; + cfg.flags = DM_COMP_RLE_BYTE_RUNS | DM_COMP_RLE_ORDER_1; cfg.rleMinCountB = 4; cfg.rleMaxCountB = 255; diff -r f5f03c5d9fd5 -r 92909caccc9e tools/lib64gfx.c --- a/tools/lib64gfx.c Sat Nov 25 06:06:18 2023 +0200 +++ b/tools/lib64gfx.c Sat Nov 25 15:56:18 2023 +0200 @@ -301,7 +301,7 @@ // According to compression type .. switch (cfg->type) { - case DM_COMP_RLE_MARKER: + case DM_COMP_TYPE_RLE_MARKER: { size_t selected = 0, smallest = buf->len; @@ -310,18 +310,18 @@ for (size_t n = 0; n < DM_STAT_MAX; n++) if (stats[n] < smallest) { - switch (cfg->flags & DM_RLE_RUNS_MASK) + switch (cfg->flags & DM_COMP_RLE_RUNS_MASK) { - case DM_RLE_BYTE_RUNS | DM_RLE_WORD_RUNS: + case DM_COMP_RLE_BYTE_RUNS | DM_COMP_RLE_WORD_RUNS: cfg->rleMarkerW = selected; cfg->rleMarkerB = selected = n; break; - case DM_RLE_BYTE_RUNS: + case DM_COMP_RLE_BYTE_RUNS: cfg->rleMarkerB = selected = n; break; - case DM_RLE_WORD_RUNS: + case DM_COMP_RLE_WORD_RUNS: cfg->rleMarkerW = selected = n; break; } @@ -330,7 +330,7 @@ } break; - case DM_COMP_RLE_MASK: + case DM_COMP_TYPE_RLE_MASK: cfg->rleMarkerMask = 0xC0; cfg->rleMarkerBits = 0xC0; cfg->rleCountMask = 0x3f; @@ -346,13 +346,13 @@ void dmSetupRLEBuffers(DMGrowBuf *dst, DMGrowBuf *src, const DMCompParams *cfg) { - if (src != NULL && (cfg->flags & DM_RLE_BACKWARDS_INPUT)) + if (src != NULL && (cfg->flags & DM_COMP_INPUT_BACKWARDS)) { src->offs = src->len; src->backwards = true; } - if (dst != NULL && (cfg->flags & DM_RLE_BACKWARDS_OUTPUT)) + if (dst != NULL && (cfg->flags & DM_COMP_OUTPUT_BACKWARDS)) { dst->backwards = true; dst->offs = dst->size; @@ -384,15 +384,15 @@ if (dst != NULL) { - if (cfg->flags & DM_RLE_BACKWARDS_OUTPUT) + if (cfg->flags & DM_COMP_OUTPUT_BACKWARDS) { memmove(dst->data, dst->data + dst->offs, dst->len); dst->offs = 0; } - switch (cfg->flags & DM_OUT_CROP_MASK) + switch (cfg->flags & DM_COMP_OUTPUT_CROP_MASK) { - case DM_OUT_CROP_END: + case DM_COMP_OUTPUT_CROP_END: if (cfg->cropOutLen < dst->len) { memmove(dst->data, dst->data + dst->len - cfg->cropOutLen, cfg->cropOutLen); @@ -400,7 +400,7 @@ } break; - case DM_OUT_CROP_START: + case DM_COMP_OUTPUT_CROP_START: if (cfg->cropOutLen <= dst->len) dst->len = cfg->cropOutLen; break; @@ -448,10 +448,10 @@ { unsigned int count = 1; - if (cfg->type == DM_COMP_RLE_MARKER) + if (cfg->type == DM_COMP_TYPE_RLE_MARKER) { // A simple marker byte RLE variant: [Marker] [count] [data] - if ((cfg->flags & DM_RLE_BYTE_RUNS) && data == cfg->rleMarkerB) + if ((cfg->flags & DM_COMP_RLE_BYTE_RUNS) && data == cfg->rleMarkerB) { if (!dmGrowBufGetU8(&src, &tmp1)) { @@ -477,24 +477,24 @@ cfg->func); goto out; } - switch (cfg->flags & DM_RLE_ORDER_MASK) + switch (cfg->flags & DM_COMP_RLE_ORDER_MASK) { - case DM_RLE_ORDER_1: + case DM_COMP_RLE_ORDER_1: count = tmp1; data = tmp2; break; - case DM_RLE_ORDER_2: + case DM_COMP_RLE_ORDER_2: count = tmp2; data = tmp1; break; } - if (count == 0 && (cfg->flags & DM_RLE_ZERO_COUNT_MAX)) + if (count == 0 && (cfg->flags & DM_COMP_RLE_ZERO_COUNT_MAX)) count = 256; } else - if ((cfg->flags & DM_RLE_WORD_RUNS) && data == cfg->rleMarkerW) + if ((cfg->flags & DM_COMP_RLE_WORD_RUNS) && data == cfg->rleMarkerW) { if (!dmGrowBufGetU8(&src, &tmp1) || !dmGrowBufGetU8(&src, &tmp2) || @@ -505,25 +505,25 @@ cfg->func); goto out; } - switch (cfg->flags & DM_RLE_ORDER_MASK) + switch (cfg->flags & DM_COMP_RLE_ORDER_MASK) { - case DM_RLE_ORDER_1: + case DM_COMP_RLE_ORDER_1: count = (tmp2 << 8) | tmp1; data = tmp3; break; - case DM_RLE_ORDER_2: + case DM_COMP_RLE_ORDER_2: data = tmp1; count = (tmp3 << 8) | tmp2; break; } - if (count == 0 && (cfg->flags & DM_RLE_ZERO_COUNT_MAX)) + if (count == 0 && (cfg->flags & DM_COMP_RLE_ZERO_COUNT_MAX)) count = 65536; } } else - if (cfg->type == DM_COMP_RLE_MASK) + if (cfg->type == DM_COMP_TYPE_RLE_MASK) { // Mask marker RLE: usually high bit(s) of byte mark RLE sequence // and the lower bits contain the count: [Mask + count] [data] @@ -571,25 +571,25 @@ switch (cfg->type) { - case DM_COMP_RLE_MARKER: - if ((cfg->flags & DM_RLE_WORD_RUNS) && + case DM_COMP_TYPE_RLE_MARKER: + if ((cfg->flags & DM_COMP_RLE_WORD_RUNS) && (count >= cfg->rleMinCountW || data == cfg->rleMarkerW)) { - if (count == 65536 && (cfg->flags & DM_RLE_ZERO_COUNT_MAX)) + if (count == 65536 && (cfg->flags & DM_COMP_RLE_ZERO_COUNT_MAX)) count = 0; if (!dmGrowBufPutU8(dst, cfg->rleMarkerW)) goto out; - switch (cfg->flags & DM_RLE_ORDER_MASK) + switch (cfg->flags & DM_COMP_RLE_ORDER_MASK) { - case DM_RLE_ORDER_1: + case DM_COMP_RLE_ORDER_1: if (!dmGrowBufPutU16LE(dst, count) || !dmGrowBufPutU8(dst, data)) goto out; break; - case DM_RLE_ORDER_2: + case DM_COMP_RLE_ORDER_2: if (!dmGrowBufPutU8(dst, data) || !dmGrowBufPutU16LE(dst, count)) goto out; @@ -597,24 +597,24 @@ } } else - if ((cfg->flags & DM_RLE_BYTE_RUNS) && + if ((cfg->flags & DM_COMP_RLE_BYTE_RUNS) && (count >= cfg->rleMinCountB || data == cfg->rleMarkerB)) { - if (count == 256 && (cfg->flags & DM_RLE_ZERO_COUNT_MAX)) + if (count == 256 && (cfg->flags & DM_COMP_RLE_ZERO_COUNT_MAX)) count = 0; if (!dmGrowBufPutU8(dst, cfg->rleMarkerB)) goto out; - switch (cfg->flags & DM_RLE_ORDER_MASK) + switch (cfg->flags & DM_COMP_RLE_ORDER_MASK) { - case DM_RLE_ORDER_1: + case DM_COMP_RLE_ORDER_1: if (!dmGrowBufPutU8(dst, count) || !dmGrowBufPutU8(dst, data)) goto out; break; - case DM_RLE_ORDER_2: + case DM_COMP_RLE_ORDER_2: if (!dmGrowBufPutU8(dst, data) || !dmGrowBufPutU8(dst, count)) goto out; @@ -625,7 +625,7 @@ copyOnly = true; break; - case DM_COMP_RLE_MASK: + case DM_COMP_TYPE_RLE_MASK: if (count >= cfg->rleMinCountB || (data & cfg->rleMarkerMask) == cfg->rleMarkerBits) { // Mask marker RLE: usually high bit(s) of byte mark RLE sequence @@ -668,8 +668,8 @@ // If new data byte is different, or we exceed the rleMaxCount // for the active runs mode(s) .. then encode the run. if ((data != prev && prev != -1) || - ((cfg->flags & DM_RLE_WORD_RUNS) && count >= cfg->rleMaxCountW) || - (((cfg->flags & DM_RLE_RUNS_MASK) == DM_RLE_BYTE_RUNS) && count >= cfg->rleMaxCountB)) + ((cfg->flags & DM_COMP_RLE_WORD_RUNS) && count >= cfg->rleMaxCountW) || + (((cfg->flags & DM_COMP_RLE_RUNS_MASK) == DM_COMP_RLE_BYTE_RUNS) && count >= cfg->rleMaxCountB)) { if ((res = dmEncodeGenericRLESequence(dst, prev, count, cfg)) != DMERR_OK) goto out; diff -r f5f03c5d9fd5 -r 92909caccc9e tools/lib64gfx.h --- a/tools/lib64gfx.h Sat Nov 25 06:06:18 2023 +0200 +++ b/tools/lib64gfx.h Sat Nov 25 15:56:18 2023 +0200 @@ -324,35 +324,34 @@ } DMC64ImageFormat; -// // Compression types -// enum { - DM_COMP_RLE_MARKER = 1, // RLE with a separate marker byte - DM_COMP_RLE_MASK = 2, // RLE that has marker bits and lower part acts as run length + DM_COMP_TYPE_RLE_MARKER = 1, // RLE with a separate marker byte + DM_COMP_TYPE_RLE_MASK = 2, // RLE that has marker bits and lower part acts as run length }; // Compression flags enum { - DM_RLE_BYTE_RUNS = 0x0001, // Uses one-byte run lengths - DM_RLE_WORD_RUNS = 0x0002, // Uses two-byte (word) run lengths - DM_RLE_RUNS_MASK = 0x000f, + DM_COMP_RLE_BYTE_RUNS = 0x000010, // Uses one-byte run lengths + DM_COMP_RLE_WORD_RUNS = 0x000020, // Uses two-byte (word) run lengths + DM_COMP_RLE_RUNS_MASK = 0x0000f0, - DM_RLE_ORDER_1 = 0x0010, // Order: , , - DM_RLE_ORDER_2 = 0x0020, // Order: , , - DM_RLE_ORDER_MASK = 0x00f0, + DM_COMP_RLE_ORDER_1 = 0x000100, // Order: , , + DM_COMP_RLE_ORDER_2 = 0x000200, // Order: , , + DM_COMP_RLE_ORDER_MASK = 0x000f00, - DM_RLE_BACKWARDS_INPUT = 0x0100, // Input is read backwards - DM_RLE_BACKWARDS_OUTPUT = 0x0200, // Output is written backwards - DM_RLE_ZERO_COUNT_MAX = 0x0400, // Zero "count" / run length value is max run (2^8, 2^16) + DM_COMP_RLE_ZERO_COUNT_MAX = 0x001000, // Zero "count" / run length value is max run (2^8, 2^16) + + DM_COMP_INPUT_BACKWARDS = 0x010000, // Input stream is read backwards + DM_COMP_OUTPUT_BACKWARDS = 0x020000, // Output stream is written backwards - DM_OUT_CROP_NONE = 0x0000, - DM_OUT_CROP_START = 0x1000, - DM_OUT_CROP_END = 0x2000, - DM_OUT_CROP_MASK = 0xf000, + DM_COMP_OUTPUT_CROP_NONE = 0x000000, + DM_COMP_OUTPUT_CROP_START = 0x100000, + DM_COMP_OUTPUT_CROP_END = 0x200000, + DM_COMP_OUTPUT_CROP_MASK = 0xf00000, }; @@ -360,15 +359,15 @@ { char *func; size_t cropOutLen; - int type; // DM_COMP_* - int flags; // + int type; // Compression type DM_COMP_ + int flags; // Compression flags Uint8 - // DM_COMP_RLE_MARKER mode - rleMarkerB, // Marker byte for byte length runs (if DM_RLE_BYTE_RUNS used) - rleMarkerW, // Marker byte for word length runs (if DM_RLE_WORD_RUNS used) + // DM_COMP_TYPE_RLE_MARKER mode + rleMarkerB, // Marker byte for byte length runs (if DM_COMP_RLE_BYTE_RUNS used) + rleMarkerW, // Marker byte for word length runs (if DM_COMP_RLE_WORD_RUNS used) - // DM_COMP_RLE_MASK mode + // DM_COMP_TYPE_RLE_MASK mode rleMarkerBits, rleMarkerMask, // Mask bits for marker: data & rleMarkerMask == rleMarkerBits rleCountMask; // Mask bits for length: count = data & rleCountMask