X-Git-Url: http://users.mur.at/ms/git/gitweb/?a=blobdiff_plain;f=aces_1.0.0%2Fpython%2Faces_ocio%2Fcolorspaces%2Faces.py;h=ce73beef69f62a84ab8a36dc9a736f3659b98e5e;hb=008ab628a49b703cd1141a39b7963947adce9e99;hp=fee627414b5f1d9dafff58f716488ea53f3869d9;hpb=922767a1d6567ea91b98b1796436e94ada818813;p=OpenColorIO-Configs.git diff --git a/aces_1.0.0/python/aces_ocio/colorspaces/aces.py b/aces_1.0.0/python/aces_ocio/colorspaces/aces.py index fee6274..ce73bee 100644 --- a/aces_1.0.0/python/aces_ocio/colorspaces/aces.py +++ b/aces_1.0.0/python/aces_ocio/colorspaces/aces.py @@ -7,6 +7,7 @@ Implements support for *ACES* colorspaces conversions and transfer functions. from __future__ import division +import copy import math import numpy import os @@ -26,7 +27,6 @@ from aces_ocio.utilities import ( sanitize, compact) - __author__ = 'ACES Developers' __copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers' __license__ = '' @@ -35,17 +35,24 @@ __email__ = 'aces@oscars.org' __status__ = 'Production' __all__ = ['ACES_AP1_TO_AP0', + 'ACES_AP0_TO_AP1', 'ACES_AP0_TO_XYZ', + 'ACES_XYZ_TO_AP0', 'create_ACES', 'create_ACEScc', 'create_ACESproxy', 'create_ACEScg', 'create_ADX', - 'create_ACES_LMT', - 'create_ACES_RRT_plus_ODT', 'create_generic_log', + 'create_Dolby_PQ', + 'create_Dolby_PQ_shaper', + 'create_ACES_LMT', 'create_LMTs', + 'create_ACES_RRT_plus_ODT', 'create_ODTs', + 'create_shapers_dolbypq' + 'create_shapers_log2', + 'create_shapers', 'get_transform_info', 'get_ODTs_info', 'get_LMTs_info', @@ -74,17 +81,16 @@ ACES_XYZ_TO_AP0 = [1.0498110175, 0.0000000000, -0.0000974845, def create_ACES(): """ - Object description. + Creates the *ACES2065-1* reference color space Parameters ---------- - parameter : type - Parameter description. + None Returns ------- - type - Return value description. + ColorSpace + *ACES2065-1* and all its identifying information """ # Defining the reference colorspace. @@ -92,7 +98,7 @@ def create_ACES(): aces2065_1.description = ( 'The Academy Color Encoding System reference color space') aces2065_1.equality_group = '' - aces2065_1.aliases = ["lin_ap0", "aces"] + aces2065_1.aliases = ['lin_ap0', 'aces'] aces2065_1.family = 'ACES' aces2065_1.is_data = False aces2065_1.allocation_type = ocio.Constants.ALLOCATION_LG2 @@ -110,31 +116,52 @@ def create_ACEScc(aces_ctl_directory, max_value=1, input_scale=1): """ - Creates the *ACEScc* colorspace. + Creates the *ACEScc* reference color space Parameters ---------- - parameter : type - Parameter description. + aces_ctl_directory : str or unicode + The path to the aces 'transforms/ctl/utilities' + lut_directory : str or unicode + The directory to use when generating LUTs + lut_resolution_1d : int + The resolution of generated 1D LUTs + cleanup : bool + Whether or not to clean up the intermediate images + name : str or unicode, optional + The name of the ColorSpace + min_value : float, optional + The minimum value to consider for the space + max_value : float, optional + The maximum value to consider for the space + input_scale : float, optional + A scale factor to divide input values Returns ------- - Colorspace - *ACEScc* colorspace. + ColorSpace + *ACEScc* and all its identifying information """ cs = ColorSpace(name) cs.description = 'The %s color space' % name - cs.aliases = ["acescc_ap1"] + cs.aliases = ['acescc', 'acescc_ap1'] cs.equality_group = '' cs.family = 'ACES' cs.is_data = False cs.allocation_type = ocio.Constants.ALLOCATION_UNIFORM cs.allocation_vars = [min_value, max_value] + cs.aces_transform_id = 'ACEScsc.ACEScc_to_ACES.a1.0.0' ctls = [os.path.join(aces_ctl_directory, 'ACEScc', - 'ACEScsc.ACEScc_to_ACES.a1.0.0.ctl')] + '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_linear.spi1d' % name lut = sanitize(lut) @@ -146,7 +173,7 @@ def create_ACEScc(aces_ctl_directory, 'float', input_scale, 1, - {'transferFunctionOnly': 1}, + {}, cleanup, aces_ctl_directory, min_value, @@ -160,7 +187,7 @@ def create_ACEScc(aces_ctl_directory, 'interpolation': 'linear', '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), @@ -176,26 +203,36 @@ def create_ACESproxy(aces_ctl_directory, cleanup, name='ACESproxy'): """ - Creates the *ACESproxy* colorspace. + Creates the *ACESproxy* color space Parameters ---------- - parameter : type - Parameter description. + aces_ctl_directory : str or unicode + The path to the aces 'transforms/ctl/utilities' + lut_directory : str or unicode + The directory to use when generating LUTs + lut_resolution_1d : int + The resolution of generated 1D LUTs + cleanup : bool + Whether or not to clean up the intermediate images + name : str or unicode, optional + The name of the ColorSpace Returns ------- - Colorspace - *ACESproxy* colorspace. + ColorSpace + *ACESproxy* and all its identifying information """ cs = ColorSpace(name) cs.description = 'The %s color space' % name - cs.aliases = ["acesproxy_ap1"] + cs.aliases = ['acesproxy', 'acesproxy_ap1'] cs.equality_group = '' cs.family = 'ACES' cs.is_data = False + cs.aces_transform_id = 'ACEScsc.ACESproxy10i_to_ACES.a1.0.0' + ctls = [os.path.join(aces_ctl_directory, 'ACESproxy', 'ACEScsc.ACESproxy10i_to_ACES.a1.0.0.ctl'), @@ -213,8 +250,8 @@ def create_ACESproxy(aces_ctl_directory, os.path.join(lut_directory, lut), ctls, lut_resolution_1d, - 'uint16', - 64, + 'float', + 1, 1, {}, cleanup, @@ -230,7 +267,7 @@ def create_ACESproxy(aces_ctl_directory, 'interpolation': 'linear', '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), @@ -243,43 +280,53 @@ def create_ACESproxy(aces_ctl_directory, # ------------------------------------------------------------------------- # *ACEScg* # ------------------------------------------------------------------------- -def create_ACEScg(aces_ctl_directory, - lut_directory, - lut_resolution_1d, - cleanup, - name='ACEScg'): +def create_ACEScg(): """ - Creates the *ACEScg* colorspace. + Creates the *ACEScg* color space Parameters ---------- - parameter : type - Parameter description. + None Returns ------- - Colorspace - *ACEScg* colorspace. + ColorSpace + *ACEScg* and all its identifying information """ + name = 'ACEScg' + cs = ColorSpace(name) cs.description = 'The %s color space' % name - cs.aliases = ["lin_ap1"] + cs.aliases = ['acescg', 'lin_ap1'] cs.equality_group = '' cs.family = 'ACES' cs.is_data = False cs.allocation_type = ocio.Constants.ALLOCATION_LG2 cs.allocation_vars = [-8, 5, 0.00390625] + cs.aces_transform_id = 'ACEScsc.ACEScg_to_ACES.a1.0.0' + 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), 'direction': 'forward'}) cs.from_reference_transforms = [] + + # Commented out because specifying the inverse matrix causes some + # of OCIO's checks to see if a set of transforms can be collapsed + # to fail. + + # *AP1* primaries to *AP0* primaries + #cs.from_reference_transforms.append({ + # 'type': 'matrix', + # 'matrix': mat44_from_mat33(ACES_AP0_TO_AP1), + # 'direction': 'forward'}) + return cs @@ -287,32 +334,37 @@ def create_ACEScg(aces_ctl_directory, # *ADX* # ------------------------------------------------------------------------- def create_ADX(lut_directory, - lut_resolution_1d, bit_depth=10, name='ADX'): """ - Creates the *ADX* colorspace. + Creates the *ADX* color space Parameters ---------- - parameter : type - Parameter description. + lut_directory : str or unicode + The directory to use when generating LUTs + bit_depth : int + Choose either 10 or 16 bit ADX + name : str or unicode, optional + The name of the ColorSpace Returns ------- - Colorspace - *ADX* colorspace. + ColorSpace + *ADX* and all its identifying information """ name = '%s%s' % (name, bit_depth) cs = ColorSpace(name) cs.description = '%s color space - used for film scans' % name - cs.aliases = ["adx%s" % str(bit_depth)] + cs.aliases = ['adx%s' % str(bit_depth)] cs.equality_group = '' cs.family = 'ADX' cs.is_data = False if bit_depth == 10: + cs.aces_transform_id = 'ACEScsc.ADX10_to_ACES.a1.0.0' + cs.bit_depth = ocio.Constants.BIT_DEPTH_UINT10 ADX_to_CDD = [1023 / 500, 0, 0, 0, 0, 1023 / 500, 0, 0, @@ -320,6 +372,8 @@ def create_ADX(lut_directory, 0, 0, 0, 1] offset = [-95 / 500, -95 / 500, -95 / 500, 0] elif bit_depth == 16: + cs.aces_transform_id = 'ACEScsc.ADX16_to_ACES.a1.0.0' + cs.bit_depth = ocio.Constants.BIT_DEPTH_UINT16 ADX_to_CDD = [65535 / 8000, 0, 0, 0, 0, 65535 / 8000, 0, 0, @@ -336,7 +390,8 @@ def create_ADX(lut_directory, 'offset': offset, 'direction': 'forward'}) - # Convert from Channel-Dependent Density to Channel-Independent Density + # Converting from *Channel-Dependent Density* to + # *Channel-Independent Density*. cs.to_reference_transforms.append({ 'type': 'matrix', 'matrix': [0.75573, 0.22197, 0.02230, 0, @@ -348,10 +403,10 @@ def create_ADX(lut_directory, # Copied from *Alex Fry*'s *adx_cid_to_rle.py* def create_CID_to_RLE_LUT(): - def interpolate_1D(x, xp, fp): + def interpolate_1d(x, xp, fp): return numpy.interp(x, xp, fp) - LUT_1D_xp = [-0.190000000000000, + LUT_1D_XP = [-0.190000000000000, 0.010000000000000, 0.028000000000000, 0.054000000000000, @@ -363,7 +418,7 @@ def create_ADX(lut_directory, 0.500000000000000, 0.600000000000000] - LUT_1D_fp = [-6.000000000000000, + LUT_1D_FP = [-6.000000000000000, -2.721718645000000, -2.521718645000000, -2.321718645000000, @@ -380,7 +435,7 @@ def create_ADX(lut_directory, def cid_to_rle(x): if x <= 0.6: - return interpolate_1D(x, LUT_1D_xp, LUT_1D_fp) + return interpolate_1d(x, LUT_1D_XP, LUT_1D_FP) return (100 / 55) * x - REF_PT def fit(value, from_min, from_max, to_min, to_max): @@ -436,34 +491,61 @@ def create_ADX(lut_directory, # ------------------------------------------------------------------------- -# *Generic Log Transform* +# Generic *Log* Transform # ------------------------------------------------------------------------- def create_generic_log(aces_ctl_directory, lut_directory, lut_resolution_1d, cleanup, name='log', - aliases=[], + aliases=None, min_value=0, max_value=1, input_scale=1, middle_grey=0.18, - min_exposure=-6, + min_exposure=-6.5, max_exposure=6.5): """ Creates the *Generic Log* colorspace. Parameters ---------- - parameter : type - Parameter description. + aces_ctl_directory : str or unicode + The path to the aces 'transforms/ctl/utilities' + lut_directory : str or unicode + The directory to use when generating LUTs + lut_resolution_1d : int + The resolution of generated 1D LUTs + cleanup : bool + Whether or not to clean up the intermediate images + name : str or unicode, optional + The name of the ColorSpace + aliases : list of str or unicode, optional + The alias names to use for the ColorSpace + min_value : float, optional + The minimum value to consider for the space + max_value : float, optional + The maximum value to consider for the space + input_scale : float, optional + A scale factor to divide input values + middle_grey : float, optional + The middle of the dynamic range covered by the transfer function + min_exposure : float, optional + The offset from middle grey, in stops, that defines the low end of the dynamic + range covered by the transfer function + max_exposure : float, optional + The offset from middle grey, in stops, that defines the high end of the dynamic + range covered by the transfer function Returns ------- - Colorspace + ColorSpace *Generic Log* colorspace. """ + if aliases is None: + aliases = [] + cs = ColorSpace(name) cs.description = 'The %s color space' % name cs.aliases = aliases @@ -474,7 +556,7 @@ def create_generic_log(aces_ctl_directory, ctls = [os.path.join( aces_ctl_directory, 'utilities', - 'ACESlib.OCIO_shaper_log2_to_lin_param.a1.0.0.ctl')] + 'ACESlib.Log2_to_Lin_param.a1.0.0.ctl')] lut = '%s_to_linear.spi1d' % name lut = sanitize(lut) @@ -507,17 +589,50 @@ def create_generic_log(aces_ctl_directory, # ------------------------------------------------------------------------- -# *base Dolby PQ Transform* +# Base *Dolby PQ* Transform # ------------------------------------------------------------------------- -def create_dolbypq(aces_CTL_directory, - lut_directory, - lut_resolution_1d, - cleanup, - name='pq', - aliases=[], - min_value=0.0, - max_value=1.0, - input_scale=1.0): +def create_Dolby_PQ(aces_ctl_directory, + lut_directory, + lut_resolution_1d, + cleanup, + name='pq', + aliases=None, + min_value=0.0, + max_value=1.0, + input_scale=1.0): + """ + Creates the generic *Dolby PQ* colorspace. + + Parameters + ---------- + aces_ctl_directory : str or unicode + The path to the aces 'transforms/ctl/utilities' + lut_directory : str or unicode + The directory to use when generating LUTs + lut_resolution_1d : int + The resolution of generated 1D LUTs + cleanup : bool + Whether or not to clean up the intermediate images + name : str or unicode, optional + The name of the ColorSpace + aliases : list of str or unicode, optional + The alias names to use for the ColorSpace + min_value : float, optional + The minimum value to consider for the space + max_value : float, optional + The maximum value to consider for the space + input_scale : float, optional + A scale factor to divide input values + + Returns + ------- + ColorSpace + Generic *Dolby PQ* colorspace. + """ + + if aliases is None: + aliases = [] + cs = ColorSpace(name) cs.description = 'The %s color space' % name cs.aliases = aliases @@ -526,9 +641,9 @@ def create_dolbypq(aces_CTL_directory, cs.is_data = False ctls = [os.path.join( - aces_CTL_directory, + aces_ctl_directory, 'utilities', - 'ACESlib.OCIO_shaper_dolbypq_to_lin.a1.0.0.ctl')] + 'ACESlib.DolbyPQ_to_Lin.a1.0.0.ctl')] lut = '%s_to_linear.spi1d' % name lut = sanitize(lut) @@ -542,7 +657,7 @@ def create_dolbypq(aces_CTL_directory, 1.0, {}, cleanup, - aces_CTL_directory, + aces_ctl_directory, min_value, max_value) @@ -558,20 +673,61 @@ def create_dolbypq(aces_CTL_directory, # ------------------------------------------------------------------------- -# *Dolby PQ Transform that considers a fixed linear range* +# *Dolby PQ* Transform - Fixed Linear Range # ------------------------------------------------------------------------- -def create_dolbypq_scaled(aces_CTL_directory, - lut_directory, - lut_resolution_1d, - cleanup, - name='pq', - 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): +def create_Dolby_PQ_shaper(aces_ctl_directory, + lut_directory, + lut_resolution_1d, + cleanup, + name='pq', + aliases=None, + min_value=0.0, + max_value=1.0, + input_scale=1.0, + middle_grey=0.18, + min_exposure=-6.5, + max_exposure=6.5): + """ + Creates a *Dolby PQ* colorspace that covers a specific dynamic range + + Parameters + ---------- + aces_ctl_directory : str or unicode + The path to the aces 'transforms/ctl/utilities' + lut_directory : str or unicode + The directory to use when generating LUTs + lut_resolution_1d : int + The resolution of generated 1D LUTs + cleanup : bool + Whether or not to clean up the intermediate images + name : str or unicode, optional + The name of the ColorSpace + aliases : list of str or unicode, optional + The alias names to use for the ColorSpace + min_value : float, optional + The minimum value to consider for the space + max_value : float, optional + The maximum value to consider for the space + input_scale : float, optional + A scale factor to divide input values + middle_grey : float, optional + The middle of the dynamic range covered by the transfer function + min_exposure : float, optional + The offset from middle grey, in stops, that defines the low end of the dynamic + range covered by the transfer function + max_exposure : float, optional + The offset from middle grey, in stops, that defines the high end of the dynamic + range covered by the transfer function + + Returns + ------- + ColorSpace + A *Dolby PQ* colorspace that covers a specific dynamic range + """ + + if aliases is None: + aliases = [] + cs = ColorSpace(name) cs.description = 'The %s color space' % name cs.aliases = aliases @@ -580,9 +736,9 @@ def create_dolbypq_scaled(aces_CTL_directory, cs.is_data = False ctls = [os.path.join( - aces_CTL_directory, + aces_ctl_directory, 'utilities', - 'ACESlib.OCIO_shaper_dolbypq_to_lin_param.a1.0.0.ctl')] + 'ACESlib.OCIOshaper_to_Lin_param.a1.0.0.ctl')] lut = '%s_to_linear.spi1d' % name lut = sanitize(lut) @@ -598,7 +754,7 @@ def create_dolbypq_scaled(aces_CTL_directory, 'minExposure': min_exposure, 'maxExposure': max_exposure}, cleanup, - aces_CTL_directory, + aces_ctl_directory, min_value, max_value) @@ -614,29 +770,43 @@ def create_dolbypq_scaled(aces_CTL_directory, # ------------------------------------------------------------------------- -# *Individual LMT* +# Individual *LMT* # ------------------------------------------------------------------------- def create_ACES_LMT(lmt_name, lmt_values, shaper_info, aces_ctl_directory, lut_directory, - lut_resolution_1d=1024, lut_resolution_3d=64, cleanup=True, aliases=None): """ - Creates the *ACES LMT* colorspace. + Creates an *ACES Look Transform (LMT)* colorspace. Parameters ---------- - parameter : type - Parameter description. + lmt_name : str or unicode + The name of the Look Transform (LMT) + lmt_values : dict + A collection of values that define the Look Transform's attributes and behavior + shaper_info : dict + A collection of values that define the Shaper to use when generating LUTs to + represent the Look Transform + aces_ctl_directory : str or unicode + The path to the aces 'transforms/ctl/utilities' + lut_directory : str or unicode + The directory to use when generating LUTs + lut_resolution_3d : int, optional + The resolution of generated 3D LUTs + cleanup : bool, optional + Whether or not to clean up the intermediate images + aliases : list of str or unicode, optional + The alias names to use for the ColorSpace Returns ------- - Colorspace - *ACES LMT* colorspace. + ColorSpace + An *ACES LMT* colorspace. """ if aliases is None: @@ -650,21 +820,21 @@ def create_ACES_LMT(lmt_name, cs.is_data = False cs.allocation_type = ocio.Constants.ALLOCATION_LG2 cs.allocation_vars = [-8, 5, 0.00390625] + cs.aces_transform_id = lmt_values['transformID'] pprint.pprint(lmt_values) # Generating the *shaper* transform. (shaper_name, - shaper_to_ACES_CTL, - shaper_from_ACES_CTL, + shaper_to_aces_ctl, + shaper_from_aces_ctl, shaper_input_scale, shaper_params) = shaper_info - # Add the shaper transform shaper_lut = '%s_to_linear.spi1d' % shaper_name shaper_lut = sanitize(shaper_lut) - shaper_OCIO_transform = { + shaper_ocio_transform = { 'type': 'lutFile', 'path': shaper_lut, 'interpolation': 'linear', @@ -674,7 +844,7 @@ def create_ACES_LMT(lmt_name, cs.from_reference_transforms = [] if 'transformCTL' in lmt_values: - ctls = [shaper_to_ACES_CTL % 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) @@ -692,7 +862,7 @@ def create_ACES_LMT(lmt_name, cleanup, aces_ctl_directory) - cs.from_reference_transforms.append(shaper_OCIO_transform) + cs.from_reference_transforms.append(shaper_ocio_transform) cs.from_reference_transforms.append({ 'type': 'lutFile', 'path': lut, @@ -705,8 +875,8 @@ def create_ACES_LMT(lmt_name, if 'transformCTLInverse' in lmt_values: ctls = [os.path.join(aces_ctl_directory, lmt_values['transformCTLInverse']), - shaper_from_ACES_CTL % aces_ctl_directory] - lut = 'Inverse.%s.%s.spi3d' % (odt_name, shaper_name) + shaper_from_aces_ctl % aces_ctl_directory] + lut = 'Inverse.%s.%s.spi3d' % (lmt_name, shaper_name) lut = sanitize(lut) @@ -720,9 +890,7 @@ def create_ACES_LMT(lmt_name, shaper_params, cleanup, aces_ctl_directory, - 0, - 1, - 1) + 0) cs.to_reference_transforms.append({ 'type': 'lutFile', @@ -730,7 +898,7 @@ def create_ACES_LMT(lmt_name, 'interpolation': 'tetrahedral', 'direction': 'forward'}) - shaper_inverse = shaper_OCIO_transform.copy() + shaper_inverse = shaper_ocio_transform.copy() shaper_inverse['direction'] = 'forward' cs.to_reference_transforms.append(shaper_inverse) @@ -745,20 +913,32 @@ def create_LMTs(aces_ctl_directory, lut_resolution_1d, lut_resolution_3d, lmt_info, - shaper_name, cleanup): """ - Object description. + Create ColorSpaces representing the *ACES Look Transforms* Parameters ---------- - parameter : type - Parameter description. + aces_ctl_directory : str or unicode + The path to the aces 'transforms/ctl/utilities' + lut_directory : str or unicode + The directory to use when generating LUTs + lut_resolution_1d : int + The resolution of generated 1D LUTs + lut_resolution_3d : int + The resolution of generated 3D LUTs + cleanup : bool + Whether or not to clean up the intermediate images + aliases : list of str or unicode, optional + The alias names to use for the ColorSpace + lmt_info : dict + A collection of values that define the Look Transforms that need to be + generated Returns ------- - type - Return value description. + list of ColorSpaces + ColorSpaces representing the *ACES Look Transforms* """ colorspaces = [] @@ -795,25 +975,24 @@ def create_LMTs(aces_ctl_directory, lmt_shaper_name, os.path.join('%s', 'utilities', - 'ACESlib.OCIO_shaper_log2_to_lin_param.a1.0.0.ctl'), + 'ACESlib.Log2_to_Lin_param.a1.0.0.ctl'), os.path.join('%s', 'utilities', - 'ACESlib.OCIO_shaper_lin_to_log2_param.a1.0.0.ctl'), + 'ACESlib.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: + 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'])] + 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) @@ -830,22 +1009,36 @@ def create_ACES_RRT_plus_ODT(odt_name, shaper_info, aces_ctl_directory, lut_directory, - lut_resolution_1d=1024, lut_resolution_3d=64, cleanup=True, aliases=None): """ - Object description. + Creates an *ACES Output Transform (RRT + ODT)* colorspace. Parameters ---------- - parameter : type - Parameter description. + odt_name : str or unicode + The name of the Output Transform (RRT + ODT) + odt_values : dict + A collection of values that define the Output Transform's attributes and behavior + shaper_info : dict + A collection of values that define the Shaper to use when generating LUTs to + represent the Output Transform + aces_ctl_directory : str or unicode + The path to the aces 'transforms/ctl/utilities' + lut_directory : str or unicode + The directory to use when generating LUTs + lut_resolution_3d : int, optional + The resolution of generated 3D LUTs + cleanup : bool, optional + Whether or not to clean up the intermediate images + aliases : list of str or unicode, optional + The alias names to use for the ColorSpace Returns ------- - type - Return value description. + ColorSpace + An *ACES Output Transform (RRT + ODT)* colorspace. """ if aliases is None: @@ -859,12 +1052,14 @@ def create_ACES_RRT_plus_ODT(odt_name, cs.family = 'Output' cs.is_data = False + cs.aces_transform_id = odt_values['transformID'] + pprint.pprint(odt_values) # Generating the *shaper* transform. (shaper_name, - shaper_to_ACES_CTL, - shaper_from_ACES_CTL, + shaper_to_aces_ctl, + shaper_from_aces_ctl, shaper_input_scale, shaper_params) = shaper_info @@ -873,11 +1068,10 @@ def create_ACES_RRT_plus_ODT(odt_name, else: shaper_params['legalRange'] = 0 - # Add the shaper transform shaper_lut = '%s_to_linear.spi1d' % shaper_name shaper_lut = sanitize(shaper_lut) - shaper_OCIO_transform = { + shaper_ocio_transform = { 'type': 'lutFile', 'path': shaper_lut, 'interpolation': 'linear', @@ -887,20 +1081,20 @@ def create_ACES_RRT_plus_ODT(odt_name, cs.from_reference_transforms = [] if 'transformLUT' in odt_values: - transform_LUT_file_name = os.path.basename( + transform_lut_file_name = os.path.basename( odt_values['transformLUT']) - lut = os.path.join(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) + cs.from_reference_transforms.append(shaper_ocio_transform) cs.from_reference_transforms.append({ 'type': 'lutFile', - 'path': transform_LUT_file_name, + 'path': transform_lut_file_name, 'interpolation': 'tetrahedral', 'direction': 'forward'}) elif 'transformCTL' in odt_values: ctls = [ - shaper_to_ACES_CTL % aces_ctl_directory, + shaper_to_aces_ctl % aces_ctl_directory, os.path.join(aces_ctl_directory, 'rrt', 'RRT.a1.0.0.ctl'), @@ -913,7 +1107,6 @@ def create_ACES_RRT_plus_ODT(odt_name, generate_3d_LUT_from_CTL( os.path.join(lut_directory, lut), - # shaperLUT, ctls, lut_resolution_3d, 'float', @@ -923,7 +1116,7 @@ def create_ACES_RRT_plus_ODT(odt_name, cleanup, aces_ctl_directory) - cs.from_reference_transforms.append(shaper_OCIO_transform) + cs.from_reference_transforms.append(shaper_ocio_transform) cs.from_reference_transforms.append({ 'type': 'lutFile', 'path': lut, @@ -934,18 +1127,18 @@ def create_ACES_RRT_plus_ODT(odt_name, cs.to_reference_transforms = [] if 'transformLUTInverse' in odt_values: - transform_LUT_inverse_file_name = os.path.basename( + transform_lut_inverse_file_name = os.path.basename( odt_values['transformLUTInverse']) - lut = os.path.join(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, + 'path': transform_lut_inverse_file_name, 'interpolation': 'tetrahedral', 'direction': 'forward'}) - shaper_inverse = shaper_OCIO_transform.copy() + shaper_inverse = shaper_ocio_transform.copy() shaper_inverse['direction'] = 'forward' cs.to_reference_transforms.append(shaper_inverse) elif 'transformCTLInverse' in odt_values: @@ -955,14 +1148,13 @@ def create_ACES_RRT_plus_ODT(odt_name, 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(lut) generate_3d_LUT_from_CTL( os.path.join(lut_directory, lut), - # None, ctls, lut_resolution_3d, 'half', @@ -978,54 +1170,63 @@ def create_ACES_RRT_plus_ODT(odt_name, 'interpolation': 'tetrahedral', 'direction': 'forward'}) - shaper_inverse = shaper_OCIO_transform.copy() + shaper_inverse = shaper_ocio_transform.copy() shaper_inverse['direction'] = 'forward' cs.to_reference_transforms.append(shaper_inverse) return cs - # ------------------------------------------------------------------------- -# *ODTs* +# *Log 2 Shapers* # ------------------------------------------------------------------------- -def create_ODTs(aces_ctl_directory, - lut_directory, - lut_resolution_1d, - lut_resolution_3d, - odt_info, - shaper_name, - cleanup, - linear_display_space, - log_display_space): +def create_shapers_log2(aces_ctl_directory, + lut_directory, + lut_resolution_1d, + cleanup, + shaper_name, + middle_grey, + min_exposure, + max_exposure): """ - Object description. + Creates a *Log base 2* colorspace that covers a specific dynamic range Parameters ---------- - parameter : type - Parameter description. + aces_ctl_directory : str or unicode + The path to the aces 'transforms/ctl/utilities' + lut_directory : str or unicode + The directory to use when generating LUTs + lut_resolution_1d : int + The resolution of generated 1D LUTs + cleanup : bool + Whether or not to clean up the intermediate images + shaper_name : str or unicode, optional + The name of the ColorSpace + middle_grey : float + The middle of the dynamic range covered by the transfer function + min_exposure : float + The offset from middle grey, in stops, that defines the low end of the dynamic + range covered by the transfer function + max_exposure : float + The offset from middle grey, in stops, that defines the high end of the dynamic + range covered by the transfer function Returns ------- - type - Return value description. + ColorSpace + A *Log base 2* colorspace that covers a specific dynamic range """ colorspaces = [] - displays = {} - - # ------------------------------------------------------------------------- - # *RRT / ODT* Shaper Options - # ------------------------------------------------------------------------- shaper_data = {} - # Defining the *Log 2* shaper. + # Defining the *Log 2* shaper for *ODTs covering 48 nit output*. log2_shaper_name = shaper_name - log2_shaper_name_aliases = ["crv_%s" % compact(log2_shaper_name)] + log2_shaper_name_aliases = ['crv_%s' % compact(log2_shaper_name)] log2_params = { - 'middleGrey': 0.18, - 'minExposure': -6, - 'maxExposure': 6.5} + 'middleGrey': middle_grey, + 'minExposure': min_exposure, + 'maxExposure': max_exposure} log2_shaper_colorspace = create_generic_log( aces_ctl_directory, @@ -1046,44 +1247,27 @@ def create_ODTs(aces_ctl_directory, log2_shaper_name, os.path.join('%s', 'utilities', - 'ACESlib.OCIO_shaper_log2_to_lin_param.a1.0.0.ctl'), + 'ACESlib.Log2_to_Lin_param.a1.0.0.ctl'), os.path.join('%s', 'utilities', - 'ACESlib.OCIO_shaper_lin_to_log2_param.a1.0.0.ctl'), + 'ACESlib.Lin_to_Log2_param.a1.0.0.ctl'), shaper_input_scale_generic_log2, log2_params] shaper_data[log2_shaper_name] = log2_shaper_data - # Space with a more user-friendly name. Direct copy otherwise. - log2_shaper_copy_name = "Log2 Shaper" - log2_shaper_copy_colorspace = ColorSpace(log2_shaper_copy_name) - log2_shaper_copy_colorspace.description = 'The %s color space' % log2_shaper_copy_name - log2_shaper_copy_colorspace.aliases = ["crv_%s" % compact(log2_shaper_copy_name)] - log2_shaper_copy_colorspace.equality_group = log2_shaper_copy_name - log2_shaper_copy_colorspace.family = log2_shaper_colorspace.family - log2_shaper_copy_colorspace.is_data = log2_shaper_colorspace.is_data - log2_shaper_copy_colorspace.to_reference_transforms = list( - log2_shaper_colorspace.to_reference_transforms) - log2_shaper_copy_colorspace.from_reference_transforms = list( - log2_shaper_colorspace.from_reference_transforms) - colorspaces.append(log2_shaper_copy_colorspace) - # Defining the *Log2 shaper that includes the AP1* primaries. - log2_shaper_api1_name = "%s - AP1" % "Log2 Shaper" - log2_shaper_api1_colorspace = ColorSpace(log2_shaper_api1_name) - log2_shaper_api1_colorspace.description = 'The %s color space' % log2_shaper_api1_name + log2_shaper_api1_name = '%s - AP1' % log2_shaper_name + log2_shaper_api1_colorspace = copy.deepcopy(log2_shaper_colorspace) + + log2_shaper_api1_colorspace.name = log2_shaper_api1_name + log2_shaper_api1_colorspace.description = ( + 'The %s color space' % log2_shaper_api1_name) log2_shaper_api1_colorspace.aliases = [ - "%s_ap1" % compact(log2_shaper_copy_name)] + '%s_ap1' % compact(log2_shaper_name)] log2_shaper_api1_colorspace.equality_group = log2_shaper_api1_name - log2_shaper_api1_colorspace.family = log2_shaper_colorspace.family - log2_shaper_api1_colorspace.is_data = log2_shaper_colorspace.is_data - log2_shaper_api1_colorspace.to_reference_transforms = list( - log2_shaper_colorspace.to_reference_transforms) - log2_shaper_api1_colorspace.from_reference_transforms = list( - log2_shaper_colorspace.from_reference_transforms) - - # *AP1* primaries to *AP0* primaries. + + # *AP1* primaries to *AP0* primaries log2_shaper_api1_colorspace.to_reference_transforms.append({ 'type': 'matrix', 'matrix': mat44_from_mat33(ACES_AP1_TO_AP0), @@ -1091,82 +1275,354 @@ def create_ODTs(aces_ctl_directory, }) colorspaces.append(log2_shaper_api1_colorspace) - # Defining the *Log2 shaper that includes the AP1* primaries. - # Named with 'shaper_name' variable. Needed for some LUT baking steps. - shaper_api1_name = "%s - AP1" % shaper_name - shaper_api1_colorspace = ColorSpace(shaper_api1_name) - shaper_api1_colorspace.description = 'The %s color space' % shaper_api1_name - shaper_api1_colorspace.aliases = ["%s_ap1" % compact(shaper_name)] - shaper_api1_colorspace.equality_group = shaper_api1_name - shaper_api1_colorspace.family = log2_shaper_colorspace.family - shaper_api1_colorspace.is_data = log2_shaper_colorspace.is_data - shaper_api1_colorspace.to_reference_transforms = list( - log2_shaper_api1_colorspace.to_reference_transforms) - shaper_api1_colorspace.from_reference_transforms = list( - log2_shaper_api1_colorspace.from_reference_transforms) - colorspaces.append(shaper_api1_colorspace) - - # Define the base *Dolby PQ Shaper* - # - dolbypq_shaper_name = "Dolby PQ 10000" - dolbypq_shaper_name_aliases = ["crv_%s" % "dolbypq_10000"] + return shaper_data, colorspaces + +# ------------------------------------------------------------------------- +# *Dolby PQ-based Shapers* +# ------------------------------------------------------------------------- +def create_shapers_dolbypq(aces_ctl_directory, + lut_directory, + lut_resolution_1d, + cleanup, + shaper_name, + middle_grey, + min_exposure, + max_exposure): + """ + Creates two *Dolby PQ* colorspaces, one with now gamut conversion, the other with + the conversion from *ACES* *AP0* to *AP1* + + Parameters + ---------- + aces_ctl_directory : str or unicode + The path to the aces 'transforms/ctl/utilities' + lut_directory : str or unicode + The directory to use when generating LUTs + lut_resolution_1d : int + The resolution of generated 1D LUTs + cleanup : bool + Whether or not to clean up the intermediate images + shaper_name : str or unicode, optional + The name of the ColorSpace + middle_grey : float + The middle of the dynamic range covered by the transfer function + min_exposure : float + The offset from middle grey, in stops, that defines the low end of the dynamic + range covered by the transfer function + max_exposure : float + The offset from middle grey, in stops, that defines the high end of the dynamic + range covered by the transfer function + + Returns + ------- + dict + Values defining a Shaper + list of ColorSpaces + A list of *Dolby PQ* colorspaces that covers a specific dynamic range + """ + colorspaces = [] + shaper_data = {} + + # Define the *Dolby PQ Shaper that considers a fixed linear range* + dolby_pq_shaper_name = shaper_name + dolby_pq_shaper_name_aliases = ['crv_%s' % compact(dolby_pq_shaper_name)] + + dolby_pq_params = { + 'middleGrey': middle_grey, + 'minExposure': min_exposure, + 'maxExposure': max_exposure} - dolbypq_shaper_colorspace = create_dolbypq( + dolby_pq_shaper_colorspace = create_Dolby_PQ_shaper( aces_ctl_directory, lut_directory, lut_resolution_1d, cleanup, - name=dolbypq_shaper_name, - aliases=dolbypq_shaper_name_aliases) - colorspaces.append(dolbypq_shaper_colorspace) + name=dolby_pq_shaper_name, + aliases=dolby_pq_shaper_name_aliases, + middle_grey=dolby_pq_params['middleGrey'], + min_exposure=dolby_pq_params['minExposure'], + max_exposure=dolby_pq_params['maxExposure']) + colorspaces.append(dolby_pq_shaper_colorspace) # *Dolby PQ* shaper name and *CTL* transforms bundled up. - dolbypq_shaper_data = [ - dolbypq_shaper_name, + dolby_pq_shaper_data = [ + dolby_pq_shaper_name, os.path.join('%s', 'utilities', - 'ACESlib.OCIO_shaper_dolbypq_to_lin.a1.0.0.ctl'), + 'ACESlib.OCIOshaper_to_Lin_param.a1.0.0.ctl'), os.path.join('%s', 'utilities', - 'ACESlib.OCIO_shaper_lin_to_dolbypq.a1.0.0.ctl'), + 'ACESlib.Lin_to_OCIOshaper_param.a1.0.0.ctl'), 1.0, - {}] + dolby_pq_params] - shaper_data[dolbypq_shaper_name] = dolbypq_shaper_data + shaper_data[dolby_pq_shaper_name] = dolby_pq_shaper_data - # Define the *Dolby PQ Shaper that considers a fixed linear range* + # Defining the *Dolby PQ shaper that includes the AP1* primaries. + dolby_pq_shaper_api1_name = '%s - AP1' % dolby_pq_shaper_name + dolby_pq_shaper_api1_colorspace = copy.deepcopy(dolby_pq_shaper_colorspace) + + dolby_pq_shaper_api1_colorspace.name = dolby_pq_shaper_api1_name + dolby_pq_shaper_api1_colorspace.description = ( + 'The %s color space' % dolby_pq_shaper_api1_name) + dolby_pq_shaper_api1_colorspace.aliases = [ + '%s_ap1' % compact(dolby_pq_shaper_name)] + dolby_pq_shaper_api1_colorspace.equality_group = dolby_pq_shaper_api1_name + + # *AP1* primaries to *AP0* primaries + dolby_pq_shaper_api1_colorspace.to_reference_transforms.append({ + 'type': 'matrix', + 'matrix': mat44_from_mat33(ACES_AP1_TO_AP0), + 'direction': 'forward' + }) + colorspaces.append(dolby_pq_shaper_api1_colorspace) + + return shaper_data, colorspaces + + +# ------------------------------------------------------------------------- +# *Shapers* +# ------------------------------------------------------------------------- +def create_shapers(aces_ctl_directory, + lut_directory, + lut_resolution_1d, + cleanup): + + """ + Creates sets of shaper colorspaces covering the *Log 2* and *Dolby PQ* + transfer functions and dynamic ranges suitable of use with the 48 nit, + 1000 nit, 2000 nit and 4000 nit *ACES Output Transforms* + + Parameters + ---------- + aces_ctl_directory : str or unicode + The path to the aces 'transforms/ctl/utilities' + lut_directory : str or unicode + The directory to use when generating LUTs + lut_resolution_1d : int + The resolution of generated 1D LUTs + cleanup : bool + Whether or not to clean up the intermediate images + + Returns + ------- + list of dicts + Values defining a set of Shapers + list of ColorSpaces + A list of Shaper colorspaces that covers a varying dynamic ranges and + transfer functions + """ + + colorspaces = [] + shaper_data = {} + + # Define the base *Log2 48 nits shaper* # - dolbypq_scaled_shaper_name = "Dolby PQ Scaled" - dolbypq_scaled_shaper_name_aliases = ["crv_%s" % "dolbypq_scaled"] + (log2_48nits_shaper_data, + log2_48nits_colorspaces) = create_shapers_log2(aces_ctl_directory, + lut_directory, + lut_resolution_1d, + cleanup, + 'Log2 48 nits Shaper', + 0.18, + -6.5, + 6.5) + colorspaces.extend(log2_48nits_colorspaces) + shaper_data.update(log2_48nits_shaper_data) + + # Define the base *Log2 1000 nits shaper* + # + (log2_1000nits_shaper_data, + log2_1000nits_colorspaces) = create_shapers_log2(aces_ctl_directory, + lut_directory, + lut_resolution_1d, + cleanup, + 'Log2 1000 nits Shaper', + 0.18, + -12.0, + 10.0) + colorspaces.extend(log2_1000nits_colorspaces) + shaper_data.update(log2_1000nits_shaper_data) + + # Define the base *Log2 2000 nits shaper* + # + (log2_2000nits_shaper_data, + log2_2000nits_colorspaces) = create_shapers_log2(aces_ctl_directory, + lut_directory, + lut_resolution_1d, + cleanup, + 'Log2 2000 nits Shaper', + 0.18, + -12.0, + 11.0) + colorspaces.extend(log2_2000nits_colorspaces) + shaper_data.update(log2_2000nits_shaper_data) + + # Define the base *Log2 4000 nits shaper* + # + (log2_4000nits_shaper_data, + log2_4000nits_colorspaces) = create_shapers_log2(aces_ctl_directory, + lut_directory, + lut_resolution_1d, + cleanup, + 'Log2 4000 nits Shaper', + 0.18, + -12.0, + 12.0) + colorspaces.extend(log2_4000nits_colorspaces) + shaper_data.update(log2_4000nits_shaper_data) + + # Define the base *Dolby PQ transfer function* + # + dolby_pq_shaper_name = 'Dolby PQ 10000' + dolby_pq_shaper_name_aliases = ['crv_%s' % 'dolbypq_10000'] - dolbypq_scaled_shaper_colorspace = create_dolbypq_scaled( + dolby_pq_shaper_colorspace = create_Dolby_PQ( aces_ctl_directory, lut_directory, lut_resolution_1d, cleanup, - name=dolbypq_scaled_shaper_name, - aliases=dolbypq_scaled_shaper_name_aliases) - colorspaces.append(dolbypq_scaled_shaper_colorspace) + name=dolby_pq_shaper_name, + aliases=dolby_pq_shaper_name_aliases) + colorspaces.append(dolby_pq_shaper_colorspace) # *Dolby PQ* shaper name and *CTL* transforms bundled up. - dolbypq_scaled_shaper_data = [ - dolbypq_scaled_shaper_name, + dolby_pq_shaper_data = [ + dolby_pq_shaper_name, os.path.join('%s', 'utilities', - 'ACESlib.OCIO_shaper_dolbypq_to_lin_param.a1.0.0.ctl'), + 'ACESlib.DolbyPQ_to_Lin.a1.0.0.ctl'), os.path.join('%s', 'utilities', - 'ACESlib.OCIO_shaper_lin_to_dolbypq_param.a1.0.0.ctl'), + 'ACESlib.Lin_to_DolbyPQ.a1.0.0.ctl'), 1.0, - log2_params] + {}] - shaper_data[dolbypq_scaled_shaper_name] = dolbypq_scaled_shaper_data + shaper_data[dolby_pq_shaper_name] = dolby_pq_shaper_data + # Define the *Dolby PQ 48 nits shaper* # - # Pick a specific shaper + (dolbypq_48nits_shaper_data, + dolbypq_48nits_colorspaces) = create_shapers_dolbypq(aces_ctl_directory, + lut_directory, + lut_resolution_1d, + cleanup, + 'Dolby PQ 48 nits Shaper', + 0.18, + -6.5, + 6.5) + colorspaces.extend(dolbypq_48nits_colorspaces) + shaper_data.update(dolbypq_48nits_shaper_data) + + # Define the *Dolby PQ 1000 nits shaper* # - rrt_shaper = log2_shaper_data - # rrt_shaper = dolbypq_scaled_shaper_data + (dolbypq_1000nits_shaper_data, + dolbypq_1000nits_colorspaces) = create_shapers_dolbypq(aces_ctl_directory, + lut_directory, + lut_resolution_1d, + cleanup, + 'Dolby PQ 1000 nits Shaper', + 0.18, + -12.0, + 10.0) + colorspaces.extend(dolbypq_1000nits_colorspaces) + shaper_data.update(dolbypq_1000nits_shaper_data) + + # Define the *Dolby PQ 2000 nits shaper* + # + (dolbypq_2000nits_shaper_data, + dolbypq_2000nits_colorspaces) = create_shapers_dolbypq(aces_ctl_directory, + lut_directory, + lut_resolution_1d, + cleanup, + 'Dolby PQ 2000 nits Shaper', + 0.18, + -12.0, + 11.0) + colorspaces.extend(dolbypq_2000nits_colorspaces) + shaper_data.update(dolbypq_2000nits_shaper_data) + + # Define the *Dolby PQ 4000 nits shaper* + # + (dolbypq_4000nits_shaper_data, + dolbypq_4000nits_colorspaces) = create_shapers_dolbypq(aces_ctl_directory, + lut_directory, + lut_resolution_1d, + cleanup, + 'Dolby PQ 4000 nits Shaper', + 0.18, + -12.0, + 12.0) + colorspaces.extend(dolbypq_4000nits_colorspaces) + shaper_data.update(dolbypq_4000nits_shaper_data) + + return shaper_data, colorspaces + +# ------------------------------------------------------------------------- +# *ODTs* +# ------------------------------------------------------------------------- +def create_ODTs(aces_ctl_directory, + lut_directory, + lut_resolution_1d, + lut_resolution_3d, + odt_info, + shaper_name, + cleanup, + linear_display_space, + log_display_space): + """ + Create ColorSpaces representing the *ACES Output Transforms* + + Parameters + ---------- + aces_ctl_directory : str or unicode + The path to the aces 'transforms/ctl/utilities' + lut_directory : str or unicode + The directory to use when generating LUTs + lut_resolution_1d : int + The resolution of generated 1D LUTs + lut_resolution_3d : int + The resolution of generated 3D LUTs + odt_info : dict + A collection of values that define the Output Transforms that need to be + generated + shaper_name : str or unicode, optional + The name of Shaper ColorSpace to use when generating LUTs + cleanup : bool + Whether or not to clean up the intermediate images + linear_display_space : lstr or unicode + The name of the ColorSpace to use for the raw or linear View + log_display_space : lstr or unicode + The name of the ColorSpace to use for the log View + + Returns + ------- + list of ColorSpaces + ColorSpaces representing the *ACES Output Transforms* + list of dicts + Collections of names and ColorSpaces corresponding to the Displays and + Views + """ + + colorspaces = [] + displays = {} + + # ------------------------------------------------------------------------- + # *RRT / ODT* Shaper Options + # ------------------------------------------------------------------------- + shaper_data, shaper_colorspaces = create_shapers(aces_ctl_directory, + lut_directory, + lut_resolution_1d, + cleanup) + + colorspaces.extend(shaper_colorspaces) + + # Assumes shaper has variants covering the range expected by the + # 48 nit, 1000 nit, 2000 nit and 4000 nit Ouput Transforms + rrt_shaper_48nits = shaper_data[shaper_name] + rrt_shaper_1000nits = shaper_data[shaper_name.replace("48 nits", "1000 nits")] + rrt_shaper_2000nits = shaper_data[shaper_name.replace("48 nits", "2000 nits")] + rrt_shaper_4000nits = shaper_data[shaper_name.replace("48 nits", "4000 nits")] # *RRT + ODT* combinations. sorted_odts = sorted(odt_info.iteritems(), key=lambda x: x[1]) @@ -1174,17 +1630,21 @@ def create_ODTs(aces_ctl_directory, for odt in sorted_odts: (odt_name, odt_values) = odt - # Generating legal range transform for *ODTs* that can generate - # either *legal* or *full* output. if odt_values['transformHasFullLegalSwitch']: - odt_name_legal = '%s - Legal' % odt_values['transformUserName'] - else: - odt_name_legal = odt_values['transformUserName'] + odt_legal['legalRange'] = 0 + odt_name_legal = odt_values['transformUserName'] odt_legal = odt_values.copy() - odt_legal['legalRange'] = 1 - - odt_aliases = ["out_%s" % compact(odt_name_legal)] + odt_aliases = ['out_%s' % compact(odt_name_legal)] + + if odt_name_legal in ['P3-D60 PQ (1000 nits)']: + rrt_shaper = rrt_shaper_1000nits + elif odt_name_legal in ['P3-D60 PQ (2000 nits)']: + rrt_shaper = rrt_shaper_2000nits + elif odt_name_legal in ['P3-D60 PQ (4000 nits)']: + rrt_shaper = rrt_shaper_4000nits + else: + rrt_shaper = rrt_shaper_48nits cs = create_ACES_RRT_plus_ODT( odt_name_legal, @@ -1192,62 +1652,34 @@ def create_ODTs(aces_ctl_directory, rrt_shaper, aces_ctl_directory, lut_directory, - lut_resolution_1d, lut_resolution_3d, cleanup, odt_aliases) colorspaces.append(cs) displays[odt_name_legal] = { - 'Linear': linear_display_space, + 'Raw': linear_display_space, 'Log': log_display_space, 'Output Transform': cs} - - # Generating full range transform for *ODTs* that can generate - # either *legal* or *full* output. - if odt_values['transformHasFullLegalSwitch']: - print('Generating full range ODT for %s' % odt_name) - - odt_name_full = '%s - Full' % odt_values['transformUserName'] - odt_full = odt_values.copy() - odt_full['legalRange'] = 0 - - odt_full_aliases = ["out_%s" % compact(odt_name_full)] - - cs_full = create_ACES_RRT_plus_ODT( - odt_name_full, - odt_full, - rrt_shaper, - aces_ctl_directory, - lut_directory, - lut_resolution_1d, - lut_resolution_3d, - cleanup, - odt_full_aliases) - colorspaces.append(cs_full) - - displays[odt_name_full] = { - 'Linear': linear_display_space, - 'Log': log_display_space, - 'Output Transform': cs_full} - - return (colorspaces, displays) + return colorspaces, displays def get_transform_info(ctl_transform): """ - Object description. + Returns the information stored in first couple of lines of an official + *ACES Transform* CTL file Parameters ---------- - parameter : type - Parameter description. + ctl_transform : str or unicode + The path to the CTL file to be scraped. Returns ------- - type - Return value description. + tuple + Combination of Transform ID, User Name, User Name Prefix and Full/Legal + switch """ with open(ctl_transform, 'rb') as fp: @@ -1260,33 +1692,35 @@ def get_transform_info(ctl_transform): transform_user_name_prefix = ( lines[2][3:].split('<')[1].split('>')[1].split('-')[0].strip()) - # Figuring out if this transform has options for processing full and legal range + # Figuring out if this transform has options for processing *full* and + # *legal* ranges. 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) + if line.strip() == 'input varying int legalRange = 0': + # 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, + return (transform_id, + transform_user_name, + transform_user_name_prefix, transform_full_legal_switch) def get_ODTs_info(aces_ctl_directory): """ - Object description. - - For versions after WGR9. + Returns the information describing the names and CTL files associated with + the *ACES Output Transforms* in a given ACES release Parameters ---------- - parameter : type - Parameter description. + aces_ctl_directory : str or unicode + The path to the base *ACES* CTL directory Returns ------- - type - Return value description. + dict of dicts + Collecton of dicts, one describing each *ACES Output Transform* """ # TODO: Investigate usage of *files_walker* definition here. @@ -1297,13 +1731,13 @@ def get_ODTs_info(aces_ctl_directory): for fname in file_list: all_odt.append((os.path.join(dir_name, fname))) - odt_CTLs = [x for x in all_odt if + odt_ctls = [x for x in all_odt if ('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) + for odt_ctl in odt_ctls: + odt_tokens = os.path.split(odt_ctl) # Handling nested directories. odt_path_tokens = os.path.split(odt_tokens[-2]) @@ -1312,48 +1746,48 @@ def get_ODTs_info(aces_ctl_directory): odt_path_tokens = os.path.split(odt_path_tokens[-2]) odt_dir = os.path.join(odt_path_tokens[-1], odt_dir) - # Building full name, - transform_CTL = odt_tokens[-1] - odt_name = string.join(transform_CTL.split('.')[1:-1], '.') + # Building full name. + transform_ctl = odt_tokens[-1] + odt_name = string.join(transform_ctl.split('.')[1:-1], '.') # Finding id, user name and user name prefix. - (transform_ID, + (transform_id, 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 + 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 + os.path.join(odt_tokens[-2], transform_ctl_inverse)): + transform_ctl_inverse = None - # Add to list of ODTs + # Adding to list of *ODTs*. odts[odt_name] = {} - odts[odt_name]['transformCTL'] = os.path.join(odt_dir, transform_CTL) - if transform_CTL_inverse is not None: + odts[odt_name]['transformCTL'] = os.path.join(odt_dir, transform_ctl) + if transform_ctl_inverse is not None: odts[odt_name]['transformCTLInverse'] = os.path.join( - odt_dir, transform_CTL_inverse) + odt_dir, transform_ctl_inverse) - odts[odt_name]['transformID'] = transform_ID + 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 - forward_CTL = odts[odt_name]['transformCTL'] + forward_ctl = odts[odt_name]['transformCTL'] print('ODT : %s' % odt_name) - print('\tTransform ID : %s' % transform_ID) + 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('\tForward ctl : %s' % forward_CTL) + print('\tForward ctl : %s' % forward_ctl) if 'transformCTLInverse' in odts[odt_name]: - inverse_CTL = odts[odt_name]['transformCTLInverse'] - print('\tInverse ctl : %s' % inverse_CTL) + inverse_ctl = odts[odt_name]['transformCTLInverse'] + print('\tInverse ctl : %s' % inverse_ctl) else: print('\tInverse ctl : %s' % 'None') @@ -1364,19 +1798,18 @@ def get_ODTs_info(aces_ctl_directory): def get_LMTs_info(aces_ctl_directory): """ - Object description. - - For versions after WGR9. + Returns the information describing the names and CTL files associated with + the *ACES Look Transforms* in a given ACES release Parameters ---------- - parameter : type - Parameter description. + aces_ctl_directory : str or unicode + The path to the base *ACES* CTL directory Returns ------- - type - Return value description. + dict of dicts + Collecton of dicts, one describing each *ACES Look Transform* """ # TODO: Investigate refactoring with previous definition. @@ -1388,14 +1821,14 @@ def get_LMTs_info(aces_ctl_directory): for fname in file_list: all_lmt.append((os.path.join(dir_name, fname))) - lmt_CTLs = [x for x in all_lmt if + lmt_ctls = [x for x in all_lmt if ('InvLMT' not in x) and ('README' not in x) and ( os.path.split(x)[-1][0] != '.')] lmts = {} - for lmt_CTL in lmt_CTLs: - lmt_tokens = os.path.split(lmt_CTL) + for lmt_ctl in lmt_ctls: + lmt_tokens = os.path.split(lmt_ctl) # Handlimg nested directories. lmt_path_tokens = os.path.split(lmt_tokens[-2]) @@ -1405,42 +1838,42 @@ def get_LMTs_info(aces_ctl_directory): lmt_dir = os.path.join(lmt_path_tokens[-1], lmt_dir) # Building full name. - transform_CTL = lmt_tokens[-1] - lmt_name = string.join(transform_CTL.split('.')[1:-1], '.') + transform_ctl = lmt_tokens[-1] + lmt_name = string.join(transform_ctl.split('.')[1:-1], '.') # Finding id, user name and user name prefix. - (transform_ID, + (transform_id, 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 + 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 + os.path.join(lmt_tokens[-2], transform_ctl_inverse)): + transform_ctl_inverse = None lmts[lmt_name] = {} - lmts[lmt_name]['transformCTL'] = os.path.join(lmt_dir, transform_CTL) - if transform_CTL_inverse is not None: + lmts[lmt_name]['transformCTL'] = os.path.join(lmt_dir, transform_ctl) + if transform_ctl_inverse is not None: lmts[lmt_name]['transformCTLInverse'] = os.path.join( - lmt_dir, transform_CTL_inverse) + lmt_dir, transform_ctl_inverse) - lmts[lmt_name]['transformID'] = transform_ID + lmts[lmt_name]['transformID'] = transform_id lmts[lmt_name]['transformUserNamePrefix'] = transform_user_name_prefix lmts[lmt_name]['transformUserName'] = transform_user_name - forward_CTL = lmts[lmt_name]['transformCTL'] + forward_ctl = lmts[lmt_name]['transformCTL'] print('LMT : %s' % lmt_name) - print('\tTransform ID : %s' % transform_ID) + 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) + print('\t Forward ctl : %s' % forward_ctl) if 'transformCTLInverse' in lmts[lmt_name]: - inverse_CTL = lmts[lmt_name]['transformCTLInverse'] - print('\t Inverse ctl : %s' % inverse_CTL) + inverse_ctl = lmts[lmt_name]['transformCTLInverse'] + print('\t Inverse ctl : %s' % inverse_ctl) else: print('\t Inverse ctl : %s' % 'None') @@ -1458,17 +1891,39 @@ def create_colorspaces(aces_ctl_directory, shaper_name, cleanup): """ - Generates the colorspace conversions. + Generates the *ACES* colorspaces, displays and views Parameters ---------- - parameter : type - Parameter description. + aces_ctl_directory : str or unicode + The path to the aces 'transforms/ctl/utilities' + lut_directory : str or unicode + The directory to use when generating LUTs + lut_resolution_1d : int + The resolution of generated 1D LUTs + lut_resolution_3d : int + The resolution of generated 3D LUTs + lmt_info : dict + A collection of values that define the Look Transforms that need to be + generated + odt_info : dict + A collection of values that define the Output Transforms that need to be + generated + shaper_name : str or unicode, optional + The name of Shaper ColorSpace to use when generating LUTs + cleanup : bool + Whether or not to clean up the intermediate images Returns ------- - type - Return value description. + tuple + A collection of values defining + the reference colorspace : ACES + a list of the colorspaces created + a list of the displays created + a list of the general log colorspace + a list of the role assignments + the name of the default display """ colorspaces = [] @@ -1484,14 +1939,13 @@ def create_colorspaces(aces_ctl_directory, lut_resolution_1d, cleanup) colorspaces.append(ACESproxy) - ACEScg = create_ACEScg(aces_ctl_directory, lut_directory, - lut_resolution_1d, cleanup) + ACEScg = create_ACEScg() colorspaces.append(ACEScg) - ADX10 = create_ADX(lut_directory, lut_resolution_1d, bit_depth=10) + ADX10 = create_ADX(lut_directory, bit_depth=10) colorspaces.append(ADX10) - ADX16 = create_ADX(lut_directory, lut_resolution_1d, bit_depth=16) + ADX16 = create_ADX(lut_directory, bit_depth=16) colorspaces.append(ADX16) lmts = create_LMTs(aces_ctl_directory, @@ -1499,7 +1953,6 @@ def create_colorspaces(aces_ctl_directory, lut_resolution_1d, lut_resolution_3d, lmt_info, - shaper_name, cleanup) colorspaces.extend(lmts) @@ -1514,10 +1967,11 @@ def create_colorspaces(aces_ctl_directory, ACEScc) colorspaces.extend(odts) - # Wish there was an automatic way to get this from the CTL - defaultDisplay = "sRGB (D60 sim.)" + # TODO: Investigate if there is a way to retrieve these values from *CTL*. + default_display = 'sRGB (D60 sim.)' + color_picking = 'Rec.709' - roles = {'color_picking': ACEScg.name, + roles = {'color_picking': color_picking, 'color_timing': ACEScc.name, 'compositing_log': ACEScc.name, 'data': '', @@ -1525,6 +1979,8 @@ def create_colorspaces(aces_ctl_directory, 'matte_paint': ACEScc.name, 'reference': '', 'scene_linear': ACEScg.name, - 'texture_paint': ''} + 'texture_paint': '', + 'compositing_linear': ACEScg.name, + 'rendering': ACEScg.name} - return ACES, colorspaces, displays, ACEScc, roles, defaultDisplay + return ACES, colorspaces, displays, ACEScc, roles, default_display