Shaper LUTs are now single channel. They were previously three channel, with the...
[OpenColorIO-Configs.git] / aces_1.0.0 / python / aces_ocio / create_aces_colorspaces.py
index 0a79ec6..c4ba524 100644 (file)
@@ -5,6 +5,8 @@
 Implements support for *ACES* colorspaces conversions and transfer functions.
 """
 
+from __future__ import division
+
 import math
 import numpy
 import os
@@ -49,16 +51,26 @@ __all__ = ['ACES_AP1_TO_AP0',
            'get_LMTs_info',
            'create_colorspaces']
 
-# Matrix converting *ACES AP1* primaries to *AP0*.
+# Matrix converting *ACES AP1* primaries to *ACES AP0*.
 ACES_AP1_TO_AP0 = [0.6954522414, 0.1406786965, 0.1638690622,
                    0.0447945634, 0.8596711185, 0.0955343182,
                    -0.0055258826, 0.0040252103, 1.0015006723]
 
+# Matrix converting *ACES AP0* primaries to *ACES AP1*.
+ACES_AP0_TO_AP1 = [1.4514393161, -0.2365107469, -0.2149285693,
+                   -0.0765537734, 1.1762296998, -0.0996759264,
+                   0.0083161484, -0.0060324498, 0.9977163014]
+
 # Matrix converting *ACES AP0* primaries to *XYZ*.
 ACES_AP0_TO_XYZ = [0.9525523959, 0.0000000000, 0.0000936786,
                    0.3439664498, 0.7281660966, -0.0721325464,
                    0.0000000000, 0.0000000000, 1.0088251844]
 
+# Matrix converting *ACES AP0* primaries to *XYZ*.
+ACES_XYZ_TO_AP0 = [1.0498110175, 0.0000000000, -0.0000974845,
+                   -0.4959030231, 1.3733130458, 0.0982400361,
+                   0.0000000000, 0.0000000000, 0.9912520182]
+
 
 def create_ACES():
     """
@@ -84,7 +96,7 @@ def create_ACES():
     aces2065_1.family = 'ACES'
     aces2065_1.is_data = False
     aces2065_1.allocation_type = ocio.Constants.ALLOCATION_LG2
-    aces2065_1.allocation_vars = [-15, 6]
+    aces2065_1.allocation_vars = [-8, 5, 0.00390625]
 
     return aces2065_1
 
