2 # -*- coding: utf-8 -*-
5 Implements support for *Sony* colorspaces conversions and transfer functions.
11 import aces_ocio.generate_lut as genlut
12 from aces_ocio.utilities import ColorSpace, mat44_from_mat33
14 __author__ = 'ACES Developers'
15 __copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers'
17 __maintainer__ = 'ACES Developers'
18 __email__ = 'aces@oscars.org'
19 __status__ = 'Production'
21 __all__ = ['create_s_log',
25 def create_s_log(gamut,
38 Parameter description.
43 Return value description.
46 name = '%s - %s' % (transfer_function, gamut)
47 if transfer_function == '':
48 name = 'Linear - %s' % gamut
50 name = '%s' % transfer_function
54 cs.equality_group = ''
58 def s_log1_to_linear(s_log):
66 (w - b) - 0.616596 - 0.03) / 0.432699)) -
69 linear = (((s_log - b) / (
70 w - b) - 0.030001222851889303) / 5.) * 0.9
73 def s_log2_to_linear(s_log):
79 linear = ((219. * (pow(10.,
81 (w - b) - 0.616596 - 0.03) / 0.432699)) -
82 0.037584) / 155.) * 0.9)
84 linear = (((s_log - b) / (
85 w - b) - 0.030001222851889303) / 3.53881278538813) * 0.9
88 def s_log3_to_linear(code_value):
89 if code_value >= 171.2102946929:
90 linear = (pow(10.0, ((code_value - 420.0) / 261.5)) *
93 linear = (code_value - 95.0) * 0.01125000 / (171.2102946929 - 95.0)
97 cs.to_reference_transforms = []
99 if transfer_function == 'S-Log1':
100 data = array.array('f', '\0' * lut_resolution_1d * 4)
101 for c in range(lut_resolution_1d):
102 data[c] = s_log1_to_linear(1023.0 * c / (lut_resolution_1d - 1))
104 lut = '%s_to_linear.spi1d' % transfer_function
106 os.path.join(lut_directory, lut),
113 cs.to_reference_transforms.append({
116 'interpolation': 'linear',
117 'direction': 'forward'})
118 elif transfer_function == 'S-Log2':
119 data = array.array('f', '\0' * lut_resolution_1d * 4)
120 for c in range(lut_resolution_1d):
121 data[c] = s_log2_to_linear(1023.0 * c / (lut_resolution_1d - 1))
123 lut = '%s_to_linear.spi1d' % transfer_function
125 os.path.join(lut_directory, lut),
132 cs.to_reference_transforms.append({
135 'interpolation': 'linear',
136 'direction': 'forward'})
137 elif transfer_function == 'S-Log3':
138 data = array.array('f', '\0' * lut_resolution_1d * 4)
139 for c in range(lut_resolution_1d):
140 data[c] = s_log3_to_linear(1023.0 * c / (lut_resolution_1d - 1))
142 lut = '%s_to_linear.spi1d' % transfer_function
144 os.path.join(lut_directory, lut),
151 cs.to_reference_transforms.append({
154 'interpolation': 'linear',
155 'direction': 'forward'})
157 if gamut == 'S-Gamut':
158 cs.to_reference_transforms.append({
160 'matrix': mat44_from_mat33(
161 [0.754338638, 0.133697046, 0.111968437,
162 0.021198141, 1.005410934, -0.026610548,
163 -0.009756991, 0.004508563, 1.005253201]),
164 'direction': 'forward'})
165 elif gamut == 'S-Gamut Daylight':
166 cs.to_reference_transforms.append({
168 'matrix': mat44_from_mat33(
169 [0.8764457030, 0.0145411681, 0.1090131290,
170 0.0774075345, 0.9529571767, -0.0303647111,
171 0.0573564351, -0.1151066335, 1.0577501984]),
172 'direction': 'forward'})
173 elif gamut == 'S-Gamut Tungsten':
174 cs.to_reference_transforms.append({
176 'matrix': mat44_from_mat33(
177 [1.0110238740, -0.1362526051, 0.1252287310,
178 0.1011994504, 0.9562196265, -0.0574190769,
179 0.0600766530, -0.1010185315, 1.0409418785]),
180 'direction': 'forward'})
181 elif gamut == 'S-Gamut3.Cine':
182 cs.to_reference_transforms.append({
184 'matrix': mat44_from_mat33(
185 [0.6387886672, 0.2723514337, 0.0888598992,
186 -0.0039159061, 1.0880732308, -0.0841573249,
187 -0.0299072021, -0.0264325799, 1.0563397820]),
188 'direction': 'forward'})
189 elif gamut == 'S-Gamut3':
190 cs.to_reference_transforms.append({
192 'matrix': mat44_from_mat33(
193 [0.7529825954, 0.1433702162, 0.1036471884,
194 0.0217076974, 1.0153188355, -0.0370265329,
195 -0.0094160528, 0.0033704179, 1.0060456349]),
196 'direction': 'forward'})
198 cs.from_reference_transforms = []
202 def create_colorspaces(lut_directory, lut_resolution_1d):
204 Generates the colorspace conversions.
209 Parameter description.
214 Return value description.
220 s_log1_s_gamut = create_s_log(
226 colorspaces.append(s_log1_s_gamut)
229 s_log2_s_gamut = create_s_log(
235 colorspaces.append(s_log2_s_gamut)
237 s_log2_s_gamut_daylight = create_s_log(
243 colorspaces.append(s_log2_s_gamut_daylight)
245 s_log2_s_gamut_tungsten = create_s_log(
251 colorspaces.append(s_log2_s_gamut_tungsten)
254 s_log3_s_gamut3Cine = create_s_log(
260 colorspaces.append(s_log3_s_gamut3Cine)
262 s_log3_s_gamut3 = create_s_log(
268 colorspaces.append(s_log3_s_gamut3)
271 s_log1 = create_s_log(
277 colorspaces.append(s_log1)
279 s_log2 = create_s_log(
285 colorspaces.append(s_log2)
287 s_log3 = create_s_log(
293 colorspaces.append(s_log3)
296 s_gamut = create_s_log(
302 colorspaces.append(s_gamut)
304 s_gamut_daylight = create_s_log(
310 colorspaces.append(s_gamut_daylight)
312 s_gamut_tungsten = create_s_log(
318 colorspaces.append(s_gamut_tungsten)
320 s_gamut3Cine = create_s_log(
326 colorspaces.append(s_gamut3Cine)
328 s_gamut3 = create_s_log(
334 colorspaces.append(s_gamut3)