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,
39 Parameter description.
44 Return value description.
47 name = '%s - %s' % (transfer_function, gamut)
48 if transfer_function == '':
49 name = 'Linear - %s' % gamut
51 name = '%s' % transfer_function
56 cs.equality_group = ''
60 def s_log1_to_linear(s_log):
68 (w - b) - 0.616596 - 0.03) / 0.432699)) -
71 linear = (((s_log - b) / (
72 w - b) - 0.030001222851889303) / 5.) * 0.9
75 def s_log2_to_linear(s_log):
81 linear = ((219. * (pow(10.,
83 (w - b) - 0.616596 - 0.03) / 0.432699)) -
84 0.037584) / 155.) * 0.9)
86 linear = (((s_log - b) / (
87 w - b) - 0.030001222851889303) / 3.53881278538813) * 0.9
90 def s_log3_to_linear(code_value):
91 if code_value >= 171.2102946929:
92 linear = (pow(10.0, ((code_value - 420.0) / 261.5)) *
95 linear = (code_value - 95.0) * 0.01125000 / (171.2102946929 - 95.0)
99 cs.to_reference_transforms = []
101 if transfer_function == 'S-Log1':
102 data = array.array('f', '\0' * lut_resolution_1d * 4)
103 for c in range(lut_resolution_1d):
104 data[c] = s_log1_to_linear(1023.0 * c / (lut_resolution_1d - 1))
106 lut = '%s_to_linear.spi1d' % transfer_function
108 os.path.join(lut_directory, lut),
115 cs.to_reference_transforms.append({
118 'interpolation': 'linear',
119 'direction': 'forward'})
120 elif transfer_function == 'S-Log2':
121 data = array.array('f', '\0' * lut_resolution_1d * 4)
122 for c in range(lut_resolution_1d):
123 data[c] = s_log2_to_linear(1023.0 * c / (lut_resolution_1d - 1))
125 lut = '%s_to_linear.spi1d' % transfer_function
127 os.path.join(lut_directory, lut),
134 cs.to_reference_transforms.append({
137 'interpolation': 'linear',
138 'direction': 'forward'})
139 elif transfer_function == 'S-Log3':
140 data = array.array('f', '\0' * lut_resolution_1d * 4)
141 for c in range(lut_resolution_1d):
142 data[c] = s_log3_to_linear(1023.0 * c / (lut_resolution_1d - 1))
144 lut = '%s_to_linear.spi1d' % transfer_function
146 os.path.join(lut_directory, lut),
153 cs.to_reference_transforms.append({
156 'interpolation': 'linear',
157 'direction': 'forward'})
159 if gamut == 'S-Gamut':
160 cs.to_reference_transforms.append({
162 'matrix': mat44_from_mat33(
163 [0.754338638, 0.133697046, 0.111968437,
164 0.021198141, 1.005410934, -0.026610548,
165 -0.009756991, 0.004508563, 1.005253201]),
166 'direction': 'forward'})
167 elif gamut == 'S-Gamut Daylight':
168 cs.to_reference_transforms.append({
170 'matrix': mat44_from_mat33(
171 [0.8764457030, 0.0145411681, 0.1090131290,
172 0.0774075345, 0.9529571767, -0.0303647111,
173 0.0573564351, -0.1151066335, 1.0577501984]),
174 'direction': 'forward'})
175 elif gamut == 'S-Gamut Tungsten':
176 cs.to_reference_transforms.append({
178 'matrix': mat44_from_mat33(
179 [1.0110238740, -0.1362526051, 0.1252287310,
180 0.1011994504, 0.9562196265, -0.0574190769,
181 0.0600766530, -0.1010185315, 1.0409418785]),
182 'direction': 'forward'})
183 elif gamut == 'S-Gamut3.Cine':
184 cs.to_reference_transforms.append({
186 'matrix': mat44_from_mat33(
187 [0.6387886672, 0.2723514337, 0.0888598992,
188 -0.0039159061, 1.0880732308, -0.0841573249,
189 -0.0299072021, -0.0264325799, 1.0563397820]),
190 'direction': 'forward'})
191 elif gamut == 'S-Gamut3':
192 cs.to_reference_transforms.append({
194 'matrix': mat44_from_mat33(
195 [0.7529825954, 0.1433702162, 0.1036471884,
196 0.0217076974, 1.0153188355, -0.0370265329,
197 -0.0094160528, 0.0033704179, 1.0060456349]),
198 'direction': 'forward'})
200 cs.from_reference_transforms = []
204 def create_colorspaces(lut_directory, lut_resolution_1d):
206 Generates the colorspace conversions.
211 Parameter description.
216 Return value description.
222 s_log1_s_gamut = create_s_log(
229 colorspaces.append(s_log1_s_gamut)
232 s_log2_s_gamut = create_s_log(
239 colorspaces.append(s_log2_s_gamut)
241 s_log2_s_gamut_daylight = create_s_log(
248 colorspaces.append(s_log2_s_gamut_daylight)
250 s_log2_s_gamut_tungsten = create_s_log(
256 ["slog2_sgamuttung"])
257 colorspaces.append(s_log2_s_gamut_tungsten)
260 s_log3_s_gamut3Cine = create_s_log(
266 ["slog3_sgamutcine"])
267 colorspaces.append(s_log3_s_gamut3Cine)
269 s_log3_s_gamut3 = create_s_log(
276 colorspaces.append(s_log3_s_gamut3)
279 s_log1 = create_s_log(
286 colorspaces.append(s_log1)
288 s_log2 = create_s_log(
295 colorspaces.append(s_log2)
297 s_log3 = create_s_log(
304 colorspaces.append(s_log3)
307 s_gamut = create_s_log(
314 colorspaces.append(s_gamut)
316 s_gamut_daylight = create_s_log(
323 colorspaces.append(s_gamut_daylight)
325 s_gamut_tungsten = create_s_log(
332 colorspaces.append(s_gamut_tungsten)
334 s_gamut3Cine = create_s_log(
341 colorspaces.append(s_gamut3Cine)
343 s_gamut3 = create_s_log(
350 colorspaces.append(s_gamut3)