Coverage for models/rgb/transfer_functions/viper_log.py: 32%

19 statements  

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

1""" 

2Viper Log Encoding 

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

4 

5Define the *Viper Log* encoding. 

6 

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

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

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 Domain1, 

24 Range1, 

25) 

26from colour.utilities import as_float, from_range_1, to_domain_1 

27 

28__author__ = "Colour Developers" 

29__copyright__ = "Copyright 2013 Colour Developers" 

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

31__maintainer__ = "Colour Developers" 

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

33__status__ = "Production" 

34 

35__all__ = [ 

36 "log_encoding_ViperLog", 

37 "log_decoding_ViperLog", 

38] 

39 

40 

41def log_encoding_ViperLog(x: Domain1) -> Range1: 

42 """ 

43 Apply the *Viper Log* log encoding opto-electronic transfer function (OETF). 

44 

45 Parameters 

46 ---------- 

47 x 

48 Linear data :math:`x`. 

49 

50 Returns 

51 ------- 

52 :class:`numpy.ndarray` 

53 Non-linear encoded data :math:`y`. 

54 

55 Notes 

56 ----- 

57 +------------+-----------------------+---------------+ 

58 | **Domain** | **Scale - Reference** | **Scale - 1** | 

59 +============+=======================+===============+ 

60 | ``x`` | 1 | 1 | 

61 +------------+-----------------------+---------------+ 

62 

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

64 | **Range** | **Scale - Reference** | **Scale - 1** | 

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

66 | ``y`` | 1 | 1 | 

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

68 

69 References 

70 ---------- 

71 :cite:`SonyImageworks2012a` 

72 

73 Examples 

74 -------- 

75 >>> log_encoding_ViperLog(0.18) # doctest: +ELLIPSIS 

76 0.6360080... 

77 """ 

78 

79 x = to_domain_1(x) 

80 

81 y = (1023 + 500 * np.log10(x)) / 1023 

82 

83 return as_float(from_range_1(y)) 

84 

85 

86def log_decoding_ViperLog(y: Domain1) -> Range1: 

87 """ 

88 Apply the *Viper Log* log decoding inverse opto-electronic transfer function (OETF). 

89 

90 Parameters 

91 ---------- 

92 y 

93 Non-linear encoded data :math:`y`. 

94 

95 Returns 

96 ------- 

97 :class:`numpy.ndarray` 

98 Linear data :math:`x`. 

99 

100 Notes 

101 ----- 

102 +------------+-----------------------+---------------+ 

103 | **Domain** | **Scale - Reference** | **Scale - 1** | 

104 +============+=======================+===============+ 

105 | ``y`` | 1 | 1 | 

106 +------------+-----------------------+---------------+ 

107 

108 +------------+-----------------------+---------------+ 

109 | **Range** | **Scale - Reference** | **Scale - 1** | 

110 +============+=======================+===============+ 

111 | ``x`` | 1 | 1 | 

112 +------------+-----------------------+---------------+ 

113 

114 References 

115 ---------- 

116 :cite:`SonyImageworks2012a` 

117 

118 Examples 

119 -------- 

120 >>> log_decoding_ViperLog(0.636008067010413) # doctest: +ELLIPSIS 

121 0.1799999... 

122 """ 

123 

124 y = to_domain_1(y) 

125 

126 x = 10 ** ((1023 * y - 1023) / 500) 

127 

128 return as_float(from_range_1(x))