Coverage for models/rgb/tests/test_common.py: 100%

1"""Define the unit tests for the :mod:`colour.models.rgb.common` module."""

2

3 from __future__ import annotations

4

5 import numpy as np

6

7 from colour.constants import TOLERANCE_ABSOLUTE_TESTS

8 from colour.models import XYZ_to_sRGB, sRGB_to_XYZ

9

10 __author__ = "Colour Developers"

11 __copyright__ = "Copyright 2013 Colour Developers"

12 __license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"

13 __maintainer__ = "Colour Developers"

14 __email__ = "colour-developers@colour-science.org"

15 __status__ = "Production"

16

17 __all__ = [

18 "TestXYZ_to_sRGB",

19 "TestsRGB_to_XYZ",

20]

21

22

23 class TestXYZ_to_sRGB:

24 """

25 Define :func:`colour.models.rgb.common.XYZ_to_sRGB` definition unit tests

26 methods.

27 """

28

29 def test_XYZ_to_sRGB(self) -> None:

30 """Test :func:`colour.models.rgb.common.XYZ_to_sRGB` definition."""

31

32 np.testing.assert_allclose(

33 XYZ_to_sRGB(np.array([0.20654008, 0.12197225, 0.05136952])),

34 np.array([0.70573936, 0.19248266, 0.22354169]),

35 atol=TOLERANCE_ABSOLUTE_TESTS,

36 )

37

38 np.testing.assert_allclose(

39 XYZ_to_sRGB(np.array([0.14222010, 0.23042768, 0.10495772])),

40 np.array([0.25847003, 0.58276102, 0.29718877]),

41 atol=TOLERANCE_ABSOLUTE_TESTS,

42 )

43

44 np.testing.assert_allclose(

45 XYZ_to_sRGB(

46 np.array([0.07818780, 0.06157201, 0.28099326]),

47 np.array([0.34570, 0.35850]),

48 ),

49 np.array([0.09838967, 0.25404426, 0.65130925]),

50 atol=TOLERANCE_ABSOLUTE_TESTS,

51 )

52

53 np.testing.assert_allclose(

54 XYZ_to_sRGB(

55 np.array([0.00000000, 0.00000000, 0.00000000]),

56 np.array([0.44757, 0.40745]),

57 ),

58 np.array([0.00000000, 0.00000000, 0.00000000]),

59 atol=TOLERANCE_ABSOLUTE_TESTS,

60 )

61

62 np.testing.assert_allclose(

63 XYZ_to_sRGB(

64 np.array([0.20654008, 0.12197225, 0.05136952]),

65 np.array([0.44757, 0.40745]),

66 chromatic_adaptation_transform="Bradford",

67 ),

68 np.array([0.60873814, 0.23259548, 0.43714892]),

69 atol=TOLERANCE_ABSOLUTE_TESTS,

70 )

71

72 np.testing.assert_allclose(

73 XYZ_to_sRGB(

74 np.array([0.20654008, 0.12197225, 0.05136952]),

75 apply_cctf_encoding=False,

76 ),

77 np.array([0.45620520, 0.03081070, 0.04091953]),

78 atol=TOLERANCE_ABSOLUTE_TESTS,

79 )

80

81

82 class TestsRGB_to_XYZ:

83 """

84 Define :func:`colour.models.rgb.common.sRGB_to_XYZ` definition unit tests

85 methods.

86 """

87

88 def test_sRGB_to_XYZ(self) -> None:

89 """Test :func:`colour.models.rgb.common.sRGB_to_XYZ` definition."""

90

91 np.testing.assert_allclose(

92 sRGB_to_XYZ(np.array([0.70573936, 0.19248266, 0.22354169])),

93 np.array([0.20654290, 0.12197943, 0.05137140]),

94 atol=TOLERANCE_ABSOLUTE_TESTS,

95 )

96

97 np.testing.assert_allclose(

98 sRGB_to_XYZ(np.array([0.25847003, 0.58276102, 0.29718877])),

99 np.array([0.14222582, 0.23043727, 0.10496290]),

100 atol=TOLERANCE_ABSOLUTE_TESTS,

101 )

102

103 np.testing.assert_allclose(

104 sRGB_to_XYZ(

105 np.array([0.09838967, 0.25404426, 0.65130925]),

106 np.array([0.34570, 0.35850]),

107 ),

108 np.array([0.07819162, 0.06157356, 0.28099475]),

109 atol=TOLERANCE_ABSOLUTE_TESTS,

110 )

111

112 np.testing.assert_allclose(

113 sRGB_to_XYZ(

114 np.array([0.00000000, 0.00000000, 0.00000000]),

115 np.array([0.44757, 0.40745]),

116 ),

117 np.array([0.00000000, 0.00000000, 0.00000000]),

118 atol=TOLERANCE_ABSOLUTE_TESTS,

119 )

120

121 np.testing.assert_allclose(

122 sRGB_to_XYZ(

123 np.array([0.60873814, 0.23259548, 0.43714892]),

124 np.array([0.44757, 0.40745]),

125 chromatic_adaptation_transform="Bradford",

126 ),

127 np.array([0.20654449, 0.12197792, 0.05137030]),

128 atol=TOLERANCE_ABSOLUTE_TESTS,

129 )

130

131 np.testing.assert_allclose(

132 sRGB_to_XYZ(

133 np.array([0.45620520, 0.03081070, 0.04091953]),

134 apply_cctf_decoding=False,

135 ),

136 np.array([0.20654291, 0.12197943, 0.05137141]),

137 atol=TOLERANCE_ABSOLUTE_TESTS,

138 )