libavif Tone-Mapping Operators for SDR Fallback
This article examines how the open-source AV1 Image File Format
library, libavif, manages Standard Dynamic Range (SDR)
fallback when decoding High Dynamic Range (HDR) content. It breaks down
the parametric gain map operators embedded within the library, how
standard colorimetry transforms are handled, and how tone mapping
responsibilities are delineated between libavif and
downstream rendering engines.
Gain Map-Based Tone-Mapping (ISO/IEC 21496-1)
Rather than applying subjective, heuristic-based dynamic tone-mapping
operators (such as Reinhard, Hable, or ACES) directly to a standalone
HDR signal, libavif implements parametric tone-mapping
through gain maps. Standardized under ISO/IEC 21496-1
(incorporating concepts from Adobe Gain Map and Google UltraHDR
formats), this mechanism is the primary method used by
libavif to generate accurate SDR fallbacks or adapt content
across varying display capabilities.
The operator functions through a deterministic parametric model:
- Dual Representation: The container stores an explicit SDR base image alongside a downscaled or full-resolution gain map image (or an HDR base image with an SDR-targeting gain map).
- Parametric Math: The tone-mapping calculation
applies a weight \(W\) based on the
maximum display brightness relative to the image metadata (such as
hdrCapacityMinandhdrCapacityMax). - Log-Space Interpolation: The formula interpolates color channels between the SDR baseline and the HDR reconstruction:
\[\text{Output} = (\text{Base} + \text{offset}_1) \times \exp(W \times \log(\text{Gain} + \text{offset}_2)) - \text{offset}_1\]
This operator ensures that when rendering on an SDR display, the decoder can bypass heavy computation and present the author-intended SDR baseline without tone-compression artifacts.
Transfer Function Operations: PQ and HLG Handling
When dealing with native HDR AVIF images that do not contain an
auxiliary gain map channel, libavif does not embed an
internal, arbitrary tone-mapping algorithm to squash HDR luminance into
SDR. Instead, it relies on standardized transfer function
transformations:
- SMPTE ST 2084 (PQ): The library exposes the raw electro-optical transfer function (EOTF) to decode values into absolute linear luminance (up to 10,000 nits). Without an external tone mapper, direct downsampling to standard SDR formats relies on hard clipping at the 100-nit SDR white level.
- ITU-R BT.2100 (HLG): For Hybrid Log-Gamma assets, the optical-electro transfer function (OETF) can naturally degrade to standard gamma curves on legacy displays, using standard gamma approximations for the lower 50% of the signal.
Delegation to Host Rendering Pipelines
libavif is deliberately architected as an image
container parser and codec interface rather than a full color-grading
engine. Consequently, advanced non-parametric tone-mapping operations
are delegated to consuming frameworks:
- Chromium / Skia: When
libavifis used within web browsers, tone-mapping operators (such as tone-curve fitting or customized 3D LUTs) are executed by Skia or the underlying OS compositor (e.g., DirectComposition, CoreGraphics). - libplacebo: In media player integrations (such as
mpv or VLC),
libavifoutputs decoded pixel buffers in standard BT.2020 or P3 color spaces, which are then passed tolibplaceboto apply algorithms like Mobius, BT.2390 (EETF), or Spline-based tone-mapping.