Why PNGs are a poor choice for games

Optimising game load time is something often neglected by developers, but still it is quite important. It’s quite tedious for players waiting several seconds each time a new level loads. Quite a lot of this load time is caused by the PNG format.

Recently, in the course of releasing our Texture Atlas Maker tool, I benchmarked the loading time of various PNG and Targa images on both PC and iPhone platforms. The images were loaded via libpng on the PC and via UIImage on the iPhone. The image tested is a complex 1024×1024 texture with alpha transparency.

Load iPhone Load PC size Size Zipped
32-bit RLE Targa 87 ms 8 ms 1.79 MB 1.10 MB
PNG uncompressed 350 ms 32 ms 4.00 MB 1.14 MB
PNG no filter 379 ms 59 ms 1.13 MB 1.12 MB
PNG adaptive filter 529 ms 129 ms 1.01 MB 1.01 MB

Targa uses a much simpler method of compression – run-length encoding – and hence is much faster to decode. As you can see from the chart it’s 5 times faster to load on the iPhone and 16 times faster on the PC, while being 77% larger. While the size difference is important for a web page, in a game it’s pretty inconsequential. Disk space is cheap, and a few kilobytes more won’t make much of a difference. Besides that games are normally distributed in zipped form and when the images are zipped they are all about the same size.

These benchmarks highlighted another interesting fact. PNGs are compressed in two phases, first a filtering phase, then it’s compressed by zlib. Most programs, including Photoshop and the Gimp, use adaptive filtering. The filter phase results in better PNG compression, but it also results in a much slower decode time. PNGs with adaptive, or paeth filtering load 40% slower on the iPhone, and 118% slower on the PC.

Using PNGOUT the filtering can be easily removed. In fact, we can potentially double the load speed of a game simply by calling this line on all the PNGs:

pngout /f0 /force

This entry was posted in graphics and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

Anti-Spam Quiz: