2 # -*- coding: utf-8 -*-
5 Implements support for *Sony* colorspaces conversions and transfer functions.
10 import aces_ocio.generate_lut as genlut
11 from aces_ocio.utilities import ColorSpace, mat44_from_mat33
13 __author__ = 'ACES Developers'
14 __copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers'
16 __maintainer__ = 'ACES Developers'
17 __email__ = 'aces@oscars.org'
18 __status__ = 'Production'
20 __all__ = ['create_s_log',
24 def create_s_log(gamut,
37 Parameter description.
42 Return value description.
45 name = "%s - %s" % (transfer_function, gamut)
46 if transfer_function == "":
47 name = "Linear - %s" % gamut
49 name = "%s" % transfer_function
53 cs.equality_group = ''
57 def s_log1_to_linear(s_log):
65 (w - b) - 0.616596 - 0.03) / 0.432699)) -
70 w - b) - 0.030001222851889303) / 5.) * 0.9
73 def s_log2_to_linear(s_log):
79 linear = (219. * (pow(10.,
81 (w - b) - 0.616596 - 0.03) / 0.432699)) -
82 0.037584) / 155.) * 0.9)
84 linear = (((s_log - b) / (
85 w - b) - 0.030001222851889303) / 3.53881278538813) * 0.9
88 def s_log3_to_linear(code_value):
89 if code_value >= (171.2102946929):
90 linear = (pow(10.0, ((code_value - 420.0) / 261.5)) *
93 linear = (code_value - 95.0) * 0.01125000 / (171.2102946929 - 95.0)
94 # print(codeValue, linear)
97 cs.to_reference_transforms = []
99 if transfer_function == "S-Log1":
100 data = array.array('f', "\0" * lut_resolution_1d * 4)
101 for c in range(lut_resolution_1d):
102 data[c] = s_log1_to_linear(1023.0 * c / (lut_resolution_1d - 1))
104 lut = "%s_to_linear.spi1d" % transfer_function
105 genlut.write_SPI_1d(lut_directory + "/" + lut,
112 # print("Writing %s" % lut)
114 cs.to_reference_transforms.append({
117 'interpolation': 'linear',
118 'direction': 'forward'
120 elif transfer_function == "S-Log2":
121 data = array.array('f', "\0" * lut_resolution_1d * 4)
122 for c in range(lut_resolution_1d):
123 data[c] = s_log2_to_linear(1023.0 * c / (lut_resolution_1d - 1))
125 lut = "%s_to_linear.spi1d" % transfer_function
126 genlut.write_SPI_1d(lut_directory + "/" + lut,
133 # print("Writing %s" % lut)
135 cs.to_reference_transforms.append({
138 'interpolation': 'linear',
139 '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.0 * c / (lut_resolution_1d - 1))
146 lut = "%s_to_linear.spi1d" % transfer_function
147 genlut.write_SPI_1d(lut_directory + "/" + lut,
154 # print("Writing %s" % lut)
156 cs.to_reference_transforms.append({
159 'interpolation': 'linear',
160 'direction': 'forward'
163 if gamut == 'S-Gamut':
164 cs.to_reference_transforms.append({
166 'matrix': mat44_from_mat33(
167 [0.754338638, 0.133697046, 0.111968437,
168 0.021198141, 1.005410934, -0.026610548,
169 -0.009756991, 0.004508563, 1.005253201]),
170 'direction': 'forward'})
171 elif gamut == 'S-Gamut Daylight':
172 cs.to_reference_transforms.append({
174 'matrix': mat44_from_mat33(
175 [0.8764457030, 0.0145411681, 0.1090131290,
176 0.0774075345, 0.9529571767, -0.0303647111,
177 0.0573564351, -0.1151066335, 1.0577501984]),
178 'direction': 'forward'})
179 elif gamut == 'S-Gamut Tungsten':
180 cs.to_reference_transforms.append({
182 'matrix': mat44_from_mat33(
183 [1.0110238740, -0.1362526051, 0.1252287310,
184 0.1011994504, 0.9562196265, -0.0574190769,
185 0.0600766530, -0.1010185315, 1.0409418785]),
186 'direction': 'forward'})
187 elif gamut == 'S-Gamut3.Cine':
188 cs.to_reference_transforms.append({
190 'matrix': mat44_from_mat33(
191 [0.6387886672, 0.2723514337, 0.0888598992,
192 -0.0039159061, 1.0880732308, -0.0841573249,
193 -0.0299072021, -0.0264325799, 1.0563397820]),
194 'direction': 'forward'})
195 elif gamut == 'S-Gamut3':
196 cs.to_reference_transforms.append({
198 'matrix': mat44_from_mat33(
199 [0.7529825954, 0.1433702162, 0.1036471884,
200 0.0217076974, 1.0153188355, -0.0370265329,
201 -0.0094160528, 0.0033704179, 1.0060456349]),
202 'direction': 'forward'})
204 cs.from_reference_transforms = []
208 def create_colorspaces(lut_directory, lut_resolution_1d):
210 Generates the colorspace conversions.
215 Parameter description.
220 Return value description.
226 s_log1_s_gamut = create_s_log(
232 colorspaces.append(s_log1_s_gamut)
235 s_log2_s_gamut = create_s_log(
241 colorspaces.append(s_log2_s_gamut)
243 s_log2_s_gamut_daylight = create_s_log(
249 colorspaces.append(s_log2_s_gamut_daylight)
251 s_log2_s_gamut_tungsten = create_s_log(
257 colorspaces.append(s_log2_s_gamut_tungsten)
260 s_log3_s_gamut3Cine = create_s_log(
266 colorspaces.append(s_log3_s_gamut3Cine)
268 s_log3_s_gamut3 = create_s_log(
274 colorspaces.append(s_log3_s_gamut3)
277 s_log1 = create_s_log(
283 colorspaces.append(s_log1)
285 s_log2 = create_s_log(
291 colorspaces.append(s_log2)
293 s_log3 = create_s_log(
299 colorspaces.append(s_log3)
302 s_gamut = create_s_log(
308 colorspaces.append(s_gamut)
310 s_gamut_daylight = create_s_log(
316 colorspaces.append(s_gamut_daylight)
318 s_gamut_tungsten = create_s_log(
324 colorspaces.append(s_gamut_tungsten)
326 s_gamut3Cine = create_s_log(
332 colorspaces.append(s_gamut3Cine)
334 s_gamut3 = create_s_log(
340 colorspaces.append(s_gamut3)