I'd like to ask you guys if anyone had any luck trying to compress pattern table data so that you can store it in CHR-RAM carts using less space?
I just tried out my latest idea for this, something based on quadtrees. I encode each bit plane separately, because they seem to have much more flat areas than when combined to make the 2bpp tile.
The pixels in a each tile are checked, and if they are all equal a flag indicating this is output, and the color comes next. So, a tile that uses only one color will be encoded in only 4 bits, 2 for each plane. But that rarely happens, of course.
If any of the pixels is different, a flag is output to indicate this, and the tile is divided into 4 4x4-pixel blocks, and each of them is processed the same way. These blocks will be divided into 2x2-pixel blocks if needed, and those will either share the same color or all 4 pixels are output.
The worst case would be when all squares need to be divided into smaller squares, because all the pixels will be there, and so will the flags that indicate that the blocks should be divided. In that case, the tile would be encoded in 149 bits, instead of the usual 128. Quite a bit of expansion there.
I was not so happy with the results. SMB's tileset was compressed to 71% of it's size. 8KB of some Mega Man tiles compressed about the same, 72%. So I guess the results do not get any better than this.
A really good compression ratio would be about 50% I guess... But is that a realistic goal for lossless compression of NES graphics? When I ZIP the SMB tileset I get a file about 1KB smaller than my own compression. When I ZIP my compressed file, nothing seems to happen, so that results in a bigger file than compressing the original data.
Just for fun, I also tested the algorithm on other types of data, such as JPEG images and NES code. All those tests resulted in some expansion of the original files.
Anyway, this method was my best idea so far, but I'm not really pleased with the results. Does anyone have any ideas on how to improve compression of tiles?
EDIT: Just to give you an idea of what my algorithm did, it turned this:

into this:

The compressed data was successfully decompressed back into the original data, the only problem is the sub-optimal compression ratio.
