2 # -*- coding: utf-8 -*-
5 Implements support for *Sony* colorspaces conversions and transfer functions.
10 import aces_ocio.generateLUT as genlut
11 from aces_ocio.util import ColorSpace, mat44FromMat33
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__ = ['createSlog',
24 def createSlog(gamut, transferFunction, name, lutDir, lutResolution1d):
33 Parameter description.
38 Return value description.
41 name = "%s - %s" % (transferFunction, gamut)
42 if transferFunction == "":
43 name = "Linear - %s" % gamut
45 name = "%s" % transferFunction
53 def sLog1ToLinear(SLog):
61 (w - b) - 0.616596 - 0.03) / 0.432699)) -
65 ((SLog - b) / (w - b) - 0.030001222851889303) / 5.) * 0.9
68 def sLog2ToLinear(SLog):
74 lin = (219. * (pow(10.,
76 (w - b) - 0.616596 - 0.03) / 0.432699)) -
77 0.037584) / 155.) * 0.9)
79 lin = (((SLog - b) / (
80 w - b) - 0.030001222851889303) / 3.53881278538813) * 0.9
83 def sLog3ToLinear(codeValue):
84 if codeValue >= (171.2102946929):
85 linear = (pow(10.0, ((codeValue - 420.0) / 261.5)) *
88 linear = (codeValue - 95.0) * 0.01125000 / (171.2102946929 - 95.0)
89 # print(codeValue, linear)
92 cs.toReferenceTransforms = []
94 if transferFunction == "S-Log1":
95 data = array.array('f', "\0" * lutResolution1d * 4)
96 for c in range(lutResolution1d):
97 data[c] = sLog1ToLinear(1023.0 * c / (lutResolution1d - 1))
99 lut = "%s_to_linear.spi1d" % transferFunction
108 # print("Writing %s" % lut)
110 cs.toReferenceTransforms.append({
113 'interpolation': 'linear',
114 'direction': 'forward'
116 elif transferFunction == "S-Log2":
117 data = array.array('f', "\0" * lutResolution1d * 4)
118 for c in range(lutResolution1d):
119 data[c] = sLog2ToLinear(1023.0 * c / (lutResolution1d - 1))
121 lut = "%s_to_linear.spi1d" % transferFunction
130 # print("Writing %s" % lut)
132 cs.toReferenceTransforms.append({
135 'interpolation': 'linear',
136 'direction': 'forward'
138 elif transferFunction == "S-Log3":
139 data = array.array('f', "\0" * lutResolution1d * 4)
140 for c in range(lutResolution1d):
141 data[c] = sLog3ToLinear(1023.0 * c / (lutResolution1d - 1))
143 lut = "%s_to_linear.spi1d" % transferFunction
152 # print("Writing %s" % lut)
154 cs.toReferenceTransforms.append({
157 'interpolation': 'linear',
158 'direction': 'forward'
161 if gamut == 'S-Gamut':
162 cs.toReferenceTransforms.append({
164 'matrix': mat44FromMat33([0.754338638, 0.133697046, 0.111968437,
165 0.021198141, 1.005410934, -0.026610548,
166 -0.009756991, 0.004508563, 1.005253201]),
167 'direction': 'forward'
169 elif gamut == 'S-Gamut Daylight':
170 cs.toReferenceTransforms.append({
172 'matrix': mat44FromMat33(
173 [0.8764457030, 0.0145411681, 0.1090131290,
174 0.0774075345, 0.9529571767, -0.0303647111,
175 0.0573564351, -0.1151066335, 1.0577501984]),
176 'direction': 'forward'
178 elif gamut == 'S-Gamut Tungsten':
179 cs.toReferenceTransforms.append({
181 'matrix': mat44FromMat33(
182 [1.0110238740, -0.1362526051, 0.1252287310,
183 0.1011994504, 0.9562196265, -0.0574190769,
184 0.0600766530, -0.1010185315, 1.0409418785]),
185 'direction': 'forward'
187 elif gamut == 'S-Gamut3.Cine':
188 cs.toReferenceTransforms.append({
190 'matrix': mat44FromMat33(
191 [0.6387886672, 0.2723514337, 0.0888598992,
192 -0.0039159061, 1.0880732308, -0.0841573249,
193 -0.0299072021, -0.0264325799, 1.0563397820]),
194 'direction': 'forward'
196 elif gamut == 'S-Gamut3':
197 cs.toReferenceTransforms.append({
199 'matrix': mat44FromMat33(
200 [0.7529825954, 0.1433702162, 0.1036471884,
201 0.0217076974, 1.0153188355, -0.0370265329,
202 -0.0094160528, 0.0033704179, 1.0060456349]),
203 'direction': 'forward'
206 cs.fromReferenceTransforms = []
210 def createColorSpaces(lutDir, lutResolution1d):
212 Generates the colorspace conversions.
217 Parameter description.
222 Return value description.
228 SLog1SGamut = createSlog(
229 "S-Gamut", "S-Log1", "S-Log", lutDir, lutResolution1d)
230 colorspaces.append(SLog1SGamut)
233 SLog2SGamut = createSlog(
234 "S-Gamut", "S-Log2", "S-Log2", lutDir, lutResolution1d)
235 colorspaces.append(SLog2SGamut)
237 SLog2SGamutDaylight = createSlog(
238 "S-Gamut Daylight", "S-Log2", "S-Log2", lutDir, lutResolution1d)
239 colorspaces.append(SLog2SGamutDaylight)
241 SLog2SGamutTungsten = createSlog(
242 "S-Gamut Tungsten", "S-Log2", "S-Log2", lutDir, lutResolution1d)
243 colorspaces.append(SLog2SGamutTungsten)
246 SLog3SGamut3Cine = createSlog(
247 "S-Gamut3.Cine", "S-Log3", "S-Log3", lutDir, lutResolution1d)
248 colorspaces.append(SLog3SGamut3Cine)
250 SLog3SGamut3 = createSlog(
251 "S-Gamut3", "S-Log3", "S-Log3", lutDir, lutResolution1d)
252 colorspaces.append(SLog3SGamut3)
255 SLog1 = createSlog("", "S-Log1", "S-Log", lutDir, lutResolution1d)
256 colorspaces.append(SLog1)
258 SLog2 = createSlog("", "S-Log2", "S-Log2", lutDir, lutResolution1d)
259 colorspaces.append(SLog2)
261 SLog3 = createSlog("", "S-Log3", "S-Log3", lutDir, lutResolution1d)
262 colorspaces.append(SLog3)
265 SGamut = createSlog("S-Gamut", "", "S-Log", lutDir, lutResolution1d)
266 colorspaces.append(SGamut)
268 SGamutDaylight = createSlog(
269 "S-Gamut Daylight", "", "S-Log2", lutDir, lutResolution1d)
270 colorspaces.append(SGamutDaylight)
272 SGamutTungsten = createSlog(
273 "S-Gamut Tungsten", "", "S-Log2", lutDir, lutResolution1d)
274 colorspaces.append(SGamutTungsten)
276 SGamut3Cine = createSlog(
277 "S-Gamut3.Cine", "", "S-Log3", lutDir, lutResolution1d)
278 colorspaces.append(SGamut3Cine)
280 SGamut3 = createSlog("S-Gamut3", "", "S-Log3", lutDir, lutResolution1d)
281 colorspaces.append(SGamut3)