2 # -*- coding: utf-8 -*-
6 import aces_ocio.generateLUT as genlut
7 from aces_ocio.util import ColorSpace
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__ = ['createCanonLog',
20 def createCanonLog(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 legalToFull(codeValue):
50 return (codeValue - 64.0) / (940.0 - 64.0)
52 def canonLogToLinear(codeValue):
53 # log = fullToLegal(c1 * log10(c2*linear + 1) + c3)
54 # linear = (pow(10, (legalToFul(log) - c3)/c1) - 1)/c2
59 linear = (pow(10.0, (legalToFull(codeValue) - c3) / c1) - 1.0) / c2
61 # print(codeValue, linear)
64 cs.toReferenceTransforms = []
66 if transferFunction == "Canon-Log":
67 data = array.array('f', "\0" * lutResolution1d * 4)
68 for c in range(lutResolution1d):
69 data[c] = canonLogToLinear(1023.0 * c / (lutResolution1d - 1))
71 lut = "%s_to_linear.spi1d" % transferFunction
72 genlut.writeSPI1D(lutDir + "/" + lut,
79 cs.toReferenceTransforms.append({
82 'interpolation': 'linear',
83 'direction': 'forward'
86 if gamut == 'Rec. 709 Daylight':
87 cs.toReferenceTransforms.append({
89 'matrix': [0.561538969, 0.402060105, 0.036400926, 0.0,
90 0.092739623, 0.924121198, -0.016860821, 0.0,
91 0.084812961, 0.006373835, 0.908813204, 0.0,
93 'direction': 'forward'
95 elif gamut == 'Rec. 709 Tungsten':
96 cs.toReferenceTransforms.append({
98 'matrix': [0.566996399, 0.365079418, 0.067924183, 0.0,
99 0.070901044, 0.880331008, 0.048767948, 0.0,
100 0.073013542, -0.066540862, 0.99352732, 0.0,
102 'direction': 'forward'
104 elif gamut == 'DCI-P3 Daylight':
105 cs.toReferenceTransforms.append({
107 'matrix': [0.607160575, 0.299507286, 0.093332140, 0.0,
108 0.004968120, 1.050982224, -0.055950343, 0.0,
109 -0.007839939, 0.000809127, 1.007030813, 0.0,
111 'direction': 'forward'
113 elif gamut == 'DCI-P3 Tungsten':
114 cs.toReferenceTransforms.append({
116 'matrix': [0.650279125, 0.253880169, 0.095840706, 0.0,
117 -0.026137986, 1.017900530, 0.008237456, 0.0,
118 0.007757558, -0.063081669, 1.055324110, 0.0,
120 'direction': 'forward'
122 elif gamut == 'Cinema Gamut Daylight':
123 cs.toReferenceTransforms.append({
125 'matrix': [0.763064455, 0.149021161, 0.087914384, 0.0,
126 0.003657457, 1.10696038, -0.110617837, 0.0,
127 -0.009407794, -0.218383305, 1.227791099, 0.0,
129 'direction': 'forward'
131 elif gamut == 'Cinema Gamut Tungsten':
132 cs.toReferenceTransforms.append({
134 'matrix': [0.817416293, 0.090755698, 0.091828009, 0.0,
135 -0.035361374, 1.065690585, -0.030329211, 0.0,
136 0.010390366, -0.299271107, 1.288880741, 0.0,
138 'direction': 'forward'
141 cs.fromReferenceTransforms = []
145 def createColorSpaces(lutDir, lutResolution1d):
147 Generates the colorspace conversions.
152 Parameter description.
157 Return value description.
163 CanonLog1 = createCanonLog(
164 "Rec. 709 Daylight", "Canon-Log", "Canon-Log", lutDir, lutResolution1d)
165 colorspaces.append(CanonLog1)
167 CanonLog2 = createCanonLog(
168 "Rec. 709 Tungsten", "Canon-Log", "Canon-Log", lutDir, lutResolution1d)
169 colorspaces.append(CanonLog2)
171 CanonLog3 = createCanonLog(
172 "DCI-P3 Daylight", "Canon-Log", "Canon-Log", lutDir, lutResolution1d)
173 colorspaces.append(CanonLog3)
175 CanonLog4 = createCanonLog(
176 "DCI-P3 Tungsten", "Canon-Log", "Canon-Log", lutDir, lutResolution1d)
177 colorspaces.append(CanonLog4)
179 CanonLog5 = createCanonLog(
180 "Cinema Gamut Daylight", "Canon-Log", "Canon-Log",
181 lutDir, lutResolution1d)
182 colorspaces.append(CanonLog5)
184 CanonLog6 = createCanonLog(
185 "Cinema Gamut Tungsten", "Canon-Log", "Canon-Log",
186 lutDir, lutResolution1d)
187 colorspaces.append(CanonLog6)
190 CanonLog7 = createCanonLog(
191 '', "Canon-Log", "Canon-Log", lutDir, lutResolution1d)
192 colorspaces.append(CanonLog7)
195 CanonLog8 = createCanonLog(
196 "Rec. 709 Daylight", "", "Canon-Log", lutDir, lutResolution1d)
197 colorspaces.append(CanonLog8)
199 CanonLog9 = createCanonLog(
200 "Rec. 709 Tungsten", "", "Canon-Log", lutDir, lutResolution1d)
201 colorspaces.append(CanonLog9)
203 CanonLog10 = createCanonLog(
204 "DCI-P3 Daylight", "", "Canon-Log", lutDir, lutResolution1d)
205 colorspaces.append(CanonLog10)
207 CanonLog11 = createCanonLog("DCI-P3 Tungsten", "", "Canon-Log", lutDir,
209 colorspaces.append(CanonLog11)
211 CanonLog12 = createCanonLog(
212 "Cinema Gamut Daylight", "", "Canon-Log", lutDir, lutResolution1d)
213 colorspaces.append(CanonLog12)
215 CanonLog13 = createCanonLog(
216 "Cinema Gamut Tungsten", "", "Canon-Log", lutDir, lutResolution1d)
217 colorspaces.append(CanonLog13)