2 # -*- coding: utf-8 -*-
5 Implements support for *ARRI* colorspaces conversions and transfer functions.
8 from __future__ import division
14 import aces_ocio.generate_lut as genlut
15 from aces_ocio.utilities import ColorSpace, mat44_from_mat33, sanitize
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_log_c',
29 def create_log_c(gamut,
44 Parameter description.
49 Return value description.
52 name = '%s (EI%s) - %s' % (transfer_function, exposure_index, gamut)
53 if transfer_function == '':
54 name = 'Linear - %s' % gamut
56 name = '%s (EI%s)' % (transfer_function, exposure_index)
61 cs.equality_group = ''
66 IDT_maker_version = '0.08'
69 black_signal = 0.003907
70 mid_gray_signal = 0.01
71 encoding_gain = 0.256598
72 encoding_offset = 0.391007
75 return (math.log(EI / nominal_EI) / math.log(2) * (
76 0.89 - 1) / 3 + 1) * encoding_gain
78 def log_c_inverse_parameters_for_EI(EI):
80 slope = 1 / (cut * math.log(10))
81 offset = math.log10(cut) - slope * cut
82 gain = EI / nominal_EI
83 gray = mid_gray_signal / gain
84 # The higher the EI, the lower the gamma.
85 enc_gain = gain_for_EI(EI)
86 enc_offset = encoding_offset
88 nz = ((95 / 1023 - enc_offset) / enc_gain - offset) / slope
89 enc_offset = encoding_offset - math.log10(1 + nz) * enc_gain
92 b = nz - black_signal / gray
93 e = slope * a * enc_gain
94 f = enc_gain * (slope * b + offset) + enc_offset
96 # Ensuring we can return relative exposure.
106 'cut': (cut - b) / a,
112 def log_c_to_linear(code_value, exposure_index):
113 p = log_c_inverse_parameters_for_EI(exposure_index)
114 breakpoint = p['e'] * p['cut'] + p['f']
115 if code_value > breakpoint:
116 linear = ((pow(10, (code_value / 1023 - p['d']) / p['c']) -
119 linear = (code_value / 1023 - p['f']) / p['e']
122 cs.to_reference_transforms = []
124 if transfer_function == 'V3 LogC':
125 data = array.array('f', '\0' * lut_resolution_1d * 4)
126 for c in range(lut_resolution_1d):
127 data[c] = log_c_to_linear(1023 * c / (lut_resolution_1d - 1),
130 lut = '%s_to_linear.spi1d' % (
131 '%s_%s' % (transfer_function, exposure_index))
136 os.path.join(lut_directory, lut),
143 cs.to_reference_transforms.append({
146 'interpolation': 'linear',
147 'direction': 'forward'
150 if gamut == 'Wide Gamut':
151 cs.to_reference_transforms.append({
153 'matrix': mat44_from_mat33([0.680206, 0.236137, 0.083658,
154 0.085415, 1.017471, -0.102886,
155 0.002057, -0.062563, 1.060506]),
156 'direction': 'forward'
159 cs.from_reference_transforms = []
163 def create_colorspaces(lut_directory, lut_resolution_1d):
165 Generates the colorspace conversions.
170 Parameter description.
175 Return value description.
180 transfer_function = 'V3 LogC'
183 # EIs = [160, 200, 250, 320, 400, 500, 640, 800,
184 # 1000, 1280, 1600, 2000, 2560, 3200]
185 EIs = [160, 200, 250, 320, 400, 500, 640, 800,
186 1000, 1280, 1600, 2000, 2560, 3200]
191 log_c_EI_full = create_log_c(
198 ["%sei%s_%s" % ("logc3", str(EI), "arriwide")])
199 colorspaces.append(log_c_EI_full)
203 log_c_EI_linearization = create_log_c(
210 ["crv_%sei%s" % ("logc3", str(EI))])
211 colorspaces.append(log_c_EI_linearization)
214 log_c_EI_primaries = create_log_c(
221 ["%s_%s" % ('lin', "arriwide")])
222 colorspaces.append(log_c_EI_primaries)