2 # -*- coding: utf-8 -*-
6 import aces_ocio.generateLUT as genlut
7 from aces_ocio.util import ColorSpace, mat44FromMat33
12 def createSlog(gamut, transferFunction, name, lutDir, lutResolution1d):
13 name = "%s - %s" % (transferFunction, gamut)
14 if transferFunction == "":
15 name = "Linear - %s" % gamut
17 name = "%s" % transferFunction
25 def sLog1ToLinear(SLog):
33 (w - b) - 0.616596 - 0.03) / 0.432699)) -
37 ((SLog - b) / (w - b) - 0.030001222851889303) / 5.) * 0.9
40 def sLog2ToLinear(SLog):
46 lin = (219. * (pow(10.,
48 (w - b) - 0.616596 - 0.03) / 0.432699)) -
49 0.037584) / 155.) * 0.9)
51 lin = (((SLog - b) / (
52 w - b) - 0.030001222851889303) / 3.53881278538813) * 0.9
55 def sLog3ToLinear(codeValue):
56 if codeValue >= (171.2102946929):
57 linear = (pow(10.0, ((codeValue - 420.0) / 261.5)) *
60 linear = (codeValue - 95.0) * 0.01125000 / (171.2102946929 - 95.0)
61 # print(codeValue, linear)
64 cs.toReferenceTransforms = []
66 if transferFunction == "S-Log1":
67 data = array.array('f', "\0" * lutResolution1d * 4)
68 for c in range(lutResolution1d):
69 data[c] = sLog1ToLinear(1023.0 * c / (lutResolution1d - 1))
71 lut = "%s_to_linear.spi1d" % transferFunction
80 # print("Writing %s" % lut)
82 cs.toReferenceTransforms.append({
85 'interpolation': 'linear',
86 'direction': 'forward'
88 elif transferFunction == "S-Log2":
89 data = array.array('f', "\0" * lutResolution1d * 4)
90 for c in range(lutResolution1d):
91 data[c] = sLog2ToLinear(1023.0 * c / (lutResolution1d - 1))
93 lut = "%s_to_linear.spi1d" % transferFunction
102 # print("Writing %s" % lut)
104 cs.toReferenceTransforms.append({
107 'interpolation': 'linear',
108 'direction': 'forward'
110 elif transferFunction == "S-Log3":
111 data = array.array('f', "\0" * lutResolution1d * 4)
112 for c in range(lutResolution1d):
113 data[c] = sLog3ToLinear(1023.0 * c / (lutResolution1d - 1))
115 lut = "%s_to_linear.spi1d" % transferFunction
124 # print("Writing %s" % lut)
126 cs.toReferenceTransforms.append({
129 'interpolation': 'linear',
130 'direction': 'forward'
133 if gamut == 'S-Gamut':
134 cs.toReferenceTransforms.append({
136 'matrix': mat44FromMat33([0.754338638, 0.133697046, 0.111968437,
137 0.021198141, 1.005410934, -0.026610548,
138 -0.009756991, 0.004508563, 1.005253201]),
139 'direction': 'forward'
141 elif gamut == 'S-Gamut Daylight':
142 cs.toReferenceTransforms.append({
144 'matrix': mat44FromMat33(
145 [0.8764457030, 0.0145411681, 0.1090131290,
146 0.0774075345, 0.9529571767, -0.0303647111,
147 0.0573564351, -0.1151066335, 1.0577501984]),
148 'direction': 'forward'
150 elif gamut == 'S-Gamut Tungsten':
151 cs.toReferenceTransforms.append({
153 'matrix': mat44FromMat33(
154 [1.0110238740, -0.1362526051, 0.1252287310,
155 0.1011994504, 0.9562196265, -0.0574190769,
156 0.0600766530, -0.1010185315, 1.0409418785]),
157 'direction': 'forward'
159 elif gamut == 'S-Gamut3.Cine':
160 cs.toReferenceTransforms.append({
162 'matrix': mat44FromMat33(
163 [0.6387886672, 0.2723514337, 0.0888598992,
164 -0.0039159061, 1.0880732308, -0.0841573249,
165 -0.0299072021, -0.0264325799, 1.0563397820]),
166 'direction': 'forward'
168 elif gamut == 'S-Gamut3':
169 cs.toReferenceTransforms.append({
171 'matrix': mat44FromMat33(
172 [0.7529825954, 0.1433702162, 0.1036471884,
173 0.0217076974, 1.0153188355, -0.0370265329,
174 -0.0094160528, 0.0033704179, 1.0060456349]),
175 'direction': 'forward'
178 cs.fromReferenceTransforms = []
182 def createColorSpaces(lutDir, lutResolution1d):
186 SLog1SGamut = createSlog(
187 "S-Gamut", "S-Log1", "S-Log", lutDir, lutResolution1d)
188 colorspaces.append(SLog1SGamut)
191 SLog2SGamut = createSlog(
192 "S-Gamut", "S-Log2", "S-Log2", lutDir, lutResolution1d)
193 colorspaces.append(SLog2SGamut)
195 SLog2SGamutDaylight = createSlog(
196 "S-Gamut Daylight", "S-Log2", "S-Log2", lutDir, lutResolution1d)
197 colorspaces.append(SLog2SGamutDaylight)
199 SLog2SGamutTungsten = createSlog(
200 "S-Gamut Tungsten", "S-Log2", "S-Log2", lutDir, lutResolution1d)
201 colorspaces.append(SLog2SGamutTungsten)
204 SLog3SGamut3Cine = createSlog(
205 "S-Gamut3.Cine", "S-Log3", "S-Log3", lutDir, lutResolution1d)
206 colorspaces.append(SLog3SGamut3Cine)
208 SLog3SGamut3 = createSlog(
209 "S-Gamut3", "S-Log3", "S-Log3", lutDir, lutResolution1d)
210 colorspaces.append(SLog3SGamut3)
213 SLog1 = createSlog("", "S-Log1", "S-Log", lutDir, lutResolution1d)
214 colorspaces.append(SLog1)
216 SLog2 = createSlog("", "S-Log2", "S-Log2", lutDir, lutResolution1d)
217 colorspaces.append(SLog2)
219 SLog3 = createSlog("", "S-Log3", "S-Log3", lutDir, lutResolution1d)
220 colorspaces.append(SLog3)
223 SGamut = createSlog("S-Gamut", "", "S-Log", lutDir, lutResolution1d)
224 colorspaces.append(SGamut)
226 SGamutDaylight = createSlog(
227 "S-Gamut Daylight", "", "S-Log2", lutDir, lutResolution1d)
228 colorspaces.append(SGamutDaylight)
230 SGamutTungsten = createSlog(
231 "S-Gamut Tungsten", "", "S-Log2", lutDir, lutResolution1d)
232 colorspaces.append(SGamutTungsten)
234 SGamut3Cine = createSlog(
235 "S-Gamut3.Cine", "", "S-Log3", lutDir, lutResolution1d)
236 colorspaces.append(SGamut3Cine)
238 SGamut3 = createSlog("S-Gamut3", "", "S-Log3", lutDir, lutResolution1d)
239 colorspaces.append(SGamut3)