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_panasonic_colorspaces as panasonic
19 import aces_ocio.create_red_colorspaces as red
20 import aces_ocio.create_sony_colorspaces as sony
21 import aces_ocio.create_general_colorspaces as general
23 from aces_ocio.process import Process
25 __author__ = 'ACES Developers'
26 __copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers'
28 __maintainer__ = 'ACES Developers'
29 __email__ = 'aces@oscars.org'
30 __status__ = 'Production'
32 __all__ = ['ACES_OCIO_CTL_DIRECTORY_ENVIRON',
33 'ACES_OCIO_CONFIGURATION_DIRECTORY_ENVIRON',
34 'set_config_default_roles',
36 'generate_OCIO_transform',
37 'add_colorspace_alias',
40 'generate_baked_LUTs',
45 ACES_OCIO_CTL_DIRECTORY_ENVIRON = 'ACES_OCIO_CTL_DIRECTORY'
46 ACES_OCIO_CONFIGURATION_DIRECTORY_ENVIRON = 'ACES_OCIO_CONFIGURATION_DIRECTORY'
49 def set_config_default_roles(config,
60 Sets given *OCIO* configuration default roles.
66 color_picking : str or unicode
67 Color picking role title.
68 color_timing : str or unicode
69 Color timing role title.
70 compositing_log : str or unicode
71 Compositing log role title.
74 default : str or unicode
76 matte_paint : str or unicode
77 Matte painting role title.
78 reference : str or unicode
80 scene_linear : str or unicode
81 Scene linear role title.
82 texture_paint : str or unicode
83 Texture painting role title.
92 config.setRole(ocio.Constants.ROLE_COLOR_PICKING, color_picking)
94 config.setRole(ocio.Constants.ROLE_COLOR_TIMING, color_timing)
96 config.setRole(ocio.Constants.ROLE_COMPOSITING_LOG, compositing_log)
98 config.setRole(ocio.Constants.ROLE_DATA, data)
100 config.setRole(ocio.Constants.ROLE_DEFAULT, default)
102 config.setRole(ocio.Constants.ROLE_MATTE_PAINT, matte_paint)
104 config.setRole(ocio.Constants.ROLE_REFERENCE, reference)
106 config.setRole(ocio.Constants.ROLE_SCENE_LINEAR, scene_linear)
108 config.setRole(ocio.Constants.ROLE_TEXTURE_PAINT, texture_paint)
113 def write_config(config, config_path, sanity_check=True):
115 Writes the configuration to given path.
120 Parameter description.
125 Return value description.
133 print 'Configuration was not written due to a failed Sanity Check'
136 with open(config_path, mode='w') as fp:
137 fp.write(config.serialize())
140 def generate_OCIO_transform(transforms):
147 Parameter description.
152 Return value description.
155 interpolation_options = {
156 'linear': ocio.Constants.INTERP_LINEAR,
157 'nearest': ocio.Constants.INTERP_NEAREST,
158 'tetrahedral': ocio.Constants.INTERP_TETRAHEDRAL}
160 direction_options = {
161 'forward': ocio.Constants.TRANSFORM_DIR_FORWARD,
162 'inverse': ocio.Constants.TRANSFORM_DIR_INVERSE}
166 for transform in transforms:
169 if transform['type'] == 'lutFile':
170 ocio_transform = ocio.FileTransform(
171 src=transform['path'],
172 interpolation=interpolation_options[
173 transform['interpolation']],
174 direction=direction_options[transform['direction']])
175 ocio_transforms.append(ocio_transform)
178 elif transform['type'] == 'matrix':
179 ocio_transform = ocio.MatrixTransform()
180 # MatrixTransform member variables can't be initialized directly.
181 # Each must be set individually.
182 ocio_transform.setMatrix(transform['matrix'])
184 if 'offset' in transform:
185 ocio_transform.setOffset(transform['offset'])
187 if 'direction' in transform:
188 ocio_transform.setDirection(
189 direction_options[transform['direction']])
191 ocio_transforms.append(ocio_transform)
194 elif transform['type'] == 'exponent':
195 ocio_transform = ocio.ExponentTransform()
196 ocio_transform.setValue(transform['value'])
197 ocio_transforms.append(ocio_transform)
200 elif transform['type'] == 'log':
201 ocio_transform = ocio.LogTransform(
202 base=transform['base'],
203 direction=direction_options[transform['direction']])
205 ocio_transforms.append(ocio_transform)
207 # color space transform
208 elif transform['type'] == 'colorspace':
209 ocio_transform = ocio.ColorSpaceTransform(src=transform['src'],
210 dst=transform['dst'],
214 ocio_transforms.append(ocio_transform)
217 print("Ignoring unknown transform type : %s" % transform['type'])
219 if len(ocio_transforms) > 1:
220 group_transform = ocio.GroupTransform()
221 for transform in ocio_transforms:
222 group_transform.push_back(transform)
223 transform = group_transform
225 transform = ocio_transforms[0]
230 def add_colorspace_alias(config,
231 reference_colorspace,
233 colorspace_alias_names):
240 Parameter description.
245 Return value description.
248 for alias_name in colorspace_alias_names:
249 if alias_name == colorspace.name.lower():
252 print('Adding alias colorspace space %s, alias to %s' % (
253 alias_name, colorspace.name))
255 compact_family_name = 'Aliases'
257 ocio_colorspace_alias = ocio.ColorSpace(
259 bitDepth=colorspace.bit_depth,
260 description=colorspace.description,
261 equalityGroup=colorspace.equality_group,
262 family=compact_family_name,
263 isData=colorspace.is_data,
264 allocation=colorspace.allocation_type,
265 allocationVars=colorspace.allocation_vars)
267 if not colorspace.to_reference_transforms:
268 print('Generating To-Reference transforms')
269 ocio_transform = generate_OCIO_transform(
270 [{'type': 'colorspace',
271 'src': colorspace.name,
272 'dst': reference_colorspace.name,
273 'direction': 'forward'}])
274 ocio_colorspace_alias.setTransform(
276 ocio.Constants.COLORSPACE_DIR_TO_REFERENCE)
278 if not colorspace.from_reference_transforms:
279 print('Generating From-Reference transforms')
280 ocio_transform = generate_OCIO_transform(
281 [{'type': 'colorspace',
282 'src': reference_colorspace.name,
283 'dst': colorspace.name,
284 'direction': 'forward'}])
285 ocio_colorspace_alias.setTransform(
287 ocio.Constants.COLORSPACE_DIR_FROM_REFERENCE)
289 config.addColorSpace(ocio_colorspace_alias)
292 def create_config(config_data, nuke=False):
299 Parameter description.
304 Return value description.
307 # Creating the *OCIO* configuration.
308 config = ocio.Config()
310 # Setting configuration overall values.
311 config.setDescription('An ACES config generated from python')
312 config.setSearchPath('luts')
314 # Defining the reference colorspace.
315 reference_data = config_data['referenceColorSpace']
316 print('Adding the reference color space : %s' % reference_data.name)
318 reference = ocio.ColorSpace(
319 name=reference_data.name,
320 bitDepth=reference_data.bit_depth,
321 description=reference_data.description,
322 equalityGroup=reference_data.equality_group,
323 family=reference_data.family,
324 isData=reference_data.is_data,
325 allocation=reference_data.allocation_type,
326 allocationVars=reference_data.allocation_vars)
328 config.addColorSpace(reference)
331 if reference_data.aliases != []:
332 add_colorspace_alias(config, reference_data,
333 reference_data, reference_data.aliases)
337 # Creating the remaining colorspaces.
338 for colorspace in sorted(config_data['colorSpaces']):
339 print('Creating new color space : %s' % colorspace.name)
341 ocio_colorspace = ocio.ColorSpace(
342 name=colorspace.name,
343 bitDepth=colorspace.bit_depth,
344 description=colorspace.description,
345 equalityGroup=colorspace.equality_group,
346 family=colorspace.family,
347 isData=colorspace.is_data,
348 allocation=colorspace.allocation_type,
349 allocationVars=colorspace.allocation_vars)
351 if colorspace.to_reference_transforms:
352 print('Generating To-Reference transforms')
353 ocio_transform = generate_OCIO_transform(
354 colorspace.to_reference_transforms)
355 ocio_colorspace.setTransform(
357 ocio.Constants.COLORSPACE_DIR_TO_REFERENCE)
359 if colorspace.from_reference_transforms:
360 print('Generating From-Reference transforms')
361 ocio_transform = generate_OCIO_transform(
362 colorspace.from_reference_transforms)
363 ocio_colorspace.setTransform(
365 ocio.Constants.COLORSPACE_DIR_FROM_REFERENCE)
367 config.addColorSpace(ocio_colorspace)
370 # Add alias to normal colorspace, using compact name
372 if colorspace.aliases != []:
373 add_colorspace_alias(config, reference_data,
374 colorspace, colorspace.aliases)
378 # Defining the *views* and *displays*.
382 # Defining a *generic* *display* and *view* setup.
384 for display, view_list in config_data['displays'].iteritems():
385 for view_name, colorspace in view_list.iteritems():
386 config.addDisplay(display, view_name, colorspace.name)
387 if not (view_name in views):
388 views.append(view_name)
389 displays.append(display)
391 # Defining the *Nuke* specific set of *views* and *displays*.
393 for display, view_list in config_data['displays'].iteritems():
394 for view_name, colorspace in view_list.iteritems():
395 if view_name == 'Output Transform':
397 config.addDisplay(display, view_name, colorspace.name)
398 if not (view_name in views):
399 views.append(view_name)
400 displays.append(display)
402 linear_display_space_name = config_data['linearDisplaySpace'].name
403 log_display_space_name = config_data['logDisplaySpace'].name
405 config.addDisplay('linear', 'View', linear_display_space_name)
406 displays.append('linear')
407 config.addDisplay('log', 'View', log_display_space_name)
408 displays.append('log')
410 # Setting the active *displays* and *views*.
411 config.setActiveDisplays(','.join(sorted(displays)))
412 config.setActiveViews(','.join(views))
414 set_config_default_roles(
416 color_picking=config_data['roles']['color_picking'],
417 color_timing=config_data['roles']['color_timing'],
418 compositing_log=config_data['roles']['compositing_log'],
419 data=config_data['roles']['data'],
420 default=config_data['roles']['default'],
421 matte_paint=config_data['roles']['matte_paint'],
422 reference=config_data['roles']['reference'],
423 scene_linear=config_data['roles']['scene_linear'],
424 texture_paint=config_data['roles']['texture_paint'])
431 def generate_LUTs(odt_info,
436 lut_resolution_1d=4096,
437 lut_resolution_3d=64,
445 Parameter description.
450 Colorspaces and transforms converting between those colorspaces and
451 the reference colorspace, *ACES*.
454 print('generateLUTs - begin')
457 # Initialize a few variables
458 config_data['displays'] = {}
459 config_data['colorSpaces'] = []
461 # -------------------------------------------------------------------------
462 # *ACES Color Spaces*
463 # -------------------------------------------------------------------------
469 aces_log_display_space,
470 aces_roles) = aces.create_colorspaces(aces_ctl_directory,
479 config_data['referenceColorSpace'] = aces_reference
480 config_data['roles'] = aces_roles
482 for cs in aces_colorspaces:
483 config_data['colorSpaces'].append(cs)
485 for name, data in aces_displays.iteritems():
486 config_data['displays'][name] = data
488 config_data['linearDisplaySpace'] = aces_reference
489 config_data['logDisplaySpace'] = aces_log_display_space
491 # -------------------------------------------------------------------------
492 # *Camera Input Transforms*
493 # -------------------------------------------------------------------------
495 # *ARRI Log-C* to *ACES*.
496 arri_colorSpaces = arri.create_colorspaces(lut_directory,
498 for cs in arri_colorSpaces:
499 config_data['colorSpaces'].append(cs)
501 # *Canon-Log* to *ACES*.
502 canon_colorspaces = canon.create_colorspaces(lut_directory,
504 for cs in canon_colorspaces:
505 config_data['colorSpaces'].append(cs)
507 # *Panasonic V-Log* to *ACES*.
508 panasonic_colorSpaces = panasonic.create_colorspaces(lut_directory,
510 for cs in panasonic_colorSpaces:
511 config_data['colorSpaces'].append(cs)
513 # *RED* colorspaces to *ACES*.
514 red_colorspaces = red.create_colorspaces(lut_directory,
516 for cs in red_colorspaces:
517 config_data['colorSpaces'].append(cs)
520 sony_colorSpaces = sony.create_colorspaces(lut_directory,
522 for cs in sony_colorSpaces:
523 config_data['colorSpaces'].append(cs)
525 # -------------------------------------------------------------------------
526 # General Color Spaces
527 # -------------------------------------------------------------------------
528 general_colorSpaces = general.create_colorspaces(lut_directory,
531 for cs in general_colorSpaces:
532 config_data['colorSpaces'].append(cs)
534 # The *Raw* color space
535 raw = general.create_raw()
536 config_data['colorSpaces'].append(raw)
538 # Override 'linear' display
539 config_data['linearDisplaySpace'] = raw
541 # Override certain roles, for now
542 config_data['roles']['data'] = raw.name
543 config_data['roles']['reference'] = raw.name
544 config_data['roles']['texture_paint'] = raw.name
546 print('generateLUTs - end')
550 def generate_baked_LUTs(odt_info,
556 lut_resolution_shaper=1024):
563 Parameter description.
568 Return value description.
571 # Create two entries for ODTs that have full and legal range support
572 odt_info_C = dict(odt_info)
573 for odt_ctl_name, odt_values in odt_info.iteritems():
574 if odt_values['transformHasFullLegalSwitch']:
575 odt_name = odt_values['transformUserName']
577 odt_values_legal = dict(odt_values)
578 odt_values_legal['transformUserName'] = '%s - Legal' % odt_name
579 odt_info_C['%s - Legal' % odt_ctl_name] = odt_values_legal
581 odt_values_full = dict(odt_values)
582 odt_values_full['transformUserName'] = '%s - Full' % odt_name
583 odt_info_C['%s - Full' % odt_ctl_name] = odt_values_full
585 del (odt_info_C[odt_ctl_name])
587 # Generate appropriate LUTs for each ODT
588 for odt_ctl_name, odt_values in odt_info_C.iteritems():
589 odt_prefix = odt_values['transformUserNamePrefix']
590 odt_name = odt_values['transformUserName']
593 for input_space in ['ACEScc', 'ACESproxy']:
594 args = ['--iconfig', config_path,
596 '--inputspace', input_space]
597 args += ['--outputspace', '%s' % odt_name]
598 args += ['--description',
599 '%s - %s for %s data' % (odt_prefix,
602 args += ['--shaperspace', shaper_name,
603 '--shapersize', str(lut_resolution_shaper)]
604 args += ['--cubesize', str(lut_resolution_3d)]
607 os.path.join(baked_directory,
609 '%s for %s.icc' % (odt_name, input_space))]
611 bake_lut = Process(description='bake a LUT',
617 for input_space in ['ACEScc', 'ACESproxy']:
618 args = ['--iconfig', config_path,
620 '--inputspace', input_space]
621 args += ['--outputspace', '%s' % odt_name]
622 args += ['--description',
623 '%s - %s for %s data' % (
624 odt_prefix, odt_name, input_space)]
625 args += ['--shaperspace', shaper_name,
626 '--shapersize', str(lut_resolution_shaper)]
627 args += ['--cubesize', str(lut_resolution_3d)]
634 '%s for %s Flame.3dl' % (odt_name, input_space))]
635 bake_lut = Process(description='bake a LUT',
645 '%s for %s Lustre.3dl' % (odt_name, input_space))]
646 bake_lut = Process(description='bake a LUT',
652 for input_space in ['ACEScg', 'ACES2065-1']:
653 args = ['--iconfig', config_path,
655 '--inputspace', input_space]
656 args += ['--outputspace', '%s' % odt_name]
657 args += ['--description',
658 '%s - %s for %s data' % (
659 odt_prefix, odt_name, input_space)]
660 if input_space == 'ACEScg':
661 lin_shaper_name = '%s - AP1' % shaper_name
663 lin_shaper_name = shaper_name
664 args += ['--shaperspace', lin_shaper_name,
665 '--shapersize', str(lut_resolution_shaper)]
667 args += ['--cubesize', str(lut_resolution_3d)]
674 '%s for %s Maya.csp' % (odt_name, input_space))]
675 bake_lut = Process(description='bake a LUT',
685 '%s for %s Houdini.lut' % (odt_name, input_space))]
686 bake_lut = Process(description='bake a LUT',
692 def create_config_dir(config_directory, bake_secondary_LUTs):
699 Parameter description.
704 Return value description.
707 lut_directory = os.path.join(config_directory, 'luts')
708 dirs = [config_directory, lut_directory]
709 if bake_secondary_LUTs:
710 dirs.extend([os.path.join(config_directory, 'baked'),
711 os.path.join(config_directory, 'baked', 'flame'),
712 os.path.join(config_directory, 'baked', 'photoshop'),
713 os.path.join(config_directory, 'baked', 'houdini'),
714 os.path.join(config_directory, 'baked', 'lustre'),
715 os.path.join(config_directory, 'baked', 'maya')])
718 not os.path.exists(d) and os.mkdir(d)
723 def create_ACES_config(aces_ctl_directory,
725 lut_resolution_1d=4096,
726 lut_resolution_3d=64,
727 bake_secondary_LUTs=True,
730 Creates the ACES configuration.
735 Parameter description.
740 Return value description.
743 lut_directory = create_config_dir(config_directory, bake_secondary_LUTs)
745 odt_info = aces.get_ODTs_info(aces_ctl_directory)
746 lmt_info = aces.get_LMTs_info(aces_ctl_directory)
748 shaper_name = 'Output Shaper'
749 config_data = generate_LUTs(odt_info,
758 print('Creating "generic" config')
759 config = create_config(config_data)
763 os.path.join(config_directory, 'config.ocio'))
765 print('Creating "Nuke" config')
766 nuke_config = create_config(config_data, nuke=True)
769 write_config(nuke_config,
770 os.path.join(config_directory, 'nuke_config.ocio'))
772 if bake_secondary_LUTs:
773 generate_baked_LUTs(odt_info,
775 os.path.join(config_directory, 'baked'),
776 os.path.join(config_directory, 'config.ocio'),
791 Parameter description.
796 Return value description.
801 p = optparse.OptionParser(description='An OCIO config generation script',
802 prog='createACESConfig',
803 version='createACESConfig 0.1',
804 usage='%prog [options]')
805 p.add_option('--acesCTLDir', '-a', default=os.environ.get(
806 ACES_OCIO_CTL_DIRECTORY_ENVIRON, None))
807 p.add_option('--configDir', '-c', default=os.environ.get(
808 ACES_OCIO_CONFIGURATION_DIRECTORY_ENVIRON, None))
809 p.add_option('--lutResolution1d', default=4096)
810 p.add_option('--lutResolution3d', default=64)
811 p.add_option('--dontBakeSecondaryLUTs', action='store_true')
812 p.add_option('--keepTempImages', action='store_true')
814 options, arguments = p.parse_args()
816 aces_ctl_directory = options.acesCTLDir
817 config_directory = options.configDir
818 lut_resolution_1d = int(options.lutResolution1d)
819 lut_resolution_3d = int(options.lutResolution3d)
820 bake_secondary_luts = not options.dontBakeSecondaryLUTs
821 cleanup_temp_images = not options.keepTempImages
823 # TODO: Investigate the following statements.
825 args_start = sys.argv.index('--') + 1
826 args = sys.argv[args_start:]
828 args_start = len(sys.argv) + 1
831 print('command line : \n%s\n' % ' '.join(sys.argv))
833 assert aces_ctl_directory is not None, (
834 'process: No "{0}" environment variable defined or no "ACES CTL" '
835 'directory specified'.format(
836 ACES_OCIO_CTL_DIRECTORY_ENVIRON))
838 assert config_directory is not None, (
839 'process: No "{0}" environment variable defined or no configuration '
840 'directory specified'.format(
841 ACES_OCIO_CONFIGURATION_DIRECTORY_ENVIRON))
843 return create_ACES_config(aces_ctl_directory,
851 if __name__ == '__main__':