import string
import sys
-# TODO: This restores the capability of running the script without having
-# added the package to PYTHONPATH, this is ugly and should ideally replaced by
-# dedicated executable in a /bin directory.
-sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
-
import PyOpenColorIO as ocio
import aces_ocio.create_arri_colorspaces as arri
generate_3d_LUT_from_CTL,
write_SPI_1d)
from aces_ocio.process import Process
-from aces_ocio.utilities import ColorSpace, mat44_from_mat33
+from aces_ocio.utilities import ColorSpace, mat44_from_mat33, sanitize_path
__author__ = 'ACES Developers'
__copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers'
return
# sys.exit()
- file_handle = open(config_path, mode='w')
- file_handle.write(config.serialize())
- file_handle.close()
+ with open(config_path, mode='w') as fp:
+ fp.write(config.serialize())
def generate_OCIO_transform(transforms):
cs.family = 'ACES'
cs.is_data = False
- ctls = [
- '%s/ACEScc/ACEScsc.ACEScc_to_ACES.a1.0.0.ctl' % aces_CTL_directory,
- # This transform gets back to the AP1 primaries
- # Useful as the 1d LUT is only covering the transfer function
- # The primaries switch is covered by the matrix below
- '%s/ACEScg/ACEScsc.ACES_to_ACEScg.a1.0.0.ctl' % aces_CTL_directory
- ]
+ ctls = [os.path.join(aces_CTL_directory,
+ 'ACEScc',
+ 'ACEScsc.ACEScc_to_ACES.a1.0.0.ctl'),
+ # This transform gets back to the AP1 primaries
+ # Useful as the 1d LUT is only covering the transfer function
+ # The primaries switch is covered by the matrix below
+ os.path.join(aces_CTL_directory,
+ 'ACEScg',
+ 'ACEScsc.ACES_to_ACEScg.a1.0.0.ctl')]
lut = '%s_to_ACES.spi1d' % name
- # Remove spaces and parentheses
- lut = lut.replace(' ', '_').replace(')', '_').replace('(', '_')
+ lut = sanitize_path(lut)
generate_1d_LUT_from_CTL(
os.path.join(lut_directory, lut),
cs.is_data = False
ctls = [
- '%s/ACESproxy/ACEScsc.ACESproxy10i_to_ACES.a1.0.0.ctl' % (
- aces_CTL_directory),
+ 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
- '%s/ACEScg/ACEScsc.ACES_to_ACEScg.a1.0.0.ctl' % aces_CTL_directory
- ]
+ os.path.join(aces_CTL_directory,
+ 'ACEScg',
+ 'ACEScsc.ACES_to_ACEScg.a1.0.0.ctl')]
lut = '%s_to_aces.spi1d' % name
- # Remove spaces and parentheses
- lut = lut.replace(' ', '_').replace(')', '_').replace('(', '_')
+ lut = sanitize_path(lut)
generate_1d_LUT_from_CTL(
os.path.join(lut_directory, lut),
cs.is_data = False
ctls = [
- '%s/utilities/ACESlib.OCIO_shaper_log2_to_lin_param.a1.0.0.ctl' % (
- aces_CTL_directory)]
+ os.path.join(aces_CTL_directory,
+ 'utilities',
+ 'ACESlib.OCIO_shaper_log2_to_lin_param.a1.0.0.ctl')]
lut = '%s_to_aces.spi1d' % name
- # Remove spaces and parentheses
- lut = lut.replace(' ', '_').replace(')', '_').replace('(', '_')
+ lut = sanitize_path(lut)
generate_1d_LUT_from_CTL(
os.path.join(lut_directory, lut),
if 'transformCTL' in lmt_values:
ctls = [
shaper_to_ACES_CTL % aces_CTL_directory,
- '%s/%s' % (aces_CTL_directory, lmt_values['transformCTL'])
- ]
+ os.path.join(aces_CTL_directory, lmt_values['transformCTL'])]
lut = '%s.%s.spi3d' % (shaper_name, lmt_name)
- # Remove spaces and parentheses
- lut = lut.replace(' ', '_').replace(')', '_').replace('(', '_')
+ lut = sanitize_path(lut)
generate_3d_LUT_from_CTL(
os.path.join(lut_directory, lut),
if 'transformCTLInverse' in lmt_values:
ctls = [
- '%s/%s' % (
- aces_CTL_directory, odt_values['transformCTLInverse']),
+ os.path.join(aces_CTL_directory,
+ odt_values['transformCTLInverse']),
shaper_from_ACES_CTL % aces_CTL_directory
]
lut = 'Inverse.%s.%s.spi3d' % (odt_name, shaper_name)
- # Remove spaces and parentheses
- lut = lut.replace(' ', '_').replace(')', '_').replace('(', '_')
+ lut = sanitize_path(lut)
generate_3d_LUT_from_CTL(
os.path.join(lut_directory, lut),
# Log 2 shaper name and CTL transforms bundled up
lmt_shaper_data = [
lmt_shaper_name,
- '%s/utilities/ACESlib.OCIO_shaper_log2_to_lin_param.a1.0.0.ctl',
- '%s/utilities/ACESlib.OCIO_shaper_lin_to_log2_param.a1.0.0.ctl',
+ os.path.join('%s',
+ 'utilities',
+ 'ACESlib.OCIO_shaper_log2_to_lin_param.a1.0.0.ctl'),
+ os.path.join('%s',
+ 'utilities',
+ 'ACESlib.OCIO_shaper_lin_to_log2_param.a1.0.0.ctl'),
shaper_input_scale_generic_log2,
- lmt_params
- ]
+ lmt_params]
sorted_LMTs = sorted(lmt_info.iteritems(), key=lambda x: x[1])
print(sorted_LMTs)
ctls = [
shaper_to_ACES_CTL % aces_CTL_directory,
- '%s/rrt/RRT.a1.0.0.ctl' % aces_CTL_directory,
- '%s/odt/%s' % (aces_CTL_directory, odt_values['transformCTL'])
- ]
+ os.path.join(aces_CTL_directory,
+ 'rrt',
+ 'RRT.a1.0.0.ctl'),
+ os.path.join(aces_CTL_directory,
+ 'odt',
+ odt_values['transformCTL'])]
lut = '%s.RRT.a1.0.0.%s.spi3d' % (shaper_name, odt_name)
- # Remove spaces and parentheses
- lut = lut.replace(' ', '_').replace(')', '_').replace('(', '_')
+ lut = sanitize_path(lut)
generate_3d_LUT_from_CTL(
os.path.join(lut_directory, lut),
cs.to_reference_transforms.append(shaper_inverse)
elif 'transformCTLInverse' in odt_values:
ctls = [
- '%s/odt/%s' % (
- aces_CTL_directory, odt_values['transformCTLInverse']),
- '%s/rrt/InvRRT.a1.0.0.ctl' % aces_CTL_directory,
+ os.path.join(aces_CTL_directory,
+ 'odt',
+ odt_values['transformCTLInverse']),
+ os.path.join(aces_CTL_directory,
+ 'rrt',
+ 'InvRRT.a1.0.0.ctl'),
shaper_from_ACES_CTL % aces_CTL_directory
]
lut = 'InvRRT.a1.0.0.%s.%s.spi3d' % (odt_name, shaper_name)
- # Remove spaces and parentheses
- lut = lut.replace(' ', '_').replace(')', '_').replace('(', '_')
+ lut = sanitize_path(lut)
generate_3d_LUT_from_CTL(
os.path.join(lut_directory, lut),
# Log 2 shaper name and CTL transforms bundled up
log2_shaper_data = [
log2_shaper_name,
- '%s/utilities/ACESlib.OCIO_shaper_log2_to_lin_param.a1.0.0.ctl',
- '%s/utilities/ACESlib.OCIO_shaper_lin_to_log2_param.a1.0.0.ctl',
+ os.path.join('%s',
+ 'utilities',
+ 'ACESlib.OCIO_shaper_log2_to_lin_param.a1.0.0.ctl'),
+ os.path.join('%s',
+ 'utilities',
+ 'ACESlib.OCIO_shaper_lin_to_log2_param.a1.0.0.ctl'),
shaper_input_scale_generic_log2,
- log2_params
- ]
+ log2_params]
shaper_data[log2_shaper_name] = log2_shaper_data
args += ['--cubesize', str(lut_resolution_3d)]
args += ['--format',
'icc',
- '%s/photoshop/%s for %s.icc' % (baked_directory,
- odt_name,
- input_space)]
+ os.path.join(baked_directory,
+ 'photoshop',
+ '%s for %s.icc' % (odt_name, input_space))]
bake_LUT = Process(description='bake a LUT',
cmd='ociobakelut',
'--shapersize', str(lut_resolution_shaper)]
args += ['--cubesize', str(lut_resolution_3d)]
- fargs = ['--format', 'flame', '%s/flame/%s for %s Flame.3dl' % (
- baked_directory, odt_name, input_space)]
+ fargs = ['--format',
+ 'flame',
+ os.path.join(
+ baked_directory,
+ 'flame',
+ '%s for %s Flame.3dl' % (odt_name, input_space))]
bake_LUT = Process(description='bake a LUT',
cmd='ociobakelut',
args=(args + fargs))
bake_LUT.execute()
- largs = ['--format', 'lustre', '%s/lustre/%s for %s Lustre.3dl' % (
- baked_directory, odt_name, input_space)]
+ largs = ['--format',
+ 'lustre',
+ os.path.join(
+ baked_directory,
+ 'lustre',
+ '%s for %s Lustre.3dl' % (odt_name, input_space))]
bake_LUT = Process(description='bake a LUT',
cmd='ociobakelut',
args=(args + largs))
args += ['--cubesize', str(lut_resolution_3d)]
- margs = ['--format', 'cinespace', '%s/maya/%s for %s Maya.csp' % (
- baked_directory, odt_name, input_space)]
+ margs = ['--format',
+ 'cinespace',
+ os.path.join(
+ baked_directory,
+ 'maya',
+ '%s for %s Maya.csp' % (odt_name, input_space))]
bake_LUT = Process(description='bake a LUT',
cmd='ociobakelut',
args=(args + margs))
bake_LUT.execute()
- hargs = ['--format', 'houdini',
- '%s/houdini/%s for %s Houdini.lut' % (
- baked_directory, odt_name, input_space)]
+ hargs = ['--format',
+ 'houdini',
+ os.path.join(
+ baked_directory,
+ 'houdini',
+ '%s for %s Houdini.lut' % (odt_name, input_space))]
bake_LUT = Process(description='bake a LUT',
cmd='ociobakelut',
args=(args + hargs))
Return value description.
"""
- dirs = [config_directory, '%s/luts' % config_directory]
+ dirs = [config_directory, os.path.join(config_directory, 'luts')]
if bake_secondary_LUTs:
- dirs.extend(['%s/baked' % config_directory,
- '%s/baked/flame' % config_directory,
- '%s/baked/photoshop' % config_directory,
- '%s/baked/houdini' % config_directory,
- '%s/baked/lustre' % config_directory,
- '%s/baked/maya' % config_directory])
+ dirs.extend([os.path.join(config_directory, 'baked'),
+ os.path.join(config_directory, 'baked', 'flame'),
+ os.path.join(config_directory, 'baked', 'photoshop'),
+ os.path.join(config_directory, 'baked', 'houdini'),
+ os.path.join(config_directory, 'baked', 'lustre'),
+ os.path.join(config_directory, 'baked', 'maya')])
for d in dirs:
not os.path.exists(d) and os.mkdir(d)
Return value description.
"""
- # TODO: Use *with* statement.
- fp = open(ctl_transform, 'rb')
-
- # Read lines
- lines = fp.readlines()
+ with open(ctl_transform, 'rb') as fp:
+ lines = fp.readlines()
# Grab transform ID and User Name
transform_ID = lines[1][3:].split('<')[1].split('>')[1].strip()
transform_user_name_prefix = (
lines[2][3:].split('<')[1].split('>')[1].split('-')[0].strip())
# print(transformUserName)
- fp.close()
return transform_ID, transform_user_name, transform_user_name_prefix
(transform_ID,
transform_user_name,
transform_user_name_prefix) = get_transform_info(
- '%s/odt/%s/%s' % (aces_CTL_directory, odt_dir, transform_CTL))
+ os.path.join(aces_CTL_directory, 'odt', odt_dir, transform_CTL))
# Find inverse
transform_CTL_inverse = 'InvODT.%s.ctl' % odt_name
(transform_ID,
transform_user_name,
transform_user_name_prefix) = get_transform_info(
- '%s/%s/%s' % (aces_CTL_directory, lmt_dir, transform_CTL))
+ os.path.join(aces_CTL_directory, lmt_dir, transform_CTL))
# Find inverse
transform_CTL_inverse = 'InvLMT.%s.ctl' % lmt_name
create_config_dir(config_directory, bake_secondary_LUTs)
# Generate config data and LUTs for different transforms
- lut_directory = '%s/luts' % config_directory
+ lut_directory = os.path.join(config_directory, 'luts')
shaper_name = 'Output Shaper'
config_data = generate_LUTs(odt_info,
lmt_info,
print('\n\n\n')
# Write the config to disk
- write_config(config, '%s/config.ocio' % config_directory)
+ write_config(config,
+ os.path.join(config_directory, 'config.ocio'))
# Create a config that will work well with Nuke using the previously
# generated LUTs.
print('\n\n\n')
# Write the config to disk
- write_config(nuke_config, '%s/nuke_config.ocio' % config_directory)
+ write_config(nuke_config,
+ os.path.join(config_directory, 'nuke_config.ocio'))
# Bake secondary LUTs using the config
if bake_secondary_LUTs:
generate_baked_LUTs(odt_info,
shaper_name,
- '%s/baked' % config_directory,
- '%s/config.ocio' % config_directory,
+ os.path.join(config_directory, 'baked'),
+ os.path.join(config_directory, 'config.ocio'),
lut_resolution_1d,
lut_resolution_3d,
lut_resolution_1d)
version='createACESConfig 0.1',
usage='%prog [options]')
p.add_option('--acesCTLDir', '-a', default=os.environ.get(
- 'ACES_OCIO_CTL_DIRECTORY', None))
+ ACES_OCIO_CTL_DIRECTORY_ENVIRON, None))
p.add_option('--configDir', '-c', default=os.environ.get(
- 'ACES_OCIO_CONFIGURATION_DIRECTORY', None))
+ ACES_OCIO_CONFIGURATION_DIRECTORY_ENVIRON, None))
p.add_option('--lutResolution1d', default=4096)
p.add_option('--lutResolution3d', default=64)
p.add_option('--dontBakeSecondaryLUTs', action='store_true')
config_directory = options.configDir
lut_resolution_1d = int(options.lutResolution1d)
lut_resolution_3d = int(options.lutResolution3d)
- bake_secondary_LUTs = not (options.dontBakeSecondaryLUTs)
- cleanup_temp_images = not (options.keepTempImages)
+ bake_secondary_LUTs = not options.dontBakeSecondaryLUTs
+ cleanup_temp_images = not options.keepTempImages
+ # TODO: Investigate the following statements.
try:
args_start = sys.argv.index('--') + 1
args = sys.argv[args_start:]
print('command line : \n%s\n' % ' '.join(sys.argv))
- # TODO: Use assertion and mention environment variables.
- if not aces_CTL_directory:
- print('process: No ACES CTL directory specified')
- return
- if not config_directory:
- print('process: No configuration directory specified')
- return
- #
- # Generate the configuration
- #
+ assert aces_CTL_directory is not None, (
+ 'process: No "{0}" environment variable defined or no "ACES CTL" '
+ 'directory specified'.format(
+ ACES_OCIO_CTL_DIRECTORY_ENVIRON))
+
+ assert config_directory is not None, (
+ 'process: No "{0}" environment variable defined or no configuration '
+ 'directory specified'.format(
+ ACES_OCIO_CONFIGURATION_DIRECTORY_ENVIRON))
+
return create_ACES_config(aces_CTL_directory,
config_directory,
lut_resolution_1d,