I've been playing around with image formats, so I can store my graphics in RAW format inside my productions without relying on PNG or JPG decompression. The goal was to come up with a simple format that didn't need decoding, which would save me having to carry a PNG or JPG decompressor.
I'm currently storing the data in simple RGBA or BGRA format, so the data is sequential with a byte for each colour per pixel (i.e. R-G-B-A, R-G-B-A etc). I figured something like Kkrunchy or UPX would have little trouble compression the data when stored inside an exe.
After some initial tests and some reading of how Crinkler works, I started thinking about ordering the data into streams, so each colour is stored in its own stream. This means the file data is ordered R-R-R-G-G-G-B-B-B-A-A-A for example. Depending on the data, this can greatly increase the compressibility of the file.
I've been using WinRAR to compress the output in order to gauge what sort of compression ratio I'd get with kkrunchy/upx. I'm working on a little program that will convert and re-order the data and will try a number of different orderings to determine which one best suits the file being processed.
This is never going to beat JPG, but I often seem to get a better ratio using my method vs. PNG. Here are some examples:
PNG = size in bytes of orginal PNG file.
RBA(I) = size in bytes using RGBA interleaving (RGBA, RGBA...)
RBA(S) = size in bytes using RGBA streams (R.., G.., B.., A..)
RBA(ISA) = size in bytes using interleaved RGB with trailing Alpha stream (RGB, RGB..., A...)
FILENAME | FILE DETAILS | PNG | RGBA(I) | RGBA(S) | RGBA(ISA)
---------------------------------------------------------------------------------------------------------------------------
space.png | 1024x1024x24bpp (no alpha) | 848,420 | 916,300 | 844,453 | 611,094
---------------------------------------------------------------------------------------------------------------------------
fire.png | 640x640x24bpp (no alpha) | 709,003 | 651,211 | 699,500 | 398,535
---------------------------------------------------------------------------------------------------------------------------
logo.png | 1371x883x24bpp (alpha) | 138,071 | 168,119 | 143,732 | 145,732
The results so far are quite interesting (at least to me). I know comparing RAR compression to KKrunchy/UPX is not accurate so I will need to perform some more tests against those two exe packers to be sure, but I'm fairly confident they will yield similar results.
As we can see, for complex images (with no alpha channel) the streaming method allows for better compressibility than PNG. It might be possible to further reduce the PNG images using something like PNG-Crush, which may make this whole exercise moot. It's been interesting playing around with this anyway.
I just thought I'd share this and see if anyone else had any other ideas on different data arrangement patterns to increase compressibility.
Cheers,
Raizor