Comments pruning session.
[OpenColorIO-Configs.git] / aces_1.0.0 / python / aces_ocio / create_sony_colorspaces.py
index db67cb1..fba4c80 100644 (file)
@@ -6,6 +6,7 @@ Implements support for *Sony* colorspaces conversions and transfer functions.
 """
 
 import array
+import os
 
 import aces_ocio.generate_lut as genlut
 from aces_ocio.utilities import ColorSpace, mat44_from_mat33
@@ -42,11 +43,11 @@ def create_s_log(gamut,
          Return value description.
     """
 
-    name = "%s - %s" % (transfer_function, gamut)
-    if transfer_function == "":
-        name = "Linear - %s" % gamut
-    if gamut == "":
-        name = "%s" % transfer_function
+    name = '%s - %s' % (transfer_function, gamut)
+    if transfer_function == '':
+        name = 'Linear - %s' % gamut
+    if gamut == '':
+        name = '%s' % transfer_function
 
     cs = ColorSpace(name)
     cs.description = name
@@ -61,13 +62,12 @@ def create_s_log(gamut,
 
         if (s_log >= ab):
             linear = ((pow(10.,
-                           ((((s_log - b) /
-                              (w - b) - 0.616596 - 0.03) / 0.432699)) -
-                           0.037584) * 0.9))
+                           (((s_log - b) /
+                             (w - b) - 0.616596 - 0.03) / 0.432699)) -
+                       0.037584) * 0.9)
         else:
-            linear = (
-                         ((s_log - b) / (
-                             w - b) - 0.030001222851889303) / 5.) * 0.9
+            linear = (((s_log - b) / (
+                w - b) - 0.030001222851889303) / 5.) * 0.9
         return linear
 
     def s_log2_to_linear(s_log):
@@ -76,89 +76,83 @@ def create_s_log(gamut,
         w = 940.
 
         if (s_log >= ab):
-            linear = (219. * (pow(10.,
-                                  ((((s_log - b) /
+            linear = ((219. * (pow(10.,
+                                   (((s_log - b) /
                                      (w - b) - 0.616596 - 0.03) / 0.432699)) -
-                                  0.037584) / 155.) * 0.9)
+                               0.037584) / 155.) * 0.9)
         else:
             linear = (((s_log - b) / (
                 w - b) - 0.030001222851889303) / 3.53881278538813) * 0.9
         return linear
 
     def s_log3_to_linear(code_value):
-        if code_value >= (171.2102946929):
+        if code_value >= 171.2102946929:
             linear = (pow(10.0, ((code_value - 420.0) / 261.5)) *
                       (0.18 + 0.01) - 0.01)
         else:
             linear = (code_value - 95.0) * 0.01125000 / (171.2102946929 - 95.0)
-        # print(codeValue, linear)
+
         return linear
 
     cs.to_reference_transforms = []
 
-    if transfer_function == "S-Log1":
-        data = array.array('f', "\0" * lut_resolution_1d * 4)
+    if transfer_function == 'S-Log1':
+        data = array.array('f', '\0' * lut_resolution_1d * 4)
         for c in range(lut_resolution_1d):
             data[c] = s_log1_to_linear(1023.0 * c / (lut_resolution_1d - 1))
 
-        lut = "%s_to_linear.spi1d" % transfer_function
-        genlut.write_SPI_1d(lut_directory + "/" + lut,
-                            0.0,
-                            1.0,
-                            data,
-                            lut_resolution_1d,
-                            1)
-
-        # print("Writing %s" % lut)
+        lut = '%s_to_linear.spi1d' % transfer_function
+        genlut.write_SPI_1d(
+            os.path.join(lut_directory, lut),
+            0.0,
+            1.0,
+            data,
+            lut_resolution_1d,
+            1)
 
         cs.to_reference_transforms.append({
             'type': 'lutFile',
             'path': lut,
             'interpolation': 'linear',
-            'direction': 'forward'
-        })
-    elif transfer_function == "S-Log2":
-        data = array.array('f', "\0" * lut_resolution_1d * 4)
+            'direction': 'forward'})
+    elif transfer_function == 'S-Log2':
+        data = array.array('f', '\0' * lut_resolution_1d * 4)
         for c in range(lut_resolution_1d):
             data[c] = s_log2_to_linear(1023.0 * c / (lut_resolution_1d - 1))
 
-        lut = "%s_to_linear.spi1d" % transfer_function
-        genlut.write_SPI_1d(lut_directory + "/" + lut,
-                            0.0,
-                            1.0,
-                            data,
-                            lut_resolution_1d,
-                            1)
-
-        # print("Writing %s" % lut)
+        lut = '%s_to_linear.spi1d' % transfer_function
+        genlut.write_SPI_1d(
+            os.path.join(lut_directory, lut),
+            0.0,
+            1.0,
+            data,
+            lut_resolution_1d,
+            1)
 
         cs.to_reference_transforms.append({
             'type': 'lutFile',
             'path': lut,
             'interpolation': 'linear',
-            'direction': 'forward'
-        })
-    elif transfer_function == "S-Log3":
-        data = array.array('f', "\0" * lut_resolution_1d * 4)
+            'direction': 'forward'})
+    elif transfer_function == 'S-Log3':
+        data = array.array('f', '\0' * lut_resolution_1d * 4)
         for c in range(lut_resolution_1d):
             data[c] = s_log3_to_linear(1023.0 * c / (lut_resolution_1d - 1))
 
