Coverage for models/rgb/transfer_functions/tests/test__init__.py: 100%

1"""

2 Define the unit tests for the

3:mod:`colour.models.rgb.transfer_functions.common` module.

4"""

5

6 import numpy as np

7 import pytest

8

9 from colour.constants import TOLERANCE_ABSOLUTE_TESTS

10 from 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)

24 from colour.utilities import ColourUsageWarning

25

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"

32

33 __all__ = [

34 "TestCctfEncoding",

35 "TestCctfDecoding",

36 "TestTransferFunctions",

37]

38

39

40 class TestCctfEncoding:

41 """

42 Define :func:`colour.models.rgb.transfer_functions.cctf_encoding`

43 definition unit tests methods.

44 """

45

46 def test_raise_exception_cctf_encoding(self) -> None:

47 """

48 Test :func:`colour.models.rgb.transfer_functions.aces.\

49 log_encoding_ACESproxy` definition raised exception.

50 """

51

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 )

64

65

66 class TestCctfDecoding:

67 """

68 Define :func:`colour.models.rgb.transfer_functions.cctf_decoding`

69 definition unit tests methods.

70 """

71

72 def test_raise_exception_cctf_decoding(self) -> None:

73 """

74 Test :func:`colour.models.rgb.transfer_functions.aces.\

75 log_encoding_ACESproxy` definition raised exception.

76 """

77

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 )

90

91

92 class TestTransferFunctions:

93 """Define the transfer functions unit tests methods."""

94

95 def test_transfer_functions(self) -> None:

96 """Test the transfer functions reciprocity."""

97

98 ignored_transfer_functions = (

99 "ACESproxy",

100 "DICOM GSDF",

101 "Filmic Pro 6",

102 )

103

104 tolerance = {"D-Log": 0.1, "F-Log": 5e-4, "L-Log": 5e-4, "N-Log": 5e-3}

105

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 ]

113

114 samples = np.hstack(

115 [np.linspace(0, 1, int(1e5)), np.linspace(0, 65504, 65504 * 10)]

116 )

117

118 for encoding_mapping, _decoding_mapping in reciprocal_mappings:

119 for name in encoding_mapping:

120 if name in ignored_transfer_functions:

121 continue

122

123 samples_r = np.copy(samples)

124

125 if name == "ITU-T H.273 Log":

126 samples_r = np.clip(samples_r, 0.1, np.inf)

127

128 if name == "ITU-T H.273 Log Sqrt":

129 samples_r = np.clip(samples_r, np.sqrt(10) / 1000, np.inf)

130

131 samples_e = CCTF_ENCODINGS[name](samples_r)

132 samples_d = CCTF_DECODINGS[name](samples_e)

133

134 np.testing.assert_allclose(

135 samples_r,

136 samples_d,

137 atol=tolerance.get(name, TOLERANCE_ABSOLUTE_TESTS),

138 )