Coverage for colour/models/rgb/transfer_functions/tests/test__init__.py: 100%
38 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.common` module.
4"""
6import numpy as np
7import pytest
9from colour.constants import TOLERANCE_ABSOLUTE_TESTS
10from colour.models.rgb.transfer_functions import (
11 CCTF_DECODINGS,
12 CCTF_ENCODINGS,
13 EOTF_INVERSES,
14 EOTFS,
15 LOG_DECODINGS,
16 LOG_ENCODINGS,
17 OETF_INVERSES,
18 OETFS,
19 OOTF_INVERSES,
20 OOTFS,
21 cctf_decoding,
22 cctf_encoding,
23)
24from colour.utilities import ColourUsageWarning
26__author__ = "Colour Developers"
27__copyright__ = "Copyright 2013 Colour Developers"
28__license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"
29__maintainer__ = "Colour Developers"
30__email__ = "colour-developers@colour-science.org"
31__status__ = "Development"
33__all__ = [
34 "TestCctfEncoding",
35 "TestCctfDecoding",
36 "TestTransferFunctions",
37]
40class TestCctfEncoding:
41 """
42 Define :func:`colour.models.rgb.transfer_functions.cctf_encoding`
43 definition unit tests methods.
44 """
46 def test_raise_exception_cctf_encoding(self) -> None:
47 """
48 Test :func:`colour.models.rgb.transfer_functions.aces.\
49log_encoding_ACESproxy` definition raised exception.
50 """
52 pytest.warns(
53 ColourUsageWarning,
54 cctf_encoding,
55 0.18,
56 function="ITU-R BT.2100 HLG",
57 )
58 pytest.warns(
59 ColourUsageWarning,
60 cctf_encoding,
61 0.18,
62 function="ITU-R BT.2100 PQ",
63 )
66class TestCctfDecoding:
67 """
68 Define :func:`colour.models.rgb.transfer_functions.cctf_decoding`
69 definition unit tests methods.
70 """
72 def test_raise_exception_cctf_decoding(self) -> None:
73 """
74 Test :func:`colour.models.rgb.transfer_functions.aces.\
75log_encoding_ACESproxy` definition raised exception.
76 """
78 pytest.warns(
79 ColourUsageWarning,
80 cctf_decoding,
81 0.18,
82 function="ITU-R BT.2100 HLG",
83 )
84 pytest.warns(
85 ColourUsageWarning,
86 cctf_decoding,
87 0.18,
88 function="ITU-R BT.2100 PQ",
89 )
92class TestTransferFunctions:
93 """Define the transfer functions unit tests methods."""
95 def test_transfer_functions(self) -> None:
96 """Test the transfer functions reciprocity."""
98 ignored_transfer_functions = (
99 "ACESproxy",
100 "DICOM GSDF",
101 "Filmic Pro 6",
102 )
104 tolerance = {"D-Log": 0.1, "F-Log": 5e-4, "L-Log": 5e-4, "N-Log": 5e-3}
106 reciprocal_mappings = [
107 (LOG_ENCODINGS, LOG_DECODINGS),
108 (OETFS, OETF_INVERSES),
109 (EOTFS, EOTF_INVERSES),
110 (CCTF_ENCODINGS, CCTF_DECODINGS),
111 (OOTFS, OOTF_INVERSES),
112 ]
114 samples = np.hstack(
115 [np.linspace(0, 1, int(1e5)), np.linspace(0, 65504, 65504 * 10)]
116 )
118 for encoding_mapping, _decoding_mapping in reciprocal_mappings:
119 for name in encoding_mapping:
120 if name in ignored_transfer_functions:
121 continue
123 samples_r = np.copy(samples)
125 if name == "ITU-T H.273 Log":
126 samples_r = np.clip(samples_r, 0.1, np.inf)
128 if name == "ITU-T H.273 Log Sqrt":
129 samples_r = np.clip(samples_r, np.sqrt(10) / 1000, np.inf)
131 samples_e = CCTF_ENCODINGS[name](samples_r)
132 samples_d = CCTF_DECODINGS[name](samples_e)
134 np.testing.assert_allclose(
135 samples_r,
136 samples_d,
137 atol=tolerance.get(name, TOLERANCE_ABSOLUTE_TESTS),
138 )