2 # -*- coding: utf-8 -*-
5 Implements support for *Canon* colorspaces conversions and transfer functions.
10 import aces_ocio.generateLUT as genlut
11 from aces_ocio.util import ColorSpace
13 __author__ = 'ACES Developers'
14 __copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers'
16 __maintainer__ = 'ACES Developers'
17 __email__ = 'aces@oscars.org'
18 __status__ = 'Production'
20 __all__ = ['createCanonLog',
24 def createCanonLog(gamut, transferFunction, name, lutDir, lutResolution1d):
33 Parameter description.
38 Return value description.
41 name = "%s - %s" % (transferFunction, gamut)
42 if transferFunction == "":
43 name = "Linear - %s" % gamut
45 name = "%s" % transferFunction
53 def legalToFull(codeValue):
54 return (codeValue - 64.0) / (940.0 - 64.0)
56 def canonLogToLinear(codeValue):
57 # log = fullToLegal(c1 * log10(c2*linear + 1) + c3)
58 # linear = (pow(10, (legalToFul(log) - c3)/c1) - 1)/c2
63 linear = (pow(10.0, (legalToFull(codeValue) - c3) / c1) - 1.0) / c2
65 # print(codeValue, linear)
68 cs.toReferenceTransforms = []
70 if transferFunction == "Canon-Log":
71 data = array.array('f', "\0" * lutResolution1d * 4)
72 for c in range(lutResolution1d):
73 data[c] = canonLogToLinear(1023.0 * c / (lutResolution1d - 1))
75 lut = "%s_to_linear.spi1d" % transferFunction
76 genlut.writeSPI1D(lutDir + "/" + lut,
83 cs.toReferenceTransforms.append({
86 'interpolation': 'linear',
87 'direction': 'forward'
90 if gamut == 'Rec. 709 Daylight':
91 cs.toReferenceTransforms.append({
93 'matrix': [0.561538969, 0.402060105, 0.036400926, 0.0,
94 0.092739623, 0.924121198, -0.016860821, 0.0,
95 0.084812961, 0.006373835, 0.908813204, 0.0,
97 'direction': 'forward'
99 elif gamut == 'Rec. 709 Tungsten':
100 cs.toReferenceTransforms.append({
102 'matrix': [0.566996399, 0.365079418, 0.067924183, 0.0,
103 0.070901044, 0.880331008, 0.048767948, 0.0,
104 0.073013542, -0.066540862, 0.99352732, 0.0,
106 'direction': 'forward'
108 elif gamut == 'DCI-P3 Daylight':
109 cs.toReferenceTransforms.append({
111 'matrix': [0.607160575, 0.299507286, 0.093332140, 0.0,
112 0.004968120, 1.050982224, -0.055950343, 0.0,
113 -0.007839939, 0.000809127, 1.007030813, 0.0,
115 'direction': 'forward'
117 elif gamut == 'DCI-P3 Tungsten':
118 cs.toReferenceTransforms.append({
120 'matrix': [0.650279125, 0.253880169, 0.095840706, 0.0,
121 -0.026137986, 1.017900530, 0.008237456, 0.0,
122 0.007757558, -0.063081669, 1.055324110, 0.0,
124 'direction': 'forward'
126 elif gamut == 'Cinema Gamut Daylight':
127 cs.toReferenceTransforms.append({
129 'matrix': [0.763064455, 0.149021161, 0.087914384, 0.0,
130 0.003657457, 1.10696038, -0.110617837, 0.0,
131 -0.009407794, -0.218383305, 1.227791099, 0.0,
133 'direction': 'forward'
135 elif gamut == 'Cinema Gamut Tungsten':
136 cs.toReferenceTransforms.append({
138 'matrix': [0.817416293, 0.090755698, 0.091828009, 0.0,
139 -0.035361374, 1.065690585, -0.030329211, 0.0,
140 0.010390366, -0.299271107, 1.288880741, 0.0,
142 'direction': 'forward'
145 cs.fromReferenceTransforms = []
149 def createColorSpaces(lutDir, lutResolution1d):
151 Generates the colorspace conversions.
156 Parameter description.
161 Return value description.
167 CanonLog1 = createCanonLog(
168 "Rec. 709 Daylight", "Canon-Log", "Canon-Log", lutDir, lutResolution1d)
169 colorspaces.append(CanonLog1)
171 CanonLog2 = createCanonLog(
172 "Rec. 709 Tungsten", "Canon-Log", "Canon-Log", lutDir, lutResolution1d)
173 colorspaces.append(CanonLog2)
175 CanonLog3 = createCanonLog(
176 "DCI-P3 Daylight", "Canon-Log", "Canon-Log", lutDir, lutResolution1d)
177 colorspaces.append(CanonLog3)
179 CanonLog4 = createCanonLog(
180 "DCI-P3 Tungsten", "Canon-Log", "Canon-Log", lutDir, lutResolution1d)
181 colorspaces.append(CanonLog4)
183 CanonLog5 = createCanonLog(
184 "Cinema Gamut Daylight", "Canon-Log", "Canon-Log",
185 lutDir, lutResolution1d)
186 colorspaces.append(CanonLog5)
188 CanonLog6 = createCanonLog(
189 "Cinema Gamut Tungsten", "Canon-Log", "Canon-Log",
190 lutDir, lutResolution1d)
191 colorspaces.append(CanonLog6)
194 CanonLog7 = createCanonLog(
195 '', "Canon-Log", "Canon-Log", lutDir, lutResolution1d)
196 colorspaces.append(CanonLog7)
199 CanonLog8 = createCanonLog(
200 "Rec. 709 Daylight", "", "Canon-Log", lutDir, lutResolution1d)
201 colorspaces.append(CanonLog8)
203 CanonLog9 = createCanonLog(
204 "Rec. 709 Tungsten", "", "Canon-Log", lutDir, lutResolution1d)
205 colorspaces.append(CanonLog9)
207 CanonLog10 = createCanonLog(
208 "DCI-P3 Daylight", "", "Canon-Log", lutDir, lutResolution1d)
209 colorspaces.append(CanonLog10)
211 CanonLog11 = createCanonLog("DCI-P3 Tungsten", "", "Canon-Log", lutDir,
213 colorspaces.append(CanonLog11)
215 CanonLog12 = createCanonLog(
216 "Cinema Gamut Daylight", "", "Canon-Log", lutDir, lutResolution1d)
217 colorspaces.append(CanonLog12)
219 CanonLog13 = createCanonLog(
220 "Cinema Gamut Tungsten", "", "Canon-Log", lutDir, lutResolution1d)
221 colorspaces.append(CanonLog13)