Coverage for colour/models/rgb/transfer_functions/davinci_intermediate.py: 100%

33 statements  

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

1""" 

2DaVinci Intermediate 

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

4 

5Define the *DaVinci Intermediate* opto-electrical transfer function 

6(OETF) and its inverse. 

7 

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

9- :func:`colour.models.oetf_inverse_DaVinciIntermediate` 

10 

11References 

12---------- 

13- :cite:`BlackmagicDesign2020a` : Blackmagic Design. (2020). Wide Gamut 

14 Intermediate DaVinci Resolve. Retrieved December 12, 2020, from 

15 https://documents.blackmagicdesign.com/InformationNotes/\ 

16DaVinci_Resolve_17_Wide_Gamut_Intermediate.pdf?_v=1607414410000 

17""" 

18 

19from __future__ import annotations 

20 

21import numpy as np 

22 

23from colour.hints import ( # noqa: TC001 

24 Domain1, 

25 Range1, 

26) 

27from colour.utilities import Structure, as_float, from_range_1, optional, 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 "CONSTANTS_DAVINCI_INTERMEDIATE", 

38 "oetf_DaVinciIntermediate", 

39 "oetf_inverse_DaVinciIntermediate", 

40] 

41 

42CONSTANTS_DAVINCI_INTERMEDIATE: Structure = Structure( 

43 DI_A=0.0075, 

44 DI_B=7.0, 

45 DI_C=0.07329248, 

46 DI_M=10.44426855, 

47 DI_LIN_CUT=0.00262409, 

48 DI_LOG_CUT=0.02740668, 

49) 

50"""*DaVinci Intermediate* colour component transfer functions constants.""" 

51 

52 

53def oetf_DaVinciIntermediate( 

54 L: Domain1, 

55 constants: Structure | None = None, 

56) -> Range1: 

57 """ 

58 Apply the *DaVinci Intermediate* opto-electronic transfer function (OETF). 

59 

60 Parameters 

61 ---------- 

62 L 

63 Linear light value :math:`L`. 

64 constants 

65 *DaVinci Intermediate* colour component transfer function constants. 

66 

67 Returns 

68 ------- 

69 :class:`numpy.ndarray` 

70 Encoded value :math:`V`. 

71 

72 Notes 

73 ----- 

74 +------------+-----------------------+---------------+ 

75 | **Domain** | **Scale - Reference** | **Scale - 1** | 

76 +============+=======================+===============+ 

77 | ``L`` | 1 | 1 | 

78 +------------+-----------------------+---------------+ 

79 

80 +------------+-----------------------+---------------+ 

81 | **Range** | **Scale - Reference** | **Scale - 1** | 

82 +============+=======================+===============+ 

83 | ``V`` | 1 | 1 | 

84 +------------+-----------------------+---------------+ 

85 

86 References 

87 ---------- 

88 :cite:`BlackmagicDesign2020a` 

89 

90 Examples 

91 -------- 

92 >>> oetf_DaVinciIntermediate(0.18) # doctest: +ELLIPSIS 

93 0.3360432... 

94 """ 

95 

96 L = to_domain_1(L) 

97 constants = optional(constants, CONSTANTS_DAVINCI_INTERMEDIATE) 

98 

99 DI_LIN_CUT = constants.DI_LIN_CUT 

100 DI_A = constants.DI_A 

101 DI_B = constants.DI_B 

102 DI_C = constants.DI_C 

103 DI_M = constants.DI_M 

104 

105 V_out = np.where( 

106 L <= DI_LIN_CUT, 

107 L * DI_M, 

108 DI_C * (np.log2(L + DI_A) + DI_B), 

109 ) 

110 

111 return as_float(from_range_1(V_out)) 

112 

113 

114def oetf_inverse_DaVinciIntermediate( 

115 V: Domain1, 

116 constants: Structure | None = None, 

117) -> Range1: 

118 """ 

119 Apply the *DaVinci Intermediate* inverse opto-electronic transfer 

120 function (OETF). 

121 

122 Parameters 

123 ---------- 

124 V 

125 Encoded value :math:`V`. 

126 constants 

127 *DaVinci Intermediate* colour component transfer function constants. 

128 

129 Returns 

130 ------- 

131 :class:`numpy.ndarray` 

132 Linear light value :math:`L`. 

133 

134 Notes 

135 ----- 

136 +------------+-----------------------+---------------+ 

137 | **Domain** | **Scale - Reference** | **Scale - 1** | 

138 +============+=======================+===============+ 

139 | ``V`` | 1 | 1 | 

140 +------------+-----------------------+---------------+ 

141 

142 +------------+-----------------------+---------------+ 

143 | **Range** | **Scale - Reference** | **Scale - 1** | 

144 +============+=======================+===============+ 

145 | ``L`` | 1 | 1 | 

146 +------------+-----------------------+---------------+ 

147 

148 References 

149 ---------- 

150 :cite:`BlackmagicDesign2020a` 

151 

152 Examples 

153 -------- 

154 >>> oetf_inverse_DaVinciIntermediate(0.336043272384855) 

155 ... # doctest: +ELLIPSIS 

156 0.1799999... 

157 """ 

158 

159 V = to_domain_1(V) 

160 constants = optional(constants, CONSTANTS_DAVINCI_INTERMEDIATE) 

161 

162 DI_LOG_CUT = constants.DI_LOG_CUT 

163 DI_A = constants.DI_A 

164 DI_B = constants.DI_B 

165 DI_C = constants.DI_C 

166 DI_M = constants.DI_M 

167 

168 L_out = np.where( 

169 V <= DI_LOG_CUT, 

170 V / DI_M, 

171 2 ** ((V / DI_C) - DI_B) - DI_A, 

172 ) 

173 return as_float(from_range_1(L_out))