Coverage for colour/models/rgb/transfer_functions/tests/test_smpte_240m.py: 100%
67 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
3:mod:`colour.models.rgb.transfer_functions.smpte_240m` module.
4"""
6import numpy as np
8from colour.constants import TOLERANCE_ABSOLUTE_TESTS
9from colour.models.rgb.transfer_functions import eotf_SMPTE240M, oetf_SMPTE240M
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 "TestOetf_SMPTE240M",
21 "TestEotf_SMPTE240M",
22]
25class TestOetf_SMPTE240M:
26 """
27 Define :func:`colour.models.rgb.transfer_functions.smpte_240m.\
28oetf_SMPTE240M` definition unit tests methods.
29 """
31 def test_oetf_SMPTE240M(self) -> None:
32 """
33 Test :func:`colour.models.rgb.transfer_functions.smpte_240m.\
34oetf_SMPTE240M` definition.
35 """
37 np.testing.assert_allclose(
38 oetf_SMPTE240M(0.0), 0.0, atol=TOLERANCE_ABSOLUTE_TESTS
39 )
41 np.testing.assert_allclose(
42 oetf_SMPTE240M(0.02),
43 0.080000000000000,
44 atol=TOLERANCE_ABSOLUTE_TESTS,
45 )
47 np.testing.assert_allclose(
48 oetf_SMPTE240M(0.18),
49 0.402285796753870,
50 atol=TOLERANCE_ABSOLUTE_TESTS,
51 )
53 np.testing.assert_allclose(
54 oetf_SMPTE240M(1.0), 1.0, atol=TOLERANCE_ABSOLUTE_TESTS
55 )
57 def test_n_dimensional_oetf_SMPTE240M(self) -> None:
58 """
59 Test :func:`colour.models.rgb.transfer_functions.smpte_240m.\
60oetf_SMPTE240M` definition n-dimensional arrays support.
61 """
63 L_c = 0.18
64 V_c = oetf_SMPTE240M(L_c)
66 L_c = np.tile(L_c, 6)
67 V_c = np.tile(V_c, 6)
68 np.testing.assert_allclose(
69 oetf_SMPTE240M(L_c), V_c, atol=TOLERANCE_ABSOLUTE_TESTS
70 )
72 L_c = np.reshape(L_c, (2, 3))
73 V_c = np.reshape(V_c, (2, 3))
74 np.testing.assert_allclose(
75 oetf_SMPTE240M(L_c), V_c, atol=TOLERANCE_ABSOLUTE_TESTS
76 )
78 L_c = np.reshape(L_c, (2, 3, 1))
79 V_c = np.reshape(V_c, (2, 3, 1))
80 np.testing.assert_allclose(
81 oetf_SMPTE240M(L_c), V_c, atol=TOLERANCE_ABSOLUTE_TESTS
82 )
84 def test_domain_range_scale_oetf_SMPTE240M(self) -> None:
85 """
86 Test :func:`colour.models.rgb.transfer_functions.smpte_240m.\
87oetf_SMPTE240M` definition domain and range scale support.
88 """
90 L_c = 0.18
91 V_c = oetf_SMPTE240M(L_c)
93 d_r = (("reference", 1), ("1", 1), ("100", 100))
94 for scale, factor in d_r:
95 with domain_range_scale(scale):
96 np.testing.assert_allclose(
97 oetf_SMPTE240M(L_c * factor),
98 V_c * factor,
99 atol=TOLERANCE_ABSOLUTE_TESTS,
100 )
102 @ignore_numpy_errors
103 def test_nan_oetf_SMPTE240M(self) -> None:
104 """
105 Test :func:`colour.models.rgb.transfer_functions.smpte_240m.\
106oetf_SMPTE240M` definition nan support.
107 """
109 oetf_SMPTE240M(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))
112class TestEotf_SMPTE240M:
113 """
114 Define :func:`colour.models.rgb.transfer_functions.smpte_240m.\
115eotf_SMPTE240M` definition unit tests methods.
116 """
118 def test_eotf_SMPTE240M(self) -> None:
119 """
120 Test :func:`colour.models.rgb.transfer_functions.smpte_240m.\
121eotf_SMPTE240M` definition.
122 """
124 np.testing.assert_allclose(
125 eotf_SMPTE240M(0.0), 0.0, atol=TOLERANCE_ABSOLUTE_TESTS
126 )
128 np.testing.assert_allclose(
129 eotf_SMPTE240M(0.080000000000000),
130 0.02,
131 atol=TOLERANCE_ABSOLUTE_TESTS,
132 )
134 np.testing.assert_allclose(
135 eotf_SMPTE240M(0.402285796753870),
136 0.18,
137 atol=TOLERANCE_ABSOLUTE_TESTS,
138 )
140 np.testing.assert_allclose(
141 eotf_SMPTE240M(1.0), 1.0, atol=TOLERANCE_ABSOLUTE_TESTS
142 )
144 def test_n_dimensional_eotf_SMPTE240M(self) -> None:
145 """
146 Test :func:`colour.models.rgb.transfer_functions.smpte_240m.\
147eotf_SMPTE240M` definition n-dimensional arrays support.
148 """
150 V_r = 0.402285796753870
151 L_r = eotf_SMPTE240M(V_r)
153 V_r = np.tile(V_r, 6)
154 L_r = np.tile(L_r, 6)
155 np.testing.assert_allclose(
156 eotf_SMPTE240M(V_r), L_r, atol=TOLERANCE_ABSOLUTE_TESTS
157 )
159 V_r = np.reshape(V_r, (2, 3))
160 L_r = np.reshape(L_r, (2, 3))
161 np.testing.assert_allclose(
162 eotf_SMPTE240M(V_r), L_r, atol=TOLERANCE_ABSOLUTE_TESTS
163 )
165 V_r = np.reshape(V_r, (2, 3, 1))
166 L_r = np.reshape(L_r, (2, 3, 1))
167 np.testing.assert_allclose(
168 eotf_SMPTE240M(V_r), L_r, atol=TOLERANCE_ABSOLUTE_TESTS
169 )
171 def test_domain_range_scale_eotf_SMPTE240M(self) -> None:
172 """
173 Test :func:`colour.models.rgb.transfer_functions.smpte_240m.\
174eotf_SMPTE240M` definition domain and range scale support.
175 """
177 V_r = 0.402285796753870
178 L_r = eotf_SMPTE240M(V_r)
180 d_r = (("reference", 1), ("1", 1), ("100", 100))
181 for scale, factor in d_r:
182 with domain_range_scale(scale):
183 np.testing.assert_allclose(
184 eotf_SMPTE240M(V_r * factor),
185 L_r * factor,
186 atol=TOLERANCE_ABSOLUTE_TESTS,
187 )
189 @ignore_numpy_errors
190 def test_nan_eotf_SMPTE240M(self) -> None:
191 """
192 Test :func:`colour.models.rgb.transfer_functions.smpte_240m.\
193eotf_SMPTE240M` definition nan support.
194 """
196 eotf_SMPTE240M(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))