Commit Graph

5 Commits

Author SHA1 Message Date
Pekka Paalanen 9f4a9089f4 tests: fix perceptual intent in cLUT ICC profiles
The ICC profiles created for tests here are supposed to produce the same
results regardless of whether they are of the matrix-shaper or cLUT
form, and whether the compositor uses a colorimetric or perceptual
rendering intent. This is silly, but it fits our tests very well since
we mostly want to ensure correct computations in matrix and cLUT code
rather than meaningful results from different rendering intents.

When trying to switch the compositor from colorimetric to perceptual
rendering intent as required by the color-management protocol extension,
all and only the cLUT based tests failed (color-icc-output test).

The reason is that ICCv4 defines the perceptual PCS having a specific
non-zero black point. It requires ICC profiles to convert device black
to the PCS black and vice versa. However, matrix-shaper type ICC
profiles have no way to provide a perceptual transformation to/from PCS
separate from the colorimetric transformation. Hence, LittleCMS exempts
ICCv4 matrix-shaper profiles from the ICCv4 perceptual PCS definition.

Black point compensation (BPC) is always added by LittleCMS with the
perceptual rendering intent. If an ICC profile claims to be ICC version
4, the perceptual transformation in it is assumed to adhere to the
percptual PCS black point, which is non-zero. Hence, DToB0 and BToD0
tags need to respect that so that BPC works correctly.

Before this patch, DToB0 and BToD0 transformations did not use the
correct PCS black point, so when BPC got added, the color space
conversion went wrong. This patch replicates the BPC algorithm that
LittleCMS uses in order to respect the perceptual PCS definition. This
will then cancel out with the BPC added by LittleCMS, producing the
expected color space conversion.

The problem arises only with cLUT ICC profiles because matrix-shaper
profiles are exempt: the black points between source (always
matrix-shaper sRGB profile for now) and destination color spaces match,
and no BPC is added by LittleCMS.

There is no way to ask LittleCMS to add its BPC on our will, so we need
to copy that code from LittleCMS 2.16.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2024-04-19 12:19:36 +00:00
Pekka Paalanen 94ccce4e38 tests: replace mat2XYZ
The primaries and the white point are the fundamental definition of the
color spaces in these tests. Instead of hard-coding mat2XYZ, use
LittleCMS to derive the result from the fundamental definition.

This removes derived hard-coded constants, which is a benefit in itself.
How these constants were originally produced was not mentioned in
0c5860fafb but I was able to reproduce
them with python3:

import colour
import numpy as np
x = colour.RGB_COLOURSPACES['sRGB']
w_d50 = np.array([0.34567, 0.35850])
print(x.chromatically_adapt(w_d50, 'D50', 'Bradford'))

It's identical to 3-4 decimals of the hardcoded values, and also for
Adobe RGB. I printed the LittleCMS generated values as well, and they
are the same as with python up to roughly 4 decimals.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2024-04-19 12:19:36 +00:00
Leandro Ribeiro ac3e416402 tests: move functions that create ICC profiles to lcms_util.c
We'll need to craft ICC profiles in the CM&HDR protocol implementation
tests. So move it from color-icc-output-test.c to the LittleCMS helper
in our test suite.

This also removes some unused headers from color-icc-output-test.c, as
we've moved a bunch of code to the LittleCMS helper.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2024-02-12 14:10:44 +00:00
Pekka Paalanen 5921a00b38 tests/lcms_util: add SetTextTags()
This function sets some basic text tags to make an ICC file better
formed.

The code is taken from LittleCMS, https://github.com/mm2/Little-CMS.git
git revision
lcms2.13.1-28-g6ae2e99 (6ae2e99a3535417ca5c95b602eb61fdd29d294d0)
file src/cmsvirt.c.

Suggested-by: Vitaly Prosyak <vitaly.prosyak@amd.com>
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2022-06-03 10:22:25 +00:00
Pekka Paalanen 44c3079567 tests: add lcms-util with MPE curves
This adds a new test helper library that depends on LittleCMS 2.

For starters, the library implements conversion from enum transfer_fn to
ICC multiProcessingElements compatible LittleCMS curve object.

That conversion allows encoding transfer funtions in ICC files and
LittleCMS pipelines with full float32 precision instead of forcing a
conversion to a 1D LUT which for power-type curves is surprisingly
imprecise.

This also adds CI tests to make sure the conversion matches our
hand-coded transfer functions.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2022-06-03 10:22:25 +00:00