Skip to content

Color management update (fixes #1010, #1207)

Adrian Knagg-Baugh requested to merge lcms2 into master

This MR revamps color management in Siril and extends it to all image types. A default working color space can be set as well as custom monitor and soft proofing transforms, color profiles can be assigned to images manually or automatically and conversion between color profiles is possible (RGB and Gray only).

One use case is shown in #1207 (closed) (accurate conversion from linear light to a working space and accurate display on a monitor) in order to assess image chromaticity from a calibrated dSLR. Another use case is support for editing images in wide gamut color spaces.

This will also provide the groundwork for a future MR to implement correct conversion of >8bpp HEIF, AVIF and JPEGXL files to HLG tone response curves in order to output files that are compliant with HDR10 HLG etc. (once this and the JPEGXL MR have both merged). It may also support future HDR image blending.

The default behaviour is to use sRGB as the working space and the display space. This means no color space transforms are actually done (for display) thus causing a negligible CPU overhead and the extent of the MR is to manage profiles and ensure that files are saved in the right color space. If the defaults are changed then color space transforms are carried out as necessary. Furthermore, no color management operations are carried out in scriptable commands with the exception of 3 new commands - icc_assign, icc_convert and icc_remove.

Two Little CMS contexts are used, one with the fast_float and threaded plugins and one with only the fast_float plugin. The ff + threaded plugin is used for single image processing where all threads may be used to process an image; the ff-only plugin is used for sequence processing where a single thread is allocated per image. This prevents contention between OpenMP and the pthreads threading code used in the Little CMS threading plugin.

NOTES FOR REVIEWERS

This MR looks a bit scary as the changes touch a lot of files. However everything in algos/lcms_acceleration can be ignored for review purposes, as it is library code that we have to include as the standard distributions don't build the fast float and threaded plugins as part of their lcms2 packages. Ignoring that directory reduces the code a lot! And although a lot of files are touched, the changes in many of them are only a few lines of code.

For the actual implementation code, the most important files are:

  • core/icc_profile.c, which does most of the initialization and management of profiles and transforms
  • gui/image_display.c, which does the rendering to display including the new soft proofing display mode
  • io/image_format_fits.c, this includes new code to read and write embedded ICC profiles in FITS in the same manner as PixInsight
  • io/image_format_libraries.c, this includes the IO code that handles TIFF and PNG formats, which come in a range of bit depths and in the case of PNG uses bulky rather than planar pixel packing, it also includes JPG support

Apart from those, the other IO code is pretty straightforward, simply assigning an appropriate profile depending on what is appropriate for the format, or converting to sRGB prior to saving to formats that don't support color profiles.

There's also some fairly standard UI and preferences code, and various little bits of code that do specific things in various tools, such as:

  • Prompt to convert from a linear to a nonlinear working profile on occasions selected in preferences;
  • Manage the image profile in starnet code, because the starnet app does not implement color management;
  • Make use of lcms2 for {profile}-to-CIEL*a*b* transforms in various places;
  • Manage what the resulting profile should be when combining images using pixelmath, RGB composition or remixer.

Many of the utility functions for handling ICC profiles are shamelessly based on the Gimp 3 color profile handling code from Gimp github.

Edited by Vincent Hourdin

Merge request reports