LZSS Compression: Difference between revisions

→‎Example C Decompression Function: tried to use this function and it didn't work. oops. fixed.
>Aruki
m (consistency)
>Aruki
(→‎Example C Decompression Function: tried to use this function and it didn't work. oops. fixed.)
 
(2 intermediate revisions by the same user not shown)
Line 21: Line 21:
|-
|-
| 0x4
| 0x4
| colspan=2 | Compressed data starts
| colspan=2 {{unknown|Compressed data starts}}
|}
|}


Line 60: Line 60:
If the bit corresponding to the current data chunk is not set, you read one byte group directly from the compressed buffer; simple.
If the bit corresponding to the current data chunk is not set, you read one byte group directly from the compressed buffer; simple.


If the bit is set, then that means you need to read data back from the decompressed buffer, which is where it gets a little more complicated. Read two bytes from the compressed buffer; these tell you exactly how far back in the decompressed buffer to seek, and how many byte groups to read from it. The exact way to utilize it varies depending which mode is set:
If the bit is set, then that means you need to read data back from the decompressed buffer, which is where it gets a little more complicated. Read two bytes from the compressed buffer; these tell you exactly how far back in the decompressed buffer to seek, and how many byte groups to read from it. The exact way to utilize them varies depending which mode is set:


{| class="wikitable"
{| class="wikitable"
Line 126: Line 126:
             case 1:
             case 1:
                 count = (bytes[0] >> 4) + 3;
                 count = (bytes[0] >> 4) + 3;
                 length = (bytes[0] & 0xF) | bytes[1];
                 length = ((bytes[0] & 0xF) << 0x8) | bytes[1];
                 break;
                 break;
             case 2:
             case 2:
                 count = (bytes[0] >> 4) + 2;
                 count = (bytes[0] >> 4) + 2;
                 length = ((bytes[0] & 0xF) | bytes[1]) << 1;
                 length = (((bytes[0] & 0xF) << 0x8) | bytes[1]) << 1;
                 break;
                 break;
             case 3:
             case 3:
                 count = (bytes[0] >> 4) + 1;
                 count = (bytes[0] >> 4) + 1;
                 length = ((bytes[0] & 0xF) | bytes[1]) << 2;
                 length = (((bytes[0] & 0xF) << 0x8) | bytes[1]) << 2;
                 break;
                 break;
             }
             }
Anonymous user