Roles now have some assignments
[OpenColorIO-Configs.git] / aces_1.0.0 / python / aces_ocio / create_aces_config.py
index 72badd8..1de65b1 100755 (executable)
@@ -5,9 +5,9 @@
 Defines objects creating the *ACES* configuration.
 """
 
-import math
+from __future__ import division
+
 import os
-import shutil
 import sys
 
 import PyOpenColorIO as ocio
@@ -15,16 +15,12 @@ import PyOpenColorIO as ocio
 import aces_ocio.create_aces_colorspaces as aces
 import aces_ocio.create_arri_colorspaces as arri
 import aces_ocio.create_canon_colorspaces as canon
+import aces_ocio.create_panasonic_colorspaces as panasonic
 import aces_ocio.create_red_colorspaces as red
 import aces_ocio.create_sony_colorspaces as sony
 import aces_ocio.create_general_colorspaces as general
 
-from aces_ocio.generate_lut import (
-    generate_1d_LUT_from_CTL,
-    generate_3d_LUT_from_CTL,
-    write_SPI_1d)
 from aces_ocio.process import Process
-from aces_ocio.utilities import ColorSpace, mat44_from_mat33, sanitize_path, compact
 
 __author__ = 'ACES Developers'
 __copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers'
@@ -38,6 +34,7 @@ __all__ = ['ACES_OCIO_CTL_DIRECTORY_ENVIRON',
            'set_config_default_roles',
            'write_config',
            'generate_OCIO_transform',
+           'add_colorspace_alias',
            'create_config',
            'generate_LUTs',
            'generate_baked_LUTs',
@@ -158,12 +155,11 @@ def generate_OCIO_transform(transforms):
     interpolation_options = {
         'linear': ocio.Constants.INTERP_LINEAR,
         'nearest': ocio.Constants.INTERP_NEAREST,
-        'tetrahedral': ocio.Constants.INTERP_TETRAHEDRAL
-    }
+        'tetrahedral': ocio.Constants.INTERP_TETRAHEDRAL}
+
     direction_options = {
         'forward': ocio.Constants.TRANSFORM_DIR_FORWARD,
-        'inverse': ocio.Constants.TRANSFORM_DIR_INVERSE
-    }
+        'inverse': ocio.Constants.TRANSFORM_DIR_INVERSE}
 
     ocio_transforms = []
 
@@ -177,7 +173,7 @@ def generate_OCIO_transform(transforms):
                     transform['interpolation']],
                 direction=direction_options[transform['direction']])
             ocio_transforms.append(ocio_transform)
-        
+
         # matrix transform
         elif transform['type'] == 'matrix':
             ocio_transform = ocio.MatrixTransform()
@@ -210,11 +206,12 @@ def generate_OCIO_transform(transforms):
 
         # color space transform
         elif transform['type'] == 'colorspace':
-            ocio_transform = ocio.ColorSpaceTransform( src=transform['src'],
-                dst=transform['dst'],
-                direction=direction_options['forward'] )
+            ocio_transform = ocio.ColorSpaceTransform(src=transform['src'],
+                                                      dst=transform['dst'],
+                                                      direction=
+                                                      direction_options[
+                                                          'forward'])
             ocio_transforms.append(ocio_transform)
-
         # unknown type
         else:
             print("Ignoring unknown transform type : %s" % transform['type'])
@@ -229,7 +226,11 @@ def generate_OCIO_transform(transforms):
 
     return transform
 
-def add_colorspace_alias(config, reference_colorspace, colorspace, colorspace_alias_names):
+
+def add_colorspace_alias(config,
+                         reference_colorspace,
+                         colorspace,
+                         colorspace_alias_names):
     """
     Object description.
 
