Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Starbix
Copy link

@Starbix Starbix commented Dec 23, 2025

This is a first go at code for converting image with nclx/CICP signals to scRGB. It's incomplete and was only briefly tested for my use case: HDR AVIF with PQ transfer and Display P3 primaries.

It seems to work reasonably well so far and the output JPG and PNG look much better than using copy.
Specifically the ultrahdr output in the JPG looks pretty good if the gainmap is shown.
pics.zip

In the zip you can find the original AVIF, the non-CICP-aware out_copy.jpg, and the CICP2scRGB outputs (both PNG and JPG, but original PNG was too large).

TODO:

  • Add support for other loaders, e.g. PNG
  • Handle other transfer characteristics
  • Add more colour primary matrices
  • Make it faster/more elegant
  • Add tests

@Starbix Starbix marked this pull request as draft December 23, 2025 12:26
@Starbix Starbix force-pushed the cicp2scrgb branch 3 times, most recently from f9b7bbd to b938075 Compare December 24, 2025 10:46
@jcupitt
Copy link
Member

jcupitt commented Dec 24, 2025

Great!

JXL also has CICP, so that would be a good one to add.

I bumped master to 8.19 ready for this to be merged when it's done.

@Starbix Starbix force-pushed the cicp2scrgb branch 3 times, most recently from 3783b75 to a855895 Compare December 28, 2025 14:24
@Starbix
Copy link
Author

Starbix commented Dec 28, 2025

CICP is now its own "colourspace" and transformations always go via scRGB. So "copy" from a CICP-tagged file should now yield somewhat decent colours. The libheif saver now also has support for CICP/nclx values. PNG saver should be relatively straightforward. Formats other than HEIF/AVIF/PNG/JXL could also profit from this, but there we'd need to generate an ICC profile with the "cicp" tag. That ICC profile should only be used for final output as lcms2 wouldn't support any transformations with it. So far conversion to CICP is not implemented.
JXL is also a special case as it doesn't implement H.273 (rarely used options removed, but support for more colour spaces). This isn't handled super gracefully yet.
I probably broke TIFF support here, as TIFF is usually assumed to support any format. But it only supports CICP via ICC profiles.
Bitdepths also need a second look.

@Starbix Starbix changed the title Add CICP2scRGB Add CICP and HDR support Dec 28, 2025
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.

2 participants