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',
22 def createSlog(gamut, transferFunction, name, lutDir, lutResolution1d):
23 name = "%s - %s" % (transferFunction, gamut)
24 if transferFunction == "":
25 name = "Linear - %s" % gamut
27 name = "%s" % transferFunction
35 def sLog1ToLinear(SLog):
43 (w - b) - 0.616596 - 0.03) / 0.432699)) -
47 ((SLog - b) / (w - b) - 0.030001222851889303) / 5.) * 0.9
50 def sLog2ToLinear(SLog):
56 lin = (219. * (pow(10.,
58 (w - b) - 0.616596 - 0.03) / 0.432699)) -
59 0.037584) / 155.) * 0.9)
61 lin = (((SLog - b) / (
62 w - b) - 0.030001222851889303) / 3.53881278538813) * 0.9
65 def sLog3ToLinear(codeValue):
66 if codeValue >= (171.2102946929):
67 linear = (pow(10.0, ((codeValue - 420.0) / 261.5)) *
70 linear = (codeValue - 95.0) * 0.01125000 / (171.2102946929 - 95.0)
71 # print(codeValue, linear)
74 cs.toReferenceTransforms = []
76 if transferFunction == "S-Log1":
77 data = array.array('f', "\0" * lutResolution1d * 4)
78 for c in range(lutResolution1d):
79 data[c] = sLog1ToLinear(1023.0 * c / (lutResolution1d - 1))
81 lut = "%s_to_linear.spi1d" % transferFunction
90 # print("Writing %s" % lut)
92 cs.toReferenceTransforms.append({
95 'interpolation': 'linear',
96 'direction': 'forward'
98 elif transferFunction == "S-Log2":
99 data = array.array('f', "\0" * lutResolution1d * 4)
100 for c in range(lutResolution1d):
101 data[c] = sLog2ToLinear(1023.0 * c / (lutResolution1d - 1))
103 lut = "%s_to_linear.spi1d" % transferFunction
112 # print("Writing %s" % lut)
114 cs.toReferenceTransforms.append({
117 'interpolation': 'linear',
118 'direction': 'forward'
120 elif transferFunction == "S-Log3":
121 data = array.array('f', "\0" * lutResolution1d * 4)
122 for c in range(lutResolution1d):
123 data[c] = sLog3ToLinear(1023.0 * c / (lutResolution1d - 1))
125 lut = "%s_to_linear.spi1d" % transferFunction
134 # print("Writing %s" % lut)
136 cs.toReferenceTransforms.append({
139 'interpolation': 'linear',
140 'direction': 'forward'
143 if gamut == 'S-Gamut':
144 cs.toReferenceTransforms.append({
146 'matrix': mat44FromMat33([0.754338638, 0.133697046, 0.111968437,
147 0.021198141, 1.005410934, -0.026610548,
148 -0.009756991, 0.004508563, 1.005253201]),
149 'direction': 'forward'
151 elif gamut == 'S-Gamut Daylight':
152 cs.toReferenceTransforms.append({
154 'matrix': mat44FromMat33(
155 [0.8764457030, 0.0145411681, 0.1090131290,
156 0.0774075345, 0.9529571767, -0.0303647111,
157 0.0573564351, -0.1151066335, 1.0577501984]),
158 'direction': 'forward'
160 elif gamut == 'S-Gamut Tungsten':
161 cs.toReferenceTransforms.append({
163 'matrix': mat44FromMat33(
164 [1.0110238740, -0.1362526051, 0.1252287310,
165 0.1011994504, 0.9562196265, -0.0574190769,
166 0.0600766530, -0.1010185315, 1.0409418785]),
167 'direction': 'forward'
169 elif gamut == 'S-Gamut3.Cine':
170 cs.toReferenceTransforms.append({
172 'matrix': mat44FromMat33(
173 [0.6387886672, 0.2723514337, 0.0888598992,
174 -0.0039159061, 1.0880732308, -0.0841573249,
175 -0.0299072021, -0.0264325799, 1.0563397820]),
176 'direction': 'forward'
178 elif gamut == 'S-Gamut3':
179 cs.toReferenceTransforms.append({
181 'matrix': mat44FromMat33(
182 [0.7529825954, 0.1433702162, 0.1036471884,
183 0.0217076974, 1.0153188355, -0.0370265329,
184 -0.0094160528, 0.0033704179, 1.0060456349]),
185 'direction': 'forward'
188 cs.fromReferenceTransforms = []
192 def createColorSpaces(lutDir, lutResolution1d):
196 SLog1SGamut = createSlog(
197 "S-Gamut", "S-Log1", "S-Log", lutDir, lutResolution1d)
198 colorspaces.append(SLog1SGamut)
201 SLog2SGamut = createSlog(
202 "S-Gamut", "S-Log2", "S-Log2", lutDir, lutResolution1d)
203 colorspaces.append(SLog2SGamut)
205 SLog2SGamutDaylight = createSlog(
206 "S-Gamut Daylight", "S-Log2", "S-Log2", lutDir, lutResolution1d)
207 colorspaces.append(SLog2SGamutDaylight)
209 SLog2SGamutTungsten = createSlog(
210 "S-Gamut Tungsten", "S-Log2", "S-Log2", lutDir, lutResolution1d)
211 colorspaces.append(SLog2SGamutTungsten)
214 SLog3SGamut3Cine = createSlog(
215 "S-Gamut3.Cine", "S-Log3", "S-Log3", lutDir, lutResolution1d)
216 colorspaces.append(SLog3SGamut3Cine)
218 SLog3SGamut3 = createSlog(
219 "S-Gamut3", "S-Log3", "S-Log3", lutDir, lutResolution1d)
220 colorspaces.append(SLog3SGamut3)
223 SLog1 = createSlog("", "S-Log1", "S-Log", lutDir, lutResolution1d)
224 colorspaces.append(SLog1)
226 SLog2 = createSlog("", "S-Log2", "S-Log2", lutDir, lutResolution1d)
227 colorspaces.append(SLog2)
229 SLog3 = createSlog("", "S-Log3", "S-Log3", lutDir, lutResolution1d)
230 colorspaces.append(SLog3)
233 SGamut = createSlog("S-Gamut", "", "S-Log", lutDir, lutResolution1d)
234 colorspaces.append(SGamut)
236 SGamutDaylight = createSlog(
237 "S-Gamut Daylight", "", "S-Log2", lutDir, lutResolution1d)
238 colorspaces.append(SGamutDaylight)
240 SGamutTungsten = createSlog(
241 "S-Gamut Tungsten", "", "S-Log2", lutDir, lutResolution1d)
242 colorspaces.append(SGamutTungsten)
244 SGamut3Cine = createSlog(
245 "S-Gamut3.Cine", "", "S-Log3", lutDir, lutResolution1d)
246 colorspaces.append(SGamut3Cine)
248 SGamut3 = createSlog("S-Gamut3", "", "S-Log3", lutDir, lutResolution1d)
249 colorspaces.append(SGamut3)