Huffman: encode using paths down binary tree. Build tree by iteratively selecting the lowest prob pair of nodes to parent/group together.
Lempel Ziv
Deflate compression: LZSS → Huffman
Zstd
JPEG compression
Algo
Convert from RGB to YCbCr color space which separates luminance from chrominance
Downsample chrominance—can get away with quite a bit without being perceptible
Divide into 8x8 blocks
Center around 0
Perform DCT, so the block is a linear combo of the following, coeffs between -1024 and 1024. Most big coefs are in lower freqs. (“energy compaction”)
Divide each int coef by a quantization value int. A quality level of 50% has the following table. Result is many of the values will go to 0, esp. the higher freq entries
RLE the result. Use zigzag pattern, since this keeps the high-freq 0s together:
Huffman compress
DCT: can be just a matmul. Because C below is orthonormal, its transpose is the inv.
Weakness: images with lots of high freqs, like text, which ends up having artifacts around the text
PNG
Focus on lossless compression
Filters (like UP, AVG, PAETH, etc.) → deflate
Filters use one’s complement
MPEG
Operate on macroblocks (16x16)
Want to find blocks that result in smaller encoding
Could just find in local area - good for real movement
But for finding the best match in the entire frame (purely for optimizing encoding), then want to search larger area. Do this by iteratively 2D binary search, with some fixed-depth beam search keeping the top 25%
Search by these metrics