Enforce quotes consistency.
[OpenColorIO-Configs.git] / aces_1.0.0 / python / aces_ocio / generate_lut.py
index e0d4dfa..78bc9f6 100644 (file)
@@ -52,7 +52,7 @@ def generate_1d_LUT_image(ramp_1d_path,
          Return value description.
     """
 
-    # print("Generate 1d LUT image - %s" % ramp1dPath)
+    # print('Generate 1d LUT image - %s' % ramp1dPath)
 
     # open image
     format = os.path.splitext(ramp_1d_path)[1]
@@ -68,8 +68,8 @@ def generate_1d_LUT_image(ramp_1d_path,
 
     ramp.open(ramp_1d_path, spec, oiio.Create)
 
-    data = array.array("f",
-                       "\0" * spec.width * spec.height * spec.nchannels * 4)
+    data = array.array('f',
+                       '\0' * spec.width * spec.height * spec.nchannels * 4)
     for i in range(resolution):
         value = float(i) / (resolution - 1) * (
             max_value - min_value) + min_value
@@ -100,17 +100,17 @@ def write_SPI_1d(filename, from_min, from_max, data, entries, channels):
     """
 
     f = file(filename, 'w')
-    f.write("Version 1\n")
-    f.write("From %f %f\n" % (from_min, from_max))
-    f.write("Length %d\n" % entries)
-    f.write("Components %d\n" % (min(3, channels)))
-    f.write("{\n")
+    f.write('Version 1\n')
+    f.write('From %f %f\n' % (from_min, from_max))
+    f.write('Length %d\n' % entries)
+    f.write('Components %d\n' % (min(3, channels)))
+    f.write('{\n')
     for i in range(0, entries):
-        entry = ""
+        entry = ''
         for j in range(0, min(3, channels)):
-            entry = "%s %s" % (entry, data[i * channels + j])
-        f.write("        %s\n" % entry)
-    f.write("}\n")
+            entry = '%s %s' % (entry, data[i * channels + j])
+        f.write('        %s\n' % entry)
+    f.write('}\n')
     f.close()
 
 
@@ -133,7 +133,7 @@ def generate_1d_LUT_from_image(ramp_1d_path,
     """
 
     if output_path is None:
-        output_path = ramp_1d_path + ".spi1d"
+        output_path = ramp_1d_path + '.spi1d'
 
     # open image
     ramp = oiio.ImageInput.open(ramp_1d_path)
@@ -169,15 +169,15 @@ def generate_3d_LUT_image(ramp_3d_path, resolution=32):
          Return value description.
     """
 
-    args = ["--generate",
-            "--cubesize",
+    args = ['--generate',
+            '--cubesize',
             str(resolution),
-            "--maxwidth",
+            '--maxwidth',
             str(resolution * resolution),
-            "--output",
+            '--output',
             ramp_3d_path]
-    lut_extract = Process(description="generate a 3d LUT image",
-                          cmd="ociolutimage",
+    lut_extract = Process(description='generate a 3d LUT image',
+                          cmd='ociolutimage',
                           args=args)
     lut_extract.execute()
 
@@ -198,19 +198,19 @@ def generate_3d_LUT_from_image(ramp_3d_path, output_path=None, resolution=32):
     """
 
     if output_path is None:
-        output_path = ramp_3d_path + ".spi3d"
+        output_path = ramp_3d_path + '.spi3d'
 
-    args = ["--extract",
-            "--cubesize",
+    args = ['--extract',
+            '--cubesize',
             str(resolution),
-            "--maxwidth",
+            '--maxwidth',
             str(resolution * resolution),
-            "--input",
+            '--input',
             ramp_3d_path,
-            "--output",
+            '--output',
             output_path]
-    lut_extract = Process(description="extract a 3d LUT",
-                          cmd="ociolutimage",
+    lut_extract = Process(description='extract a 3d LUT',
+                          cmd='ociolutimage',
                           args=args)
     lut_extract.execute()
 
@@ -239,8 +239,8 @@ def apply_CTL_to_image(input_image,
     if len(ctl_paths) > 0:
         ctlenv = os.environ
         if aces_CTL_directory != None:
-            if os.path.split(aces_CTL_directory)[1] != "utilities":
-                ctl_module_path = "%s/utilities" % aces_CTL_directory
+            if os.path.split(aces_CTL_directory)[1] != 'utilities':
+                ctl_module_path = '%s/utilities' % aces_CTL_directory
             else:
                 ctl_module_path = aces_CTL_directory
             ctlenv['CTL_MODULE_PATH'] = ctl_module_path
@@ -248,20 +248,20 @@ def apply_CTL_to_image(input_image,
         args = []
         for ctl in ctl_paths:
             args += ['-ctl', ctl]
-        args += ["-force"]
-        # args += ["-verbose"]
-        args += ["-input_scale", str(input_scale)]
-        args += ["-output_scale", str(output_scale)]
-        args += ["-global_param1", "aIn", "1.0"]
+        args += ['-force']
+        # args += ['-verbose']
+        args += ['-input_scale', str(input_scale)]
+        args += ['-output_scale', str(output_scale)]
+        args += ['-global_param1', 'aIn', '1.0']
         for key, value in global_params.iteritems():
-            args += ["-global_param1", key, str(value)]
+            args += ['-global_param1', key, str(value)]
         args += [input_image]
         args += [output_image]
 
-        # print("args : %s" % args)
+        # print('args : %s' % args)
 
-        ctlp = Process(description="a ctlrender process",
-                       cmd="ctlrender",
+        ctlp = Process(description='a ctlrender process',
+                       cmd='ctlrender',
                        args=args, env=ctlenv)
 
         ctlp.execute()
@@ -283,12 +283,12 @@ def convert_bit_depth(input_image, output_image, depth):
     """
 
     args = [input_image,
-            "-d",
+            '-d',
             depth,
-            "-o",
+            '-o',
             output_image]
-    convert = Process(description="convert image bit depth",
-                      cmd="oiiotool",
+    convert = Process(description='convert image bit depth',
+                      cmd='oiiotool',
                       args=args)
     convert.execute()
 
@@ -323,21 +323,21 @@ def generate_1d_LUT_from_CTL(lut_path,
 
     lut_path_base = os.path.splitext(lut_path)[0]
 
-    identity_LUT_image_float = lut_path_base + ".float.tiff"
+    identity_LUT_image_float = lut_path_base + '.float.tiff'
     generate_1d_LUT_image(identity_LUT_image_float,
                           lut_resolution,
                           min_value,
                           max_value)
 
     if identity_LUT_bit_depth != 'half':
-        identity_LUT_image = lut_path_base + ".uint16.tiff"
+        identity_LUT_image = lut_path_base + '.uint16.tiff'
         convert_bit_depth(identity_LUT_image_float,
                           identity_LUT_image,
                           identity_LUT_bit_depth)
     else:
         identity_LUT_image = identity_LUT_image_float
 
-    transformed_LUT_image = lut_path_base + ".transformed.exr"
+    transformed_LUT_image = lut_path_base + '.transformed.exr'
     apply_CTL_to_image(identity_LUT_image,
                        transformed_LUT_image,
                        ctl_paths,
@@ -387,13 +387,13 @@ def correct_LUT_image(transformed_LUT_image,
 
     # rotate or not
     if width != lut_resolution * lut_resolution or height != lut_resolution:
-        print(("Correcting image as resolution is off. "
-               "Found %d x %d. Expected %d x %d") % (
+        print(('Correcting image as resolution is off. '
+               'Found %d x %d. Expected %d x %d') % (
                   width,
                   height,
                   lut_resolution * lut_resolution,
                   lut_resolution))
-        print("Generating %s" % corrected_LUT_image)
+        print('Generating %s' % corrected_LUT_image)
 
         #
         # We're going to generate a new correct image
@@ -417,8 +417,8 @@ def correct_LUT_image(transformed_LUT_image,
 
         correct.open(corrected_LUT_image, correct_spec, oiio.Create)
 
-        dest_data = array.array("f",
-                                ("\0" * correct_spec.width *
+        dest_data = array.array('f',
+                                ('\0' * correct_spec.width *
                                  correct_spec.height *
                                  correct_spec.nchannels * 4))
         for j in range(0, correct_spec.height):
@@ -471,21 +471,21 @@ def generate_3d_LUT_from_CTL(lut_path,
 
     lut_path_base = os.path.splitext(lut_path)[0]
 
-    identity_LUT_image_float = lut_path_base + ".float.tiff"
+    identity_LUT_image_float = lut_path_base + '.float.tiff'
     generate_3d_LUT_image(identity_LUT_image_float, lut_resolution)
 
     if identity_LUT_bit_depth != 'half':
         identity_LUT_image = (lut_path_base +
-                              "." +
+                              '.' +
                               identity_LUT_bit_depth +
-                              ".tiff")
+                              '.tiff')
         convert_bit_depth(identity_LUT_image_float,
                           identity_LUT_image,
                           identity_LUT_bit_depth)
     else:
         identity_LUT_image = identity_LUT_image_float
 
-    transformed_LUT_image = lut_path_base + ".transformed.exr"
+    transformed_LUT_image = lut_path_base + '.transformed.exr'
     apply_CTL_to_image(identity_LUT_image,
                        transformed_LUT_image,
                        ctl_paths,
@@ -494,7 +494,7 @@ def generate_3d_LUT_from_CTL(lut_path,
                        global_params,
                        aces_CTL_directory)
 
-    corrected_LUT_image = lut_path_base + ".correct.exr"
+    corrected_LUT_image = lut_path_base + '.correct.exr'
     corrected_LUT_image = correct_LUT_image(transformed_LUT_image,
                                             corrected_LUT_image,
                                             lut_resolution)
@@ -534,22 +534,22 @@ def main():
         version='0.01',
         usage='%prog [options]')
 
-    p.add_option('--lut', '-l', type="string", default="")
-    p.add_option('--ctl', '-c', type="string", action="append")
-    p.add_option('--lut_resolution_1d', '', type="int", default=1024)
-    p.add_option('--lut_resolution_3d', '', type="int", default=33)
-    p.add_option('--ctlReleasePath', '-r', type="string", default="")
-    p.add_option('--bitDepth', '-b', type="string", default="float")
-    p.add_option('--keepTempImages', '', action="store_true")
-    p.add_option('--minValue', '', type="float", default=0.0)
-    p.add_option('--maxValue', '', type="float", default=1.0)
-    p.add_option('--inputScale', '', type="float", default=1.0)
-    p.add_option('--outputScale', '', type="float", default=1.0)
-    p.add_option('--ctlRenderParam', '-p', type="string", nargs=2,
-                 action="append")
-
-    p.add_option('--generate1d', '', action="store_true")
-    p.add_option('--generate3d', '', action="store_true")
+    p.add_option('--lut', '-l', type='string', default='')
+    p.add_option('--ctl', '-c', type='string', action='append')
+    p.add_option('--lut_resolution_1d', '', type='int', default=1024)
+    p.add_option('--lut_resolution_3d', '', type='int', default=33)
+    p.add_option('--ctlReleasePath', '-r', type='string', default='')
+    p.add_option('--bitDepth', '-b', type='string', default='float')
+    p.add_option('--keepTempImages', '', action='store_true')
+    p.add_option('--minValue', '', type='float', default=0.0)
+    p.add_option('--maxValue', '', type='float', default=1.0)
+    p.add_option('--inputScale', '', type='float', default=1.0)
+    p.add_option('--outputScale', '', type='float', default=1.0)
+    p.add_option('--ctlRenderParam', '-p', type='string', nargs=2,
+                 action='append')
+
+    p.add_option('--generate1d', '', action='store_true')
+    p.add_option('--generate3d', '', action='store_true')
 
     options, arguments = p.parse_args()
 
@@ -582,28 +582,28 @@ def main():
         args_start = len(sys.argv) + 1
         args = []
 
-    # print("command line : \n%s\n" % " ".join(sys.argv))
+    # print('command line : \n%s\n' % ' '.join(sys.argv))
 
     #
     # Generate LUTs
     #
     if generate_1d:
-        print("1D LUT generation options")
+        print('1D LUT generation options')
     else:
-        print("3D LUT generation options")
-
-    print("lut                 : %s" % lut)
-    print("ctls                : %s" % ctls)
-    print("lut res 1d          : %s" % lut_resolution_1d)
-    print("lut res 3d          : %s" % lut_resolution_3d)
-    print("min value           : %s" % min_value)
-    print("max value           : %s" % max_value)
-    print("input scale         : %s" % input_scale)
-    print("output scale        : %s" % output_scale)
-    print("ctl render params   : %s" % params)
-    print("ctl release path    : %s" % ctl_release_path)
-    print("bit depth of input  : %s" % bitdepth)
-    print("cleanup temp images : %s" % cleanup)
+        print('3D LUT generation options')
+
+    print('lut                 : %s' % lut)
+    print('ctls                : %s' % ctls)
+    print('lut res 1d          : %s' % lut_resolution_1d)
+    print('lut res 3d          : %s' % lut_resolution_3d)
+    print('min value           : %s' % min_value)
+    print('max value           : %s' % max_value)
+    print('input scale         : %s' % input_scale)
+    print('output scale        : %s' % output_scale)
+    print('ctl render params   : %s' % params)
+    print('ctl release path    : %s' % ctl_release_path)
+    print('bit depth of input  : %s' % bitdepth)
+    print('cleanup temp images : %s' % cleanup)
 
     if generate_1d:
         generate_1d_LUT_from_CTL(lut,
@@ -629,8 +629,8 @@ def main():
                                  cleanup,
                                  ctl_release_path)
     else:
-        print(("\n\nNo LUT generated. "
-               "You must choose either 1D or 3D LUT generation\n\n"))
+        print(('\n\nNo LUT generated. '
+               'You must choose either 1D or 3D LUT generation\n\n'))
 
 
 if __name__ == '__main__':