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)) -
71 w - b) - 0.030001222851889303) / 5.) * 0.9
74 def s_log2_to_linear(s_log):
80 linear = ((219. * (pow(10.,
82 (w - b) - 0.616596 - 0.03) / 0.432699)) -
83 0.037584) / 155.) * 0.9)
85 linear = (((s_log - b) / (
86 w - b) - 0.030001222851889303) / 3.53881278538813) * 0.9
89 def s_log3_to_linear(code_value):
90 if code_value >= (171.2102946929):
91 linear = (pow(10.0, ((code_value - 420.0) / 261.5)) *
94 linear = (code_value - 95.0) * 0.01125000 / (171.2102946929 - 95.0)
95 # print(codeValue, linear)
98 cs.to_reference_transforms = []
100 if transfer_function == 'S-Log1':
101 data = array.array('f', '\0' * lut_resolution_1d * 4)
102 for c in range(lut_resolution_1d):
103 data[c] = s_log1_to_linear(1023.0 * c / (lut_resolution_1d - 1))
105 lut = '%s_to_linear.spi1d' % transfer_function
107 os.path.join(lut_directory, lut),
114 # print('Writing %s' % lut)
116 cs.to_reference_transforms.append({
119 'interpolation': 'linear',
120 'direction': 'forward'
122 elif transfer_function == 'S-Log2':
123 data = array.array('f', '\0' * lut_resolution_1d * 4)
124 for c in range(lut_resolution_1d):
125 data[c] = s_log2_to_linear(1023.0 * c / (lut_resolution_1d - 1))
127 lut = '%s_to_linear.spi1d' % transfer_function
129 os.path.join(lut_directory, lut),
136 # print('Writing %s' % lut)
138 cs.to_reference_transforms.append({
141 'interpolation': 'linear',
142 'direction': 'forward'
144 elif transfer_function == 'S-Log3':
145 data = array.array('f', '\0' * lut_resolution_1d * 4)
146 for c in range(lut_resolution_1d):
147 data[c] = s_log3_to_linear(1023.0 * c / (lut_resolution_1d - 1))
149 lut = '%s_to_linear.spi1d' % transfer_function
151 os.path.join(lut_directory, lut),
158 # print('Writing %s' % lut)
160 cs.to_reference_transforms.append({
163 'interpolation': 'linear',
164 'direction': 'forward'
167 if gamut == 'S-Gamut':
168 cs.to_reference_transforms.append({
170 'matrix': mat44_from_mat33(
171 [0.754338638, 0.133697046, 0.111968437,
172 0.021198141, 1.005410934, -0.026610548,
173 -0.009756991, 0.004508563, 1.005253201]),
174 'direction': 'forward'})
175 elif gamut == 'S-Gamut Daylight':
176 cs.to_reference_transforms.append({
178 'matrix': mat44_from_mat33(
179 [0.8764457030, 0.0145411681, 0.1090131290,
180 0.0774075345, 0.9529571767, -0.0303647111,
181 0.0573564351, -0.1151066335, 1.0577501984]),
182 'direction': 'forward'})
183 elif gamut == 'S-Gamut Tungsten':
184 cs.to_reference_transforms.append({
186 'matrix': mat44_from_mat33(
187 [1.0110238740, -0.1362526051, 0.1252287310,
188 0.1011994504, 0.9562196265, -0.0574190769,
189 0.0600766530, -0.1010185315, 1.0409418785]),
190 'direction': 'forward'})
191 elif gamut == 'S-Gamut3.Cine':
192 cs.to_reference_transforms.append({
194 'matrix': mat44_from_mat33(
195 [0.6387886672, 0.2723514337, 0.0888598992,
196 -0.0039159061, 1.0880732308, -0.0841573249,
197 -0.0299072021, -0.0264325799, 1.0563397820]),
198 'direction': 'forward'})
199 elif gamut == 'S-Gamut3':
200 cs.to_reference_transforms.append({
202 'matrix': mat44_from_mat33(
203 [0.7529825954, 0.1433702162, 0.1036471884,
204 0.0217076974, 1.0153188355, -0.0370265329,
205 -0.0094160528, 0.0033704179, 1.0060456349]),
206 'direction': 'forward'})
208 cs.from_reference_transforms = []
212 def create_colorspaces(lut_directory, lut_resolution_1d):
214 Generates the colorspace conversions.
219 Parameter description.
224 Return value description.
230 s_log1_s_gamut = create_s_log(
236 colorspaces.append(s_log1_s_gamut)
239 s_log2_s_gamut = create_s_log(
245 colorspaces.append(s_log2_s_gamut)
247 s_log2_s_gamut_daylight = create_s_log(
253 colorspaces.append(s_log2_s_gamut_daylight)
255 s_log2_s_gamut_tungsten = create_s_log(
261 colorspaces.append(s_log2_s_gamut_tungsten)
264 s_log3_s_gamut3Cine = create_s_log(
270 colorspaces.append(s_log3_s_gamut3Cine)
272 s_log3_s_gamut3 = create_s_log(
278 colorspaces.append(s_log3_s_gamut3)
281 s_log1 = create_s_log(
287 colorspaces.append(s_log1)
289 s_log2 = create_s_log(
295 colorspaces.append(s_log2)
297 s_log3 = create_s_log(
303 colorspaces.append(s_log3)
306 s_gamut = create_s_log(
312 colorspaces.append(s_gamut)
314 s_gamut_daylight = create_s_log(
320 colorspaces.append(s_gamut_daylight)
322 s_gamut_tungsten = create_s_log(
328 colorspaces.append(s_gamut_tungsten)
330 s_gamut3Cine = create_s_log(
336 colorspaces.append(s_gamut3Cine)
338 s_gamut3 = create_s_log(
344 colorspaces.append(s_gamut3)