Coverage for colour/models/rgb/transfer_functions/tests/test_srgb.py: 100%
65 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-15 19:01 +1300
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-15 19:01 +1300
1"""
2Define the unit tests for the :mod:`colour.models.rgb.transfer_functions.sRGB`
3module.
4"""
6import numpy as np
8from colour.constants import TOLERANCE_ABSOLUTE_TESTS
9from colour.models.rgb.transfer_functions import eotf_inverse_sRGB, eotf_sRGB
10from colour.utilities import domain_range_scale, ignore_numpy_errors
12__author__ = "Colour Developers"
13__copyright__ = "Copyright 2013 Colour Developers"
14__license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"
15__maintainer__ = "Colour Developers"
16__email__ = "colour-developers@colour-science.org"
17__status__ = "Production"
19__all__ = [
20 "TestEotf_inverse_sRGB",
21 "TestEotf_sRGB",
22]
25class TestEotf_inverse_sRGB:
26 """
27 Define :func:`colour.models.rgb.transfer_functions.sRGB.eotf_inverse_sRGB`
28 definition unit tests methods.
29 """
31 def test_eotf_inverse_sRGB(self) -> None:
32 """
33 Test :func:`colour.models.rgb.transfer_functions.sRGB.\
34eotf_inverse_sRGB` definition.
35 """
37 np.testing.assert_allclose(
38 eotf_inverse_sRGB(0.0), 0.0, atol=TOLERANCE_ABSOLUTE_TESTS
39 )
41 np.testing.assert_allclose(
42 eotf_inverse_sRGB(0.18),
43 0.461356129500442,
44 atol=TOLERANCE_ABSOLUTE_TESTS,
45 )
47 np.testing.assert_allclose(
48 eotf_inverse_sRGB(1.0), 1.0, atol=TOLERANCE_ABSOLUTE_TESTS
49 )
51 def test_n_dimensional_eotf_inverse_sRGB(self) -> None:
52 """
53 Test :func:`colour.models.rgb.transfer_functions.sRGB.\
54eotf_inverse_sRGB` definition n-dimensional arrays support.
55 """
57 L = 0.18
58 V = eotf_inverse_sRGB(L)
60 L = np.tile(L, 6)
61 V = np.tile(V, 6)
62 np.testing.assert_allclose(
63 eotf_inverse_sRGB(L), V, atol=TOLERANCE_ABSOLUTE_TESTS
64 )
66 L = np.reshape(L, (2, 3))
67 V = np.reshape(V, (2, 3))
68 np.testing.assert_allclose(
69 eotf_inverse_sRGB(L), V, atol=TOLERANCE_ABSOLUTE_TESTS
70 )
72 L = np.reshape(L, (2, 3, 1))
73 V = np.reshape(V, (2, 3, 1))
74 np.testing.assert_allclose(
75 eotf_inverse_sRGB(L), V, atol=TOLERANCE_ABSOLUTE_TESTS
76 )
78 def test_domain_range_scale_eotf_inverse_sRGB(self) -> None:
79 """
80 Test :func:`colour.models.rgb.transfer_functions.sRGB.\
81eotf_inverse_sRGB` definition domain and range scale support.
82 """
84 L = 0.18
85 V = eotf_inverse_sRGB(L)
87 d_r = (("reference", 1), ("1", 1), ("100", 100))
88 for scale, factor in d_r:
89 with domain_range_scale(scale):
90 np.testing.assert_allclose(
91 eotf_inverse_sRGB(L * factor),
92 V * factor,
93 atol=TOLERANCE_ABSOLUTE_TESTS,
94 )
96 @ignore_numpy_errors
97 def test_nan_eotf_inverse_sRGB(self) -> None:
98 """
99 Test :func:`colour.models.rgb.transfer_functions.sRGB.\
100eotf_inverse_sRGB` definition nan support.
101 """
103 eotf_inverse_sRGB(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))
106class TestEotf_sRGB:
107 """
108 Define :func:`colour.models.rgb.transfer_functions.sRGB.eotf_sRGB`
109 definition unit tests methods.
110 """
112 def test_eotf_sRGB(self) -> None:
113 """
114 Test :func:`colour.models.rgb.transfer_functions.sRGB.\
115eotf_sRGB` definition.
116 """
118 np.testing.assert_allclose(eotf_sRGB(0.0), 0.0, atol=TOLERANCE_ABSOLUTE_TESTS)
120 np.testing.assert_allclose(
121 eotf_sRGB(0.461356129500442), 0.18, atol=TOLERANCE_ABSOLUTE_TESTS
122 )
124 np.testing.assert_allclose(eotf_sRGB(1.0), 1.0, atol=TOLERANCE_ABSOLUTE_TESTS)
126 def test_n_dimensional_eotf_sRGB(self) -> None:
127 """
128 Test :func:`colour.models.rgb.transfer_functions.sRGB.\
129eotf_sRGB` definition n-dimensional arrays support.
130 """
132 V = 0.461356129500442
133 L = eotf_sRGB(V)
135 V = np.tile(V, 6)
136 L = np.tile(L, 6)
137 np.testing.assert_allclose(eotf_sRGB(V), L, atol=TOLERANCE_ABSOLUTE_TESTS)
139 V = np.reshape(V, (2, 3))
140 L = np.reshape(L, (2, 3))
141 np.testing.assert_allclose(eotf_sRGB(V), L, atol=TOLERANCE_ABSOLUTE_TESTS)
143 V = np.reshape(V, (2, 3, 1))
144 L = np.reshape(L, (2, 3, 1))
145 np.testing.assert_allclose(eotf_sRGB(V), L, atol=TOLERANCE_ABSOLUTE_TESTS)
147 def test_domain_range_scale_eotf_sRGB(self) -> None:
148 """
149 Test :func:`colour.models.rgb.transfer_functions.sRGB.\
150eotf_sRGB` definition domain and range scale support.
151 """
153 V = 0.461356129500442
154 L = eotf_sRGB(V)
156 d_r = (("reference", 1), ("1", 1), ("100", 100))
157 for scale, factor in d_r:
158 with domain_range_scale(scale):
159 np.testing.assert_allclose(
160 eotf_sRGB(V * factor),
161 L * factor,
162 atol=TOLERANCE_ABSOLUTE_TESTS,
163 )
165 @ignore_numpy_errors
166 def test_nan_eotf_sRGB(self) -> None:
167 """
168 Test :func:`colour.models.rgb.transfer_functions.sRGB.\
169eotf_sRGB` definition nan support.
170 """
172 eotf_sRGB(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))