Coverage for models/rgb/transfer_functions/tests/test_apple_log_profile.py: 100%
65 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-16 22:49 +1300
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-16 22:49 +1300
1"""
2Define the unit tests for the :mod:`colour.models.rgb.transfer_functions.\
3apple_log_profile` module.
4"""
6import numpy as np
8from colour.constants import TOLERANCE_ABSOLUTE_TESTS
9from colour.models.rgb.transfer_functions import (
10 log_decoding_AppleLogProfile,
11 log_encoding_AppleLogProfile,
12)
13from colour.utilities import domain_range_scale, ignore_numpy_errors
15__author__ = "Colour Developers"
16__copyright__ = "Copyright 2013 Colour Developers"
17__license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"
18__maintainer__ = "Colour Developers"
19__email__ = "colour-developers@colour-science.org"
20__status__ = "Production"
22__all__ = [
23 "TestLogEncoding_AppleLogProfile",
24 "TestLogDecoding_AppleLogProfile",
25]
28class TestLogEncoding_AppleLogProfile:
29 """
30 Define :func:`colour.models.rgb.transfer_functions.apple_log_profile.\
31log_encoding_AppleLogProfile` definition unit tests methods.
32 """
34 def test_log_encoding_AppleLogProfile(self) -> None:
35 """
36 Test :func:`colour.models.rgb.transfer_functions.apple_log_profile.\
37log_encoding_AppleLogProfile` definition.
38 """
40 np.testing.assert_allclose(
41 log_encoding_AppleLogProfile(0.0),
42 0.150476452300913,
43 atol=TOLERANCE_ABSOLUTE_TESTS,
44 )
46 np.testing.assert_allclose(
47 log_encoding_AppleLogProfile(0.18),
48 0.488272458526868,
49 atol=TOLERANCE_ABSOLUTE_TESTS,
50 )
52 np.testing.assert_allclose(
53 log_encoding_AppleLogProfile(1.0),
54 0.694552983055191,
55 atol=TOLERANCE_ABSOLUTE_TESTS,
56 )
58 def test_n_dimensional_log_encoding_DLog(self) -> None:
59 """
60 Test :func:`colour.models.rgb.transfer_functions.apple_log_profile.\
61log_encoding_AppleLogProfile` definition n-dimensional arrays support.
62 """
64 R = 0.18
65 P = log_encoding_AppleLogProfile(R)
67 R = np.tile(R, 6)
68 P = np.tile(P, 6)
69 np.testing.assert_allclose(
70 log_encoding_AppleLogProfile(R), P, atol=TOLERANCE_ABSOLUTE_TESTS
71 )
73 R = np.reshape(R, (2, 3))
74 P = np.reshape(P, (2, 3))
75 np.testing.assert_allclose(
76 log_encoding_AppleLogProfile(R), P, atol=TOLERANCE_ABSOLUTE_TESTS
77 )
79 R = np.reshape(R, (2, 3, 1))
80 P = np.reshape(P, (2, 3, 1))
81 np.testing.assert_allclose(
82 log_encoding_AppleLogProfile(R), P, atol=TOLERANCE_ABSOLUTE_TESTS
83 )
85 def test_domain_range_scale_log_encoding_DLog(self) -> None:
86 """
87 Test :func:`colour.models.rgb.transfer_functions.apple_log_profile.\
88log_encoding_AppleLogProfile` definition domain and range scale support.
89 """
91 R = 0.18
92 P = log_encoding_AppleLogProfile(R)
94 d_r = (("reference", 1), ("1", 1), ("100", 100))
95 for scale, factor in d_r:
96 with domain_range_scale(scale):
97 np.testing.assert_allclose(
98 log_encoding_AppleLogProfile(R * factor),
99 P * factor,
100 atol=TOLERANCE_ABSOLUTE_TESTS,
101 )
103 @ignore_numpy_errors
104 def test_nan_log_encoding_DLog(self) -> None:
105 """
106 Test :func:`colour.models.rgb.transfer_functions.apple_log_profile.\
107log_encoding_AppleLogProfile` definition nan support.
108 """
110 log_encoding_AppleLogProfile(
111 np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan])
112 )
115class TestLogDecoding_AppleLogProfile:
116 """
117 Define :func:`colour.models.rgb.transfer_functions.apple_log_profile.\
118log_decoding_AppleLogProfile` definition unit tests methods.
119 """
121 def test_log_decoding_AppleLogProfile(self) -> None:
122 """
123 Test :func:`colour.models.rgb.transfer_functions.apple_log_profile.\
124log_decoding_AppleLogProfile` definition.
125 """
127 np.testing.assert_allclose(
128 log_decoding_AppleLogProfile(0.150476452300913),
129 0.0,
130 atol=TOLERANCE_ABSOLUTE_TESTS,
131 )
133 np.testing.assert_allclose(
134 log_decoding_AppleLogProfile(0.488272458526868),
135 0.18,
136 atol=TOLERANCE_ABSOLUTE_TESTS,
137 )
139 np.testing.assert_allclose(
140 log_decoding_AppleLogProfile(0.694552983055191),
141 1.0,
142 atol=TOLERANCE_ABSOLUTE_TESTS,
143 )
145 def test_n_dimensional_log_decoding_DLog(self) -> None:
146 """
147 Test :func:`colour.models.rgb.transfer_functions.apple_log_profile.\
148log_decoding_AppleLogProfile` definition n-dimensional arrays support.
149 """
151 P = 0.398764556189331
152 R = log_decoding_AppleLogProfile(P)
154 P = np.tile(P, 6)
155 R = np.tile(R, 6)
156 np.testing.assert_allclose(
157 log_decoding_AppleLogProfile(P), R, atol=TOLERANCE_ABSOLUTE_TESTS
158 )
160 P = np.reshape(P, (2, 3))
161 R = np.reshape(R, (2, 3))
162 np.testing.assert_allclose(
163 log_decoding_AppleLogProfile(P), R, atol=TOLERANCE_ABSOLUTE_TESTS
164 )
166 P = np.reshape(P, (2, 3, 1))
167 R = np.reshape(R, (2, 3, 1))
168 np.testing.assert_allclose(
169 log_decoding_AppleLogProfile(P), R, atol=TOLERANCE_ABSOLUTE_TESTS
170 )
172 def test_domain_range_scale_log_decoding_DLog(self) -> None:
173 """
174 Test :func:`colour.models.rgb.transfer_functions.apple_log_profile.\
175log_decoding_AppleLogProfile` definition domain and range scale support.
176 """
178 P = 0.398764556189331
179 R = log_decoding_AppleLogProfile(P)
181 d_r = (("reference", 1), ("1", 1), ("100", 100))
182 for scale, factor in d_r:
183 with domain_range_scale(scale):
184 np.testing.assert_allclose(
185 log_decoding_AppleLogProfile(P * factor),
186 R * factor,
187 atol=TOLERANCE_ABSOLUTE_TESTS,
188 )
190 @ignore_numpy_errors
191 def test_nan_log_decoding_DLog(self) -> None:
192 """
193 Test :func:`colour.models.rgb.transfer_functions.apple_log_profile.\
194log_decoding_AppleLogProfile` definition nan support.
195 """
197 log_decoding_AppleLogProfile(
198 np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan])
199 )