2 # -*- coding: utf-8 -*-
5 Implements support for *Sony* colorspaces conversions and transfer functions.
8 from __future__ import division
13 import PyOpenColorIO as ocio
15 import aces_ocio.generate_lut as genlut
16 from aces_ocio.utilities import ColorSpace, mat44_from_mat33
18 __author__ = 'ACES Developers'
19 __copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers'
21 __maintainer__ = 'ACES Developers'
22 __email__ = 'aces@oscars.org'
23 __status__ = 'Production'
25 __all__ = ['create_s_log',
29 def create_s_log(gamut,
43 Parameter description.
48 Return value description.
51 name = '%s - %s' % (transfer_function, gamut)
52 if transfer_function == '':
53 name = 'Linear - %s' % gamut
55 name = 'Curve - %s' % transfer_function
60 cs.equality_group = ''
61 cs.family = 'Input/Sony'
64 if gamut and transfer_function:
65 cs.aces_transform_id = "IDT.Sony.%s_%s_10i.a1.v1" % (
66 transfer_function.replace('-', ''), gamut.replace('-', '').replace(' ', '_'))
68 # A linear space needs allocation variables
69 if transfer_function == '':
70 cs.allocation_type = ocio.Constants.ALLOCATION_LG2
71 cs.allocation_vars = [-8, 5, 0.00390625]
73 def s_log1_to_linear(s_log):
81 (w - b) - 0.616596 - 0.03) / 0.432699)) -
84 linear = (((s_log - b) / (
85 w - b) - 0.030001222851889303) / 5.) * 0.9
88 def s_log2_to_linear(s_log):
94 linear = ((219. * (pow(10.,
96 (w - b) - 0.616596 - 0.03) / 0.432699)) -
97 0.037584) / 155.) * 0.9)
99 linear = (((s_log - b) / (
100 w - b) - 0.030001222851889303) / 3.53881278538813) * 0.9
103 def s_log3_to_linear(code_value):
104 if code_value >= 171.2102946929:
105 linear = (pow(10, ((code_value - 420) / 261.5)) *
106 (0.18 + 0.01) - 0.01)
108 linear = (code_value - 95) * 0.01125000 / (171.2102946929 - 95)
112 cs.to_reference_transforms = []
114 if transfer_function == 'S-Log1':
115 data = array.array('f', '\0' * lut_resolution_1d * 4)
116 for c in range(lut_resolution_1d):
117 data[c] = s_log1_to_linear(1023 * c / (lut_resolution_1d - 1))
119 lut = '%s_to_linear.spi1d' % transfer_function
121 os.path.join(lut_directory, lut),
128 cs.to_reference_transforms.append({
131 'interpolation': 'linear',
132 'direction': 'forward'})
133 elif transfer_function == 'S-Log2':
134 data = array.array('f', '\0' * lut_resolution_1d * 4)
135 for c in range(lut_resolution_1d):
136 data[c] = s_log2_to_linear(1023 * c / (lut_resolution_1d - 1))
138 lut = '%s_to_linear.spi1d' % transfer_function
140 os.path.join(lut_directory, lut),
147 cs.to_reference_transforms.append({
150 'interpolation': 'linear',
151 'direction': 'forward'})
152 elif transfer_function == 'S-Log3':
153 data = array.array('f', '\0' * lut_resolution_1d * 4)
154 for c in range(lut_resolution_1d):
155 data[c] = s_log3_to_linear(1023 * c / (lut_resolution_1d - 1))
157 lut = '%s_to_linear.spi1d' % transfer_function
159 os.path.join(lut_directory, lut),
166 cs.to_reference_transforms.append({
169 'interpolation': 'linear',
170 'direction': 'forward'})
172 if gamut == 'S-Gamut':
173 cs.to_reference_transforms.append({
175 'matrix': mat44_from_mat33(
176 [0.754338638, 0.133697046, 0.111968437,
177 0.021198141, 1.005410934, -0.026610548,
178 -0.009756991, 0.004508563, 1.005253201]),
179 'direction': 'forward'})
180 elif gamut == 'S-Gamut Daylight':
181 cs.to_reference_transforms.append({
183 'matrix': mat44_from_mat33(
184 [0.8764457030, 0.0145411681, 0.1090131290,
185 0.0774075345, 0.9529571767, -0.0303647111,
186 0.0573564351, -0.1151066335, 1.0577501984]),
187 'direction': 'forward'})
188 elif gamut == 'S-Gamut Tungsten':
189 cs.to_reference_transforms.append({
191 'matrix': mat44_from_mat33(
192 [1.0110238740, -0.1362526051, 0.1252287310,
193 0.1011994504, 0.9562196265, -0.0574190769,
194 0.0600766530, -0.1010185315, 1.0409418785]),
195 'direction': 'forward'})
196 elif gamut == 'S-Gamut3.Cine':
197 cs.to_reference_transforms.append({
199 'matrix': mat44_from_mat33(
200 [0.6387886672, 0.2723514337, 0.0888598992,
201 -0.0039159061, 1.0880732308, -0.0841573249,
202 -0.0299072021, -0.0264325799, 1.0563397820]),
203 'direction': 'forward'})
204 elif gamut == 'S-Gamut3':
205 cs.to_reference_transforms.append({
207 'matrix': mat44_from_mat33(
208 [0.7529825954, 0.1433702162, 0.1036471884,
209 0.0217076974, 1.0153188355, -0.0370265329,
210 -0.0094160528, 0.0033704179, 1.0060456349]),
211 'direction': 'forward'})
213 cs.from_reference_transforms = []
217 def create_colorspaces(lut_directory, lut_resolution_1d):
219 Generates the colorspace conversions.
224 Parameter description.
229 Return value description.
235 s_log1_s_gamut = create_s_log(
242 colorspaces.append(s_log1_s_gamut)
245 s_log2_s_gamut = create_s_log(
252 colorspaces.append(s_log2_s_gamut)
254 s_log2_s_gamut_daylight = create_s_log(
261 colorspaces.append(s_log2_s_gamut_daylight)
263 s_log2_s_gamut_tungsten = create_s_log(
269 ["slog2_sgamuttung"])
270 colorspaces.append(s_log2_s_gamut_tungsten)
273 s_log3_s_gamut3Cine = create_s_log(
279 ["slog3_sgamutcine"])
280 colorspaces.append(s_log3_s_gamut3Cine)
282 s_log3_s_gamut3 = create_s_log(
289 colorspaces.append(s_log3_s_gamut3)
292 s_log1 = create_s_log(
299 colorspaces.append(s_log1)
301 s_log2 = create_s_log(
308 colorspaces.append(s_log2)
310 s_log3 = create_s_log(
317 colorspaces.append(s_log3)
320 s_gamut = create_s_log(
327 colorspaces.append(s_gamut)
329 s_gamut_daylight = create_s_log(
336 colorspaces.append(s_gamut_daylight)
338 s_gamut_tungsten = create_s_log(
345 colorspaces.append(s_gamut_tungsten)
347 s_gamut3Cine = create_s_log(
354 colorspaces.append(s_gamut3Cine)
356 s_gamut3 = create_s_log(
363 colorspaces.append(s_gamut3)