#16488 - DekuTree64 - Tue Feb 17, 2004 9:57 pm
Inspired by that 'buffers & compression' thread a little ways down, I'd like to start some general discussion of different compression algorithms applied to sprites, which need to be readable one frame at a time.
128 byte chunks seems to be best, since most sprites are at least 16x16 pixels, and with 4-bit color, that's what you need. So far I've tried a variation of RLE and LZ77. The RLE performs just like any other RLE, getting large areas of color basically free, and everything else basically the same. LZ77 doesn't do too good on 128 byte chunks, as it's based on referencing the previously decompressed data, but it does take care of large emtpy areas about as well as RLE.
Now I'm thinking about a 4-bit based LZ77. The 8-bit one's decompression goes like this:
So if you're not familiar with LZ77, if the next string of data matches anything that's already decompressed, it copies it from the decompressed data to the current position. Then, wether there was any matching data or not, it copies the next character (I'll call it C) to the current pos.
In the 4-bit version, the max string length is 15, so it can store the 4-bit C (the next char) in the upper part of that, and then if the matching string length != 0, the next byte will be the starting pos of the string in the decompressed data.
Anyway, what I'm thinking about it a more LZSS approach, having one byte to tell the next 8 types (matching string or not), and that way you don't have to store the 0 in the lower 4 bits of a non-string entry. But then it gets even more compicated reading the data because it's no longer always byte-aligned, and it's only the writing of data that doesn't matter if it's 4-bit aligned, because the GBA's VRAM is 16 bits anyway, so I'd have to write a 20byte at a time decompresser anyway.
Does anyone else have any good ideas on small-data compression? I have another possible algorithm in mind, but it's pretty confusing and I don't really have time to explain it right now, so I'll add that later.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku
128 byte chunks seems to be best, since most sprites are at least 16x16 pixels, and with 4-bit color, that's what you need. So far I've tried a variation of RLE and LZ77. The RLE performs just like any other RLE, getting large areas of color basically free, and everything else basically the same. LZ77 doesn't do too good on 128 byte chunks, as it's based on referencing the previously decompressed data, but it does take care of large emtpy areas about as well as RLE.
Now I'm thinking about a 4-bit based LZ77. The 8-bit one's decompression goes like this:
Code: |
Read byte into length
if length != 0 read another byte into start copy length bytes from dest[start] to dest[destPos] add length to destPos else no start byte is stored, so do nothing then read next byte into dest[destPos++] repeat until destPos == 128 |
So if you're not familiar with LZ77, if the next string of data matches anything that's already decompressed, it copies it from the decompressed data to the current position. Then, wether there was any matching data or not, it copies the next character (I'll call it C) to the current pos.
In the 4-bit version, the max string length is 15, so it can store the 4-bit C (the next char) in the upper part of that, and then if the matching string length != 0, the next byte will be the starting pos of the string in the decompressed data.
Anyway, what I'm thinking about it a more LZSS approach, having one byte to tell the next 8 types (matching string or not), and that way you don't have to store the 0 in the lower 4 bits of a non-string entry. But then it gets even more compicated reading the data because it's no longer always byte-aligned, and it's only the writing of data that doesn't matter if it's 4-bit aligned, because the GBA's VRAM is 16 bits anyway, so I'd have to write a 20byte at a time decompresser anyway.
Does anyone else have any good ideas on small-data compression? I have another possible algorithm in mind, but it's pretty confusing and I don't really have time to explain it right now, so I'll add that later.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku