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):
31 lin = ( pow(10., ( ( ( SLog - b) / ( w - b) - 0.616596 - 0.03) / 0.432699)) - 0.037584) * 0.9
33 lin = ( ( ( SLog - b) / ( w - b) - 0.030001222851889303) / 5.) * 0.9
36 def sLog2ToLinear(SLog):
42 lin = ( 219. * ( pow(10., ( ( ( SLog - b) / ( w - b) - 0.616596 - 0.03) / 0.432699)) - 0.037584) / 155.) * 0.9
44 lin = ( ( ( SLog - b) / ( w - b) - 0.030001222851889303) / 3.53881278538813) * 0.9
47 def sLog3ToLinear(codeValue):
48 if codeValue >= (171.2102946929):
49 linear = pow(10.0, ((codeValue - 420.0) / 261.5)) * (0.18 + 0.01) - 0.01
51 linear = (codeValue - 95.0)*0.01125000/(171.2102946929 - 95.0)
52 #print( codeValue, linear )
55 cs.toReferenceTransforms = []
57 if transferFunction == "S-Log1":
58 data = array.array('f', "\0" * lutResolution1d * 4)
59 for c in range(lutResolution1d):
60 data[c] = sLog1ToLinear(1023.0*c/(lutResolution1d-1))
62 lut = "%s_to_linear.spi1d" % transferFunction
63 genlut.writeSPI1D(lutDir + "/" + lut, 0.0, 1.0, data, lutResolution1d, 1)
65 #print( "Writing %s" % lut)
67 cs.toReferenceTransforms.append( {
70 'interpolation':'linear',
73 elif transferFunction == "S-Log2":
74 data = array.array('f', "\0" * lutResolution1d * 4)
75 for c in range(lutResolution1d):
76 data[c] = sLog2ToLinear(1023.0*c/(lutResolution1d-1))
78 lut = "%s_to_linear.spi1d" % transferFunction
79 genlut.writeSPI1D(lutDir + "/" + lut, 0.0, 1.0, data, lutResolution1d, 1)
81 #print( "Writing %s" % lut)
83 cs.toReferenceTransforms.append( {
86 'interpolation':'linear',
89 elif transferFunction == "S-Log3":
90 data = array.array('f', "\0" * lutResolution1d * 4)
91 for c in range(lutResolution1d):
92 data[c] = sLog3ToLinear(1023.0*c/(lutResolution1d-1))
94 lut = "%s_to_linear.spi1d" % transferFunction
95 genlut.writeSPI1D(lutDir + "/" + lut, 0.0, 1.0, data, lutResolution1d, 1)
97 #print( "Writing %s" % lut)
99 cs.toReferenceTransforms.append( {
102 'interpolation':'linear',
103 'direction':'forward'
106 if gamut == 'S-Gamut':
107 cs.toReferenceTransforms.append( {
109 'matrix':mat44FromMat33([0.754338638, 0.133697046, 0.111968437,
110 0.021198141, 1.005410934, -0.026610548,
111 -0.009756991, 0.004508563, 1.005253201]),
112 'direction':'forward'
114 elif gamut == 'S-Gamut Daylight':
115 cs.toReferenceTransforms.append( {
117 'matrix':mat44FromMat33([0.8764457030, 0.0145411681, 0.1090131290,
118 0.0774075345, 0.9529571767, -0.0303647111,
119 0.0573564351, -0.1151066335, 1.0577501984]),
120 'direction':'forward'
122 elif gamut == 'S-Gamut Tungsten':
123 cs.toReferenceTransforms.append( {
125 'matrix':mat44FromMat33([1.0110238740, -0.1362526051, 0.1252287310,
126 0.1011994504, 0.9562196265, -0.0574190769,
127 0.0600766530, -0.1010185315, 1.0409418785]),
128 'direction':'forward'
130 elif gamut == 'S-Gamut3.Cine':
131 cs.toReferenceTransforms.append( {
133 'matrix':mat44FromMat33([0.6387886672, 0.2723514337, 0.0888598992,
134 -0.0039159061, 1.0880732308, -0.0841573249,
135 -0.0299072021, -0.0264325799, 1.0563397820]),
136 'direction':'forward'
138 elif gamut == 'S-Gamut3':
139 cs.toReferenceTransforms.append( {
141 'matrix':mat44FromMat33([0.7529825954, 0.1433702162, 0.1036471884,
142 0.0217076974, 1.0153188355, -0.0370265329,
143 -0.0094160528, 0.0033704179, 1.0060456349]),
144 'direction':'forward'
147 cs.fromReferenceTransforms = []
150 def createColorSpaces(lutDir, lutResolution1d):
154 SLog1SGamut = createSlog("S-Gamut", "S-Log1", "S-Log", lutDir, lutResolution1d)
155 colorspaces.append(SLog1SGamut)
158 SLog2SGamut = createSlog("S-Gamut", "S-Log2", "S-Log2", lutDir, lutResolution1d)
159 colorspaces.append(SLog2SGamut)
161 SLog2SGamutDaylight = createSlog("S-Gamut Daylight", "S-Log2", "S-Log2", lutDir, lutResolution1d)
162 colorspaces.append(SLog2SGamutDaylight)
164 SLog2SGamutTungsten = createSlog("S-Gamut Tungsten", "S-Log2", "S-Log2", lutDir, lutResolution1d)
165 colorspaces.append(SLog2SGamutTungsten)
168 SLog3SGamut3Cine = createSlog("S-Gamut3.Cine", "S-Log3", "S-Log3", lutDir, lutResolution1d)
169 colorspaces.append(SLog3SGamut3Cine)
171 SLog3SGamut3 = createSlog("S-Gamut3", "S-Log3", "S-Log3", lutDir, lutResolution1d)
172 colorspaces.append(SLog3SGamut3)
175 SLog1 = createSlog("", "S-Log1", "S-Log", lutDir, lutResolution1d)
176 colorspaces.append(SLog1)
178 SLog2 = createSlog("", "S-Log2", "S-Log2", lutDir, lutResolution1d)
179 colorspaces.append(SLog2)
181 SLog3 = createSlog("", "S-Log3", "S-Log3", lutDir, lutResolution1d)
182 colorspaces.append(SLog3)
185 SGamut = createSlog("S-Gamut", "", "S-Log", lutDir, lutResolution1d)
186 colorspaces.append(SGamut)
188 SGamutDaylight = createSlog("S-Gamut Daylight", "", "S-Log2", lutDir, lutResolution1d)
189 colorspaces.append(SGamutDaylight)
191 SGamutTungsten = createSlog("S-Gamut Tungsten", "", "S-Log2", lutDir, lutResolution1d)
192 colorspaces.append(SGamutTungsten)
194 SGamut3Cine = createSlog("S-Gamut3.Cine", "", "S-Log3", lutDir, lutResolution1d)
195 colorspaces.append(SGamut3Cine)
197 SGamut3 = createSlog("S-Gamut3", "", "S-Log3", lutDir, lutResolution1d)
198 colorspaces.append(SGamut3)