Repository navigation
Tone map PQ and HLG HEICs in decode_bounded - #42
Merged
laurenspriem merged 2 commits intoNov 30, 2026
Merged
laurenspriem merged 2 commits into
laurenspriem merged 2 commits into
Conversation
decode_bounded refused every 10-bit file, so HDR HEICs from cameras and editing tools fell back to the full decode, which shows raw PQ or HLG values as if they were sRGB. Bounded decoding now accepts 8-, 10- and 12-bit 4:2:0 HEVC, including the negative QPs those depths allow, and checks that pixi matches the coded bit depth. PQ and HLG colour, taken from the cicp tag of a valid RGB ICC profile, the container nclx or, without container colour, the HEVC VUI, is converted to display light with 203 cd/m2 as SDR reference white. HLG goes through the BT.2100 OOTF for a 1000 cd/m2 display. The colour is converted to BT.709 and the BT.2390 EETF is applied to the largest component, using the clli or mdcv peak (1000 cd/m2 when absent) as the source peak. Reference white lands at 229 of 255 for a 1000 cd/m2 peak and highlights roll off to white. Malformed, repeated or zero light levels are ignored, and grid tiles may carry different ones. Contradictory HDR signalling is still refused, the incremental experiment and its rolling decoder stay 8-bit SDR, and 10- and 12-bit SDR images decode exactly like the RGB8 path followed by the ICC conversion. The regular RGB8 region converter now shares its setup and generic loop with a native-depth RGB sample converter; regular output is unchanged on a 454-file sweep. The bounded oracle comparison now asks libheif for images above 8 bits at their coded depth and rounds each sample once, because libheif's own 8-bit output truncates them and put the 10- and 12-bit stress files up to 10 levels off.
Author
|
@codex review |
…-hdr-support-0e0715 The 4:4:4 conversion for odd crops, rotations and mirrors assumed 8-bit samples and RGB8 output. It now converts at the coded bit depth and tone maps PQ and HLG bands, so 10- and 12-bit images that need it decode like the regular decoders and HDR ones are tone mapped.
This was referenced Dec 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
decode_boundedrefused every 10-bit HEIC, so HDR photos fell back to the regular decoder, which returns the raw PQ or HLG samples. Shown as sRGB, those look flat and washed out. Since the Ente viewer also usesdecode_bounded, the tone mapping is aimed at viewing, not only thumbnails and ML.decode_boundednow accepts 8-, 10- and 12-bit 4:2:0 HEVC and tone maps PQ and HLG to sRGB:cicptag, otherwise the container nclx, otherwise the HEVC VUI.clliormdcvvalue, or 1000 cd/m² if neither is set.Other high-bit-depth behaviour:
clli/mdcvboxes never fail a decode.The regular and
image-crate decodes are unchanged: their RGB8 and RGBA output hashes matchmainon 454 files.The bounded oracle step in CI needed a change to the libheif reference. libheif's 8-bit output truncates samples above 8 bits (
in >> shift), which put the six 10- and 12-bit stress files up to 10 levels off. The oracle now decodes those images at their coded depth and rounds each sample once. With that change they match libheif exactly at full size and within 1 when downscaled. A 10-bit stream with a negative slice QP (from a hand-edited x265 encode) also matches libheif exactly.Not tested with real camera HDR HEICs or in the app. 4:2:2 HDR is still refused, and Apple gain-map photos still decode as their SDR base image.
Source fork PR: laurens-pilot#30
@laurenspriem