@@ -94,9 +106,9 @@ def create_ACEScc(aces_ctl_directory,
                   lut_resolution_1d,
                   cleanup,
                   name='ACEScc',
-                  min_value=0.0,
-                  max_value=1.0,
-                  input_scale=1.0):
+                  min_value=0,
+                  max_value=1,
+                  input_scale=1):
     """
     Creates the *ACEScc* colorspace.
 
@@ -117,17 +129,13 @@ def create_ACEScc(aces_ctl_directory,
     cs.equality_group = ''
     cs.family = 'ACES'
     cs.is_data = False
+    cs.allocation_type = ocio.Constants.ALLOCATION_UNIFORM
+    cs.allocation_vars = [min_value, max_value]
 
     ctls = [os.path.join(aces_ctl_directory,
                          'ACEScc',
-                         'ACEScsc.ACEScc_to_ACES.a1.0.0.ctl'),
-            # This transform gets back to the *AP1* primaries.
-            # Useful as the 1d LUT is only covering the transfer function.
-            # The primaries switch is covered by the matrix below:
-            os.path.join(aces_ctl_directory,
-                         'ACEScg',
-                         'ACEScsc.ACES_to_ACEScg.a1.0.0.ctl')]
-    lut = '%s_to_ACES.spi1d' % name
+                         'ACEScsc.ACEScc_to_ACES.a1.0.0.ctl')]
+    lut = '%s_to_linear.spi1d' % name
 
     lut = sanitize(lut)
 
@@ -137,12 +145,13 @@ def create_ACEScc(aces_ctl_directory,
         lut_resolution_1d,
         'float',
         input_scale,
-        1.0,
-        {},
+        1,
+        {'transferFunctionOnly':1},
         cleanup,
         aces_ctl_directory,
         min_value,
-        max_value)
+        max_value,
+        1)
 
     cs.to_reference_transforms = []
     cs.to_reference_transforms.append({
@@ -190,13 +199,13 @@ def create_ACESproxy(aces_ctl_directory,
     ctls = [os.path.join(aces_ctl_directory,
                          'ACESproxy',
                          'ACEScsc.ACESproxy10i_to_ACES.a1.0.0.ctl'),
-            # This transform gets back to the *AP1* primaries.
-            # Useful as the 1d LUT is only covering the transfer function.
-            # The primaries switch is covered by the matrix below:
-            os.path.join(aces_ctl_directory,
-                         'ACEScg',
-                         'ACEScsc.ACES_to_ACEScg.a1.0.0.ctl')]
-    lut = '%s_to_aces.spi1d' % name
+                          # This transform gets back to the *AP1* primaries.
+                          # Useful as the 1d LUT is only covering the transfer function.
+                          # The primaries switch is covered by the matrix below:
+                          os.path.join(aces_ctl_directory,
+                                       'ACEScg',
+                                       'ACEScsc.ACES_to_ACEScg.a1.0.0.ctl')]
+    lut = '%s_to_linear.spi1d' % name
 
     lut = sanitize(lut)
 
@@ -205,11 +214,14 @@ def create_ACESproxy(aces_ctl_directory,
         ctls,
         lut_resolution_1d,
         'uint16',
-        64.0,
-        1.0,
+        64,
+        1,
         {},
         cleanup,
-        aces_ctl_directory)
+        aces_ctl_directory,
+        0,
+        1,
+        1)
 
     cs.to_reference_transforms = []
     cs.to_reference_transforms.append({
@@ -256,6 +268,8 @@ def create_ACEScg(aces_ctl_directory,
     cs.equality_group = ''
     cs.family = 'ACES'
     cs.is_data = False
+    cs.allocation_type = ocio.Constants.ALLOCATION_LG2
+    cs.allocation_vars = [-8, 5, 0.00390625]
 
     cs.to_reference_transforms = []
 
@@ -300,18 +314,18 @@ def create_ADX(lut_directory,
 
     if bit_depth == 10:
         cs.bit_depth = ocio.Constants.BIT_DEPTH_UINT10
-        ADX_to_CDD = [1023.0 / 500.0, 0.0, 0.0, 0.0,
-                      0.0, 1023.0 / 500.0, 0.0, 0.0,
-                      0.0, 0.0, 1023.0 / 500.0, 0.0,
-                      0.0, 0.0, 0.0, 1.0]
-        offset = [-95.0 / 500.0, -95.0 / 500.0, -95.0 / 500.0, 0.0]
+        ADX_to_CDD = [1023 / 500, 0, 0, 0,
+                      0, 1023 / 500, 0, 0,
+                      0, 0, 1023 / 500, 0,
+                      0, 0, 0, 1]
+        offset = [-95 / 500, -95 / 500, -95 / 500, 0]
     elif bit_depth == 16:
         cs.bit_depth = ocio.Constants.BIT_DEPTH_UINT16
-        ADX_to_CDD = [65535.0 / 8000.0, 0.0, 0.0, 0.0,
-                      0.0, 65535.0 / 8000.0, 0.0, 0.0,
-                      0.0, 0.0, 65535.0 / 8000.0, 0.0,
-                      0.0, 0.0, 0.0, 1.0]
-        offset = [-1520.0 / 8000.0, -1520.0 / 8000.0, -1520.0 / 8000.0, 0.0]
+        ADX_to_CDD = [65535 / 8000, 0, 0, 0,
+                      0, 65535 / 8000, 0, 0,
+                      0, 0, 65535 / 8000, 0,
+                      0, 0, 0, 1]
+        offset = [-1520 / 8000, -1520 / 8000, -1520 / 8000, 0]
 
     cs.to_reference_transforms = []
 
@@ -328,7 +342,7 @@ def create_ADX(lut_directory,
         'matrix': [0.75573, 0.22197, 0.02230, 0,
                    0.05901, 0.96928, -0.02829, 0,
                    0.16134, 0.07406, 0.76460, 0,
-                   0.0, 0.0, 0.0, 1.0],
+                   0, 0, 0, 1],
         'direction': 'forward'})
 
     # Copied from *Alex Fry*'s *adx_cid_to_rle.py*
@@ -361,13 +375,13 @@ def create_ADX(lut_directory,
                      -1.121718645000000,
                      -0.926545676714876]
 
-        REF_PT = ((7120.0 - 1520.0) / 8000.0 * (100.0 / 55.0) -
-                  math.log(0.18, 10.0))
+        REF_PT = ((7120 - 1520) / 8000 * (100 / 55) -
+                  math.log(0.18, 10))
 
         def cid_to_rle(x):
             if x <= 0.6:
                 return interpolate_1D(x, LUT_1D_xp, LUT_1D_fp)
-            return (100.0 / 55.0) * x - REF_PT
+            return (100 / 55) * x - REF_PT
 
         def fit(value, from_min, from_max, to_min, to_max):
             if from_min == from_max:
@@ -376,11 +390,11 @@ def create_ADX(lut_directory,
                 to_max - to_min) + to_min
 
         num_samples = 2 ** 12
-        domain = (-0.19, 3.0)
+        domain = (-0.19, 3)
         data = []
         for i in xrange(num_samples):
-            x = i / (num_samples - 1.0)
-            x = fit(x, 0.0, 1.0, domain[0], domain[1])
+            x = i / (num_samples - 1)
+            x = fit(x, 0, 1, domain[0], domain[1])
             data.append(cid_to_rle(x))
 
         lut = 'ADX_CID_to_RLE.spi1d'
@@ -414,7 +428,7 @@ def create_ADX(lut_directory,
         'matrix': [0.72286, 0.12630, 0.15084, 0,
                    0.11923, 0.76418, 0.11659, 0,
                    0.01427, 0.08213, 0.90359, 0,
-                   0.0, 0.0, 0.0, 1.0],
+                   0, 0, 0, 1],
         'direction': 'forward'})
 
     cs.from_reference_transforms = []
@@ -429,7 +443,7 @@ def create_ACES_LMT(lmt_name,
                     lut_resolution_1d=1024,
                     lut_resolution_3d=64,
                     cleanup=True,
-                    aliases=[]):
+                    aliases=None):
     """
     Creates the *ACES LMT* colorspace.
 
@@ -444,12 +458,17 @@ def create_ACES_LMT(lmt_name,
          *ACES LMT* colorspace.
     """
 
+    if aliases is None:
+        aliases = []
+
     cs = ColorSpace('%s' % lmt_name)
     cs.description = 'The ACES Look Transform: %s' % lmt_name
     cs.aliases = aliases
     cs.equality_group = ''
     cs.family = 'Look'
     cs.is_data = False
+    cs.allocation_type = ocio.Constants.ALLOCATION_LG2
+    cs.allocation_vars = [-8, 5, 0.00390625]
 
     pprint.pprint(lmt_values)
 
@@ -460,7 +479,7 @@ def create_ACES_LMT(lmt_name,
      shaper_input_scale,
      shaper_params) = shaper_info
 
-    shaper_lut = '%s_to_aces.spi1d' % shaper_name
+    shaper_lut = '%s_to_linear.spi1d' % shaper_name
     if not os.path.exists(os.path.join(lut_directory, shaper_lut)):
         ctls = [shaper_to_ACES_CTL % aces_ctl_directory]
 
@@ -471,11 +490,14 @@ def create_ACES_LMT(lmt_name,
             ctls,
             lut_resolution_1d,
             'float',
-            1.0 / shaper_input_scale,
-            1.0,
+            1 / shaper_input_scale,
+            1,
             shaper_params,
             cleanup,
-            aces_ctl_directory)
+            aces_ctl_directory,
+            0,
+            1,
+            1)
 
     shaper_OCIO_transform = {
         'type': 'lutFile',
@@ -499,8 +521,8 @@ def create_ACES_LMT(lmt_name,
             ctls,
             lut_resolution_3d,
             'float',
-            1.0 / shaper_input_scale,
-            1.0,
+            1 / shaper_input_scale,
+            1,
             shaper_params,
             cleanup,
             aces_ctl_directory)
@@ -517,9 +539,7 @@ def create_ACES_LMT(lmt_name,
 
     if 'transformCTLInverse' in lmt_values:
         ctls = [os.path.join(aces_ctl_directory,
-                             # TODO: Investigate "odt_values" undeclared
-                             # variable.
-                             odt_values['transformCTLInverse']),
+                             lmt_values['transformCTLInverse']),
                 shaper_from_ACES_CTL % aces_ctl_directory]
         lut = 'Inverse.%s.%s.spi3d' % (odt_name, shaper_name)
 
@@ -530,11 +550,14 @@ def create_ACES_LMT(lmt_name,
             ctls,
             lut_resolution_3d,
             'half',
-            1.0,
+            1,
             shaper_input_scale,
             shaper_params,
             cleanup,
-            aces_ctl_directory)
+            aces_ctl_directory,
+            0,
+            1,
+            1)
 
         cs.to_reference_transforms.append({
             'type': 'lutFile',
@@ -557,7 +580,7 @@ def create_ACES_RRT_plus_ODT(odt_name,
                              lut_resolution_1d=1024,
                              lut_resolution_3d=64,
                              cleanup=True,
-                             aliases=[]):
+                             aliases=None):
     """
     Object description.
 
@@ -572,6 +595,9 @@ def create_ACES_RRT_plus_ODT(odt_name,
          Return value description.
     """
 
+    if aliases is None:
+        aliases = []
+
     cs = ColorSpace('%s' % odt_name)
     cs.description = '%s - %s Output Transform' % (
         odt_values['transformUserNamePrefix'], odt_name)
@@ -594,7 +620,7 @@ def create_ACES_RRT_plus_ODT(odt_name,
     else:
         shaper_params['legalRange'] = 0
 
-    shaper_lut = '%s_to_aces.spi1d' % shaper_name
+    shaper_lut = '%s_to_linear.spi1d' % shaper_name
     if not os.path.exists(os.path.join(lut_directory, shaper_lut)):
         ctls = [shaper_to_ACES_CTL % aces_ctl_directory]
 
@@ -605,11 +631,14 @@ def create_ACES_RRT_plus_ODT(odt_name,
             ctls,
             lut_resolution_1d,
             'float',
-            1.0 / shaper_input_scale,
-            1.0,
+            1 / shaper_input_scale,
+            1,
             shaper_params,
             cleanup,
-            aces_ctl_directory)
+            aces_ctl_directory,
+            0,
+            1,
+            1)
 
     shaper_OCIO_transform = {
         'type': 'lutFile',
@@ -651,8 +680,8 @@ def create_ACES_RRT_plus_ODT(odt_name,
             ctls,
             lut_resolution_3d,
             'float',
-            1.0 / shaper_input_scale,
-            1.0,
+            1 / shaper_input_scale,
+            1,
             shaper_params,
             cleanup,
             aces_ctl_directory)
@@ -700,7 +729,7 @@ def create_ACES_RRT_plus_ODT(odt_name,
             ctls,
             lut_resolution_3d,
             'half',
-            1.0,
+            1,
             shaper_input_scale,
             shaper_params,
             cleanup,
@@ -725,11 +754,11 @@ def create_generic_log(aces_ctl_directory,
                        cleanup,
                        name='log',
                        aliases=[],
-                       min_value=0.0,
-                       max_value=1.0,
-                       input_scale=1.0,
+                       min_value=0,
+                       max_value=1,
+                       input_scale=1,
                        middle_grey=0.18,
-                       min_exposure=-6.0,
+                       min_exposure=-6,
                        max_exposure=6.5):
     """
     Creates the *Generic Log* colorspace.
@@ -756,7 +785,7 @@ def create_generic_log(aces_ctl_directory,
         aces_ctl_directory,
         'utilities',
         'ACESlib.OCIO_shaper_log2_to_lin_param.a1.0.0.ctl')]
-    lut = '%s_to_aces.spi1d' % name
+    lut = '%s_to_linear.spi1d' % name
 
     lut = sanitize(lut)
 
@@ -766,14 +795,15 @@ def create_generic_log(aces_ctl_directory,
         lut_resolution_1d,
         'float',
         input_scale,
-        1.0,
+        1,
         {'middleGrey': middle_grey,
          'minExposure': min_exposure,
          'maxExposure': max_exposure},
         cleanup,
         aces_ctl_directory,
         min_value,
-        max_value)
+        max_value,
+        1)
 
     cs.to_reference_transforms = []
     cs.to_reference_transforms.append({
@@ -820,7 +850,7 @@ def create_LMTs(aces_ctl_directory,
     lmt_shaper_name_aliases = ['crv_lmtshaper']
     lmt_params = {
         'middleGrey': 0.18,
-        'minExposure': -10.0,
+        'minExposure': -10,
         'maxExposure': 6.5}
 
     lmt_shaper = create_generic_log(aces_ctl_directory,
@@ -834,7 +864,7 @@ def create_LMTs(aces_ctl_directory,
                                     aliases=lmt_shaper_name_aliases)
     colorspaces.append(lmt_shaper)
 
-    shaper_input_scale_generic_log2 = 1.0
+    shaper_input_scale_generic_log2 = 1
 
     # *Log 2* shaper name and *CTL* transforms bundled up.
     lmt_shaper_data = [
@@ -904,7 +934,7 @@ def create_ODTs(aces_ctl_directory,
     log2_shaper_name_aliases = ["crv_%s" % compact(shaper_name)]
     log2_params = {
         'middleGrey': 0.18,
-        'minExposure': -6.0,
+        'minExposure': -6,
         'maxExposure': 6.5}
 
     log2_shaper = create_generic_log(
@@ -919,7 +949,7 @@ def create_ODTs(aces_ctl_directory,
         aliases=log2_shaper_name_aliases)
     colorspaces.append(log2_shaper)
 
-    shaper_input_scale_generic_log2 = 1.0
+    shaper_input_scale_generic_log2 = 1
 
     # *Log 2* shaper name and *CTL* transforms bundled up.
     log2_shaper_data = [
@@ -1268,7 +1298,8 @@ def create_colorspaces(aces_ctl_directory,
     ACES = create_ACES()
 
     ACEScc = create_ACEScc(aces_ctl_directory, lut_directory,
-                           lut_resolution_1d, cleanup)
+                           lut_resolution_1d, cleanup, 
+                           min_value=-0.35840, max_value=1.468)
     colorspaces.append(ACEScc)
 
     ACESproxy = create_ACESproxy(aces_ctl_directory, lut_directory,