Gildor's Homepage |
|
A few words about image compression
A day or two ago I worked on adding PNG texture export into UE Viewer. As it is well known, PNG is using Zlib for data compression, so I did some performance tests comparing "original" Zlib with my Fast Zlib. Compared various compression levels, plus TGA texture export.
For testing I've exported PlayerSkins.utx file from the Unreal Tournament 2004. Provided timings includes decoding of DXT textures and writing compressed files back to the disk.
| Format | Compression | Time, s | Size, b |
|---|---|---|---|
| TGA | uncompressed | 4.5 | 456,138,028 |
| RLE | 5.7 | 311,947,003 | |
| PNG | uncompressed (0) | 13.0 | 584,107,986 |
| fastest (1) | 21.4 | 194,321,540 | |
| level 2 | 29.1 | 184,665,393 | |
| level 4 | 32.9 | 177,131,537 | |
| PNG/old_zlib | level 5 | 42.1 | 174,039,732 |
| maximal (9) | 547 | 168,343,067 | |
| PNG/fast_zlib | level 5 | 38.0 | 171,825,533 |
| maximal (9) | 93.3 | 166,202,424 | |
| Original (DDS) | N/A | 0.3 s | 81,811,686 |
The difference between original zlib and FastZlib starts to appear at compression level 5 (it is by design). It's easy to see that performance boost at level 9 is huge - 547s vs 93s, and compression is slightly better.
"DDS" row says original size of these textures. Timings for these rows just includes writing DDS files to the disk, without doing any processing. Interestingly, PNG compression can't achieve ratio of DDS. However DDS is a lossy compression format, so probably it's not correct to compare them.
Unfortunately "PNG level 5" is still much slower than acceptable value, so UE Viewer is using fastest possible compression (at level 1). It's 4 times slower than TGA, however it generates more widely used file format, plus - even with compression level 1 it's still much smaller than compressed TGA.