-        lut = "%s_to_linear.spi1d" % transfer_function
-        genlut.write_SPI_1d(lut_directory + "/" + lut,
-                            0.0,
-                            1.0,
-                            data,
-                            lut_resolution_1d,
-                            1)
-
-        # print("Writing %s" % lut)
+        lut = '%s_to_linear.spi1d' % transfer_function
+        genlut.write_SPI_1d(
+            os.path.join(lut_directory, lut),
+            0.0,
+            1.0,
+            data,
+            lut_resolution_1d,
+            1)
 
         cs.to_reference_transforms.append({
             'type': 'lutFile',
             'path': lut,
             'interpolation': 'linear',
-            'direction': 'forward'
-        })
+            'direction': 'forward'})
 
     if gamut == 'S-Gamut':
         cs.to_reference_transforms.append({
@@ -222,122 +216,121 @@ def create_colorspaces(lut_directory, lut_resolution_1d):
 
     colorspaces = []
 
-    # S-Log1
+    # *S-Log1*
     s_log1_s_gamut = create_s_log(
-        "S-Gamut",
-        "S-Log1",
-        "S-Log",
+        'S-Gamut',
+        'S-Log1',
+        'S-Log',
         lut_directory,
         lut_resolution_1d)
     colorspaces.append(s_log1_s_gamut)
 
-    # S-Log2
+    # *S-Log2*
     s_log2_s_gamut = create_s_log(
-        "S-Gamut",
-        "S-Log2",
-        "S-Log2",
+        'S-Gamut',
+        'S-Log2',
+        'S-Log2',
         lut_directory,
         lut_resolution_1d)
     colorspaces.append(s_log2_s_gamut)
 
     s_log2_s_gamut_daylight = create_s_log(
-        "S-Gamut Daylight",
-        "S-Log2",
-        "S-Log2",
+        'S-Gamut Daylight',
+        'S-Log2',
+        'S-Log2',
         lut_directory,
         lut_resolution_1d)
     colorspaces.append(s_log2_s_gamut_daylight)
 
     s_log2_s_gamut_tungsten = create_s_log(
-        "S-Gamut Tungsten",
-        "S-Log2",
-        "S-Log2",
+        'S-Gamut Tungsten',
+        'S-Log2',
+        'S-Log2',
         lut_directory,
         lut_resolution_1d)
     colorspaces.append(s_log2_s_gamut_tungsten)
 
-    # S-Log3
+    # *S-Log3*
     s_log3_s_gamut3Cine = create_s_log(
-        "S-Gamut3.Cine",
-        "S-Log3",
-        "S-Log3",
+        'S-Gamut3.Cine',
+        'S-Log3',
+        'S-Log3',
         lut_directory,
         lut_resolution_1d)
     colorspaces.append(s_log3_s_gamut3Cine)
 
     s_log3_s_gamut3 = create_s_log(
-        "S-Gamut3",
-        "S-Log3",
-        "S-Log3",
+        'S-Gamut3',
+        'S-Log3',
+        'S-Log3',
         lut_directory,
         lut_resolution_1d)
     colorspaces.append(s_log3_s_gamut3)
 
-    # Linearization only
+    # Linearization Only
     s_log1 = create_s_log(
-        "",
-        "S-Log1",
-        "S-Log",
+        '',
+        'S-Log1',
+        'S-Log',
         lut_directory,
         lut_resolution_1d)
     colorspaces.append(s_log1)
 
     s_log2 = create_s_log(
-        "",
-        "S-Log2",
-        "S-Log2",
+        '',
+        'S-Log2',
+        'S-Log2',
         lut_directory,
         lut_resolution_1d)
     colorspaces.append(s_log2)
 
     s_log3 = create_s_log(
-        "",
-        "S-Log3",
-        "S-Log3",
+        '',
+        'S-Log3',
+        'S-Log3',
         lut_directory,
         lut_resolution_1d)
     colorspaces.append(s_log3)
 
-    # Primaries only
+    # Primaries Only
     s_gamut = create_s_log(
-        "S-Gamut",
-        "",
-        "S-Log",
+        'S-Gamut',
+        '',
+        'S-Log',
         lut_directory,
         lut_resolution_1d)
     colorspaces.append(s_gamut)
 
     s_gamut_daylight = create_s_log(
-        "S-Gamut Daylight",
-        "",
-        "S-Log2",
+        'S-Gamut Daylight',
+        '',
+        'S-Log2',
         lut_directory,
         lut_resolution_1d)
     colorspaces.append(s_gamut_daylight)
 
     s_gamut_tungsten = create_s_log(
-        "S-Gamut Tungsten",
-        "",
-        "S-Log2",
+        'S-Gamut Tungsten',
+        '',
+        'S-Log2',
         lut_directory,
         lut_resolution_1d)
     colorspaces.append(s_gamut_tungsten)
 
     s_gamut3Cine = create_s_log(
-        "S-Gamut3.Cine",
-        "",
-        "S-Log3",
+        'S-Gamut3.Cine',
+        '',
+        'S-Log3',
         lut_directory,
         lut_resolution_1d)
     colorspaces.append(s_gamut3Cine)
 
     s_gamut3 = create_s_log(
-        "S-Gamut3",
-        "",
-        "S-Log3",
+        'S-Gamut3',
+        '',
+        'S-Log3',
         lut_directory,
         lut_resolution_1d)
     colorspaces.append(s_gamut3)
 
     return colorspaces
-