The default display now drives the value of the 'color_picking' role
[OpenColorIO-Configs.git] / aces_1.0.0 / python / aces_ocio / aces_config.py
index 9272908..3cc5727 100755 (executable)
@@ -290,10 +290,11 @@ def generate_OCIO_transform(transforms):
     return transform
 
 
-def add_colorspace_alias(config,
-                         reference_colorspace,
-                         colorspace,
-                         colorspace_alias_names):
+def add_colorspace_aliases(config,
+                           reference_colorspace,
+                           colorspace,
+                           colorspace_alias_names,
+                           family='Aliases'):
     """
     Object description.
 
@@ -312,12 +313,12 @@ def add_colorspace_alias(config,
         if alias_name.lower() == colorspace.name.lower():
             print('Skipping alias creation for %s, alias %s, because lower cased names match' % (
                 colorspace.name, alias_name) )
-            return
+            continue
 
         print('Adding alias colorspace space %s, alias to %s' % (
             alias_name, colorspace.name))
 
-        compact_family_name = 'Aliases'
+        compact_family_name = family
 
         description = colorspace.description
         if colorspace.aces_transform_id:
@@ -692,23 +693,108 @@ def create_config(config_data,
 
     print("")
 
+    #
+    # We add roles early so we can create alias colorspaces with the names of the roles
+    # before the rest of the colorspace aliases are added to the config.
+    #
+    print('Setting the roles')
+
+    if prefix:
+        set_config_default_roles(
+            config,
+            color_picking=prefixed_names[config_data['roles']['color_picking']],
+            color_timing=prefixed_names[config_data['roles']['color_timing']],
+            compositing_log=prefixed_names[config_data['roles']['compositing_log']],
+            data=prefixed_names[config_data['roles']['data']],
+            default=prefixed_names[config_data['roles']['default']],
+            matte_paint=prefixed_names[config_data['roles']['matte_paint']],
+            reference=prefixed_names[config_data['roles']['reference']],
+            scene_linear=prefixed_names[config_data['roles']['scene_linear']],
+            texture_paint=prefixed_names[config_data['roles']['texture_paint']])
+        # Not allowed for the moment. role names can not overlap with colorspace names.
+        '''
+        # Add the aliased colorspaces for each role
+        for role_name, role_colorspace_name in config_data['roles'].iteritems():
+            role_colorspace_prefixed_name = prefixed_names[role_colorspace_name]
+
+            print( "Finding colorspace : %s" % role_colorspace_prefixed_name )
+            # Find the colorspace pointed to by the role
+            role_colorspaces = [colorspace for colorspace in config_data['colorSpaces'] if colorspace.name == role_colorspace_prefixed_name]
+            role_colorspace = None
+            if len(role_colorspaces) > 0:
+                role_colorspace = role_colorspaces[0]
+            else:
+                if reference_data.name == role_colorspace_prefixed_name:
+                    role_colorspace = reference_data
+
+            if role_colorspace:
+                print( "Adding an alias colorspace named %s, pointing to %s" % (
+                    role_name, role_colorspace.name))
+
+                add_colorspace_aliases(config, reference_data, role_colorspace, [role_name], 'Roles')
+        '''
+
+    else:
+        set_config_default_roles(
+            config,
+            color_picking=config_data['roles']['color_picking'],
+            color_timing=config_data['roles']['color_timing'],
+            compositing_log=config_data['roles']['compositing_log'],
+            data=config_data['roles']['data'],
+            default=config_data['roles']['default'],
+            matte_paint=config_data['roles']['matte_paint'],
+            reference=config_data['roles']['reference'],
+            scene_linear=config_data['roles']['scene_linear'],
+            texture_paint=config_data['roles']['texture_paint'])
+
+        # Not allowed for the moment. role names can not overlap with colorspace names.
+        '''
+        # Add the aliased colorspaces for each role
+        for role_name, role_colorspace_name in config_data['roles'].iteritems():
+            # Find the colorspace pointed to by the role
+            role_colorspaces = [colorspace for colorspace in config_data['colorSpaces'] if colorspace.name == role_colorspace_name]
+            role_colorspace = None
+            if len(role_colorspaces) > 0:
+                role_colorspace = role_colorspaces[0]
+            else:
+                if reference_data.name == role_colorspace_name:
+                    role_colorspace = reference_data
+
+            if role_colorspace:
+                print( "Adding an alias colorspace named %s, pointing to %s" % (
+                    role_name, role_colorspace.name))
+
+                add_colorspace_aliases(config, reference_data, role_colorspace, [role_name], 'Roles')
+        '''
+
+    print("")
+
     # We add these at the end as some applications use the order of the colorspaces
     # definitions in the config to order the colorspaces in their selection lists.
     # Other go alphabetically. This should keep the alias colorspaces out of the way
     # for the apps that use the order of definition in the config.
     print('Adding the alias colorspaces')
     for reference, colorspace, aliases in alias_colorspaces:
-        add_colorspace_alias(config, reference, colorspace, aliases)
+        add_colorspace_aliases(config, reference, colorspace, aliases)
 
     print("")
 
     print('Adding the diplays and views')
 
+    # Set the color_picking role to be the first Display's Output Transform View
+    default_display_name = config_data['defaultDisplay']
+    default_display_views = config_data['displays'][default_display_name]
+    default_display_colorspace = default_display_views['Output Transform']
+
+    set_config_default_roles(
+        config,
+        color_picking=default_display_colorspace.name)
+
     # Defining the *views* and *displays*.
     displays = []
     views = []
 
-
     # Defining a *generic* *display* and *view* setup.
     if multiple_displays:
         # Built list of looks to add to Displays
@@ -716,6 +802,9 @@ def create_config(config_data,
         looks = ", ".join(looks)
         print( "Creating multiple displays, with looks : %s" % looks)
 
+        # Note: We don't reorder the Displays to put the 'defaultDisplay' first
+        # because OCIO will order them alphabetically when the config is written to disk.
+
         # Create Displays, Views
         for display, view_list in config_data['displays'].iteritems():
             for view_name, colorspace in view_list.iteritems():
@@ -733,17 +822,15 @@ def create_config(config_data,
                     views.append(view_name)
             displays.append(display)
 
+    # Defining the set of *views* and *displays* useful in a *GUI* context.
     else:
-        # Defining the set of *views* and *displays* useful in a *GUI* context.
-        #display_name = 'ACES'
-        single_display_name = config_data['roles']['scene_linear']
+        single_display_name = 'ACES'
+        #single_display_name = config_data['roles']['scene_linear']
         displays.append(single_display_name)
 
-        display_names = sorted(config_data['displays'])
-
         # Make sure the default display is first
-        default_display = config_data['defaultDisplay']
-        display_names.insert(0, display_names.pop(display_names.index(default_display)))
+        display_names = sorted(config_data['displays'])
+        display_names.insert(0, display_names.pop(display_names.index(default_display_name)))
 
         # Built list of looks to add to Displays
         looks = config_data['looks'] if ('looks' in config_data) else []
@@ -756,15 +843,15 @@ def create_config(config_data,
             view_list = config_data['displays'][display]
             for view_name, colorspace in view_list.iteritems():
                 if 'Output Transform' in view_name:
-                    #print( "Adding view for %s" % view_name )
-
-                    # Maya 2016 doesn't like parentheses in View names
-                    display_cleaned = replace(display, {')': '', '(': ''})
+                    #print( "Adding view for %s" % colorspace.name )
 
                     # We use the Display names as the View names in this case
                     # as there is a single Display that contains all views.
                     # This works for more applications than not, as of the time of this implementation.
 
+                    # Maya 2016 doesn't like parentheses in View names
+                    display_cleaned = replace(display, {')': '', '(': ''})
+
                     # If View includes looks
                     if 'with' in view_name:
                         # Integrate looks into view name
@@ -793,6 +880,7 @@ def create_config(config_data,
                             views.append(display_cleaned)
 
         # Add to config any display, view combinations that were saved for later
+        # This list will be empty unless viewsWithLooksAtEnd is set to True above 
         for display_view_colorspace in displays_views_colorspaces:
             single_display_name, display_cleaned, colorspace_name = display_view_colorspace
 
@@ -828,35 +916,6 @@ def create_config(config_data,
 
     print("")
 
-    print('Setting the roles')
-
-    if prefix:
-        set_config_default_roles(
-            config,
-            color_picking=prefixed_names[config_data['roles']['color_picking']],
-            color_timing=prefixed_names[config_data['roles']['color_timing']],
-            compositing_log=prefixed_names[config_data['roles']['compositing_log']],
-            data=prefixed_names[config_data['roles']['data']],
-            default=prefixed_names[config_data['roles']['default']],
-            matte_paint=prefixed_names[config_data['roles']['matte_paint']],
-            reference=prefixed_names[config_data['roles']['reference']],
-            scene_linear=prefixed_names[config_data['roles']['scene_linear']],
-            texture_paint=prefixed_names[config_data['roles']['texture_paint']])
-    else:
-        set_config_default_roles(
-            config,
-            color_picking=config_data['roles']['color_picking'],
-            color_timing=config_data['roles']['color_timing'],
-            compositing_log=config_data['roles']['compositing_log'],
-            data=config_data['roles']['data'],
-            default=config_data['roles']['default'],
-            matte_paint=config_data['roles']['matte_paint'],
-            reference=config_data['roles']['reference'],
-            scene_linear=config_data['roles']['scene_linear'],
-            texture_paint=config_data['roles']['texture_paint'])
-
-    print("")
-
     # Make sure we didn't create a bad config
     config.sanityCheck()
 
@@ -867,12 +926,24 @@ def create_config(config_data,
         for original, prefixed in prefixed_names.iteritems():
             prefixed_names_inverse[prefixed] = original
 
-        # Reet the reference colorspace name
+        # Reset the reference colorspace name
         reference_data.name = prefixed_names_inverse[reference_data.name]
 
         # Reset the rest of the colorspace names
-        for colorspace in config_data['colorSpaces']:
-            colorspace.name = prefixed_names_inverse[colorspace.name]
+        try:
+            for colorspace in config_data['colorSpaces']:
+                colorspace.name = prefixed_names_inverse[colorspace.name]
+        except:
+            print( "Prefixed names")
+            for original, prefixed in prefixed_names.iteritems():
+                print( "%s, %s" % (original, prefixed) )
+
+            print( "\n")
+
+            print( "Inverse Lookup of Prefixed names")
+            for prefixed, original in prefixed_names_inverse.iteritems():
+                print( "%s, %s" % (prefixed, original) )
+            raise
 
     return config
 
@@ -1023,8 +1094,12 @@ def generate_baked_LUTs(odt_info,
          Return value description.
     """
 
-    # Create two entries for ODTs that have full and legal range support
     odt_info_C = dict(odt_info)
+
+    # Uncomment if you would like to support the older behavior where ODTs
+    # that have support for full and legal range output generate a LUT for each.
+    '''
+    # Create two entries for ODTs that have full and legal range support
     for odt_ctl_name, odt_values in odt_info.iteritems():
         if odt_values['transformHasFullLegalSwitch']:
             odt_name = odt_values['transformUserName']
@@ -1038,6 +1113,7 @@ def generate_baked_LUTs(odt_info,
             odt_info_C['%s - Full' % odt_ctl_name] = odt_values_full
 
             del (odt_info_C[odt_ctl_name])
+    '''
 
     # Generate appropriate LUTs for each ODT
     for odt_ctl_name, odt_values in odt_info_C.iteritems():