2 # -*- coding: utf-8 -*-
5 Implements support for *RED* 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, mat44_from_mat33
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_red_log_film',
29 def create_red_log_film(gamut,
35 Creates colorspace covering the conversion from RED spaces to ACES, with various
36 transfer 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.
61 name = '%s - %s' % (transfer_function, gamut)
62 if transfer_function == '':
63 name = 'Linear - %s' % gamut
65 name = 'Curve - %s' % transfer_function
70 cs.equality_group = ''
71 cs.family = 'Input/RED'
74 # A linear space needs allocation variables
75 if transfer_function == '':
76 cs.allocation_type = ocio.Constants.ALLOCATION_LG2
77 cs.allocation_vars = [-8, 5, 0.00390625]
79 def cineon_to_linear(code_value):
83 code_value_to_density = 0.002
85 black_linear = pow(10, (black_point - white_point) * (
86 code_value_to_density / n_gamma))
87 code_linear = pow(10, (code_value - white_point) * (
88 code_value_to_density / n_gamma))
90 return (code_linear - black_linear) / (1 - black_linear)
92 cs.to_reference_transforms = []
94 if transfer_function == 'REDlogFilm':
95 data = array.array('f', '\0' * lut_resolution_1d * 4)
96 for c in range(lut_resolution_1d):
97 data[c] = cineon_to_linear(1023 * c / (lut_resolution_1d - 1))
99 lut = 'CineonLog_to_linear.spi1d'
101 os.path.join(lut_directory, lut),
108 cs.to_reference_transforms.append({
111 'interpolation': 'linear',
112 'direction': 'forward'})
114 if gamut == 'DRAGONcolor':
115 cs.to_reference_transforms.append({
117 'matrix': mat44_from_mat33([0.532279, 0.376648, 0.091073,
118 0.046344, 0.974513, -0.020860,
119 -0.053976, -0.000320, 1.054267]),
120 'direction': 'forward'})
121 elif gamut == 'DRAGONcolor2':
122 cs.to_reference_transforms.append({
124 'matrix': mat44_from_mat33([0.468452, 0.331484, 0.200064,
125 0.040787, 0.857658, 0.101553,
126 -0.047504, -0.000282, 1.047756]),
127 'direction': 'forward'})
128 elif gamut == 'REDcolor':
129 cs.to_reference_transforms.append({
131 'matrix': mat44_from_mat33([0.451464, 0.388498, 0.160038,
132 0.062716, 0.866790, 0.070491,
133 -0.017541, 0.086921, 0.930590]),
134 'direction': 'forward'})
135 elif gamut == 'REDcolor2':
136 cs.to_reference_transforms.append({
138 'matrix': mat44_from_mat33([0.480997, 0.402289, 0.116714,
139 -0.004938, 1.000154, 0.004781,
140 -0.105257, 0.025320, 1.079907]),
141 'direction': 'forward'})
142 elif gamut == 'REDcolor3':
143 cs.to_reference_transforms.append({
145 'matrix': mat44_from_mat33([0.512136, 0.360370, 0.127494,
146 0.070377, 0.903884, 0.025737,
147 -0.020824, 0.017671, 1.003123]),
148 'direction': 'forward'})
149 elif gamut == 'REDcolor4':
150 cs.to_reference_transforms.append({
152 'matrix': mat44_from_mat33([0.474202, 0.333677, 0.192121,
153 0.065164, 0.836932, 0.097901,
154 -0.019281, 0.016362, 1.002889]),
155 'direction': 'forward'})
157 cs.from_reference_transforms = []
161 def create_colorspaces(lut_directory, lut_resolution_1d):
163 Generates the colorspace conversions.
167 lut_directory : str or unicode
168 The directory to use when generating LUTs
169 lut_resolution_1d : int
170 The resolution of generated 1D LUTs
175 A list of colorspaces for RED cameras and encodings
181 red_log_film_dragon = create_red_log_film(
187 colorspaces.append(red_log_film_dragon)
189 red_log_film_dragon2 = create_red_log_film(
195 colorspaces.append(red_log_film_dragon2)
197 red_log_film_color = create_red_log_film(
203 colorspaces.append(red_log_film_color)
205 red_log_film_color2 = create_red_log_film(
211 colorspaces.append(red_log_film_color2)
213 red_log_film_color3 = create_red_log_film(
219 colorspaces.append(red_log_film_color3)
221 red_log_film_color4 = create_red_log_film(
227 colorspaces.append(red_log_film_color4)
230 red_log_film = create_red_log_film(
236 colorspaces.append(red_log_film)
239 red_dragon = create_red_log_film(
245 colorspaces.append(red_dragon)
247 red_dragon2 = create_red_log_film(
253 colorspaces.append(red_dragon2)
255 red_color = create_red_log_film(
261 colorspaces.append(red_color)
263 red_color2 = create_red_log_film(
269 colorspaces.append(red_color2)
271 red_color3 = create_red_log_film(
277 colorspaces.append(red_color3)
279 red_color4 = create_red_log_film(
285 colorspaces.append(red_color4)