How AVIF Optimizes Palette-Based Coding

AVIF leverages the advanced compression toolset of the AV1 video codec to deliver superior compression for graphic-heavy imagery. When processing images with limited distinct color counts—such as user interface elements, screenshots, diagrams, and pixel art—AVIF employs a specialized palette prediction mode. This article explains the technical mechanics behind AVIF’s palette-based coding, detailing how it detects low-color blocks, replaces complex transform operations with color lookup tables, and achieves compact file sizes while eliminating visual artifacts.

The Mechanism of Palette Mode in AV1/AVIF

Standard image compression pipelines process pixel blocks through intra-prediction, forward transforms (like DCT or ADST), and quantization of residual frequencies. While effective for continuous-tone photography, this approach introduces ringing artifacts and high bitrate overhead around sharp, high-contrast edges typical of flat graphics.

AVIF bypasses this standard pipeline using the AV1 intra-prediction "palette mode." Instead of predicting continuous gradient values across a block, the encoder identifies blocks that contain only a few unique colors and encodes them using an indexed color representation.

Dynamic Block-Level Detection

AVIF’s palette coding operates dynamically on coding blocks ranging in size from 8x8 up to 64x64 pixels. The encoder evaluates whether applying a local palette yields a lower rate-distortion (RD) cost than standard directional intra-prediction:

Palette Construction and Signaling

Once the encoder decides to use palette mode for a block, it performs two main tasks:

  1. Base Palette Transmission: The encoder determines the representative colors (the palette entries) for the block. To save bits, the values in the palette can be predicted from neighboring reconstructed palette colors using differential pulse-code modulation (DPCM), transmitting only small delta values.
  2. Color Sorting: The entries within the palette are sorted numerically. Sorting eliminates redundancy in indexing and establishes a deterministic order that simplifies subsequent entropy coding steps.

Index Map and Entropy Coding

After establishing the palette, each pixel in the block is mapped to a zero-based index corresponding to its assigned color. The resulting two-dimensional grid of indices is then compressed using AV1’s advanced arithmetic entropy coder:

Elimination of Compression Artifacts

Traditional lossy transforms approximate sharp edges by summing various sinusoidal frequencies, often resulting in "mosquito noise" and edge blurring. By directly mapping pixels to discrete palette entries, AVIF ensures that boundaries between distinct color regions remain perfectly sharp. For images with sparse palettes, AVIF functions essentially as a near-lossless or high-fidelity indexed encoder, providing significantly higher visual fidelity and smaller byte footprints compared to legacy formats like PNG and GIF.