2 # -*- coding: utf-8 -*-
5 Defines objects creating the *ACES* configuration.
8 from __future__ import division
15 import PyOpenColorIO as ocio
16 from aces_ocio.colorspaces import aces
17 from aces_ocio.colorspaces import arri
18 from aces_ocio.colorspaces import canon
19 from aces_ocio.colorspaces import general
20 from aces_ocio.colorspaces import gopro
21 from aces_ocio.colorspaces import panasonic
22 from aces_ocio.colorspaces import red
23 from aces_ocio.colorspaces import sony
24 from aces_ocio.process import Process
26 from aces_ocio.utilities import (
28 colorspace_prefixed_name,
33 __author__ = 'ACES Developers'
34 __copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers'
36 __maintainer__ = 'ACES Developers'
37 __email__ = 'aces@oscars.org'
38 __status__ = 'Production'
40 __all__ = ['ACES_OCIO_CTL_DIRECTORY_ENVIRON',
41 'ACES_OCIO_CONFIGURATION_DIRECTORY_ENVIRON',
43 'create_ocio_transform',
44 'add_colorspace_aliases',
50 'generate_baked_LUTs',
51 'generate_config_directory',
55 ACES_OCIO_CTL_DIRECTORY_ENVIRON = 'ACES_OCIO_CTL_DIRECTORY'
56 ACES_OCIO_CONFIGURATION_DIRECTORY_ENVIRON = 'ACES_OCIO_CONFIGURATION_DIRECTORY'
59 def set_config_roles(config,
70 compositing_linear=None):
72 Sets given *OCIO* configuration roles to the config.
77 color_picking : str or unicode, optional
78 Color picking role title.
79 color_timing : str or unicode, optional
80 Color timing role title.
81 compositing_log : str or unicode, optional
82 Compositing log role title.
83 data : str or unicode, optional
85 default : str or unicode, optional
87 matte_paint : str or unicode, optional
88 Matte painting role title.
89 reference : str or unicode, optional
91 scene_linear : str or unicode, optional
92 Scene linear role title.
93 texture_paint : str or unicode, optional
94 Texture painting role title.
101 if color_picking is not None:
102 config.setRole(ocio.Constants.ROLE_COLOR_PICKING, color_picking)
103 if color_timing is not None:
104 config.setRole(ocio.Constants.ROLE_COLOR_TIMING, color_timing)
105 if compositing_log is not None:
106 config.setRole(ocio.Constants.ROLE_COMPOSITING_LOG, compositing_log)
108 config.setRole(ocio.Constants.ROLE_DATA, data)
109 if default is not None:
110 config.setRole(ocio.Constants.ROLE_DEFAULT, default)
111 if matte_paint is not None:
112 config.setRole(ocio.Constants.ROLE_MATTE_PAINT, matte_paint)
113 if reference is not None:
114 config.setRole(ocio.Constants.ROLE_REFERENCE, reference)
115 if texture_paint is not None:
116 config.setRole(ocio.Constants.ROLE_TEXTURE_PAINT, texture_paint)
118 # *rendering* and *compositing_linear* roles default to the *scene_linear*
119 # value if not set explicitly.
120 if rendering is not None:
121 config.setRole('rendering', rendering)
122 if compositing_linear is not None:
123 config.setRole('compositing_linear', compositing_linear)
124 if scene_linear is not None:
125 config.setRole(ocio.Constants.ROLE_SCENE_LINEAR, scene_linear)
126 if rendering is None:
127 config.setRole('rendering', scene_linear)
128 if compositing_linear is None:
129 config.setRole('compositing_linear', scene_linear)
134 def create_ocio_transform(transforms):
136 Returns an *OCIO* transform from given array of transform descriptions.
140 transforms : array_like
141 Transform descriptions as an array_like of dicts:
142 {'type', 'src', 'dst', 'direction'}
150 direction_options = {
151 'forward': ocio.Constants.TRANSFORM_DIR_FORWARD,
152 'inverse': ocio.Constants.TRANSFORM_DIR_INVERSE}
156 for transform in transforms:
158 # *lutFile* transform
159 if transform['type'] == 'lutFile':
160 ocio_transform = ocio.FileTransform()
162 if 'path' in transform:
163 ocio_transform.setSrc(transform['path'])
165 if 'cccid' in transform:
166 ocio_transform.setCCCId(transform['cccid'])
168 if 'interpolation' in transform:
169 ocio_transform.setInterpolation(transform['interpolation'])
171 ocio_transform.setInterpolation(ocio.Constants.INTERP_BEST)
173 if 'direction' in transform:
174 ocio_transform.setDirection(
175 direction_options[transform['direction']])
177 ocio_transforms.append(ocio_transform)
180 elif transform['type'] == 'matrix':
181 ocio_transform = ocio.MatrixTransform()
182 # `MatrixTransform` member variables can't be initialized directly,
183 # each must be set individually.
184 ocio_transform.setMatrix(transform['matrix'])
186 if 'offset' in transform:
187 ocio_transform.setOffset(transform['offset'])
189 if 'direction' in transform:
190 ocio_transform.setDirection(
191 direction_options[transform['direction']])
193 ocio_transforms.append(ocio_transform)
195 # *exponent* transform
196 elif transform['type'] == 'exponent':
197 ocio_transform = ocio.ExponentTransform()
199 if 'value' in transform:
200 ocio_transform.setValue(transform['value'])
202 ocio_transforms.append(ocio_transform)
205 elif transform['type'] == 'log':
206 ocio_transform = ocio.LogTransform()
208 if 'base' in transform:
209 ocio_transform.setBase(transform['base'])
211 if 'direction' in transform:
212 ocio_transform.setDirection(
213 direction_options[transform['direction']])
215 ocio_transforms.append(ocio_transform)
217 # *colorspace* transform
218 elif transform['type'] == 'colorspace':
219 ocio_transform = ocio.ColorSpaceTransform()
221 if 'src' in transform:
222 ocio_transform.setSrc(transform['src'])
224 if 'dst' in transform:
225 ocio_transform.setDst(transform['dst'])
227 if 'direction' in transform:
228 ocio_transform.setDirection(
229 direction_options[transform['direction']])
231 ocio_transforms.append(ocio_transform)
234 elif transform['type'] == 'look':
235 ocio_transform = ocio.LookTransform()
236 if 'look' in transform:
237 ocio_transform.setLooks(transform['look'])
239 if 'src' in transform:
240 ocio_transform.setSrc(transform['src'])
242 if 'dst' in transform:
243 ocio_transform.setDst(transform['dst'])
245 if 'direction' in transform:
246 ocio_transform.setDirection(
247 direction_options[transform['direction']])
249 ocio_transforms.append(ocio_transform)
253 print('Ignoring unknown transform type : %s' % transform['type'])
255 if len(ocio_transforms) > 1:
256 group_transform = ocio.GroupTransform()
257 for transform in ocio_transforms:
258 group_transform.push_back(transform)
259 transform = group_transform
261 transform = ocio_transforms[0]
266 def add_colorspace_aliases(config,
267 reference_colorspace,
269 colorspace_alias_names,
272 Adds given colorspace aliases to the *OCIO* config.
277 *OCIO* configuration.
278 reference_colorspace : Colorspace
279 Reference colorspace.
280 colorspace : Colorspace
281 Colorspace to set the aliases into the *OCIO* config.
291 for alias_name in colorspace_alias_names:
292 if alias_name.lower() == colorspace.name.lower():
293 print('Skipping alias creation for %s, alias %s, '
294 'because lower cased names match' % (
295 colorspace.name, alias_name))
298 print('Adding alias colorspace space %s, alias to %s' % (
299 alias_name, colorspace.name))
301 compact_family_name = family
303 description = colorspace.description
304 if colorspace.aces_transform_id:
306 '\n\nACES Transform ID : %s' % colorspace.aces_transform_id)
308 ocio_colorspace_alias = ocio.ColorSpace(
310 bitDepth=colorspace.bit_depth,
311 description=description,
312 equalityGroup=colorspace.equality_group,
313 family=compact_family_name,
314 isData=colorspace.is_data,
315 allocation=colorspace.allocation_type,
316 allocationVars=colorspace.allocation_vars)
318 if colorspace.to_reference_transforms:
319 print('\tGenerating To-Reference transforms')
320 ocio_transform = create_ocio_transform(
321 [{'type': 'colorspace',
322 'src': colorspace.name,
323 'dst': reference_colorspace.name,
324 'direction': 'forward'}])
325 ocio_colorspace_alias.setTransform(
327 ocio.Constants.COLORSPACE_DIR_TO_REFERENCE)
329 if colorspace.from_reference_transforms:
330 print('\tGenerating From-Reference transforms')
331 ocio_transform = create_ocio_transform(
332 [{'type': 'colorspace',
333 'src': reference_colorspace.name,
334 'dst': colorspace.name,
335 'direction': 'forward'}])
336 ocio_colorspace_alias.setTransform(
338 ocio.Constants.COLORSPACE_DIR_FROM_REFERENCE)
340 config.addColorSpace(ocio_colorspace_alias)
349 Adds given look to the *OCIO* config.
354 *OCIO* configuration.
356 Look description: {'name', 'colorspace', 'lut', 'cccid'}
357 custom_lut_dir : str or unicode
358 Directory to copy the look lut into.
359 reference_name : str or unicode
362 Colorspaces and transforms converting between those colorspaces and
363 the reference colorspace, *ACES*.
371 look_name, look_colorspace, look_lut, look_cccid = unpack_default(look, 4)
373 print('Adding look %s - %s' % (look_name, ', '.join(look)))
375 # Copy *look LUT* if `custom_lut_dir` is provided.
377 if '$' not in look_lut:
378 print('Getting ready to copy look lut : %s' % look_lut)
379 shutil.copy2(look_lut, custom_lut_dir)
380 look_lut = os.path.split(look_lut)[1]
382 print('Skipping LUT copy because path contains a context variable')
384 print('Adding look to config')
385 ocio_look = ocio.Look()
386 ocio_look.setName(look_name)
387 ocio_look.setProcessSpace(look_colorspace)
389 keys = {'type': 'lutFile',
391 'direction': 'forward'}
393 keys['cccid'] = look_cccid
395 ocio_transform = create_ocio_transform([keys])
396 ocio_look.setTransform(ocio_transform)
398 config.addLook(ocio_look)
400 print('Creating aliased colorspace')
402 # Creating *OCIO* colorspace referencing the look:
403 # - Needed for implementations that don't process looks properly.
404 # - Needed for implementations that don't expose looks properly.
405 look_aliases = ['look_%s' % compact(look_name)]
406 colorspace = ColorSpace(look_name,
407 aliases=look_aliases,
408 description='The %s Look colorspace' % look_name,
411 colorspace.from_reference_transforms = [{'type': 'look',
413 'src': reference_name,
414 'dst': reference_name,
415 'direction': 'forward'}]
417 print('Adding colorspace %s, alias to look %s to config data' % (
418 look_name, look_name))
420 config_data['colorSpaces'].append(colorspace)
425 def add_looks_to_views(looks,
428 multiple_displays=False):
435 Parameter description.
440 Return value description.
442 look_names = [look[0] for look in looks]
445 # - Adding a *look* per *Display*.
446 # - Assuming there is a *Display* for each *ACES* *Output Transform*.
447 if multiple_displays:
448 for look_name in look_names:
449 config_data['looks'].append(look_name)
452 # - Copy each *Output Transform* colorspace.
453 # - For each copy, add a *LookTransform* to the head of the
454 # `from_reference` transform list.
455 # - Add these the copy colorspaces for the *Displays* / *Views*.
457 for display, view_list in config_data['displays'].iteritems():
459 look_names_string = ''
460 for view_name, output_colorspace in view_list.iteritems():
461 if view_name == 'Output Transform':
463 print('Adding new View that incorporates looks')
465 colorspace_c = copy.deepcopy(output_colorspace)
467 for i, look_name in enumerate(look_names):
468 look_name = look_names[i]
470 # Add the `LookTransform` to the head of the
471 # `from_reference` transform list.
472 if colorspace_c.from_reference_transforms:
473 colorspace_c.from_reference_transforms.insert(
477 'src': reference_name,
478 'dst': reference_name,
479 'direction': 'forward'})
481 # Add the `LookTransform` to the end of
482 # the `to_reference` transform list.
483 if colorspace_c.to_reference_transforms:
484 inverse_look_name = look_names[
485 len(look_names) - 1 - i]
487 colorspace_c.to_reference_transforms.append(
489 'look': inverse_look_name,
490 'src': reference_name,
491 'dst': reference_name,
492 'direction': 'inverse'})
494 if look_name not in config_data['looks']:
495 config_data['looks'].append(look_name)
497 look_names_string = ', '.join(look_names)
498 colorspace_c.name = '%s with %s' % (
499 output_colorspace.name, look_names_string)
500 colorspace_c.aliases = [
501 'out_%s' % compact(colorspace_c.name)]
503 print('Colorspace that incorporates looks '
504 'created : %s' % colorspace_c.name)
506 config_data['colorSpaces'].append(colorspace_c)
509 print('Adding colorspace that incorporates looks '
512 # Updating the *View* name.
513 view_list['Output Transform with %s' % look_names_string] = (
515 config_data['displays'][display] = view_list
518 def create_config(config_data,
521 multiple_displays=False,
523 custom_lut_dir=None):
530 Parameter description.
535 Return value description.
538 if look_info is None:
542 alias_colorspaces = []
544 config = ocio.Config()
546 config.setDescription('An ACES config generated from python')
548 search_path = ['luts']
550 search_path.append('custom')
551 config.setSearchPath(':'.join(search_path))
553 reference_data = config_data['referenceColorSpace']
555 # Adding the colorspace *Family* into the name which helps with
556 # applications that presenting colorspaces as one a flat list.
558 prefixed_name = colorspace_prefixed_name(reference_data)
559 prefixed_names[reference_data.name] = prefixed_name
560 reference_data.name = prefixed_name
562 print('Adding the reference color space : %s' % reference_data.name)
564 reference = ocio.ColorSpace(
565 name=reference_data.name,
566 bitDepth=reference_data.bit_depth,
567 description=reference_data.description,
568 equalityGroup=reference_data.equality_group,
569 family=reference_data.family,
570 isData=reference_data.is_data,
571 allocation=reference_data.allocation_type,
572 allocationVars=reference_data.allocation_vars)
574 config.addColorSpace(reference)
577 if reference_data.aliases:
578 # Deferring adding alias colorspaces until end, which helps with
579 # applications listing the colorspaces in the order that they were
580 # defined in the configuration: alias colorspaces are usually named
581 # lower case with spaces but normal colorspaces names are longer
582 # and more verbose, thus it becomes harder for user to visually
583 # parse the list of colorspaces when there are names such as
584 # "crv_canonlog" interspersed with names like
585 # "Input - Canon - Curve - Canon-Log".
586 # Moving the alias colorspace definitions to the end of the
587 # configuration avoids the above problem.
588 alias_colorspaces.append(
589 [reference_data, reference_data, reference_data.aliases])
594 print('Adding looks')
596 config_data['looks'] = []
598 for look in look_info:
605 add_looks_to_views(look_info,
612 print('Adding regular colorspaces')
614 for colorspace in sorted(config_data['colorSpaces'],
615 cmp=lambda x,y: cmp(x.family.lower(), y.family.lower())):
616 # Adding the colorspace *Family* into the name which helps with
617 # applications that presenting colorspaces as one a flat list.
619 prefixed_name = colorspace_prefixed_name(colorspace)
620 prefixed_names[colorspace.name] = prefixed_name
621 colorspace.name = prefixed_name
623 print('Creating new color space : %s' % colorspace.name)
625 description = colorspace.description
626 if colorspace.aces_transform_id:
628 '\n\nACES Transform ID : %s' % colorspace.aces_transform_id)
630 ocio_colorspace = ocio.ColorSpace(
631 name=colorspace.name,
632 bitDepth=colorspace.bit_depth,
633 description=description,
634 equalityGroup=colorspace.equality_group,
635 family=colorspace.family,
636 isData=colorspace.is_data,
637 allocation=colorspace.allocation_type,
638 allocationVars=colorspace.allocation_vars)
640 if colorspace.to_reference_transforms:
641 print('\tGenerating To-Reference transforms')
642 ocio_transform = create_ocio_transform(
643 colorspace.to_reference_transforms)
644 ocio_colorspace.setTransform(
646 ocio.Constants.COLORSPACE_DIR_TO_REFERENCE)
648 if colorspace.from_reference_transforms:
649 print('\tGenerating From-Reference transforms')
650 ocio_transform = create_ocio_transform(
651 colorspace.from_reference_transforms)
652 ocio_colorspace.setTransform(
654 ocio.Constants.COLORSPACE_DIR_FROM_REFERENCE)
656 config.addColorSpace(ocio_colorspace)
659 if colorspace.aliases:
660 # Deferring adding alias colorspaces until end, which helps
661 # with applications listing the colorspaces in the order that
662 # they were defined in the configuration.
663 alias_colorspaces.append(
664 [reference_data, colorspace, colorspace.aliases])
670 # Adding roles early so that alias colorspaces can be created
671 # with roles names before remaining colorspace aliases are added
672 # to the configuration.
673 print('Setting the roles')
678 color_picking=prefixed_names[
679 config_data['roles']['color_picking']],
680 color_timing=prefixed_names[config_data['roles']['color_timing']],
681 compositing_log=prefixed_names[
682 config_data['roles']['compositing_log']],
683 data=prefixed_names[config_data['roles']['data']],
684 default=prefixed_names[config_data['roles']['default']],
685 matte_paint=prefixed_names[config_data['roles']['matte_paint']],
686 reference=prefixed_names[config_data['roles']['reference']],
687 scene_linear=prefixed_names[config_data['roles']['scene_linear']],
688 texture_paint=prefixed_names[
689 config_data['roles']['texture_paint']])
691 # TODO: Pending code path reactivation.
692 # Not allowed at the moment as role names can not overlap
693 # with colorspace names.
695 # Add the aliased colorspaces for each role
696 for role_name, role_colorspace_name in config_data['roles'].iteritems():
697 role_colorspace_prefixed_name = prefixed_names[role_colorspace_name]
699 print( 'Finding colorspace : %s' % role_colorspace_prefixed_name )
700 # Find the colorspace pointed to by the role
701 role_colorspaces = [colorspace
702 for colorspace in config_data['colorSpaces']
703 if colorspace.name == role_colorspace_prefixed_name]
704 role_colorspace = None
705 if len(role_colorspaces) > 0:
706 role_colorspace = role_colorspaces[0]
708 if reference_data.name == role_colorspace_prefixed_name:
709 role_colorspace = reference_data
712 print( 'Adding an alias colorspace named %s, pointing to %s' % (
713 role_name, role_colorspace.name))
715 add_colorspace_aliases(
716 config, reference_data, role_colorspace, [role_name], 'Roles')
722 color_picking=config_data['roles']['color_picking'],
723 color_timing=config_data['roles']['color_timing'],
724 compositing_log=config_data['roles']['compositing_log'],
725 data=config_data['roles']['data'],
726 default=config_data['roles']['default'],
727 matte_paint=config_data['roles']['matte_paint'],
728 reference=config_data['roles']['reference'],
729 scene_linear=config_data['roles']['scene_linear'],
730 texture_paint=config_data['roles']['texture_paint'])
732 # TODO: Pending code path reactivation.
733 # Not allowed at the moment as role names can not overlap
734 # with colorspace names.
736 # Add the aliased colorspaces for each role
737 for role_name, role_colorspace_name in config_data['roles'].iteritems():
738 # Find the colorspace pointed to by the role
739 role_colorspaces = [colorspace
740 for colorspace in config_data['colorSpaces']
741 if colorspace.name == role_colorspace_name]
742 role_colorspace = None
743 if len(role_colorspaces) > 0:
744 role_colorspace = role_colorspaces[0]
746 if reference_data.name == role_colorspace_name:
747 role_colorspace = reference_data
750 print('Adding an alias colorspace named %s, pointing to %s' % (
751 role_name, role_colorspace.name))
753 add_colorspace_aliases(
754 config, reference_data, role_colorspace, [role_name], 'Roles')
759 # Adding alias colorspaces at the end as some applications use
760 # colorspaces definitions order of the configuration to order
761 # the colorspaces in their selection lists, some applications
762 # use alphabetical ordering.
763 # This should keep the alias colorspaces out of the way for applications
764 # using the configuration order.
765 print('Adding the alias colorspaces')
766 for reference, colorspace, aliases in alias_colorspaces:
767 add_colorspace_aliases(config, reference, colorspace, aliases)
771 print('Adding the diplays and views')
773 # Setting the *color_picking* role to be the first *Display*'s
774 # *Output Transform* *View*.
775 default_display_name = config_data['defaultDisplay']
776 default_display_views = config_data['displays'][default_display_name]
777 default_display_colorspace = default_display_views['Output Transform']
781 color_picking=default_display_colorspace.name)
783 # Defining *Displays* and *Views*.
784 displays, views = [], []
786 # Defining a generic *Display* and *View* setup.
787 if multiple_displays:
788 looks = config_data['looks'] if ('looks' in config_data) else []
789 looks = ', '.join(looks)
790 print('Creating multiple displays, with looks : %s' % looks)
792 # *Displays* are not reordered to put the *defaultDisplay* first
793 # because *OCIO* will order them alphabetically when the configuration
794 # is written to disk.
795 for display, view_list in config_data['displays'].iteritems():
796 for view_name, colorspace in view_list.iteritems():
797 config.addDisplay(display, view_name, colorspace.name, looks)
798 if 'Output Transform' in view_name and looks != '':
799 # *Views* without *Looks*.
800 config.addDisplay(display, view_name, colorspace.name)
802 # *Views* with *Looks*.
803 view_name_with_looks = '%s with %s' % (view_name, looks)
804 config.addDisplay(display, view_name_with_looks,
805 colorspace.name, looks)
807 config.addDisplay(display, view_name, colorspace.name)
808 if not (view_name in views):
809 views.append(view_name)
810 displays.append(display)
812 # *Displays* and *Views* useful in a *GUI* context.
814 single_display_name = 'ACES'
815 displays.append(single_display_name)
817 # Ensuring the *defaultDisplay* is first.
818 display_names = sorted(config_data['displays'])
819 display_names.insert(0, display_names.pop(
820 display_names.index(default_display_name)))
822 looks = config_data['looks'] if ('looks' in config_data) else []
823 look_names = ', '.join(looks)
825 displays_views_colorspaces = []
827 for display in display_names:
828 view_list = config_data['displays'][display]
829 for view_name, colorspace in view_list.iteritems():
830 if 'Output Transform' in view_name:
832 # We use the *Display* names as the *View* names in this
833 # case as there is a single *Display* containing all the
835 # This works for more applications than not,as of the time
836 # of this implementation.
838 # Autodesk Maya 2016 doesn't support parentheses in
840 sanitised_display = replace(display, {')': '', '(': ''})
842 # *View* with *Looks*.
843 if 'with' in view_name:
844 sanitised_display = '%s with %s' % (
845 sanitised_display, look_names)
847 views_with_looks_at_end = False
848 # Storing combo of *Display*, *View* and *Colorspace*
849 # name so they can be added to the end of the list.
850 if views_with_looks_at_end:
851 displays_views_colorspaces.append(
852 [single_display_name, sanitised_display,
855 config.addDisplay(single_display_name,
859 if not (sanitised_display in views):
860 views.append(sanitised_display)
862 # *View* without *Looks*.
864 config.addDisplay(single_display_name,
868 if not (sanitised_display in views):
869 views.append(sanitised_display)
871 # Adding to the configuration any *Display*, *View* combinations that
872 # were saved for later.
873 # This list should be empty unless `views_with_looks_at_end` is
875 for display_view_colorspace in displays_views_colorspaces:
876 single_display_name, sanitised_display, colorspace_name = (
877 display_view_colorspace)
879 config.addDisplay(single_display_name,
883 if not (sanitised_display in views):
884 views.append(sanitised_display)
886 raw_display_space_name = config_data['roles']['data']
887 log_display_space_name = config_data['roles']['compositing_log']
890 raw_display_space_name = prefixed_names[raw_display_space_name]
891 log_display_space_name = prefixed_names[log_display_space_name]
893 config.addDisplay(single_display_name, 'Raw', raw_display_space_name)
895 config.addDisplay(single_display_name, 'Log', log_display_space_name)
898 config.setActiveDisplays(','.join(sorted(displays)))
899 config.setActiveViews(','.join(views))
903 # Ensuring the configuration is valid.
906 # Resetting colorspace names to their non-prefixed versions.
908 prefixed_names_inverse = {}
909 for original, prefixed in prefixed_names.iteritems():
910 prefixed_names_inverse[prefixed] = original
912 reference_data.name = prefixed_names_inverse[reference_data.name]
915 for colorspace in config_data['colorSpaces']:
916 colorspace.name = prefixed_names_inverse[colorspace.name]
918 print('Prefixed names')
919 for original, prefixed in prefixed_names.iteritems():
920 print('%s, %s' % (original, prefixed))
924 print('Inverse Lookup of Prefixed names')
925 for prefixed, original in prefixed_names_inverse.iteritems():
926 print('%s, %s' % (prefixed, original))
932 def create_config_data(odt_info,
937 lut_resolution_1d=4096,
938 lut_resolution_3d=64,
946 Parameter description.
951 Colorspaces and transforms converting between those colorspaces and
952 the reference colorspace, *ACES*.
955 print('create_config_data - begin')
958 config_data['displays'] = {}
959 config_data['colorSpaces'] = []
961 # -------------------------------------------------------------------------
962 # *ACES Color Spaces*
963 # -------------------------------------------------------------------------
969 aces_log_display_space,
971 aces_default_display) = aces.create_colorspaces(aces_ctl_directory,
980 config_data['referenceColorSpace'] = aces_reference
981 config_data['roles'] = aces_roles
983 for cs in aces_colorspaces:
984 config_data['colorSpaces'].append(cs)
986 for name, data in aces_displays.iteritems():
987 config_data['displays'][name] = data
989 config_data['defaultDisplay'] = aces_default_display
990 config_data['linearDisplaySpace'] = aces_reference
991 config_data['logDisplaySpace'] = aces_log_display_space
993 # -------------------------------------------------------------------------
994 # *Camera Input Transforms*
995 # -------------------------------------------------------------------------
997 # *ARRI Log-C* to *ACES*
998 arri_colorspaces = arri.create_colorspaces(lut_directory,
1000 for cs in arri_colorspaces:
1001 config_data['colorSpaces'].append(cs)
1003 # *Canon-Log* to *ACES*
1004 canon_colorspaces = canon.create_colorspaces(lut_directory,
1006 for cs in canon_colorspaces:
1007 config_data['colorSpaces'].append(cs)
1009 # *GoPro Protune* to *ACES*
1010 gopro_colorspaces = gopro.create_colorspaces(lut_directory,
1012 for cs in gopro_colorspaces:
1013 config_data['colorSpaces'].append(cs)
1015 # *Panasonic V-Log* to *ACES*
1016 panasonic_colorspaces = panasonic.create_colorspaces(lut_directory,
1018 for cs in panasonic_colorspaces:
1019 config_data['colorSpaces'].append(cs)
1021 # *RED* colorspaces to *ACES*
1022 red_colorspaces = red.create_colorspaces(lut_directory,
1024 for cs in red_colorspaces:
1025 config_data['colorSpaces'].append(cs)
1028 sony_colorspaces = sony.create_colorspaces(lut_directory,
1030 for cs in sony_colorspaces:
1031 config_data['colorSpaces'].append(cs)
1033 # -------------------------------------------------------------------------
1034 # General Colorspaces
1035 # -------------------------------------------------------------------------
1036 general_colorspaces = general.create_colorspaces(lut_directory,
1038 for cs in general_colorspaces:
1039 config_data['colorSpaces'].append(cs)
1041 # The *Raw* colorspace
1042 raw = general.create_raw()
1043 config_data['colorSpaces'].append(raw)
1045 # Overriding various roles
1046 config_data['roles']['data'] = raw.name
1047 config_data['roles']['reference'] = raw.name
1048 config_data['roles']['texture_paint'] = raw.name
1050 print('create_config_data - end')
1055 def write_config(config, config_path, sanity_check=True):
1057 Writes the configuration to given path.
1062 *OCIO* configuration.
1063 config_path : str or unicode
1064 Path to write the configuration path.
1066 Performs configuration sanity checking prior to writing it on disk.
1076 config.sanityCheck()
1077 except Exception, e:
1079 print 'Configuration was not written due to a failed Sanity Check'
1082 with open(config_path, mode='w') as fp:
1083 fp.write(config.serialize())
1086 def generate_baked_LUTs(odt_info,
1091 lut_resolution_shaper=1024,
1099 Parameter description.
1104 Return value description.
1107 odt_info_C = dict(odt_info)
1109 # Older behavior for *ODTs* that have support for full and legal ranges,
1110 # generating a LUT for both ranges.
1112 # Create two entries for ODTs that have full and legal range support
1113 for odt_ctl_name, odt_values in odt_info.iteritems():
1114 if odt_values['transformHasFullLegalSwitch']:
1115 odt_name = odt_values['transformUserName']
1117 odt_values_legal = dict(odt_values)
1118 odt_values_legal['transformUserName'] = '%s - Legal' % odt_name
1119 odt_info_C['%s - Legal' % odt_ctl_name] = odt_values_legal
1121 odt_values_full = dict(odt_values)
1122 odt_values_full['transformUserName'] = '%s - Full' % odt_name
1123 odt_info_C['%s - Full' % odt_ctl_name] = odt_values_full
1125 del (odt_info_C[odt_ctl_name])
1128 for odt_ctl_name, odt_values in odt_info_C.iteritems():
1129 odt_prefix = odt_values['transformUserNamePrefix']
1130 odt_name = odt_values['transformUserName']
1133 for input_space in ['ACEScc', 'ACESproxy']:
1134 args = ['--iconfig', config_path,
1137 args += ['--inputspace', 'ACES - %s' % input_space]
1138 args += ['--outputspace', 'Output - %s' % odt_name]
1140 args += ['--inputspace', input_space]
1141 args += ['--outputspace', odt_name]
1143 args += ['--description',
1144 '%s - %s for %s data' % (odt_prefix,
1148 args += ['--shaperspace', 'Utility - %s' % shaper_name,
1149 '--shapersize', str(lut_resolution_shaper)]
1151 args += ['--shaperspace', shaper_name,
1152 '--shapersize', str(lut_resolution_shaper)]
1153 args += ['--cubesize', str(lut_resolution_3d)]
1154 args += ['--format',
1156 os.path.join(baked_directory,
1158 '%s for %s.icc' % (odt_name, input_space))]
1160 bake_lut = Process(description='bake a LUT',
1166 for input_space in ['ACEScc', 'ACESproxy']:
1167 args = ['--iconfig', config_path,
1170 args += ['--inputspace', 'ACES - %s' % input_space]
1171 args += ['--outputspace', 'Output - %s' % odt_name]
1173 args += ['--inputspace', input_space]
1174 args += ['--outputspace', odt_name]
1175 args += ['--description',
1176 '%s - %s for %s data' % (
1177 odt_prefix, odt_name, input_space)]
1179 args += ['--shaperspace', 'Utility - %s' % shaper_name,
1180 '--shapersize', str(lut_resolution_shaper)]
1182 args += ['--shaperspace', shaper_name,
1183 '--shapersize', str(lut_resolution_shaper)]
1184 args += ['--cubesize', str(lut_resolution_3d)]
1186 fargs = ['--format',
1191 '%s for %s Flame.3dl' % (odt_name, input_space))]
1192 bake_lut = Process(description='bake a LUT',
1194 args=(args + fargs))
1197 largs = ['--format',
1202 '%s for %s Lustre.3dl' % (odt_name, input_space))]
1203 bake_lut = Process(description='bake a LUT',
1205 args=(args + largs))
1209 for input_space in ['ACEScg', 'ACES2065-1']:
1210 args = ['--iconfig', config_path,
1213 args += ['--inputspace', 'ACES - %s' % input_space]
1214 args += ['--outputspace', 'Output - %s' % odt_name]
1216 args += ['--inputspace', input_space]
1217 args += ['--outputspace', odt_name]
1218 args += ['--description',
1219 '%s - %s for %s data' % (
1220 odt_prefix, odt_name, input_space)]
1221 if input_space == 'ACEScg':
1222 lin_shaper_name = '%s - AP1' % shaper_name
1224 lin_shaper_name = shaper_name
1226 lin_shaper_name = 'Utility - %s' % lin_shaper_name
1227 args += ['--shaperspace', lin_shaper_name,
1228 '--shapersize', str(lut_resolution_shaper)]
1230 args += ['--cubesize', str(lut_resolution_3d)]
1232 margs = ['--format',
1237 '%s for %s Maya.csp' % (odt_name, input_space))]
1238 bake_lut = Process(description='bake a LUT',
1240 args=(args + margs))
1243 hargs = ['--format',
1248 '%s for %s Houdini.lut' % (odt_name, input_space))]
1249 bake_lut = Process(description='bake a LUT',
1251 args=(args + hargs))
1255 def generate_config_directory(config_directory,
1256 bake_secondary_luts=False,
1257 custom_lut_dir=None):
1264 Parameter description.
1269 Return value description.
1272 lut_directory = os.path.join(config_directory, 'luts')
1273 dirs = [config_directory, lut_directory]
1275 if bake_secondary_luts:
1276 dirs.extend([os.path.join(config_directory, 'baked'),
1277 os.path.join(config_directory, 'baked', 'flame'),
1278 os.path.join(config_directory, 'baked', 'photoshop'),
1279 os.path.join(config_directory, 'baked', 'houdini'),
1280 os.path.join(config_directory, 'baked', 'lustre'),
1281 os.path.join(config_directory, 'baked', 'maya')])
1284 dirs.append(os.path.join(config_directory, 'custom'))
1287 not os.path.exists(d) and os.mkdir(d)
1289 return lut_directory
1292 def generate_config(aces_ctl_directory,
1294 lut_resolution_1d=4096,
1295 lut_resolution_3d=64,
1296 bake_secondary_luts=True,
1297 multiple_displays=False,
1299 copy_custom_luts=True,
1301 prefix_colorspaces_with_family_names=True):
1303 Creates the ACES configuration.
1308 Parameter description.
1313 Return value description.
1316 if look_info is None:
1319 custom_lut_dir = None
1320 if copy_custom_luts:
1321 custom_lut_dir = os.path.join(config_directory, 'custom')
1323 lut_directory = generate_config_directory(config_directory,
1324 bake_secondary_luts,
1327 odt_info = aces.get_ODTs_info(aces_ctl_directory)
1328 lmt_info = aces.get_LMTs_info(aces_ctl_directory)
1330 shaper_name = 'Output Shaper'
1331 config_data = create_config_data(odt_info,
1340 print('Creating config - with prefixes, with aliases')
1341 config = create_config(config_data,
1342 prefix=prefix_colorspaces_with_family_names,
1344 multiple_displays=multiple_displays,
1345 look_info=look_info,
1346 custom_lut_dir=custom_lut_dir)
1349 write_config(config,
1350 os.path.join(config_directory, 'config.ocio'))
1352 if bake_secondary_luts:
1353 generate_baked_LUTs(odt_info,
1355 os.path.join(config_directory, 'baked'),
1356 os.path.join(config_directory, 'config.ocio'),
1359 prefix=prefix_colorspaces_with_family_names)
1371 Parameter description.
1376 Return value description.
1381 usage = '%prog [options]\n'
1383 usage += 'An OCIO config generation script for ACES 1.0\n'
1385 usage += 'Command line examples'
1387 usage += ('Create a GUI-friendly ACES 1.0 config with no secondary, '
1389 usage += ('\tcreate_aces_config -a /path/to/aces-dev/transforms/ctl '
1390 '--lutResolution1d 1024 --lutResolution3d 33 -c aces_1.0.0 '
1391 '--dontBakeSecondaryLUTs')
1393 usage += 'Create a more OCIO-compliant ACES 1.0 config : \n'
1394 usage += ('\tcreate_aces_config -a /path/to/aces-dev/transforms/ctl '
1395 '--lutResolution1d 1024 --lutResolution3d 33 -c aces_1.0.0 '
1396 '--createMultipleDisplays')
1399 usage += 'Adding custom looks'
1401 usage += ('Create a GUI-friendly ACES 1.0 config with an ACES-style CDL '
1402 '(will be applied in the ACEScc colorspace): \n')
1403 usage += ('\tcreate_aces_config -a /path/to/aces-dev/transforms/ctl '
1404 '--lutResolution1d 1024 --lutResolution3d 33 -c aces_1.0.0 '
1405 '\n\t\t--addACESLookCDL ACESCDLName '
1406 '/path/to/SampleCDL.ccc cc03345')
1408 usage += 'Create a GUI-friendly ACES 1.0 config with an general CDL: \n'
1409 usage += ('\tcreate_aces_config -a /path/to/aces-dev/transforms/ctl '
1410 '--lutResolution1d 1024 --lutResolution3d 33 -c aces_1.0.0 '
1411 '\n\t\t--addCustomLookCDL CustomCDLName "ACES - ACEScc" '
1412 '/path/to/SampleCDL.ccc cc03345')
1414 usage += ('\tIn this example, the CDL will be applied in the '
1415 'ACEScc colorspace, but the user could choose other spaces '
1416 'by changing the argument after the name of the look. \n')
1418 usage += ('Create a GUI-friendly ACES 1.0 config with an ACES-style LUT '
1419 '(will be applied in the ACEScc colorspace): \n')
1420 usage += ('\tcreate_aces_config -a /path/to/aces-dev/transforms/ctl '
1421 '--lutResolution1d 1024 --lutResolution3d 33 -c aces_1.0.0 '
1422 '\n\t\t--addACESLookLUT ACESLUTName '
1423 '/path/to/SampleCDL.ccc cc03345')
1425 usage += 'Create a GUI-friendly ACES 1.0 config with an general LUT: \n'
1426 usage += ('\tcreate_aces_config -a /path/to/aces-dev/transforms/ctl '
1427 '--lutResolution1d 1024 --lutResolution3d 33 -c aces_1.0.0 '
1428 '\n\t\t--addCustomLookLUT CustomLUTName "ACES - ACEScc" '
1429 '/path/to/SampleCDL.ccc cc03345')
1431 usage += ('\tIn this example, the LUT will be applied in the '
1432 'ACEScc colorspace, but the user could choose other spaces '
1433 'by changing the argument after the name of the look. \n')
1438 def look_info_callback(option, opt_str, value, parser):
1439 print('look_info_callback')
1440 print(option, opt_str, value, parser)
1441 if opt_str == '--addCustomLookCDL':
1442 look_info.append(value)
1443 elif opt_str == '--addCustomLookLUT':
1444 look_info.append(value)
1445 elif opt_str == '--addACESLookCDL':
1446 look_info.append([value[0], 'ACES - ACEScc', value[1], value[2]])
1447 elif opt_str == '--addACESLookLUT':
1448 look_info.append([value[0], 'ACES - ACEScc', value[1]])
1450 p = optparse.OptionParser(description='',
1451 prog='create_aces_config',
1452 version='create_aces_config 1.0',
1454 p.add_option('--acesCTLDir', '-a', default=os.environ.get(
1455 ACES_OCIO_CTL_DIRECTORY_ENVIRON, None))
1456 p.add_option('--configDir', '-c', default=os.environ.get(
1457 ACES_OCIO_CONFIGURATION_DIRECTORY_ENVIRON, None))
1458 p.add_option('--lutResolution1d', default=4096)
1459 p.add_option('--lutResolution3d', default=64)
1460 p.add_option('--dontBakeSecondaryLUTs', action='store_true', default=False)
1461 p.add_option('--keepTempImages', action='store_true', default=False)
1463 p.add_option('--createMultipleDisplays', action='store_true',
1466 p.add_option('--addCustomLookLUT', '', type='string', nargs=3,
1467 action='callback', callback=look_info_callback)
1468 p.add_option('--addCustomLookCDL', '', type='string', nargs=4,
1469 action='callback', callback=look_info_callback)
1470 p.add_option('--addACESLookLUT', '', type='string', nargs=2,
1471 action='callback', callback=look_info_callback)
1472 p.add_option('--addACESLookCDL', '', type='string', nargs=3,
1473 action='callback', callback=look_info_callback)
1474 p.add_option('--copyCustomLUTs', action='store_true', default=False)
1476 options, arguments = p.parse_args()
1478 aces_ctl_directory = options.acesCTLDir
1479 config_directory = options.configDir
1480 lut_resolution_1d = int(options.lutResolution1d)
1481 lut_resolution_3d = int(options.lutResolution3d)
1482 bake_secondary_luts = not options.dontBakeSecondaryLUTs
1483 cleanup_temp_images = not options.keepTempImages
1484 multiple_displays = options.createMultipleDisplays
1485 copy_custom_luts = options.copyCustomLUTs
1489 print('command line : \n%s\n' % ' '.join(sys.argv))
1491 assert aces_ctl_directory is not None, (
1492 'process: No "{0}" environment variable defined or no "ACES CTL" '
1493 'directory specified'.format(
1494 ACES_OCIO_CTL_DIRECTORY_ENVIRON))
1496 assert config_directory is not None, (
1497 'process: No "{0}" environment variable defined or no configuration '
1498 'directory specified'.format(
1499 ACES_OCIO_CONFIGURATION_DIRECTORY_ENVIRON))
1501 return generate_config(aces_ctl_directory,
1505 bake_secondary_luts,
1509 cleanup_temp_images)
1512 if __name__ == '__main__':