21.5. PNG Compression
PNGs use a "deflate" compression scheme (the same engine used to "zip" files with gzip, WinZip, etc.). Like GIFs, PNG's compression works on rows of pixels, taking advantage of repetition in bytes of information. By use of internal filters, it can take advantage of some vertical patterns as well. PNG's compression engine typically compresses images 5-25% better than GIF (and up to 39% better under optimal conditions). Unfortunately, with the currently available tools, it is difficult to achieve such file savings. See Section 21.7, "Creating PNG Files" later in this chapter.
Before PNG compresses an image, it first runs the image data, row by row, through one of five filters (Sub, Up, Average, Paeth, Adaptive). The filters use different methods for finding patterns in the image information that can then be condensed more efficiently. The process is similar to how LZW compression takes advantage of horizontal repetition in GIFs, but PNG can look for vertical repetition as well.
In most applications, the filters are applied internally and are hidden from the end user (as they should be). If your tool provides filter options, there are only two you need to remember:
Copyright © 2002 O'Reilly & Associates. All rights reserved.