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,
42 Parameter description.
47 Return value description.
50 name = '%s - %s' % (transfer_function, gamut)
51 if transfer_function == '':
52 name = 'Linear - %s' % gamut
54 name = 'Curve - %s' % transfer_function
59 cs.equality_group = ''
60 cs.family = 'Input/Sony'
63 if gamut and transfer_function:
64 cs.aces_transform_id = 'IDT.Sony.%s_%s_10i.a1.v1' % (
65 transfer_function.replace('-', ''),
66 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(
241 colorspaces.append(s_log1_s_gamut)
244 s_log2_s_gamut = create_s_log(
250 colorspaces.append(s_log2_s_gamut)
252 s_log2_s_gamut_daylight = create_s_log(
258 colorspaces.append(s_log2_s_gamut_daylight)
260 s_log2_s_gamut_tungsten = create_s_log(
265 ['slog2_sgamuttung'])
266 colorspaces.append(s_log2_s_gamut_tungsten)
269 s_log3_s_gamut3Cine = create_s_log(
274 ['slog3_sgamutcine'])
275 colorspaces.append(s_log3_s_gamut3Cine)
277 s_log3_s_gamut3 = create_s_log(
283 colorspaces.append(s_log3_s_gamut3)
286 s_log1 = create_s_log(
292 colorspaces.append(s_log1)
294 s_log2 = create_s_log(
300 colorspaces.append(s_log2)
302 s_log3 = create_s_log(
308 colorspaces.append(s_log3)
311 s_gamut = create_s_log(
317 colorspaces.append(s_gamut)
319 s_gamut_daylight = create_s_log(
325 colorspaces.append(s_gamut_daylight)
327 s_gamut_tungsten = create_s_log(
333 colorspaces.append(s_gamut_tungsten)
335 s_gamut3Cine = create_s_log(
341 colorspaces.append(s_gamut3Cine)
343 s_gamut3 = create_s_log(
349 colorspaces.append(s_gamut3)