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)
332 if reference_data.aliases != []:
333 add_colorspace_alias(config, reference_data,
334 reference_data, reference_data.aliases)
338 # Creating the remaining colorspaces.
339 for colorspace in sorted(config_data['colorSpaces']):
340 print('Creating new color space : %s' % colorspace.name)
342 ocio_colorspace = ocio.ColorSpace(
343 name=colorspace.name,
344 bitDepth=colorspace.bit_depth,
345 description=colorspace.description,
346 equalityGroup=colorspace.equality_group,
347 family=colorspace.family,
348 isData=colorspace.is_data,
349 allocation=colorspace.allocation_type,
350 allocationVars=colorspace.allocation_vars)
352 if colorspace.to_reference_transforms:
353 print('Generating To-Reference transforms')
354 ocio_transform = generate_OCIO_transform(
355 colorspace.to_reference_transforms)
356 ocio_colorspace.setTransform(
358 ocio.Constants.COLORSPACE_DIR_TO_REFERENCE)
360 if colorspace.from_reference_transforms:
361 print('Generating From-Reference transforms')
362 ocio_transform = generate_OCIO_transform(
363 colorspace.from_reference_transforms)
364 ocio_colorspace.setTransform(
366 ocio.Constants.COLORSPACE_DIR_FROM_REFERENCE)
368 config.addColorSpace(ocio_colorspace)
371 # Add alias to normal colorspace, using compact name
373 if colorspace.aliases != []:
374 add_colorspace_alias(config, reference_data,
375 colorspace, colorspace.aliases)
379 # Defining the *views* and *displays*.
383 # Defining a *generic* *display* and *view* setup.
385 for display, view_list in config_data['displays'].iteritems():
386 for view_name, colorspace in view_list.iteritems():
387 config.addDisplay(display, view_name, colorspace.name)
388 if not (view_name in views):
389 views.append(view_name)
390 displays.append(display)
392 # Defining the *Nuke* specific set of *views* and *displays*.
394 display_name = 'Output'
395 displays.append(display_name)
397 display_names = sorted(config_data['displays'])
398 for display in display_names:
399 view_list = config_data['displays'][display]
400 for view_name, colorspace in view_list.iteritems():
401 if view_name == 'Output Transform':
402 config.addDisplay(display_name, display, colorspace.name)
403 if not (display in views):
404 views.append(display)
406 linear_display_space_name = config_data['linearDisplaySpace'].name
407 log_display_space_name = config_data['logDisplaySpace'].name
409 config.addDisplay(display_name, 'Linear', linear_display_space_name)
410 views.append('Linear')
411 config.addDisplay(display_name, 'Log', log_display_space_name)
414 # Setting the active *displays* and *views*.
415 config.setActiveDisplays(','.join(sorted(displays)))
416 config.setActiveViews(','.join(views))
418 set_config_default_roles(
420 color_picking=config_data['roles']['color_picking'],
421 color_timing=config_data['roles']['color_timing'],
422 compositing_log=config_data['roles']['compositing_log'],
423 data=config_data['roles']['data'],
424 default=config_data['roles']['default'],
425 matte_paint=config_data['roles']['matte_paint'],
426 reference=config_data['roles']['reference'],
427 scene_linear=config_data['roles']['scene_linear'],
428 texture_paint=config_data['roles']['texture_paint'])
435 def generate_LUTs(odt_info,
440 lut_resolution_1d=4096,
441 lut_resolution_3d=64,
449 Parameter description.
454 Colorspaces and transforms converting between those colorspaces and
455 the reference colorspace, *ACES*.
458 print('generateLUTs - begin')
461 # Initialize a few variables
462 config_data['displays'] = {}
463 config_data['colorSpaces'] = []
465 # -------------------------------------------------------------------------
466 # *ACES Color Spaces*
467 # -------------------------------------------------------------------------
473 aces_log_display_space,
474 aces_roles) = aces.create_colorspaces(aces_ctl_directory,
483 config_data['referenceColorSpace'] = aces_reference
484 config_data['roles'] = aces_roles
486 for cs in aces_colorspaces:
487 config_data['colorSpaces'].append(cs)
489 for name, data in aces_displays.iteritems():
490 config_data['displays'][name] = data
492 config_data['linearDisplaySpace'] = aces_reference
493 config_data['logDisplaySpace'] = aces_log_display_space
495 # -------------------------------------------------------------------------
496 # *Camera Input Transforms*
497 # -------------------------------------------------------------------------
499 # *ARRI Log-C* to *ACES*.
500 arri_colorSpaces = arri.create_colorspaces(lut_directory,
502 for cs in arri_colorSpaces:
503 config_data['colorSpaces'].append(cs)
505 # *Canon-Log* to *ACES*.
506 canon_colorspaces = canon.create_colorspaces(lut_directory,
508 for cs in canon_colorspaces:
509 config_data['colorSpaces'].append(cs)
511 # *GoPro Protune* to *ACES*.
512 gopro_colorspaces = gopro.create_colorspaces(lut_directory,
514 for cs in gopro_colorspaces:
515 config_data['colorSpaces'].append(cs)
517 # *Panasonic V-Log* to *ACES*.
518 panasonic_colorSpaces = panasonic.create_colorspaces(lut_directory,
520 for cs in panasonic_colorSpaces:
521 config_data['colorSpaces'].append(cs)
523 # *RED* colorspaces to *ACES*.
524 red_colorspaces = red.create_colorspaces(lut_directory,
526 for cs in red_colorspaces:
527 config_data['colorSpaces'].append(cs)
530 sony_colorSpaces = sony.create_colorspaces(lut_directory,
532 for cs in sony_colorSpaces:
533 config_data['colorSpaces'].append(cs)
535 # -------------------------------------------------------------------------
536 # General Color Spaces
537 # -------------------------------------------------------------------------
538 general_colorSpaces = general.create_colorspaces(lut_directory,
541 for cs in general_colorSpaces:
542 config_data['colorSpaces'].append(cs)
544 # The *Raw* color space
545 raw = general.create_raw()
546 config_data['colorSpaces'].append(raw)
548 # Override certain roles, for now
549 config_data['roles']['data'] = raw.name
550 config_data['roles']['reference'] = raw.name
551 config_data['roles']['texture_paint'] = raw.name
553 print('generateLUTs - end')
557 def generate_baked_LUTs(odt_info,
563 lut_resolution_shaper=1024):
570 Parameter description.
575 Return value description.
578 # Create two entries for ODTs that have full and legal range support
579 odt_info_C = dict(odt_info)
580 for odt_ctl_name, odt_values in odt_info.iteritems():
581 if odt_values['transformHasFullLegalSwitch']:
582 odt_name = odt_values['transformUserName']
584 odt_values_legal = dict(odt_values)
585 odt_values_legal['transformUserName'] = '%s - Legal' % odt_name
586 odt_info_C['%s - Legal' % odt_ctl_name] = odt_values_legal
588 odt_values_full = dict(odt_values)
589 odt_values_full['transformUserName'] = '%s - Full' % odt_name
590 odt_info_C['%s - Full' % odt_ctl_name] = odt_values_full
592 del (odt_info_C[odt_ctl_name])
594 # Generate appropriate LUTs for each ODT
595 for odt_ctl_name, odt_values in odt_info_C.iteritems():
596 odt_prefix = odt_values['transformUserNamePrefix']
597 odt_name = odt_values['transformUserName']
600 for input_space in ['ACEScc', 'ACESproxy']:
601 args = ['--iconfig', config_path,
603 '--inputspace', input_space]
604 args += ['--outputspace', '%s' % odt_name]
605 args += ['--description',
606 '%s - %s for %s data' % (odt_prefix,
609 args += ['--shaperspace', shaper_name,
610 '--shapersize', str(lut_resolution_shaper)]
611 args += ['--cubesize', str(lut_resolution_3d)]
614 os.path.join(baked_directory,
616 '%s for %s.icc' % (odt_name, input_space))]
618 bake_lut = Process(description='bake a LUT',
624 for input_space in ['ACEScc', 'ACESproxy']:
625 args = ['--iconfig', config_path,
627 '--inputspace', input_space]
628 args += ['--outputspace', '%s' % odt_name]
629 args += ['--description',
630 '%s - %s for %s data' % (
631 odt_prefix, odt_name, input_space)]
632 args += ['--shaperspace', shaper_name,
633 '--shapersize', str(lut_resolution_shaper)]
634 args += ['--cubesize', str(lut_resolution_3d)]
641 '%s for %s Flame.3dl' % (odt_name, input_space))]
642 bake_lut = Process(description='bake a LUT',
652 '%s for %s Lustre.3dl' % (odt_name, input_space))]
653 bake_lut = Process(description='bake a LUT',
659 for input_space in ['ACEScg', 'ACES2065-1']:
660 args = ['--iconfig', config_path,
662 '--inputspace', input_space]
663 args += ['--outputspace', '%s' % odt_name]
664 args += ['--description',
665 '%s - %s for %s data' % (
666 odt_prefix, odt_name, input_space)]
667 if input_space == 'ACEScg':
668 lin_shaper_name = '%s - AP1' % shaper_name
670 lin_shaper_name = shaper_name
671 args += ['--shaperspace', lin_shaper_name,
672 '--shapersize', str(lut_resolution_shaper)]
674 args += ['--cubesize', str(lut_resolution_3d)]
681 '%s for %s Maya.csp' % (odt_name, input_space))]
682 bake_lut = Process(description='bake a LUT',
692 '%s for %s Houdini.lut' % (odt_name, input_space))]
693 bake_lut = Process(description='bake a LUT',
699 def create_config_dir(config_directory, bake_secondary_LUTs):
706 Parameter description.
711 Return value description.
714 lut_directory = os.path.join(config_directory, 'luts')
715 dirs = [config_directory, lut_directory]
716 if bake_secondary_LUTs:
717 dirs.extend([os.path.join(config_directory, 'baked'),
718 os.path.join(config_directory, 'baked', 'flame'),
719 os.path.join(config_directory, 'baked', 'photoshop'),
720 os.path.join(config_directory, 'baked', 'houdini'),
721 os.path.join(config_directory, 'baked', 'lustre'),
722 os.path.join(config_directory, 'baked', 'maya')])
725 not os.path.exists(d) and os.mkdir(d)
730 def create_ACES_config(aces_ctl_directory,
732 lut_resolution_1d=4096,
733 lut_resolution_3d=64,
734 bake_secondary_LUTs=True,
737 Creates the ACES configuration.
742 Parameter description.
747 Return value description.
750 lut_directory = create_config_dir(config_directory, bake_secondary_LUTs)
752 odt_info = aces.get_ODTs_info(aces_ctl_directory)
753 lmt_info = aces.get_LMTs_info(aces_ctl_directory)
755 shaper_name = 'Output Shaper'
756 config_data = generate_LUTs(odt_info,
765 print('Creating "generic" config')
766 config = create_config(config_data)
770 os.path.join(config_directory, 'config.ocio'))
772 print('Creating "Nuke" config')
773 nuke_config = create_config(config_data, nuke=True)
776 write_config(nuke_config,
777 os.path.join(config_directory, 'nuke_config.ocio'))
779 if bake_secondary_LUTs:
780 generate_baked_LUTs(odt_info,
782 os.path.join(config_directory, 'baked'),
783 os.path.join(config_directory, 'config.ocio'),
798 Parameter description.
803 Return value description.
808 p = optparse.OptionParser(description='An OCIO config generation script',
809 prog='createACESConfig',
810 version='createACESConfig 0.1',
811 usage='%prog [options]')
812 p.add_option('--acesCTLDir', '-a', default=os.environ.get(
813 ACES_OCIO_CTL_DIRECTORY_ENVIRON, None))
814 p.add_option('--configDir', '-c', default=os.environ.get(
815 ACES_OCIO_CONFIGURATION_DIRECTORY_ENVIRON, None))
816 p.add_option('--lutResolution1d', default=4096)
817 p.add_option('--lutResolution3d', default=64)
818 p.add_option('--dontBakeSecondaryLUTs', action='store_true')
819 p.add_option('--keepTempImages', action='store_true')
821 options, arguments = p.parse_args()
823 aces_ctl_directory = options.acesCTLDir
824 config_directory = options.configDir
825 lut_resolution_1d = int(options.lutResolution1d)
826 lut_resolution_3d = int(options.lutResolution3d)
827 bake_secondary_luts = not options.dontBakeSecondaryLUTs
828 cleanup_temp_images = not options.keepTempImages
830 # TODO: Investigate the following statements.
832 args_start = sys.argv.index('--') + 1
833 args = sys.argv[args_start:]
835 args_start = len(sys.argv) + 1
838 print('command line : \n%s\n' % ' '.join(sys.argv))
840 assert aces_ctl_directory is not None, (
841 'process: No "{0}" environment variable defined or no "ACES CTL" '
842 'directory specified'.format(
843 ACES_OCIO_CTL_DIRECTORY_ENVIRON))
845 assert config_directory is not None, (
846 'process: No "{0}" environment variable defined or no configuration '
847 'directory specified'.format(
848 ACES_OCIO_CONFIGURATION_DIRECTORY_ENVIRON))
850 return create_ACES_config(aces_ctl_directory,
858 if __name__ == '__main__':