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,
35 Creates colorspace covering the conversion from Sony spaces to ACES, with various
36 transfer functions and encoding gamuts covered
41 The name of the encoding gamut to use.
42 transfer_function : str
43 The name of the transfer function to use
44 lut_directory : str or unicode
45 The directory to use when generating LUTs
46 lut_resolution_1d : int
47 The resolution of generated 1D LUTs
49 Aliases for this colorspace
54 A ColorSpace container class referencing the LUTs, matrices and identifying
55 information for the requested colorspace.
58 name = '%s - %s' % (transfer_function, gamut)
59 if transfer_function == '':
60 name = 'Linear - %s' % gamut
62 name = 'Curve - %s' % transfer_function
67 cs.equality_group = ''
68 cs.family = 'Input/Sony'
71 if gamut and transfer_function:
72 cs.aces_transform_id = 'IDT.Sony.%s_%s_10i.a1.v1' % (
73 transfer_function.replace('-', ''),
74 gamut.replace('-', '').replace(' ', '_'))
76 # A linear space needs allocation variables.
77 if transfer_function == '':
78 cs.allocation_type = ocio.Constants.ALLOCATION_LG2
79 cs.allocation_vars = [-8, 5, 0.00390625]
81 def s_log1_to_linear(s_log):
89 (w - b) - 0.616596 - 0.03) / 0.432699)) -
92 linear = (((s_log - b) / (
93 w - b) - 0.030001222851889303) / 5.) * 0.9
96 def s_log2_to_linear(s_log):
102 linear = ((219. * (pow(10.,
104 (w - b) - 0.616596 - 0.03) / 0.432699)) -
105 0.037584) / 155.) * 0.9)
107 linear = (((s_log - b) / (
108 w - b) - 0.030001222851889303) / 3.53881278538813) * 0.9
111 def s_log3_to_linear(code_value):
112 if code_value >= 171.2102946929:
113 linear = (pow(10, ((code_value - 420) / 261.5)) *
114 (0.18 + 0.01) - 0.01)
116 linear = (code_value - 95) * 0.01125000 / (171.2102946929 - 95)
120 cs.to_reference_transforms = []
122 if transfer_function == 'S-Log1':
123 data = array.array('f', '\0' * lut_resolution_1d * 4)
124 for c in range(lut_resolution_1d):
125 data[c] = s_log1_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-Log2':
142 data = array.array('f', '\0' * lut_resolution_1d * 4)
143 for c in range(lut_resolution_1d):
144 data[c] = s_log2_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'})
160 elif transfer_function == 'S-Log3':
161 data = array.array('f', '\0' * lut_resolution_1d * 4)
162 for c in range(lut_resolution_1d):
163 data[c] = s_log3_to_linear(1023 * c / (lut_resolution_1d - 1))
165 lut = '%s_to_linear.spi1d' % transfer_function
167 os.path.join(lut_directory, lut),
174 cs.to_reference_transforms.append({
177 'interpolation': 'linear',
178 'direction': 'forward'})
180 if gamut == 'S-Gamut':
181 cs.to_reference_transforms.append({
183 'matrix': mat44_from_mat33(
184 [0.754338638, 0.133697046, 0.111968437,
185 0.021198141, 1.005410934, -0.026610548,
186 -0.009756991, 0.004508563, 1.005253201]),
187 'direction': 'forward'})
188 elif gamut == 'S-Gamut Daylight':
189 cs.to_reference_transforms.append({
191 'matrix': mat44_from_mat33(
192 [0.8764457030, 0.0145411681, 0.1090131290,
193 0.0774075345, 0.9529571767, -0.0303647111,
194 0.0573564351, -0.1151066335, 1.0577501984]),
195 'direction': 'forward'})
196 elif gamut == 'S-Gamut Tungsten':
197 cs.to_reference_transforms.append({
199 'matrix': mat44_from_mat33(
200 [1.0110238740, -0.1362526051, 0.1252287310,
201 0.1011994504, 0.9562196265, -0.0574190769,
202 0.0600766530, -0.1010185315, 1.0409418785]),
203 'direction': 'forward'})
204 elif gamut == 'S-Gamut3.Cine':
205 cs.to_reference_transforms.append({
207 'matrix': mat44_from_mat33(
208 [0.6387886672, 0.2723514337, 0.0888598992,
209 -0.0039159061, 1.0880732308, -0.0841573249,
210 -0.0299072021, -0.0264325799, 1.0563397820]),
211 'direction': 'forward'})
212 elif gamut == 'S-Gamut3':
213 cs.to_reference_transforms.append({
215 'matrix': mat44_from_mat33(
216 [0.7529825954, 0.1433702162, 0.1036471884,
217 0.0217076974, 1.0153188355, -0.0370265329,
218 -0.0094160528, 0.0033704179, 1.0060456349]),
219 'direction': 'forward'})
221 cs.from_reference_transforms = []
225 def create_colorspaces(lut_directory, lut_resolution_1d):
227 Generates the colorspace conversions.
231 lut_directory : str or unicode
232 The directory to use when generating LUTs
233 lut_resolution_1d : int
234 The resolution of generated 1D LUTs
239 A list of colorspaces for Sony cameras and encodings
245 s_log1_s_gamut = create_s_log(
251 colorspaces.append(s_log1_s_gamut)
254 s_log2_s_gamut = create_s_log(
260 colorspaces.append(s_log2_s_gamut)
262 s_log2_s_gamut_daylight = create_s_log(
268 colorspaces.append(s_log2_s_gamut_daylight)
270 s_log2_s_gamut_tungsten = create_s_log(
275 ['slog2_sgamuttung'])
276 colorspaces.append(s_log2_s_gamut_tungsten)
279 s_log3_s_gamut3Cine = create_s_log(
284 ['slog3_sgamutcine'])
285 colorspaces.append(s_log3_s_gamut3Cine)
287 s_log3_s_gamut3 = create_s_log(
293 colorspaces.append(s_log3_s_gamut3)
296 s_log1 = create_s_log(
302 colorspaces.append(s_log1)
304 s_log2 = create_s_log(
310 colorspaces.append(s_log2)
312 s_log3 = create_s_log(
318 colorspaces.append(s_log3)
321 s_gamut = create_s_log(
327 colorspaces.append(s_gamut)
329 s_gamut_daylight = create_s_log(
335 colorspaces.append(s_gamut_daylight)
337 s_gamut_tungsten = create_s_log(
343 colorspaces.append(s_gamut_tungsten)
345 s_gamut3Cine = create_s_log(
351 colorspaces.append(s_gamut3Cine)
353 s_gamut3 = create_s_log(
359 colorspaces.append(s_gamut3)