[WIP] Create synthetic ICC profile from nclx tag in libheif #4723
+150
−2
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.
This is a WIP PR trying to fix #3912.
HDR AVIF (and most likely HEIF) files that lack an ICC profile signal their interpretation via CICP values (as defined in H.273) in the nclx field. libvips ignores this information, leading to very desaturated colors.
This PR attempts to create an ICC profile from the CICP. Creating a simple parametric curve ICC profile does not work for PQ/HLG as the curves defined by lcms2 aren't able to cover PQ or HLG. Thus in this PR I simply applied ITU-R BT.2020-2 curves.

This doesn't solve the wrong brightness. Defined in ICC v4.4 there is a CICP tag which can signal the exact transfer function. This is interpreted by Chromium and macOS Preview (I didn't test other clients). Unfortunately, this tag is not supported by lcms2: (mm2/Little-CMS#439). Meaning in case of an
icc_transformthat HDR information is lost again. But at least it makes it already easier for downstream clients (such as Immich) to handle HDR from libheif more easily (e.g. by not doing an icc_transform)In a second step we should add a tonemapping curve instead so clients (such as libvips itself) that don't support the cicp tag in the ICC profile can still produce a decent looking image. relevant: https://issues.chromium.org/issues/40239687, discord/lilliput#218
I only tested this with a P3 PQ HDR file created by Adobe Lightroom.
I have attached three files: the original HDR AVIF, the output JPG by upstream libvips, and the JPG with an HDR ICC profile.
examples.zip