From: hpd Date: Wed, 28 Jan 2015 21:54:21 +0000 (-0800) Subject: Merge pull request #3 from colour-science/code_style X-Git-Url: http://users.mur.at/ms/git/gitweb/?p=OpenColorIO-Configs.git;a=commitdiff_plain;h=ab47928e6f563f2bfd6bb8eadaf2a37f2b3a1e08;hp=6fc0fbf65d1217af1962d82c948fb83613bcb400 Merge pull request #3 from colour-science/code_style PR: Improve various code style aspects and implement "__future__" division support. --- diff --git a/aces_1.0.0/python/aces_ocio/__init__.py b/aces_1.0.0/python/aces_ocio/__init__.py index 7a50220..3d33635 100644 --- a/aces_1.0.0/python/aces_ocio/__init__.py +++ b/aces_1.0.0/python/aces_ocio/__init__.py @@ -12,9 +12,9 @@ Python ****** >>> from aces_ocio.create_aces_config import create_ACES_config ->>> aces_CTL_directory = '/path/to/github/checkout/releases/v1.0.0/transforms/ctl' +>>> 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) +>>> create_ACES_config(aces_ctl_directory, config_directory, 1024, 33, True) Command Line ************ diff --git a/aces_1.0.0/python/aces_ocio/create_aces_colorspaces.py b/aces_1.0.0/python/aces_ocio/create_aces_colorspaces.py index 606b160..c69fcac 100644 --- a/aces_1.0.0/python/aces_ocio/create_aces_colorspaces.py +++ b/aces_1.0.0/python/aces_ocio/create_aces_colorspaces.py @@ -5,21 +5,26 @@ Implements support for *ACES* colorspaces conversions and transfer functions. """ -import array +from __future__ import division + import math import numpy import os import pprint import string +import shutil import PyOpenColorIO as ocio -import aces_ocio.generate_lut as genlut from aces_ocio.generate_lut import ( generate_1d_LUT_from_CTL, generate_3d_LUT_from_CTL, write_SPI_1d) -from aces_ocio.utilities import ColorSpace, mat44_from_mat33, sanitize_path, compact +from aces_ocio.utilities import ( + ColorSpace, + mat44_from_mat33, + sanitize, + compact) __author__ = 'ACES Developers' @@ -29,46 +34,85 @@ __maintainer__ = 'ACES Developers' __email__ = 'aces@oscars.org' __status__ = 'Production' -__all__ = ['create_ACEScc', +__all__ = ['ACES_AP1_TO_AP0', + 'ACES_AP0_TO_XYZ', + 'create_ACES', + 'create_ACEScc', 'create_ACESproxy', 'create_ACEScg', 'create_ADX', - 'create_generic_log', 'create_ACES_LMT', - 'create_lmts', 'create_ACES_RRT_plus_ODT', - 'create_odts', - 'create_aces', + 'create_generic_log', + 'create_LMTs', + 'create_ODTs', 'get_transform_info', - 'get_ODT_info', - 'get_LMT_info', + 'get_ODTs_info', + 'get_LMTs_info', 'create_colorspaces'] -# ------------------------------------------------------------------------- -# *Matrices* -# ------------------------------------------------------------------------- - # Matrix converting *ACES AP1* primaries to *AP0*. -ACES_AP1_to_AP0 = [0.6954522414, 0.1406786965, 0.1638690622, +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*. -ACES_AP0_to_XYZ = [0.9525523959, 0.0000000000, 0.0000936786, +ACES_AP0_TO_XYZ = [0.9525523959, 0.0000000000, 0.0000936786, 0.3439664498, 0.7281660966, -0.0721325464, 0.0000000000, 0.0000000000, 1.0088251844] -# ------------------------------------------------------------------------- -# *ACEScc* -# ------------------------------------------------------------------------- -def create_ACEScc(aces_CTL_directory, - lut_directory, + +def create_ACES(): + """ + Object description. + + Parameters + ---------- + parameter : type + Parameter description. + + Returns + ------- + type + Return value description. + """ + + # Defining the reference colorspace. + aces2065_1 = ColorSpace('ACES2065-1') + aces2065_1.description = ( + 'The Academy Color Encoding System reference color space') + aces2065_1.equality_group = '' + aces2065_1.aliases = ["lin_ap0", "aces"] + aces2065_1.family = 'ACES' + aces2065_1.is_data = False + aces2065_1.allocation_type = ocio.Constants.ALLOCATION_LG2 + aces2065_1.allocation_vars = [-15, 6] + + return aces2065_1 + + +def create_ACEScc(aces_ctl_directory, + lut_directory, lut_resolution_1d, cleanup, name='ACEScc', - min_value=0.0, - max_value=1.0, - input_scale=1.0): + min_value=0, + max_value=1, + input_scale=1): + """ + Creates the *ACEScc* colorspace. + + Parameters + ---------- + parameter : type + Parameter description. + + Returns + ------- + Colorspace + *ACEScc* colorspace. + """ + cs = ColorSpace(name) cs.description = 'The %s color space' % name cs.aliases = ["acescc_ap1"] @@ -76,18 +120,18 @@ def create_ACEScc(aces_CTL_directory, cs.family = 'ACES' cs.is_data = False - ctls = [os.path.join(aces_CTL_directory, + 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, + os.path.join(aces_ctl_directory, 'ACEScg', 'ACEScsc.ACES_to_ACEScg.a1.0.0.ctl')] lut = '%s_to_ACES.spi1d' % name - lut = sanitize_path(lut) + lut = sanitize(lut) generate_1d_LUT_from_CTL( os.path.join(lut_directory, lut), @@ -95,10 +139,10 @@ def create_ACEScc(aces_CTL_directory, lut_resolution_1d, 'float', input_scale, - 1.0, + 1, {}, cleanup, - aces_CTL_directory, + aces_ctl_directory, min_value, max_value) @@ -112,21 +156,32 @@ def create_ACEScc(aces_CTL_directory, # *AP1* primaries to *AP0* primaries. cs.to_reference_transforms.append({ 'type': 'matrix', - 'matrix': mat44_from_mat33(ACES_AP1_to_AP0), + 'matrix': mat44_from_mat33(ACES_AP1_TO_AP0), 'direction': 'forward'}) cs.from_reference_transforms = [] return cs -# ------------------------------------------------------------------------- -# *ACESproxy* -# ------------------------------------------------------------------------- -def create_ACESproxy(aces_CTL_directory, - lut_directory, +def create_ACESproxy(aces_ctl_directory, + lut_directory, lut_resolution_1d, cleanup, name='ACESproxy'): + """ + Creates the *ACESproxy* colorspace. + + Parameters + ---------- + parameter : type + Parameter description. + + Returns + ------- + Colorspace + *ACESproxy* colorspace. + """ + cs = ColorSpace(name) cs.description = 'The %s color space' % name cs.aliases = ["acesproxy_ap1"] @@ -134,56 +189,69 @@ def create_ACESproxy(aces_CTL_directory, cs.family = 'ACES' cs.is_data = False - ctls = [os.path.join(aces_CTL_directory, + ctls = [os.path.join(aces_ctl_directory, 'ACESproxy', 'ACEScsc.ACESproxy10i_to_ACES.a1.0.0.ctl'), # This transform gets back to the *AP1* primaries. # Useful as the 1d LUT is only covering the transfer function. # The primaries switch is covered by the matrix below: - os.path.join(aces_CTL_directory, + os.path.join(aces_ctl_directory, 'ACEScg', 'ACEScsc.ACES_to_ACEScg.a1.0.0.ctl')] lut = '%s_to_aces.spi1d' % name - lut = sanitize_path(lut) + lut = sanitize(lut) generate_1d_LUT_from_CTL( os.path.join(lut_directory, lut), ctls, lut_resolution_1d, 'uint16', - 64.0, - 1.0, + 64, + 1, {}, cleanup, - aces_CTL_directory) + aces_ctl_directory) cs.to_reference_transforms = [] cs.to_reference_transforms.append({ 'type': 'lutFile', 'path': lut, 'interpolation': 'linear', - 'direction': 'forward' - }) + 'direction': 'forward'}) # *AP1* primaries to *AP0* primaries. cs.to_reference_transforms.append({ 'type': 'matrix', - 'matrix': mat44_from_mat33(ACES_AP1_to_AP0), - 'direction': 'forward' - }) + 'matrix': mat44_from_mat33(ACES_AP1_TO_AP0), + 'direction': 'forward'}) cs.from_reference_transforms = [] return cs + # ------------------------------------------------------------------------- # *ACEScg* # ------------------------------------------------------------------------- -def create_ACEScg(aces_CTL_directory, - lut_directory, +def create_ACEScg(aces_ctl_directory, + lut_directory, lut_resolution_1d, cleanup, name='ACEScg'): + """ + Creates the *ACEScg* colorspace. + + Parameters + ---------- + parameter : type + Parameter description. + + Returns + ------- + Colorspace + *ACEScg* colorspace. + """ + cs = ColorSpace(name) cs.description = 'The %s color space' % name cs.aliases = ["lin_ap1"] @@ -196,20 +264,34 @@ def create_ACEScg(aces_CTL_directory, # *AP1* primaries to *AP0* primaries. cs.to_reference_transforms.append({ 'type': 'matrix', - 'matrix': mat44_from_mat33(ACES_AP1_to_AP0), - 'direction': 'forward' - }) + 'matrix': mat44_from_mat33(ACES_AP1_TO_AP0), + 'direction': 'forward'}) cs.from_reference_transforms = [] return cs + # ------------------------------------------------------------------------- # *ADX* # ------------------------------------------------------------------------- -def create_ADX(lut_directory, +def create_ADX(lut_directory, lut_resolution_1d, - bit_depth=10, + bit_depth=10, name='ADX'): + """ + Creates the *ADX* colorspace. + + Parameters + ---------- + parameter : type + Parameter description. + + Returns + ------- + Colorspace + *ADX* colorspace. + """ + name = '%s%s' % (name, bit_depth) cs = ColorSpace(name) cs.description = '%s color space - used for film scans' % name @@ -220,26 +302,25 @@ def create_ADX(lut_directory, if bit_depth == 10: cs.bit_depth = ocio.Constants.BIT_DEPTH_UINT10 - adx_to_cdd = [1023.0 / 500.0, 0.0, 0.0, 0.0, - 0.0, 1023.0 / 500.0, 0.0, 0.0, - 0.0, 0.0, 1023.0 / 500.0, 0.0, - 0.0, 0.0, 0.0, 1.0] - offset = [-95.0 / 500.0, -95.0 / 500.0, -95.0 / 500.0, 0.0] + ADX_to_CDD = [1023 / 500, 0, 0, 0, + 0, 1023 / 500, 0, 0, + 0, 0, 1023 / 500, 0, + 0, 0, 0, 1] + offset = [-95 / 500, -95 / 500, -95 / 500, 0] elif bit_depth == 16: cs.bit_depth = ocio.Constants.BIT_DEPTH_UINT16 - adx_to_cdd = [65535.0 / 8000.0, 0.0, 0.0, 0.0, - 0.0, 65535.0 / 8000.0, 0.0, 0.0, - 0.0, 0.0, 65535.0 / 8000.0, 0.0, - 0.0, 0.0, 0.0, 1.0] - offset = [-1520.0 / 8000.0, -1520.0 / 8000.0, -1520.0 / 8000.0, - 0.0] + ADX_to_CDD = [65535 / 8000, 0, 0, 0, + 0, 65535 / 8000, 0, 0, + 0, 0, 65535 / 8000, 0, + 0, 0, 0, 1] + offset = [-1520 / 8000, -1520 / 8000, -1520 / 8000, 0] cs.to_reference_transforms = [] # Converting from *ADX* to *Channel-Dependent Density*. cs.to_reference_transforms.append({ 'type': 'matrix', - 'matrix': adx_to_cdd, + 'matrix': ADX_to_CDD, 'offset': offset, 'direction': 'forward'}) @@ -249,7 +330,7 @@ def create_ADX(lut_directory, 'matrix': [0.75573, 0.22197, 0.02230, 0, 0.05901, 0.96928, -0.02829, 0, 0.16134, 0.07406, 0.76460, 0, - 0.0, 0.0, 0.0, 1.0], + 0, 0, 0, 1], 'direction': 'forward'}) # Copied from *Alex Fry*'s *adx_cid_to_rle.py* @@ -282,13 +363,13 @@ def create_ADX(lut_directory, -1.121718645000000, -0.926545676714876] - REF_PT = ((7120.0 - 1520.0) / 8000.0 * (100.0 / 55.0) - - math.log(0.18, 10.0)) + REF_PT = ((7120 - 1520) / 8000 * (100 / 55) - + math.log(0.18, 10)) def cid_to_rle(x): if x <= 0.6: return interpolate_1D(x, LUT_1D_xp, LUT_1D_fp) - return (100.0 / 55.0) * x - REF_PT + return (100 / 55) * x - REF_PT def fit(value, from_min, from_max, to_min, to_max): if from_min == from_max: @@ -296,20 +377,20 @@ def create_ADX(lut_directory, return (value - from_min) / (from_max - from_min) * ( to_max - to_min) + to_min - NUM_SAMPLES = 2 ** 12 - RANGE = (-0.19, 3.0) + num_samples = 2 ** 12 + domain = (-0.19, 3) data = [] - for i in xrange(NUM_SAMPLES): - x = i / (NUM_SAMPLES - 1.0) - x = fit(x, 0.0, 1.0, RANGE[0], RANGE[1]) + for i in xrange(num_samples): + x = i / (num_samples - 1) + x = fit(x, 0, 1, domain[0], domain[1]) data.append(cid_to_rle(x)) lut = 'ADX_CID_to_RLE.spi1d' write_SPI_1d(os.path.join(lut_directory, lut), - RANGE[0], - RANGE[1], + domain[0], + domain[1], data, - NUM_SAMPLES, 1) + num_samples, 1) return lut @@ -335,80 +416,39 @@ def create_ADX(lut_directory, 'matrix': [0.72286, 0.12630, 0.15084, 0, 0.11923, 0.76418, 0.11659, 0, 0.01427, 0.08213, 0.90359, 0, - 0.0, 0.0, 0.0, 1.0], + 0, 0, 0, 1], 'direction': 'forward'}) cs.from_reference_transforms = [] return cs -# ------------------------------------------------------------------------- -# *Generic Log Transform* -# ------------------------------------------------------------------------- -def create_generic_log(aces_CTL_directory, - lut_directory, - lut_resolution_1d, - cleanup, - name='log', - aliases=[], - min_value=0.0, - max_value=1.0, - input_scale=1.0, - middle_grey=0.18, - min_exposure=-6.0, - max_exposure=6.5): - cs = ColorSpace(name) - cs.description = 'The %s color space' % name - cs.aliases = aliases - cs.equality_group = name - cs.family = 'Utility' - cs.is_data = False - - 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 - - lut = sanitize_path(lut) - - generate_1d_LUT_from_CTL( - os.path.join(lut_directory, lut), - ctls, - lut_resolution_1d, - 'float', - input_scale, - 1.0, - {'middleGrey': middle_grey, - 'minExposure': min_exposure, - 'maxExposure': max_exposure}, - cleanup, - aces_CTL_directory, - min_value, - max_value) - - cs.to_reference_transforms = [] - cs.to_reference_transforms.append({ - 'type': 'lutFile', - 'path': lut, - 'interpolation': 'linear', - 'direction': 'forward'}) - cs.from_reference_transforms = [] - return cs - - -# ------------------------------------------------------------------------- -# *Individual LMTs* -# ------------------------------------------------------------------------- def create_ACES_LMT(lmt_name, lmt_values, shaper_info, - aces_CTL_directory, + aces_ctl_directory, lut_directory, lut_resolution_1d=1024, lut_resolution_3d=64, cleanup=True, - aliases=[]): + aliases=None): + """ + Creates the *ACES LMT* colorspace. + + Parameters + ---------- + parameter : type + Parameter description. + + Returns + ------- + Colorspace + *ACES LMT* colorspace. + """ + + if aliases is None: + aliases = [] + cs = ColorSpace('%s' % lmt_name) cs.description = 'The ACES Look Transform: %s' % lmt_name cs.aliases = aliases @@ -427,20 +467,20 @@ def create_ACES_LMT(lmt_name, 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] + ctls = [shaper_to_ACES_CTL % aces_ctl_directory] - shaper_lut = sanitize_path(shaper_lut) + shaper_lut = sanitize(shaper_lut) generate_1d_LUT_from_CTL( os.path.join(lut_directory, shaper_lut), ctls, lut_resolution_1d, 'float', - 1.0 / shaper_input_scale, - 1.0, + 1 / shaper_input_scale, + 1, shaper_params, cleanup, - aces_CTL_directory) + aces_ctl_directory) shaper_OCIO_transform = { 'type': 'lutFile', @@ -452,53 +492,54 @@ def create_ACES_LMT(lmt_name, cs.from_reference_transforms = [] if 'transformCTL' in lmt_values: - ctls = [shaper_to_ACES_CTL % aces_CTL_directory, - os.path.join(aces_CTL_directory, + 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) - lut = sanitize_path(lut) + lut = sanitize(lut) generate_3d_LUT_from_CTL( os.path.join(lut_directory, lut), ctls, lut_resolution_3d, 'float', - 1.0 / shaper_input_scale, - 1.0, + 1 / shaper_input_scale, + 1, shaper_params, cleanup, - aces_CTL_directory) + 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'}) # Generating the inverse transform. cs.to_reference_transforms = [] if 'transformCTLInverse' in lmt_values: - ctls = [os.path.join(aces_CTL_directory, + ctls = [os.path.join(aces_ctl_directory, + # TODO: Investigate "odt_values" undeclared + # variable. odt_values['transformCTLInverse']), - shaper_from_ACES_CTL % aces_CTL_directory] + shaper_from_ACES_CTL % aces_ctl_directory] lut = 'Inverse.%s.%s.spi3d' % (odt_name, shaper_name) - lut = sanitize_path(lut) + lut = sanitize(lut) generate_3d_LUT_from_CTL( os.path.join(lut_directory, lut), ctls, lut_resolution_3d, 'half', - 1.0, + 1, shaper_input_scale, shaper_params, cleanup, - aces_CTL_directory) + aces_ctl_directory) cs.to_reference_transforms.append({ 'type': 'lutFile', @@ -512,89 +553,33 @@ def create_ACES_LMT(lmt_name, return cs -# ------------------------------------------------------------------------- -# *LMTs* -# ------------------------------------------------------------------------- -def create_lmts(aces_CTL_directory, - lut_directory, - lut_resolution_1d, - lut_resolution_3d, - lmt_info, - shaper_name, - cleanup): - - colorspaces = [] - - # ------------------------------------------------------------------------- - # *LMT Shaper* - # ------------------------------------------------------------------------- - lmt_lut_resolution_1d = max(4096, lut_resolution_1d) - lmt_lut_resolution_3d = max(65, lut_resolution_3d) - - # Defining the *Log 2* shaper. - lmt_shaper_name = 'LMT Shaper' - lmt_shaper_name_aliases = ['crv_lmtshaper'] - lmt_params = { - 'middleGrey': 0.18, - 'minExposure': -10.0, - 'maxExposure': 6.5} - - lmt_shaper = create_generic_log(aces_CTL_directory, - lut_directory, - lmt_lut_resolution_1d, - cleanup, - name=lmt_shaper_name, - middle_grey=lmt_params['middleGrey'], - min_exposure=lmt_params['minExposure'], - max_exposure=lmt_params['maxExposure'], - aliases=lmt_shaper_name_aliases) - colorspaces.append(lmt_shaper) - - shaper_input_scale_generic_log2 = 1.0 - - # *Log 2* shaper name and *CTL* transforms bundled up. - lmt_shaper_data = [ - lmt_shaper_name, - 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] - - sorted_LMTs = sorted(lmt_info.iteritems(), key=lambda x: x[1]) - print(sorted_LMTs) - for lmt in sorted_LMTs: - (lmt_name, lmt_values) = lmt - lmt_aliases = ["look_%s" % compact(lmt_values['transformUserName'])] - cs = create_ACES_LMT( - lmt_values['transformUserName'], - lmt_values, - lmt_shaper_data, - aces_CTL_directory, - lut_directory, - lmt_lut_resolution_1d, - lmt_lut_resolution_3d, - cleanup, - lmt_aliases) - colorspaces.append(cs) - - return colorspaces -# ------------------------------------------------------------------------- -# *ACES RRT* with supplied *ODT*. -# ------------------------------------------------------------------------- def create_ACES_RRT_plus_ODT(odt_name, odt_values, shaper_info, - aces_CTL_directory, + aces_ctl_directory, lut_directory, lut_resolution_1d=1024, lut_resolution_3d=64, cleanup=True, - aliases=[]): + aliases=None): + """ + Object description. + + Parameters + ---------- + parameter : type + Parameter description. + + Returns + ------- + type + Return value description. + """ + + if aliases is None: + aliases = [] + cs = ColorSpace('%s' % odt_name) cs.description = '%s - %s Output Transform' % ( odt_values['transformUserNamePrefix'], odt_name) @@ -619,20 +604,20 @@ def create_ACES_RRT_plus_ODT(odt_name, 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] + ctls = [shaper_to_ACES_CTL % aces_ctl_directory] - shaper_lut = sanitize_path(shaper_lut) + shaper_lut = sanitize(shaper_lut) generate_1d_LUT_from_CTL( os.path.join(lut_directory, shaper_lut), ctls, lut_resolution_1d, 'float', - 1.0 / shaper_input_scale, - 1.0, + 1 / shaper_input_scale, + 1, shaper_params, cleanup, - aces_CTL_directory) + aces_ctl_directory) shaper_OCIO_transform = { 'type': 'lutFile', @@ -657,16 +642,16 @@ def create_ACES_RRT_plus_ODT(odt_name, 'direction': 'forward'}) elif 'transformCTL' in odt_values: ctls = [ - shaper_to_ACES_CTL % aces_CTL_directory, - os.path.join(aces_CTL_directory, + shaper_to_ACES_CTL % aces_ctl_directory, + os.path.join(aces_ctl_directory, 'rrt', 'RRT.a1.0.0.ctl'), - os.path.join(aces_CTL_directory, + 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) + lut = sanitize(lut) generate_3d_LUT_from_CTL( os.path.join(lut_directory, lut), @@ -674,11 +659,11 @@ def create_ACES_RRT_plus_ODT(odt_name, ctls, lut_resolution_3d, 'float', - 1.0 / shaper_input_scale, - 1.0, + 1 / shaper_input_scale, + 1, shaper_params, cleanup, - aces_CTL_directory) + aces_ctl_directory) cs.from_reference_transforms.append(shaper_OCIO_transform) cs.from_reference_transforms.append({ @@ -706,16 +691,16 @@ def create_ACES_RRT_plus_ODT(odt_name, shaper_inverse['direction'] = 'forward' cs.to_reference_transforms.append(shaper_inverse) elif 'transformCTLInverse' in odt_values: - ctls = [os.path.join(aces_CTL_directory, + ctls = [os.path.join(aces_ctl_directory, 'odt', odt_values['transformCTLInverse']), - os.path.join(aces_CTL_directory, + os.path.join(aces_ctl_directory, 'rrt', 'InvRRT.a1.0.0.ctl'), - shaper_from_ACES_CTL % aces_CTL_directory] + shaper_from_ACES_CTL % aces_ctl_directory] lut = 'InvRRT.a1.0.0.%s.%s.spi3d' % (odt_name, shaper_name) - lut = sanitize_path(lut) + lut = sanitize(lut) generate_3d_LUT_from_CTL( os.path.join(lut_directory, lut), @@ -723,11 +708,11 @@ def create_ACES_RRT_plus_ODT(odt_name, ctls, lut_resolution_3d, 'half', - 1.0, + 1, shaper_input_scale, shaper_params, cleanup, - aces_CTL_directory) + aces_ctl_directory) cs.to_reference_transforms.append({ 'type': 'lutFile', @@ -741,11 +726,158 @@ def create_ACES_RRT_plus_ODT(odt_name, return cs -# ------------------------------------------------------------------------- -# *ODTs* -# ------------------------------------------------------------------------- -def create_odts(aces_CTL_directory, - lut_directory, + +def create_generic_log(aces_ctl_directory, + lut_directory, + lut_resolution_1d, + cleanup, + name='log', + aliases=[], + min_value=0, + max_value=1, + input_scale=1, + middle_grey=0.18, + min_exposure=-6, + max_exposure=6.5): + """ + Creates the *Generic Log* colorspace. + + Parameters + ---------- + parameter : type + Parameter description. + + Returns + ------- + Colorspace + *Generic Log* colorspace. + """ + + cs = ColorSpace(name) + cs.description = 'The %s color space' % name + cs.aliases = aliases + cs.equality_group = name + cs.family = 'Utility' + cs.is_data = False + + 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 + + lut = sanitize(lut) + + generate_1d_LUT_from_CTL( + os.path.join(lut_directory, lut), + ctls, + lut_resolution_1d, + 'float', + input_scale, + 1, + {'middleGrey': middle_grey, + 'minExposure': min_exposure, + 'maxExposure': max_exposure}, + cleanup, + aces_ctl_directory, + min_value, + max_value) + + cs.to_reference_transforms = [] + cs.to_reference_transforms.append({ + 'type': 'lutFile', + 'path': lut, + 'interpolation': 'linear', + 'direction': 'forward'}) + + cs.from_reference_transforms = [] + return cs + + +def create_LMTs(aces_ctl_directory, + lut_directory, + lut_resolution_1d, + lut_resolution_3d, + lmt_info, + shaper_name, + cleanup): + """ + Object description. + + Parameters + ---------- + parameter : type + Parameter description. + + Returns + ------- + type + Return value description. + """ + + colorspaces = [] + + # ------------------------------------------------------------------------- + # *LMT Shaper* + # ------------------------------------------------------------------------- + lmt_lut_resolution_1d = max(4096, lut_resolution_1d) + lmt_lut_resolution_3d = max(65, lut_resolution_3d) + + # Defining the *Log 2* shaper. + lmt_shaper_name = 'LMT Shaper' + lmt_shaper_name_aliases = ['crv_lmtshaper'] + lmt_params = { + 'middleGrey': 0.18, + 'minExposure': -10, + 'maxExposure': 6.5} + + lmt_shaper = create_generic_log(aces_ctl_directory, + lut_directory, + lmt_lut_resolution_1d, + cleanup, + name=lmt_shaper_name, + middle_grey=lmt_params['middleGrey'], + min_exposure=lmt_params['minExposure'], + max_exposure=lmt_params['maxExposure'], + aliases=lmt_shaper_name_aliases) + colorspaces.append(lmt_shaper) + + shaper_input_scale_generic_log2 = 1 + + # *Log 2* shaper name and *CTL* transforms bundled up. + lmt_shaper_data = [ + lmt_shaper_name, + 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] + + sorted_LMTs = sorted(lmt_info.iteritems(), key=lambda x: x[1]) + print(sorted_LMTs) + for lmt in sorted_LMTs: + lmt_name, lmt_values = lmt + lmt_aliases = ["look_%s" % compact(lmt_values['transformUserName'])] + cs = create_ACES_LMT( + lmt_values['transformUserName'], + lmt_values, + lmt_shaper_data, + aces_ctl_directory, + lut_directory, + lmt_lut_resolution_1d, + lmt_lut_resolution_3d, + cleanup, + lmt_aliases) + colorspaces.append(cs) + + return colorspaces + + +def create_ODTs(aces_ctl_directory, + lut_directory, lut_resolution_1d, lut_resolution_3d, odt_info, @@ -753,6 +885,19 @@ def create_odts(aces_CTL_directory, cleanup, linear_display_space, log_display_space): + """ + Object description. + + Parameters + ---------- + parameter : type + Parameter description. + + Returns + ------- + type + Return value description. + """ colorspaces = [] displays = {} @@ -767,11 +912,11 @@ def create_odts(aces_CTL_directory, log2_shaper_name_aliases = ["crv_%s" % compact(shaper_name)] log2_params = { 'middleGrey': 0.18, - 'minExposure': -6.0, + 'minExposure': -6, 'maxExposure': 6.5} log2_shaper = create_generic_log( - aces_CTL_directory, + aces_ctl_directory, lut_directory, lut_resolution_1d, cleanup, @@ -782,7 +927,7 @@ def create_odts(aces_CTL_directory, aliases=log2_shaper_name_aliases) colorspaces.append(log2_shaper) - shaper_input_scale_generic_log2 = 1.0 + shaper_input_scale_generic_log2 = 1 # *Log 2* shaper name and *CTL* transforms bundled up. log2_shaper_data = [ @@ -801,8 +946,8 @@ def create_odts(aces_CTL_directory, # Shaper that also includes the AP1 primaries. # Needed for some LUT baking steps. log2_shaper_api1_name_aliases = ["%s_ap1" % compact(shaper_name)] - log2_shaper_AP1 = create_generic_log( - aces_CTL_directory, + log2_shaper_ap1 = create_generic_log( + aces_ctl_directory, lut_directory, lut_resolution_1d, cleanup, @@ -811,15 +956,15 @@ def create_odts(aces_CTL_directory, min_exposure=log2_params['minExposure'], max_exposure=log2_params['maxExposure'], aliases=log2_shaper_api1_name_aliases) - log2_shaper_AP1.name = '%s - AP1' % log2_shaper_AP1.name + log2_shaper_ap1.name = '%s - AP1' % log2_shaper_ap1.name # *AP1* primaries to *AP0* primaries. - log2_shaper_AP1.to_reference_transforms.append({ + log2_shaper_ap1.to_reference_transforms.append({ 'type': 'matrix', - 'matrix': mat44_from_mat33(ACES_AP1_to_AP0), + 'matrix': mat44_from_mat33(ACES_AP1_TO_AP0), 'direction': 'forward' }) - colorspaces.append(log2_shaper_AP1) + colorspaces.append(log2_shaper_ap1) rrt_shaper = log2_shaper_data @@ -845,7 +990,7 @@ def create_odts(aces_CTL_directory, odt_name_legal, odt_legal, rrt_shaper, - aces_CTL_directory, + aces_ctl_directory, lut_directory, lut_resolution_1d, lut_resolution_3d, @@ -874,7 +1019,7 @@ def create_odts(aces_CTL_directory, odt_name_full, odt_full, rrt_shaper, - aces_CTL_directory, + aces_ctl_directory, lut_directory, lut_resolution_1d, lut_resolution_3d, @@ -889,20 +1034,6 @@ def create_odts(aces_CTL_directory, return (colorspaces, displays) -def create_aces(): - # Defining the reference colorspace. - ACES = ColorSpace('ACES2065-1') - ACES.description = ( - 'The Academy Color Encoding System reference color space') - ACES.equality_group = '' - ACES.aliases = ["lin_ap0", "aces"] - ACES.family = 'ACES' - ACES.is_data = False - ACES.allocation_type = ocio.Constants.ALLOCATION_LG2 - ACES.allocation_vars = [-15, 6] - - return ACES - def get_transform_info(ctl_transform): """ @@ -933,13 +1064,15 @@ def get_transform_info(ctl_transform): transform_full_legal_switch = False for line in lines: if line.strip() == "input varying int legalRange = 0": - #print( "%s has legal range flag" % transform_user_name) + # print( "%s has legal range flag" % transform_user_name) transform_full_legal_switch = True break - return (transform_id, transform_user_name, transform_user_name_prefix, transform_full_legal_switch) + return (transform_id, transform_user_name, transform_user_name_prefix, + transform_full_legal_switch) + -def get_ODT_info(aces_CTL_directory): +def get_ODTs_info(aces_ctl_directory): """ Object description. @@ -958,7 +1091,7 @@ 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') + 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: @@ -988,7 +1121,7 @@ def get_ODT_info(aces_CTL_directory): transform_user_name, transform_user_name_prefix, transform_full_legal_switch) = get_transform_info( - os.path.join(aces_CTL_directory, 'odt', odt_dir, transform_CTL)) + os.path.join(aces_ctl_directory, 'odt', odt_dir, transform_CTL)) # Finding inverse. transform_CTL_inverse = 'InvODT.%s.ctl' % odt_name @@ -1006,7 +1139,8 @@ def get_ODT_info(aces_CTL_directory): odts[odt_name]['transformID'] = transform_ID odts[odt_name]['transformUserNamePrefix'] = transform_user_name_prefix odts[odt_name]['transformUserName'] = transform_user_name - odts[odt_name]['transformHasFullLegalSwitch'] = transform_full_legal_switch + odts[odt_name][ + 'transformHasFullLegalSwitch'] = transform_full_legal_switch forward_CTL = odts[odt_name]['transformCTL'] @@ -1014,7 +1148,8 @@ def get_ODT_info(aces_CTL_directory): 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('\tHas Full / Legal Switch : %s' % transform_full_legal_switch) + print( + '\tHas Full / Legal Switch : %s' % transform_full_legal_switch) print('\tForward ctl : %s' % forward_CTL) if 'transformCTLInverse' in odts[odt_name]: inverse_CTL = odts[odt_name]['transformCTLInverse'] @@ -1027,7 +1162,7 @@ def get_ODT_info(aces_CTL_directory): return odts -def get_LMT_info(aces_CTL_directory): +def get_LMTs_info(aces_ctl_directory): """ Object description. @@ -1047,7 +1182,7 @@ 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: @@ -1078,7 +1213,7 @@ def get_LMT_info(aces_CTL_directory): transform_user_name, transform_user_name_prefix, transform_full_legal_switch) = get_transform_info( - os.path.join(aces_CTL_directory, lmt_dir, transform_CTL)) + os.path.join(aces_ctl_directory, lmt_dir, transform_CTL)) # Finding inverse. transform_CTL_inverse = 'InvLMT.%s.ctl' % lmt_name @@ -1113,9 +1248,10 @@ def get_LMT_info(aces_CTL_directory): return lmts -def create_colorspaces(aces_CTL_directory, - lut_directory, - lut_resolution_1d, + +def create_colorspaces(aces_ctl_directory, + lut_directory, + lut_resolution_1d, lut_resolution_3d, lmt_info, odt_info, @@ -1137,15 +1273,18 @@ def create_colorspaces(aces_CTL_directory, colorspaces = [] - ACES = create_aces() + ACES = create_ACES() - ACEScc = create_ACEScc(aces_CTL_directory, lut_directory, lut_resolution_1d, cleanup) + ACEScc = create_ACEScc(aces_ctl_directory, lut_directory, + lut_resolution_1d, cleanup) colorspaces.append(ACEScc) - ACESproxy = create_ACESproxy(aces_CTL_directory, lut_directory, lut_resolution_1d, cleanup) + ACESproxy = create_ACESproxy(aces_ctl_directory, lut_directory, + lut_resolution_1d, cleanup) colorspaces.append(ACESproxy) - ACEScg = create_ACEScg(aces_CTL_directory, lut_directory, lut_resolution_1d, cleanup) + ACEScg = create_ACEScg(aces_ctl_directory, lut_directory, + lut_resolution_1d, cleanup) colorspaces.append(ACEScg) ADX10 = create_ADX(lut_directory, lut_resolution_1d, bit_depth=10) @@ -1154,24 +1293,24 @@ def create_colorspaces(aces_CTL_directory, ADX16 = create_ADX(lut_directory, lut_resolution_1d, bit_depth=16) colorspaces.append(ADX16) - lmts = create_lmts(aces_CTL_directory, - lut_directory, - lut_resolution_1d, + lmts = create_LMTs(aces_ctl_directory, + lut_directory, + lut_resolution_1d, lut_resolution_3d, lmt_info, shaper_name, cleanup) colorspaces.extend(lmts) - (odts, displays) = create_odts(aces_CTL_directory, - lut_directory, - lut_resolution_1d, - lut_resolution_3d, - odt_info, - shaper_name, - cleanup, - ACES, - ACEScc) + odts, displays = create_ODTs(aces_ctl_directory, + lut_directory, + lut_resolution_1d, + lut_resolution_3d, + odt_info, + shaper_name, + cleanup, + ACES, + ACEScc) colorspaces.extend(odts) - return (ACES, colorspaces, displays, ACEScc) + return ACES, colorspaces, displays, ACEScc 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 72badd8..7c43a68 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 @@ -5,9 +5,9 @@ Defines objects creating the *ACES* configuration. """ -import math +from __future__ import division + import os -import shutil import sys import PyOpenColorIO as ocio @@ -19,12 +19,7 @@ import aces_ocio.create_red_colorspaces as red import aces_ocio.create_sony_colorspaces as sony import aces_ocio.create_general_colorspaces as general -from aces_ocio.generate_lut import ( - generate_1d_LUT_from_CTL, - generate_3d_LUT_from_CTL, - write_SPI_1d) from aces_ocio.process import Process -from aces_ocio.utilities import ColorSpace, mat44_from_mat33, sanitize_path, compact __author__ = 'ACES Developers' __copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers' @@ -38,6 +33,7 @@ __all__ = ['ACES_OCIO_CTL_DIRECTORY_ENVIRON', 'set_config_default_roles', 'write_config', 'generate_OCIO_transform', + 'add_colorspace_alias', 'create_config', 'generate_LUTs', 'generate_baked_LUTs', @@ -158,12 +154,11 @@ def generate_OCIO_transform(transforms): interpolation_options = { 'linear': ocio.Constants.INTERP_LINEAR, 'nearest': ocio.Constants.INTERP_NEAREST, - 'tetrahedral': ocio.Constants.INTERP_TETRAHEDRAL - } + 'tetrahedral': ocio.Constants.INTERP_TETRAHEDRAL} + direction_options = { 'forward': ocio.Constants.TRANSFORM_DIR_FORWARD, - 'inverse': ocio.Constants.TRANSFORM_DIR_INVERSE - } + 'inverse': ocio.Constants.TRANSFORM_DIR_INVERSE} ocio_transforms = [] @@ -177,7 +172,7 @@ def generate_OCIO_transform(transforms): transform['interpolation']], direction=direction_options[transform['direction']]) ocio_transforms.append(ocio_transform) - + # matrix transform elif transform['type'] == 'matrix': ocio_transform = ocio.MatrixTransform() @@ -210,11 +205,12 @@ def generate_OCIO_transform(transforms): # color space transform elif transform['type'] == 'colorspace': - ocio_transform = ocio.ColorSpaceTransform( src=transform['src'], - dst=transform['dst'], - direction=direction_options['forward'] ) + ocio_transform = ocio.ColorSpaceTransform(src=transform['src'], + dst=transform['dst'], + direction= + direction_options[ + 'forward']) ocio_transforms.append(ocio_transform) - # unknown type else: print("Ignoring unknown transform type : %s" % transform['type']) @@ -229,7 +225,11 @@ def generate_OCIO_transform(transforms): return transform -def add_colorspace_alias(config, reference_colorspace, colorspace, colorspace_alias_names): + +def add_colorspace_alias(config, + reference_colorspace, + colorspace, + colorspace_alias_names): """ Object description. @@ -248,10 +248,10 @@ def add_colorspace_alias(config, reference_colorspace, colorspace, colorspace_al if alias_name == colorspace.name.lower(): return - print( "Adding alias colorspace space %s, alias to %s" % ( + print('Adding alias colorspace space %s, alias to %s' % ( alias_name, colorspace.name)) - compact_family_name = "Aliases" + compact_family_name = 'Aliases' ocio_colorspace_alias = ocio.ColorSpace( name=alias_name, @@ -263,26 +263,24 @@ def add_colorspace_alias(config, reference_colorspace, colorspace, colorspace_al allocation=colorspace.allocation_type, allocationVars=colorspace.allocation_vars) - if colorspace.to_reference_transforms != []: - print("Generating To-Reference transforms") - ocio_transform = generate_OCIO_transform([{ - 'type': 'colorspace', - 'src': colorspace.name, - 'dst': reference_colorspace.name, - 'direction': 'forward' - }]) + if not colorspace.to_reference_transforms: + print('Generating To-Reference transforms') + ocio_transform = generate_OCIO_transform( + [{'type': 'colorspace', + 'src': colorspace.name, + 'dst': reference_colorspace.name, + 'direction': 'forward'}]) ocio_colorspace_alias.setTransform( ocio_transform, ocio.Constants.COLORSPACE_DIR_TO_REFERENCE) - if colorspace.from_reference_transforms != []: - print("Generating From-Reference transforms") - ocio_transform = generate_OCIO_transform([{ - 'type': 'colorspace', - 'src': reference_colorspace.name, - 'dst': colorspace.name, - 'direction': 'forward' - }]) + if not colorspace.from_reference_transforms: + print('Generating From-Reference transforms') + ocio_transform = generate_OCIO_transform( + [{'type': 'colorspace', + 'src': reference_colorspace.name, + 'dst': colorspace.name, + 'direction': 'forward'}]) ocio_colorspace_alias.setTransform( ocio_transform, ocio.Constants.COLORSPACE_DIR_FROM_REFERENCE) @@ -331,7 +329,7 @@ def create_config(config_data, nuke=False): # Add alias if reference_data.aliases != []: add_colorspace_alias(config, reference_data, - reference_data, reference_data.aliases) + reference_data, reference_data.aliases) print("") @@ -371,8 +369,8 @@ def create_config(config_data, nuke=False): # Add alias to normal colorspace, using compact name # if colorspace.aliases != []: - add_colorspace_alias(config, reference_data, - colorspace, colorspace.aliases) + add_colorspace_alias(config, reference_data, + colorspace, colorspace.aliases) print('') @@ -428,10 +426,11 @@ def create_config(config_data, nuke=False): return config + def generate_LUTs(odt_info, lmt_info, shaper_name, - aces_CTL_directory, + aces_ctl_directory, lut_directory, lut_resolution_1d=4096, lut_resolution_3d=64, @@ -464,10 +463,10 @@ def generate_LUTs(odt_info, # *ACES* colorspaces (aces_reference, - aces_colorspaces, + aces_colorspaces, aces_displays, - aces_log_display_space) = aces.create_colorspaces(aces_CTL_directory, - lut_directory, + aces_log_display_space) = aces.create_colorspaces(aces_ctl_directory, + lut_directory, lut_resolution_1d, lut_resolution_3d, lmt_info, @@ -503,7 +502,7 @@ def generate_LUTs(odt_info, config_data['colorSpaces'].append(cs) # *RED* colorspaces to *ACES*. - red_colorspaces = red.create_colorspaces(lut_directory, + red_colorspaces = red.create_colorspaces(lut_directory, lut_resolution_1d) for cs in red_colorspaces: config_data['colorSpaces'].append(cs) @@ -550,22 +549,22 @@ def generate_baked_LUTs(odt_info, # Create two entries for ODTs that have full and legal range support odt_info_C = dict(odt_info) - for odt_CTL_name, odt_values in odt_info.iteritems(): + for odt_ctl_name, odt_values in odt_info.iteritems(): if odt_values['transformHasFullLegalSwitch']: 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_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_info_C['%s - Full' % odt_ctl_name] = odt_values_full - del (odt_info_C[odt_CTL_name]) + del (odt_info_C[odt_ctl_name]) # Generate appropriate LUTs for each ODT - for odt_CTL_name, odt_values in odt_info_C.iteritems(): + for odt_ctl_name, odt_values in odt_info_C.iteritems(): odt_prefix = odt_values['transformUserNamePrefix'] odt_name = odt_values['transformUserName'] @@ -588,10 +587,10 @@ def generate_baked_LUTs(odt_info, 'photoshop', '%s for %s.icc' % (odt_name, input_space))] - bake_LUT = Process(description='bake a LUT', + bake_lut = Process(description='bake a LUT', cmd='ociobakelut', args=args) - bake_LUT.execute() + bake_lut.execute() # *Flame*, *Lustre* for input_space in ['ACEScc', 'ACESproxy']: @@ -612,10 +611,10 @@ def generate_baked_LUTs(odt_info, baked_directory, 'flame', '%s for %s Flame.3dl' % (odt_name, input_space))] - bake_LUT = Process(description='bake a LUT', + bake_lut = Process(description='bake a LUT', cmd='ociobakelut', args=(args + fargs)) - bake_LUT.execute() + bake_lut.execute() largs = ['--format', 'lustre', @@ -623,10 +622,10 @@ def generate_baked_LUTs(odt_info, baked_directory, 'lustre', '%s for %s Lustre.3dl' % (odt_name, input_space))] - bake_LUT = Process(description='bake a LUT', + bake_lut = Process(description='bake a LUT', cmd='ociobakelut', args=(args + largs)) - bake_LUT.execute() + bake_lut.execute() # *Maya*, *Houdini* for input_space in ['ACEScg', 'ACES2065-1']: @@ -652,10 +651,10 @@ def generate_baked_LUTs(odt_info, baked_directory, 'maya', '%s for %s Maya.csp' % (odt_name, input_space))] - bake_LUT = Process(description='bake a LUT', + bake_lut = Process(description='bake a LUT', cmd='ociobakelut', args=(args + margs)) - bake_LUT.execute() + bake_lut.execute() hargs = ['--format', 'houdini', @@ -663,10 +662,10 @@ def generate_baked_LUTs(odt_info, baked_directory, 'houdini', '%s for %s Houdini.lut' % (odt_name, input_space))] - bake_LUT = Process(description='bake a LUT', + bake_lut = Process(description='bake a LUT', cmd='ociobakelut', args=(args + hargs)) - bake_LUT.execute() + bake_lut.execute() def create_config_dir(config_directory, bake_secondary_LUTs): @@ -699,7 +698,8 @@ def create_config_dir(config_directory, bake_secondary_LUTs): return lut_directory -def create_ACES_config(aces_CTL_directory, + +def create_ACES_config(aces_ctl_directory, config_directory, lut_resolution_1d=4096, lut_resolution_3d=64, @@ -721,14 +721,14 @@ def create_ACES_config(aces_CTL_directory, lut_directory = create_config_dir(config_directory, bake_secondary_LUTs) - odt_info = aces.get_ODT_info(aces_CTL_directory) - lmt_info = aces.get_LMT_info(aces_CTL_directory) + odt_info = aces.get_ODTs_info(aces_ctl_directory) + lmt_info = aces.get_LMTs_info(aces_ctl_directory) shaper_name = 'Output Shaper' config_data = generate_LUTs(odt_info, lmt_info, shaper_name, - aces_CTL_directory, + aces_ctl_directory, lut_directory, lut_resolution_1d, lut_resolution_3d, @@ -792,11 +792,11 @@ def main(): options, arguments = p.parse_args() - aces_CTL_directory = options.acesCTLDir + 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 + bake_secondary_luts = not options.dontBakeSecondaryLUTs cleanup_temp_images = not options.keepTempImages # TODO: Investigate the following statements. @@ -809,7 +809,7 @@ def main(): print('command line : \n%s\n' % ' '.join(sys.argv)) - assert aces_CTL_directory is not None, ( + 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)) @@ -819,11 +819,11 @@ def main(): 'directory specified'.format( ACES_OCIO_CONFIGURATION_DIRECTORY_ENVIRON)) - return create_ACES_config(aces_CTL_directory, + return create_ACES_config(aces_ctl_directory, config_directory, lut_resolution_1d, lut_resolution_3d, - bake_secondary_LUTs, + bake_secondary_luts, cleanup_temp_images) 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 e05e37d..13533d5 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 @@ -5,12 +5,14 @@ Implements support for *ARRI* colorspaces conversions and transfer functions. """ +from __future__ import division + import array import math import os import aces_ocio.generate_lut as genlut -from aces_ocio.utilities import ColorSpace, mat44_from_mat33, sanitize_path, compact +from aces_ocio.utilities import ColorSpace, mat44_from_mat33, sanitize __author__ = 'ACES Developers' @@ -63,7 +65,7 @@ def create_log_c(gamut, # Globals. IDT_maker_version = '0.08' - nominal_EI = 400.0 + nominal_EI = 400 black_signal = 0.003907 mid_gray_signal = 0.01 encoding_gain = 0.256598 @@ -74,8 +76,8 @@ def create_log_c(gamut, 0.89 - 1) / 3 + 1) * encoding_gain def log_c_inverse_parameters_for_EI(EI): - cut = 1.0 / 9.0 - slope = 1.0 / (cut * math.log(10)) + cut = 1 / 9 + slope = 1 / (cut * math.log(10)) offset = math.log10(cut) - slope * cut gain = EI / nominal_EI gray = mid_gray_signal / gain @@ -83,10 +85,10 @@ def create_log_c(gamut, 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 + nz = ((95 / 1023 - enc_offset) / enc_gain - offset) / slope enc_offset = encoding_offset - math.log10(1 + nz) * enc_gain - a = 1.0 / gray + a = 1 / gray b = nz - black_signal / gray e = slope * a * enc_gain f = enc_gain * (slope * b + offset) + enc_offset @@ -111,10 +113,10 @@ def create_log_c(gamut, p = log_c_inverse_parameters_for_EI(exposure_index) breakpoint = p['e'] * p['cut'] + p['f'] if code_value > breakpoint: - linear = ((pow(10, (code_value / 1023.0 - p['d']) / p['c']) - + linear = ((pow(10, (code_value / 1023 - p['d']) / p['c']) - p['b']) / p['a']) else: - linear = (code_value / 1023.0 - p['f']) / p['e'] + linear = (code_value / 1023 - p['f']) / p['e'] return linear cs.to_reference_transforms = [] @@ -122,18 +124,18 @@ def create_log_c(gamut, 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), + data[c] = log_c_to_linear(1023 * c / (lut_resolution_1d - 1), int(exposure_index)) lut = '%s_to_linear.spi1d' % ( '%s_%s' % (transfer_function, exposure_index)) - lut = sanitize_path(lut) + lut = sanitize(lut) genlut.write_SPI_1d( os.path.join(lut_directory, lut), - 0.0, - 1.0, + 0, + 1, data, lut_resolution_1d, 1) @@ -178,8 +180,8 @@ def create_colorspaces(lut_directory, lut_resolution_1d): 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] + # EIs = [160, 200, 250, 320, 400, 500, 640, 800, + # 1000, 1280, 1600, 2000, 2560, 3200] EIs = [160, 200, 250, 320, 400, 500, 640, 800, 1000, 1280, 1600, 2000, 2560, 3200] default_EI = 800 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 ed39c9d..f63c1bb 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 @@ -5,6 +5,8 @@ Implements support for *Canon* colorspaces conversions and transfer functions. """ +from __future__ import division + import array import os @@ -57,17 +59,17 @@ def create_c_log(gamut, cs.family = 'Canon' cs.is_data = False - def legal_to_full(codeValue): - return (codeValue - 64.0) / (940.0 - 64.0) + def legal_to_full(code_value): + return (code_value - 64) / (940 - 64) - def c_log_to_linear(codeValue): + def c_log_to_linear(code_value): # log = fullToLegal(c1 * log10(c2*linear + 1) + c3) # linear = (pow(10, (legalToFul(log) - c3)/c1) - 1)/c2 c1 = 0.529136 c2 = 10.1596 c3 = 0.0730597 - linear = (pow(10.0, (legal_to_full(codeValue) - c3) / c1) - 1.0) / c2 + linear = (pow(10, (legal_to_full(code_value) - c3) / c1) - 1) / c2 linear *= 0.9 return linear @@ -77,13 +79,13 @@ def create_c_log(gamut, 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)) + data[c] = c_log_to_linear(1023 * c / (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, + 0, + 1, data, lut_resolution_1d, 1) @@ -97,50 +99,50 @@ def create_c_log(gamut, if gamut == 'Rec. 709 Daylight': cs.to_reference_transforms.append({ 'type': 'matrix', - 'matrix': [0.561538969, 0.402060105, 0.036400926, 0.0, - 0.092739623, 0.924121198, -0.016860821, 0.0, - 0.084812961, 0.006373835, 0.908813204, 0.0, - 0, 0, 0, 1.0], + 'matrix': [0.561538969, 0.402060105, 0.036400926, 0, + 0.092739623, 0.924121198, -0.016860821, 0, + 0.084812961, 0.006373835, 0.908813204, 0, + 0, 0, 0, 1], 'direction': 'forward'}) elif gamut == 'Rec. 709 Tungsten': cs.to_reference_transforms.append({ 'type': 'matrix', - 'matrix': [0.566996399, 0.365079418, 0.067924183, 0.0, - 0.070901044, 0.880331008, 0.048767948, 0.0, - 0.073013542, -0.066540862, 0.99352732, 0.0, - 0, 0, 0, 1.0], + 'matrix': [0.566996399, 0.365079418, 0.067924183, 0, + 0.070901044, 0.880331008, 0.048767948, 0, + 0.073013542, -0.066540862, 0.99352732, 0, + 0, 0, 0, 1], 'direction': 'forward'}) elif gamut == 'DCI-P3 Daylight': cs.to_reference_transforms.append({ 'type': 'matrix', - 'matrix': [0.607160575, 0.299507286, 0.093332140, 0.0, - 0.004968120, 1.050982224, -0.055950343, 0.0, - -0.007839939, 0.000809127, 1.007030813, 0.0, - 0, 0, 0, 1.0], + 'matrix': [0.607160575, 0.299507286, 0.093332140, 0, + 0.004968120, 1.050982224, -0.055950343, 0, + -0.007839939, 0.000809127, 1.007030813, 0, + 0, 0, 0, 1], 'direction': 'forward'}) elif gamut == 'DCI-P3 Tungsten': cs.to_reference_transforms.append({ 'type': 'matrix', - 'matrix': [0.650279125, 0.253880169, 0.095840706, 0.0, - -0.026137986, 1.017900530, 0.008237456, 0.0, - 0.007757558, -0.063081669, 1.055324110, 0.0, - 0, 0, 0, 1.0], + 'matrix': [0.650279125, 0.253880169, 0.095840706, 0, + -0.026137986, 1.017900530, 0.008237456, 0, + 0.007757558, -0.063081669, 1.055324110, 0, + 0, 0, 0, 1], 'direction': 'forward'}) elif gamut == 'Cinema Gamut Daylight': cs.to_reference_transforms.append({ 'type': 'matrix', - 'matrix': [0.763064455, 0.149021161, 0.087914384, 0.0, - 0.003657457, 1.10696038, -0.110617837, 0.0, - -0.009407794, -0.218383305, 1.227791099, 0.0, - 0, 0, 0, 1.0], + 'matrix': [0.763064455, 0.149021161, 0.087914384, 0, + 0.003657457, 1.10696038, -0.110617837, 0, + -0.009407794, -0.218383305, 1.227791099, 0, + 0, 0, 0, 1], 'direction': 'forward'}) elif gamut == 'Cinema Gamut Tungsten': cs.to_reference_transforms.append({ 'type': 'matrix', - 'matrix': [0.817416293, 0.090755698, 0.091828009, 0.0, - -0.035361374, 1.065690585, -0.030329211, 0.0, - 0.010390366, -0.299271107, 1.288880741, 0.0, - 0, 0, 0, 1.0], + 'matrix': [0.817416293, 0.090755698, 0.091828009, 0, + -0.035361374, 1.065690585, -0.030329211, 0, + 0.010390366, -0.299271107, 1.288880741, 0, + 0, 0, 0, 1], 'direction': 'forward'}) cs.from_reference_transforms = [] diff --git a/aces_1.0.0/python/aces_ocio/create_general_colorspaces.py b/aces_1.0.0/python/aces_ocio/create_general_colorspaces.py index 868a367..410f844 100644 --- a/aces_1.0.0/python/aces_ocio/create_general_colorspaces.py +++ b/aces_1.0.0/python/aces_ocio/create_general_colorspaces.py @@ -5,13 +5,10 @@ Implements support for general colorspaces conversions and transfer functions. """ -import array -import math -import os +from __future__ import division -import aces_ocio.generate_lut as genlut import aces_ocio.create_aces_colorspaces as aces -from aces_ocio.utilities import ColorSpace, mat44_from_mat33, sanitize_path, compact +from aces_ocio.utilities import ColorSpace, mat44_from_mat33 __author__ = 'ACES Developers' @@ -24,18 +21,30 @@ __status__ = 'Production' __all__ = ['create_generic_matrix', 'create_colorspaces'] -# ------------------------------------------------------------------------- -# Generic Matrix transform -# ------------------------------------------------------------------------- + def create_generic_matrix(name='matrix', from_reference_values=None, to_reference_values=None, aliases=[]): + """ + Object description. + + Parameters + ---------- + parameter : type + Parameter description. + + Returns + ------- + type + Return value description. + """ if from_reference_values is None: - from_reference_values = [] + from_reference_values = [] + if to_reference_values is None: - to_reference_values = [] + to_reference_values = [] cs = ColorSpace(name) cs.description = 'The %s color space' % name @@ -62,10 +71,10 @@ def create_generic_matrix(name='matrix', return cs -def create_colorspaces(lut_directory, - lut_resolution_1d, - lut_resolution_3d): +def create_colorspaces(lut_directory, + lut_resolution_1d, + lut_resolution_3d): """ Generates the colorspace conversions. @@ -82,14 +91,14 @@ def create_colorspaces(lut_directory, colorspaces = [] - cs = create_generic_matrix('XYZ', - from_reference_values=[aces.ACES_AP0_to_XYZ], - aliases=["lin_xyz"]) + cs = create_generic_matrix('XYZ', + from_reference_values=[aces.ACES_AP0_TO_XYZ], + aliases=["lin_xyz"]) colorspaces.append(cs) cs = create_generic_matrix( - 'Linear - AP1', - to_reference_values=[aces.ACES_AP1_to_AP0], + 'Linear - AP1', + to_reference_values=[aces.ACES_AP1_TO_AP0], aliases=["lin_ap1"]) colorspaces.append(cs) @@ -100,7 +109,7 @@ def create_colorspaces(lut_directory, cs = create_generic_matrix( 'Linear - P3-D60', - from_reference_values=[aces.ACES_AP0_to_XYZ, XYZ_to_P3D60], + from_reference_values=[aces.ACES_AP0_TO_XYZ, XYZ_to_P3D60], aliases=["lin_p3d60"]) colorspaces.append(cs) @@ -111,7 +120,7 @@ def create_colorspaces(lut_directory, cs = create_generic_matrix( 'Linear - P3-DCI', - from_reference_values=[aces.ACES_AP0_to_XYZ, XYZ_to_P3DCI], + from_reference_values=[aces.ACES_AP0_TO_XYZ, XYZ_to_P3DCI], aliases=["lin_p3dci"]) colorspaces.append(cs) @@ -122,7 +131,7 @@ def create_colorspaces(lut_directory, cs = create_generic_matrix( 'Linear - Rec.709', - from_reference_values=[aces.ACES_AP0_to_XYZ, XYZ_to_Rec709], + from_reference_values=[aces.ACES_AP0_TO_XYZ, XYZ_to_Rec709], aliases=["lin_rec709"]) colorspaces.append(cs) @@ -133,14 +142,14 @@ def create_colorspaces(lut_directory, cs = create_generic_matrix( 'Linear - Rec.2020', - from_reference_values=[aces.ACES_AP0_to_XYZ, XYZ_to_Rec2020], + from_reference_values=[aces.ACES_AP0_TO_XYZ, XYZ_to_Rec2020], aliases=["lin_rec2020"]) colorspaces.append(cs) # *ACES* to *Linear*, *Pro Photo* primaries. - AP0_to_RIMM = [ 1.2412367771, -0.1685692287, -0.0726675484, - 0.0061203066, 1.083151174, -0.0892714806, - -0.0032853314, 0.0099796402, 0.9933056912] + AP0_to_RIMM = [1.2412367771, -0.1685692287, -0.0726675484, + 0.0061203066, 1.083151174, -0.0892714806, + -0.0032853314, 0.0099796402, 0.9933056912] cs = create_generic_matrix( 'Linear - ProPhoto', @@ -149,9 +158,9 @@ def create_colorspaces(lut_directory, colorspaces.append(cs) # *ACES* to *Linear*, *Adobe RGB* primaries. - AP0_to_ADOBERGB = [ 1.7245603168, -0.4199935942, -0.3045667227, - -0.2764799142, 1.3727190877, -0.0962391734, - -0.0261255258, -0.0901747807, 1.1163003065] + AP0_to_ADOBERGB = [1.7245603168, -0.4199935942, -0.3045667227, + -0.2764799142, 1.3727190877, -0.0962391734, + -0.0261255258, -0.0901747807, 1.1163003065] cs = create_generic_matrix( 'Linear - Adobe RGB', @@ -160,9 +169,9 @@ def create_colorspaces(lut_directory, colorspaces.append(cs) # *ACES* to *Linear*, *Adobe Wide Gamut RGB* primaries. - AP0_to_ADOBERGB = [ 1.3809814778, -0.1158594573, -0.2651220205, - 0.0057015535, 1.0402949043, -0.0459964578, - -0.0038908746, -0.0597091815, 1.0636000561] + AP0_to_ADOBERGB = [1.3809814778, -0.1158594573, -0.2651220205, + 0.0057015535, 1.0402949043, -0.0459964578, + -0.0038908746, -0.0597091815, 1.0636000561] cs = create_generic_matrix( 'Linear - Adobe Wide Gamut RGB', 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 5443f16..2bdea91 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 @@ -5,6 +5,8 @@ Implements support for *RED* colorspaces conversions and transfer functions. """ +from __future__ import division + import array import os @@ -59,29 +61,29 @@ def create_RED_log_film(gamut, def cineon_to_linear(code_value): n_gamma = 0.6 - black_point = 95.0 - white_point = 685.0 + black_point = 95 + white_point = 685 code_value_to_density = 0.002 - black_linear = pow(10.0, (black_point - white_point) * ( + black_linear = pow(10, (black_point - white_point) * ( code_value_to_density / n_gamma)) - code_linear = pow(10.0, (code_value - white_point) * ( + code_linear = pow(10, (code_value - white_point) * ( code_value_to_density / n_gamma)) - return (code_linear - black_linear) / (1.0 - black_linear) + return (code_linear - black_linear) / (1 - black_linear) cs.to_reference_transforms = [] if transfer_function == 'REDlogFilm': 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)) + data[c] = cineon_to_linear(1023 * c / (lut_resolution_1d - 1)) lut = 'CineonLog_to_linear.spi1d' genlut.write_SPI_1d( os.path.join(lut_directory, lut), - 0.0, - 1.0, + 0, + 1, data, lut_resolution_1d, 1) 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 94d1201..c16b708 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 @@ -5,6 +5,8 @@ Implements support for *Sony* colorspaces conversions and transfer functions. """ +from __future__ import division + import array import os @@ -89,10 +91,10 @@ def create_s_log(gamut, def s_log3_to_linear(code_value): if code_value >= 171.2102946929: - linear = (pow(10.0, ((code_value - 420.0) / 261.5)) * + linear = (pow(10, ((code_value - 420) / 261.5)) * (0.18 + 0.01) - 0.01) else: - linear = (code_value - 95.0) * 0.01125000 / (171.2102946929 - 95.0) + linear = (code_value - 95) * 0.01125000 / (171.2102946929 - 95) return linear @@ -101,13 +103,13 @@ def create_s_log(gamut, 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)) + data[c] = s_log1_to_linear(1023 * c / (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, + 0, + 1, data, lut_resolution_1d, 1) @@ -120,13 +122,13 @@ def create_s_log(gamut, 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)) + data[c] = s_log2_to_linear(1023 * c / (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, + 0, + 1, data, lut_resolution_1d, 1) @@ -139,13 +141,13 @@ def create_s_log(gamut, 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)) + data[c] = s_log3_to_linear(1023 * c / (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, + 0, + 1, data, lut_resolution_1d, 1) diff --git a/aces_1.0.0/python/aces_ocio/generate_lut.py b/aces_1.0.0/python/aces_ocio/generate_lut.py index 1f23b06..a9b84c3 100755 --- a/aces_1.0.0/python/aces_ocio/generate_lut.py +++ b/aces_1.0.0/python/aces_ocio/generate_lut.py @@ -6,6 +6,8 @@ Defines objects to generate various kind of 1d, 2d and 3d LUTs in various file formats. """ +from __future__ import division + import array import os import sys @@ -36,8 +38,8 @@ __all__ = ['generate_1d_LUT_image', def generate_1d_LUT_image(ramp_1d_path, resolution=1024, - min_value=0.0, - max_value=1.0): + min_value=0, + max_value=1): """ Object description. @@ -110,8 +112,8 @@ def write_SPI_1d(filename, from_min, from_max, data, entries, channels): def generate_1d_LUT_from_image(ramp_1d_path, output_path=None, - min_value=0.0, - max_value=1.0): + min_value=0, + max_value=1): """ Object description. @@ -207,10 +209,10 @@ def generate_3d_LUT_from_image(ramp_3d_path, output_path=None, resolution=32): def apply_CTL_to_image(input_image, output_image, ctl_paths=None, - input_scale=1.0, - output_scale=1.0, + input_scale=1, + output_scale=1, global_params=None, - aces_CTL_directory=None): + aces_ctl_directory=None): """ Object description. @@ -232,11 +234,11 @@ def apply_CTL_to_image(input_image, if len(ctl_paths) > 0: ctlenv = os.environ - 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') + 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 + ctl_module_path = aces_ctl_directory ctlenv['CTL_MODULE_PATH'] = ctl_module_path args = [] @@ -288,13 +290,13 @@ def generate_1d_LUT_from_CTL(lut_path, ctl_paths, lut_resolution=1024, identity_LUT_bit_depth='half', - input_scale=1.0, - output_scale=1.0, + input_scale=1, + output_scale=1, global_params=None, cleanup=True, - aces_CTL_directory=None, - min_value=0.0, - max_value=1.0): + aces_ctl_directory=None, + min_value=0, + max_value=1): """ Object description. @@ -335,7 +337,7 @@ def generate_1d_LUT_from_CTL(lut_path, input_scale, output_scale, global_params, - aces_CTL_directory) + aces_ctl_directory) generate_1d_LUT_from_image(transformed_LUT_image, lut_path, @@ -426,11 +428,11 @@ def generate_3d_LUT_from_CTL(lut_path, ctl_paths, lut_resolution=64, identity_LUT_bit_depth='half', - input_scale=1.0, - output_scale=1.0, + input_scale=1, + output_scale=1, global_params=None, cleanup=True, - aces_CTL_directory=None): + aces_ctl_directory=None): """ Object description. @@ -470,7 +472,7 @@ def generate_3d_LUT_from_CTL(lut_path, input_scale, output_scale, global_params, - aces_CTL_directory) + aces_ctl_directory) corrected_LUT_image = '%s.%s.%s' % (lut_path_base, 'correct', 'exr') corrected_LUT_image = correct_LUT_image(transformed_LUT_image, @@ -518,10 +520,10 @@ def main(): 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('--minValue', '', type='float', default=0) + p.add_option('--maxValue', '', type='float', default=1) + p.add_option('--inputScale', '', type='float', default=1) + p.add_option('--outputScale', '', type='float', default=1) p.add_option('--ctlRenderParam', '-p', type='string', nargs=2, action='append') diff --git a/aces_1.0.0/python/aces_ocio/process.py b/aces_1.0.0/python/aces_ocio/process.py index 062855e..bb8f199 100755 --- a/aces_1.0.0/python/aces_ocio/process.py +++ b/aces_1.0.0/python/aces_ocio/process.py @@ -6,6 +6,8 @@ A process wrapper class that maintains the text output and execution status of a process or a list of other process wrappers which carry such data. """ +from __future__ import division + import os import sys import traceback 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 229c880..f41349e 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 @@ -5,6 +5,8 @@ Defines unit tests for *ACES* configuration. """ +from __future__ import division + import hashlib import os import re diff --git a/aces_1.0.0/python/aces_ocio/utilities.py b/aces_1.0.0/python/aces_ocio/utilities.py index 54a495e..75222f1 100644 --- a/aces_1.0.0/python/aces_ocio/utilities.py +++ b/aces_1.0.0/python/aces_ocio/utilities.py @@ -5,8 +5,11 @@ Defines various package utilities objects. """ +from __future__ import division + import os import re +from collections import OrderedDict import PyOpenColorIO as OCIO @@ -21,7 +24,9 @@ __all__ = ['ColorSpace', 'mat44_from_mat33', 'filter_words', 'files_walker', - 'sanitize_path'] + 'replace', + 'sanitize', + 'compact'] class ColorSpace(object): @@ -40,7 +45,7 @@ class ColorSpace(object): to_reference_transforms=[], from_reference_transforms=[], allocation_type=OCIO.Constants.ALLOCATION_UNIFORM, - allocation_vars=[0.0, 1.0]): + allocation_vars=[0, 1]): """ Object description. @@ -83,10 +88,10 @@ def mat44_from_mat33(mat33): Return value description. """ - return [mat33[0], mat33[1], mat33[2], 0.0, - mat33[3], mat33[4], mat33[5], 0.0, - mat33[6], mat33[7], mat33[8], 0.0, - 0, 0, 0, 1.0] + return [mat33[0], mat33[1], mat33[2], 0, + mat33[3], mat33[4], mat33[5], 0, + mat33[6], mat33[7], mat33[8], 0, + 0, 0, 0, 1] def filter_words(words, filters_in=None, filters_out=None, flags=0): @@ -154,7 +159,39 @@ def files_walker(directory, filters_in=None, filters_out=None, flags=0): yield path -def sanitize_path(path): +def replace(string, data): + """ + Replaces the data occurrences in the string. + + Parameters + ---------- + string : str or unicode + String to manipulate. + data : dict + Replacement occurrences. + + Returns + ------- + unicode + Manipulated string. + + Examples + -------- + >>> patterns = {"John" : "Luke", + ... "Jane" : "Anakin", + ... "Doe" : "Skywalker", + ... "Z6PO" : "R2D2"} + >>> data = "Users are: John Doe, Jane Doe, Z6PO." + >>> replace(data,patterns ) + u'Users are: Luke Skywalker, Anakin Skywalker, R2D2.' + """ + + for old, new in data.iteritems(): + string = string.replace(old, new) + return string + + +def sanitize(path): """ Object description. @@ -169,32 +206,30 @@ def sanitize_path(path): Return value description. """ - return path.replace(' ', '_').replace(')', '_').replace('(', '_') + return replace(path, {' ': '_', ')': '_', '(': '_'}) + def compact(string): """ - Removes blanks, underscores, dashes and parentheses + Removes blanks, underscores, dashes and parentheses. Parameters ---------- - parameter : type - A string. + string : str or unicode + String to compact. Returns ------- - type + str or unicode A compact version of that string. """ - compact = string - compact = compact.lower() - compact = compact.replace(' ', '_') - compact = compact.replace('(', '_') - compact = compact.replace(')', '_') - compact = compact.replace('.', '_') - compact = compact.replace('-', '_') - compact = compact.replace('___', '_') - compact = compact.replace('__', '_') - compact = compact.replace('_', '') - - return compact + return replace(string.lower(), + OrderedDict(((' ', '_'), + ('(', '_'), + (')', '_'), + ('.', '_'), + ('-', '_'), + ('___', '_'), + ('__', '_'), + ('_', '')))) diff --git a/aces_1.0.0/python/bin/create_aces_config b/aces_1.0.0/python/bin/create_aces_config index b59fa39..b889dd5 100755 --- a/aces_1.0.0/python/bin/create_aces_config +++ b/aces_1.0.0/python/bin/create_aces_config @@ -5,6 +5,8 @@ Creates the *ACES* configuration. """ +from __future__ import division + import os import sys diff --git a/aces_1.0.0/python/bin/tests_aces_config b/aces_1.0.0/python/bin/tests_aces_config index 6fe08ed..190c40f 100755 --- a/aces_1.0.0/python/bin/tests_aces_config +++ b/aces_1.0.0/python/bin/tests_aces_config @@ -5,6 +5,8 @@ Tests the *ACES* configuration. """ +from __future__ import division + import os import unittest import sys