2 # -*- coding: utf-8 -*-
5 Defines objects creating the *ACES* configuration.
11 import PyOpenColorIO as ocio
13 import aces_ocio.create_aces_colorspaces as aces
14 import aces_ocio.create_arri_colorspaces as arri
15 import aces_ocio.create_canon_colorspaces as canon
16 import aces_ocio.create_red_colorspaces as red
17 import aces_ocio.create_sony_colorspaces as sony
18 import aces_ocio.create_general_colorspaces as general
20 from aces_ocio.process import Process
22 __author__ = 'ACES Developers'
23 __copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers'
25 __maintainer__ = 'ACES Developers'
26 __email__ = 'aces@oscars.org'
27 __status__ = 'Production'
29 __all__ = ['ACES_OCIO_CTL_DIRECTORY_ENVIRON',
30 'ACES_OCIO_CONFIGURATION_DIRECTORY_ENVIRON',
31 'set_config_default_roles',
33 'generate_OCIO_transform',
34 'add_colorspace_alias',
37 'generate_baked_LUTs',
42 ACES_OCIO_CTL_DIRECTORY_ENVIRON = 'ACES_OCIO_CTL_DIRECTORY'
43 ACES_OCIO_CONFIGURATION_DIRECTORY_ENVIRON = 'ACES_OCIO_CONFIGURATION_DIRECTORY'
46 def set_config_default_roles(config,
57 Sets given *OCIO* configuration default roles.
63 color_picking : str or unicode
64 Color picking role title.
65 color_timing : str or unicode
66 Color timing role title.
67 compositing_log : str or unicode
68 Compositing log role title.
71 default : str or unicode
73 matte_paint : str or unicode
74 Matte painting role title.
75 reference : str or unicode
77 scene_linear : str or unicode
78 Scene linear role title.
79 texture_paint : str or unicode
80 Texture painting role title.
89 config.setRole(ocio.Constants.ROLE_COLOR_PICKING, color_picking)
91 config.setRole(ocio.Constants.ROLE_COLOR_TIMING, color_timing)
93 config.setRole(ocio.Constants.ROLE_COMPOSITING_LOG, compositing_log)
95 config.setRole(ocio.Constants.ROLE_DATA, data)
97 config.setRole(ocio.Constants.ROLE_DEFAULT, default)
99 config.setRole(ocio.Constants.ROLE_MATTE_PAINT, matte_paint)
101 config.setRole(ocio.Constants.ROLE_REFERENCE, reference)
103 config.setRole(ocio.Constants.ROLE_SCENE_LINEAR, scene_linear)
105 config.setRole(ocio.Constants.ROLE_TEXTURE_PAINT, texture_paint)
110 def write_config(config, config_path, sanity_check=True):
112 Writes the configuration to given path.
117 Parameter description.
122 Return value description.
130 print 'Configuration was not written due to a failed Sanity Check'
133 with open(config_path, mode='w') as fp:
134 fp.write(config.serialize())
137 def generate_OCIO_transform(transforms):
144 Parameter description.
149 Return value description.
152 interpolation_options = {
153 'linear': ocio.Constants.INTERP_LINEAR,
154 'nearest': ocio.Constants.INTERP_NEAREST,
155 'tetrahedral': ocio.Constants.INTERP_TETRAHEDRAL}
157 direction_options = {
158 'forward': ocio.Constants.TRANSFORM_DIR_FORWARD,
159 'inverse': ocio.Constants.TRANSFORM_DIR_INVERSE}
163 for transform in transforms:
166 if transform['type'] == 'lutFile':
167 ocio_transform = ocio.FileTransform(
168 src=transform['path'],
169 interpolation=interpolation_options[
170 transform['interpolation']],
171 direction=direction_options[transform['direction']])
172 ocio_transforms.append(ocio_transform)
175 elif transform['type'] == 'matrix':
176 ocio_transform = ocio.MatrixTransform()
177 # MatrixTransform member variables can't be initialized directly.
178 # Each must be set individually.
179 ocio_transform.setMatrix(transform['matrix'])
181 if 'offset' in transform:
182 ocio_transform.setOffset(transform['offset'])
184 if 'direction' in transform:
185 ocio_transform.setDirection(
186 direction_options[transform['direction']])
188 ocio_transforms.append(ocio_transform)
191 elif transform['type'] == 'exponent':
192 ocio_transform = ocio.ExponentTransform()
193 ocio_transform.setValue(transform['value'])
194 ocio_transforms.append(ocio_transform)
197 elif transform['type'] == 'log':
198 ocio_transform = ocio.LogTransform(
199 base=transform['base'],
200 direction=direction_options[transform['direction']])
202 ocio_transforms.append(ocio_transform)
204 # color space transform
205 elif transform['type'] == 'colorspace':
206 ocio_transform = ocio.ColorSpaceTransform(src=transform['src'],
207 dst=transform['dst'],
211 ocio_transforms.append(ocio_transform)
214 print("Ignoring unknown transform type : %s" % transform['type'])
216 if len(ocio_transforms) > 1:
217 group_transform = ocio.GroupTransform()
218 for transform in ocio_transforms:
219 group_transform.push_back(transform)
220 transform = group_transform
222 transform = ocio_transforms[0]
227 def add_colorspace_alias(config,
228 reference_colorspace,
230 colorspace_alias_names):
237 Parameter description.
242 Return value description.
245 for alias_name in colorspace_alias_names:
246 if alias_name == colorspace.name.lower():
249 print('Adding alias colorspace space %s, alias to %s' % (
250 alias_name, colorspace.name))
252 compact_family_name = 'Aliases'
254 ocio_colorspace_alias = ocio.ColorSpace(
256 bitDepth=colorspace.bit_depth,
257 description=colorspace.description,
258 equalityGroup=colorspace.equality_group,
259 family=compact_family_name,
260 isData=colorspace.is_data,
261 allocation=colorspace.allocation_type,
262 allocationVars=colorspace.allocation_vars)
264 if not colorspace.to_reference_transforms:
265 print('Generating To-Reference transforms')
266 ocio_transform = generate_OCIO_transform(
267 [{'type': 'colorspace',
268 'src': colorspace.name,
269 'dst': reference_colorspace.name,
270 'direction': 'forward'}])
271 ocio_colorspace_alias.setTransform(
273 ocio.Constants.COLORSPACE_DIR_TO_REFERENCE)
275 if not colorspace.from_reference_transforms:
276 print('Generating From-Reference transforms')
277 ocio_transform = generate_OCIO_transform(
278 [{'type': 'colorspace',
279 'src': reference_colorspace.name,
280 'dst': colorspace.name,
281 'direction': 'forward'}])
282 ocio_colorspace_alias.setTransform(
284 ocio.Constants.COLORSPACE_DIR_FROM_REFERENCE)
286 config.addColorSpace(ocio_colorspace_alias)
289 def create_config(config_data, nuke=False):
296 Parameter description.
301 Return value description.
304 # Creating the *OCIO* configuration.
305 config = ocio.Config()
307 # Setting configuration overall values.
308 config.setDescription('An ACES config generated from python')
309 config.setSearchPath('luts')
311 # Defining the reference colorspace.
312 reference_data = config_data['referenceColorSpace']
313 print('Adding the reference color space : %s' % reference_data.name)
315 reference = ocio.ColorSpace(
316 name=reference_data.name,
317 bitDepth=reference_data.bit_depth,
318 description=reference_data.description,
319 equalityGroup=reference_data.equality_group,
320 family=reference_data.family,
321 isData=reference_data.is_data,
322 allocation=reference_data.allocation_type,
323 allocationVars=reference_data.allocation_vars)
325 config.addColorSpace(reference)
328 if reference_data.aliases != []:
329 add_colorspace_alias(config, reference_data,
330 reference_data, reference_data.aliases)
334 # Creating the remaining colorspaces.
335 for colorspace in sorted(config_data['colorSpaces']):
336 print('Creating new color space : %s' % colorspace.name)
338 ocio_colorspace = ocio.ColorSpace(
339 name=colorspace.name,
340 bitDepth=colorspace.bit_depth,
341 description=colorspace.description,
342 equalityGroup=colorspace.equality_group,
343 family=colorspace.family,
344 isData=colorspace.is_data,
345 allocation=colorspace.allocation_type,
346 allocationVars=colorspace.allocation_vars)
348 if colorspace.to_reference_transforms:
349 print('Generating To-Reference transforms')
350 ocio_transform = generate_OCIO_transform(
351 colorspace.to_reference_transforms)
352 ocio_colorspace.setTransform(
354 ocio.Constants.COLORSPACE_DIR_TO_REFERENCE)
356 if colorspace.from_reference_transforms:
357 print('Generating From-Reference transforms')
358 ocio_transform = generate_OCIO_transform(
359 colorspace.from_reference_transforms)
360 ocio_colorspace.setTransform(
362 ocio.Constants.COLORSPACE_DIR_FROM_REFERENCE)
364 config.addColorSpace(ocio_colorspace)
367 # Add alias to normal colorspace, using compact name
369 if colorspace.aliases != []:
370 add_colorspace_alias(config, reference_data,
371 colorspace, colorspace.aliases)
375 # Defining the *views* and *displays*.
379 # Defining a *generic* *display* and *view* setup.
381 for display, view_list in config_data['displays'].iteritems():
382 for view_name, colorspace in view_list.iteritems():
383 config.addDisplay(display, view_name, colorspace.name)
384 if not (view_name in views):
385 views.append(view_name)
386 displays.append(display)
388 # Defining the *Nuke* specific set of *views* and *displays*.
390 for display, view_list in config_data['displays'].iteritems():
391 for view_name, colorspace in view_list.iteritems():
392 if view_name == 'Output Transform':
394 config.addDisplay(display, view_name, colorspace.name)
395 if not (view_name in views):
396 views.append(view_name)
397 displays.append(display)
399 linear_display_space_name = config_data['linearDisplaySpace'].name
400 log_display_space_name = config_data['logDisplaySpace'].name
402 config.addDisplay('linear', 'View', linear_display_space_name)
403 displays.append('linear')
404 config.addDisplay('log', 'View', log_display_space_name)
405 displays.append('log')
407 # Setting the active *displays* and *views*.
408 config.setActiveDisplays(','.join(sorted(displays)))
409 config.setActiveViews(','.join(views))
411 set_config_default_roles(
413 color_picking=reference.getName(),
414 color_timing=reference.getName(),
415 compositing_log=reference.getName(),
416 data=reference.getName(),
417 default=reference.getName(),
418 matte_paint=reference.getName(),
419 reference=reference.getName(),
420 scene_linear=reference.getName(),
421 texture_paint=reference.getName())
428 def generate_LUTs(odt_info,
433 lut_resolution_1d=4096,
434 lut_resolution_3d=64,
442 Parameter description.
447 Colorspaces and transforms converting between those colorspaces and
448 the reference colorspace, *ACES*.
451 print('generateLUTs - begin')
454 # Initialize a few variables
455 config_data['displays'] = {}
456 config_data['colorSpaces'] = []
458 # -------------------------------------------------------------------------
459 # *ACES Color Spaces*
460 # -------------------------------------------------------------------------
466 aces_log_display_space) = aces.create_colorspaces(aces_ctl_directory,
475 config_data['referenceColorSpace'] = aces_reference
477 for cs in aces_colorspaces:
478 config_data['colorSpaces'].append(cs)
480 for name, data in aces_displays.iteritems():
481 config_data['displays'][name] = data
483 config_data['linearDisplaySpace'] = aces_reference
484 config_data['logDisplaySpace'] = aces_log_display_space
486 # -------------------------------------------------------------------------
487 # *Camera Input Transforms*
488 # -------------------------------------------------------------------------
491 arri_colorSpaces = arri.create_colorspaces(lut_directory,
493 for cs in arri_colorSpaces:
494 config_data['colorSpaces'].append(cs)
496 # *Canon-Log* to *ACES*.
497 canon_colorspaces = canon.create_colorspaces(lut_directory,
499 for cs in canon_colorspaces:
500 config_data['colorSpaces'].append(cs)
502 # *RED* colorspaces to *ACES*.
503 red_colorspaces = red.create_colorspaces(lut_directory,
505 for cs in red_colorspaces:
506 config_data['colorSpaces'].append(cs)
509 sony_colorSpaces = sony.create_colorspaces(lut_directory,
511 for cs in sony_colorSpaces:
512 config_data['colorSpaces'].append(cs)
514 # -------------------------------------------------------------------------
515 # General Color Spaces
516 # -------------------------------------------------------------------------
517 general_colorSpaces = general.create_colorspaces(lut_directory,
520 for cs in general_colorSpaces:
521 config_data['colorSpaces'].append(cs)
523 print('generateLUTs - end')
527 def generate_baked_LUTs(odt_info,
533 lut_resolution_shaper=1024):
540 Parameter description.
545 Return value description.
548 # Create two entries for ODTs that have full and legal range support
549 odt_info_C = dict(odt_info)
550 for odt_ctl_name, odt_values in odt_info.iteritems():
551 if odt_values['transformHasFullLegalSwitch']:
552 odt_name = odt_values['transformUserName']
554 odt_values_legal = dict(odt_values)
555 odt_values_legal['transformUserName'] = '%s - Legal' % odt_name
556 odt_info_C['%s - Legal' % odt_ctl_name] = odt_values_legal
558 odt_values_full = dict(odt_values)
559 odt_values_full['transformUserName'] = '%s - Full' % odt_name
560 odt_info_C['%s - Full' % odt_ctl_name] = odt_values_full
562 del (odt_info_C[odt_ctl_name])
564 # Generate appropriate LUTs for each ODT
565 for odt_ctl_name, odt_values in odt_info_C.iteritems():
566 odt_prefix = odt_values['transformUserNamePrefix']
567 odt_name = odt_values['transformUserName']
570 for input_space in ['ACEScc', 'ACESproxy']:
571 args = ['--iconfig', config_path,
573 '--inputspace', input_space]
574 args += ['--outputspace', '%s' % odt_name]
575 args += ['--description',
576 '%s - %s for %s data' % (odt_prefix,
579 args += ['--shaperspace', shaper_name,
580 '--shapersize', str(lut_resolution_shaper)]
581 args += ['--cubesize', str(lut_resolution_3d)]
584 os.path.join(baked_directory,
586 '%s for %s.icc' % (odt_name, input_space))]
588 bake_lut = Process(description='bake a LUT',
594 for input_space in ['ACEScc', 'ACESproxy']:
595 args = ['--iconfig', config_path,
597 '--inputspace', input_space]
598 args += ['--outputspace', '%s' % odt_name]
599 args += ['--description',
600 '%s - %s for %s data' % (
601 odt_prefix, odt_name, input_space)]
602 args += ['--shaperspace', shaper_name,
603 '--shapersize', str(lut_resolution_shaper)]
604 args += ['--cubesize', str(lut_resolution_3d)]
611 '%s for %s Flame.3dl' % (odt_name, input_space))]
612 bake_lut = Process(description='bake a LUT',
622 '%s for %s Lustre.3dl' % (odt_name, input_space))]
623 bake_lut = Process(description='bake a LUT',
629 for input_space in ['ACEScg', 'ACES2065-1']:
630 args = ['--iconfig', config_path,
632 '--inputspace', input_space]
633 args += ['--outputspace', '%s' % odt_name]
634 args += ['--description',
635 '%s - %s for %s data' % (
636 odt_prefix, odt_name, input_space)]
637 if input_space == 'ACEScg':
638 lin_shaper_name = '%s - AP1' % shaper_name
640 lin_shaper_name = shaper_name
641 args += ['--shaperspace', lin_shaper_name,
642 '--shapersize', str(lut_resolution_shaper)]
644 args += ['--cubesize', str(lut_resolution_3d)]
651 '%s for %s Maya.csp' % (odt_name, input_space))]
652 bake_lut = Process(description='bake a LUT',
662 '%s for %s Houdini.lut' % (odt_name, input_space))]
663 bake_lut = Process(description='bake a LUT',
669 def create_config_dir(config_directory, bake_secondary_LUTs):
676 Parameter description.
681 Return value description.
684 lut_directory = os.path.join(config_directory, 'luts')
685 dirs = [config_directory, lut_directory]
686 if bake_secondary_LUTs:
687 dirs.extend([os.path.join(config_directory, 'baked'),
688 os.path.join(config_directory, 'baked', 'flame'),
689 os.path.join(config_directory, 'baked', 'photoshop'),
690 os.path.join(config_directory, 'baked', 'houdini'),
691 os.path.join(config_directory, 'baked', 'lustre'),
692 os.path.join(config_directory, 'baked', 'maya')])
695 not os.path.exists(d) and os.mkdir(d)
700 def create_ACES_config(aces_ctl_directory,
702 lut_resolution_1d=4096,
703 lut_resolution_3d=64,
704 bake_secondary_LUTs=True,
707 Creates the ACES configuration.
712 Parameter description.
717 Return value description.
720 lut_directory = create_config_dir(config_directory, bake_secondary_LUTs)
722 odt_info = aces.get_ODTs_info(aces_ctl_directory)
723 lmt_info = aces.get_LMTs_info(aces_ctl_directory)
725 shaper_name = 'Output Shaper'
726 config_data = generate_LUTs(odt_info,
735 print('Creating "generic" config')
736 config = create_config(config_data)
740 os.path.join(config_directory, 'config.ocio'))
742 print('Creating "Nuke" config')
743 nuke_config = create_config(config_data, nuke=True)
746 write_config(nuke_config,
747 os.path.join(config_directory, 'nuke_config.ocio'))
749 if bake_secondary_LUTs:
750 generate_baked_LUTs(odt_info,
752 os.path.join(config_directory, 'baked'),
753 os.path.join(config_directory, 'config.ocio'),
768 Parameter description.
773 Return value description.
778 p = optparse.OptionParser(description='An OCIO config generation script',
779 prog='createACESConfig',
780 version='createACESConfig 0.1',
781 usage='%prog [options]')
782 p.add_option('--acesCTLDir', '-a', default=os.environ.get(
783 ACES_OCIO_CTL_DIRECTORY_ENVIRON, None))
784 p.add_option('--configDir', '-c', default=os.environ.get(
785 ACES_OCIO_CONFIGURATION_DIRECTORY_ENVIRON, None))
786 p.add_option('--lutResolution1d', default=4096)
787 p.add_option('--lutResolution3d', default=64)
788 p.add_option('--dontBakeSecondaryLUTs', action='store_true')
789 p.add_option('--keepTempImages', action='store_true')
791 options, arguments = p.parse_args()
793 aces_ctl_directory = options.acesCTLDir
794 config_directory = options.configDir
795 lut_resolution_1d = int(options.lutResolution1d)
796 lut_resolution_3d = int(options.lutResolution3d)
797 bake_secondary_luts = not options.dontBakeSecondaryLUTs
798 cleanup_temp_images = not options.keepTempImages
800 # TODO: Investigate the following statements.
802 args_start = sys.argv.index('--') + 1
803 args = sys.argv[args_start:]
805 args_start = len(sys.argv) + 1
808 print('command line : \n%s\n' % ' '.join(sys.argv))
810 assert aces_ctl_directory is not None, (
811 'process: No "{0}" environment variable defined or no "ACES CTL" '
812 'directory specified'.format(
813 ACES_OCIO_CTL_DIRECTORY_ENVIRON))
815 assert config_directory is not None, (
816 'process: No "{0}" environment variable defined or no configuration '
817 'directory specified'.format(
818 ACES_OCIO_CONFIGURATION_DIRECTORY_ENVIRON))
820 return create_ACES_config(aces_ctl_directory,
828 if __name__ == '__main__':