2 # -*- coding: utf-8 -*-
5 Implements support for *Canon* colorspaces conversions and transfer functions.
11 import aces_ocio.generate_lut as genlut
12 from aces_ocio.utilities import ColorSpace
14 __author__ = 'ACES Developers'
15 __copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers'
17 __maintainer__ = 'ACES Developers'
18 __email__ = 'aces@oscars.org'
19 __status__ = 'Production'
21 __all__ = ['create_c_log',
25 def create_c_log(gamut,
39 Parameter description.
44 Return value description.
47 name = '%s - %s' % (transfer_function, gamut)
48 if transfer_function == '':
49 name = 'Linear - %s' % gamut
51 name = '%s' % transfer_function
56 cs.equality_group = ''
60 def legal_to_full(code_value):
61 return (code_value - 64.0) / (940.0 - 64.0)
63 def c_log_to_linear(code_value):
64 # log = fullToLegal(c1 * log10(c2*linear + 1) + c3)
65 # linear = (pow(10, (legalToFul(log) - c3)/c1) - 1)/c2
70 linear = (pow(10.0, (legal_to_full(code_value) - c3) / c1) - 1.0) / c2
75 cs.to_reference_transforms = []
77 if transfer_function == 'Canon-Log':
78 data = array.array('f', '\0' * lut_resolution_1d * 4)
79 for c in range(lut_resolution_1d):
80 data[c] = c_log_to_linear(1023.0 * c / (lut_resolution_1d - 1))
82 lut = '%s_to_linear.spi1d' % transfer_function
84 os.path.join(lut_directory, lut),
91 cs.to_reference_transforms.append({
94 'interpolation': 'linear',
95 'direction': 'forward'})
97 if gamut == 'Rec. 709 Daylight':
98 cs.to_reference_transforms.append({
100 'matrix': [0.561538969, 0.402060105, 0.036400926, 0.0,
101 0.092739623, 0.924121198, -0.016860821, 0.0,
102 0.084812961, 0.006373835, 0.908813204, 0.0,
104 'direction': 'forward'})
105 elif gamut == 'Rec. 709 Tungsten':
106 cs.to_reference_transforms.append({
108 'matrix': [0.566996399, 0.365079418, 0.067924183, 0.0,
109 0.070901044, 0.880331008, 0.048767948, 0.0,
110 0.073013542, -0.066540862, 0.99352732, 0.0,
112 'direction': 'forward'})
113 elif gamut == 'DCI-P3 Daylight':
114 cs.to_reference_transforms.append({
116 'matrix': [0.607160575, 0.299507286, 0.093332140, 0.0,
117 0.004968120, 1.050982224, -0.055950343, 0.0,
118 -0.007839939, 0.000809127, 1.007030813, 0.0,
120 'direction': 'forward'})
121 elif gamut == 'DCI-P3 Tungsten':
122 cs.to_reference_transforms.append({
124 'matrix': [0.650279125, 0.253880169, 0.095840706, 0.0,
125 -0.026137986, 1.017900530, 0.008237456, 0.0,
126 0.007757558, -0.063081669, 1.055324110, 0.0,
128 'direction': 'forward'})
129 elif gamut == 'Cinema Gamut Daylight':
130 cs.to_reference_transforms.append({
132 'matrix': [0.763064455, 0.149021161, 0.087914384, 0.0,
133 0.003657457, 1.10696038, -0.110617837, 0.0,
134 -0.009407794, -0.218383305, 1.227791099, 0.0,
136 'direction': 'forward'})
137 elif gamut == 'Cinema Gamut Tungsten':
138 cs.to_reference_transforms.append({
140 'matrix': [0.817416293, 0.090755698, 0.091828009, 0.0,
141 -0.035361374, 1.065690585, -0.030329211, 0.0,
142 0.010390366, -0.299271107, 1.288880741, 0.0,
144 'direction': 'forward'})
146 cs.from_reference_transforms = []
150 def create_colorspaces(lut_directory, lut_resolution_1d):
152 Generates the colorspace conversions.
157 Parameter description.
162 Return value description.
168 c_log_1 = create_c_log(
174 ["canonlog_rec709day"])
175 colorspaces.append(c_log_1)
177 c_log_2 = create_c_log(
183 ["canonlog_rec709tung"])
184 colorspaces.append(c_log_2)
186 c_log_3 = create_c_log(
192 ["canonlog_dcip3day"])
193 colorspaces.append(c_log_3)
195 c_log_4 = create_c_log(
201 ["canonlog_dcip3tung"])
202 colorspaces.append(c_log_4)
204 c_log_5 = create_c_log(
205 'Cinema Gamut Daylight',
210 ["canonlog_cgamutday"])
211 colorspaces.append(c_log_5)
213 c_log_6 = create_c_log(
214 'Cinema Gamut Tungsten',
219 ["canonlog_cgamuttung"])
220 colorspaces.append(c_log_6)
223 c_log_7 = create_c_log(
230 colorspaces.append(c_log_7)
233 c_log_8 = create_c_log(
240 colorspaces.append(c_log_8)
242 c_log_9 = create_c_log(
249 colorspaces.append(c_log_9)
251 c_log_10 = create_c_log(
258 colorspaces.append(c_log_10)
260 c_log_11 = create_c_log(
267 colorspaces.append(c_log_11)
269 c_log_12 = create_c_log(
270 'Cinema Gamut Daylight',
276 colorspaces.append(c_log_12)
278 c_log_13 = create_c_log(
279 'Cinema Gamut Tungsten',
285 colorspaces.append(c_log_13)