2 # -*- coding: utf-8 -*-
6 import aces_ocio.generateLUT as genlut
7 from aces_ocio.util import ColorSpace, mat44FromMat33
9 __author__ = 'ACES Developers'
10 __copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers'
12 __maintainer__ = 'ACES Developers'
13 __email__ = 'aces@oscars.org'
14 __status__ = 'Production'
16 __all__ = ['createSlog',
20 def createSlog(gamut, transferFunction, name, lutDir, lutResolution1d):
29 Parameter description.
34 Return value description.
37 name = "%s - %s" % (transferFunction, gamut)
38 if transferFunction == "":
39 name = "Linear - %s" % gamut
41 name = "%s" % transferFunction
49 def sLog1ToLinear(SLog):
57 (w - b) - 0.616596 - 0.03) / 0.432699)) -
61 ((SLog - b) / (w - b) - 0.030001222851889303) / 5.) * 0.9
64 def sLog2ToLinear(SLog):
70 lin = (219. * (pow(10.,
72 (w - b) - 0.616596 - 0.03) / 0.432699)) -
73 0.037584) / 155.) * 0.9)
75 lin = (((SLog - b) / (
76 w - b) - 0.030001222851889303) / 3.53881278538813) * 0.9
79 def sLog3ToLinear(codeValue):
80 if codeValue >= (171.2102946929):
81 linear = (pow(10.0, ((codeValue - 420.0) / 261.5)) *
84 linear = (codeValue - 95.0) * 0.01125000 / (171.2102946929 - 95.0)
85 # print(codeValue, linear)
88 cs.toReferenceTransforms = []
90 if transferFunction == "S-Log1":
91 data = array.array('f', "\0" * lutResolution1d * 4)
92 for c in range(lutResolution1d):
93 data[c] = sLog1ToLinear(1023.0 * c / (lutResolution1d - 1))
95 lut = "%s_to_linear.spi1d" % transferFunction
104 # print("Writing %s" % lut)
106 cs.toReferenceTransforms.append({
109 'interpolation': 'linear',
110 'direction': 'forward'
112 elif transferFunction == "S-Log2":
113 data = array.array('f', "\0" * lutResolution1d * 4)
114 for c in range(lutResolution1d):
115 data[c] = sLog2ToLinear(1023.0 * c / (lutResolution1d - 1))
117 lut = "%s_to_linear.spi1d" % transferFunction
126 # print("Writing %s" % lut)
128 cs.toReferenceTransforms.append({
131 'interpolation': 'linear',
132 'direction': 'forward'
134 elif transferFunction == "S-Log3":
135 data = array.array('f', "\0" * lutResolution1d * 4)
136 for c in range(lutResolution1d):
137 data[c] = sLog3ToLinear(1023.0 * c / (lutResolution1d - 1))
139 lut = "%s_to_linear.spi1d" % transferFunction
148 # print("Writing %s" % lut)
150 cs.toReferenceTransforms.append({
153 'interpolation': 'linear',
154 'direction': 'forward'
157 if gamut == 'S-Gamut':
158 cs.toReferenceTransforms.append({
160 'matrix': mat44FromMat33([0.754338638, 0.133697046, 0.111968437,
161 0.021198141, 1.005410934, -0.026610548,
162 -0.009756991, 0.004508563, 1.005253201]),
163 'direction': 'forward'
165 elif gamut == 'S-Gamut Daylight':
166 cs.toReferenceTransforms.append({
168 'matrix': mat44FromMat33(
169 [0.8764457030, 0.0145411681, 0.1090131290,
170 0.0774075345, 0.9529571767, -0.0303647111,
171 0.0573564351, -0.1151066335, 1.0577501984]),
172 'direction': 'forward'
174 elif gamut == 'S-Gamut Tungsten':
175 cs.toReferenceTransforms.append({
177 'matrix': mat44FromMat33(
178 [1.0110238740, -0.1362526051, 0.1252287310,
179 0.1011994504, 0.9562196265, -0.0574190769,
180 0.0600766530, -0.1010185315, 1.0409418785]),
181 'direction': 'forward'
183 elif gamut == 'S-Gamut3.Cine':
184 cs.toReferenceTransforms.append({
186 'matrix': mat44FromMat33(
187 [0.6387886672, 0.2723514337, 0.0888598992,
188 -0.0039159061, 1.0880732308, -0.0841573249,
189 -0.0299072021, -0.0264325799, 1.0563397820]),
190 'direction': 'forward'
192 elif gamut == 'S-Gamut3':
193 cs.toReferenceTransforms.append({
195 'matrix': mat44FromMat33(
196 [0.7529825954, 0.1433702162, 0.1036471884,
197 0.0217076974, 1.0153188355, -0.0370265329,
198 -0.0094160528, 0.0033704179, 1.0060456349]),
199 'direction': 'forward'
202 cs.fromReferenceTransforms = []
206 def createColorSpaces(lutDir, lutResolution1d):
208 Generates the colorspace conversions.
213 Parameter description.
218 Return value description.
224 SLog1SGamut = createSlog(
225 "S-Gamut", "S-Log1", "S-Log", lutDir, lutResolution1d)
226 colorspaces.append(SLog1SGamut)
229 SLog2SGamut = createSlog(
230 "S-Gamut", "S-Log2", "S-Log2", lutDir, lutResolution1d)
231 colorspaces.append(SLog2SGamut)
233 SLog2SGamutDaylight = createSlog(
234 "S-Gamut Daylight", "S-Log2", "S-Log2", lutDir, lutResolution1d)
235 colorspaces.append(SLog2SGamutDaylight)
237 SLog2SGamutTungsten = createSlog(
238 "S-Gamut Tungsten", "S-Log2", "S-Log2", lutDir, lutResolution1d)
239 colorspaces.append(SLog2SGamutTungsten)
242 SLog3SGamut3Cine = createSlog(
243 "S-Gamut3.Cine", "S-Log3", "S-Log3", lutDir, lutResolution1d)
244 colorspaces.append(SLog3SGamut3Cine)
246 SLog3SGamut3 = createSlog(
247 "S-Gamut3", "S-Log3", "S-Log3", lutDir, lutResolution1d)
248 colorspaces.append(SLog3SGamut3)
251 SLog1 = createSlog("", "S-Log1", "S-Log", lutDir, lutResolution1d)
252 colorspaces.append(SLog1)
254 SLog2 = createSlog("", "S-Log2", "S-Log2", lutDir, lutResolution1d)
255 colorspaces.append(SLog2)
257 SLog3 = createSlog("", "S-Log3", "S-Log3", lutDir, lutResolution1d)
258 colorspaces.append(SLog3)
261 SGamut = createSlog("S-Gamut", "", "S-Log", lutDir, lutResolution1d)
262 colorspaces.append(SGamut)
264 SGamutDaylight = createSlog(
265 "S-Gamut Daylight", "", "S-Log2", lutDir, lutResolution1d)
266 colorspaces.append(SGamutDaylight)
268 SGamutTungsten = createSlog(
269 "S-Gamut Tungsten", "", "S-Log2", lutDir, lutResolution1d)
270 colorspaces.append(SGamutTungsten)
272 SGamut3Cine = createSlog(
273 "S-Gamut3.Cine", "", "S-Log3", lutDir, lutResolution1d)
274 colorspaces.append(SGamut3Cine)
276 SGamut3 = createSlog("S-Gamut3", "", "S-Log3", lutDir, lutResolution1d)
277 colorspaces.append(SGamut3)