Coverage for colour/io/tests/test_ocio.py: 100%

29 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-11-16 23:01 +1300

1"""Define the unit tests for the :mod:`colour.io.ocio` module.""" 

2 

3from __future__ import annotations 

4 

5import os 

6 

7import numpy as np 

8 

9from colour.constants import TOLERANCE_ABSOLUTE_TESTS 

10from colour.io import process_image_OpenColorIO 

11from colour.utilities import full, is_opencolorio_installed 

12 

13__author__ = "Colour Developers" 

14__copyright__ = "Copyright 2013 Colour Developers" 

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

16__maintainer__ = "Colour Developers" 

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

18__status__ = "Production" 

19 

20__all__ = [ 

21 "ROOT_RESOURCES", 

22 "TestProcessImageOpenColorIO", 

23] 

24 

25ROOT_RESOURCES: str = os.path.join(os.path.dirname(__file__), "resources") 

26 

27 

28class TestProcessImageOpenColorIO: 

29 """ 

30 Define :func:`colour.io.ocio.process_image_OpenColorIO` definition unit 

31 tests methods. 

32 """ 

33 

34 def test_process_image_OpenColorIO(self) -> None: 

35 """Test :func:`colour.io.ocio.process_image_OpenColorIO` definition.""" 

36 

37 # TODO: Remove when "Pypi" wheel compatible with "ARM" on "macOS" is 

38 # released. 

39 if not is_opencolorio_installed(): # pragma: no cover 

40 return 

41 

42 import PyOpenColorIO as ocio # noqa: PLC0415 

43 

44 config = os.path.join(ROOT_RESOURCES, "config-aces-reference.ocio.yaml") 

45 

46 a = full([4, 2, 3], 0.18) 

47 

48 np.testing.assert_allclose( 

49 process_image_OpenColorIO( 

50 a, "ACES - ACES2065-1", "ACES - ACEScct", config=config 

51 ), 

52 np.array( 

53 [ 

54 [ 

55 [0.41358781, 0.41358781, 0.41358781], 

56 [0.41358781, 0.41358781, 0.41358781], 

57 ], 

58 [ 

59 [0.41358781, 0.41358781, 0.41358781], 

60 [0.41358781, 0.41358781, 0.41358781], 

61 ], 

62 [ 

63 [0.41358781, 0.41358781, 0.41358781], 

64 [0.41358781, 0.41358781, 0.41358781], 

65 ], 

66 [ 

67 [0.41358781, 0.41358781, 0.41358781], 

68 [0.41358781, 0.41358781, 0.41358781], 

69 ], 

70 ] 

71 ), 

72 atol=TOLERANCE_ABSOLUTE_TESTS, 

73 ) 

74 

75 np.testing.assert_allclose( 

76 process_image_OpenColorIO( 

77 a, 

78 "ACES - ACES2065-1", 

79 "Display - sRGB", 

80 "Output - SDR Video - ACES 1.0", 

81 ocio.TRANSFORM_DIR_FORWARD, # pyright: ignore 

82 config=config, 

83 ), 

84 np.array( 

85 [ 

86 [ 

87 [0.35595229, 0.35595256, 0.35595250], 

88 [0.35595229, 0.35595256, 0.35595250], 

89 ], 

90 [ 

91 [0.35595229, 0.35595256, 0.35595250], 

92 [0.35595229, 0.35595256, 0.35595250], 

93 ], 

94 [ 

95 [0.35595229, 0.35595256, 0.35595250], 

96 [0.35595229, 0.35595256, 0.35595250], 

97 ], 

98 [ 

99 [0.35595229, 0.35595256, 0.35595250], 

100 [0.35595229, 0.35595256, 0.35595250], 

101 ], 

102 ] 

103 ), 

104 atol=TOLERANCE_ABSOLUTE_TESTS, 

105 ) 

106 

107 # Test scalar input 

108 a_scalar = np.array(0.18) 

109 result_scalar = process_image_OpenColorIO( 

110 a_scalar, "ACES - ACES2065-1", "ACES - ACEScct", config=config 

111 ) 

112 assert isinstance(result_scalar, (float, np.floating)) 

113 np.testing.assert_allclose( 

114 result_scalar, 0.41358781, atol=TOLERANCE_ABSOLUTE_TESTS 

115 ) 

116 

117 # Test single-channel input 

118 a_single = np.array([0.18]) 

119 result_single = process_image_OpenColorIO( 

120 a_single, "ACES - ACES2065-1", "ACES - ACEScct", config=config 

121 ) 

122 assert result_single.shape == (1,) 

123 np.testing.assert_allclose( 

124 result_single, np.array([0.41358781]), atol=TOLERANCE_ABSOLUTE_TESTS 

125 )