From: hpd Date: Tue, 20 Jan 2015 02:53:57 +0000 (-0800) Subject: Merge pull request #2 from colour-science/code_style X-Git-Url: http://users.mur.at/ms/git/gitweb/?p=OpenColorIO-Configs.git;a=commitdiff_plain;h=c8a3f414098c640cdcfa0c5329637b4bfc913433;hp=355167cd6a9c220f9828791d46620548af0798bb Merge pull request #2 from colour-science/code_style PR: Improve various code style aspects and add pseudo-binary calling scripts. --- diff --git a/aces_1.0.0/README b/aces_1.0.0/README deleted file mode 100644 index ed7bf1c..0000000 --- a/aces_1.0.0/README +++ /dev/null @@ -1,87 +0,0 @@ -ACES VERSION: 1.0 - -Information about ACES ----------------------- -The ACES home page is here -- http://www.oscars.org/aces - -Generating configurations -------------------------- -Configurations can be generated by the Python script here: -- https://github.com/hpd/OpenColorIO-Configs/tree/master/aces_1.0.0/python -The resolution of 1D and 3D LUTs can be set by the user. -Usage is described at the head of the file. - -Two resolutions of configs are available. -- The current, default resolution is 33x33x33 for the 3D LUTs and 1024 for the 1D LUTs. ---- That can be grabbed from the current repo. ---- https://github.com/hpd/OpenColorIO-Configs/tree/master/aces_1.0.0/luts ---- https://github.com/hpd/OpenColorIO-Configs/tree/master/aces_1.0.0/baked - -- A previous commit had resolutions of 65x65x65 for the 3D LUTs and 4096 for the 1D LUTs ---- Those LUTs can be grabbed from the following earlier commit ---- https://github.com/hpd/OpenColorIO-Configs/tree/3df6975d47cdea87abdbbadf6640fc707f4728f0/aces_1.0.0/luts ---- https://github.com/hpd/OpenColorIO-Configs/tree/3df6975d47cdea87abdbbadf6640fc707f4728f0/aces_1.0.0/baked - -ACES CTL code used as source for configuration can be found here -- https://github.com/ampas/aces-dev/tree/v1.0 -- https://github.com/ampas/aces-dev/releases/tag/v1.0 - -Transforms ----------- -Transforms generated based on the following sources - -ACES2065, ACEScc, ACESproxy, ACEScg -Ouput Transforms (RRT/ODTs), LMTs -- https://github.com/ampas/aces-dev/tree/v1.0/transforms/ctl - -ARRI -- https://github.com/ampas/aces-dev/tree/v1.0/transforms/ctl/idt/vendorSupplied/arri/alexa -- Conversations with Joseph Goldstone of ARRI - -Canon -- http://usa.canon.com/cusa/professional/standard_display/aces -- http://learn.usa.canon.com/app/pdfs/white_papers/White_Paper_Clog_optoelectronic.pdf -- http://www.usa.canon.com/cusa/professional/products/professional_cameras/cinema_eos_cameras/eos_c500#DriversAndSoftware -- http://www.usa.canon.com/cusa/professional/products/professional_cameras/cinema_eos_cameras/eos_c300#DriversAndSoftware ---- Choose 'OSX Mountain Lion v10.8' to download the IDTs -- http://www.usa.canon.com/cusa/professional/products/professional_cameras/cinema_eos_cameras/eos_c100#DriversAndSoftware ---- Choose 'OSX Mountain Lion v10.8' to download the IDTs - -RED -- http://www.red.com/learn/red-101/redlogfilm-redgamma -- Conversations with Graeme Nattress of RED - -Sony -- https://github.com/ampas/aces-dev/tree/v1.0/transforms/ctl/idt/vendorSupplied/sony - -ADX -- https://github.com/imageworks/OpenColorIO-Configs/tree/master/aces_0.7.1 -- https://github.com/ampas/aces-dev/tree/v1.0/transforms/ctl/unbuild/universal - -Thanks ------- -The script used to generate these transforms and the transforms themselves were the product of work and conversations with a number of people. Thanks go to - -Steve Agland -Joe Bogacz -Scott Dyer -Alex Fry -Alex Forsythe -Joseph Goldstone -Jim Houston -Thomas Mansencal -Will McCown -Graeme Nattress -Doug Walker - -Dependencies ------------- -The Python config generation script depends on the following packages -OpenImageIO -- http://openimageio.org - -OpenColorIO -- http://opencolorio.org/ - - diff --git a/aces_1.0.0/README.md b/aces_1.0.0/README.md new file mode 100644 index 0000000..2ab0e19 --- /dev/null +++ b/aces_1.0.0/README.md @@ -0,0 +1,85 @@ +ACES 1.0.0 +========== + +Informations about ACES +----------------------- + +The **ACES** project home page is here: http://www.oscars.org/aces + +Generating Configurations +------------------------- + +Configurations can be generated by the following *Python* package: https://github.com/hpd/OpenColorIO-Configs/tree/master/aces_1.0.0/python + +The resolution of 1D and 3D LUTs can be set by the user. + +Usage is described in the package root [\_\_init__.py](https://github.com/hpd/OpenColorIO-Configs/blob/master/aces_1.0.0/python/aces_ocio/__init__.py) file. + +Two resolutions of configuration are available: + +- The current, default resolution is 33x33x33 for the 3D LUTs and 1024 for the 1D LUTs. They can be retrieved from the current repository: + - https://github.com/hpd/OpenColorIO-Configs/tree/master/aces_1.0.0/luts + - https://github.com/hpd/OpenColorIO-Configs/tree/master/aces_1.0.0/baked + +- A previous commit had resolutions of 65x65x65 for the 3D LUTs and 4096 for the 1D LUTs. They can be retrieved from the following commit: + - https://github.com/hpd/OpenColorIO-Configs/tree/3df6975d47cdea87abdbbadf6640fc707f4728f0/aces_1.0.0/luts + - https://github.com/hpd/OpenColorIO-Configs/tree/3df6975d47cdea87abdbbadf6640fc707f4728f0/aces_1.0.0/baked + +The **ACES CTL** code used as source for the configuration is available here: +- https://github.com/ampas/aces-dev/tree/v1.0 +- https://github.com/ampas/aces-dev/releases/tag/v1.0 + +Transforms +---------- +Transforms generated based on the following sources: + +### ACES2065, ACEScc, ACESproxy, ACEScg Output Transforms (RRT/ODTs), LMTs +- https://github.com/ampas/aces-dev/tree/v1.0/transforms/ctl + +### ARRI +- https://github.com/ampas/aces-dev/tree/v1.0/transforms/ctl/idt/vendorSupplied/arri/alexa +- Conversations with Joseph Goldstone of ARRI + +### Canon +- http://usa.canon.com/cusa/professional/standard_display/aces +- http://learn.usa.canon.com/app/pdfs/white_papers/White_Paper_Clog_optoelectronic.pdf +- http://www.usa.canon.com/cusa/professional/products/professional_cameras/cinema_eos_cameras/eos_c500#DriversAndSoftware +- http://www.usa.canon.com/cusa/professional/products/professional_cameras/cinema_eos_cameras/eos_c300#DriversAndSoftware + - Choose *OSX Mountain Lion v10.8* to download the IDTs +- http://www.usa.canon.com/cusa/professional/products/professional_cameras/cinema_eos_cameras/eos_c100#DriversAndSoftware + - Choose *OSX Mountain Lion v10.8* to download the IDTs + +### RED +- http://www.red.com/learn/red-101/redlogfilm-redgamma +- Conversations with Graeme Nattress of RED + +### Sony +- https://github.com/ampas/aces-dev/tree/v1.0/transforms/ctl/idt/vendorSupplied/sony + +### ADX +- https://github.com/imageworks/OpenColorIO-Configs/tree/master/aces_0.7.1 +- https://github.com/ampas/aces-dev/tree/v1.0/transforms/ctl/unbuild/universal + +Thanks +------ +The script used to generate these transforms and the transforms themselves were the product of work and conversations with a number of people. Thanks go to: + +- Steve Agland +- Joe Bogacz +- Scott Dyer +- Alex Fry +- Alex Forsythe +- Joseph Goldstone +- Jim Houston +- Thomas Mansencal +- Will McCown +- Graeme Nattress +- Doug Walker + +Dependencies +------------ +The *Python* configuration generation package depends on the following +libraries: + +- **OpenImageIO**: http://openimageio.org +- **OpenColorIO**: http://opencolorio.org/ diff --git a/aces_1.0.0/python/aces_ocio/__init__.py b/aces_1.0.0/python/aces_ocio/__init__.py index 55576c9..7a50220 100644 --- a/aces_1.0.0/python/aces_ocio/__init__.py +++ b/aces_1.0.0/python/aces_ocio/__init__.py @@ -11,19 +11,33 @@ Usage Python ****** ->>> import sys ->>> sys.path.append("/path/to/script") ->>> import create_aces_config as cac ->>> acesReleaseCTLDir = "/path/to/github/checkout/releases/v0.7.1/transforms/ctl" ->>> configDir = "/path/to/config/dir" ->>> cac.createACESConfig(acesReleaseCTLDir, configDir, 1024, 33, True) +>>> from aces_ocio.create_aces_config import create_ACES_config +>>> aces_CTL_directory = '/path/to/github/checkout/releases/v1.0.0/transforms/ctl' +>>> config_directory = '/path/to/configuration/dir' +>>> create_ACES_config(aces_CTL_directory, config_directory, 1024, 33, True) Command Line ************ -From the directory with 'create_aces_config.py': +Using the *create_aces_config* binary: -$ python create_aces_config.py -a "/path/to/github/checkout/releases/v0.7.1/transforms/ctl" -c "/path/to/config/dir" --lut_resolution_1d 1024 --lut_resolution_3d 33 --keepTempImages +$ create_aces_config -a '/path/to/github/checkout/releases/v0.7.1/transforms/ctl' -c '/path/to/config/dir' --lutResolution1d 1024 --lutResolution3d 33 --keepTempImages + +It is possible to set the following environment variables to avoid passing +the paths to the binary: + +- *ACES_OCIO_CTL_DIRECTORY* +- *ACES_OCIO_CONFIGURATION_DIRECTORY* + +The above command line call would be done as follows: + +$ create_aces_config --lutResolution1d 1024 --lutResolution3d 33 --keepTempImages + +Testing the generated configuration is needs the +*ACES_OCIO_CTL_DIRECTORY* environment variable to be set and is done as +follows: + +$ tests_aces_config Build ----- diff --git a/aces_1.0.0/python/aces_ocio/create_aces_config.py b/aces_1.0.0/python/aces_ocio/create_aces_config.py index a18ba48..e83896a 100755 --- a/aces_1.0.0/python/aces_ocio/create_aces_config.py +++ b/aces_1.0.0/python/aces_ocio/create_aces_config.py @@ -13,12 +13,7 @@ import shutil import string import sys -# TODO: This restores the capability of running the script without having -# added the package to PYTHONPATH, this is ugly and should ideally replaced by -# dedicated executable in a /bin directory. -sys.path.append(os.path.join(os.path.dirname(__file__), '..')) - -import PyOpenColorIO as OCIO +import PyOpenColorIO as ocio import aces_ocio.create_arri_colorspaces as arri import aces_ocio.create_canon_colorspaces as canon @@ -29,7 +24,7 @@ from aces_ocio.generate_lut import ( generate_3d_LUT_from_CTL, write_SPI_1d) from aces_ocio.process import Process -from aces_ocio.utilities import ColorSpace, mat44_from_mat33 +from aces_ocio.utilities import ColorSpace, mat44_from_mat33, sanitize_path __author__ = 'ACES Developers' __copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers' @@ -58,15 +53,15 @@ ACES_OCIO_CONFIGURATION_DIRECTORY_ENVIRON = 'ACES_OCIO_CONFIGURATION_DIRECTORY' def set_config_default_roles(config, - color_picking="", - color_timing="", - compositing_log="", - data="", - default="", - matte_paint="", - reference="", - scene_linear="", - texture_paint=""): + color_picking='', + color_timing='', + compositing_log='', + data='', + default='', + matte_paint='', + reference='', + scene_linear='', + texture_paint=''): """ Sets given *OCIO* configuration default roles. @@ -100,23 +95,23 @@ def set_config_default_roles(config, """ if color_picking: - config.setRole(OCIO.Constants.ROLE_COLOR_PICKING, color_picking) + config.setRole(ocio.Constants.ROLE_COLOR_PICKING, color_picking) if color_timing: - config.setRole(OCIO.Constants.ROLE_COLOR_TIMING, color_timing) + config.setRole(ocio.Constants.ROLE_COLOR_TIMING, color_timing) if compositing_log: - config.setRole(OCIO.Constants.ROLE_COMPOSITING_LOG, compositing_log) + config.setRole(ocio.Constants.ROLE_COMPOSITING_LOG, compositing_log) if data: - config.setRole(OCIO.Constants.ROLE_DATA, data) + config.setRole(ocio.Constants.ROLE_DATA, data) if default: - config.setRole(OCIO.Constants.ROLE_DEFAULT, default) + config.setRole(ocio.Constants.ROLE_DEFAULT, default) if matte_paint: - config.setRole(OCIO.Constants.ROLE_MATTE_PAINT, matte_paint) + config.setRole(ocio.Constants.ROLE_MATTE_PAINT, matte_paint) if reference: - config.setRole(OCIO.Constants.ROLE_REFERENCE, reference) + config.setRole(ocio.Constants.ROLE_REFERENCE, reference) if scene_linear: - config.setRole(OCIO.Constants.ROLE_SCENE_LINEAR, scene_linear) + config.setRole(ocio.Constants.ROLE_SCENE_LINEAR, scene_linear) if texture_paint: - config.setRole(OCIO.Constants.ROLE_TEXTURE_PAINT, texture_paint) + config.setRole(ocio.Constants.ROLE_TEXTURE_PAINT, texture_paint) return True @@ -141,13 +136,11 @@ def write_config(config, config_path, sanity_check=True): config.sanityCheck() except Exception, e: print e - print "Configuration was not written due to a failed Sanity Check" + print 'Configuration was not written due to a failed Sanity Check' return - # sys.exit() - file_handle = open(config_path, mode='w') - file_handle.write(config.serialize()) - file_handle.close() + with open(config_path, mode='w') as fp: + fp.write(config.serialize()) def generate_OCIO_transform(transforms): @@ -165,32 +158,30 @@ def generate_OCIO_transform(transforms): Return value description. """ - # print("Generating transforms") - interpolation_options = { - 'linear': OCIO.Constants.INTERP_LINEAR, - 'nearest': OCIO.Constants.INTERP_NEAREST, - 'tetrahedral': OCIO.Constants.INTERP_TETRAHEDRAL + 'linear': ocio.Constants.INTERP_LINEAR, + 'nearest': ocio.Constants.INTERP_NEAREST, + 'tetrahedral': ocio.Constants.INTERP_TETRAHEDRAL } direction_options = { - 'forward': OCIO.Constants.TRANSFORM_DIR_FORWARD, - 'inverse': OCIO.Constants.TRANSFORM_DIR_INVERSE + 'forward': ocio.Constants.TRANSFORM_DIR_FORWARD, + 'inverse': ocio.Constants.TRANSFORM_DIR_INVERSE } ocio_transforms = [] for transform in transforms: if transform['type'] == 'lutFile': - ocio_transform = OCIO.FileTransform( + ocio_transform = ocio.FileTransform( src=transform['path'], interpolation=interpolation_options[ transform['interpolation']], direction=direction_options[transform['direction']]) ocio_transforms.append(ocio_transform) elif transform['type'] == 'matrix': - ocio_transform = OCIO.MatrixTransform() - # MatrixTransform member variables can't be initialized directly. - # Each must be set individually. + ocio_transform = ocio.MatrixTransform() + # MatrixTransform member variables can't be initialized directly + # and must be set individually. ocio_transform.setMatrix(transform['matrix']) if 'offset' in transform: @@ -202,26 +193,23 @@ def generate_OCIO_transform(transforms): ocio_transforms.append(ocio_transform) elif transform['type'] == 'exponent': - ocio_transform = OCIO.ExponentTransform() + ocio_transform = ocio.ExponentTransform() ocio_transform.setValue(transform['value']) ocio_transforms.append(ocio_transform) elif transform['type'] == 'log': - ocio_transform = OCIO.LogTransform( + ocio_transform = ocio.LogTransform( base=transform['base'], direction=direction_options[transform['direction']]) ocio_transforms.append(ocio_transform) else: - print("Ignoring unknown transform type : %s" % transform['type']) + print('Ignoring unknown transform type : %s' % transform['type']) - # Build a group transform if necessary if len(ocio_transforms) > 1: - transform_G = OCIO.GroupTransform() + group_transform = ocio.GroupTransform() for transform in ocio_transforms: - transform_G.push_back(transform) - transform = transform_G - - # Or take the first transform from the list + group_transform.push_back(transform) + transform = group_transform else: transform = ocio_transforms[0] @@ -243,23 +231,18 @@ def create_config(config_data, nuke=False): Return value description. """ - # Create the config - config = OCIO.Config() + # Creating the *OCIO* configuration. + config = ocio.Config() - # - # Set config wide values - # - config.setDescription("An ACES config generated from python") - config.setSearchPath("luts") + # Setting configuration overall values. + config.setDescription('An ACES config generated from python') + config.setSearchPath('luts') - # - # Define the reference color space - # + # Defining the reference colorspace. reference_data = config_data['referenceColorSpace'] - print("Adding the reference color space : %s" % reference_data.name) + print('Adding the reference color space : %s' % reference_data.name) - # Create a color space - reference = OCIO.ColorSpace( + reference = ocio.ColorSpace( name=reference_data.name, bitDepth=reference_data.bit_depth, description=reference_data.description, @@ -269,16 +252,13 @@ def create_config(config_data, nuke=False): allocation=reference_data.allocation_type, allocationVars=reference_data.allocation_vars) - # Add to config config.addColorSpace(reference) - # - # Create the rest of the color spaces - # + # Creating the remaining colorspaces. for colorspace in sorted(config_data['colorSpaces']): - print("Creating new color space : %s" % colorspace.name) + print('Creating new color space : %s' % colorspace.name) - ocio_colorspace = OCIO.ColorSpace( + ocio_colorspace = ocio.ColorSpace( name=colorspace.name, bitDepth=colorspace.bit_depth, description=colorspace.description, @@ -288,33 +268,31 @@ def create_config(config_data, nuke=False): allocation=colorspace.allocation_type, allocationVars=colorspace.allocation_vars) - if colorspace.to_reference_transforms != []: - print("Generating To-Reference transforms") + if colorspace.to_reference_transforms: + print('Generating To-Reference transforms') ocio_transform = generate_OCIO_transform( colorspace.to_reference_transforms) ocio_colorspace.setTransform( ocio_transform, - OCIO.Constants.COLORSPACE_DIR_TO_REFERENCE) + ocio.Constants.COLORSPACE_DIR_TO_REFERENCE) - if colorspace.from_reference_transforms != []: - print("Generating From-Reference transforms") + if colorspace.from_reference_transforms: + print('Generating From-Reference transforms') ocio_transform = generate_OCIO_transform( colorspace.from_reference_transforms) ocio_colorspace.setTransform( ocio_transform, - OCIO.Constants.COLORSPACE_DIR_FROM_REFERENCE) + ocio.Constants.COLORSPACE_DIR_FROM_REFERENCE) config.addColorSpace(ocio_colorspace) - print("") + print('') - # - # Define the views and displays - # + # Defining the *views* and *displays*. displays = [] views = [] - # Generic display and view setup + # Defining a *generic* *display* and *view* setup. if not nuke: for display, view_list in config_data['displays'].iteritems(): for view_name, colorspace in view_list.iteritems(): @@ -322,16 +300,11 @@ def create_config(config_data, nuke=False): if not (view_name in views): views.append(view_name) displays.append(display) - # A Nuke specific set of views and displays - # - # XXX - # A few names: Output Transform, ACES, ACEScc, are hard-coded here. - # Would be better to automate. - # + # Defining the *Nuke* specific set of *views* and *displays*. else: for display, view_list in config_data['displays'].iteritems(): for view_name, colorspace in view_list.iteritems(): - if (view_name == 'Output Transform'): + if view_name == 'Output Transform': view_name = 'View' config.addDisplay(display, view_name, colorspace.name) if not (view_name in views): @@ -343,15 +316,10 @@ def create_config(config_data, nuke=False): config.addDisplay('log', 'View', 'ACEScc') displays.append('log') - # Set active displays and views + # Setting the active *displays* and *views*. config.setActiveDisplays(','.join(sorted(displays))) config.setActiveViews(','.join(views)) - # - # Need to generalize this at some point - # - - # Add Default Roles set_config_default_roles( config, color_picking=reference.getName(), @@ -364,7 +332,6 @@ def create_config(config_data, nuke=False): scene_linear=reference.getName(), texture_paint=reference.getName()) - # Check to make sure we didn't screw something up config.sanityCheck() return config @@ -393,70 +360,62 @@ def generate_LUTs(odt_info, the reference colorspace, *ACES*. """ - print("generateLUTs - begin") + print('generateLUTs - begin') config_data = {} - # - # Define the reference color space - # + # Defining the reference colorspace. ACES = ColorSpace('ACES2065-1') ACES.description = ( 'The Academy Color Encoding System reference color space') ACES.equality_group = '' ACES.family = 'ACES' ACES.is_data = False - ACES.allocation_type = OCIO.Constants.ALLOCATION_LG2 + ACES.allocation_type = ocio.Constants.ALLOCATION_LG2 ACES.allocation_vars = [-15, 6] config_data['referenceColorSpace'] = ACES - # - # Define the displays - # config_data['displays'] = {} - - # - # Define the other color spaces - # config_data['colorSpaces'] = [] - # Matrix converting ACES AP1 primaries to AP0 + # Matrix converting *ACES AP1* primaries to *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 XYZ + # 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] - # - # ACEScc - # + # ------------------------------------------------------------------------- + # *ACEScc* + # ------------------------------------------------------------------------- def create_ACEScc(name='ACEScc', min_value=0.0, max_value=1.0, input_scale=1.0): cs = ColorSpace(name) - cs.description = "The %s color space" % name + cs.description = 'The %s color space' % name cs.equality_group = '' cs.family = 'ACES' cs.is_data = False - ctls = [ - '%s/ACEScc/ACEScsc.ACEScc_to_ACES.a1.0.0.ctl' % aces_CTL_directory, - # 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 - '%s/ACEScg/ACEScsc.ACES_to_ACEScg.a1.0.0.ctl' % aces_CTL_directory - ] - lut = "%s_to_ACES.spi1d" % name + 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 - # Remove spaces and parentheses - lut = lut.replace(' ', '_').replace(')', '_').replace('(', '_') + lut = sanitize_path(lut) generate_1d_LUT_from_CTL( - lut_directory + "/" + lut, + os.path.join(lut_directory, lut), ctls, lut_resolution_1d, 'float', @@ -473,15 +432,13 @@ def generate_LUTs(odt_info, 'type': 'lutFile', 'path': lut, 'interpolation': 'linear', - 'direction': 'forward' - }) + 'direction': 'forward'}) - # AP1 primaries to AP0 primaries + # *AP1* primaries to *AP0* primaries. cs.to_reference_transforms.append({ 'type': 'matrix', 'matrix': mat44_from_mat33(ACES_AP1_to_AP0), - 'direction': 'forward' - }) + 'direction': 'forward'}) cs.from_reference_transforms = [] return cs @@ -489,31 +446,31 @@ def generate_LUTs(odt_info, ACEScc = create_ACEScc() config_data['colorSpaces'].append(ACEScc) - # - # ACESproxy - # + # ------------------------------------------------------------------------- + # *ACESproxy* + # ------------------------------------------------------------------------- def create_ACESproxy(name='ACESproxy'): cs = ColorSpace(name) - cs.description = "The %s color space" % name + cs.description = 'The %s color space' % name cs.equality_group = '' cs.family = 'ACES' cs.is_data = False - ctls = [ - '%s/ACESproxy/ACEScsc.ACESproxy10i_to_ACES.a1.0.0.ctl' % ( - aces_CTL_directory), - # 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 - '%s/ACEScg/ACEScsc.ACES_to_ACEScg.a1.0.0.ctl' % aces_CTL_directory - ] - lut = "%s_to_aces.spi1d" % name + 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 - # Remove spaces and parentheses - lut = lut.replace(' ', '_').replace(')', '_').replace('(', '_') + lut = sanitize_path(lut) generate_1d_LUT_from_CTL( - lut_directory + "/" + lut, + os.path.join(lut_directory, lut), ctls, lut_resolution_1d, 'uint16', @@ -531,7 +488,7 @@ def generate_LUTs(odt_info, 'direction': 'forward' }) - # AP1 primaries to AP0 primaries + # *AP1* primaries to *AP0* primaries. cs.to_reference_transforms.append({ 'type': 'matrix', 'matrix': mat44_from_mat33(ACES_AP1_to_AP0), @@ -544,19 +501,19 @@ def generate_LUTs(odt_info, ACESproxy = create_ACESproxy() config_data['colorSpaces'].append(ACESproxy) - # - # ACEScg - # + # ------------------------------------------------------------------------- + # *ACEScg* + # ------------------------------------------------------------------------- def create_ACEScg(name='ACEScg'): cs = ColorSpace(name) - cs.description = "The %s color space" % name + cs.description = 'The %s color space' % name cs.equality_group = '' cs.family = 'ACES' cs.is_data = False cs.to_reference_transforms = [] - # AP1 primaries to AP0 primaries + # *AP1* primaries to *AP0* primaries. cs.to_reference_transforms.append({ 'type': 'matrix', 'matrix': mat44_from_mat33(ACES_AP1_to_AP0), @@ -569,26 +526,26 @@ def generate_LUTs(odt_info, ACEScg = create_ACEScg() config_data['colorSpaces'].append(ACEScg) - # - # ADX - # + # ------------------------------------------------------------------------- + # *ADX* + # ------------------------------------------------------------------------- def create_ADX(bit_depth=10, name='ADX'): - name = "%s%s" % (name, bit_depth) + name = '%s%s' % (name, bit_depth) cs = ColorSpace(name) - cs.description = "%s color space - used for film scans" % name + cs.description = '%s color space - used for film scans' % name cs.equality_group = '' cs.family = 'ADX' cs.is_data = False if bit_depth == 10: - cs.bit_depth = bit_depth = OCIO.Constants.BIT_DEPTH_UINT10 + 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] elif bit_depth == 16: - cs.bit_depth = bit_depth = OCIO.Constants.BIT_DEPTH_UINT16 + 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, @@ -598,13 +555,12 @@ def generate_LUTs(odt_info, cs.to_reference_transforms = [] - # Convert from ADX to Channel-Dependent Density + # Converting from *ADX* to *Channel-Dependent Density*. cs.to_reference_transforms.append({ 'type': 'matrix', 'matrix': adx_to_cdd, 'offset': offset, - 'direction': 'forward' - }) + 'direction': 'forward'}) # Convert from Channel-Dependent Density to Channel-Independent Density cs.to_reference_transforms.append({ @@ -613,11 +569,11 @@ def generate_LUTs(odt_info, 0.05901, 0.96928, -0.02829, 0, 0.16134, 0.07406, 0.76460, 0, 0.0, 0.0, 0.0, 1.0], - 'direction': 'forward' - }) + 'direction': 'forward'}) - # Copied from Alex Fry's adx_cid_to_rle.py + # Copied from *Alex Fry*'s *adx_cid_to_rle.py* def create_CID_to_RLE_LUT(): + def interpolate_1D(x, xp, fp): return numpy.interp(x, xp, fp) @@ -655,7 +611,7 @@ def generate_LUTs(odt_info, def fit(value, from_min, from_max, to_min, to_max): if from_min == from_max: - raise ValueError("from_min == from_max") + raise ValueError('from_min == from_max') return (value - from_min) / (from_max - from_min) * ( to_max - to_min) + to_min @@ -668,38 +624,38 @@ def generate_LUTs(odt_info, data.append(cid_to_rle(x)) lut = 'ADX_CID_to_RLE.spi1d' - write_SPI_1d(lut_directory + "/" + lut, RANGE[0], RANGE[1], + write_SPI_1d(os.path.join(lut_directory, lut), + RANGE[0], + RANGE[1], data, NUM_SAMPLES, 1) return lut - # Convert Channel Independent Density values to Relative Log Exposure - # values. + # Converting *Channel Independent Density* values to + # *Relative Log Exposure* values. lut = create_CID_to_RLE_LUT() cs.to_reference_transforms.append({ 'type': 'lutFile', 'path': lut, 'interpolation': 'linear', - 'direction': 'forward' - }) + 'direction': 'forward'}) - # Convert Relative Log Exposure values to Relative Exposure values + # Converting *Relative Log Exposure* values to + # *Relative Exposure* values. cs.to_reference_transforms.append({ 'type': 'log', 'base': 10, - 'direction': 'inverse' - }) + 'direction': 'inverse'}) - # Convert Relative Exposure values to ACES values + # Convert *Relative Exposure* values to *ACES* values. cs.to_reference_transforms.append({ 'type': 'matrix', '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], - 'direction': 'forward' - }) + 'direction': 'forward'}) cs.from_reference_transforms = [] return cs @@ -710,36 +666,36 @@ def generate_LUTs(odt_info, ADX16 = create_ADX(bit_depth=16) config_data['colorSpaces'].append(ADX16) - # - # Camera Input Transforms - # + # ------------------------------------------------------------------------- + # *Camera Input Transforms* + # ------------------------------------------------------------------------- - # RED color spaces to ACES + # *RED* colorspaces to *ACES*. red_colorspaces = red.create_colorspaces(lut_directory, lut_resolution_1d) for cs in red_colorspaces: config_data['colorSpaces'].append(cs) - # Canon-Log to ACES + # *Canon-Log* to *ACES*. canon_colorspaces = canon.create_colorspaces(lut_directory, lut_resolution_1d) for cs in canon_colorspaces: config_data['colorSpaces'].append(cs) - # S-Log to ACES + # *S-Log* to *ACES*. sony_colorSpaces = sony.create_colorspaces(lut_directory, lut_resolution_1d) for cs in sony_colorSpaces: config_data['colorSpaces'].append(cs) - # Log-C to ACES + # *Log-C* to *ACES*. arri_colorSpaces = arri.create_colorspaces(lut_directory, lut_resolution_1d) for cs in arri_colorSpaces: config_data['colorSpaces'].append(cs) - # - # Generic log transform - # + # ------------------------------------------------------------------------- + # *Generic Log Transform* + # ------------------------------------------------------------------------- def create_generic_log(name='log', min_value=0.0, max_value=1.0, @@ -749,31 +705,29 @@ def generate_LUTs(odt_info, max_exposure=6.5, lut_resolution_1d=lut_resolution_1d): cs = ColorSpace(name) - cs.description = "The %s color space" % name + cs.description = 'The %s color space' % name cs.equality_group = name cs.family = 'Utility' cs.is_data = False - ctls = [ - '%s/utilities/ACESlib.OCIO_shaper_log2_to_lin_param.a1.0.0.ctl' % ( - aces_CTL_directory)] - lut = "%s_to_aces.spi1d" % name + ctls = [os.path.join( + aces_CTL_directory, + 'utilities', + 'ACESlib.OCIO_shaper_log2_to_lin_param.a1.0.0.ctl')] + lut = '%s_to_aces.spi1d' % name - # Remove spaces and parentheses - lut = lut.replace(' ', '_').replace(')', '_').replace('(', '_') + lut = sanitize_path(lut) generate_1d_LUT_from_CTL( - lut_directory + "/" + lut, + os.path.join(lut_directory, lut), ctls, lut_resolution_1d, 'float', input_scale, 1.0, - { - 'middleGrey': middle_grey, - 'minExposure': min_exposure, - 'maxExposure': max_exposure - }, + {'middleGrey': middle_grey, + 'minExposure': min_exposure, + 'maxExposure': max_exposure}, cleanup, aces_CTL_directory, min_value, @@ -784,48 +738,43 @@ def generate_LUTs(odt_info, 'type': 'lutFile', 'path': lut, 'interpolation': 'linear', - 'direction': 'forward' - }) + 'direction': 'forward'}) cs.from_reference_transforms = [] return cs - # - # ACES LMTs - # + # ------------------------------------------------------------------------- + # *ACES LMTs* + # ------------------------------------------------------------------------- def create_ACES_LMT(lmt_name, lmt_values, shaper_info, lut_resolution_1d=1024, lut_resolution_3d=64, cleanup=True): - cs = ColorSpace("%s" % lmt_name) - cs.description = "The ACES Look Transform: %s" % lmt_name + cs = ColorSpace('%s' % lmt_name) + cs.description = 'The ACES Look Transform: %s' % lmt_name cs.equality_group = '' cs.family = 'Look' cs.is_data = False pprint.pprint(lmt_values) - # - # Generate the shaper transform - # + # Generating the *shaper* transform. (shaper_name, shaper_to_ACES_CTL, shaper_from_ACES_CTL, shaper_input_scale, shaper_params) = shaper_info - shaper_lut = "%s_to_aces.spi1d" % shaper_name - if (not os.path.exists(lut_directory + "/" + shaper_lut)): + shaper_lut = '%s_to_aces.spi1d' % shaper_name + if not os.path.exists(os.path.join(lut_directory, shaper_lut)): ctls = [shaper_to_ACES_CTL % aces_CTL_directory] - # Remove spaces and parentheses - shaper_lut = shaper_lut.replace( - ' ', '_').replace(')', '_').replace('(', '_') + shaper_lut = sanitize_path(shaper_lut) generate_1d_LUT_from_CTL( - lut_directory + "/" + shaper_lut, + os.path.join(lut_directory, shaper_lut), ctls, lut_resolution_1d, 'float', @@ -839,26 +788,21 @@ def generate_LUTs(odt_info, 'type': 'lutFile', 'path': shaper_lut, 'interpolation': 'linear', - 'direction': 'inverse' - } + 'direction': 'inverse'} - # - # Generate the forward transform - # + # Generating the forward transform. cs.from_reference_transforms = [] if 'transformCTL' in lmt_values: - ctls = [ - shaper_to_ACES_CTL % aces_CTL_directory, - '%s/%s' % (aces_CTL_directory, lmt_values['transformCTL']) - ] - lut = "%s.%s.spi3d" % (shaper_name, lmt_name) + ctls = [shaper_to_ACES_CTL % aces_CTL_directory, + os.path.join(aces_CTL_directory, + lmt_values['transformCTL'])] + lut = '%s.%s.spi3d' % (shaper_name, lmt_name) - # Remove spaces and parentheses - lut = lut.replace(' ', '_').replace(')', '_').replace('(', '_') + lut = sanitize_path(lut) generate_3d_LUT_from_CTL( - lut_directory + "/" + lut, + os.path.join(lut_directory, lut), ctls, lut_resolution_3d, 'float', @@ -876,24 +820,19 @@ def generate_LUTs(odt_info, 'direction': 'forward' }) - # - # Generate the inverse transform - # + # Generating the inverse transform. cs.to_reference_transforms = [] if 'transformCTLInverse' in lmt_values: - ctls = [ - '%s/%s' % ( - aces_CTL_directory, odt_values['transformCTLInverse']), - shaper_from_ACES_CTL % aces_CTL_directory - ] - lut = "Inverse.%s.%s.spi3d" % (odt_name, shaper_name) + ctls = [os.path.join(aces_CTL_directory, + odt_values['transformCTLInverse']), + shaper_from_ACES_CTL % aces_CTL_directory] + lut = 'Inverse.%s.%s.spi3d' % (odt_name, shaper_name) - # Remove spaces and parentheses - lut = lut.replace(' ', '_').replace(')', '_').replace('(', '_') + lut = sanitize_path(lut) generate_3d_LUT_from_CTL( - lut_directory + "/" + lut, + os.path.join(lut_directory, lut), ctls, lut_resolution_3d, 'half', @@ -907,8 +846,7 @@ def generate_LUTs(odt_info, 'type': 'lutFile', 'path': lut, 'interpolation': 'tetrahedral', - 'direction': 'forward' - }) + 'direction': 'forward'}) shaper_inverse = shaper_OCIO_transform.copy() shaper_inverse['direction'] = 'forward' @@ -916,20 +854,20 @@ def generate_LUTs(odt_info, return cs - # - # LMT Shaper - # + # ------------------------------------------------------------------------- + # *LMT Shaper* + # ------------------------------------------------------------------------- lmt_lut_resolution_1d = max(4096, lut_resolution_1d) lmt_lut_resolution_3d = max(65, lut_resolution_3d) - # Log 2 shaper + # Defining the *Log 2* shaper. lmt_shaper_name = 'LMT Shaper' lmt_params = { 'middleGrey': 0.18, 'minExposure': -10.0, - 'maxExposure': 6.5 - } + 'maxExposure': 6.5} + lmt_shaper = create_generic_log(name=lmt_shaper_name, middle_grey=lmt_params['middleGrey'], min_exposure=lmt_params['minExposure'], @@ -939,14 +877,17 @@ def generate_LUTs(odt_info, shaper_input_scale_generic_log2 = 1.0 - # Log 2 shaper name and CTL transforms bundled up + # *Log 2* shaper name and *CTL* transforms bundled up. lmt_shaper_data = [ lmt_shaper_name, - '%s/utilities/ACESlib.OCIO_shaper_log2_to_lin_param.a1.0.0.ctl', - '%s/utilities/ACESlib.OCIO_shaper_lin_to_log2_param.a1.0.0.ctl', + os.path.join('%s', + 'utilities', + 'ACESlib.OCIO_shaper_log2_to_lin_param.a1.0.0.ctl'), + os.path.join('%s', + 'utilities', + 'ACESlib.OCIO_shaper_lin_to_log2_param.a1.0.0.ctl'), shaper_input_scale_generic_log2, - lmt_params - ] + lmt_params] sorted_LMTs = sorted(lmt_info.iteritems(), key=lambda x: x[1]) print(sorted_LMTs) @@ -961,17 +902,17 @@ def generate_LUTs(odt_info, cleanup) config_data['colorSpaces'].append(cs) - # - # ACES RRT with the supplied ODT - # + # ------------------------------------------------------------------------- + # *ACES RRT* with supplied *ODT*. + # ------------------------------------------------------------------------- def create_ACES_RRT_plus_ODT(odt_name, odt_values, shaper_info, lut_resolution_1d=1024, lut_resolution_3d=64, cleanup=True): - cs = ColorSpace("%s" % odt_name) - cs.description = "%s - %s Output Transform" % ( + cs = ColorSpace('%s' % odt_name) + cs.description = '%s - %s Output Transform' % ( odt_values['transformUserNamePrefix'], odt_name) cs.equality_group = '' cs.family = 'Output' @@ -979,10 +920,7 @@ def generate_LUTs(odt_info, pprint.pprint(odt_values) - # - # Generate the shaper transform - # - # if 'shaperCTL' in odtValues: + # Generating the *shaper* transform. (shaper_name, shaper_to_ACES_CTL, shaper_from_ACES_CTL, @@ -994,16 +932,14 @@ def generate_LUTs(odt_info, else: shaper_params['legalRange'] = 0 - shaper_lut = "%s_to_aces.spi1d" % shaper_name - if (not os.path.exists(lut_directory + "/" + shaper_lut)): + shaper_lut = '%s_to_aces.spi1d' % shaper_name + if not os.path.exists(os.path.join(lut_directory, shaper_lut)): ctls = [shaper_to_ACES_CTL % aces_CTL_directory] - # Remove spaces and parentheses - shaper_lut = shaper_lut.replace( - ' ', '_').replace(')', '_').replace('(', '_') + shaper_lut = sanitize_path(shaper_lut) generate_1d_LUT_from_CTL( - lut_directory + "/" + shaper_lut, + os.path.join(lut_directory, shaper_lut), ctls, lut_resolution_1d, 'float', @@ -1017,19 +953,15 @@ def generate_LUTs(odt_info, 'type': 'lutFile', 'path': shaper_lut, 'interpolation': 'linear', - 'direction': 'inverse' - } + 'direction': 'inverse'} - # - # Generate the forward transform - # + # Generating the *forward* transform. cs.from_reference_transforms = [] if 'transformLUT' in odt_values: - # Copy into the lut dir transform_LUT_file_name = os.path.basename( odt_values['transformLUT']) - lut = lut_directory + "/" + transform_LUT_file_name + lut = os.path.join(lut_directory, transform_LUT_file_name) shutil.copy(odt_values['transformLUT'], lut) cs.from_reference_transforms.append(shaper_OCIO_transform) @@ -1037,76 +969,71 @@ def generate_LUTs(odt_info, 'type': 'lutFile', 'path': transform_LUT_file_name, 'interpolation': 'tetrahedral', - 'direction': 'forward' - }) + 'direction': 'forward'}) elif 'transformCTL' in odt_values: - # shaperLut - ctls = [ shaper_to_ACES_CTL % aces_CTL_directory, - '%s/rrt/RRT.a1.0.0.ctl' % aces_CTL_directory, - '%s/odt/%s' % (aces_CTL_directory, odt_values['transformCTL']) - ] - lut = "%s.RRT.a1.0.0.%s.spi3d" % (shaper_name, odt_name) - - # Remove spaces and parentheses - lut = lut.replace(' ', '_').replace(')', '_').replace('(', '_') - - generate_3d_LUT_from_CTL(lut_directory + "/" + lut, - # shaperLUT, - ctls, - lut_resolution_3d, - 'float', - 1.0 / shaper_input_scale, - 1.0, - shaper_params, - cleanup, - aces_CTL_directory) + os.path.join(aces_CTL_directory, + 'rrt', + 'RRT.a1.0.0.ctl'), + os.path.join(aces_CTL_directory, + 'odt', + odt_values['transformCTL'])] + lut = '%s.RRT.a1.0.0.%s.spi3d' % (shaper_name, odt_name) + + lut = sanitize_path(lut) + + generate_3d_LUT_from_CTL( + os.path.join(lut_directory, lut), + # shaperLUT, + ctls, + lut_resolution_3d, + 'float', + 1.0 / shaper_input_scale, + 1.0, + shaper_params, + cleanup, + aces_CTL_directory) cs.from_reference_transforms.append(shaper_OCIO_transform) cs.from_reference_transforms.append({ 'type': 'lutFile', 'path': lut, 'interpolation': 'tetrahedral', - 'direction': 'forward' - }) + 'direction': 'forward'}) - # - # Generate the inverse transform - # + # Generating the *inverse* transform. cs.to_reference_transforms = [] if 'transformLUTInverse' in odt_values: - # Copy into the lut dir transform_LUT_inverse_file_name = os.path.basename( odt_values['transformLUTInverse']) - lut = lut_directory + "/" + transform_LUT_inverse_file_name + lut = os.path.join(lut_directory, transform_LUT_inverse_file_name) shutil.copy(odt_values['transformLUTInverse'], lut) cs.to_reference_transforms.append({ 'type': 'lutFile', 'path': transform_LUT_inverse_file_name, 'interpolation': 'tetrahedral', - 'direction': 'forward' - }) + 'direction': 'forward'}) shaper_inverse = shaper_OCIO_transform.copy() shaper_inverse['direction'] = 'forward' cs.to_reference_transforms.append(shaper_inverse) elif 'transformCTLInverse' in odt_values: - ctls = [ - '%s/odt/%s' % ( - aces_CTL_directory, odt_values['transformCTLInverse']), - '%s/rrt/InvRRT.a1.0.0.ctl' % aces_CTL_directory, - shaper_from_ACES_CTL % aces_CTL_directory - ] - lut = "InvRRT.a1.0.0.%s.%s.spi3d" % (odt_name, shaper_name) + ctls = [os.path.join(aces_CTL_directory, + 'odt', + odt_values['transformCTLInverse']), + os.path.join(aces_CTL_directory, + 'rrt', + 'InvRRT.a1.0.0.ctl'), + shaper_from_ACES_CTL % aces_CTL_directory] + lut = 'InvRRT.a1.0.0.%s.%s.spi3d' % (odt_name, shaper_name) - # Remove spaces and parentheses - lut = lut.replace(' ', '_').replace(')', '_').replace('(', '_') + lut = sanitize_path(lut) generate_3d_LUT_from_CTL( - lut_directory + "/" + lut, + os.path.join(lut_directory, lut), # None, ctls, lut_resolution_3d, @@ -1121,8 +1048,7 @@ def generate_LUTs(odt_info, 'type': 'lutFile', 'path': lut, 'interpolation': 'tetrahedral', - 'direction': 'forward' - }) + 'direction': 'forward'}) shaper_inverse = shaper_OCIO_transform.copy() shaper_inverse['direction'] = 'forward' @@ -1130,18 +1056,18 @@ def generate_LUTs(odt_info, return cs - # - # RRT/ODT shaper options - # + # ------------------------------------------------------------------------- + # *RRT / ODT* Shaper Options + # ------------------------------------------------------------------------- shaper_data = {} - # Log 2 shaper + # Defining the *Log 2* shaper. log2_shaper_name = shaper_name log2_params = { 'middleGrey': 0.18, 'minExposure': -6.0, - 'maxExposure': 6.5 - } + 'maxExposure': 6.5} + log2_shaper = create_generic_log( name=log2_shaper_name, middle_grey=log2_params['middleGrey'], @@ -1151,28 +1077,30 @@ def generate_LUTs(odt_info, shaper_input_scale_generic_log2 = 1.0 - # Log 2 shaper name and CTL transforms bundled up + # *Log 2* shaper name and *CTL* transforms bundled up. log2_shaper_data = [ log2_shaper_name, - '%s/utilities/ACESlib.OCIO_shaper_log2_to_lin_param.a1.0.0.ctl', - '%s/utilities/ACESlib.OCIO_shaper_lin_to_log2_param.a1.0.0.ctl', + os.path.join('%s', + 'utilities', + 'ACESlib.OCIO_shaper_log2_to_lin_param.a1.0.0.ctl'), + os.path.join('%s', + 'utilities', + 'ACESlib.OCIO_shaper_lin_to_log2_param.a1.0.0.ctl'), shaper_input_scale_generic_log2, - log2_params - ] + log2_params] shaper_data[log2_shaper_name] = log2_shaper_data - # - # Shaper that also includes the AP1 primaries - # - Needed for some LUT baking steps - # + # Shaper that also includes the AP1 primaries. + # Needed for some LUT baking steps. log2_shaper_AP1 = create_generic_log( name=log2_shaper_name, middle_grey=log2_params['middleGrey'], min_exposure=log2_params['minExposure'], max_exposure=log2_params['maxExposure']) - log2_shaper_AP1.name = "%s - AP1" % log2_shaper_AP1.name - # AP1 primaries to AP0 primaries + log2_shaper_AP1.name = '%s - AP1' % log2_shaper_AP1.name + + # *AP1* primaries to *AP0* primaries. log2_shaper_AP1.to_reference_transforms.append({ 'type': 'matrix', 'matrix': mat44_from_mat33(ACES_AP1_to_AP0), @@ -1180,21 +1108,15 @@ def generate_LUTs(odt_info, }) config_data['colorSpaces'].append(log2_shaper_AP1) - # - # Choose your shaper - # - rrt_shaper_name = log2_shaper_name rrt_shaper = log2_shaper_data - # - # RRT + ODT Combinations - # + # *RRT + ODT* combinations. sorted_odts = sorted(odt_info.iteritems(), key=lambda x: x[1]) print(sorted_odts) for odt in sorted_odts: (odt_name, odt_values) = odt - # Have to handle ODTs that can generate either legal or full output + # Handling *ODTs* that can generate either *legal* or *full* output. if odt_name in ['Academy.Rec2020_100nits_dim.a1.0.0', 'Academy.Rec709_100nits_dim.a1.0.0', 'Academy.Rec709_D60sim_100nits_dim.a1.0.0']: @@ -1214,7 +1136,6 @@ def generate_LUTs(odt_info, cleanup) config_data['colorSpaces'].append(cs) - # Create a display entry using this color space config_data['displays'][odt_name_legal] = { 'Linear': ACES, 'Log': ACEScc, @@ -1223,9 +1144,9 @@ def generate_LUTs(odt_info, if odt_name in ['Academy.Rec2020_100nits_dim.a1.0.0', 'Academy.Rec709_100nits_dim.a1.0.0', 'Academy.Rec709_D60sim_100nits_dim.a1.0.0']: - print("Generating full range ODT for %s" % odt_name) + print('Generating full range ODT for %s' % odt_name) - odt_name_full = "%s - Full" % odt_values['transformUserName'] + odt_name_full = '%s - Full' % odt_values['transformUserName'] odt_full = odt_values.copy() odt_full['legalRange'] = 0 @@ -1238,41 +1159,44 @@ def generate_LUTs(odt_info, cleanup) config_data['colorSpaces'].append(cs_full) - # Create a display entry using this color space config_data['displays'][odt_name_full] = { 'Linear': ACES, 'Log': ACEScc, 'Output Transform': cs_full} - # + # ------------------------------------------------------------------------- # Generic Matrix transform - # + # ------------------------------------------------------------------------- def create_generic_matrix(name='matrix', - from_reference_values=[], - to_reference_values=[]): + from_reference_values=None, + to_reference_values=None): + + if from_reference_values is None: + from_reference_values = [] + if to_reference_values is None: + to_reference_values = [] + cs = ColorSpace(name) - cs.description = "The %s color space" % name + cs.description = 'The %s color space' % name cs.equality_group = name cs.family = 'Utility' cs.is_data = False cs.to_reference_transforms = [] - if to_reference_values != []: + if to_reference_values: for matrix in to_reference_values: cs.to_reference_transforms.append({ 'type': 'matrix', 'matrix': mat44_from_mat33(matrix), - 'direction': 'forward' - }) + 'direction': 'forward'}) cs.from_reference_transforms = [] - if from_reference_values != []: + if from_reference_values: for matrix in from_reference_values: cs.from_reference_transforms.append({ 'type': 'matrix', 'matrix': mat44_from_mat33(matrix), - 'direction': 'forward' - }) + 'direction': 'forward'}) return cs @@ -1283,7 +1207,7 @@ def generate_LUTs(odt_info, 'Linear - AP1', to_reference_values=[ACES_AP1_to_AP0]) config_data['colorSpaces'].append(cs) - # ACES to Linear, P3D60 primaries + # *ACES* to *Linear*, *P3D60* primaries. XYZ_to_P3D60 = [2.4027414142, -0.8974841639, -0.3880533700, -0.8325796487, 1.7692317536, 0.0237127115, 0.0388233815, -0.0824996856, 1.0363685997] @@ -1293,7 +1217,7 @@ def generate_LUTs(odt_info, from_reference_values=[ACES_AP0_to_XYZ, XYZ_to_P3D60]) config_data['colorSpaces'].append(cs) - # ACES to Linear, P3D60 primaries + # *ACES* to *Linear*, *P3DCI* primaries. XYZ_to_P3DCI = [2.7253940305, -1.0180030062, -0.4401631952, -0.7951680258, 1.6897320548, 0.0226471906, 0.0412418914, -0.0876390192, 1.1009293786] @@ -1303,7 +1227,7 @@ def generate_LUTs(odt_info, from_reference_values=[ACES_AP0_to_XYZ, XYZ_to_P3DCI]) config_data['colorSpaces'].append(cs) - # ACES to Linear, Rec 709 primaries + # *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] @@ -1313,7 +1237,7 @@ def generate_LUTs(odt_info, from_reference_values=[ACES_AP0_to_XYZ, XYZ_to_Rec709]) config_data['colorSpaces'].append(cs) - # ACES to Linear, Rec 2020 primaries + # *ACES* to *Linear*, *Rec. 2020* primaries. XYZ_to_Rec2020 = [1.7166511880, -0.3556707838, -0.2533662814, -0.6666843518, 1.6164812366, 0.0157685458, 0.0176398574, -0.0427706133, 0.9421031212] @@ -1323,7 +1247,7 @@ def generate_LUTs(odt_info, from_reference_values=[ACES_AP0_to_XYZ, XYZ_to_Rec2020]) config_data['colorSpaces'].append(cs) - print("generateLUTs - end") + print('generateLUTs - end') return config_data @@ -1348,109 +1272,123 @@ def generate_baked_LUTs(odt_info, Return value description. """ - # Add the legal and full variations into this list odt_info_C = dict(odt_info) for odt_CTL_name, odt_values in odt_info.iteritems(): if odt_CTL_name in ['Academy.Rec2020_100nits_dim.a1.0.0', 'Academy.Rec709_100nits_dim.a1.0.0', 'Academy.Rec709_D60sim_100nits_dim.a1.0.0']: - odt_name = odt_values["transformUserName"] + 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_values_legal['transformUserName'] = '%s - Legal' % odt_name + 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_values_full['transformUserName'] = '%s - Full' % odt_name + odt_info_C['%s - Full' % odt_CTL_name] = odt_values_full del (odt_info_C[odt_CTL_name]) for odt_CTL_name, odt_values in odt_info_C.iteritems(): - odt_prefix = odt_values["transformUserNamePrefix"] - odt_name = odt_values["transformUserName"] - - # For Photoshop - for input_space in ["ACEScc", "ACESproxy"]: - args = ["--iconfig", config_path, - "-v", - "--inputspace", input_space] - args += ["--outputspace", "%s" % odt_name] - args += ["--description", - "%s - %s for %s data" % (odt_prefix, + odt_prefix = odt_values['transformUserNamePrefix'] + odt_name = odt_values['transformUserName'] + + # *Photoshop* + for input_space in ['ACEScc', 'ACESproxy']: + args = ['--iconfig', config_path, + '-v', + '--inputspace', input_space] + args += ['--outputspace', '%s' % odt_name] + args += ['--description', + '%s - %s for %s data' % (odt_prefix, odt_name, input_space)] - args += ["--shaperspace", shaper_name, - "--shapersize", str(lut_resolution_shaper)] - args += ["--cubesize", str(lut_resolution_3d)] - args += ["--format", - "icc", - "%s/photoshop/%s for %s.icc" % (baked_directory, - odt_name, - input_space)] - - bake_LUT = Process(description="bake a LUT", - cmd="ociobakelut", + args += ['--shaperspace', shaper_name, + '--shapersize', str(lut_resolution_shaper)] + args += ['--cubesize', str(lut_resolution_3d)] + args += ['--format', + 'icc', + os.path.join(baked_directory, + 'photoshop', + '%s for %s.icc' % (odt_name, input_space))] + + bake_LUT = Process(description='bake a LUT', + cmd='ociobakelut', args=args) bake_LUT.execute() - # For Flame, Lustre - for input_space in ["ACEScc", "ACESproxy"]: - args = ["--iconfig", config_path, - "-v", - "--inputspace", input_space] - args += ["--outputspace", "%s" % odt_name] - args += ["--description", - "%s - %s for %s data" % ( + # *Flame*, *Lustre* + for input_space in ['ACEScc', 'ACESproxy']: + args = ['--iconfig', config_path, + '-v', + '--inputspace', input_space] + args += ['--outputspace', '%s' % odt_name] + args += ['--description', + '%s - %s for %s data' % ( odt_prefix, odt_name, input_space)] - args += ["--shaperspace", shaper_name, - "--shapersize", str(lut_resolution_shaper)] - args += ["--cubesize", str(lut_resolution_3d)] - - fargs = ["--format", "flame", "%s/flame/%s for %s Flame.3dl" % ( - baked_directory, odt_name, input_space)] - bake_LUT = Process(description="bake a LUT", - cmd="ociobakelut", + args += ['--shaperspace', shaper_name, + '--shapersize', str(lut_resolution_shaper)] + args += ['--cubesize', str(lut_resolution_3d)] + + fargs = ['--format', + 'flame', + os.path.join( + baked_directory, + 'flame', + '%s for %s Flame.3dl' % (odt_name, input_space))] + bake_LUT = Process(description='bake a LUT', + cmd='ociobakelut', args=(args + fargs)) bake_LUT.execute() - largs = ["--format", "lustre", "%s/lustre/%s for %s Lustre.3dl" % ( - baked_directory, odt_name, input_space)] - bake_LUT = Process(description="bake a LUT", - cmd="ociobakelut", + largs = ['--format', + 'lustre', + os.path.join( + baked_directory, + 'lustre', + '%s for %s Lustre.3dl' % (odt_name, input_space))] + bake_LUT = Process(description='bake a LUT', + cmd='ociobakelut', args=(args + largs)) bake_LUT.execute() - # For Maya, Houdini - for input_space in ["ACEScg", "ACES2065-1"]: - args = ["--iconfig", config_path, - "-v", - "--inputspace", input_space] - args += ["--outputspace", "%s" % odt_name] - args += ["--description", - "%s - %s for %s data" % ( + # *Maya*, *Houdini* + for input_space in ['ACEScg', 'ACES2065-1']: + args = ['--iconfig', config_path, + '-v', + '--inputspace', input_space] + args += ['--outputspace', '%s' % odt_name] + args += ['--description', + '%s - %s for %s data' % ( odt_prefix, odt_name, input_space)] if input_space == 'ACEScg': - lin_shaper_name = "%s - AP1" % shaper_name + lin_shaper_name = '%s - AP1' % shaper_name else: lin_shaper_name = shaper_name - args += ["--shaperspace", lin_shaper_name, - "--shapersize", str(lut_resolution_shaper)] - - args += ["--cubesize", str(lut_resolution_3d)] - - margs = ["--format", "cinespace", "%s/maya/%s for %s Maya.csp" % ( - baked_directory, odt_name, input_space)] - bake_LUT = Process(description="bake a LUT", - cmd="ociobakelut", + args += ['--shaperspace', lin_shaper_name, + '--shapersize', str(lut_resolution_shaper)] + + args += ['--cubesize', str(lut_resolution_3d)] + + margs = ['--format', + 'cinespace', + os.path.join( + baked_directory, + 'maya', + '%s for %s Maya.csp' % (odt_name, input_space))] + bake_LUT = Process(description='bake a LUT', + cmd='ociobakelut', args=(args + margs)) bake_LUT.execute() - hargs = ["--format", "houdini", - "%s/houdini/%s for %s Houdini.lut" % ( - baked_directory, odt_name, input_space)] - bake_LUT = Process(description="bake a LUT", - cmd="ociobakelut", + hargs = ['--format', + 'houdini', + os.path.join( + baked_directory, + 'houdini', + '%s for %s Houdini.lut' % (odt_name, input_space))] + bake_LUT = Process(description='bake a LUT', + cmd='ociobakelut', args=(args + hargs)) bake_LUT.execute() @@ -1470,14 +1408,14 @@ def create_config_dir(config_directory, bake_secondary_LUTs): Return value description. """ - dirs = [config_directory, "%s/luts" % config_directory] + dirs = [config_directory, os.path.join(config_directory, 'luts')] if bake_secondary_LUTs: - dirs.extend(["%s/baked" % config_directory, - "%s/baked/flame" % config_directory, - "%s/baked/photoshop" % config_directory, - "%s/baked/houdini" % config_directory, - "%s/baked/lustre" % config_directory, - "%s/baked/maya" % config_directory]) + dirs.extend([os.path.join(config_directory, 'baked'), + os.path.join(config_directory, 'baked', 'flame'), + os.path.join(config_directory, 'baked', 'photoshop'), + os.path.join(config_directory, 'baked', 'houdini'), + os.path.join(config_directory, 'baked', 'lustre'), + os.path.join(config_directory, 'baked', 'maya')]) for d in dirs: not os.path.exists(d) and os.mkdir(d) @@ -1498,23 +1436,17 @@ def get_transform_info(ctl_transform): Return value description. """ - # TODO: Use *with* statement. - fp = open(ctl_transform, 'rb') + with open(ctl_transform, 'rb') as fp: + lines = fp.readlines() - # Read lines - lines = fp.readlines() - - # Grab transform ID and User Name - transform_ID = lines[1][3:].split('<')[1].split('>')[1].strip() - # print(transformID) + # Retrieving the *transform ID* and *User Name*. + transform_id = lines[1][3:].split('<')[1].split('>')[1].strip() transform_user_name = '-'.join( lines[2][3:].split('<')[1].split('>')[1].split('-')[1:]).strip() transform_user_name_prefix = ( lines[2][3:].split('<')[1].split('>')[1].split('-')[0].strip()) - # print(transformUserName) - fp.close() - return transform_ID, transform_user_name, transform_user_name_prefix + return transform_id, transform_user_name, transform_user_name_prefix def get_ODT_info(aces_CTL_directory): @@ -1535,55 +1467,48 @@ def get_ODT_info(aces_CTL_directory): """ # TODO: Investigate usage of *files_walker* definition here. - # Credit to Alex Fry for the original approach here - odt_dir = os.path.join(aces_CTL_directory, "odt") + # Credit to *Alex Fry* for the original approach here. + odt_dir = os.path.join(aces_CTL_directory, 'odt') all_odt = [] for dir_name, subdir_list, file_list in os.walk(odt_dir): for fname in file_list: all_odt.append((os.path.join(dir_name, fname))) odt_CTLs = [x for x in all_odt if - ("InvODT" not in x) and (os.path.split(x)[-1][0] != '.')] - - # print odtCTLs + ('InvODT' not in x) and (os.path.split(x)[-1][0] != '.')] odts = {} for odt_CTL in odt_CTLs: odt_tokens = os.path.split(odt_CTL) - # print(odtTokens) - # Handle nested directories + # Handling nested directories. odt_path_tokens = os.path.split(odt_tokens[-2]) odt_dir = odt_path_tokens[-1] while odt_path_tokens[-2][-3:] != 'odt': odt_path_tokens = os.path.split(odt_path_tokens[-2]) odt_dir = os.path.join(odt_path_tokens[-1], odt_dir) - # Build full name - # print("odtDir : %s" % odtDir) + # Building full name, transform_CTL = odt_tokens[-1] - # print(transformCTL) odt_name = string.join(transform_CTL.split('.')[1:-1], '.') - # print(odtName) - # Find id, user name and user name prefix + # Finding id, user name and user name prefix. (transform_ID, transform_user_name, transform_user_name_prefix) = get_transform_info( - "%s/odt/%s/%s" % (aces_CTL_directory, odt_dir, transform_CTL)) + os.path.join(aces_CTL_directory, 'odt', odt_dir, transform_CTL)) - # Find inverse - transform_CTL_inverse = "InvODT.%s.ctl" % odt_name + # Finding inverse. + transform_CTL_inverse = 'InvODT.%s.ctl' % odt_name if not os.path.exists( os.path.join(odt_tokens[-2], transform_CTL_inverse)): transform_CTL_inverse = None - # print(transformCTLInverse) # Add to list of ODTs odts[odt_name] = {} odts[odt_name]['transformCTL'] = os.path.join(odt_dir, transform_CTL) - if transform_CTL_inverse != None: + if transform_CTL_inverse is not None: odts[odt_name]['transformCTLInverse'] = os.path.join( odt_dir, transform_CTL_inverse) @@ -1591,19 +1516,20 @@ def get_ODT_info(aces_CTL_directory): odts[odt_name]['transformUserNamePrefix'] = transform_user_name_prefix odts[odt_name]['transformUserName'] = transform_user_name - print("ODT : %s" % odt_name) - print("\tTransform ID : %s" % transform_ID) - print("\tTransform User Name Prefix : %s" % transform_user_name_prefix) - print("\tTransform User Name : %s" % transform_user_name) - print("\tForward ctl : %s" % ( - odts[odt_name]['transformCTL'])) + forward_CTL = odts[odt_name]['transformCTL'] + + print('ODT : %s' % odt_name) + print('\tTransform ID : %s' % transform_ID) + print('\tTransform User Name Prefix : %s' % transform_user_name_prefix) + print('\tTransform User Name : %s' % transform_user_name) + print('\tForward ctl : %s' % forward_CTL) if 'transformCTLInverse' in odts[odt_name]: - print("\tInverse ctl : %s" % ( - odts[odt_name]['transformCTLInverse'])) + inverse_CTL = odts[odt_name]['transformCTLInverse'] + print('\tInverse ctl : %s' % inverse_CTL) else: - print("\tInverse ctl : %s" % "None") + print('\tInverse ctl : %s' % 'None') - print("\n") + print('\n') return odts @@ -1628,75 +1554,68 @@ def get_LMT_info(aces_CTL_directory): # TODO: Investigate refactoring with previous definition. # Credit to Alex Fry for the original approach here - lmt_dir = os.path.join(aces_CTL_directory, "lmt") + lmt_dir = os.path.join(aces_CTL_directory, 'lmt') all_lmt = [] for dir_name, subdir_list, file_list in os.walk(lmt_dir): for fname in file_list: all_lmt.append((os.path.join(dir_name, fname))) lmt_CTLs = [x for x in all_lmt if - ("InvLMT" not in x) and ("README" not in x) and ( + ('InvLMT' not in x) and ('README' not in x) and ( os.path.split(x)[-1][0] != '.')] - # print lmtCTLs - lmts = {} for lmt_CTL in lmt_CTLs: lmt_tokens = os.path.split(lmt_CTL) - # print(lmtTokens) - # Handle nested directories + # Handlimg nested directories. lmt_path_tokens = os.path.split(lmt_tokens[-2]) lmt_dir = lmt_path_tokens[-1] while lmt_path_tokens[-2][-3:] != 'ctl': lmt_path_tokens = os.path.split(lmt_path_tokens[-2]) lmt_dir = os.path.join(lmt_path_tokens[-1], lmt_dir) - # Build full name - # print("lmtDir : %s" % lmtDir) + # Building full name. transform_CTL = lmt_tokens[-1] - # print(transformCTL) lmt_name = string.join(transform_CTL.split('.')[1:-1], '.') - # print(lmtName) - # Find id, user name and user name prefix + # Finding id, user name and user name prefix. (transform_ID, transform_user_name, transform_user_name_prefix) = get_transform_info( - "%s/%s/%s" % (aces_CTL_directory, lmt_dir, transform_CTL)) + os.path.join(aces_CTL_directory, lmt_dir, transform_CTL)) - # Find inverse - transform_CTL_inverse = "InvLMT.%s.ctl" % lmt_name + # Finding inverse. + transform_CTL_inverse = 'InvLMT.%s.ctl' % lmt_name if not os.path.exists( os.path.join(lmt_tokens[-2], transform_CTL_inverse)): transform_CTL_inverse = None - # print(transformCTLInverse) - # Add to list of LMTs lmts[lmt_name] = {} lmts[lmt_name]['transformCTL'] = os.path.join(lmt_dir, transform_CTL) - if transform_CTL_inverse != None: - # TODO: Check unresolved *odt_name* referemce. - lmts[odt_name]['transformCTLInverse'] = os.path.join( + if transform_CTL_inverse is not None: + lmts[lmt_name]['transformCTLInverse'] = os.path.join( lmt_dir, transform_CTL_inverse) lmts[lmt_name]['transformID'] = transform_ID lmts[lmt_name]['transformUserNamePrefix'] = transform_user_name_prefix lmts[lmt_name]['transformUserName'] = transform_user_name - print("LMT : %s" % lmt_name) - print("\tTransform ID : %s" % transform_ID) - print("\tTransform User Name Prefix : %s" % transform_user_name_prefix) - print("\tTransform User Name : %s" % transform_user_name) - print("\t Forward ctl : %s" % lmts[lmt_name]['transformCTL']) + forward_CTL = lmts[lmt_name]['transformCTL'] + + print('LMT : %s' % lmt_name) + print('\tTransform ID : %s' % transform_ID) + print('\tTransform User Name Prefix : %s' % transform_user_name_prefix) + print('\tTransform User Name : %s' % transform_user_name) + print('\t Forward ctl : %s' % forward_CTL) if 'transformCTLInverse' in lmts[lmt_name]: - print("\t Inverse ctl : %s" % ( - lmts[lmt_name]['transformCTLInverse'])) + inverse_CTL = lmts[lmt_name]['transformCTLInverse'] + print('\t Inverse ctl : %s' % inverse_CTL) else: - print("\t Inverse ctl : %s" % "None") + print('\t Inverse ctl : %s' % 'None') - print("\n") + print('\n') return lmts @@ -1721,17 +1640,12 @@ def create_ACES_config(aces_CTL_directory, Return value description. """ - # Get ODT names and CTL paths odt_info = get_ODT_info(aces_CTL_directory) - - # Get ODT names and CTL paths lmt_info = get_LMT_info(aces_CTL_directory) - # Create config dir create_config_dir(config_directory, bake_secondary_LUTs) - # Generate config data and LUTs for different transforms - lut_directory = "%s/luts" % config_directory + lut_directory = os.path.join(config_directory, 'luts') shaper_name = 'Output Shaper' config_data = generate_LUTs(odt_info, lmt_info, @@ -1742,29 +1656,25 @@ def create_ACES_config(aces_CTL_directory, lut_resolution_3d, cleanup) - # Create the config using the generated LUTs - print("Creating generic config") + print('Creating "generic" config') config = create_config(config_data) - print("\n\n\n") + print('\n\n\n') - # Write the config to disk - write_config(config, "%s/config.ocio" % config_directory) + write_config(config, + os.path.join(config_directory, 'config.ocio')) - # Create a config that will work well with Nuke using the previously - # generated LUTs. - print("Creating Nuke-specific config") + print('Creating "Nuke" config') nuke_config = create_config(config_data, nuke=True) - print("\n\n\n") + print('\n\n\n') - # Write the config to disk - write_config(nuke_config, "%s/nuke_config.ocio" % config_directory) + write_config(nuke_config, + os.path.join(config_directory, 'nuke_config.ocio')) - # Bake secondary LUTs using the config if bake_secondary_LUTs: generate_baked_LUTs(odt_info, shaper_name, - "%s/baked" % config_directory, - "%s/config.ocio" % config_directory, + os.path.join(config_directory, 'baked'), + os.path.join(config_directory, 'config.ocio'), lut_resolution_1d, lut_resolution_3d, lut_resolution_1d) @@ -1794,26 +1704,24 @@ def main(): version='createACESConfig 0.1', usage='%prog [options]') p.add_option('--acesCTLDir', '-a', default=os.environ.get( - 'ACES_OCIO_CTL_DIRECTORY', None)) + ACES_OCIO_CTL_DIRECTORY_ENVIRON, None)) p.add_option('--configDir', '-c', default=os.environ.get( - 'ACES_OCIO_CONFIGURATION_DIRECTORY', None)) + ACES_OCIO_CONFIGURATION_DIRECTORY_ENVIRON, None)) p.add_option('--lutResolution1d', default=4096) p.add_option('--lutResolution3d', default=64) - p.add_option('--dontBakeSecondaryLUTs', action="store_true") - p.add_option('--keepTempImages', action="store_true") + p.add_option('--dontBakeSecondaryLUTs', action='store_true') + p.add_option('--keepTempImages', action='store_true') options, arguments = p.parse_args() - # - # Get options - # 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) - cleanup_temp_images = not (options.keepTempImages) + bake_secondary_LUTs = not options.dontBakeSecondaryLUTs + cleanup_temp_images = not options.keepTempImages + # TODO: Investigate the following statements. try: args_start = sys.argv.index('--') + 1 args = sys.argv[args_start:] @@ -1821,18 +1729,18 @@ def main(): args_start = len(sys.argv) + 1 args = [] - print("command line : \n%s\n" % " ".join(sys.argv)) - - # TODO: Use assertion and mention environment variables. - if not aces_CTL_directory: - print("process: No ACES CTL directory specified") - return - if not config_directory: - print("process: No configuration directory specified") - return - # - # Generate the configuration - # + print('command line : \n%s\n' % ' '.join(sys.argv)) + + 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)) + + assert config_directory is not None, ( + 'process: No "{0}" environment variable defined or no configuration ' + 'directory specified'.format( + ACES_OCIO_CONFIGURATION_DIRECTORY_ENVIRON)) + return create_ACES_config(aces_CTL_directory, config_directory, lut_resolution_1d, diff --git a/aces_1.0.0/python/aces_ocio/create_arri_colorspaces.py b/aces_1.0.0/python/aces_ocio/create_arri_colorspaces.py index be56c9d..6541140 100644 --- a/aces_1.0.0/python/aces_ocio/create_arri_colorspaces.py +++ b/aces_1.0.0/python/aces_ocio/create_arri_colorspaces.py @@ -7,9 +7,10 @@ Implements support for *ARRI* colorspaces conversions and transfer functions. import array import math +import os import aces_ocio.generate_lut as genlut -from aces_ocio.utilities import ColorSpace, mat44_from_mat33 +from aces_ocio.utilities import ColorSpace, mat44_from_mat33, sanitize_path __author__ = 'ACES Developers' @@ -45,11 +46,11 @@ def create_log_c(gamut, Return value description. """ - name = "%s (EI%s) - %s" % (transfer_function, exposure_index, gamut) - if transfer_function == "": - name = "Linear - %s" % gamut - if gamut == "": - name = "%s (EI%s)" % (transfer_function, exposure_index) + name = '%s (EI%s) - %s' % (transfer_function, exposure_index, gamut) + if transfer_function == '': + name = 'Linear - %s' % gamut + if gamut == '': + name = '%s (EI%s)' % (transfer_function, exposure_index) cs = ColorSpace(name) cs.description = name @@ -57,8 +58,8 @@ def create_log_c(gamut, cs.family = 'ARRI' cs.is_data = False - # Globals - IDT_maker_version = "0.08" + # Globals. + IDT_maker_version = '0.08' nominal_EI = 400.0 black_signal = 0.003907 @@ -76,18 +77,19 @@ def create_log_c(gamut, offset = math.log10(cut) - slope * cut gain = EI / nominal_EI gray = mid_gray_signal / gain - # The higher the EI, the lower the gamma + # The higher the EI, the lower the gamma. enc_gain = gain_for_EI(EI) enc_offset = encoding_offset for i in range(0, 3): nz = ((95.0 / 1023.0 - enc_offset) / enc_gain - offset) / slope enc_offset = encoding_offset - math.log10(1 + nz) * enc_gain - # Calculate some intermediate values + a = 1.0 / gray b = nz - black_signal / gray e = slope * a * enc_gain f = enc_gain * (slope * b + offset) + enc_offset - # Manipulations so we can return relative exposure + + # Ensuring we can return relative exposure. s = 4 / (0.18 * EI) t = black_signal b += a * t @@ -106,38 +108,34 @@ def create_log_c(gamut, def log_c_to_linear(code_value, exposure_index): p = log_c_inverse_parameters_for_EI(exposure_index) breakpoint = p['e'] * p['cut'] + p['f'] - if (code_value > breakpoint): + if code_value > breakpoint: linear = ((pow(10, (code_value / 1023.0 - p['d']) / p['c']) - p['b']) / p['a']) else: linear = (code_value / 1023.0 - p['f']) / p['e'] - - # print(codeValue, linear) return linear - cs.to_reference_transforms = [] - if transfer_function == "V3 LogC": - data = array.array('f', "\0" * lut_resolution_1d * 4) + if transfer_function == 'V3 LogC': + data = array.array('f', '\0' * lut_resolution_1d * 4) for c in range(lut_resolution_1d): data[c] = log_c_to_linear(1023.0 * c / (lut_resolution_1d - 1), int(exposure_index)) - lut = "%s_to_linear.spi1d" % ( - "%s_%s" % (transfer_function, exposure_index)) + lut = '%s_to_linear.spi1d' % ( + '%s_%s' % (transfer_function, exposure_index)) - # Remove spaces and parentheses - lut = lut.replace(' ', '_').replace(')', '_').replace('(', '_') + lut = sanitize_path(lut) - genlut.write_SPI_1d(lut_directory + "/" + lut, - 0.0, - 1.0, - data, - lut_resolution_1d, - 1) + genlut.write_SPI_1d( + os.path.join(lut_directory, lut), + 0.0, + 1.0, + data, + lut_resolution_1d, + 1) - # print("Writing %s" % lut) cs.to_reference_transforms.append({ 'type': 'lutFile', 'path': lut, @@ -149,8 +147,8 @@ def create_log_c(gamut, cs.to_reference_transforms.append({ 'type': 'matrix', 'matrix': mat44_from_mat33([0.680206, 0.236137, 0.083658, - 0.085415, 1.017471, -0.102886, - 0.002057, -0.062563, 1.060506]), + 0.085415, 1.017471, -0.102886, + 0.002057, -0.062563, 1.060506]), 'direction': 'forward' }) @@ -175,8 +173,8 @@ def create_colorspaces(lut_directory, lut_resolution_1d): colorspaces = [] - transfer_function = "V3 LogC" - gamut = "Wide Gamut" + transfer_function = 'V3 LogC' + gamut = 'Wide Gamut' # EIs = [160.0, 200.0, 250.0, 320.0, 400.0, 500.0, 640.0, 800.0, # 1000.0, 1280.0, 1600.0, 2000.0, 2560.0, 3200.0] @@ -184,34 +182,34 @@ def create_colorspaces(lut_directory, lut_resolution_1d): 1000, 1280, 1600, 2000, 2560, 3200] default_EI = 800 - # Full conversion + # Full Conversion for EI in EIs: log_c_EI_full = create_log_c( gamut, transfer_function, EI, - "LogC", + 'LogC', lut_directory, lut_resolution_1d) colorspaces.append(log_c_EI_full) - # Linearization only + # Linearization Only for EI in [800]: log_c_EI_linearization = create_log_c( - "", + '', transfer_function, EI, - "LogC", + 'LogC', lut_directory, lut_resolution_1d) colorspaces.append(log_c_EI_linearization) - # Primaries + # Primaries Only log_c_EI_primaries = create_log_c( gamut, - "", + '', default_EI, - "LogC", + 'LogC', lut_directory, lut_resolution_1d) colorspaces.append(log_c_EI_primaries) diff --git a/aces_1.0.0/python/aces_ocio/create_canon_colorspaces.py b/aces_1.0.0/python/aces_ocio/create_canon_colorspaces.py index 5ac15b3..1a3dffb 100644 --- a/aces_1.0.0/python/aces_ocio/create_canon_colorspaces.py +++ b/aces_1.0.0/python/aces_ocio/create_canon_colorspaces.py @@ -6,6 +6,7 @@ Implements support for *Canon* colorspaces conversions and transfer functions. """ import array +import os import aces_ocio.generate_lut as genlut from aces_ocio.utilities import ColorSpace @@ -42,11 +43,11 @@ def create_c_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 @@ -66,23 +67,24 @@ def create_c_log(gamut, linear = (pow(10.0, (legal_to_full(codeValue) - c3) / c1) - 1.0) / c2 linear *= 0.9 - # print(codeValue, linear) + return linear cs.to_reference_transforms = [] - if transfer_function == "Canon-Log": - data = array.array('f', "\0" * lut_resolution_1d * 4) + if transfer_function == 'Canon-Log': + data = array.array('f', '\0' * lut_resolution_1d * 4) for c in range(lut_resolution_1d): data[c] = c_log_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) + 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', @@ -162,107 +164,107 @@ def create_colorspaces(lut_directory, lut_resolution_1d): # Full conversion c_log_1 = create_c_log( - "Rec. 709 Daylight", - "Canon-Log", - "Canon-Log", + 'Rec. 709 Daylight', + 'Canon-Log', + 'Canon-Log', lut_directory, lut_resolution_1d) colorspaces.append(c_log_1) c_log_2 = create_c_log( - "Rec. 709 Tungsten", - "Canon-Log", - "Canon-Log", + 'Rec. 709 Tungsten', + 'Canon-Log', + 'Canon-Log', lut_directory, lut_resolution_1d) colorspaces.append(c_log_2) c_log_3 = create_c_log( - "DCI-P3 Daylight", - "Canon-Log", - "Canon-Log", + 'DCI-P3 Daylight', + 'Canon-Log', + 'Canon-Log', lut_directory, lut_resolution_1d) colorspaces.append(c_log_3) c_log_4 = create_c_log( - "DCI-P3 Tungsten", - "Canon-Log", - "Canon-Log", + 'DCI-P3 Tungsten', + 'Canon-Log', + 'Canon-Log', lut_directory, lut_resolution_1d) colorspaces.append(c_log_4) c_log_5 = create_c_log( - "Cinema Gamut Daylight", - "Canon-Log", - "Canon-Log", + 'Cinema Gamut Daylight', + 'Canon-Log', + 'Canon-Log', lut_directory, lut_resolution_1d) colorspaces.append(c_log_5) c_log_6 = create_c_log( - "Cinema Gamut Tungsten", - "Canon-Log", - "Canon-Log", + 'Cinema Gamut Tungsten', + 'Canon-Log', + 'Canon-Log', lut_directory, lut_resolution_1d) colorspaces.append(c_log_6) - # Linearization only + # Linearization Only c_log_7 = create_c_log( '', - "Canon-Log", - "Canon-Log", + 'Canon-Log', + 'Canon-Log', lut_directory, lut_resolution_1d) colorspaces.append(c_log_7) - # Primaries only + # Primaries Only c_log_8 = create_c_log( - "Rec. 709 Daylight", - "", - "Canon-Log", + 'Rec. 709 Daylight', + '', + 'Canon-Log', lut_directory, lut_resolution_1d) colorspaces.append(c_log_8) c_log_9 = create_c_log( - "Rec. 709 Tungsten", - "", - "Canon-Log", + 'Rec. 709 Tungsten', + '', + 'Canon-Log', lut_directory, lut_resolution_1d) colorspaces.append(c_log_9) c_log_10 = create_c_log( - "DCI-P3 Daylight", - "", - "Canon-Log", + 'DCI-P3 Daylight', + '', + 'Canon-Log', lut_directory, lut_resolution_1d) colorspaces.append(c_log_10) c_log_11 = create_c_log( - "DCI-P3 Tungsten", - "", - "Canon-Log", + 'DCI-P3 Tungsten', + '', + 'Canon-Log', lut_directory, lut_resolution_1d) colorspaces.append(c_log_11) c_log_12 = create_c_log( - "Cinema Gamut Daylight", - "", - "Canon-Log", + 'Cinema Gamut Daylight', + '', + 'Canon-Log', lut_directory, lut_resolution_1d) colorspaces.append(c_log_12) c_log_13 = create_c_log( - "Cinema Gamut Tungsten", - "", - "Canon-Log", + 'Cinema Gamut Tungsten', + '', + 'Canon-Log', lut_directory, lut_resolution_1d) colorspaces.append(c_log_13) diff --git a/aces_1.0.0/python/aces_ocio/create_red_colorspaces.py b/aces_1.0.0/python/aces_ocio/create_red_colorspaces.py index 4c09151..aaf4ce4 100644 --- a/aces_1.0.0/python/aces_ocio/create_red_colorspaces.py +++ b/aces_1.0.0/python/aces_ocio/create_red_colorspaces.py @@ -6,6 +6,7 @@ Implements support for *RED* 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_RED_log_film(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 @@ -70,17 +71,18 @@ def create_RED_log_film(gamut, cs.to_reference_transforms = [] if transfer_function == 'REDlogFilm': - data = array.array('f', "\0" * lut_resolution_1d * 4) + data = array.array('f', '\0' * lut_resolution_1d * 4) for c in range(lut_resolution_1d): data[c] = cineon_to_linear(1023.0 * c / (lut_resolution_1d - 1)) - lut = "CineonLog_to_linear.spi1d" - genlut.write_SPI_1d(lut_directory + "/" + lut, - 0.0, - 1.0, - data, - lut_resolution_1d, - 1) + lut = 'CineonLog_to_linear.spi1d' + 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', @@ -92,36 +94,36 @@ def create_RED_log_film(gamut, cs.to_reference_transforms.append({ 'type': 'matrix', 'matrix': mat44_from_mat33([0.532279, 0.376648, 0.091073, - 0.046344, 0.974513, -0.020860, - -0.053976, -0.000320, 1.054267]), + 0.046344, 0.974513, -0.020860, + -0.053976, -0.000320, 1.054267]), 'direction': 'forward'}) elif gamut == 'DRAGONcolor2': cs.to_reference_transforms.append({ 'type': 'matrix', 'matrix': mat44_from_mat33([0.468452, 0.331484, 0.200064, - 0.040787, 0.857658, 0.101553, - -0.047504, -0.000282, 1.047756]), + 0.040787, 0.857658, 0.101553, + -0.047504, -0.000282, 1.047756]), 'direction': 'forward'}) elif gamut == 'REDcolor2': cs.to_reference_transforms.append({ 'type': 'matrix', 'matrix': mat44_from_mat33([0.480997, 0.402289, 0.116714, - -0.004938, 1.000154, 0.004781, - -0.105257, 0.025320, 1.079907]), + -0.004938, 1.000154, 0.004781, + -0.105257, 0.025320, 1.079907]), 'direction': 'forward'}) elif gamut == 'REDcolor3': cs.to_reference_transforms.append({ 'type': 'matrix', 'matrix': mat44_from_mat33([0.512136, 0.360370, 0.127494, - 0.070377, 0.903884, 0.025737, - -0.020824, 0.017671, 1.003123]), + 0.070377, 0.903884, 0.025737, + -0.020824, 0.017671, 1.003123]), 'direction': 'forward'}) elif gamut == 'REDcolor4': cs.to_reference_transforms.append({ 'type': 'matrix', 'matrix': mat44_from_mat33([0.474202, 0.333677, 0.192121, - 0.065164, 0.836932, 0.097901, - -0.019281, 0.016362, 1.002889]), + 0.065164, 0.836932, 0.097901, + -0.019281, 0.016362, 1.002889]), 'direction': 'forward'}) cs.from_reference_transforms = [] @@ -147,91 +149,91 @@ def create_colorspaces(lut_directory, lut_resolution_1d): # Full conversion RED_log_film_dragon = create_RED_log_film( - "DRAGONcolor", - "REDlogFilm", - "REDlogFilm", + 'DRAGONcolor', + 'REDlogFilm', + 'REDlogFilm', lut_directory, lut_resolution_1d) colorspaces.append(RED_log_film_dragon) RED_log_film_dragon2 = create_RED_log_film( - "DRAGONcolor2", - "REDlogFilm", - "REDlogFilm", + 'DRAGONcolor2', + 'REDlogFilm', + 'REDlogFilm', lut_directory, lut_resolution_1d) colorspaces.append(RED_log_film_dragon2) RED_log_film_color2 = create_RED_log_film( - "REDcolor2", - "REDlogFilm", - "REDlogFilm", + 'REDcolor2', + 'REDlogFilm', + 'REDlogFilm', lut_directory, lut_resolution_1d) colorspaces.append(RED_log_film_color2) RED_log_film_color3 = create_RED_log_film( - "REDcolor3", - "REDlogFilm", - "REDlogFilm", + 'REDcolor3', + 'REDlogFilm', + 'REDlogFilm', lut_directory, lut_resolution_1d) colorspaces.append(RED_log_film_color3) RED_log_film_color4 = create_RED_log_film( - "REDcolor4", - "REDlogFilm", - "REDlogFilm", + 'REDcolor4', + 'REDlogFilm', + 'REDlogFilm', lut_directory, lut_resolution_1d) colorspaces.append(RED_log_film_color4) # Linearization only RED_log_film_dragon = create_RED_log_film( - "", - "REDlogFilm", - "REDlogFilm", + '', + 'REDlogFilm', + 'REDlogFilm', lut_directory, lut_resolution_1d) colorspaces.append(RED_log_film_dragon) # Primaries only RED_log_film_dragon = create_RED_log_film( - "DRAGONcolor", - "", - "REDlogFilm", + 'DRAGONcolor', + '', + 'REDlogFilm', lut_directory, lut_resolution_1d) colorspaces.append(RED_log_film_dragon) RED_log_film_dragon2 = create_RED_log_film( - "DRAGONcolor2", - "", - "REDlogFilm", + 'DRAGONcolor2', + '', + 'REDlogFilm', lut_directory, lut_resolution_1d) colorspaces.append(RED_log_film_dragon2) RED_log_film_color2 = create_RED_log_film( - "REDcolor2", - "", - "REDlogFilm", + 'REDcolor2', + '', + 'REDlogFilm', lut_directory, lut_resolution_1d) colorspaces.append(RED_log_film_color2) RED_log_film_color3 = create_RED_log_film( - "REDcolor3", - "", - "REDlogFilm", + 'REDcolor3', + '', + 'REDlogFilm', lut_directory, lut_resolution_1d) colorspaces.append(RED_log_film_color3) RED_log_film_color4 = create_RED_log_film( - "REDcolor4", - "", - "REDlogFilm", + 'REDcolor4', + '', + 'REDlogFilm', lut_directory, lut_resolution_1d) colorspaces.append(RED_log_film_color4) diff --git a/aces_1.0.0/python/aces_ocio/create_sony_colorspaces.py b/aces_1.0.0/python/aces_ocio/create_sony_colorspaces.py index 3867e87..af334b8 100644 --- a/aces_1.0.0/python/aces_ocio/create_sony_colorspaces.py +++ b/aces_1.0.0/python/aces_ocio/create_sony_colorspaces.py @@ -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 @@ -59,15 +60,14 @@ def create_s_log(gamut, ab = 90. w = 940. - if (s_log >= ab): + if s_log >= ab: linear = ((pow(10., - ( ((s_log - b) / - (w - b) - 0.616596 - 0.03) / 0.432699)) - + (((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): @@ -75,7 +75,7 @@ def create_s_log(gamut, ab = 90. w = 940. - if (s_log >= ab): + if s_log >= ab: linear = ((219. * (pow(10., (((s_log - b) / (w - b) - 0.616596 - 0.03) / 0.432699)) - @@ -86,79 +86,73 @@ def create_s_log(gamut, 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,119 +216,119 @@ 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) diff --git a/aces_1.0.0/python/aces_ocio/generate_lut.py b/aces_1.0.0/python/aces_ocio/generate_lut.py old mode 100644 new mode 100755 index e0d4dfa..1f23b06 --- a/aces_1.0.0/python/aces_ocio/generate_lut.py +++ b/aces_1.0.0/python/aces_ocio/generate_lut.py @@ -52,13 +52,8 @@ def generate_1d_LUT_image(ramp_1d_path, Return value description. """ - # print("Generate 1d LUT image - %s" % ramp1dPath) - - # open image - format = os.path.splitext(ramp_1d_path)[1] ramp = oiio.ImageOutput.create(ramp_1d_path) - # set image specs spec = oiio.ImageSpec() spec.set_format(oiio.FLOAT) # spec.format.basetype = oiio.FLOAT @@ -68,8 +63,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 @@ -99,19 +94,18 @@ def write_SPI_1d(filename, from_min, from_max, data, entries, channels): Return value description. """ - 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") - for i in range(0, entries): - 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") - f.close() + with open(filename, 'w') as fp: + fp.write('Version 1\n') + fp.write('From %f %f\n' % (from_min, from_max)) + fp.write('Length %d\n' % entries) + fp.write('Components %d\n' % (min(3, channels))) + fp.write('{\n') + for i in range(0, entries): + entry = '' + for j in range(0, min(3, channels)): + entry = '%s %s' % (entry, data[i * channels + j]) + fp.write(' %s\n' % entry) + fp.write('}\n') def generate_1d_LUT_from_image(ramp_1d_path, @@ -133,21 +127,16 @@ def generate_1d_LUT_from_image(ramp_1d_path, """ if output_path is None: - output_path = ramp_1d_path + ".spi1d" + output_path = '%s.%s' % (ramp_1d_path, 'spi1d') - # open image ramp = oiio.ImageInput.open(ramp_1d_path) - # get image specs spec = ramp.spec() - type = spec.format.basetype width = spec.width - height = spec.height channels = spec.nchannels - # get data - # Force data to be read as float. The Python API doesn't handle - # half-floats well yet. + # Forcibly read data as float, the Python API doesn't handle half-float + # well yet. type = oiio.FLOAT data = ramp.read_image(type) @@ -169,15 +158,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,29 +187,29 @@ 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 = '%s.%s' % (ramp_3d_path, 'spi1d') - 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() def apply_CTL_to_image(input_image, output_image, - ctl_paths=[], + ctl_paths=None, input_scale=1.0, output_scale=1.0, - global_params={}, + global_params=None, aces_CTL_directory=None): """ Object description. @@ -236,11 +225,16 @@ def apply_CTL_to_image(input_image, Return value description. """ + if ctl_paths is None: + ctl_paths = [] + if global_params is None: + global_params = {} + 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 aces_CTL_directory is not None: + if os.path.split(aces_CTL_directory)[1] != 'utilities': + ctl_module_path = os.path.join(aces_CTL_directory, 'utilities') else: ctl_module_path = aces_CTL_directory ctlenv['CTL_MODULE_PATH'] = ctl_module_path @@ -248,20 +242,17 @@ 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 += ['-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) - - ctlp = Process(description="a ctlrender process", - cmd="ctlrender", + ctlp = Process(description='a ctlrender process', + cmd='ctlrender', args=args, env=ctlenv) ctlp.execute() @@ -283,12 +274,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() @@ -299,7 +290,7 @@ def generate_1d_LUT_from_CTL(lut_path, identity_LUT_bit_depth='half', input_scale=1.0, output_scale=1.0, - global_params={}, + global_params=None, cleanup=True, aces_CTL_directory=None, min_value=0.0, @@ -318,26 +309,26 @@ def generate_1d_LUT_from_CTL(lut_path, Return value description. """ - # print(lutPath) - # print(ctlPaths) + if global_params is None: + global_params = {} lut_path_base = os.path.splitext(lut_path)[0] - identity_LUT_image_float = lut_path_base + ".float.tiff" + identity_LUT_image_float = '%s.%s.%s' % (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 = '%s.%s.%s' % (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 = '%s.%s.%s' % (lut_path_base, 'transformed', 'exr') apply_CTL_to_image(identity_LUT_image, transformed_LUT_image, ctl_paths, @@ -375,40 +366,29 @@ def correct_LUT_image(transformed_LUT_image, Return value description. """ - # open image transformed = oiio.ImageInput.open(transformed_LUT_image) - # get image specs transformed_spec = transformed.spec() - type = transformed_spec.format.basetype width = transformed_spec.width height = transformed_spec.height channels = transformed_spec.nchannels - # 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 - # - - # Get the source data - # Force data to be read as float. The Python API doesn't handle - # half-floats well yet. + # Forcibly read data as float, the Python API doesn't handle half-float + # well yet. type = oiio.FLOAT source_data = transformed.read_image(type) - format = os.path.splitext(corrected_LUT_image)[1] correct = oiio.ImageOutput.create(corrected_LUT_image) - # set image specs correct_spec = oiio.ImageSpec() correct_spec.set_format(oiio.FLOAT) correct_spec.width = height @@ -417,14 +397,13 @@ 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): for i in range(0, correct_spec.width): for c in range(0, correct_spec.nchannels): - # print(i, j, c) dest_data[(correct_spec.nchannels * correct_spec.width * j + correct_spec.nchannels * i + c)] = ( @@ -449,7 +428,7 @@ def generate_3d_LUT_from_CTL(lut_path, identity_LUT_bit_depth='half', input_scale=1.0, output_scale=1.0, - global_params={}, + global_params=None, cleanup=True, aces_CTL_directory=None): """ @@ -466,26 +445,25 @@ def generate_3d_LUT_from_CTL(lut_path, Return value description. """ - # print(lutPath) - # print(ctlPaths) + if global_params is None: + global_params = {} lut_path_base = os.path.splitext(lut_path)[0] - identity_LUT_image_float = lut_path_base + ".float.tiff" + identity_LUT_image_float = '%s.%s.%s' % (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") + identity_LUT_image = '%s.%s.%s' % (lut_path_base, + identity_LUT_bit_depth, + '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 = '%s.%s.%s' % (lut_path_base, 'transformed', 'exr') apply_CTL_to_image(identity_LUT_image, transformed_LUT_image, ctl_paths, @@ -494,7 +472,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 = '%s.%s.%s' % (lut_path_base, 'correct', 'exr') corrected_LUT_image = correct_LUT_image(transformed_LUT_image, corrected_LUT_image, lut_resolution) @@ -508,7 +486,6 @@ def generate_3d_LUT_from_CTL(lut_path, os.remove(transformed_LUT_image) if corrected_LUT_image != transformed_LUT_image: os.remove(corrected_LUT_image) - # os.remove(correctedLUTImage) def main(): @@ -534,28 +511,25 @@ 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('--lutResolution1d', '', type='int', default=1024) + p.add_option('--lutResolution3d', '', 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() - # - # Get options - # lut = options.lut ctls = options.ctl lut_resolution_1d = options.lut_resolution_1d @@ -567,11 +541,11 @@ def main(): ctl_release_path = options.ctlReleasePath generate_1d = options.generate1d is True generate_3d = options.generate3d is True - bitdepth = options.bitDepth + bit_depth = options.bitDepth cleanup = not options.keepTempImages params = {} - if options.ctlRenderParam != None: + if options.ctlRenderParam is not None: for param in options.ctlRenderParam: params[param[0]] = float(param[1]) @@ -582,34 +556,29 @@ def main(): args_start = len(sys.argv) + 1 args = [] - # 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' % bit_depth) + print('cleanup temp images : %s' % cleanup) if generate_1d: generate_1d_LUT_from_CTL(lut, ctls, lut_resolution_1d, - bitdepth, + bit_depth, input_scale, output_scale, params, @@ -622,15 +591,15 @@ def main(): generate_3d_LUT_from_CTL(lut, ctls, lut_resolution_3d, - bitdepth, + bit_depth, input_scale, output_scale, params, 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__': diff --git a/aces_1.0.0/python/aces_ocio/process.py b/aces_1.0.0/python/aces_ocio/process.py index 6445b46..062855e 100755 --- a/aces_1.0.0/python/aces_ocio/process.py +++ b/aces_1.0.0/python/aces_ocio/process.py @@ -39,11 +39,9 @@ def read_text(text_file): Return value description. """ - if (text_file != ""): - fp = open(text_file, 'rb') - # Create a text/plain message - text = (fp.read()) - fp.close() + if text_file != '': + with open(text_file, 'rb') as fp: + text = (fp.read()) return text @@ -62,11 +60,9 @@ def write_text(text, text_file): Return value description. """ - if (text_file != ""): - fp = open(text_file, 'wb') - # Create a text/plain message - fp.write(text) - fp.close() + if text_file != '': + with open(text_file, 'wb') as fp: + fp.write(text) return text @@ -78,7 +74,7 @@ class Process: def __init__(self, description=None, cmd=None, - args=[], + args=None, cwd=None, env=None, batch_wrapper=False): @@ -96,6 +92,9 @@ class Process: Return value description. """ + if args is None: + args = [] + self.cmd = cmd if not description: self.description = cmd @@ -131,7 +130,7 @@ class Process: if self.end and self.start: delta = (self.end - self.start) - formatted = "%s.%s" % (delta.days * 86400 + delta.seconds, + formatted = '%s.%s' % (delta.days * 86400 + delta.seconds, int(math.floor(delta.microseconds / 1e3))) else: formatted = None @@ -152,19 +151,19 @@ class Process: Return value description. """ - if key != None and (value != None or start_stop != None): + if key is not None and (value is not None or start_stop is not None): indent = '\t' * write_dict['indentationLevel'] if write_dict['format'] == 'xml': if start_stop == 'start': - write_dict['logHandle'].write("%s<%s>\n" % (indent, key)) + write_dict['logHandle'].write('%s<%s>\n' % (indent, key)) elif start_stop == 'stop': - write_dict['logHandle'].write("%s\n" % (indent, key)) + write_dict['logHandle'].write('%s\n' % (indent, key)) else: write_dict['logHandle'].write( - "%s<%s>%s\n" % (indent, key, value, key)) - else: # writeDict['format'] == 'txt': + '%s<%s>%s\n' % (indent, key, value, key)) + else: write_dict['logHandle'].write( - "%s%40s : %s\n" % (indent, key, value)) + '%s%40s : %s\n' % (indent, key, value)) def write_log_header(self, write_dict): """ @@ -183,28 +182,22 @@ class Process: import platform - # Retrieve operating environment information - user = None try: user = os.getlogin() except: try: - user = os.getenv("USERNAME") + user = os.getenv('USERNAME') if user is None: - user = os.getenv("USER") + user = os.getenv('USER') except: - user = "unknown_user" + user = 'unknown_user' try: (sysname, nodename, release, version, machine, processor) = platform.uname() except: (sysname, nodename, release, version, machine, processor) = ( - "unknown_sysname", "unknown_nodename", "unknown_release", - "unknown_version", "unknown_machine", "unknown_processor") - try: - hostname = platform.node() - except: - hostname = "unknown_hostname" + 'unknown_sysname', 'unknown_nodename', 'unknown_release', + 'unknown_version', 'unknown_machine', 'unknown_processor') self.write_key(write_dict, 'process', None, 'start') write_dict['indentationLevel'] += 1 @@ -283,11 +276,11 @@ class Process: if self.log: self.write_key(write_dict, 'output', None, 'start') if format == 'xml': - log_handle.write("\n") + log_handle.write(']]>\n') self.write_key(write_dict, 'output', None, 'stop') self.write_log_footer(write_dict) @@ -309,27 +302,25 @@ class Process: if log_filename: try: - # This also doesn't seem like the best structure... + # TODO: Review statements. # 3.1 try: - log_handle = open(log_filename, - mode='wt', - encoding="utf-8") + log_handle = ( + open(log_filename, mode='wt', encoding='utf-8')) # 2.6 except: - log_handle = open(log_filename, - mode='wt') + log_handle = open(log_filename, mode='wt') except: - print("Couldn't open log : %s" % log_filename) + print('Couldn\'t open log : %s' % log_filename) log_handle = None if log_handle: if header: if format == 'xml': - log_handle.write("\n") + log_handle.write(']]>\n') self.write_log(log_handle) log_handle.close() @@ -350,7 +341,7 @@ class Process: self.log.append(line.rstrip()) if self.echo: - print("%s" % line.rstrip()) + print('%s' % line.rstrip()) def execute(self): """ @@ -383,11 +374,10 @@ class Process: if self.echo: if sp: print( - "\n%s : %s\n" % (self.__class__, sp.list2cmdline(cmdargs))) + '\n%s : %s\n' % (self.__class__, sp.list2cmdline(cmdargs))) else: - print("\n%s : %s\n" % (self.__class__, " ".join(cmdargs))) + print('\n%s : %s\n' % (self.__class__, ' '.join(cmdargs))) - # intialize a few variables that may or may not be set later process = None tmp_wrapper = None stdout = None @@ -396,13 +386,13 @@ class Process: parentcwd = os.getcwd() try: - # Using subprocess + # Using *subprocess*. if sp: if self.batch_wrapper: - cmd = " ".join(cmdargs) - tmp_wrapper = os.path.join(self.cwd, "process.bat") + cmd = ' '.join(cmdargs) + tmp_wrapper = os.path.join(self.cwd, 'process.bat') write_text(cmd, tmp_wrapper) - print("%s : Running process through wrapper %s\n" % ( + print('%s : Running process through wrapper %s\n' % ( self.__class__, tmp_wrapper)) process = sp.Popen([tmp_wrapper], stdout=sp.PIPE, stderr=sp.STDOUT, @@ -412,7 +402,7 @@ class Process: stderr=sp.STDOUT, cwd=self.cwd, env=self.env) - # using os.popen4 + # using *os.popen4*. else: if self.env: os.environ = self.env @@ -421,42 +411,44 @@ class Process: stdin, stdout = os.popen4(cmdargs, 'r') except: - print("Couldn't execute command : %s" % cmdargs[0]) + print('Couldn\'t execute command : %s' % cmdargs[0]) traceback.print_exc() - # Using subprocess + # Using *subprocess* if sp: - if process != None: + if process is not None: # pid = process.pid - # log.logLine("process id %s\n" % pid) + # log.logLine('process id %s\n' % pid) try: # This is more proper python, and resolves some issues with # a process ending before all of its output has been # processed, but it also seems to stall when the read - # buffer is near or over it's limit. this happens + # buffer is near or over its limit. This happens # relatively frequently with processes that generate lots # of print statements. for line in process.stdout: self.log_line(line) - # - # So we go with the, um, uglier option below - # This is now used to ensure that the process has finished - line = "" - while line != None and process.poll() is None: + # So we go with the, um, uglier option below. + + # This is now used to ensure that the process has finished. + line = '' + while line is not None and process.poll() is None: try: line = process.stdout.readline() except: break # 3.1 try: - self.log_line(str(line, encoding="utf-8")) + # TODO: Investigate previous eroneous statement. + # self.log_line(str(line, encoding='utf-8')) + self.log_line(str(line)) # 2.6 except: self.log_line(line) except: - self.log_line("Logging error : %s" % sys.exc_info()[0]) + self.log_line('Logging error : %s' % sys.exc_info()[0]) self.status = process.returncode @@ -465,15 +457,16 @@ class Process: os.remove(tmp_wrapper) except: print( - "Couldn't remove temp wrapper : %s" % tmp_wrapper) + 'Couldn\'t remove temp wrapper : %s' % tmp_wrapper) traceback.print_exc() - # Using os.popen4 + # Using *os.popen4*. else: exit_code = -1 try: - # print("reading stdout lines") stdout_lines = stdout.readlines() + # TODO: Investigate if this is the good behavior, close() does + # not return anything / None. exit_code = stdout.close() stdout.close() @@ -491,7 +484,7 @@ class Process: if not exit_code: exit_code = 0 except: - self.log_line("Logging error : %s" % sys.exc_info()[0]) + self.log_line('Logging error : %s' % sys.exc_info()[0]) self.status = exit_code @@ -519,7 +512,7 @@ class ProcessList(Process): """ Process.__init__(self, description, None, None, cwd, env) - "Initialize the standard class variables" + 'Initialize the standard class variables' self.processes = [] self.blocking = blocking @@ -548,15 +541,14 @@ class ProcessList(Process): if isinstance(child, ProcessList): child.generate_report(write_dict) - child_result = "" key = child.description value = child.status if write_dict['format'] == 'xml': child_result = ( - "%s%s" % ( + '%s%s' % ( indent, key, value)) - else: # writeDict['format'] == 'txt': - child_result = ("%s%40s : %s" % (indent, key, value)) + else: + child_result = ('%s%40s : %s' % (indent, key, value)) self.log.append(child_result) if child.status != 0: @@ -566,7 +558,7 @@ class ProcessList(Process): else: self.status = 0 else: - self.log = ["No child processes available to generate a report"] + self.log = ['No child processes available to generate a report'] self.status = -1 def write_log_header(self, write_dict): @@ -643,7 +635,7 @@ class ProcessList(Process): if self.log: self.write_key(write_dict, 'output', None, 'start') for line in self.log: - log_handle.write('%s%s\n' % ("", line)) + log_handle.write('%s%s\n' % ('', line)) self.write_key(write_dict, 'output', None, 'stop') if self.processes: @@ -680,13 +672,13 @@ class ProcessList(Process): try: child.execute() except: - print("%s : caught exception in child class %s" % ( + print('%s : caught exception in child class %s' % ( self.__class__, child.__class__)) traceback.print_exc() child.status = -1 if self.blocking and child.status != 0: - print("%s : child class %s finished with an error" % ( + print('%s : child class %s finished with an error' % ( self.__class__, child.__class__)) self.status = -1 break @@ -721,9 +713,6 @@ def main(): options, arguments = p.parse_args() - # - # Get options - # cmd = options.cmd log_filename = options.log @@ -735,17 +724,13 @@ def main(): args = [] if cmd is None: - print("process: No command specified") + print('process: No command specified') - # - # Test regular logging - # - process = Process(description="a process", cmd=cmd, args=args) + # Testing regular logging. + process = Process(description='a process', cmd=cmd, args=args) - # - # Test report generation and writing a log - # - process_list = ProcessList("a process list") + # Testing report generation and writing a log. + process_list = ProcessList('a process list') process_list.processes.append(process) process_list.echo = True process_list.execute() diff --git a/aces_1.0.0/python/aces_ocio/tests/tests_aces_config.py b/aces_1.0.0/python/aces_ocio/tests/tests_aces_config.py index 61acfa5..229c880 100644 --- a/aces_1.0.0/python/aces_ocio/tests/tests_aces_config.py +++ b/aces_1.0.0/python/aces_ocio/tests/tests_aces_config.py @@ -9,12 +9,6 @@ import hashlib import os import re import shutil -import sys - -# TODO: Temporary ugly thing to be discussed, ideally the package should be -# in PYTHONPATH. -sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..')) - import tempfile import unittest @@ -39,7 +33,7 @@ __all__ = ['REFERENCE_CONFIG_ROOT_DIRECTORY', # TODO: Investigate how the current config has been generated to use it for # tests. # REFERENCE_CONFIG_ROOT_DIRECTORY = os.path.abspath( -# os.path.join(os.path.dirname(__file__), '..', '..', '..')) +# os.path.join(os.path.dirname(__file__), '..', '..', '..')) REFERENCE_CONFIG_ROOT_DIRECTORY = '/colour-science/colour-ramblings/ocio/aces' HASH_TEST_PATTERNS = ('\.3dl', '\.lut', '\.csp') @@ -105,11 +99,12 @@ class TestACESConfig(unittest.TestCase): hashes = {} for path in files_walker(directory, filters_in=filters_in, - filters_out=filters_out): + filters_out=filters_out, + flags=flags): with open(path) as file: - hash = hashlib.md5( + digest = hashlib.md5( re.sub('\s', '', file.read())).hexdigest() - hashes[path.replace(directory, '')] = hash + hashes[path.replace(directory, '')] = digest return hashes def test_ACES_config(self): diff --git a/aces_1.0.0/python/aces_ocio/utilities.py b/aces_1.0.0/python/aces_ocio/utilities.py index 00804e3..c60476a 100644 --- a/aces_1.0.0/python/aces_ocio/utilities.py +++ b/aces_1.0.0/python/aces_ocio/utilities.py @@ -20,11 +20,9 @@ __status__ = 'Production' __all__ = ['ColorSpace', 'mat44_from_mat33', 'filter_words', - 'files_walker'] + 'files_walker', + 'sanitize_path'] -# -# Utility classes and functions -# class ColorSpace(object): """ @@ -152,3 +150,21 @@ def files_walker(directory, filters_in=None, filters_out=None, flags=0): continue yield path + + +def sanitize_path(path): + """ + Object description. + + Parameters + ---------- + parameter : type + Parameter description. + + Returns + ------- + type + Return value description. + """ + + return path.replace(' ', '_').replace(')', '_').replace('(', '_') \ No newline at end of file diff --git a/aces_1.0.0/python/bin/create_aces_config b/aces_1.0.0/python/bin/create_aces_config new file mode 100755 index 0000000..b59fa39 --- /dev/null +++ b/aces_1.0.0/python/bin/create_aces_config @@ -0,0 +1,25 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +Creates the *ACES* configuration. +""" + +import os +import sys + +sys.path.append(os.path.join(os.path.dirname(__file__), '..')) + +from aces_ocio.create_aces_config import main + +__author__ = 'ACES Developers' +__copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers' +__license__ = '' +__maintainer__ = 'ACES Developers' +__email__ = 'aces@oscars.org' +__status__ = 'Production' + +__all__ = [] + +if __name__ == '__main__': + main() diff --git a/aces_1.0.0/python/bin/tests_aces_config b/aces_1.0.0/python/bin/tests_aces_config new file mode 100755 index 0000000..6fe08ed --- /dev/null +++ b/aces_1.0.0/python/bin/tests_aces_config @@ -0,0 +1,24 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +Tests the *ACES* configuration. +""" + +import os +import unittest +import sys + +sys.path.append(os.path.join(os.path.dirname(__file__), '..')) + +from aces_ocio.tests.tests_aces_config import * + +__author__ = 'ACES Developers' +__copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers' +__license__ = '' +__maintainer__ = 'ACES Developers' +__email__ = 'aces@oscars.org' +__status__ = 'Production' + +if __name__ == '__main__': + unittest.main()