Ensuring that there is a 'raw' alias for the Raw colorspace
[OpenColorIO-Configs.git] / aces_1.0.0 / python / aces_ocio / colorspaces / general.py
index 348e9b2..1a05f06 100644 (file)
@@ -62,8 +62,8 @@ def create_matrix_colorspace(name='matrix',
     cs.is_data = False
 
     # A linear space needs allocation variables
-    cs.allocation_type = ocio.Constants.ALLOCATION_LG2
-    cs.allocation_vars = [-8, 5, 0.00390625]
+    cs.allocation_type = ocio.Constants.ALLOCATION_UNIFORM
+    cs.allocation_vars = [0, 1]
 
     cs.to_reference_transforms = []
     if to_reference_values:
@@ -84,7 +84,70 @@ def create_matrix_colorspace(name='matrix',
     return cs
 
 # -------------------------------------------------------------------------
-# *Matrix Transform*
+# *Transfer Function Transform*
+# -------------------------------------------------------------------------
+def create_transfer_colorspace(name='transfer',
+                               transfer_function_name='transfer_function',
+                               transfer_function=lambda x: x,
+                               lut_directory='/tmp',
+                               lut_resolution_1d=1024,
+                               aliases=[]):
+    """
+    Object description.
+
+    Parameters
+    ----------
+    parameter : type
+        Parameter description.
+
+    Returns
+    -------
+    type
+         Return value description.
+    """
+
+    cs = ColorSpace(name)
+    cs.description = 'The %s color space' % name
+    cs.aliases = aliases
+    cs.equality_group = name
+    cs.family = 'Utility'
+    cs.is_data = False
+
+    # A linear space needs allocation variables
+    cs.allocation_type = ocio.Constants.ALLOCATION_UNIFORM
+    cs.allocation_vars = [0, 1]
+
+    # Sample the transfer function
+    data = array.array('f', '\0' * lut_resolution_1d * 4)
+    for c in range(lut_resolution_1d):
+        data[c] = transfer_function(c / (lut_resolution_1d - 1))
+
+    # Write the sampled data to a LUT
+    lut = '%s_to_linear.spi1d' % transfer_function_name
+    genlut.write_SPI_1d(
+        os.path.join(lut_directory, lut),
+        0,
+        1,
+        data,
+        lut_resolution_1d,
+        1)
+
+    # Create the 'to_reference' transforms
+    cs.to_reference_transforms = []
+    cs.to_reference_transforms.append({
+        'type': 'lutFile',
+        'path': lut,
+        'interpolation': 'linear',
+        'direction': 'forward'})
+
+    # Create the 'from_reference' transforms
+    cs.from_reference_transforms = []
+
+    return cs
+# create_transfer_colorspace
+
+# -------------------------------------------------------------------------
+# *Transfer Function + Matrix Transform*
 # -------------------------------------------------------------------------
 def create_matrix_plus_transfer_colorspace(name='matrix_plus_transfer',
                                            transfer_function_name='transfer_function',
@@ -122,8 +185,8 @@ def create_matrix_plus_transfer_colorspace(name='matrix_plus_transfer',
     cs.is_data = False
 
     # A linear space needs allocation variables
-    cs.allocation_type = ocio.Constants.ALLOCATION_LG2
-    cs.allocation_vars = [-8, 5, 0.00390625]
+    cs.allocation_type = ocio.Constants.ALLOCATION_UNIFORM
+    cs.allocation_vars = [0, 1]
 
     # Sample the transfer function
     data = array.array('f', '\0' * lut_resolution_1d * 4)
@@ -142,13 +205,13 @@ def create_matrix_plus_transfer_colorspace(name='matrix_plus_transfer',
 
     # Create the 'to_reference' transforms
     cs.to_reference_transforms = []
-    cs.to_reference_transforms.append({
-        'type': 'lutFile',
-        'path': lut,
-        'interpolation': 'linear',
-        'direction': 'forward'})
-
     if to_reference_values:
+        cs.to_reference_transforms.append({
+            'type': 'lutFile',
+            'path': lut,
+            'interpolation': 'linear',
+            'direction': 'forward'})
+
         for matrix in to_reference_values:
             cs.to_reference_transforms.append({
                 'type': 'matrix',
@@ -164,13 +227,14 @@ def create_matrix_plus_transfer_colorspace(name='matrix_plus_transfer',
                 'matrix': mat44_from_mat33(matrix),
                 'direction': 'forward'})
 
-    cs.from_reference_transforms.append({
-        'type': 'lutFile',
-        'path': lut,
-        'interpolation': 'linear',
-        'direction': 'inverse'})
+        cs.from_reference_transforms.append({
+            'type': 'lutFile',
+            'path': lut,
+            'interpolation': 'linear',
+            'direction': 'inverse'})
 
     return cs
+# create_matrix_plus_transfer_colorspace
 
 # Transfer functions for standard color spaces
 def transfer_function_sRGB_to_linear(v):
@@ -189,7 +253,7 @@ def transfer_function_Rec709_to_linear(v):
     d = 4.5
     g = (1.0/0.45)
 
-    if v < b:
+    if v < b*d:
         return v/d
 
     return pow(((v + (a - 1)) / a), g)
@@ -200,7 +264,7 @@ def transfer_function_Rec2020_10bit_to_linear(v):
     d = 4.5
     g = (1.0/0.45)
 
-    if v < b:
+    if v < b*d:
         return v/d
 
     return pow(((v + (a - 1)) / a), g)
@@ -211,7 +275,7 @@ def transfer_function_Rec2020_12bit_to_linear(v):
     d = 4.5
     g = (1.0/0.45)
 
-    if v < b:
+    if v < b*d:
         return v/d
 
     return pow(((v + (a - 1)) / a), g)
@@ -252,20 +316,10 @@ def create_colorspaces(lut_directory,
     #
     # XYZ
     #
-    cs = create_matrix_colorspace('XYZ',
+    cs = create_matrix_colorspace('XYZ-D60',
                                to_reference_values=[aces.ACES_XYZ_TO_AP0],
                                from_reference_values=[aces.ACES_AP0_TO_XYZ],
-                               aliases=["lin_xyz"])
-    colorspaces.append(cs)
-
-    #
-    # AP1
-    #
-    cs = create_matrix_colorspace(
-        'Linear - AP1',
-        to_reference_values=[aces.ACES_AP1_TO_AP0],
-        from_reference_values=[aces.ACES_AP0_TO_AP1],
-        aliases=["lin_ap1"])
+                               aliases=["lin_xyz_d60"])
     colorspaces.append(cs)
 
     #
@@ -297,41 +351,6 @@ def create_colorspaces(lut_directory,
     colorspaces.append(cs)
 
     #
-    # Rec 709
-    #
-    # *ACES* to *Linear*, *Rec. 709* primaries.
-    XYZ_to_Rec709 = [3.2409699419, -1.5373831776, -0.4986107603,
-                     -0.9692436363, 1.8759675015, 0.0415550574,
-                     0.0556300797, -0.2039769589, 1.0569715142]
-
-    cs = create_matrix_colorspace(
-        'Linear - Rec.709',
-        from_reference_values=[aces.ACES_AP0_TO_XYZ, XYZ_to_Rec709],
-        aliases=["lin_rec709"])
-    colorspaces.append(cs)
-
-    # *Linear* to *Rec. 709* Transfer Function*
-    cs = create_matrix_plus_transfer_colorspace(
-        'Curve - Rec.709',
-        'rec709',
-        transfer_function_Rec709_to_linear,
-        lut_directory,
-        lut_resolution_1d,
-        aliases=["crv_rec709"])
-    colorspaces.append(cs)
-
-    # *ACES* to *Rec. 709* Primaries + Transfer Function*
-    cs = create_matrix_plus_transfer_colorspace(
-        'Rec.709',
-        'rec709',
-        transfer_function_Rec709_to_linear,
-        lut_directory,
-        lut_resolution_1d,
-        from_reference_values=[aces.ACES_AP0_TO_XYZ, XYZ_to_Rec709],
-        aliases=["rec709"])
-    colorspaces.append(cs)
-
-    #
     # sRGB
     #
     # *ACES* to *Linear*, *Rec. 709* primaries.
@@ -343,17 +362,17 @@ def create_colorspaces(lut_directory,
     cs = create_matrix_colorspace(
         'Linear - sRGB',
         from_reference_values=[aces.ACES_AP0_TO_XYZ, XYZ_to_Rec709],
-        aliases=["lin_sRGB"])
+        aliases=["lin_srgb"])
     colorspaces.append(cs)
 
     # *Linear* to *sRGB* Transfer Function*
-    cs = create_matrix_plus_transfer_colorspace(
+    cs = create_transfer_colorspace(
         'Curve - sRGB',
         'sRGB',
         transfer_function_sRGB_to_linear,
         lut_directory,
         lut_resolution_1d,
-        aliases=["crv_sRGB"])
+        aliases=["crv_srgb"])
     colorspaces.append(cs)
 
     # *ACES* to *sRGB* Primaries + Transfer Function*
@@ -364,43 +383,42 @@ def create_colorspaces(lut_directory,
         lut_directory,
         lut_resolution_1d,
         from_reference_values=[aces.ACES_AP0_TO_XYZ, XYZ_to_Rec709],
-        aliases=["sRGB"])
+        aliases=["srgb"])
     colorspaces.append(cs)
 
     #
-    # Rec 1886
+    # Rec 709
     #
     # *ACES* to *Linear*, *Rec. 709* primaries.
-    # Rec 1886 and Rec 709 use the same gamut
     XYZ_to_Rec709 = [3.2409699419, -1.5373831776, -0.4986107603,
                      -0.9692436363, 1.8759675015, 0.0415550574,
                      0.0556300797, -0.2039769589, 1.0569715142]
 
     cs = create_matrix_colorspace(
-        'Linear - Rec.1886',
+        'Linear - Rec.709',
         from_reference_values=[aces.ACES_AP0_TO_XYZ, XYZ_to_Rec709],
-        aliases=["lin_rec1886"])
+        aliases=["lin_rec709"])
     colorspaces.append(cs)
 
-    # *Linear* to *sRGB* Transfer Function*
-    cs = create_matrix_plus_transfer_colorspace(
-        'Curve - Rec.1886',
-        'rec1886',
-        transfer_function_Rec1886_to_linear,
+    # *Linear* to *Rec. 709* Transfer Function*
+    cs = create_transfer_colorspace(
+        'Curve - Rec.709',
+        'rec709',
+        transfer_function_Rec709_to_linear,
         lut_directory,
         lut_resolution_1d,
-        aliases=["crv_rec1886"])
+        aliases=["crv_rec709"])
     colorspaces.append(cs)
 
-    # *ACES* to *sRGB* Primaries + Transfer Function*
+    # *ACES* to *Rec. 709* Primaries + Transfer Function*
     cs = create_matrix_plus_transfer_colorspace(
-        'Rec.1886',
-        'rec1886',
-        transfer_function_Rec1886_to_linear,
+        'Rec.709 - Camera',
+        'rec709',
+        transfer_function_Rec709_to_linear,
         lut_directory,
         lut_resolution_1d,
         from_reference_values=[aces.ACES_AP0_TO_XYZ, XYZ_to_Rec709],
-        aliases=["rec1886"])
+        aliases=["rec709_camera"])
     colorspaces.append(cs)
 
     #
@@ -418,45 +436,60 @@ def create_colorspaces(lut_directory,
     colorspaces.append(cs)
 
     # *Linear* to *Rec. 2020 10 bit* Transfer Function*
-    cs = create_matrix_plus_transfer_colorspace(
-        'Curve - Rec.2020 - 10 bit',
+    cs = create_transfer_colorspace(
+        'Curve - Rec.2020',
         'rec2020',
         transfer_function_Rec2020_10bit_to_linear,
         lut_directory,
         lut_resolution_1d,
-        aliases=["crv_rec202010bit"])
+        aliases=["crv_rec2020"])
     colorspaces.append(cs)
 
     # *ACES* to *Rec. 2020 10 bit* Primaries + Transfer Function*
     cs = create_matrix_plus_transfer_colorspace(
-        'Rec.2020 10 bit - Rec.2020',
+        'Rec.2020 - Camera',
         'rec2020',
         transfer_function_Rec2020_10bit_to_linear,
         lut_directory,
         lut_resolution_1d,
         from_reference_values=[aces.ACES_AP0_TO_XYZ, XYZ_to_Rec2020],
-        aliases=["rec202010bit"])
+        aliases=["rec2020_camera"])
     colorspaces.append(cs)
 
-    # *Linear* to *Rec. 2020 10 bit* Transfer Function*
+    #
+    # Rec 1886
+    #
+
+    # *Linear* to *Rec.1886* Transfer Function*
+    cs = create_transfer_colorspace(
+        'Curve - Rec.1886',
+        'rec1886',
+        transfer_function_Rec1886_to_linear,
+        lut_directory,
+        lut_resolution_1d,
+        aliases=["crv_rec1886"])
+    colorspaces.append(cs)
+
+    # *ACES* to *sRGB* Primaries + Transfer Function*
     cs = create_matrix_plus_transfer_colorspace(
-        'Curve - Rec.2020 - 12 bit',
-        'rec2020',
-        transfer_function_Rec2020_12bit_to_linear,
+        'Rec.709 - Display',
+        'rec1886',
+        transfer_function_Rec1886_to_linear,
         lut_directory,
         lut_resolution_1d,
-        aliases=["crv_rec202012bit"])
+        from_reference_values=[aces.ACES_AP0_TO_XYZ, XYZ_to_Rec709],
+        aliases=["rec709_display"])
     colorspaces.append(cs)
 
-    # *ACES* to *Rec. 2020 10 bit* Primaries + Transfer Function*
+    # *ACES* to *sRGB* Primaries + Transfer Function*
     cs = create_matrix_plus_transfer_colorspace(
-        'Rec.2020 12 bit - Rec.2020',
-        'rec2020',
-        transfer_function_Rec2020_12bit_to_linear,
+        'Rec.2020 - Display',
+        'rec1886',
+        transfer_function_Rec1886_to_linear,
         lut_directory,
         lut_resolution_1d,
         from_reference_values=[aces.ACES_AP0_TO_XYZ, XYZ_to_Rec2020],
-        aliases=["rec202012bit"])
+        aliases=["rec2020_display"])
     colorspaces.append(cs)
 
     #
@@ -510,7 +543,7 @@ def create_raw():
     name = "Raw"
     raw = ColorSpace(name)
     raw.description = 'The %s color space' % name
-    raw.aliases = []
+    raw.aliases = ["raw"]
     raw.equality_group = name
     raw.family = 'Utility'
     raw.is_data = True