Skip to content

Conversation

@lgritz
Copy link
Collaborator

@lgritz lgritz commented Jan 3, 2026

Starting with 1.21, libheif seems to change behavior: When no CICP metadata is present, libheif now returns 2,2,2 (all unspecified) on read. OIIO convention, though, is to not set the attribute if valid CICP data is not in the file.

Signed-off-by: Larry Gritz <lg@larrygritz.com>
Exif:FlashPixVersion: "0100"
heif:UnassociatedAlpha: 1
oiio:BitsPerSample: 10
oiio:ColorSpace: "srgb_rec709_scene"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing a local diff between this new ref output and the others shows what look like reasonable changes except this oiio:ColorSpace value here. Given the file is called colorspace_hlg.avif and the other reference outputs say oiio:ColorSpace: "hlg_rec2020_display", do we have to worry about this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So... I wondered about this as well.

Without my changing any heif related code in OIIO, it started failing for me locally on all branches, on my Mac laptop when Homebrew updated the libheif version from 1.20 to 1.21. So I'm going on the assumption that this is one of those version-to-version changes in behavior that we just have to absorb by providing more reference outputs for the new version. (libheif seems especially prone to frequent changes like this, I believe there are more reference output variations in testsuite/heif than any other test.)

I admit that I did not try to square this with changes in libheif internals to understand exactly what changed and validate that it's correct. Did they fix a bug? Introduce a new bug? Or just have a neutral change in behavior that is an equally plausible thing to report.

@zachlewis @brechtvl You're the additional CICP and color experts here. Do you have opinions or concerns?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... interesting.

In briefly glancing at the libheif changes that affect our reader:

I haven't looked at our test images yet, but if the only differences between cicp_pq.avif and colorspace_hlg.avif really are the actual color space encodings and the CICP values stored in the nclx colr box (9-16-9-1 versus 9-18-9-1), this is could be an upstream error...

I'd be interested to know what the heif reader does when it encounters an ICCv4 profile carrying CICP metadata...

Copy link
Contributor

@brechtvl brechtvl Jan 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When no CICP metadata is present, libheif now returns 2,2,2 (all unspecified) on read. The HLG case fails because it's using --attrib oiio:ColorSpace rather than --iscolorspace, so the CICP value does not get overridden.

Not sure if this is something that should be fixed in libheif, but the easy solution on the OIIO side would be to just ignore such unspecified CICP values.

diff --git a/src/heif.imageio/heifinput.cpp b/src/heif.imageio/heifinput.cpp
index 349bcdb1d..9e0230a86 100644
--- a/src/heif.imageio/heifinput.cpp
+++ b/src/heif.imageio/heifinput.cpp
@@ -287,7 +287,14 @@ HeifInput::seek_subimage(int subimage, int miplevel)
             m_ihandle.get_raw_image_handle(), &nclx);

         if (nclx) {
-            if (err.code == heif_error_Ok) {
+            // When CICP metadata is not present in the file, libheif returns
+            // unspecified since v1.21. Ignore it then.
+            if (err.code == heif_error_Ok
+                && !(nclx->color_primaries == heif_color_primaries_unspecified
+                     && nclx->transfer_characteristics
+                            == heif_transfer_characteristic_unspecified
+                     && nclx->matrix_coefficients
+                            == heif_matrix_coefficients_unspecified)) {
                 const int cicp[4] = { int(nclx->color_primaries),
                                       int(nclx->transfer_characteristics),
                                       int(nclx->matrix_coefficients),

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I like this idea Brecht. If our convention is to not set CICP metadata if it's not present in the file, this preserves that behavior for the new libheif.

I will try that out.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated with your suggestion. It eliminates the need for the extra reference output, so I removed it.

@lgritz lgritz requested review from brechtvl and zachlewis January 4, 2026 21:58
… set it

Signed-off-by: Larry Gritz <lg@larrygritz.com>
@lgritz lgritz changed the title deps: Update ref output for libheif 1.21 deps: libheif 1.21 support Jan 5, 2026
@lgritz
Copy link
Collaborator Author

lgritz commented Jan 5, 2026

I updated the PR's title and description after incorporating Brecht's suggestion for the correct solution.

@lgritz lgritz merged commit c3ccc9e into AcademySoftwareFoundation:main Jan 5, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants