2 # -*- coding: utf-8 -*-
5 Defines objects creating the *ACES* configuration.
8 from __future__ import division
13 import PyOpenColorIO as ocio
15 import aces_ocio.create_aces_colorspaces as aces
16 import aces_ocio.create_arri_colorspaces as arri
17 import aces_ocio.create_canon_colorspaces as canon
18 import aces_ocio.create_gopro_colorspaces as gopro
19 import aces_ocio.create_panasonic_colorspaces as panasonic
20 import aces_ocio.create_red_colorspaces as red
21 import aces_ocio.create_sony_colorspaces as sony
22 import aces_ocio.create_general_colorspaces as general
24 from aces_ocio.process import Process
26 __author__ = 'ACES Developers'
27 __copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers'
29 __maintainer__ = 'ACES Developers'
30 __email__ = 'aces@oscars.org'
31 __status__ = 'Production'
33 __all__ = ['ACES_OCIO_CTL_DIRECTORY_ENVIRON',
34 'ACES_OCIO_CONFIGURATION_DIRECTORY_ENVIRON',
35 'set_config_default_roles',
37 'generate_OCIO_transform',
38 'add_colorspace_alias',
41 'generate_baked_LUTs',
46 ACES_OCIO_CTL_DIRECTORY_ENVIRON = 'ACES_OCIO_CTL_DIRECTORY'
47 ACES_OCIO_CONFIGURATION_DIRECTORY_ENVIRON = 'ACES_OCIO_CONFIGURATION_DIRECTORY'
50 def set_config_default_roles(config,
61 Sets given *OCIO* configuration default roles.
67 color_picking : str or unicode
68 Color picking role title.
69 color_timing : str or unicode
70 Color timing role title.
71 compositing_log : str or unicode
72 Compositing log role title.
75 default : str or unicode
77 matte_paint : str or unicode
78 Matte painting role title.
79 reference : str or unicode
81 scene_linear : str or unicode
82 Scene linear role title.
83 texture_paint : str or unicode
84 Texture painting role title.
93 config.setRole(ocio.Constants.ROLE_COLOR_PICKING, color_picking)
95 config.setRole(ocio.Constants.ROLE_COLOR_TIMING, color_timing)
97 config.setRole(ocio.Constants.ROLE_COMPOSITING_LOG, compositing_log)
99 config.setRole(ocio.Constants.ROLE_DATA, data)
101 config.setRole(ocio.Constants.ROLE_DEFAULT, default)
103 config.setRole(ocio.Constants.ROLE_MATTE_PAINT, matte_paint)
105 config.setRole(ocio.Constants.ROLE_REFERENCE, reference)
107 config.setRole(ocio.Constants.ROLE_SCENE_LINEAR, scene_linear)
109 config.setRole(ocio.Constants.ROLE_TEXTURE_PAINT, texture_paint)
114 def write_config(config, config_path, sanity_check=True):
116 Writes the configuration to given path.
121 Parameter description.
126 Return value description.
134 print 'Configuration was not written due to a failed Sanity Check'
137 with open(config_path, mode='w') as fp:
138 fp.write(config.serialize())
141 def generate_OCIO_transform(transforms):
148 Parameter description.
153 Return value description.
156 interpolation_options = {
157 'linear': ocio.Constants.INTERP_LINEAR,
158 'nearest': ocio.Constants.INTERP_NEAREST,
159 'tetrahedral': ocio.Constants.INTERP_TETRAHEDRAL}
161 direction_options = {
162 'forward': ocio.Constants.TRANSFORM_DIR_FORWARD,
163 'inverse': ocio.Constants.TRANSFORM_DIR_INVERSE}
167 for transform in transforms:
170 if transform['type'] == 'lutFile':
171 ocio_transform = ocio.FileTransform(
172 src=transform['path'],
173 interpolation=interpolation_options[
174 transform['interpolation']],
175 direction=direction_options[transform['direction']])
176 ocio_transforms.append(ocio_transform)
179 elif transform['type'] == 'matrix':
180 ocio_transform = ocio.MatrixTransform()
181 # MatrixTransform member variables can't be initialized directly.
182 # Each must be set individually.
183 ocio_transform.setMatrix(transform['matrix'])
185 if 'offset' in transform:
186 ocio_transform.setOffset(transform['offset'])
188 if 'direction' in transform:
189 ocio_transform.setDirection(
190 direction_options[transform['direction']])
192 ocio_transforms.append(ocio_transform)
195 elif transform['type'] == 'exponent':
196 ocio_transform = ocio.ExponentTransform()
197 ocio_transform.setValue(transform['value'])
198 ocio_transforms.append(ocio_transform)
201 elif transform['type'] == 'log':
202 ocio_transform = ocio.LogTransform(
203 base=transform['base'],
204 direction=direction_options[transform['direction']])
206 ocio_transforms.append(ocio_transform)
208 # color space transform
209 elif transform['type'] == 'colorspace':
210 ocio_transform = ocio.ColorSpaceTransform(src=transform['src'],
211 dst=transform['dst'],
215 ocio_transforms.append(ocio_transform)
218 print("Ignoring unknown transform type : %s" % transform['type'])
220 if len(ocio_transforms) > 1:
221 group_transform = ocio.GroupTransform()
222 for transform in ocio_transforms:
223 group_transform.push_back(transform)
224 transform = group_transform
226 transform = ocio_transforms[0]
231 def add_colorspace_alias(config,
232 reference_colorspace,
234 colorspace_alias_names):
241 Parameter description.
246 Return value description.
249 for alias_name in colorspace_alias_names:
250 if alias_name == colorspace.name.lower():
253 print('Adding alias colorspace space %s, alias to %s' % (
254 alias_name, colorspace.name))
256 compact_family_name = 'Aliases'
258 ocio_colorspace_alias = ocio.ColorSpace(
260 bitDepth=colorspace.bit_depth,
261 description=colorspace.description,
262 equalityGroup=colorspace.equality_group,
263 family=compact_family_name,
264 isData=colorspace.is_data,
265 allocation=colorspace.allocation_type,
266 allocationVars=colorspace.allocation_vars)
268 if not colorspace.to_reference_transforms:
269 print('Generating To-Reference transforms')
270 ocio_transform = generate_OCIO_transform(
271 [{'type': 'colorspace',
272 'src': colorspace.name,
273 'dst': reference_colorspace.name,
274 'direction': 'forward'}])
275 ocio_colorspace_alias.setTransform(
277 ocio.Constants.COLORSPACE_DIR_TO_REFERENCE)
279 if not colorspace.from_reference_transforms:
280 print('Generating From-Reference transforms')
281 ocio_transform = generate_OCIO_transform(
282 [{'type': 'colorspace',
283 'src': reference_colorspace.name,
284 'dst': colorspace.name,
285 'direction': 'forward'}])
286 ocio_colorspace_alias.setTransform(
288 ocio.Constants.COLORSPACE_DIR_FROM_REFERENCE)
290 config.addColorSpace(ocio_colorspace_alias)
293 def create_config(config_data, nuke=False):
300 Parameter description.
305 Return value description.
308 # Creating the *OCIO* configuration.
309 config = ocio.Config()
311 # Setting configuration overall values.
312 config.setDescription('An ACES config generated from python')
313 config.setSearchPath('luts')
315 # Defining the reference colorspace.
316 reference_data = config_data['referenceColorSpace']
317 print('Adding the reference color space : %s' % reference_data.name)
319 reference = ocio.ColorSpace(
320 name=reference_data.name,
321 bitDepth=reference_data.bit_depth,
322 description=reference_data.description,
323 equalityGroup=reference_data.equality_group,
324 family=reference_data.family,
325 isData=reference_data.is_data,
326 allocation=reference_data.allocation_type,
327 allocationVars=reference_data.allocation_vars)
329 config.addColorSpace(reference)
333 if reference_data.aliases != []:
334 add_colorspace_alias(config, reference_data,
335 reference_data, reference_data.aliases)
339 # Creating the remaining colorspaces.
340 for colorspace in sorted(config_data['colorSpaces']):
341 print('Creating new color space : %s' % colorspace.name)
343 ocio_colorspace = ocio.ColorSpace(
344 name=colorspace.name,
345 bitDepth=colorspace.bit_depth,
346 description=colorspace.description,
347 equalityGroup=colorspace.equality_group,
348 family=colorspace.family,
349 isData=colorspace.is_data,
350 allocation=colorspace.allocation_type,
351 allocationVars=colorspace.allocation_vars)
353 if colorspace.to_reference_transforms:
354 print('Generating To-Reference transforms')
355 ocio_transform = generate_OCIO_transform(
356 colorspace.to_reference_transforms)
357 ocio_colorspace.setTransform(
359 ocio.Constants.COLORSPACE_DIR_TO_REFERENCE)
361 if colorspace.from_reference_transforms:
362 print('Generating From-Reference transforms')
363 ocio_transform = generate_OCIO_transform(
364 colorspace.from_reference_transforms)
365 ocio_colorspace.setTransform(
367 ocio.Constants.COLORSPACE_DIR_FROM_REFERENCE)
369 config.addColorSpace(ocio_colorspace)
372 # Add alias to normal colorspace, using compact name
375 if colorspace.aliases != []:
376 add_colorspace_alias(config, reference_data,
377 colorspace, colorspace.aliases)
381 # Defining the *views* and *displays*.
385 # Defining a *generic* *display* and *view* setup.
387 for display, view_list in config_data['displays'].iteritems():
388 for view_name, colorspace in view_list.iteritems():
389 config.addDisplay(display, view_name, colorspace.name)
390 if not (view_name in views):
391 views.append(view_name)
392 displays.append(display)
394 # Defining the *Nuke* specific set of *views* and *displays*.
396 display_name = 'ACES'
397 displays.append(display_name)
399 display_names = sorted(config_data['displays'])
400 for display in display_names:
401 view_list = config_data['displays'][display]
402 for view_name, colorspace in view_list.iteritems():
403 if view_name == 'Output Transform':
404 config.addDisplay(display_name, display, colorspace.name)
405 if not (display in views):
406 views.append(display)
408 # Works with Nuke Studio and Mari, but not Nuke
409 # display_name = 'Utility'
410 #displays.append(display_name)
412 linear_display_space_name = config_data['linearDisplaySpace'].name
413 log_display_space_name = config_data['logDisplaySpace'].name
415 config.addDisplay(display_name, 'Linear', linear_display_space_name)
416 views.append('Linear')
417 config.addDisplay(display_name, 'Log', log_display_space_name)
420 # Setting the active *displays* and *views*.
421 config.setActiveDisplays(','.join(sorted(displays)))
422 config.setActiveViews(','.join(views))
424 set_config_default_roles(
426 color_picking=config_data['roles']['color_picking'],
427 color_timing=config_data['roles']['color_timing'],
428 compositing_log=config_data['roles']['compositing_log'],
429 data=config_data['roles']['data'],
430 default=config_data['roles']['default'],
431 matte_paint=config_data['roles']['matte_paint'],
432 reference=config_data['roles']['reference'],
433 scene_linear=config_data['roles']['scene_linear'],
434 texture_paint=config_data['roles']['texture_paint'])
441 def generate_LUTs(odt_info,
446 lut_resolution_1d=4096,
447 lut_resolution_3d=64,
455 Parameter description.
460 Colorspaces and transforms converting between those colorspaces and
461 the reference colorspace, *ACES*.
464 print('generateLUTs - begin')
467 # Initialize a few variables
468 config_data['displays'] = {}
469 config_data['colorSpaces'] = []
471 # -------------------------------------------------------------------------
472 # *ACES Color Spaces*
473 # -------------------------------------------------------------------------
479 aces_log_display_space,
480 aces_roles) = aces.create_colorspaces(aces_ctl_directory,
489 config_data['referenceColorSpace'] = aces_reference
490 config_data['roles'] = aces_roles
492 for cs in aces_colorspaces:
493 config_data['colorSpaces'].append(cs)
495 for name, data in aces_displays.iteritems():
496 config_data['displays'][name] = data
498 config_data['linearDisplaySpace'] = aces_reference
499 config_data['logDisplaySpace'] = aces_log_display_space
501 # -------------------------------------------------------------------------
502 # *Camera Input Transforms*
503 # -------------------------------------------------------------------------
505 # *ARRI Log-C* to *ACES*.
506 arri_colorSpaces = arri.create_colorspaces(lut_directory,
508 for cs in arri_colorSpaces:
509 config_data['colorSpaces'].append(cs)
511 # *Canon-Log* to *ACES*.
512 canon_colorspaces = canon.create_colorspaces(lut_directory,
514 for cs in canon_colorspaces:
515 config_data['colorSpaces'].append(cs)
517 # *GoPro Protune* to *ACES*.
518 gopro_colorspaces = gopro.create_colorspaces(lut_directory,
520 for cs in gopro_colorspaces:
521 config_data['colorSpaces'].append(cs)
523 # *Panasonic V-Log* to *ACES*.
524 panasonic_colorSpaces = panasonic.create_colorspaces(lut_directory,
526 for cs in panasonic_colorSpaces:
527 config_data['colorSpaces'].append(cs)
529 # *RED* colorspaces to *ACES*.
530 red_colorspaces = red.create_colorspaces(lut_directory,
532 for cs in red_colorspaces:
533 config_data['colorSpaces'].append(cs)
536 sony_colorSpaces = sony.create_colorspaces(lut_directory,
538 for cs in sony_colorSpaces:
539 config_data['colorSpaces'].append(cs)
541 # -------------------------------------------------------------------------
542 # General Color Spaces
543 # -------------------------------------------------------------------------
544 general_colorSpaces = general.create_colorspaces(lut_directory,
547 for cs in general_colorSpaces:
548 config_data['colorSpaces'].append(cs)
550 # The *Raw* color space
551 raw = general.create_raw()
552 config_data['colorSpaces'].append(raw)
554 # Override certain roles, for now
555 config_data['roles']['data'] = raw.name
556 config_data['roles']['reference'] = raw.name
557 config_data['roles']['texture_paint'] = raw.name
559 print('generateLUTs - end')
563 def generate_baked_LUTs(odt_info,
569 lut_resolution_shaper=1024):
576 Parameter description.
581 Return value description.
584 # Create two entries for ODTs that have full and legal range support
585 odt_info_C = dict(odt_info)
586 for odt_ctl_name, odt_values in odt_info.iteritems():
587 if odt_values['transformHasFullLegalSwitch']:
588 odt_name = odt_values['transformUserName']
590 odt_values_legal = dict(odt_values)
591 odt_values_legal['transformUserName'] = '%s - Legal' % odt_name
592 odt_info_C['%s - Legal' % odt_ctl_name] = odt_values_legal
594 odt_values_full = dict(odt_values)
595 odt_values_full['transformUserName'] = '%s - Full' % odt_name
596 odt_info_C['%s - Full' % odt_ctl_name] = odt_values_full
598 del (odt_info_C[odt_ctl_name])
600 # Generate appropriate LUTs for each ODT
601 for odt_ctl_name, odt_values in odt_info_C.iteritems():
602 odt_prefix = odt_values['transformUserNamePrefix']
603 odt_name = odt_values['transformUserName']
606 for input_space in ['ACEScc', 'ACESproxy']:
607 args = ['--iconfig', config_path,
609 '--inputspace', input_space]
610 args += ['--outputspace', '%s' % odt_name]
611 args += ['--description',
612 '%s - %s for %s data' % (odt_prefix,
615 args += ['--shaperspace', shaper_name,
616 '--shapersize', str(lut_resolution_shaper)]
617 args += ['--cubesize', str(lut_resolution_3d)]
620 os.path.join(baked_directory,
622 '%s for %s.icc' % (odt_name, input_space))]
624 bake_lut = Process(description='bake a LUT',
630 for input_space in ['ACEScc', 'ACESproxy']:
631 args = ['--iconfig', config_path,
633 '--inputspace', input_space]
634 args += ['--outputspace', '%s' % odt_name]
635 args += ['--description',
636 '%s - %s for %s data' % (
637 odt_prefix, odt_name, input_space)]
638 args += ['--shaperspace', shaper_name,
639 '--shapersize', str(lut_resolution_shaper)]
640 args += ['--cubesize', str(lut_resolution_3d)]
647 '%s for %s Flame.3dl' % (odt_name, input_space))]
648 bake_lut = Process(description='bake a LUT',
658 '%s for %s Lustre.3dl' % (odt_name, input_space))]
659 bake_lut = Process(description='bake a LUT',
665 for input_space in ['ACEScg', 'ACES2065-1']:
666 args = ['--iconfig', config_path,
668 '--inputspace', input_space]
669 args += ['--outputspace', '%s' % odt_name]
670 args += ['--description',
671 '%s - %s for %s data' % (
672 odt_prefix, odt_name, input_space)]
673 if input_space == 'ACEScg':
674 lin_shaper_name = '%s - AP1' % shaper_name
676 lin_shaper_name = shaper_name
677 args += ['--shaperspace', lin_shaper_name,
678 '--shapersize', str(lut_resolution_shaper)]
680 args += ['--cubesize', str(lut_resolution_3d)]
687 '%s for %s Maya.csp' % (odt_name, input_space))]
688 bake_lut = Process(description='bake a LUT',
698 '%s for %s Houdini.lut' % (odt_name, input_space))]
699 bake_lut = Process(description='bake a LUT',
705 def create_config_dir(config_directory, bake_secondary_LUTs):
712 Parameter description.
717 Return value description.
720 lut_directory = os.path.join(config_directory, 'luts')
721 dirs = [config_directory, lut_directory]
722 if bake_secondary_LUTs:
723 dirs.extend([os.path.join(config_directory, 'baked'),
724 os.path.join(config_directory, 'baked', 'flame'),
725 os.path.join(config_directory, 'baked', 'photoshop'),
726 os.path.join(config_directory, 'baked', 'houdini'),
727 os.path.join(config_directory, 'baked', 'lustre'),
728 os.path.join(config_directory, 'baked', 'maya')])
731 not os.path.exists(d) and os.mkdir(d)
736 def create_ACES_config(aces_ctl_directory,
738 lut_resolution_1d=4096,
739 lut_resolution_3d=64,
740 bake_secondary_LUTs=True,
743 Creates the ACES configuration.
748 Parameter description.
753 Return value description.
756 lut_directory = create_config_dir(config_directory, bake_secondary_LUTs)
758 odt_info = aces.get_ODTs_info(aces_ctl_directory)
759 lmt_info = aces.get_LMTs_info(aces_ctl_directory)
761 shaper_name = 'Output Shaper'
762 config_data = generate_LUTs(odt_info,
771 print('Creating "generic" config')
772 config = create_config(config_data)
776 os.path.join(config_directory, 'config.ocio'))
778 print('Creating "Nuke" config')
779 nuke_config = create_config(config_data, nuke=True)
782 write_config(nuke_config,
783 os.path.join(config_directory, 'nuke_config.ocio'))
785 if bake_secondary_LUTs:
786 generate_baked_LUTs(odt_info,
788 os.path.join(config_directory, 'baked'),
789 os.path.join(config_directory, 'config.ocio'),
804 Parameter description.
809 Return value description.
814 p = optparse.OptionParser(description='An OCIO config generation script',
815 prog='createACESConfig',
816 version='createACESConfig 0.1',
817 usage='%prog [options]')
818 p.add_option('--acesCTLDir', '-a', default=os.environ.get(
819 ACES_OCIO_CTL_DIRECTORY_ENVIRON, None))
820 p.add_option('--configDir', '-c', default=os.environ.get(
821 ACES_OCIO_CONFIGURATION_DIRECTORY_ENVIRON, None))
822 p.add_option('--lutResolution1d', default=4096)
823 p.add_option('--lutResolution3d', default=64)
824 p.add_option('--dontBakeSecondaryLUTs', action='store_true')
825 p.add_option('--keepTempImages', action='store_true')
827 options, arguments = p.parse_args()
829 aces_ctl_directory = options.acesCTLDir
830 config_directory = options.configDir
831 lut_resolution_1d = int(options.lutResolution1d)
832 lut_resolution_3d = int(options.lutResolution3d)
833 bake_secondary_luts = not options.dontBakeSecondaryLUTs
834 cleanup_temp_images = not options.keepTempImages
836 # TODO: Investigate the following statements.
838 args_start = sys.argv.index('--') + 1
839 args = sys.argv[args_start:]
841 args_start = len(sys.argv) + 1
844 print('command line : \n%s\n' % ' '.join(sys.argv))
846 assert aces_ctl_directory is not None, (
847 'process: No "{0}" environment variable defined or no "ACES CTL" '
848 'directory specified'.format(
849 ACES_OCIO_CTL_DIRECTORY_ENVIRON))
851 assert config_directory is not None, (
852 'process: No "{0}" environment variable defined or no configuration '
853 'directory specified'.format(
854 ACES_OCIO_CONFIGURATION_DIRECTORY_ENVIRON))
856 return create_ACES_config(aces_ctl_directory,
864 if __name__ == '__main__':