nv12: HDR-correct input — PQ/HLG EOTF + BT.2020→709 gamut (Stage A pt 1)

Decode HDR video into the linear compositor correctly instead of approximating
everything as sRGB/BT.709:

- Read the frame's color_trc and color_primaries in the importer → VideoTransfer
  {Gamma,Pq,Hlg} + VideoPrimaries {Bt709,Bt2020} on GpuVideoFrame.
- nv12_blit.wgsl: branch the EOTF — sRGB gamma (SDR), SMPTE2084 PQ (normalized so
  203-nit graphics white = 1.0; highlights exceed 1.0), or HLG inverse-OETF
  (reference white ≈ 1.0). Then BT.2020→BT.709 primaries in linear light when
  wide-gamut, clamping out-of-709 colours.

Establishes the white=1.0 scene-linear convention: SDR content is unchanged
(stays in [0,1]); HDR video carries super-white highlights through compositing.
SDR-output mapping (clip default vs highlight rolloff) is Part 2. HLG's display
OOTF is omitted (scene-referred) — approximate but reasonable for SDR-out.
This commit is contained in:
Skyler Lehmkuhl
2026-06-26 02:47:09 -04:00
parent 6348e57de0
commit ff490ab9ae
5 changed files with 121 additions and 12 deletions
@@ -719,6 +719,31 @@ pub struct GpuVideoFrame {
/// so SD (BT.601) and HD/UHD clips each convert correctly: `[Cr→R, Cb→G, Cr→G, Cb→B]`.
/// R = Y + c[0]·Cr, G = Y + c[1]·Cb + c[2]·Cr, B = Y + c[3]·Cb
pub coeffs: [f32; 4],
/// Opto-electronic transfer of the encoded R'G'B' — the compositor applies the matching EOTF to
/// reach scene-linear (graphics white = 1.0). HDR (PQ/HLG) values exceed 1.0.
pub transfer: VideoTransfer,
/// Colour primaries; BT.2020 is gamut-mapped to the compositor's BT.709 space in linear light.
pub primaries: VideoPrimaries,
}
/// Transfer characteristic of a decoded video frame (selects the EOTF in the NV12→linear pass).
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum VideoTransfer {
/// SDR gamma (BT.709/sRGB/601/gamma22) — approximated by the sRGB EOTF.
Gamma,
/// SMPTE ST 2084 (PQ) — absolute, normalized so 203 nits (graphics white) = 1.0.
Pq,
/// ARIB STD-B67 (HLG) — scene-referred, normalized so reference white ≈ 1.0.
Hlg,
}
/// Colour primaries of a decoded video frame.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum VideoPrimaries {
/// BT.709 / sRGB (also used for BT.601, whose primaries differ only slightly).
Bt709,
/// BT.2020 (wide gamut) — converted to BT.709 in linear light by the compositor.
Bt2020,
}
/// Y'CbCr→R'G'B' matrix coefficients (`[Cr→R, Cb→G, Cr→G, Cb→B]`) from the luma weights `kr`/`kb`