From 2ca9e01bc86d302def859626303f09d321e90596 Mon Sep 17 00:00:00 2001 From: facelessuser Date: Tue, 10 May 2022 14:27:23 -0600 Subject: [PATCH] Fix cat16 not applying the matrix --- coloraide/cat.py | 2 +- docs/src/markdown/about/changelog.md | 1 + tests/test_cat.py | 33 ++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 tests/test_cat.py diff --git a/coloraide/cat.py b/coloraide/cat.py index 882b88788..15cb06c7f 100644 --- a/coloraide/cat.py +++ b/coloraide/cat.py @@ -232,7 +232,7 @@ class CAT16(VonKries): NAME = "cat16" - M = [ + MATRIX = [ [-0.401288, -0.250268, -0.002079], [0.650173, 1.204414, 0.048952], [-0.051461, -0.045854, -0.953127] diff --git a/docs/src/markdown/about/changelog.md b/docs/src/markdown/about/changelog.md index 07663e9f9..8623c5f3c 100644 --- a/docs/src/markdown/about/changelog.md +++ b/docs/src/markdown/about/changelog.md @@ -5,6 +5,7 @@ - **NEW**: Allow dictionary input to use aliases in the dictionary. - **FIX**: If too many channels are given to a color space via raw data, ensure the operation fails. - **FIX**: Sync up achromatic logic of the Okhsl and Okhsv `normalize` function with the actual conversion algorithm. +- **FIX**: Regression that caused `cat16` not to work due to a misnamed variable. ## 0.17.0 diff --git a/tests/test_cat.py b/tests/test_cat.py new file mode 100644 index 000000000..929dc7337 --- /dev/null +++ b/tests/test_cat.py @@ -0,0 +1,33 @@ +"""Test chromatic adaptation.""" +from coloraide import Color +from coloraide import cat +from coloraide import util as cutil +from . import util +import pytest + + +class TestCAT(util.ColorAssertsPyTest): + """Test CAT.""" + + @pytest.mark.parametrize( + 'method,cat1,cat2', + [ + ('bradford', cat.WHITES['2deg']['D65'], cat.WHITES['2deg']['D50']), + ('von-kries', cat.WHITES['2deg']['D65'], cat.WHITES['2deg']['D50']), + ('xyz-scaling', cat.WHITES['2deg']['D65'], cat.WHITES['2deg']['D50']), + ('cat02', cat.WHITES['2deg']['D65'], cat.WHITES['2deg']['D50']), + ('cmccat97', cat.WHITES['2deg']['D65'], cat.WHITES['2deg']['D50']), + ('sharp', cat.WHITES['2deg']['D65'], cat.WHITES['2deg']['D50']), + ('cmccat2000', cat.WHITES['2deg']['D65'], cat.WHITES['2deg']['D50']), + ('cat16', cat.WHITES['2deg']['D65'], cat.WHITES['2deg']['D50']) + + ] + ) + def test_cat(self, method, cat1, cat2): + """Test CAT methods.""" + + c1 = Color('white').convert('xyz-d65') + c2 = Color('xyz-d50', c1.chromatic_adaptation(cat1, cat2, c1[:-1], method=method)) + c3 = Color('xyz-d65', c2.chromatic_adaptation(cat2, cat1, c2[:-1], method=method)) + self.assertColorEqual(c1, c3) + self.assertColorEqual(c2, Color('xyz-d50', cutil.xy_to_xyz(cat2)))