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.
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.
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).
fDisplayRatioHdr) — mean luma 130.8, max per-channel
delta 89.
jhgm box, 33x25 (quarter resolution),
upscaled 16x.| render | mean luma | max channel delta vs base | fully clipped pixels |
|---|---|---|---|
| before (base only) | 121.56 | — | 0 |
| after, headroom 1.0 | 121.34 | 10 | 4 |
| after, headroom 1.5 | 124.71 | 37 | 221 |
| after, headroom 2.0 | 126.85 | 54 | 463 |
| after, headroom 4.0 | 130.78 | 89 | 766 |
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.
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
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.