@@ -248,10 +249,10 @@ def add_colorspace_alias(config, reference_colorspace, colorspace, colorspace_al
         if alias_name == colorspace.name.lower():
             return
 
-        print( "Adding alias colorspace space %s, alias to %s" % (
+        print('Adding alias colorspace space %s, alias to %s' % (
             alias_name, colorspace.name))
 
-        compact_family_name = "Aliases"
+        compact_family_name = 'Aliases'
 
         ocio_colorspace_alias = ocio.ColorSpace(
             name=alias_name,
@@ -263,26 +264,24 @@ def add_colorspace_alias(config, reference_colorspace, colorspace, colorspace_al
             allocation=colorspace.allocation_type,
             allocationVars=colorspace.allocation_vars)
 
-        if colorspace.to_reference_transforms != []:
-            print("Generating To-Reference transforms")
-            ocio_transform = generate_OCIO_transform([{
-                'type': 'colorspace',
-                'src': colorspace.name,
-                'dst': reference_colorspace.name,
-                'direction': 'forward'
-                }])
+        if not colorspace.to_reference_transforms:
+            print('Generating To-Reference transforms')
+            ocio_transform = generate_OCIO_transform(
+                [{'type': 'colorspace',
+                  'src': colorspace.name,
+                  'dst': reference_colorspace.name,
+                  'direction': 'forward'}])
             ocio_colorspace_alias.setTransform(
                 ocio_transform,
                 ocio.Constants.COLORSPACE_DIR_TO_REFERENCE)
 
-        if colorspace.from_reference_transforms != []:
-            print("Generating From-Reference transforms")
-            ocio_transform = generate_OCIO_transform([{
-                'type': 'colorspace',
-                'src': reference_colorspace.name,
-                'dst': colorspace.name,
-                'direction': 'forward'
-                }])
+        if not colorspace.from_reference_transforms:
+            print('Generating From-Reference transforms')
+            ocio_transform = generate_OCIO_transform(
+                [{'type': 'colorspace',
+                  'src': reference_colorspace.name,
+                  'dst': colorspace.name,
+                  'direction': 'forward'}])
             ocio_colorspace_alias.setTransform(
                 ocio_transform,
                 ocio.Constants.COLORSPACE_DIR_FROM_REFERENCE)
@@ -331,7 +330,7 @@ def create_config(config_data, nuke=False):
     # Add alias
     if reference_data.aliases != []:
         add_colorspace_alias(config, reference_data,
-            reference_data, reference_data.aliases)
+                             reference_data, reference_data.aliases)
 
     print("")
 
@@ -371,8 +370,8 @@ def create_config(config_data, nuke=False):
         # Add alias to normal colorspace, using compact name
         #
         if colorspace.aliases != []:
-            add_colorspace_alias(config, reference_data, 
-                colorspace, colorspace.aliases)
+            add_colorspace_alias(config, reference_data,
+                                 colorspace, colorspace.aliases)
 
         print('')
 
@@ -414,24 +413,25 @@ def create_config(config_data, nuke=False):
 
     set_config_default_roles(
         config,
-        color_picking=reference.getName(),
-        color_timing=reference.getName(),
-        compositing_log=reference.getName(),
-        data=reference.getName(),
-        default=reference.getName(),
-        matte_paint=reference.getName(),
-        reference=reference.getName(),
-        scene_linear=reference.getName(),
-        texture_paint=reference.getName())
+        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'])
 
     config.sanityCheck()
 
     return config
 
+
 def generate_LUTs(odt_info,
                   lmt_info,
                   shaper_name,
-                  aces_CTL_directory,
+                  aces_ctl_directory,
                   lut_directory,
                   lut_resolution_1d=4096,
                   lut_resolution_3d=64,
@@ -464,18 +464,20 @@ def generate_LUTs(odt_info,
 
     # *ACES* colorspaces
     (aces_reference,
-     aces_colorspaces, 
+     aces_colorspaces,
      aces_displays,
-     aces_log_display_space) = aces.create_colorspaces(aces_CTL_directory,
-                                                       lut_directory, 
-                                                       lut_resolution_1d,
-                                                       lut_resolution_3d,
-                                                       lmt_info,
-                                                       odt_info,
-                                                       shaper_name,
-                                                       cleanup)
+     aces_log_display_space,
+     aces_roles) = aces.create_colorspaces(aces_ctl_directory,
+                                           lut_directory,
+                                           lut_resolution_1d,
+                                           lut_resolution_3d,
+                                           lmt_info,
+                                           odt_info,
+                                           shaper_name,
+                                           cleanup)
 
     config_data['referenceColorSpace'] = aces_reference
+    config_data['roles'] = aces_roles
 
     for cs in aces_colorspaces:
         config_data['colorSpaces'].append(cs)
@@ -490,7 +492,7 @@ def generate_LUTs(odt_info,
     # *Camera Input Transforms*
     # -------------------------------------------------------------------------
 
-    # *Log-C* to *ACES*.
+    # *ARRI Log-C* to *ACES*.
     arri_colorSpaces = arri.create_colorspaces(lut_directory,
                                                lut_resolution_1d)
     for cs in arri_colorSpaces:
@@ -502,8 +504,14 @@ def generate_LUTs(odt_info,
     for cs in canon_colorspaces:
         config_data['colorSpaces'].append(cs)
 
+    # *Panasonic V-Log* to *ACES*.
+    panasonic_colorSpaces = panasonic.create_colorspaces(lut_directory,
+                                                         lut_resolution_1d)
+    for cs in panasonic_colorSpaces:
+        config_data['colorSpaces'].append(cs)
+
     # *RED* colorspaces to *ACES*.
-    red_colorspaces = red.create_colorspaces(lut_directory, 
+    red_colorspaces = red.create_colorspaces(lut_directory,
                                              lut_resolution_1d)
     for cs in red_colorspaces:
         config_data['colorSpaces'].append(cs)
@@ -523,6 +531,18 @@ def generate_LUTs(odt_info,
     for cs in general_colorSpaces:
         config_data['colorSpaces'].append(cs)
 
+    # The *Raw* color space
+    raw = general.create_raw()
+    config_data['colorSpaces'].append(raw)
+
+    # Override 'linear' display
+    config_data['linearDisplaySpace'] = raw
+
+    # Override certain roles, for now
+    config_data['roles']['data'] = raw.name
+    config_data['roles']['reference'] = raw.name
+    config_data['roles']['texture_paint'] = raw.name
+
     print('generateLUTs - end')
     return config_data
 
@@ -550,22 +570,22 @@ def generate_baked_LUTs(odt_info,
 
     # Create two entries for ODTs that have full and legal range support
     odt_info_C = dict(odt_info)
-    for odt_CTL_name, odt_values in odt_info.iteritems():
+    for odt_ctl_name, odt_values in odt_info.iteritems():
         if odt_values['transformHasFullLegalSwitch']:
             odt_name = odt_values['transformUserName']
 
             odt_values_legal = dict(odt_values)
             odt_values_legal['transformUserName'] = '%s - Legal' % odt_name
-            odt_info_C['%s - Legal' % odt_CTL_name] = odt_values_legal
+            odt_info_C['%s - Legal' % odt_ctl_name] = odt_values_legal
 
             odt_values_full = dict(odt_values)
             odt_values_full['transformUserName'] = '%s - Full' % odt_name
-            odt_info_C['%s - Full' % odt_CTL_name] = odt_values_full
+            odt_info_C['%s - Full' % odt_ctl_name] = odt_values_full
 
-            del (odt_info_C[odt_CTL_name])
+            del (odt_info_C[odt_ctl_name])
 
     # Generate appropriate LUTs for each ODT
-    for odt_CTL_name, odt_values in odt_info_C.iteritems():
+    for odt_ctl_name, odt_values in odt_info_C.iteritems():
         odt_prefix = odt_values['transformUserNamePrefix']
         odt_name = odt_values['transformUserName']
 
@@ -588,10 +608,10 @@ def generate_baked_LUTs(odt_info,
                                   'photoshop',
                                   '%s for %s.icc' % (odt_name, input_space))]
 
-            bake_LUT = Process(description='bake a LUT',
+            bake_lut = Process(description='bake a LUT',
                                cmd='ociobakelut',
                                args=args)
-            bake_LUT.execute()
+            bake_lut.execute()
 
         # *Flame*, *Lustre*
         for input_space in ['ACEScc', 'ACESproxy']:
@@ -612,10 +632,10 @@ def generate_baked_LUTs(odt_info,
                          baked_directory,
                          'flame',
                          '%s for %s Flame.3dl' % (odt_name, input_space))]
-            bake_LUT = Process(description='bake a LUT',
+            bake_lut = Process(description='bake a LUT',
                                cmd='ociobakelut',
                                args=(args + fargs))
-            bake_LUT.execute()
+            bake_lut.execute()
 
             largs = ['--format',
                      'lustre',
@@ -623,10 +643,10 @@ def generate_baked_LUTs(odt_info,
                          baked_directory,
                          'lustre',
                          '%s for %s Lustre.3dl' % (odt_name, input_space))]
-            bake_LUT = Process(description='bake a LUT',
+            bake_lut = Process(description='bake a LUT',
                                cmd='ociobakelut',
                                args=(args + largs))
-            bake_LUT.execute()
+            bake_lut.execute()
 
         # *Maya*, *Houdini*
         for input_space in ['ACEScg', 'ACES2065-1']:
@@ -652,10 +672,10 @@ def generate_baked_LUTs(odt_info,
                          baked_directory,
                          'maya',
                          '%s for %s Maya.csp' % (odt_name, input_space))]
-            bake_LUT = Process(description='bake a LUT',
+            bake_lut = Process(description='bake a LUT',
                                cmd='ociobakelut',
                                args=(args + margs))
-            bake_LUT.execute()
+            bake_lut.execute()
 
             hargs = ['--format',
                      'houdini',
@@ -663,10 +683,10 @@ def generate_baked_LUTs(odt_info,
                          baked_directory,
                          'houdini',
                          '%s for %s Houdini.lut' % (odt_name, input_space))]
-            bake_LUT = Process(description='bake a LUT',
+            bake_lut = Process(description='bake a LUT',
                                cmd='ociobakelut',
                                args=(args + hargs))
-            bake_LUT.execute()
+            bake_lut.execute()
 
 
 def create_config_dir(config_directory, bake_secondary_LUTs):
@@ -699,7 +719,8 @@ def create_config_dir(config_directory, bake_secondary_LUTs):
 
     return lut_directory
 
-def create_ACES_config(aces_CTL_directory,
+
+def create_ACES_config(aces_ctl_directory,
                        config_directory,
                        lut_resolution_1d=4096,
                        lut_resolution_3d=64,
@@ -721,14 +742,14 @@ def create_ACES_config(aces_CTL_directory,
 
     lut_directory = create_config_dir(config_directory, bake_secondary_LUTs)
 
-    odt_info = aces.get_ODT_info(aces_CTL_directory)
-    lmt_info = aces.get_LMT_info(aces_CTL_directory)
+    odt_info = aces.get_ODTs_info(aces_ctl_directory)
+    lmt_info = aces.get_LMTs_info(aces_ctl_directory)
 
     shaper_name = 'Output Shaper'
     config_data = generate_LUTs(odt_info,
                                 lmt_info,
                                 shaper_name,
-                                aces_CTL_directory,
+                                aces_ctl_directory,
                                 lut_directory,
                                 lut_resolution_1d,
                                 lut_resolution_3d,
@@ -792,11 +813,11 @@ def main():
 
     options, arguments = p.parse_args()
 
-    aces_CTL_directory = options.acesCTLDir
+    aces_ctl_directory = options.acesCTLDir
     config_directory = options.configDir
     lut_resolution_1d = int(options.lutResolution1d)
     lut_resolution_3d = int(options.lutResolution3d)
-    bake_secondary_LUTs = not options.dontBakeSecondaryLUTs
+    bake_secondary_luts = not options.dontBakeSecondaryLUTs
     cleanup_temp_images = not options.keepTempImages
 
     # TODO: Investigate the following statements.
@@ -809,7 +830,7 @@ def main():
 
     print('command line : \n%s\n' % ' '.join(sys.argv))
 
-    assert aces_CTL_directory is not None, (
+    assert aces_ctl_directory is not None, (
         'process: No "{0}" environment variable defined or no "ACES CTL" '
         'directory specified'.format(
             ACES_OCIO_CTL_DIRECTORY_ENVIRON))
@@ -819,11 +840,11 @@ def main():
         'directory specified'.format(
             ACES_OCIO_CONFIGURATION_DIRECTORY_ENVIRON))
 
-    return create_ACES_config(aces_CTL_directory,
+    return create_ACES_config(aces_ctl_directory,
                               config_directory,
                               lut_resolution_1d,
                               lut_resolution_3d,
-                              bake_secondary_LUTs,
+                              bake_secondary_luts,
                               cleanup_temp_images)