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',
22 def createCanonLog(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 legalToFull(codeValue):
36 return (codeValue - 64.0) / (940.0 - 64.0)
38 def canonLogToLinear(codeValue):
39 # log = fullToLegal(c1 * log10(c2*linear + 1) + c3)
40 # linear = (pow(10, (legalToFul(log) - c3)/c1) - 1)/c2
45 linear = (pow(10.0, (legalToFull(codeValue) - c3) / c1) - 1.0) / c2
47 # print(codeValue, linear)
50 cs.toReferenceTransforms = []
52 if transferFunction == "Canon-Log":
53 data = array.array('f', "\0" * lutResolution1d * 4)
54 for c in range(lutResolution1d):
55 data[c] = canonLogToLinear(1023.0 * c / (lutResolution1d - 1))
57 lut = "%s_to_linear.spi1d" % transferFunction
58 genlut.writeSPI1D(lutDir + "/" + lut,
65 cs.toReferenceTransforms.append({
68 'interpolation': 'linear',
69 'direction': 'forward'
72 if gamut == 'Rec. 709 Daylight':
73 cs.toReferenceTransforms.append({
75 'matrix': [0.561538969, 0.402060105, 0.036400926, 0.0,
76 0.092739623, 0.924121198, -0.016860821, 0.0,
77 0.084812961, 0.006373835, 0.908813204, 0.0,
79 'direction': 'forward'
81 elif gamut == 'Rec. 709 Tungsten':
82 cs.toReferenceTransforms.append({
84 'matrix': [0.566996399, 0.365079418, 0.067924183, 0.0,
85 0.070901044, 0.880331008, 0.048767948, 0.0,
86 0.073013542, -0.066540862, 0.99352732, 0.0,
88 'direction': 'forward'
90 elif gamut == 'DCI-P3 Daylight':
91 cs.toReferenceTransforms.append({
93 'matrix': [0.607160575, 0.299507286, 0.093332140, 0.0,
94 0.004968120, 1.050982224, -0.055950343, 0.0,
95 -0.007839939, 0.000809127, 1.007030813, 0.0,
97 'direction': 'forward'
99 elif gamut == 'DCI-P3 Tungsten':
100 cs.toReferenceTransforms.append({
102 'matrix': [0.650279125, 0.253880169, 0.095840706, 0.0,
103 -0.026137986, 1.017900530, 0.008237456, 0.0,
104 0.007757558, -0.063081669, 1.055324110, 0.0,
106 'direction': 'forward'
108 elif gamut == 'Cinema Gamut Daylight':
109 cs.toReferenceTransforms.append({
111 'matrix': [0.763064455, 0.149021161, 0.087914384, 0.0,
112 0.003657457, 1.10696038, -0.110617837, 0.0,
113 -0.009407794, -0.218383305, 1.227791099, 0.0,
115 'direction': 'forward'
117 elif gamut == 'Cinema Gamut Tungsten':
118 cs.toReferenceTransforms.append({
120 'matrix': [0.817416293, 0.090755698, 0.091828009, 0.0,
121 -0.035361374, 1.065690585, -0.030329211, 0.0,
122 0.010390366, -0.299271107, 1.288880741, 0.0,
124 'direction': 'forward'
127 cs.fromReferenceTransforms = []
131 # Generate all color spaces conversion
132 def createColorSpaces(lutDir, lutResolution1d):
136 CanonLog1 = createCanonLog(
137 "Rec. 709 Daylight", "Canon-Log", "Canon-Log", lutDir, lutResolution1d)
138 colorspaces.append(CanonLog1)
140 CanonLog2 = createCanonLog(
141 "Rec. 709 Tungsten", "Canon-Log", "Canon-Log", lutDir, lutResolution1d)
142 colorspaces.append(CanonLog2)
144 CanonLog3 = createCanonLog(
145 "DCI-P3 Daylight", "Canon-Log", "Canon-Log", lutDir, lutResolution1d)
146 colorspaces.append(CanonLog3)
148 CanonLog4 = createCanonLog(
149 "DCI-P3 Tungsten", "Canon-Log", "Canon-Log", lutDir, lutResolution1d)
150 colorspaces.append(CanonLog4)
152 CanonLog5 = createCanonLog(
153 "Cinema Gamut Daylight", "Canon-Log", "Canon-Log",
154 lutDir, lutResolution1d)
155 colorspaces.append(CanonLog5)
157 CanonLog6 = createCanonLog(
158 "Cinema Gamut Tungsten", "Canon-Log", "Canon-Log",
159 lutDir, lutResolution1d)
160 colorspaces.append(CanonLog6)
163 CanonLog7 = createCanonLog(
164 '', "Canon-Log", "Canon-Log", lutDir, lutResolution1d)
165 colorspaces.append(CanonLog7)
168 CanonLog8 = createCanonLog(
169 "Rec. 709 Daylight", "", "Canon-Log", lutDir, lutResolution1d)
170 colorspaces.append(CanonLog8)
172 CanonLog9 = createCanonLog(
173 "Rec. 709 Tungsten", "", "Canon-Log", lutDir, lutResolution1d)
174 colorspaces.append(CanonLog9)
176 CanonLog10 = createCanonLog(
177 "DCI-P3 Daylight", "", "Canon-Log", lutDir, lutResolution1d)
178 colorspaces.append(CanonLog10)
180 CanonLog11 = createCanonLog("DCI-P3 Tungsten", "", "Canon-Log", lutDir,
182 colorspaces.append(CanonLog11)
184 CanonLog12 = createCanonLog(
185 "Cinema Gamut Daylight", "", "Canon-Log", lutDir, lutResolution1d)
186 colorspaces.append(CanonLog12)
188 CanonLog13 = createCanonLog(
189 "Cinema Gamut Tungsten", "", "Canon-Log", lutDir, lutResolution1d)
190 colorspaces.append(CanonLog13)