PR: Improve various code style aspects and implement "__future__" division support.
******
>>> 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
************
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'
__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"]
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),
lut_resolution_1d,
'float',
input_scale,
- 1.0,
+ 1,
{},
cleanup,
- aces_CTL_directory,
+ aces_ctl_directory,
min_value,
max_value)
# *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"]
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"]
# *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
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'})
'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*
-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:
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
'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
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',
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',
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)
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',
'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),
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({
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),
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',
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,
cleanup,
linear_display_space,
log_display_space):
+ """
+ Object description.
+
+ Parameters
+ ----------
+ parameter : type
+ Parameter description.
+
+ Returns
+ -------
+ type
+ Return value description.
+ """
colorspaces = []
displays = {}
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,
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 = [
# 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,
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
odt_name_legal,
odt_legal,
rrt_shaper,
- aces_CTL_directory,
+ aces_ctl_directory,
lut_directory,
lut_resolution_1d,
lut_resolution_3d,
odt_name_full,
odt_full,
rrt_shaper,
- aces_CTL_directory,
+ aces_ctl_directory,
lut_directory,
lut_resolution_1d,
lut_resolution_3d,
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):
"""
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.
# 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:
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
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']
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']
return odts
-def get_LMT_info(aces_CTL_directory):
+def get_LMTs_info(aces_ctl_directory):
"""
Object description.
# 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:
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
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,
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)
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
Defines objects creating the *ACES* configuration.
"""
-import math
+from __future__ import division
+
import os
-import shutil
import sys
import PyOpenColorIO as ocio
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'
'set_config_default_roles',
'write_config',
'generate_OCIO_transform',
+ 'add_colorspace_alias',
'create_config',
'generate_LUTs',
'generate_baked_LUTs',
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 = []
transform['interpolation']],
direction=direction_options[transform['direction']])
ocio_transforms.append(ocio_transform)
-
+
# matrix transform
elif transform['type'] == 'matrix':
ocio_transform = ocio.MatrixTransform()
# 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'])
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.
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,
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)
# Add alias
if reference_data.aliases != []:
add_colorspace_alias(config, reference_data,
- reference_data, reference_data.aliases)
+ reference_data, reference_data.aliases)
print("")
# 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('')
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,
# *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,
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)
# 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']
'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']:
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',
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']:
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',
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):
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,
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,
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.
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))
'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)
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'
# 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
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
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
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 = []
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)
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
Implements support for *Canon* colorspaces conversions and transfer functions.
"""
+from __future__ import division
+
import array
import os
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
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)
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 = []
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'
__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
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.
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)
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)
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)
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)
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',
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',
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',
Implements support for *RED* colorspaces conversions and transfer functions.
"""
+from __future__ import division
+
import array
import os
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)
Implements support for *Sony* colorspaces conversions and transfer functions.
"""
+from __future__ import division
+
import array
import os
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
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)
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)
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)
formats.
"""
+from __future__ import division
+
import array
import os
import sys
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.
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.
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.
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 = []
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.
input_scale,
output_scale,
global_params,
- aces_CTL_directory)
+ aces_ctl_directory)
generate_1d_LUT_from_image(transformed_LUT_image,
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.
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,
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')
a process or a list of other process wrappers which carry such data.\r
"""\r
\r
+from __future__ import division\r
+\r
import os\r
import sys\r
import traceback\r
Defines unit tests for *ACES* configuration.
"""
+from __future__ import division
+
import hashlib
import os
import re
Defines various package utilities objects.
"""
+from __future__ import division
+
import os
import re
+from collections import OrderedDict
import PyOpenColorIO as OCIO
'mat44_from_mat33',
'filter_words',
'files_walker',
- 'sanitize_path']
+ 'replace',
+ 'sanitize',
+ 'compact']
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.
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):
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.
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(((' ', '_'),
+ ('(', '_'),
+ (')', '_'),
+ ('.', '_'),
+ ('-', '_'),
+ ('___', '_'),
+ ('__', '_'),
+ ('_', ''))))
Creates the *ACES* configuration.
"""
+from __future__ import division
+
import os
import sys
Tests the *ACES* configuration.
"""
+from __future__ import division
+
import os
import unittest
import sys