AVIF Decoding: Handling Non-Premultiplied Alpha
An AVIF decoder renders non-premultiplied alpha by decoding the primary color data and auxiliary transparency data as separate streams, parsing container metadata to verify the alpha association, and converting the color values to an appropriate format for display compositing. Because non-premultiplied—or "straight"—alpha preserves original RGB values under fully transparent pixels, the decoder must handle color conversion prior to blending to prevent edge artifacts and color bleeding.
Stream Separation and Decoding
In the AV1 Image File Format (AVIF), transparency is not multiplexed
directly into a single four-channel (RGBA) pixel grid at the bitstream
level. Instead, the container uses an auxiliary image item linked via an
auxiliary type reference (auxl).
When an AVIF decoder processes an image, it initiates two distinct decoding passes through the underlying AV1 codec:
- Primary Item: Decodes the primary color channels (typically YUV or RGB).
- Auxiliary Item: Decodes a monochrome (grayscale) plane representing the alpha channel.
Both passes execute independently, producing full-resolution grids for both the color planes and the alpha plane.
Identifying Straight Alpha via ISOBMFF Metadata
AVIF relies on the ISO Base Media File Format (ISOBMFF) to define the relationship between color and alpha. The decoder inspects the item properties to evaluate how transparency interacts with color:
- If the
prem(premultiplied alpha) property is absent or set to indicate unassociated alpha, the decoder marks the decoded pixel buffer as straight alpha. - The absence of this tag instructs the rendering pipeline that the color values stored in the primary image represent the true, unscaled chromaticity of the scene, independent of opacity.
Color Space Conversion
Most AVIF images store color in the YUV (YCbCr) color space to optimize compression. When handling straight alpha, the decoder must convert YUV to RGB before any alpha blending takes place.
During this stage, color matrices are applied strictly to the decoded color components:
\[R, G, B = f(Y, U, V)\]
Because the alpha channel is non-premultiplied, transparent or semi-transparent pixels retain their original color values without being darkened toward black. The decoder processes these conversions across the entire image grid without factoring in the auxiliary alpha plane.
Compositing and Pipeline Integration
Once both the RGB color channels and the single-channel alpha map reside in memory as unassociated buffers, the decoder prepares the data for the system's graphics rendering engine (such as Skia, Direct2D, or a GPU-accelerated compositor).
Most modern display compositors use standard Porter-Duff source-over blending, which mathematically favors premultiplied inputs to eliminate dark fringe artifacts and avoid division-by-zero errors:
\[\text{Final Color} = \text{Source} + \text{Destination} \times (1 - \alpha)\]
To accommodate this, the decoder or rendering pipeline executes one of two pathways:
- On-the-Fly Premultiplication: The decoder multiplies each decoded color channel by the normalized alpha value immediately prior to passing the buffer to the GPU: \[R' = R \times \alpha, \quad G' = G \times \alpha, \quad B' = B \times \alpha\]
- Shader-Based Interpretation: If the rendering API supports straight alpha surfaces, the decoder loads the RGB and alpha buffers directly into separate texture units or a single RGBA texture, executing the multiplication step inside the fragment shader during screen rasterization.
By maintaining channel separation throughout the decompression and color transformation stages, the AVIF decoder ensures that non-premultiplied alpha channels render sharp, artifact-free edges regardless of the underlying background.