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,
35 Creates colorspace covering the conversion from CLog to ACES, with various transfer
36 functions and encoding gamuts covered
41 The name of the encoding gamut to use.
42 transfer_function : str
43 The name of the transfer function to use
44 lut_directory : str or unicode
45 The directory to use when generating LUTs
46 lut_resolution_1d : int
47 The resolution of generated 1D LUTs
49 Aliases for this colorspace
54 A ColorSpace container class referencing the LUTs, matrices and identifying
55 information for the requested colorspace.
58 name = '%s - %s' % (transfer_function, gamut)
59 if transfer_function == '':
60 name = 'Linear - Canon %s' % gamut
62 name = 'Curve - %s' % transfer_function
67 cs.equality_group = ''
68 cs.family = 'Input/Canon'
71 # A linear space needs allocation variables.
72 if transfer_function == '':
73 cs.allocation_type = ocio.Constants.ALLOCATION_LG2
74 cs.allocation_vars = [-8, 5, 0.00390625]
76 def legal_to_full(code_value):
77 return (code_value - 64) / (940 - 64)
79 def c_log_to_linear(code_value):
80 # log = fullToLegal(c1 * log10(c2*linear + 1) + c3)
81 # linear = (pow(10, (legalToFul(log) - c3)/c1) - 1)/c2
86 linear = (pow(10, (legal_to_full(code_value) - c3) / c1) - 1) / c2
91 cs.to_reference_transforms = []
93 if transfer_function == 'Canon-Log':
94 data = array.array('f', '\0' * lut_resolution_1d * 4)
95 for c in range(lut_resolution_1d):
96 data[c] = c_log_to_linear(1023 * c / (lut_resolution_1d - 1))
98 lut = '%s_to_linear.spi1d' % transfer_function
100 os.path.join(lut_directory, lut),
107 cs.to_reference_transforms.append({
110 'interpolation': 'linear',
111 'direction': 'forward'})
113 if gamut == 'Rec. 709 Daylight':
114 cs.to_reference_transforms.append({
116 'matrix': [0.561538969, 0.402060105, 0.036400926, 0,
117 0.092739623, 0.924121198, -0.016860821, 0,
118 0.084812961, 0.006373835, 0.908813204, 0,
120 'direction': 'forward'})
121 elif gamut == 'Rec. 709 Tungsten':
122 cs.to_reference_transforms.append({
124 'matrix': [0.566996399, 0.365079418, 0.067924183, 0,
125 0.070901044, 0.880331008, 0.048767948, 0,
126 0.073013542, -0.066540862, 0.99352732, 0,
128 'direction': 'forward'})
129 elif gamut == 'DCI-P3 Daylight':
130 cs.to_reference_transforms.append({
132 'matrix': [0.607160575, 0.299507286, 0.093332140, 0,
133 0.004968120, 1.050982224, -0.055950343, 0,
134 -0.007839939, 0.000809127, 1.007030813, 0,
136 'direction': 'forward'})
137 elif gamut == 'DCI-P3 Tungsten':
138 cs.to_reference_transforms.append({
140 'matrix': [0.650279125, 0.253880169, 0.095840706, 0,
141 -0.026137986, 1.017900530, 0.008237456, 0,
142 0.007757558, -0.063081669, 1.055324110, 0,
144 'direction': 'forward'})
145 elif gamut == 'Cinema Gamut Daylight':
146 cs.to_reference_transforms.append({
148 'matrix': [0.763064455, 0.149021161, 0.087914384, 0,
149 0.003657457, 1.10696038, -0.110617837, 0,
150 -0.009407794, -0.218383305, 1.227791099, 0,
152 'direction': 'forward'})
153 elif gamut == 'Cinema Gamut Tungsten':
154 cs.to_reference_transforms.append({
156 'matrix': [0.817416293, 0.090755698, 0.091828009, 0,
157 -0.035361374, 1.065690585, -0.030329211, 0,
158 0.010390366, -0.299271107, 1.288880741, 0,
160 'direction': 'forward'})
162 cs.from_reference_transforms = []
166 def create_colorspaces(lut_directory, lut_resolution_1d):
168 Generates the colorspace conversions.
172 lut_directory : str or unicode
173 The directory to use when generating LUTs
174 lut_resolution_1d : int
175 The resolution of generated 1D LUTs
180 A list of colorspaces for Canon cameras and encodings
186 c_log_1 = create_c_log(
191 ['canonlog_rec709day'])
192 colorspaces.append(c_log_1)
194 c_log_2 = create_c_log(
199 ['canonlog_rec709tung'])
200 colorspaces.append(c_log_2)
202 c_log_3 = create_c_log(
207 ['canonlog_dcip3day'])
208 colorspaces.append(c_log_3)
210 c_log_4 = create_c_log(
215 ['canonlog_dcip3tung'])
216 colorspaces.append(c_log_4)
218 c_log_5 = create_c_log(
219 'Cinema Gamut Daylight',
223 ['canonlog_cgamutday'])
224 colorspaces.append(c_log_5)
226 c_log_6 = create_c_log(
227 'Cinema Gamut Tungsten',
231 ['canonlog_cgamuttung'])
232 colorspaces.append(c_log_6)
235 c_log_7 = create_c_log(
241 colorspaces.append(c_log_7)
244 c_log_8 = create_c_log(
249 ['lin_canonrec709day'])
250 colorspaces.append(c_log_8)
252 c_log_9 = create_c_log(
257 ['lin_canonrec709tung'])
258 colorspaces.append(c_log_9)
260 c_log_10 = create_c_log(
265 ['lin_canondcip3day'])
266 colorspaces.append(c_log_10)
268 c_log_11 = create_c_log(
273 ['lin_canondcip3tung'])
274 colorspaces.append(c_log_11)
276 c_log_12 = create_c_log(
277 'Cinema Gamut Daylight',
281 ['lin_canoncgamutday'])
282 colorspaces.append(c_log_12)
284 c_log_13 = create_c_log(
285 'Cinema Gamut Tungsten',
289 ['lin_canoncgamuttung'])
290 colorspaces.append(c_log_13)