2 # -*- coding: utf-8 -*-
5 Implements support for *ARRI* colorspaces conversions and transfer functions.
12 import aces_ocio.generate_lut as genlut
13 from aces_ocio.utilities import ColorSpace, mat44_from_mat33, sanitize_path
16 __author__ = 'ACES Developers'
17 __copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers'
19 __maintainer__ = 'ACES Developers'
20 __email__ = 'aces@oscars.org'
21 __status__ = 'Production'
23 __all__ = ['create_log_c',
27 def create_log_c(gamut,
41 Parameter description.
46 Return value description.
49 name = '%s (EI%s) - %s' % (transfer_function, exposure_index, gamut)
50 if transfer_function == '':
51 name = 'Linear - %s' % gamut
53 name = '%s (EI%s)' % (transfer_function, exposure_index)
57 cs.equality_group = ''
62 IDT_maker_version = '0.08'
65 black_signal = 0.003907
66 mid_gray_signal = 0.01
67 encoding_gain = 0.256598
68 encoding_offset = 0.391007
71 return (math.log(EI / nominal_EI) / math.log(2) * (
72 0.89 - 1) / 3 + 1) * encoding_gain
74 def log_c_inverse_parameters_for_EI(EI):
76 slope = 1.0 / (cut * math.log(10))
77 offset = math.log10(cut) - slope * cut
78 gain = EI / nominal_EI
79 gray = mid_gray_signal / gain
80 # The higher the EI, the lower the gamma
81 enc_gain = gain_for_EI(EI)
82 enc_offset = encoding_offset
84 nz = ((95.0 / 1023.0 - enc_offset) / enc_gain - offset) / slope
85 enc_offset = encoding_offset - math.log10(1 + nz) * enc_gain
86 # Calculate some intermediate values
88 b = nz - black_signal / gray
89 e = slope * a * enc_gain
90 f = enc_gain * (slope * b + offset) + enc_offset
91 # Manipulations so we can return relative exposure
101 'cut': (cut - b) / a,
107 def log_c_to_linear(code_value, exposure_index):
108 p = log_c_inverse_parameters_for_EI(exposure_index)
109 breakpoint = p['e'] * p['cut'] + p['f']
110 if (code_value > breakpoint):
111 linear = ((pow(10, (code_value / 1023.0 - p['d']) / p['c']) -
114 linear = (code_value / 1023.0 - p['f']) / p['e']
116 # print(codeValue, linear)
120 cs.to_reference_transforms = []
122 if transfer_function == 'V3 LogC':
123 data = array.array('f', '\0' * lut_resolution_1d * 4)
124 for c in range(lut_resolution_1d):
125 data[c] = log_c_to_linear(1023.0 * c / (lut_resolution_1d - 1),
128 lut = '%s_to_linear.spi1d' % (
129 '%s_%s' % (transfer_function, exposure_index))
131 lut = sanitize_path(lut)
134 os.path.join(lut_directory, lut),
141 # print('Writing %s' % lut)
142 cs.to_reference_transforms.append({
145 'interpolation': 'linear',
146 'direction': 'forward'
149 if gamut == 'Wide Gamut':
150 cs.to_reference_transforms.append({
152 'matrix': mat44_from_mat33([0.680206, 0.236137, 0.083658,
153 0.085415, 1.017471, -0.102886,
154 0.002057, -0.062563, 1.060506]),
155 'direction': 'forward'
158 cs.from_reference_transforms = []
162 def create_colorspaces(lut_directory, lut_resolution_1d):
164 Generates the colorspace conversions.
169 Parameter description.
174 Return value description.
179 transfer_function = 'V3 LogC'
182 # EIs = [160.0, 200.0, 250.0, 320.0, 400.0, 500.0, 640.0, 800.0,
183 # 1000.0, 1280.0, 1600.0, 2000.0, 2560.0, 3200.0]
184 EIs = [160, 200, 250, 320, 400, 500, 640, 800,
185 1000, 1280, 1600, 2000, 2560, 3200]
190 log_c_EI_full = create_log_c(
197 colorspaces.append(log_c_EI_full)
201 log_c_EI_linearization = create_log_c(
208 colorspaces.append(log_c_EI_linearization)
211 log_c_EI_primaries = create_log_c(
218 colorspaces.append(log_c_EI_primaries)