2 # -*- coding: utf-8 -*-
5 Implements support for *Sony* colorspaces conversions and transfer functions.
8 from __future__ import division
13 import aces_ocio.generate_lut as genlut
14 from aces_ocio.utilities import ColorSpace, mat44_from_mat33
16 __author__ = 'ACES Developers'
17 __copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers'
19 __maintainer__ = 'ACES Developers'
20 __email__ = 'aces@oscars.org'
21 __status__ = 'Production'
23 __all__ = ['create_s_log',
27 def create_s_log(gamut,
41 Parameter description.
46 Return value description.
49 name = '%s - %s' % (transfer_function, gamut)
50 if transfer_function == '':
51 name = 'Linear - %s' % gamut
53 name = '%s' % transfer_function
58 cs.equality_group = ''
62 def s_log1_to_linear(s_log):
70 (w - b) - 0.616596 - 0.03) / 0.432699)) -
73 linear = (((s_log - b) / (
74 w - b) - 0.030001222851889303) / 5.) * 0.9
77 def s_log2_to_linear(s_log):
83 linear = ((219. * (pow(10.,
85 (w - b) - 0.616596 - 0.03) / 0.432699)) -
86 0.037584) / 155.) * 0.9)
88 linear = (((s_log - b) / (
89 w - b) - 0.030001222851889303) / 3.53881278538813) * 0.9
92 def s_log3_to_linear(code_value):
93 if code_value >= 171.2102946929:
94 linear = (pow(10, ((code_value - 420) / 261.5)) *
97 linear = (code_value - 95) * 0.01125000 / (171.2102946929 - 95)
101 cs.to_reference_transforms = []
103 if transfer_function == 'S-Log1':
104 data = array.array('f', '\0' * lut_resolution_1d * 4)
105 for c in range(lut_resolution_1d):
106 data[c] = s_log1_to_linear(1023 * c / (lut_resolution_1d - 1))
108 lut = '%s_to_linear.spi1d' % transfer_function
110 os.path.join(lut_directory, lut),
117 cs.to_reference_transforms.append({
120 'interpolation': 'linear',
121 '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 * c / (lut_resolution_1d - 1))
127 lut = '%s_to_linear.spi1d' % transfer_function
129 os.path.join(lut_directory, lut),
136 cs.to_reference_transforms.append({
139 'interpolation': 'linear',
140 'direction': 'forward'})
141 elif transfer_function == 'S-Log3':
142 data = array.array('f', '\0' * lut_resolution_1d * 4)
143 for c in range(lut_resolution_1d):
144 data[c] = s_log3_to_linear(1023 * c / (lut_resolution_1d - 1))
146 lut = '%s_to_linear.spi1d' % transfer_function
148 os.path.join(lut_directory, lut),
155 cs.to_reference_transforms.append({
158 'interpolation': 'linear',
159 'direction': 'forward'})
161 if gamut == 'S-Gamut':
162 cs.to_reference_transforms.append({
164 'matrix': mat44_from_mat33(
165 [0.754338638, 0.133697046, 0.111968437,
166 0.021198141, 1.005410934, -0.026610548,
167 -0.009756991, 0.004508563, 1.005253201]),
168 'direction': 'forward'})
169 elif gamut == 'S-Gamut Daylight':
170 cs.to_reference_transforms.append({
172 'matrix': mat44_from_mat33(
173 [0.8764457030, 0.0145411681, 0.1090131290,
174 0.0774075345, 0.9529571767, -0.0303647111,
175 0.0573564351, -0.1151066335, 1.0577501984]),
176 'direction': 'forward'})
177 elif gamut == 'S-Gamut Tungsten':
178 cs.to_reference_transforms.append({
180 'matrix': mat44_from_mat33(
181 [1.0110238740, -0.1362526051, 0.1252287310,
182 0.1011994504, 0.9562196265, -0.0574190769,
183 0.0600766530, -0.1010185315, 1.0409418785]),
184 'direction': 'forward'})
185 elif gamut == 'S-Gamut3.Cine':
186 cs.to_reference_transforms.append({
188 'matrix': mat44_from_mat33(
189 [0.6387886672, 0.2723514337, 0.0888598992,
190 -0.0039159061, 1.0880732308, -0.0841573249,
191 -0.0299072021, -0.0264325799, 1.0563397820]),
192 'direction': 'forward'})
193 elif gamut == 'S-Gamut3':
194 cs.to_reference_transforms.append({
196 'matrix': mat44_from_mat33(
197 [0.7529825954, 0.1433702162, 0.1036471884,
198 0.0217076974, 1.0153188355, -0.0370265329,
199 -0.0094160528, 0.0033704179, 1.0060456349]),
200 'direction': 'forward'})
202 cs.from_reference_transforms = []
206 def create_colorspaces(lut_directory, lut_resolution_1d):
208 Generates the colorspace conversions.
213 Parameter description.
218 Return value description.
224 s_log1_s_gamut = create_s_log(
231 colorspaces.append(s_log1_s_gamut)
234 s_log2_s_gamut = create_s_log(
241 colorspaces.append(s_log2_s_gamut)
243 s_log2_s_gamut_daylight = create_s_log(
250 colorspaces.append(s_log2_s_gamut_daylight)
252 s_log2_s_gamut_tungsten = create_s_log(
258 ["slog2_sgamuttung"])
259 colorspaces.append(s_log2_s_gamut_tungsten)
262 s_log3_s_gamut3Cine = create_s_log(
268 ["slog3_sgamutcine"])
269 colorspaces.append(s_log3_s_gamut3Cine)
271 s_log3_s_gamut3 = create_s_log(
278 colorspaces.append(s_log3_s_gamut3)
281 s_log1 = create_s_log(
288 colorspaces.append(s_log1)
290 s_log2 = create_s_log(
297 colorspaces.append(s_log2)
299 s_log3 = create_s_log(
306 colorspaces.append(s_log3)
309 s_gamut = create_s_log(
316 colorspaces.append(s_gamut)
318 s_gamut_daylight = create_s_log(
325 colorspaces.append(s_gamut_daylight)
327 s_gamut_tungsten = create_s_log(
334 colorspaces.append(s_gamut_tungsten)
336 s_gamut3Cine = create_s_log(
343 colorspaces.append(s_gamut3Cine)
345 s_gamut3 = create_s_log(
352 colorspaces.append(s_gamut3)