![]() For images with pixels smaller than eight bits, this means that the filter algorithms actually operate on more than one pixel at a time for example, in a 2-bit palette or grayscale image, there are four pixels per byte. Most important among these is that filtering always operates on bytes, not pixels. Though the concept is simple, there are quite a few subtleties in the actual mechanics of filtering. The final filter calculation, on the other hand, is done using base-256 modular arithmetic this is true for all of the filter types. Note that all calculations to produce the Paeth predictor are done using exact integer arithmetic. In case of ties, the corresponding byte to the left has precedence as the predicted value, followed by the one directly above. ![]() (For example, the base value might equal 228 + 228 - 227 = 229.) Then the difference between the base value and each of the three corresponding bytes is calculated, and the byte that gave the smallest absolute difference-that is, the one that was closest to the base value-is used as the predictor and subtracted from the target byte to give the filtered value. Invented by Alan Paeth, the Paeth predictor is computed by first calculating a base value, equal to the sum of the corresponding bytes to the left and above, minus the byte to the upper left. The last method requires some explanation. PNG supports five types of filters, and an encoder may choose to use a different filter for each row of pixels in the image.Įach byte is replaced with the difference between it and the “corresponding byte” to its left.Įach byte is replaced with the difference between it and the byte above it (in the previous row, as it was before filtering).Įach byte is replaced with the difference between it and the average of the corresponding bytes to its left and above it, truncating any fractional part.Įach byte is replaced with the difference between it and the Paeth predictor of the corresponding bytes to its left, above it, and to its upper left. But with filtering turned on, the same compression engine reduces it to 115,989 bytes, more than 300 times better than the nonfiltered case, for a total compression factor of 434! Zowie.Īctual image data is rarely that perfect, but filtering does improve compression in grayscale and truecolor images, and it can help on some palette images as well. Simple PNG-style compression with no filtering brings it down to 36 MB, only a 25% reduction in size. As raw data, it therefore requires 48 MB to store. This 24-bit, 512 × 32,768 RGB image contains one pixel of every possible color-more than 16 million of them altogether. But a trivial modification of the sequence-namely, leaving the first byte alone but replacing each subsequent byte by the difference between it and its predecessor-transforms the sequence into an extremely compressible set of 255 identical bytes, each having the value 1.Īs a real-life example of this (though still not particularly realistic), consider the image known as 16million.png. Since there is no repetition in the sequence, it compresses either very poorly or not at all. As a simple example, consider a sequence of bytes increasing uniformly from 1 to 255. Filtering is a method of reversibly transforming the image data so that the main compression engine can operate more efficiently. PNG also supports a precompression step called filtering. We'll look at the compression engine itself shortly, but PNG's performance is not due solely to an improved compression algorithm. I will update it to the final version and convert it to HTML format when time permits.
0 Comments
Leave a Reply. |