2 # -*- coding: utf-8 -*-
5 Implements support for *ARRI* colorspaces conversions and transfer functions.
8 from __future__ import division
14 import PyOpenColorIO as ocio
16 import aces_ocio.generate_lut as genlut
17 from aces_ocio.utilities import ColorSpace, mat44_from_mat33, sanitize
20 __author__ = 'ACES Developers'
21 __copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers'
23 __maintainer__ = 'ACES Developers'
24 __email__ = 'aces@oscars.org'
25 __status__ = 'Production'
27 __all__ = ['create_log_c',
31 def create_log_c(gamut,
46 Parameter description.
51 Return value description.
54 name = '%s (EI%s) - %s' % (transfer_function, exposure_index, gamut)
55 if transfer_function == '':
56 name = 'Linear - ARRI %s' % gamut
58 name = '%s (EI%s)' % (transfer_function, exposure_index)
63 cs.equality_group = ''
64 cs.family = 'Input/ARRI'
67 # A linear space needs allocation variables
68 if transfer_function == '':
69 cs.allocation_type = ocio.Constants.ALLOCATION_LG2
70 cs.allocation_vars = [-8, 5, 0.00390625]
73 IDT_maker_version = '0.08'
76 black_signal = 0.003907
77 mid_gray_signal = 0.01
78 encoding_gain = 0.256598
79 encoding_offset = 0.391007
82 return (math.log(EI / nominal_EI) / math.log(2) * (
83 0.89 - 1) / 3 + 1) * encoding_gain
85 def log_c_inverse_parameters_for_EI(EI):
87 slope = 1 / (cut * math.log(10))
88 offset = math.log10(cut) - slope * cut
89 gain = EI / nominal_EI
90 gray = mid_gray_signal / gain
91 # The higher the EI, the lower the gamma.
92 enc_gain = gain_for_EI(EI)
93 enc_offset = encoding_offset
95 nz = ((95 / 1023 - enc_offset) / enc_gain - offset) / slope
96 enc_offset = encoding_offset - math.log10(1 + nz) * enc_gain
99 b = nz - black_signal / gray
100 e = slope * a * enc_gain
101 f = enc_gain * (slope * b + offset) + enc_offset
103 # Ensuring we can return relative exposure.
113 'cut': (cut - b) / a,
119 def log_c_to_linear(code_value, exposure_index):
120 p = log_c_inverse_parameters_for_EI(exposure_index)
121 breakpoint = p['e'] * p['cut'] + p['f']
122 if code_value > breakpoint:
123 linear = ((pow(10, (code_value / 1023 - p['d']) / p['c']) -
126 linear = (code_value / 1023 - p['f']) / p['e']
129 cs.to_reference_transforms = []
131 if transfer_function == 'V3 LogC':
132 data = array.array('f', '\0' * lut_resolution_1d * 4)
133 for c in range(lut_resolution_1d):
134 data[c] = log_c_to_linear(1023 * c / (lut_resolution_1d - 1),
137 lut = '%s_to_linear.spi1d' % (
138 '%s_%s' % (transfer_function, exposure_index))
143 os.path.join(lut_directory, lut),
150 cs.to_reference_transforms.append({
153 'interpolation': 'linear',
154 'direction': 'forward'
157 if gamut == 'Wide Gamut':
158 cs.to_reference_transforms.append({
160 'matrix': mat44_from_mat33([0.680206, 0.236137, 0.083658,
161 0.085415, 1.017471, -0.102886,
162 0.002057, -0.062563, 1.060506]),
163 'direction': 'forward'
166 cs.from_reference_transforms = []
170 def create_colorspaces(lut_directory, lut_resolution_1d):
172 Generates the colorspace conversions.
177 Parameter description.
182 Return value description.
187 transfer_function = 'V3 LogC'
190 # EIs = [160, 200, 250, 320, 400, 500, 640, 800,
191 # 1000, 1280, 1600, 2000, 2560, 3200]
192 EIs = [160, 200, 250, 320, 400, 500, 640, 800,
193 1000, 1280, 1600, 2000, 2560, 3200]
198 log_c_EI_full = create_log_c(
205 ["%sei%s_%s" % ("logc3", str(EI), "arriwide")])
206 colorspaces.append(log_c_EI_full)
210 log_c_EI_linearization = create_log_c(
217 ["crv_%sei%s" % ("logc3", str(EI))])
218 colorspaces.append(log_c_EI_linearization)
221 log_c_EI_primaries = create_log_c(
228 ["%s_%s" % ('lin', "arriwide")])
229 colorspaces.append(log_c_EI_primaries)