PNG gives back every bit of the original, but at a lower compression ratio. Learn how PNG filtering and DEFLATE work, and when to choose PNG over JPEG.
The opposite pole from JPEG is PNG (Portable Network Graphics). It is lossless compression: the original can be reconstructed without losing a single bit.
① Filtering (prediction) — each pixel is predicted from its left, upper, and upper-left neighbors, and only the difference is stored (the principle is the same as the prediction from Chapter 3, except it does exact subtraction with no loss). ② DEFLATE compression — a combination of LZ77 (replacing repeated patterns with references to earlier positions) and Huffman coding. It is the same algorithm as zip files.
Saving a photo as PNG makes the file 5–10 times larger than the JPEG, and conversely, saving a text-heavy screenshot as JPEG leaves messy ringing artifacts around the letters. The principle from Chapter 1 that '4:2:0 is a disadvantage for content with sharp color edges' applies here as well — lossy compression is fundamentally optimized for 'natural gradients' and is weak on artificial sharp edges.
A lossless image format that uses filtering prediction + DEFLATE (LZ77 + Huffman).
A general-purpose lossless compression algorithm combining LZ77 and Huffman coding.
A method that reproduces data identical to the original after compression and decompression.
Why is it a bad idea to save a text-heavy screenshot as JPEG?