Coverage for models/rgb/transfer_functions/cineon.py: 38%

21 statements  

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

1""" 

2Kodak Cineon Encoding 

3===================== 

4 

5Define the *Kodak Cineon* encoding. 

6 

7- :func:`colour.models.log_encoding_Cineon` 

8- :func:`colour.models.log_decoding_Cineon` 

9 

10References 

11---------- 

12- :cite:`SonyImageworks2012a` : Sony Imageworks. (2012). make.py. Retrieved 

13 November 27, 2014, from 

14 https://github.com/imageworks/OpenColorIO-Configs/blob/master/\ 

15nuke-default/make.py 

16""" 

17 

18from __future__ import annotations 

19 

20import numpy as np 

21 

22from colour.hints import ( # noqa: TC001 

23 ArrayLike, 

24 Domain1, 

25 Range1, 

26) 

27from colour.utilities import as_float, as_float_array, from_range_1, to_domain_1 

28 

29__author__ = "Colour Developers" 

30__copyright__ = "Copyright 2013 Colour Developers" 

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

32__maintainer__ = "Colour Developers" 

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

34__status__ = "Production" 

35 

36__all__ = [ 

37 "log_encoding_Cineon", 

38 "log_decoding_Cineon", 

39] 

40 

41 

42def log_encoding_Cineon( 

43 x: Domain1, 

44 black_offset: ArrayLike = 10 ** ((95 - 685) / 300), 

45) -> Range1: 

46 """ 

47 Apply the *Cineon* log encoding opto-electronic transfer function (OETF). 

48 

49 Parameters 

50 ---------- 

51 x 

52 Linear data :math:`x`. 

53 black_offset 

54 Black offset. 

55 

56 Returns 

57 ------- 

58 :class:`numpy.ndarray` 

59 *Cineon* non-linear encoded data :math:`y`. 

60 

61 Notes 

62 ----- 

63 +------------+-----------------------+---------------+ 

64 | **Domain** | **Scale - Reference** | **Scale - 1** | 

65 +============+=======================+===============+ 

66 | ``x`` | 1 | 1 | 

67 +------------+-----------------------+---------------+ 

68 

69 +------------+-----------------------+---------------+ 

70 | **Range** | **Scale - Reference** | **Scale - 1** | 

71 +============+=======================+===============+ 

72 | ``y`` | 1 | 1 | 

73 +------------+-----------------------+---------------+ 

74 

75 References 

76 ---------- 

77 :cite:`SonyImageworks2012a` 

78 

79 Examples 

80 -------- 

81 >>> log_encoding_Cineon(0.18) # doctest: +ELLIPSIS 

82 0.4573196... 

83 """ 

84 

85 x = to_domain_1(x) 

86 black_offset = as_float_array(black_offset) 

87 

88 y = (685 + 300 * np.log10(x * (1 - black_offset) + black_offset)) / 1023 

89 

90 return as_float(from_range_1(y)) 

91 

92 

93def log_decoding_Cineon( 

94 y: Domain1, 

95 black_offset: ArrayLike = 10 ** ((95 - 685) / 300), 

96) -> Range1: 

97 """ 

98 Apply the *Cineon* log decoding inverse opto-electronic transfer function (OETF). 

99 

100 Parameters 

101 ---------- 

102 y 

103 *Cineon* non-linear encoded data :math:`y`. 

104 black_offset 

105 Black offset. 

106 

107 Returns 

108 ------- 

109 :class:`numpy.ndarray` 

110 Linear data :math:`x`. 

111 

112 Notes 

113 ----- 

114 +------------+-----------------------+---------------+ 

115 | **Domain** | **Scale - Reference** | **Scale - 1** | 

116 +============+=======================+===============+ 

117 | ``y`` | 1 | 1 | 

118 +------------+-----------------------+---------------+ 

119 

120 +------------+-----------------------+---------------+ 

121 | **Range** | **Scale - Reference** | **Scale - 1** | 

122 +============+=======================+===============+ 

123 | ``x`` | 1 | 1 | 

124 +------------+-----------------------+---------------+ 

125 

126 References 

127 ---------- 

128 :cite:`SonyImageworks2012a` 

129 

130 Examples 

131 -------- 

132 >>> log_decoding_Cineon(0.457319613085418) # doctest: +ELLIPSIS 

133 0.1799999... 

134 """ 

135 

136 y = to_domain_1(y) 

137 black_offset = as_float_array(black_offset) 

138 

139 x = (10 ** ((1023 * y - 685) / 300) - black_offset) / (1 - black_offset) 

140 

141 return as_float(from_range_1(x))