2 # -*- coding: utf-8 -*-
5 Implements support for *Canon* colorspaces conversions and transfer functions.
8 from __future__ import division
13 import PyOpenColorIO as ocio
15 import aces_ocio.generate_lut as genlut
16 from aces_ocio.utilities import ColorSpace
18 __author__ = 'ACES Developers'
19 __copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers'
21 __maintainer__ = 'ACES Developers'
22 __email__ = 'aces@oscars.org'
23 __status__ = 'Production'
25 __all__ = ['create_c_log',
29 def create_c_log(gamut,
43 Parameter description.
48 Return value description.
51 name = '%s - %s' % (transfer_function, gamut)
52 if transfer_function == '':
53 name = 'Linear - %s' % gamut
55 name = '%s' % transfer_function
60 cs.equality_group = ''
64 # A linear space needs allocation variables
65 if transfer_function == '':
66 cs.allocation_type = ocio.Constants.ALLOCATION_LG2
67 cs.allocation_vars = [-8, 5, 0.00390625]
69 def legal_to_full(code_value):
70 return (code_value - 64) / (940 - 64)
72 def c_log_to_linear(code_value):
73 # log = fullToLegal(c1 * log10(c2*linear + 1) + c3)
74 # linear = (pow(10, (legalToFul(log) - c3)/c1) - 1)/c2
79 linear = (pow(10, (legal_to_full(code_value) - c3) / c1) - 1) / c2
84 cs.to_reference_transforms = []
86 if transfer_function == 'Canon-Log':
87 data = array.array('f', '\0' * lut_resolution_1d * 4)
88 for c in range(lut_resolution_1d):
89 data[c] = c_log_to_linear(1023 * c / (lut_resolution_1d - 1))
91 lut = '%s_to_linear.spi1d' % transfer_function
93 os.path.join(lut_directory, lut),
100 cs.to_reference_transforms.append({
103 'interpolation': 'linear',
104 'direction': 'forward'})
106 if gamut == 'Rec. 709 Daylight':
107 cs.to_reference_transforms.append({
109 'matrix': [0.561538969, 0.402060105, 0.036400926, 0,
110 0.092739623, 0.924121198, -0.016860821, 0,
111 0.084812961, 0.006373835, 0.908813204, 0,
113 'direction': 'forward'})
114 elif gamut == 'Rec. 709 Tungsten':
115 cs.to_reference_transforms.append({
117 'matrix': [0.566996399, 0.365079418, 0.067924183, 0,
118 0.070901044, 0.880331008, 0.048767948, 0,
119 0.073013542, -0.066540862, 0.99352732, 0,
121 'direction': 'forward'})
122 elif gamut == 'DCI-P3 Daylight':
123 cs.to_reference_transforms.append({
125 'matrix': [0.607160575, 0.299507286, 0.093332140, 0,
126 0.004968120, 1.050982224, -0.055950343, 0,
127 -0.007839939, 0.000809127, 1.007030813, 0,
129 'direction': 'forward'})
130 elif gamut == 'DCI-P3 Tungsten':
131 cs.to_reference_transforms.append({
133 'matrix': [0.650279125, 0.253880169, 0.095840706, 0,
134 -0.026137986, 1.017900530, 0.008237456, 0,
135 0.007757558, -0.063081669, 1.055324110, 0,
137 'direction': 'forward'})
138 elif gamut == 'Cinema Gamut Daylight':
139 cs.to_reference_transforms.append({
141 'matrix': [0.763064455, 0.149021161, 0.087914384, 0,
142 0.003657457, 1.10696038, -0.110617837, 0,
143 -0.009407794, -0.218383305, 1.227791099, 0,
145 'direction': 'forward'})
146 elif gamut == 'Cinema Gamut Tungsten':
147 cs.to_reference_transforms.append({
149 'matrix': [0.817416293, 0.090755698, 0.091828009, 0,
150 -0.035361374, 1.065690585, -0.030329211, 0,
151 0.010390366, -0.299271107, 1.288880741, 0,
153 'direction': 'forward'})
155 cs.from_reference_transforms = []
159 def create_colorspaces(lut_directory, lut_resolution_1d):
161 Generates the colorspace conversions.
166 Parameter description.
171 Return value description.
177 c_log_1 = create_c_log(
183 ["canonlog_rec709day"])
184 colorspaces.append(c_log_1)
186 c_log_2 = create_c_log(
192 ["canonlog_rec709tung"])
193 colorspaces.append(c_log_2)
195 c_log_3 = create_c_log(
201 ["canonlog_dcip3day"])
202 colorspaces.append(c_log_3)
204 c_log_4 = create_c_log(
210 ["canonlog_dcip3tung"])
211 colorspaces.append(c_log_4)
213 c_log_5 = create_c_log(
214 'Cinema Gamut Daylight',
219 ["canonlog_cgamutday"])
220 colorspaces.append(c_log_5)
222 c_log_6 = create_c_log(
223 'Cinema Gamut Tungsten',
228 ["canonlog_cgamuttung"])
229 colorspaces.append(c_log_6)
232 c_log_7 = create_c_log(
239 colorspaces.append(c_log_7)
242 c_log_8 = create_c_log(
249 colorspaces.append(c_log_8)
251 c_log_9 = create_c_log(
258 colorspaces.append(c_log_9)
260 c_log_10 = create_c_log(
267 colorspaces.append(c_log_10)
269 c_log_11 = create_c_log(
276 colorspaces.append(c_log_11)
278 c_log_12 = create_c_log(
279 'Cinema Gamut Daylight',
285 colorspaces.append(c_log_12)
287 c_log_13 = create_c_log(
288 'Cinema Gamut Tungsten',
294 colorspaces.append(c_log_13)