Adds colour management to Siril.
- Siril loads a number of basic profiles at startup: sRGB and Rec 2020 profiles in linear, TRC and v2 export variants, plus Gray profiles with linear, sRGB TRC and Rec 709 TRC to match the color profiles.
- Dependent on preferences it also tries to load a custom monitor profile and soft proofing profile, plus optionally linear and TRC profiles for the user's preferred working gamut (if they want to use something else like ProPhoto).
- Preferences also support setting the ICC intents for display, soft proofing and export.
- The fits structure has an additional element for a lcms2 cmsHPROFILE ICC profile handle.
- If a FITS is loaded, if an ICC profile is embedded in an image extension (PixInsight does it this way) it is loaded and applied, otherwise the FITS is assumed to be linear in which case the FITS profile handle is set to a linear one (RGB or Gray dependent on n_channels). (This happens lazily, the first time the profile is required in order to render the FITS for display.)
- If a file (TIF, PNG or (JPEG iff Siril was built with libjpeg-turbo >=2.0.0) has an embedded ICC profile, the FITS profile handle is set to the profile read from the file. The function that loads HEIF files is configured with a target colour space of sRGB so the sRGB profile is copied into the FITS profile handle.
- In other cases (images such as BMP, PNMs that don't support ICC profiles) the image is presumed to be in sRGB space and the sRGB profile is copied into the FITS profile handle.
- When saving a file: a. FITS are saved in their working color space. A preference toggles whether ICC profiles should be embedded in saved FITS files (this defaults to TRUE). b. 32-bit files supporting ICC profile (only TIFs) will be saved without conversion with their current assigned ICC profile embedded. c. 8- and 16- bit files supporting ICC profiles will be mapped to ether sRGB color space (or, set by a preference, left in the working color space) and saved with the relevant profile embedded. d. 8- and 16- bit files that don't support ICC profiles will always be mapped to sRGB color space and saved with no embedded profile. I believe this best meets the assumptions of other software that such file formats will use sRGB.
- Color management for display is done in the remap() function. A colorspace transform display_transform is defined that maps the FITS ICC profile handle to the display profile (either sRGB or the custom monitor profile). The color space transform is applied as well as the LUT indexing. (Note that the special modes are treated slightly differently in the order of applying the LUT and the transform, in order to minimize having the shadows crushed by the 8-bit LUT.) 10.An extra display mode has been added - Soft proofing. If a soft proofing profile is defined in preferences, the soft proofing mode will apply a proofing transform from the working color space to the proofing color space as viewed in the display color space. No other transforms are applied as is possible using other display modes - this view provides a representation of what you should see if you print your image. If the "cut" toggle button is active, the display should show out-of-gamut colours in magenta. (I need some test files for this...)
- Remove fallback rgb_to_xyz transforms from scnr.c as these are handled by lcms2 now.
- Optimize transforms in scnr.c by doing a row at a time: this will allow fast float to use SIMD within the row and OMP to parallelize the transform across multiple rows.
- Rewrite the extract_channels code in colors.c to use lcms2
- Remove the rgb_to_xyz and xyz_to_rgb functions. (xyz_to_* and *_to_xyz can stay for now in case they remain useful for color spaces that lcms2 doesn't entirely handle)
- Fix reading of ICC profiles from JPEG files.
- User feedback: does the current approach of silently making assumptions work, or are there cases where the user should be asked via a dialog what color space to assign to the image, in the way that Gimp does? (This wouldn't always be practical, for example in sequence working where thousands of files will be being opened.)
- There are a lot of functions in Siril that use the HSL / HSV color space, which has horrible properties. Consider using better perceptually uniform color spaces for these functions, e.g. OKLab / OKLch, HSLuv, JzAzBz... (This will be in a separate MR.)