JXL gain maps render as SDR (not HDR)

#476652050 Filed 2026-01-17 Assigned / P3 Blink>Image>JXL CL 8676164

What the bug is

A JPEG XL container can carry an HDR gain map in an optional jhgm auxiliary box: ISO 21496-1 metadata, the alternate image's color encoding, and the gain map itself as a nested JPEG XL codestream. Chromium's JXL decoder read only the primary codestream, so gain-map files rendered as their SDR base image. JPEG and AVIF already go through Blink's auxiliary-image path and render HDR.

Fix: CL 8676164 "Decode JXL gain maps in Blink"

third_party/rust/jxl/v0_8/wrapper/gain_map.rs parses the jhgm envelope with the vendored jxl 0.8 crate (scan-only decode, request_aux_boxes = [HDR_GAIN_MAP]) and resolves the alternate image's ICC profile through JxlColorProfile::from_raw_bytes.

JXLImageDecoder::GetGainmapInfoAndData() exposes the metadata plus the container, and the auxiliary (cc::AuxImage::kGainmap) decoder selects the nested codestream itself, so DeferredImageDecoder and Skia drive rendering unchanged.

No new third-party crate; nothing vendored.

Proof: same file, decoder output before and after

The capture below is the real decoder output of trattore-gainmap.jxl, produced by a blink_platform_unittests harness built from CL 8676164. The "before" image is the primary codestream alone, which is exactly what Chromium renders today. The "after" images are the base image composited with the decoded gain map through SkGainmapShader at increasing display headroom, which is what Chromium now feeds to the compositor on an HDR display. All images are nearest-neighbour upscaled 4x (source is 134x100).

trattore-gainmap.jxl — base vs gain-map rendition

base image only
Before — primary codestream only, gain map ignored. Mean luma 121.6.
gain map applied at headroom 1.5
After, headroom 1.5 — mean luma 124.7, max per-channel delta 37.
gain map applied at headroom 2
After, headroom 2 — mean luma 126.9, max per-channel delta 54.
gain map applied at headroom 4
After, headroom 4 (the file's fDisplayRatioHdr) — mean luma 130.8, max per-channel delta 89.
difference between before and after
Diff — |after(4) - before|, amplified 2.5x. The highlights on the tractor and the sky carry the gain, flat shadow areas do not.
decoded gain map
Decoded gain map — the nested codestream from the jhgm box, 33x25 (quarter resolution), upscaled 16x.
live JXL render
Live — your browser decoding the file. Needs JPEG XL enabled; renders HDR only with CL 8676164 and an HDR display.

Numbers from the capture

rendermean lumamax channel delta vs basefully clipped pixels
before (base only)121.56—0
after, headroom 1.0121.34104
after, headroom 1.5124.7137221
after, headroom 2.0126.8554463
after, headroom 4.0130.7889766

At headroom 1.0 the gain-map rendition collapses back onto the base image (deltas are resampling noise), which is the expected SDR behavior. The capture is an 8-bit sRGB PNG, so the HDR boost shows up as brighter and partly clipped highlights; on an HDR display those pixels go above SDR white instead.

The test file

Built from Chromium's existing real-world gain-map JPEG web_tests/images/resources/gainmap-trattore0.jpg: base and gain map were extracted, re-encoded with cjxl, and wrapped in a JPEG XL container whose jhgm box reuses the ISO 21496-1 metadata of the upstream test fixture (fDisplayRatioHdr = 4, fGainmapRatioMax = 4, base type SDR).

size=12  type=JXL
size=20  type=ftyp
size=5334 type=jxlc   # base codestream, 134x100
size=5310 type=jhgm   # version 0
                      #   u16 metadata len = 141 (ISO 21496-1)
                      #   u8  color encoding len = 3
                      #   u32 compressed ICC len = 0
                      #   nested codestream 298 bytes, 33x25
⬇ trattore-gainmap.jxl ⬇ source gain-map JPEG CL 8676164 Issue 476652050

Automated coverage in the CL

out/Default/blink_platform_unittests --gtest_filter=JXLImageDecoderTest.*
[  PASSED  ] 66 tests.

Ten of those are new: metadata plus auxiliary decode, orientation alignment between base and gain map, waiting for the complete container, the structured color-encoding (alternate math space) path, and four negative cases where an invalid, truncated or undecodable gain map must leave the base image usable, plus two DeferredImageDecoder gain-map generator cases.