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

1"""

2 Define the unit tests for the

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

4"""

5

6 import numpy as np

7

8 from colour.constants import TOLERANCE_ABSOLUTE_TESTS

9 from colour.models.rgb.transfer_functions import (

10 log_decoding_FilmicPro6,

11 log_encoding_FilmicPro6,

12)

13 from colour.utilities import domain_range_scale, ignore_numpy_errors

14

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"

21

22 __all__ = [

23 "TestLogEncoding_FilmicPro6",

24 "TestLogDecoding_FilmicPro6",

25]

26

27

28 class TestLogEncoding_FilmicPro6:

29 """

30 Define :func:`colour.models.rgb.transfer_functions.filmic_pro.\

31 log_encoding_FilmicPro6` definition unit tests methods.

32 """

33

34 def test_log_encoding_FilmicPro6(self) -> None:

35 """

36 Test :func:`colour.models.rgb.transfer_functions.filmic_pro.\

37 log_encoding_FilmicPro6` definition.

38 """

39

40 np.testing.assert_allclose(

41 log_encoding_FilmicPro6(0.0),

42 -np.inf,

43 atol=TOLERANCE_ABSOLUTE_TESTS,

44 )

45

46 np.testing.assert_allclose(

47 log_encoding_FilmicPro6(0.18),

48 0.606634519924703,

49 atol=TOLERANCE_ABSOLUTE_TESTS,

50 )

51

52 np.testing.assert_allclose(

53 log_encoding_FilmicPro6(1.0),

54 1.000000819999999,

55 atol=TOLERANCE_ABSOLUTE_TESTS,

56 )

57

58 def test_n_dimensional_log_encoding_FilmicPro6(self) -> None:

59 """

60 Test :func:`colour.models.rgb.transfer_functions.filmic_pro.\

61 log_encoding_FilmicPro6` definition n-dimensional arrays support.

62 """

63

64 x = 0.18

65 y = log_encoding_FilmicPro6(x)

66

67 x = np.tile(x, 6)

68 y = np.tile(y, 6)

69 np.testing.assert_allclose(

70 log_encoding_FilmicPro6(x), y, atol=TOLERANCE_ABSOLUTE_TESTS

71 )

72

73 x = np.reshape(x, (2, 3))

74 y = np.reshape(y, (2, 3))

75 np.testing.assert_allclose(

76 log_encoding_FilmicPro6(x), y, atol=TOLERANCE_ABSOLUTE_TESTS

77 )

78

79 x = np.reshape(x, (2, 3, 1))

80 y = np.reshape(y, (2, 3, 1))

81 np.testing.assert_allclose(

82 log_encoding_FilmicPro6(x), y, atol=TOLERANCE_ABSOLUTE_TESTS

83 )

84

85 def test_domain_range_scale_log_encoding_FilmicPro6(self) -> None:

86 """

87 Test :func:`colour.models.rgb.transfer_functions.filmic_pro.\

88 log_encoding_FilmicPro6` definition domain and range scale support.

89 """

90

91 x = 0.18

92 y = log_encoding_FilmicPro6(x)

93

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_FilmicPro6(x * factor),

99 y * factor,

100 atol=TOLERANCE_ABSOLUTE_TESTS,

101 )

102

103 @ignore_numpy_errors

104 def test_nan_log_encoding_FilmicPro6(self) -> None:

105 """

106 Test :func:`colour.models.rgb.transfer_functions.filmic_pro.\

107 log_encoding_FilmicPro6` definition nan support.

108 """

109

110 log_encoding_FilmicPro6(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))

111

112

113 class TestLogDecoding_FilmicPro6:

114 """

115 Define :func:`colour.models.rgb.transfer_functions.filmic_pro.\

116 log_decoding_FilmicPro6` definition unit tests methods.

117 """

118

119 def test_log_decoding_FilmicPro6(self) -> None:

120 """

121 Test :func:`colour.models.rgb.transfer_functions.filmic_pro.\

122 log_decoding_FilmicPro6` definition.

123 """

124

125 np.testing.assert_array_equal(log_decoding_FilmicPro6(-np.inf), 0.0)

126

127 np.testing.assert_allclose(

128 log_decoding_FilmicPro6(0.606634519924703),

129 0.18,

130 atol=TOLERANCE_ABSOLUTE_TESTS,

131 )

132

133 np.testing.assert_allclose(

134 log_decoding_FilmicPro6(1.000000819999999),

135 1.0,

136 atol=TOLERANCE_ABSOLUTE_TESTS,

137 )

138

139 def test_n_dimensional_log_decoding_FilmicPro6(self) -> None:

140 """

141 Test :func:`colour.models.rgb.transfer_functions.filmic_pro.\

142 log_decoding_FilmicPro6` definition n-dimensional arrays support.

143 """

144

145 y = 0.606634519924703

146 x = log_decoding_FilmicPro6(y)

147

148 y = np.tile(y, 6)

149 x = np.tile(x, 6)

150 np.testing.assert_allclose(

151 log_decoding_FilmicPro6(y), x, atol=TOLERANCE_ABSOLUTE_TESTS

152 )

153

154 y = np.reshape(y, (2, 3))

155 x = np.reshape(x, (2, 3))

156 np.testing.assert_allclose(

157 log_decoding_FilmicPro6(y), x, atol=TOLERANCE_ABSOLUTE_TESTS

158 )

159

160 y = np.reshape(y, (2, 3, 1))

161 x = np.reshape(x, (2, 3, 1))

162 np.testing.assert_allclose(

163 log_decoding_FilmicPro6(y), x, atol=TOLERANCE_ABSOLUTE_TESTS

164 )

165

166 def test_domain_range_scale_log_decoding_FilmicPro6(self) -> None:

167 """

168 Test :func:`colour.models.rgb.transfer_functions.filmic_pro.\

169 log_decoding_FilmicPro6` definition domain and range scale support.

170 """

171

172 y = 0.606634519924703

173 x = log_decoding_FilmicPro6(y)

174

175 d_r = (("reference", 1), ("1", 1), ("100", 100))

176 for scale, factor in d_r:

177 with domain_range_scale(scale):

178 np.testing.assert_allclose(

179 log_decoding_FilmicPro6(y * factor),

180 x * factor,

181 atol=TOLERANCE_ABSOLUTE_TESTS,

182 )

183

184 @ignore_numpy_errors

185 def test_nan_log_decoding_FilmicPro6(self) -> None:

186 """

187 Test :func:`colour.models.rgb.transfer_functions.filmic_pro.\

188 log_decoding_FilmicPro6` definition nan support.

189 """

190

191 log_decoding_FilmicPro6(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))