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('-', ''),
67 gamut.replace('-', '').replace(' ', '_'))
69 # A linear space needs allocation variables
70 if transfer_function == '':
71 cs.allocation_type = ocio.Constants.ALLOCATION_LG2
72 cs.allocation_vars = [-8, 5, 0.00390625]
74 def s_log1_to_linear(s_log):
82 (w - b) - 0.616596 - 0.03) / 0.432699)) -
85 linear = (((s_log - b) / (
86 w - b) - 0.030001222851889303) / 5.) * 0.9
89 def s_log2_to_linear(s_log):
95 linear = ((219. * (pow(10.,
97 (w - b) - 0.616596 - 0.03) / 0.432699)) -
98 0.037584) / 155.) * 0.9)
100 linear = (((s_log - b) / (
101 w - b) - 0.030001222851889303) / 3.53881278538813) * 0.9
104 def s_log3_to_linear(code_value):
105 if code_value >= 171.2102946929:
106 linear = (pow(10, ((code_value - 420) / 261.5)) *
107 (0.18 + 0.01) - 0.01)
109 linear = (code_value - 95) * 0.01125000 / (171.2102946929 - 95)
113 cs.to_reference_transforms = []
115 if transfer_function == 'S-Log1':
116 data = array.array('f', '\0' * lut_resolution_1d * 4)
117 for c in range(lut_resolution_1d):
118 data[c] = s_log1_to_linear(1023 * c / (lut_resolution_1d - 1))
120 lut = '%s_to_linear.spi1d' % transfer_function
122 os.path.join(lut_directory, lut),
129 cs.to_reference_transforms.append({
132 'interpolation': 'linear',
133 'direction': 'forward'})
134 elif transfer_function == 'S-Log2':
135 data = array.array('f', '\0' * lut_resolution_1d * 4)
136 for c in range(lut_resolution_1d):
137 data[c] = s_log2_to_linear(1023 * c / (lut_resolution_1d - 1))
139 lut = '%s_to_linear.spi1d' % transfer_function
141 os.path.join(lut_directory, lut),
148 cs.to_reference_transforms.append({
151 'interpolation': 'linear',
152 'direction': 'forward'})
153 elif transfer_function == 'S-Log3':
154 data = array.array('f', '\0' * lut_resolution_1d * 4)
155 for c in range(lut_resolution_1d):
156 data[c] = s_log3_to_linear(1023 * c / (lut_resolution_1d - 1))
158 lut = '%s_to_linear.spi1d' % transfer_function
160 os.path.join(lut_directory, lut),
167 cs.to_reference_transforms.append({
170 'interpolation': 'linear',
171 'direction': 'forward'})
173 if gamut == 'S-Gamut':
174 cs.to_reference_transforms.append({
176 'matrix': mat44_from_mat33(
177 [0.754338638, 0.133697046, 0.111968437,
178 0.021198141, 1.005410934, -0.026610548,
179 -0.009756991, 0.004508563, 1.005253201]),
180 'direction': 'forward'})
181 elif gamut == 'S-Gamut Daylight':
182 cs.to_reference_transforms.append({
184 'matrix': mat44_from_mat33(
185 [0.8764457030, 0.0145411681, 0.1090131290,
186 0.0774075345, 0.9529571767, -0.0303647111,
187 0.0573564351, -0.1151066335, 1.0577501984]),
188 'direction': 'forward'})
189 elif gamut == 'S-Gamut Tungsten':
190 cs.to_reference_transforms.append({
192 'matrix': mat44_from_mat33(
193 [1.0110238740, -0.1362526051, 0.1252287310,
194 0.1011994504, 0.9562196265, -0.0574190769,
195 0.0600766530, -0.1010185315, 1.0409418785]),
196 'direction': 'forward'})
197 elif gamut == 'S-Gamut3.Cine':
198 cs.to_reference_transforms.append({
200 'matrix': mat44_from_mat33(
201 [0.6387886672, 0.2723514337, 0.0888598992,
202 -0.0039159061, 1.0880732308, -0.0841573249,
203 -0.0299072021, -0.0264325799, 1.0563397820]),
204 'direction': 'forward'})
205 elif gamut == 'S-Gamut3':
206 cs.to_reference_transforms.append({
208 'matrix': mat44_from_mat33(
209 [0.7529825954, 0.1433702162, 0.1036471884,
210 0.0217076974, 1.0153188355, -0.0370265329,
211 -0.0094160528, 0.0033704179, 1.0060456349]),
212 'direction': 'forward'})
214 cs.from_reference_transforms = []
218 def create_colorspaces(lut_directory, lut_resolution_1d):
220 Generates the colorspace conversions.
225 Parameter description.
230 Return value description.
236 s_log1_s_gamut = create_s_log(
243 colorspaces.append(s_log1_s_gamut)
246 s_log2_s_gamut = create_s_log(
253 colorspaces.append(s_log2_s_gamut)
255 s_log2_s_gamut_daylight = create_s_log(
262 colorspaces.append(s_log2_s_gamut_daylight)
264 s_log2_s_gamut_tungsten = create_s_log(
270 ["slog2_sgamuttung"])
271 colorspaces.append(s_log2_s_gamut_tungsten)
274 s_log3_s_gamut3Cine = create_s_log(
280 ["slog3_sgamutcine"])
281 colorspaces.append(s_log3_s_gamut3Cine)
283 s_log3_s_gamut3 = create_s_log(
290 colorspaces.append(s_log3_s_gamut3)
293 s_log1 = create_s_log(
300 colorspaces.append(s_log1)
302 s_log2 = create_s_log(
309 colorspaces.append(s_log2)
311 s_log3 = create_s_log(
318 colorspaces.append(s_log3)
321 s_gamut = create_s_log(
328 colorspaces.append(s_gamut)
330 s_gamut_daylight = create_s_log(
337 colorspaces.append(s_gamut_daylight)
339 s_gamut_tungsten = create_s_log(
346 colorspaces.append(s_gamut_tungsten)
348 s_gamut3Cine = create_s_log(
355 colorspaces.append(s_gamut3Cine)
357 s_gamut3 = create_s_log(
364 colorspaces.append(s_gamut3)