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

1"""

2 Define the unit tests for the :mod:`colour.models.rgb.transfer_functions.\

3 apple_log_profile` 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_AppleLogProfile,

11 log_encoding_AppleLogProfile,

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_AppleLogProfile",

24 "TestLogDecoding_AppleLogProfile",

25]

26

27

28 class TestLogEncoding_AppleLogProfile:

29 """

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

31 log_encoding_AppleLogProfile` definition unit tests methods.

32 """

33

34 def test_log_encoding_AppleLogProfile(self) -> None:

35 """

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

37 log_encoding_AppleLogProfile` definition.

38 """

39

40 np.testing.assert_allclose(

41 log_encoding_AppleLogProfile(0.0),

42 0.150476452300913,

43 atol=TOLERANCE_ABSOLUTE_TESTS,

44 )

45

46 np.testing.assert_allclose(

47 log_encoding_AppleLogProfile(0.18),

48 0.488272458526868,

49 atol=TOLERANCE_ABSOLUTE_TESTS,

50 )

51

52 np.testing.assert_allclose(

53 log_encoding_AppleLogProfile(1.0),

54 0.694552983055191,

55 atol=TOLERANCE_ABSOLUTE_TESTS,

56 )

57

58 def test_n_dimensional_log_encoding_DLog(self) -> None:

59 """

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

61 log_encoding_AppleLogProfile` definition n-dimensional arrays support.

62 """

63

64 R = 0.18

65 P = log_encoding_AppleLogProfile(R)

66

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 )

72

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 )

78

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 )

84

85 def test_domain_range_scale_log_encoding_DLog(self) -> None:

86 """

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

88 log_encoding_AppleLogProfile` definition domain and range scale support.

89 """

90

91 R = 0.18

92 P = log_encoding_AppleLogProfile(R)

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_AppleLogProfile(R * factor),

99 P * factor,

100 atol=TOLERANCE_ABSOLUTE_TESTS,

101 )

102

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.\

107 log_encoding_AppleLogProfile` definition nan support.

108 """

109

110 log_encoding_AppleLogProfile(

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

112 )

113

114

115 class TestLogDecoding_AppleLogProfile:

116 """

117 Define :func:`colour.models.rgb.transfer_functions.apple_log_profile.\

118 log_decoding_AppleLogProfile` definition unit tests methods.

119 """

120

121 def test_log_decoding_AppleLogProfile(self) -> None:

122 """

123 Test :func:`colour.models.rgb.transfer_functions.apple_log_profile.\

124 log_decoding_AppleLogProfile` definition.

125 """

126

127 np.testing.assert_allclose(

128 log_decoding_AppleLogProfile(0.150476452300913),

129 0.0,

130 atol=TOLERANCE_ABSOLUTE_TESTS,

131 )

132

133 np.testing.assert_allclose(

134 log_decoding_AppleLogProfile(0.488272458526868),

135 0.18,

136 atol=TOLERANCE_ABSOLUTE_TESTS,

137 )

138

139 np.testing.assert_allclose(

140 log_decoding_AppleLogProfile(0.694552983055191),

141 1.0,

142 atol=TOLERANCE_ABSOLUTE_TESTS,

143 )

144

145 def test_n_dimensional_log_decoding_DLog(self) -> None:

146 """

147 Test :func:`colour.models.rgb.transfer_functions.apple_log_profile.\

148 log_decoding_AppleLogProfile` definition n-dimensional arrays support.

149 """

150

151 P = 0.398764556189331

152 R = log_decoding_AppleLogProfile(P)

153

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 )

159

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 )

165

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 )

171

172 def test_domain_range_scale_log_decoding_DLog(self) -> None:

173 """

174 Test :func:`colour.models.rgb.transfer_functions.apple_log_profile.\

175 log_decoding_AppleLogProfile` definition domain and range scale support.

176 """

177

178 P = 0.398764556189331

179 R = log_decoding_AppleLogProfile(P)

180

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 )

189

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.\

194 log_decoding_AppleLogProfile` definition nan support.

195 """

196

197 log_decoding_AppleLogProfile(

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

199 )