2 # -*- coding: utf-8 -*-
5 Defines objects creating the *ACES* configuration.
16 # TODO: This restores the capability of running the script without having
17 # added the package to PYTHONPATH, this is ugly and should ideally replaced by
18 # dedicated executable in a /bin directory.
19 sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
21 import PyOpenColorIO as ocio
23 import aces_ocio.create_arri_colorspaces as arri
24 import aces_ocio.create_canon_colorspaces as canon
25 import aces_ocio.create_red_colorspaces as red
26 import aces_ocio.create_sony_colorspaces as sony
27 from aces_ocio.generate_lut import (
28 generate_1d_LUT_from_CTL,
29 generate_3d_LUT_from_CTL,
31 from aces_ocio.process import Process
32 from aces_ocio.utilities import ColorSpace, mat44_from_mat33, sanitize_path
34 __author__ = 'ACES Developers'
35 __copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers'
37 __maintainer__ = 'ACES Developers'
38 __email__ = 'aces@oscars.org'
39 __status__ = 'Production'
41 __all__ = ['ACES_OCIO_CTL_DIRECTORY_ENVIRON',
42 'ACES_OCIO_CONFIGURATION_DIRECTORY_ENVIRON',
43 'set_config_default_roles',
45 'generate_OCIO_transform',
48 'generate_baked_LUTs',
56 ACES_OCIO_CTL_DIRECTORY_ENVIRON = 'ACES_OCIO_CTL_DIRECTORY'
57 ACES_OCIO_CONFIGURATION_DIRECTORY_ENVIRON = 'ACES_OCIO_CONFIGURATION_DIRECTORY'
60 def set_config_default_roles(config,
71 Sets given *OCIO* configuration default roles.
77 color_picking : str or unicode
78 Color picking role title.
79 color_timing : str or unicode
80 Color timing role title.
81 compositing_log : str or unicode
82 Compositing log role title.
85 default : str or unicode
87 matte_paint : str or unicode
88 Matte painting role title.
89 reference : str or unicode
91 scene_linear : str or unicode
92 Scene linear role title.
93 texture_paint : str or unicode
94 Texture painting role title.
103 config.setRole(ocio.Constants.ROLE_COLOR_PICKING, color_picking)
105 config.setRole(ocio.Constants.ROLE_COLOR_TIMING, color_timing)
107 config.setRole(ocio.Constants.ROLE_COMPOSITING_LOG, compositing_log)
109 config.setRole(ocio.Constants.ROLE_DATA, data)
111 config.setRole(ocio.Constants.ROLE_DEFAULT, default)
113 config.setRole(ocio.Constants.ROLE_MATTE_PAINT, matte_paint)
115 config.setRole(ocio.Constants.ROLE_REFERENCE, reference)
117 config.setRole(ocio.Constants.ROLE_SCENE_LINEAR, scene_linear)
119 config.setRole(ocio.Constants.ROLE_TEXTURE_PAINT, texture_paint)
124 def write_config(config, config_path, sanity_check=True):
126 Writes the configuration to given path.
131 Parameter description.
136 Return value description.
144 print 'Configuration was not written due to a failed Sanity Check'
148 with open(config_path, mode='w') as fp:
149 fp.write(config.serialize())
152 def generate_OCIO_transform(transforms):
159 Parameter description.
164 Return value description.
167 # print('Generating transforms')
169 interpolation_options = {
170 'linear': ocio.Constants.INTERP_LINEAR,
171 'nearest': ocio.Constants.INTERP_NEAREST,
172 'tetrahedral': ocio.Constants.INTERP_TETRAHEDRAL
174 direction_options = {
175 'forward': ocio.Constants.TRANSFORM_DIR_FORWARD,
176 'inverse': ocio.Constants.TRANSFORM_DIR_INVERSE
181 for transform in transforms:
182 if transform['type'] == 'lutFile':
183 ocio_transform = ocio.FileTransform(
184 src=transform['path'],
185 interpolation=interpolation_options[
186 transform['interpolation']],
187 direction=direction_options[transform['direction']])
188 ocio_transforms.append(ocio_transform)
189 elif transform['type'] == 'matrix':
190 ocio_transform = ocio.MatrixTransform()
191 # MatrixTransform member variables can't be initialized directly.
192 # Each must be set individually.
193 ocio_transform.setMatrix(transform['matrix'])
195 if 'offset' in transform:
196 ocio_transform.setOffset(transform['offset'])
198 if 'direction' in transform:
199 ocio_transform.setDirection(
200 direction_options[transform['direction']])
202 ocio_transforms.append(ocio_transform)
203 elif transform['type'] == 'exponent':
204 ocio_transform = ocio.ExponentTransform()
205 ocio_transform.setValue(transform['value'])
206 ocio_transforms.append(ocio_transform)
207 elif transform['type'] == 'log':
208 ocio_transform = ocio.LogTransform(
209 base=transform['base'],
210 direction=direction_options[transform['direction']])
212 ocio_transforms.append(ocio_transform)
214 print('Ignoring unknown transform type : %s' % transform['type'])
216 # Build a group transform if necessary
217 if len(ocio_transforms) > 1:
218 transform_G = ocio.GroupTransform()
219 for transform in ocio_transforms:
220 transform_G.push_back(transform)
221 transform = transform_G
223 # Or take the first transform from the list
225 transform = ocio_transforms[0]
230 def create_config(config_data, nuke=False):
237 Parameter description.
242 Return value description.
246 config = ocio.Config()
249 # Set config wide values
251 config.setDescription('An ACES config generated from python')
252 config.setSearchPath('luts')
255 # Define the reference color space
257 reference_data = config_data['referenceColorSpace']
258 print('Adding the reference color space : %s' % reference_data.name)
260 # Create a color space
261 reference = ocio.ColorSpace(
262 name=reference_data.name,
263 bitDepth=reference_data.bit_depth,
264 description=reference_data.description,
265 equalityGroup=reference_data.equality_group,
266 family=reference_data.family,
267 isData=reference_data.is_data,
268 allocation=reference_data.allocation_type,
269 allocationVars=reference_data.allocation_vars)
272 config.addColorSpace(reference)
275 # Create the rest of the color spaces
277 for colorspace in sorted(config_data['colorSpaces']):
278 print('Creating new color space : %s' % colorspace.name)
280 ocio_colorspace = ocio.ColorSpace(
281 name=colorspace.name,
282 bitDepth=colorspace.bit_depth,
283 description=colorspace.description,
284 equalityGroup=colorspace.equality_group,
285 family=colorspace.family,
286 isData=colorspace.is_data,
287 allocation=colorspace.allocation_type,
288 allocationVars=colorspace.allocation_vars)
290 if colorspace.to_reference_transforms != []:
291 print('Generating To-Reference transforms')
292 ocio_transform = generate_OCIO_transform(
293 colorspace.to_reference_transforms)
294 ocio_colorspace.setTransform(
296 ocio.Constants.COLORSPACE_DIR_TO_REFERENCE)
298 if colorspace.from_reference_transforms != []:
299 print('Generating From-Reference transforms')
300 ocio_transform = generate_OCIO_transform(
301 colorspace.from_reference_transforms)
302 ocio_colorspace.setTransform(
304 ocio.Constants.COLORSPACE_DIR_FROM_REFERENCE)
306 config.addColorSpace(ocio_colorspace)
311 # Define the views and displays
316 # Generic display and view setup
318 for display, view_list in config_data['displays'].iteritems():
319 for view_name, colorspace in view_list.iteritems():
320 config.addDisplay(display, view_name, colorspace.name)
321 if not (view_name in views):
322 views.append(view_name)
323 displays.append(display)
324 # A Nuke specific set of views and displays
327 # A few names: Output Transform, ACES, ACEScc, are hard-coded here.
328 # Would be better to automate.
331 for display, view_list in config_data['displays'].iteritems():
332 for view_name, colorspace in view_list.iteritems():
333 if (view_name == 'Output Transform'):
335 config.addDisplay(display, view_name, colorspace.name)
336 if not (view_name in views):
337 views.append(view_name)
338 displays.append(display)
340 config.addDisplay('linear', 'View', 'ACES2065-1')
341 displays.append('linear')
342 config.addDisplay('log', 'View', 'ACEScc')
343 displays.append('log')
345 # Set active displays and views
346 config.setActiveDisplays(','.join(sorted(displays)))
347 config.setActiveViews(','.join(views))
350 # Need to generalize this at some point
354 set_config_default_roles(
356 color_picking=reference.getName(),
357 color_timing=reference.getName(),
358 compositing_log=reference.getName(),
359 data=reference.getName(),
360 default=reference.getName(),
361 matte_paint=reference.getName(),
362 reference=reference.getName(),
363 scene_linear=reference.getName(),
364 texture_paint=reference.getName())
366 # Check to make sure we didn't screw something up
372 def generate_LUTs(odt_info,
377 lut_resolution_1d=4096,
378 lut_resolution_3d=64,
386 Parameter description.
391 Colorspaces and transforms converting between those colorspaces and
392 the reference colorspace, *ACES*.
395 print('generateLUTs - begin')
399 # Define the reference color space
401 ACES = ColorSpace('ACES2065-1')
403 'The Academy Color Encoding System reference color space')
404 ACES.equality_group = ''
407 ACES.allocation_type = ocio.Constants.ALLOCATION_LG2
408 ACES.allocation_vars = [-15, 6]
410 config_data['referenceColorSpace'] = ACES
413 # Define the displays
415 config_data['displays'] = {}
418 # Define the other color spaces
420 config_data['colorSpaces'] = []
422 # Matrix converting ACES AP1 primaries to AP0
423 ACES_AP1_to_AP0 = [0.6954522414, 0.1406786965, 0.1638690622,
424 0.0447945634, 0.8596711185, 0.0955343182,
425 -0.0055258826, 0.0040252103, 1.0015006723]
427 # Matrix converting ACES AP0 primaries to XYZ
428 ACES_AP0_to_XYZ = [0.9525523959, 0.0000000000, 0.0000936786,
429 0.3439664498, 0.7281660966, -0.0721325464,
430 0.0000000000, 0.0000000000, 1.0088251844]
435 def create_ACEScc(name='ACEScc',
439 cs = ColorSpace(name)
440 cs.description = 'The %s color space' % name
441 cs.equality_group = ''
445 ctls = [os.path.join(aces_CTL_directory,
447 'ACEScsc.ACEScc_to_ACES.a1.0.0.ctl'),
448 # This transform gets back to the AP1 primaries
449 # Useful as the 1d LUT is only covering the transfer function
450 # The primaries switch is covered by the matrix below
451 os.path.join(aces_CTL_directory,
453 'ACEScsc.ACES_to_ACEScg.a1.0.0.ctl')]
454 lut = '%s_to_ACES.spi1d' % name
456 lut = sanitize_path(lut)
458 generate_1d_LUT_from_CTL(
459 os.path.join(lut_directory, lut),
471 cs.to_reference_transforms = []
472 cs.to_reference_transforms.append({
475 'interpolation': 'linear',
476 'direction': 'forward'
479 # AP1 primaries to AP0 primaries
480 cs.to_reference_transforms.append({
482 'matrix': mat44_from_mat33(ACES_AP1_to_AP0),
483 'direction': 'forward'
486 cs.from_reference_transforms = []
489 ACEScc = create_ACEScc()
490 config_data['colorSpaces'].append(ACEScc)
495 def create_ACESproxy(name='ACESproxy'):
496 cs = ColorSpace(name)
497 cs.description = 'The %s color space' % name
498 cs.equality_group = ''
503 os.path.join(aces_CTL_directory,
505 'ACEScsc.ACESproxy10i_to_ACES.a1.0.0.ctl'),
506 # This transform gets back to the AP1 primaries
507 # Useful as the 1d LUT is only covering the transfer function
508 # The primaries switch is covered by the matrix below
509 os.path.join(aces_CTL_directory,
511 'ACEScsc.ACES_to_ACEScg.a1.0.0.ctl')]
512 lut = '%s_to_aces.spi1d' % name
514 lut = sanitize_path(lut)
516 generate_1d_LUT_from_CTL(
517 os.path.join(lut_directory, lut),
527 cs.to_reference_transforms = []
528 cs.to_reference_transforms.append({
531 'interpolation': 'linear',
532 'direction': 'forward'
535 # AP1 primaries to AP0 primaries
536 cs.to_reference_transforms.append({
538 'matrix': mat44_from_mat33(ACES_AP1_to_AP0),
539 'direction': 'forward'
542 cs.from_reference_transforms = []
545 ACESproxy = create_ACESproxy()
546 config_data['colorSpaces'].append(ACESproxy)
551 def create_ACEScg(name='ACEScg'):
552 cs = ColorSpace(name)
553 cs.description = 'The %s color space' % name
554 cs.equality_group = ''
558 cs.to_reference_transforms = []
560 # AP1 primaries to AP0 primaries
561 cs.to_reference_transforms.append({
563 'matrix': mat44_from_mat33(ACES_AP1_to_AP0),
564 'direction': 'forward'
567 cs.from_reference_transforms = []
570 ACEScg = create_ACEScg()
571 config_data['colorSpaces'].append(ACEScg)
576 def create_ADX(bit_depth=10, name='ADX'):
577 name = '%s%s' % (name, bit_depth)
578 cs = ColorSpace(name)
579 cs.description = '%s color space - used for film scans' % name
580 cs.equality_group = ''
585 cs.bit_depth = bit_depth = ocio.Constants.BIT_DEPTH_UINT10
586 adx_to_cdd = [1023.0 / 500.0, 0.0, 0.0, 0.0,
587 0.0, 1023.0 / 500.0, 0.0, 0.0,
588 0.0, 0.0, 1023.0 / 500.0, 0.0,
590 offset = [-95.0 / 500.0, -95.0 / 500.0, -95.0 / 500.0, 0.0]
591 elif bit_depth == 16:
592 cs.bit_depth = bit_depth = ocio.Constants.BIT_DEPTH_UINT16
593 adx_to_cdd = [65535.0 / 8000.0, 0.0, 0.0, 0.0,
594 0.0, 65535.0 / 8000.0, 0.0, 0.0,
595 0.0, 0.0, 65535.0 / 8000.0, 0.0,
597 offset = [-1520.0 / 8000.0, -1520.0 / 8000.0, -1520.0 / 8000.0,
600 cs.to_reference_transforms = []
602 # Convert from ADX to Channel-Dependent Density
603 cs.to_reference_transforms.append({
605 'matrix': adx_to_cdd,
607 'direction': 'forward'
610 # Convert from Channel-Dependent Density to Channel-Independent Density
611 cs.to_reference_transforms.append({
613 'matrix': [0.75573, 0.22197, 0.02230, 0,
614 0.05901, 0.96928, -0.02829, 0,
615 0.16134, 0.07406, 0.76460, 0,
617 'direction': 'forward'
620 # Copied from Alex Fry's adx_cid_to_rle.py
621 def create_CID_to_RLE_LUT():
622 def interpolate_1D(x, xp, fp):
623 return numpy.interp(x, xp, fp)
625 LUT_1D_xp = [-0.190000000000000,
637 LUT_1D_fp = [-6.000000000000000,
649 REF_PT = ((7120.0 - 1520.0) / 8000.0 * (100.0 / 55.0) -
650 math.log(0.18, 10.0))
654 return interpolate_1D(x, LUT_1D_xp, LUT_1D_fp)
655 return (100.0 / 55.0) * x - REF_PT
657 def fit(value, from_min, from_max, to_min, to_max):
658 if from_min == from_max:
659 raise ValueError('from_min == from_max')
660 return (value - from_min) / (from_max - from_min) * (
661 to_max - to_min) + to_min
663 NUM_SAMPLES = 2 ** 12
666 for i in xrange(NUM_SAMPLES):
667 x = i / (NUM_SAMPLES - 1.0)
668 x = fit(x, 0.0, 1.0, RANGE[0], RANGE[1])
669 data.append(cid_to_rle(x))
671 lut = 'ADX_CID_to_RLE.spi1d'
672 write_SPI_1d(os.path.join(lut_directory, lut),
680 # Convert Channel Independent Density values to Relative Log Exposure
682 lut = create_CID_to_RLE_LUT()
683 cs.to_reference_transforms.append({
686 'interpolation': 'linear',
687 'direction': 'forward'
690 # Convert Relative Log Exposure values to Relative Exposure values
691 cs.to_reference_transforms.append({
694 'direction': 'inverse'
697 # Convert Relative Exposure values to ACES values
698 cs.to_reference_transforms.append({
700 'matrix': [0.72286, 0.12630, 0.15084, 0,
701 0.11923, 0.76418, 0.11659, 0,
702 0.01427, 0.08213, 0.90359, 0,
704 'direction': 'forward'
707 cs.from_reference_transforms = []
710 ADX10 = create_ADX(bit_depth=10)
711 config_data['colorSpaces'].append(ADX10)
713 ADX16 = create_ADX(bit_depth=16)
714 config_data['colorSpaces'].append(ADX16)
717 # Camera Input Transforms
720 # RED color spaces to ACES
721 red_colorspaces = red.create_colorspaces(lut_directory, lut_resolution_1d)
722 for cs in red_colorspaces:
723 config_data['colorSpaces'].append(cs)
726 canon_colorspaces = canon.create_colorspaces(lut_directory,
728 for cs in canon_colorspaces:
729 config_data['colorSpaces'].append(cs)
732 sony_colorSpaces = sony.create_colorspaces(lut_directory,
734 for cs in sony_colorSpaces:
735 config_data['colorSpaces'].append(cs)
738 arri_colorSpaces = arri.create_colorspaces(lut_directory,
740 for cs in arri_colorSpaces:
741 config_data['colorSpaces'].append(cs)
744 # Generic log transform
746 def create_generic_log(name='log',
753 lut_resolution_1d=lut_resolution_1d):
754 cs = ColorSpace(name)
755 cs.description = 'The %s color space' % name
756 cs.equality_group = name
757 cs.family = 'Utility'
761 os.path.join(aces_CTL_directory,
763 'ACESlib.OCIO_shaper_log2_to_lin_param.a1.0.0.ctl')]
764 lut = '%s_to_aces.spi1d' % name
766 lut = sanitize_path(lut)
768 generate_1d_LUT_from_CTL(
769 os.path.join(lut_directory, lut),
776 'middleGrey': middle_grey,
777 'minExposure': min_exposure,
778 'maxExposure': max_exposure
785 cs.to_reference_transforms = []
786 cs.to_reference_transforms.append({
789 'interpolation': 'linear',
790 'direction': 'forward'
793 cs.from_reference_transforms = []
799 def create_ACES_LMT(lmt_name,
802 lut_resolution_1d=1024,
803 lut_resolution_3d=64,
805 cs = ColorSpace('%s' % lmt_name)
806 cs.description = 'The ACES Look Transform: %s' % lmt_name
807 cs.equality_group = ''
811 pprint.pprint(lmt_values)
814 # Generate the shaper transform
818 shaper_from_ACES_CTL,
820 shaper_params) = shaper_info
822 shaper_lut = '%s_to_aces.spi1d' % shaper_name
823 if (not os.path.exists(os.path.join(lut_directory, shaper_lut))):
824 ctls = [shaper_to_ACES_CTL % aces_CTL_directory]
826 # Remove spaces and parentheses
827 shaper_lut = shaper_lut.replace(
828 ' ', '_').replace(')', '_').replace('(', '_')
830 generate_1d_LUT_from_CTL(
831 os.path.join(lut_directory, shaper_lut),
835 1.0 / shaper_input_scale,
841 shaper_OCIO_transform = {
844 'interpolation': 'linear',
845 'direction': 'inverse'
849 # Generate the forward transform
851 cs.from_reference_transforms = []
853 if 'transformCTL' in lmt_values:
855 shaper_to_ACES_CTL % aces_CTL_directory,
856 os.path.join(aces_CTL_directory, lmt_values['transformCTL'])]
857 lut = '%s.%s.spi3d' % (shaper_name, lmt_name)
859 lut = sanitize_path(lut)
861 generate_3d_LUT_from_CTL(
862 os.path.join(lut_directory, lut),
866 1.0 / shaper_input_scale,
872 cs.from_reference_transforms.append(shaper_OCIO_transform)
873 cs.from_reference_transforms.append({
876 'interpolation': 'tetrahedral',
877 'direction': 'forward'
881 # Generate the inverse transform
883 cs.to_reference_transforms = []
885 if 'transformCTLInverse' in lmt_values:
887 os.path.join(aces_CTL_directory,
888 odt_values['transformCTLInverse']),
889 shaper_from_ACES_CTL % aces_CTL_directory
891 lut = 'Inverse.%s.%s.spi3d' % (odt_name, shaper_name)
893 lut = sanitize_path(lut)
895 generate_3d_LUT_from_CTL(
896 os.path.join(lut_directory, lut),
906 cs.to_reference_transforms.append({
909 'interpolation': 'tetrahedral',
910 'direction': 'forward'
913 shaper_inverse = shaper_OCIO_transform.copy()
914 shaper_inverse['direction'] = 'forward'
915 cs.to_reference_transforms.append(shaper_inverse)
923 lmt_lut_resolution_1d = max(4096, lut_resolution_1d)
924 lmt_lut_resolution_3d = max(65, lut_resolution_3d)
927 lmt_shaper_name = 'LMT Shaper'
930 'minExposure': -10.0,
933 lmt_shaper = create_generic_log(name=lmt_shaper_name,
934 middle_grey=lmt_params['middleGrey'],
935 min_exposure=lmt_params['minExposure'],
936 max_exposure=lmt_params['maxExposure'],
937 lut_resolution_1d=lmt_lut_resolution_1d)
938 config_data['colorSpaces'].append(lmt_shaper)
940 shaper_input_scale_generic_log2 = 1.0
942 # Log 2 shaper name and CTL transforms bundled up
947 'ACESlib.OCIO_shaper_log2_to_lin_param.a1.0.0.ctl'),
950 'ACESlib.OCIO_shaper_lin_to_log2_param.a1.0.0.ctl'),
951 shaper_input_scale_generic_log2,
954 sorted_LMTs = sorted(lmt_info.iteritems(), key=lambda x: x[1])
956 for lmt in sorted_LMTs:
957 (lmt_name, lmt_values) = lmt
958 cs = create_ACES_LMT(
959 lmt_values['transformUserName'],
962 lmt_lut_resolution_1d,
963 lmt_lut_resolution_3d,
965 config_data['colorSpaces'].append(cs)
968 # ACES RRT with the supplied ODT
970 def create_ACES_RRT_plus_ODT(odt_name,
973 lut_resolution_1d=1024,
974 lut_resolution_3d=64,
976 cs = ColorSpace('%s' % odt_name)
977 cs.description = '%s - %s Output Transform' % (
978 odt_values['transformUserNamePrefix'], odt_name)
979 cs.equality_group = ''
983 pprint.pprint(odt_values)
986 # Generate the shaper transform
988 # if 'shaperCTL' in odtValues:
991 shaper_from_ACES_CTL,
993 shaper_params) = shaper_info
995 if 'legalRange' in odt_values:
996 shaper_params['legalRange'] = odt_values['legalRange']
998 shaper_params['legalRange'] = 0
1000 shaper_lut = '%s_to_aces.spi1d' % shaper_name
1001 if (not os.path.exists(os.path.join(lut_directory, shaper_lut))):
1002 ctls = [shaper_to_ACES_CTL % aces_CTL_directory]
1004 # Remove spaces and parentheses
1005 shaper_lut = shaper_lut.replace(
1006 ' ', '_').replace(')', '_').replace('(', '_')
1008 generate_1d_LUT_from_CTL(
1009 os.path.join(lut_directory, shaper_lut),
1013 1.0 / shaper_input_scale,
1019 shaper_OCIO_transform = {
1022 'interpolation': 'linear',
1023 'direction': 'inverse'
1027 # Generate the forward transform
1029 cs.from_reference_transforms = []
1031 if 'transformLUT' in odt_values:
1032 # Copy into the lut dir
1033 transform_LUT_file_name = os.path.basename(
1034 odt_values['transformLUT'])
1035 lut = os.path.join(lut_directory, transform_LUT_file_name)
1036 shutil.copy(odt_values['transformLUT'], lut)
1038 cs.from_reference_transforms.append(shaper_OCIO_transform)
1039 cs.from_reference_transforms.append({
1041 'path': transform_LUT_file_name,
1042 'interpolation': 'tetrahedral',
1043 'direction': 'forward'
1045 elif 'transformCTL' in odt_values:
1049 shaper_to_ACES_CTL % aces_CTL_directory,
1050 os.path.join(aces_CTL_directory,
1053 os.path.join(aces_CTL_directory,
1055 odt_values['transformCTL'])]
1056 lut = '%s.RRT.a1.0.0.%s.spi3d' % (shaper_name, odt_name)
1058 lut = sanitize_path(lut)
1060 generate_3d_LUT_from_CTL(
1061 os.path.join(lut_directory, lut),
1066 1.0 / shaper_input_scale,
1072 cs.from_reference_transforms.append(shaper_OCIO_transform)
1073 cs.from_reference_transforms.append({
1076 'interpolation': 'tetrahedral',
1077 'direction': 'forward'
1081 # Generate the inverse transform
1083 cs.to_reference_transforms = []
1085 if 'transformLUTInverse' in odt_values:
1086 # Copy into the lut dir
1087 transform_LUT_inverse_file_name = os.path.basename(
1088 odt_values['transformLUTInverse'])
1089 lut = os.path.join(lut_directory, transform_LUT_inverse_file_name)
1090 shutil.copy(odt_values['transformLUTInverse'], lut)
1092 cs.to_reference_transforms.append({
1094 'path': transform_LUT_inverse_file_name,
1095 'interpolation': 'tetrahedral',
1096 'direction': 'forward'
1099 shaper_inverse = shaper_OCIO_transform.copy()
1100 shaper_inverse['direction'] = 'forward'
1101 cs.to_reference_transforms.append(shaper_inverse)
1102 elif 'transformCTLInverse' in odt_values:
1104 os.path.join(aces_CTL_directory,
1106 odt_values['transformCTLInverse']),
1107 os.path.join(aces_CTL_directory,
1109 'InvRRT.a1.0.0.ctl'),
1110 shaper_from_ACES_CTL % aces_CTL_directory
1112 lut = 'InvRRT.a1.0.0.%s.%s.spi3d' % (odt_name, shaper_name)
1114 lut = sanitize_path(lut)
1116 generate_3d_LUT_from_CTL(
1117 os.path.join(lut_directory, lut),
1128 cs.to_reference_transforms.append({
1131 'interpolation': 'tetrahedral',
1132 'direction': 'forward'
1135 shaper_inverse = shaper_OCIO_transform.copy()
1136 shaper_inverse['direction'] = 'forward'
1137 cs.to_reference_transforms.append(shaper_inverse)
1142 # RRT/ODT shaper options
1147 log2_shaper_name = shaper_name
1150 'minExposure': -6.0,
1153 log2_shaper = create_generic_log(
1154 name=log2_shaper_name,
1155 middle_grey=log2_params['middleGrey'],
1156 min_exposure=log2_params['minExposure'],
1157 max_exposure=log2_params['maxExposure'])
1158 config_data['colorSpaces'].append(log2_shaper)
1160 shaper_input_scale_generic_log2 = 1.0
1162 # Log 2 shaper name and CTL transforms bundled up
1163 log2_shaper_data = [
1167 'ACESlib.OCIO_shaper_log2_to_lin_param.a1.0.0.ctl'),
1170 'ACESlib.OCIO_shaper_lin_to_log2_param.a1.0.0.ctl'),
1171 shaper_input_scale_generic_log2,
1174 shaper_data[log2_shaper_name] = log2_shaper_data
1177 # Shaper that also includes the AP1 primaries
1178 # - Needed for some LUT baking steps
1180 log2_shaper_AP1 = create_generic_log(
1181 name=log2_shaper_name,
1182 middle_grey=log2_params['middleGrey'],
1183 min_exposure=log2_params['minExposure'],
1184 max_exposure=log2_params['maxExposure'])
1185 log2_shaper_AP1.name = '%s - AP1' % log2_shaper_AP1.name
1186 # AP1 primaries to AP0 primaries
1187 log2_shaper_AP1.to_reference_transforms.append({
1189 'matrix': mat44_from_mat33(ACES_AP1_to_AP0),
1190 'direction': 'forward'
1192 config_data['colorSpaces'].append(log2_shaper_AP1)
1195 # Choose your shaper
1197 rrt_shaper_name = log2_shaper_name
1198 rrt_shaper = log2_shaper_data
1201 # RRT + ODT Combinations
1203 sorted_odts = sorted(odt_info.iteritems(), key=lambda x: x[1])
1205 for odt in sorted_odts:
1206 (odt_name, odt_values) = odt
1208 # Have to handle ODTs that can generate either legal or full output
1209 if odt_name in ['Academy.Rec2020_100nits_dim.a1.0.0',
1210 'Academy.Rec709_100nits_dim.a1.0.0',
1211 'Academy.Rec709_D60sim_100nits_dim.a1.0.0']:
1212 odt_name_legal = '%s - Legal' % odt_values['transformUserName']
1214 odt_name_legal = odt_values['transformUserName']
1216 odt_legal = odt_values.copy()
1217 odt_legal['legalRange'] = 1
1219 cs = create_ACES_RRT_plus_ODT(
1226 config_data['colorSpaces'].append(cs)
1228 # Create a display entry using this color space
1229 config_data['displays'][odt_name_legal] = {
1232 'Output Transform': cs}
1234 if odt_name in ['Academy.Rec2020_100nits_dim.a1.0.0',
1235 'Academy.Rec709_100nits_dim.a1.0.0',
1236 'Academy.Rec709_D60sim_100nits_dim.a1.0.0']:
1237 print('Generating full range ODT for %s' % odt_name)
1239 odt_name_full = '%s - Full' % odt_values['transformUserName']
1240 odt_full = odt_values.copy()
1241 odt_full['legalRange'] = 0
1243 cs_full = create_ACES_RRT_plus_ODT(
1250 config_data['colorSpaces'].append(cs_full)
1252 # Create a display entry using this color space
1253 config_data['displays'][odt_name_full] = {
1256 'Output Transform': cs_full}
1259 # Generic Matrix transform
1261 def create_generic_matrix(name='matrix',
1262 from_reference_values=[],
1263 to_reference_values=[]):
1264 cs = ColorSpace(name)
1265 cs.description = 'The %s color space' % name
1266 cs.equality_group = name
1267 cs.family = 'Utility'
1270 cs.to_reference_transforms = []
1271 if to_reference_values != []:
1272 for matrix in to_reference_values:
1273 cs.to_reference_transforms.append({
1275 'matrix': mat44_from_mat33(matrix),
1276 'direction': 'forward'
1279 cs.from_reference_transforms = []
1280 if from_reference_values != []:
1281 for matrix in from_reference_values:
1282 cs.from_reference_transforms.append({
1284 'matrix': mat44_from_mat33(matrix),
1285 'direction': 'forward'
1290 cs = create_generic_matrix('XYZ', from_reference_values=[ACES_AP0_to_XYZ])
1291 config_data['colorSpaces'].append(cs)
1293 cs = create_generic_matrix(
1294 'Linear - AP1', to_reference_values=[ACES_AP1_to_AP0])
1295 config_data['colorSpaces'].append(cs)
1297 # ACES to Linear, P3D60 primaries
1298 XYZ_to_P3D60 = [2.4027414142, -0.8974841639, -0.3880533700,
1299 -0.8325796487, 1.7692317536, 0.0237127115,
1300 0.0388233815, -0.0824996856, 1.0363685997]
1302 cs = create_generic_matrix(
1304 from_reference_values=[ACES_AP0_to_XYZ, XYZ_to_P3D60])
1305 config_data['colorSpaces'].append(cs)
1307 # ACES to Linear, P3D60 primaries
1308 XYZ_to_P3DCI = [2.7253940305, -1.0180030062, -0.4401631952,
1309 -0.7951680258, 1.6897320548, 0.0226471906,
1310 0.0412418914, -0.0876390192, 1.1009293786]
1312 cs = create_generic_matrix(
1314 from_reference_values=[ACES_AP0_to_XYZ, XYZ_to_P3DCI])
1315 config_data['colorSpaces'].append(cs)
1317 # ACES to Linear, Rec 709 primaries
1318 XYZ_to_Rec709 = [3.2409699419, -1.5373831776, -0.4986107603,
1319 -0.9692436363, 1.8759675015, 0.0415550574,
1320 0.0556300797, -0.2039769589, 1.0569715142]
1322 cs = create_generic_matrix(
1324 from_reference_values=[ACES_AP0_to_XYZ, XYZ_to_Rec709])
1325 config_data['colorSpaces'].append(cs)
1327 # ACES to Linear, Rec 2020 primaries
1328 XYZ_to_Rec2020 = [1.7166511880, -0.3556707838, -0.2533662814,
1329 -0.6666843518, 1.6164812366, 0.0157685458,
1330 0.0176398574, -0.0427706133, 0.9421031212]
1332 cs = create_generic_matrix(
1333 'Linear - Rec.2020',
1334 from_reference_values=[ACES_AP0_to_XYZ, XYZ_to_Rec2020])
1335 config_data['colorSpaces'].append(cs)
1337 print('generateLUTs - end')
1341 def generate_baked_LUTs(odt_info,
1347 lut_resolution_shaper=1024):
1354 Parameter description.
1359 Return value description.
1362 # Add the legal and full variations into this list
1363 odt_info_C = dict(odt_info)
1364 for odt_CTL_name, odt_values in odt_info.iteritems():
1365 if odt_CTL_name in ['Academy.Rec2020_100nits_dim.a1.0.0',
1366 'Academy.Rec709_100nits_dim.a1.0.0',
1367 'Academy.Rec709_D60sim_100nits_dim.a1.0.0']:
1368 odt_name = odt_values['transformUserName']
1370 odt_values_legal = dict(odt_values)
1371 odt_values_legal['transformUserName'] = '%s - Legal' % odt_name
1372 odt_info_C['%s - Legal' % odt_CTL_name] = odt_values_legal
1374 odt_values_full = dict(odt_values)
1375 odt_values_full['transformUserName'] = '%s - Full' % odt_name
1376 odt_info_C['%s - Full' % odt_CTL_name] = odt_values_full
1378 del (odt_info_C[odt_CTL_name])
1380 for odt_CTL_name, odt_values in odt_info_C.iteritems():
1381 odt_prefix = odt_values['transformUserNamePrefix']
1382 odt_name = odt_values['transformUserName']
1385 for input_space in ['ACEScc', 'ACESproxy']:
1386 args = ['--iconfig', config_path,
1388 '--inputspace', input_space]
1389 args += ['--outputspace', '%s' % odt_name]
1390 args += ['--description',
1391 '%s - %s for %s data' % (odt_prefix,
1394 args += ['--shaperspace', shaper_name,
1395 '--shapersize', str(lut_resolution_shaper)]
1396 args += ['--cubesize', str(lut_resolution_3d)]
1397 args += ['--format',
1399 os.path.join(baked_directory,
1401 '%s for %s.icc' % (odt_name, input_space))]
1403 bake_LUT = Process(description='bake a LUT',
1409 for input_space in ['ACEScc', 'ACESproxy']:
1410 args = ['--iconfig', config_path,
1412 '--inputspace', input_space]
1413 args += ['--outputspace', '%s' % odt_name]
1414 args += ['--description',
1415 '%s - %s for %s data' % (
1416 odt_prefix, odt_name, input_space)]
1417 args += ['--shaperspace', shaper_name,
1418 '--shapersize', str(lut_resolution_shaper)]
1419 args += ['--cubesize', str(lut_resolution_3d)]
1421 fargs = ['--format',
1426 '%s for %s Flame.3dl' % (odt_name, input_space))]
1427 bake_LUT = Process(description='bake a LUT',
1429 args=(args + fargs))
1432 largs = ['--format',
1437 '%s for %s Lustre.3dl' % (odt_name, input_space))]
1438 bake_LUT = Process(description='bake a LUT',
1440 args=(args + largs))
1444 for input_space in ['ACEScg', 'ACES2065-1']:
1445 args = ['--iconfig', config_path,
1447 '--inputspace', input_space]
1448 args += ['--outputspace', '%s' % odt_name]
1449 args += ['--description',
1450 '%s - %s for %s data' % (
1451 odt_prefix, odt_name, input_space)]
1452 if input_space == 'ACEScg':
1453 lin_shaper_name = '%s - AP1' % shaper_name
1455 lin_shaper_name = shaper_name
1456 args += ['--shaperspace', lin_shaper_name,
1457 '--shapersize', str(lut_resolution_shaper)]
1459 args += ['--cubesize', str(lut_resolution_3d)]
1461 margs = ['--format',
1466 '%s for %s Maya.csp' % (odt_name, input_space))]
1467 bake_LUT = Process(description='bake a LUT',
1469 args=(args + margs))
1472 hargs = ['--format',
1477 '%s for %s Houdini.lut' % (odt_name, input_space))]
1478 bake_LUT = Process(description='bake a LUT',
1480 args=(args + hargs))
1484 def create_config_dir(config_directory, bake_secondary_LUTs):
1491 Parameter description.
1496 Return value description.
1499 dirs = [config_directory, os.path.join(config_directory, 'luts')]
1500 if bake_secondary_LUTs:
1501 dirs.extend([os.path.join(config_directory, 'baked'),
1502 os.path.join(config_directory, 'baked', 'flame'),
1503 os.path.join(config_directory, 'baked', 'photoshop'),
1504 os.path.join(config_directory, 'baked', 'houdini'),
1505 os.path.join(config_directory, 'baked', 'lustre'),
1506 os.path.join(config_directory, 'baked', 'maya')])
1509 not os.path.exists(d) and os.mkdir(d)
1512 def get_transform_info(ctl_transform):
1519 Parameter description.
1524 Return value description.
1527 with open(ctl_transform, 'rb') as fp:
1528 lines = fp.readlines()
1530 # Grab transform ID and User Name
1531 transform_ID = lines[1][3:].split('<')[1].split('>')[1].strip()
1532 # print(transformID)
1533 transform_user_name = '-'.join(
1534 lines[2][3:].split('<')[1].split('>')[1].split('-')[1:]).strip()
1535 transform_user_name_prefix = (
1536 lines[2][3:].split('<')[1].split('>')[1].split('-')[0].strip())
1537 # print(transformUserName)
1539 return transform_ID, transform_user_name, transform_user_name_prefix
1542 def get_ODT_info(aces_CTL_directory):
1546 For versions after WGR9.
1551 Parameter description.
1556 Return value description.
1559 # TODO: Investigate usage of *files_walker* definition here.
1560 # Credit to Alex Fry for the original approach here
1561 odt_dir = os.path.join(aces_CTL_directory, 'odt')
1563 for dir_name, subdir_list, file_list in os.walk(odt_dir):
1564 for fname in file_list:
1565 all_odt.append((os.path.join(dir_name, fname)))
1567 odt_CTLs = [x for x in all_odt if
1568 ('InvODT' not in x) and (os.path.split(x)[-1][0] != '.')]
1574 for odt_CTL in odt_CTLs:
1575 odt_tokens = os.path.split(odt_CTL)
1578 # Handle nested directories
1579 odt_path_tokens = os.path.split(odt_tokens[-2])
1580 odt_dir = odt_path_tokens[-1]
1581 while odt_path_tokens[-2][-3:] != 'odt':
1582 odt_path_tokens = os.path.split(odt_path_tokens[-2])
1583 odt_dir = os.path.join(odt_path_tokens[-1], odt_dir)
1586 # print('odtDir : %s' % odtDir)
1587 transform_CTL = odt_tokens[-1]
1588 # print(transformCTL)
1589 odt_name = string.join(transform_CTL.split('.')[1:-1], '.')
1592 # Find id, user name and user name prefix
1594 transform_user_name,
1595 transform_user_name_prefix) = get_transform_info(
1596 os.path.join(aces_CTL_directory, 'odt', odt_dir, transform_CTL))
1599 transform_CTL_inverse = 'InvODT.%s.ctl' % odt_name
1600 if not os.path.exists(
1601 os.path.join(odt_tokens[-2], transform_CTL_inverse)):
1602 transform_CTL_inverse = None
1603 # print(transformCTLInverse)
1605 # Add to list of ODTs
1607 odts[odt_name]['transformCTL'] = os.path.join(odt_dir, transform_CTL)
1608 if transform_CTL_inverse != None:
1609 odts[odt_name]['transformCTLInverse'] = os.path.join(
1610 odt_dir, transform_CTL_inverse)
1612 odts[odt_name]['transformID'] = transform_ID
1613 odts[odt_name]['transformUserNamePrefix'] = transform_user_name_prefix
1614 odts[odt_name]['transformUserName'] = transform_user_name
1616 print('ODT : %s' % odt_name)
1617 print('\tTransform ID : %s' % transform_ID)
1618 print('\tTransform User Name Prefix : %s' % transform_user_name_prefix)
1619 print('\tTransform User Name : %s' % transform_user_name)
1620 print('\tForward ctl : %s' % (
1621 odts[odt_name]['transformCTL']))
1622 if 'transformCTLInverse' in odts[odt_name]:
1623 print('\tInverse ctl : %s' % (
1624 odts[odt_name]['transformCTLInverse']))
1626 print('\tInverse ctl : %s' % 'None')
1633 def get_LMT_info(aces_CTL_directory):
1637 For versions after WGR9.
1642 Parameter description.
1647 Return value description.
1650 # TODO: Investigate refactoring with previous definition.
1652 # Credit to Alex Fry for the original approach here
1653 lmt_dir = os.path.join(aces_CTL_directory, 'lmt')
1655 for dir_name, subdir_list, file_list in os.walk(lmt_dir):
1656 for fname in file_list:
1657 all_lmt.append((os.path.join(dir_name, fname)))
1659 lmt_CTLs = [x for x in all_lmt if
1660 ('InvLMT' not in x) and ('README' not in x) and (
1661 os.path.split(x)[-1][0] != '.')]
1667 for lmt_CTL in lmt_CTLs:
1668 lmt_tokens = os.path.split(lmt_CTL)
1671 # Handle nested directories
1672 lmt_path_tokens = os.path.split(lmt_tokens[-2])
1673 lmt_dir = lmt_path_tokens[-1]
1674 while lmt_path_tokens[-2][-3:] != 'ctl':
1675 lmt_path_tokens = os.path.split(lmt_path_tokens[-2])
1676 lmt_dir = os.path.join(lmt_path_tokens[-1], lmt_dir)
1679 # print('lmtDir : %s' % lmtDir)
1680 transform_CTL = lmt_tokens[-1]
1681 # print(transformCTL)
1682 lmt_name = string.join(transform_CTL.split('.')[1:-1], '.')
1685 # Find id, user name and user name prefix
1687 transform_user_name,
1688 transform_user_name_prefix) = get_transform_info(
1689 os.path.join(aces_CTL_directory, lmt_dir, transform_CTL))
1692 transform_CTL_inverse = 'InvLMT.%s.ctl' % lmt_name
1693 if not os.path.exists(
1694 os.path.join(lmt_tokens[-2], transform_CTL_inverse)):
1695 transform_CTL_inverse = None
1696 # print(transformCTLInverse)
1698 # Add to list of LMTs
1700 lmts[lmt_name]['transformCTL'] = os.path.join(lmt_dir, transform_CTL)
1701 if transform_CTL_inverse != None:
1702 # TODO: Check unresolved *odt_name* referemce.
1703 lmts[odt_name]['transformCTLInverse'] = os.path.join(
1704 lmt_dir, transform_CTL_inverse)
1706 lmts[lmt_name]['transformID'] = transform_ID
1707 lmts[lmt_name]['transformUserNamePrefix'] = transform_user_name_prefix
1708 lmts[lmt_name]['transformUserName'] = transform_user_name
1710 print('LMT : %s' % lmt_name)
1711 print('\tTransform ID : %s' % transform_ID)
1712 print('\tTransform User Name Prefix : %s' % transform_user_name_prefix)
1713 print('\tTransform User Name : %s' % transform_user_name)
1714 print('\t Forward ctl : %s' % lmts[lmt_name]['transformCTL'])
1715 if 'transformCTLInverse' in lmts[lmt_name]:
1716 print('\t Inverse ctl : %s' % (
1717 lmts[lmt_name]['transformCTLInverse']))
1719 print('\t Inverse ctl : %s' % 'None')
1726 def create_ACES_config(aces_CTL_directory,
1728 lut_resolution_1d=4096,
1729 lut_resolution_3d=64,
1730 bake_secondary_LUTs=True,
1733 Creates the ACES configuration.
1738 Parameter description.
1743 Return value description.
1746 # Get ODT names and CTL paths
1747 odt_info = get_ODT_info(aces_CTL_directory)
1749 # Get ODT names and CTL paths
1750 lmt_info = get_LMT_info(aces_CTL_directory)
1753 create_config_dir(config_directory, bake_secondary_LUTs)
1755 # Generate config data and LUTs for different transforms
1756 lut_directory = os.path.join(config_directory, 'luts')
1757 shaper_name = 'Output Shaper'
1758 config_data = generate_LUTs(odt_info,
1767 # Create the config using the generated LUTs
1768 print('Creating generic config')
1769 config = create_config(config_data)
1772 # Write the config to disk
1773 write_config(config,
1774 os.path.join(config_directory, 'config.ocio'))
1776 # Create a config that will work well with Nuke using the previously
1778 print('Creating Nuke-specific config')
1779 nuke_config = create_config(config_data, nuke=True)
1782 # Write the config to disk
1783 write_config(nuke_config,
1784 os.path.join(config_directory, 'nuke_config.ocio'))
1786 # Bake secondary LUTs using the config
1787 if bake_secondary_LUTs:
1788 generate_baked_LUTs(odt_info,
1790 os.path.join(config_directory, 'baked'),
1791 os.path.join(config_directory, 'config.ocio'),
1806 Parameter description.
1811 Return value description.
1816 p = optparse.OptionParser(description='An OCIO config generation script',
1817 prog='createACESConfig',
1818 version='createACESConfig 0.1',
1819 usage='%prog [options]')
1820 p.add_option('--acesCTLDir', '-a', default=os.environ.get(
1821 'ACES_OCIO_CTL_DIRECTORY', None))
1822 p.add_option('--configDir', '-c', default=os.environ.get(
1823 'ACES_OCIO_CONFIGURATION_DIRECTORY', None))
1824 p.add_option('--lutResolution1d', default=4096)
1825 p.add_option('--lutResolution3d', default=64)
1826 p.add_option('--dontBakeSecondaryLUTs', action='store_true')
1827 p.add_option('--keepTempImages', action='store_true')
1829 options, arguments = p.parse_args()
1834 aces_CTL_directory = options.acesCTLDir
1835 config_directory = options.configDir
1836 lut_resolution_1d = int(options.lutResolution1d)
1837 lut_resolution_3d = int(options.lutResolution3d)
1838 bake_secondary_LUTs = not (options.dontBakeSecondaryLUTs)
1839 cleanup_temp_images = not (options.keepTempImages)
1842 args_start = sys.argv.index('--') + 1
1843 args = sys.argv[args_start:]
1845 args_start = len(sys.argv) + 1
1848 print('command line : \n%s\n' % ' '.join(sys.argv))
1850 # TODO: Use assertion and mention environment variables.
1851 if not aces_CTL_directory:
1852 print('process: No ACES CTL directory specified')
1854 if not config_directory:
1855 print('process: No configuration directory specified')
1858 # Generate the configuration
1860 return create_ACES_config(aces_CTL_directory,
1864 bake_secondary_LUTs,
1865 cleanup_temp_images)
1868 if __name__ == '__main__':