-#
-# Functions to generate color space definitions and LUTs for transforms for a
-# specific ACES release.
-#
-
-# Output is a list of colorspaces and transforms that convert between those
-# colorspaces and reference color space, ACES
-def generateLUTs(odtInfo,
- lmtInfo,
- shaperName,
- acesCTLReleaseDir,
- lutDir,
- lutResolution1d=4096,
- lutResolution3d=64,
- cleanup=True):
- print("generateLUTs - begin")
- configData = {}
-
- #
- # Define the reference color space
- #
- ACES = ColorSpace('ACES2065-1')
- ACES.description = (
- 'The Academy Color Encoding System reference color space')
- ACES.equalityGroup = ''
- ACES.family = 'ACES'
- ACES.isData = False
- ACES.allocationType = OCIO.Constants.ALLOCATION_LG2
- ACES.allocationVars = [-15, 6]
-
- configData['referenceColorSpace'] = ACES
-
- #
- # Define the displays
- #
- configData['displays'] = {}
-
- #
- # Define the other color spaces
- #
- configData['colorSpaces'] = []
-
- # Matrix converting ACES AP1 primaries to AP0
- acesAP1toAP0 = [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
- acesAP0toXYZ = [0.9525523959, 0.0000000000, 0.0000936786,
- 0.3439664498, 0.7281660966, -0.0721325464,
- 0.0000000000, 0.0000000000, 1.0088251844]
-
- #
- # ACEScc
- #
- def createACEScc(name='ACEScc',
- minValue=0.0,
- maxValue=1.0,
- inputScale=1.0):
- cs = ColorSpace(name)
- cs.description = "The %s color space" % name
- cs.equalityGroup = ''
- cs.family = 'ACES'
- cs.isData = False
-
- ctls = [
- '%s/ACEScc/ACEScsc.ACEScc_to_ACES.a1.0.0.ctl' % acesCTLReleaseDir,
- # 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' % acesCTLReleaseDir
- ]
- lut = "%s_to_ACES.spi1d" % name
-
- # Remove spaces and parentheses
- lut = lut.replace(' ', '_').replace(')', '_').replace('(', '_')
-
- genlut.generate1dLUTFromCTL(
- lutDir + "/" + lut,
- ctls,
- lutResolution1d,
- 'float',
- inputScale,
- 1.0,
- {},
- cleanup,
- acesCTLReleaseDir,
- minValue,
- maxValue)
-
- cs.toReferenceTransforms = []
- cs.toReferenceTransforms.append({
- 'type': 'lutFile',
- 'path': lut,
- 'interpolation': 'linear',
- 'direction': 'forward'
- })
-
- # AP1 primaries to AP0 primaries
- cs.toReferenceTransforms.append({
- 'type': 'matrix',
- 'matrix': mat44FromMat33(acesAP1toAP0),
- 'direction': 'forward'
- })
-
- cs.fromReferenceTransforms = []
- return cs
-
- ACEScc = createACEScc()
- configData['colorSpaces'].append(ACEScc)
-
- #
- # ACESproxy
- #
- def createACESProxy(name='ACESproxy'):
- cs = ColorSpace(name)
- cs.description = "The %s color space" % name
- cs.equalityGroup = ''
- cs.family = 'ACES'
- cs.isData = False
-
- ctls = [
- '%s/ACESproxy/ACEScsc.ACESproxy10i_to_ACES.a1.0.0.ctl' % (
- acesCTLReleaseDir),
- # 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' % acesCTLReleaseDir
- ]
- lut = "%s_to_aces.spi1d" % name
-
- # Remove spaces and parentheses
- lut = lut.replace(' ', '_').replace(')', '_').replace('(', '_')
-
- genlut.generate1dLUTFromCTL(
- lutDir + "/" + lut,
- ctls,
- lutResolution1d,
- 'uint16',
- 64.0,
- 1.0,
- {},
- cleanup,
- acesCTLReleaseDir)
-
- cs.toReferenceTransforms = []
- cs.toReferenceTransforms.append({
- 'type': 'lutFile',
- 'path': lut,
- 'interpolation': 'linear',
- 'direction': 'forward'
- })
-
- # AP1 primaries to AP0 primaries
- cs.toReferenceTransforms.append({
- 'type': 'matrix',
- 'matrix': mat44FromMat33(acesAP1toAP0),
- 'direction': 'forward'
- })
-
- cs.fromReferenceTransforms = []
- return cs
-
- ACESproxy = createACESProxy()
- configData['colorSpaces'].append(ACESproxy)
-
- #
- # ACEScg
- #
- def createACEScg(name='ACEScg'):
- cs = ColorSpace(name)
- cs.description = "The %s color space" % name
- cs.equalityGroup = ''
- cs.family = 'ACES'
- cs.isData = False
-
- cs.toReferenceTransforms = []
-
- # AP1 primaries to AP0 primaries
- cs.toReferenceTransforms.append({
- 'type': 'matrix',
- 'matrix': mat44FromMat33(acesAP1toAP0),
- 'direction': 'forward'
- })
-
- cs.fromReferenceTransforms = []
- return cs
-
- ACEScg = createACEScg()
- configData['colorSpaces'].append(ACEScg)
-
- #
- # ADX
- #
- def createADX(bitdepth=10, name='ADX'):
- name = "%s%s" % (name, bitdepth)
- cs = ColorSpace(name)
- cs.description = "%s color space - used for film scans" % name
- cs.equalityGroup = ''
- cs.family = 'ADX'
- cs.isData = False
-
- if bitdepth == 10:
- cs.bitDepth = bitDepth = OCIO.Constants.BIT_DEPTH_UINT10
- adx_to_cdd = [1023.0 / 500.0, 0.0, 0.0, 0.0,
- 0.0, 1023.0 / 500.0, 0.0, 0.0,
- 0.0, 0.0, 1023.0 / 500.0, 0.0,
- 0.0, 0.0, 0.0, 1.0]
- offset = [-95.0 / 500.0, -95.0 / 500.0, -95.0 / 500.0, 0.0]
- elif bitdepth == 16:
- cs.bitDepth = bitDepth = 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]
-
- cs.toReferenceTransforms = []
-
- # Convert from ADX to Channel-Dependent Density
- cs.toReferenceTransforms.append({
- 'type': 'matrix',
- 'matrix': adx_to_cdd,
- 'offset': offset,
- 'direction': 'forward'
- })
-
- # Convert from Channel-Dependent Density to Channel-Independent Density
- cs.toReferenceTransforms.append({
- 'type': 'matrix',
- '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],
- 'direction': 'forward'
- })
-
- # Copied from Alex Fry's adx_cid_to_rle.py
- def createCIDtoRLELUT():
- def interpolate1D(x, xp, fp):
- return numpy.interp(x, xp, fp)
-
- LUT_1D_xp = [-0.190000000000000,
- 0.010000000000000,
- 0.028000000000000,
- 0.054000000000000,
- 0.095000000000000,
- 0.145000000000000,
- 0.220000000000000,
- 0.300000000000000,
- 0.400000000000000,
- 0.500000000000000,
- 0.600000000000000]
-
- LUT_1D_fp = [-6.000000000000000,
- -2.721718645000000,
- -2.521718645000000,
- -2.321718645000000,
- -2.121718645000000,
- -1.921718645000000,
- -1.721718645000000,
- -1.521718645000000,
- -1.321718645000000,
- -1.121718645000000,
- -0.926545676714876]
-
- REF_PT = ((7120.0 - 1520.0) / 8000.0 * (100.0 / 55.0) -
- math.log(0.18, 10.0))
-
- def cid_to_rle(x):
- if x <= 0.6:
- return interpolate1D(x, LUT_1D_xp, LUT_1D_fp)
- return (100.0 / 55.0) * x - REF_PT
-
- def Fit(value, fromMin, fromMax, toMin, toMax):
- if fromMin == fromMax:
- raise ValueError("fromMin == fromMax")
- return (value - fromMin) / (fromMax - fromMin) * (
- toMax - toMin) + toMin
-
- NUM_SAMPLES = 2 ** 12
- RANGE = (-0.19, 3.0)
- data = []
- for i in xrange(NUM_SAMPLES):
- x = i / (NUM_SAMPLES - 1.0)
- x = Fit(x, 0.0, 1.0, RANGE[0], RANGE[1])
- data.append(cid_to_rle(x))
-
- lut = 'ADX_CID_to_RLE.spi1d'
- genlut.writeSPI1D(lutDir + "/" + lut, RANGE[0], RANGE[1], data,
- NUM_SAMPLES, 1)
-
- return lut
-
- # Convert Channel Independent Density values to Relative Log Exposure
- # values.
- lut = createCIDtoRLELUT()
- cs.toReferenceTransforms.append({
- 'type': 'lutFile',
- 'path': lut,
- 'interpolation': 'linear',
- 'direction': 'forward'
- })
-
- # Convert Relative Log Exposure values to Relative Exposure values
- cs.toReferenceTransforms.append({
- 'type': 'log',
- 'base': 10,
- 'direction': 'inverse'
- })
-
- # Convert Relative Exposure values to ACES values
- cs.toReferenceTransforms.append({
- 'type': 'matrix',
- 'matrix': [0.72286, 0.12630, 0.15084, 0,
- 0.11923, 0.76418, 0.11659, 0,
- 0.01427, 0.08213, 0.90359, 0,
- 0.0, 0.0, 0.0, 1.0],
- 'direction': 'forward'
- })
-
- cs.fromReferenceTransforms = []
- return cs
-
- ADX10 = createADX(bitdepth=10)
- configData['colorSpaces'].append(ADX10)
-
- ADX16 = createADX(bitdepth=16)
- configData['colorSpaces'].append(ADX16)
-
- #
- # Camera Input Transforms
- #
-
- # RED color spaces to ACES
- redColorSpaces = red.createColorSpaces(lutDir, lutResolution1d)
- for cs in redColorSpaces:
- configData['colorSpaces'].append(cs)
-
- # Canon-Log to ACES
- canonColorSpaces = canon.createColorSpaces(lutDir, lutResolution1d)
- for cs in canonColorSpaces:
- configData['colorSpaces'].append(cs)
-
- # SLog to ACES
- sonyColorSpaces = sony.createColorSpaces(lutDir, lutResolution1d)
- for cs in sonyColorSpaces:
- configData['colorSpaces'].append(cs)
-
- # LogC to ACES
- arriColorSpaces = arri.createColorSpaces(lutDir, lutResolution1d)
- for cs in arriColorSpaces:
- configData['colorSpaces'].append(cs)
-
- #
- # Generic log transform
- #
- def createGenericLog(name='log',
- minValue=0.0,
- maxValue=1.0,
- inputScale=1.0,
- middleGrey=0.18,
- minExposure=-6.0,
- maxExposure=6.5,
- lutResolution1d=lutResolution1d):
- cs = ColorSpace(name)
- cs.description = "The %s color space" % name
- cs.equalityGroup = name
- cs.family = 'Utility'
- cs.isData = False
-
- ctls = [
- '%s/utilities/ACESlib.OCIO_shaper_log2_to_lin_param.a1.0.0.ctl' % (
- acesCTLReleaseDir)
- ]
- lut = "%s_to_aces.spi1d" % name
-
- # Remove spaces and parentheses
- lut = lut.replace(' ', '_').replace(')', '_').replace('(', '_')
-
- genlut.generate1dLUTFromCTL(
- lutDir + "/" + lut,
- ctls,
- lutResolution1d,
- 'float',
- inputScale,
- 1.0,
- {
- 'middleGrey': middleGrey,
- 'minExposure': minExposure,
- 'maxExposure': maxExposure
- },
- cleanup,
- acesCTLReleaseDir,
- minValue,
- maxValue)
-
- cs.toReferenceTransforms = []
- cs.toReferenceTransforms.append({
- 'type': 'lutFile',
- 'path': lut,
- 'interpolation': 'linear',
- 'direction': 'forward'
- })
-
- cs.fromReferenceTransforms = []
- return cs
-
- #
- # ACES LMTs
- #
- def createACESLMT(lmtName,
- lmtValues,
- shaperInfo,
- lutResolution1d=1024,
- lutResolution3d=64,
- cleanup=True):
- cs = ColorSpace("%s" % lmtName)
- cs.description = "The ACES Look Transform: %s" % lmtName
- cs.equalityGroup = ''
- cs.family = 'Look'
- cs.isData = False
-
- import pprint
-
- pprint.pprint(lmtValues)
-
- #
- # Generate the shaper transform
- #
- (shaperName,
- shaperToACESCTL,
- shaperFromACESCTL,
- shaperInputScale,
- shaperParams) = shaperInfo
-
- shaperLut = "%s_to_aces.spi1d" % shaperName
- if (not os.path.exists(lutDir + "/" + shaperLut)):
- ctls = [
- shaperToACESCTL % acesCTLReleaseDir
- ]
-
- # Remove spaces and parentheses
- shaperLut = shaperLut.replace(
- ' ', '_').replace(')', '_').replace('(', '_')
-
- genlut.generate1dLUTFromCTL(
- lutDir + "/" + shaperLut,
- ctls,
- lutResolution1d,
- 'float',
- 1.0 / shaperInputScale,
- 1.0,
- shaperParams,
- cleanup,
- acesCTLReleaseDir)
-
- shaperOCIOTransform = {
- 'type': 'lutFile',
- 'path': shaperLut,
- 'interpolation': 'linear',
- 'direction': 'inverse'
- }
-
- #
- # Generate the forward transform
- #
- cs.fromReferenceTransforms = []
-
- if 'transformCTL' in lmtValues:
- ctls = [
- shaperToACESCTL % acesCTLReleaseDir,
- '%s/%s' % (acesCTLReleaseDir, lmtValues['transformCTL'])
- ]
- lut = "%s.%s.spi3d" % (shaperName, lmtName)
-
- # Remove spaces and parentheses
- lut = lut.replace(' ', '_').replace(')', '_').replace('(', '_')
-
- genlut.generate3dLUTFromCTL(
- lutDir + "/" + lut,
- ctls,
- lutResolution3d,
- 'float',
- 1.0 / shaperInputScale,
- 1.0,
- shaperParams,
- cleanup,
- acesCTLReleaseDir)
-
- cs.fromReferenceTransforms.append(shaperOCIOTransform)
- cs.fromReferenceTransforms.append({
- 'type': 'lutFile',
- 'path': lut,
- 'interpolation': 'tetrahedral',
- 'direction': 'forward'
- })
-
- #
- # Generate the inverse transform
- #
- cs.toReferenceTransforms = []
-
- if 'transformCTLInverse' in lmtValues:
- ctls = [
- '%s/%s' % (
- acesCTLReleaseDir, odtValues['transformCTLInverse']),
- shaperFromACESCTL % acesCTLReleaseDir
- ]
- lut = "Inverse.%s.%s.spi3d" % (odtName, shaperName)
-
- # Remove spaces and parentheses
- lut = lut.replace(' ', '_').replace(')', '_').replace('(', '_')
-
- genlut.generate3dLUTFromCTL(
- lutDir + "/" + lut,
- ctls,
- lutResolution3d,
- 'half',
- 1.0,
- shaperInputScale,
- shaperParams,
- cleanup,
- acesCTLReleaseDir)
-
- cs.toReferenceTransforms.append({
- 'type': 'lutFile',
- 'path': lut,
- 'interpolation': 'tetrahedral',
- 'direction': 'forward'
- })
-
- shaperInverse = shaperOCIOTransform.copy()
- shaperInverse['direction'] = 'forward'
- cs.toReferenceTransforms.append(shaperInverse)
-
- return cs
-
- #
- # LMT Shaper
- #
-
- lmtLutResolution1d = max(4096, lutResolution1d)
- lmtLutResolution3d = max(65, lutResolution3d)
-
- # Log 2 shaper
- lmtShaperName = 'LMT Shaper'
- lmtParams = {
- 'middleGrey': 0.18,
- 'minExposure': -10.0,
- 'maxExposure': 6.5
- }
- lmtShaper = createGenericLog(name=lmtShaperName,
- middleGrey=lmtParams['middleGrey'],
- minExposure=lmtParams['minExposure'],
- maxExposure=lmtParams['maxExposure'],
- lutResolution1d=lmtLutResolution1d)
- configData['colorSpaces'].append(lmtShaper)
-
- shaperInputScale_genericLog2 = 1.0
-
- # Log 2 shaper name and CTL transforms bundled up
- lmtShaperData = [
- lmtShaperName,
- '%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',
- shaperInputScale_genericLog2,
- lmtParams
- ]
-
- sortedLMTs = sorted(lmtInfo.iteritems(), key=lambda x: x[1])
- print(sortedLMTs)
- for lmt in sortedLMTs:
- (lmtName, lmtValues) = lmt
- cs = createACESLMT(
- lmtValues['transformUserName'],
- lmtValues,
- lmtShaperData,
- lmtLutResolution1d,
- lmtLutResolution3d,
- cleanup)
- configData['colorSpaces'].append(cs)
-
- #
- # ACES RRT with the supplied ODT
- #
- def createACESRRTplusODT(odtName,
- odtValues,
- shaperInfo,
- lutResolution1d=1024,
- lutResolution3d=64,
- cleanup=True):
- cs = ColorSpace("%s" % odtName)
- cs.description = "%s - %s Output Transform" % (
- odtValues['transformUserNamePrefix'], odtName)
- cs.equalityGroup = ''
- cs.family = 'Output'
- cs.isData = False
-
- import pprint
-
- pprint.pprint(odtValues)
-
- #
- # Generate the shaper transform
- #
- # if 'shaperCTL' in odtValues:
- (shaperName,
- shaperToACESCTL,
- shaperFromACESCTL,
- shaperInputScale,
- shaperParams) = shaperInfo
-
- if 'legalRange' in odtValues:
- shaperParams['legalRange'] = odtValues['legalRange']
- else:
- shaperParams['legalRange'] = 0
-
- shaperLut = "%s_to_aces.spi1d" % shaperName
- if (not os.path.exists(lutDir + "/" + shaperLut)):
- ctls = [
- shaperToACESCTL % acesCTLReleaseDir
- ]
-
- # Remove spaces and parentheses
- shaperLut = shaperLut.replace(
- ' ', '_').replace(')', '_').replace('(', '_')
-
- genlut.generate1dLUTFromCTL(
- lutDir + "/" + shaperLut,
- ctls,
- lutResolution1d,
- 'float',
- 1.0 / shaperInputScale,
- 1.0,
- shaperParams,
- cleanup,
- acesCTLReleaseDir)
-
- shaperOCIOTransform = {
- 'type': 'lutFile',
- 'path': shaperLut,
- 'interpolation': 'linear',
- 'direction': 'inverse'
- }
-
- #
- # Generate the forward transform
- #
- cs.fromReferenceTransforms = []
-
- if 'transformLUT' in odtValues:
- # Copy into the lut dir
- transformLUTFileName = os.path.basename(odtValues['transformLUT'])
- lut = lutDir + "/" + transformLUTFileName
- shutil.copy(odtValues['transformLUT'], lut)
-
- cs.fromReferenceTransforms.append(shaperOCIOTransform)
- cs.fromReferenceTransforms.append({
- 'type': 'lutFile',
- 'path': transformLUTFileName,
- 'interpolation': 'tetrahedral',
- 'direction': 'forward'
- })
- elif 'transformCTL' in odtValues:
- # shaperLut
-
- ctls = [
- shaperToACESCTL % acesCTLReleaseDir,
- '%s/rrt/RRT.a1.0.0.ctl' % acesCTLReleaseDir,
- '%s/odt/%s' % (acesCTLReleaseDir, odtValues['transformCTL'])
- ]
- lut = "%s.RRT.a1.0.0.%s.spi3d" % (shaperName, odtName)
-
- # Remove spaces and parentheses
- lut = lut.replace(' ', '_').replace(')', '_').replace('(', '_')
-
- genlut.generate3dLUTFromCTL(lutDir + "/" + lut,
- # shaperLUT,
- ctls,
- lutResolution3d,
- 'float',
- 1.0 / shaperInputScale,
- 1.0,
- shaperParams,
- cleanup,
- acesCTLReleaseDir)
-
- cs.fromReferenceTransforms.append(shaperOCIOTransform)
- cs.fromReferenceTransforms.append({
- 'type': 'lutFile',
- 'path': lut,
- 'interpolation': 'tetrahedral',
- 'direction': 'forward'
- })
-
- #
- # Generate the inverse transform
- #
- cs.toReferenceTransforms = []
-
- if 'transformLUTInverse' in odtValues:
- # Copy into the lut dir
- transformLUTInverseFileName = os.path.basename(
- odtValues['transformLUTInverse'])
- lut = lutDir + "/" + transformLUTInverseFileName
- shutil.copy(odtValues['transformLUTInverse'], lut)
-
- cs.toReferenceTransforms.append({
- 'type': 'lutFile',
- 'path': transformLUTInverseFileName,
- 'interpolation': 'tetrahedral',
- 'direction': 'forward'
- })
-
- shaperInverse = shaperOCIOTransform.copy()
- shaperInverse['direction'] = 'forward'
- cs.toReferenceTransforms.append(shaperInverse)
- elif 'transformCTLInverse' in odtValues:
- ctls = [
- '%s/odt/%s' % (
- acesCTLReleaseDir, odtValues['transformCTLInverse']),
- '%s/rrt/InvRRT.a1.0.0.ctl' % acesCTLReleaseDir,
- shaperFromACESCTL % acesCTLReleaseDir
- ]
- lut = "InvRRT.a1.0.0.%s.%s.spi3d" % (odtName, shaperName)
-
- # Remove spaces and parentheses
- lut = lut.replace(' ', '_').replace(')', '_').replace('(', '_')
-
- genlut.generate3dLUTFromCTL(
- lutDir + "/" + lut,
- # None,
- ctls,
- lutResolution3d,
- 'half',
- 1.0,
- shaperInputScale,
- shaperParams,
- cleanup,
- acesCTLReleaseDir)
-
- cs.toReferenceTransforms.append({
- 'type': 'lutFile',
- 'path': lut,
- 'interpolation': 'tetrahedral',
- 'direction': 'forward'
- })
-
- shaperInverse = shaperOCIOTransform.copy()
- shaperInverse['direction'] = 'forward'
- cs.toReferenceTransforms.append(shaperInverse)
-
- return cs
-
- #
- # RRT/ODT shaper options
- #
- shaperData = {}
-
- # Log 2 shaper
- log2ShaperName = shaperName
- log2Params = {
- 'middleGrey': 0.18,
- 'minExposure': -6.0,
- 'maxExposure': 6.5
- }
- log2Shaper = createGenericLog(name=log2ShaperName,
- middleGrey=log2Params['middleGrey'],
- minExposure=log2Params['minExposure'],
- maxExposure=log2Params['maxExposure'])
- configData['colorSpaces'].append(log2Shaper)
-
- shaperInputScale_genericLog2 = 1.0
-
- # Log 2 shaper name and CTL transforms bundled up
- log2ShaperData = [
- log2ShaperName,
- '%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',
- shaperInputScale_genericLog2,
- log2Params
- ]
-
- shaperData[log2ShaperName] = log2ShaperData
-
- #
- # Shaper that also includes the AP1 primaries
- # - Needed for some LUT baking steps
- #
- log2ShaperAP1 = createGenericLog(name=log2ShaperName,
- middleGrey=log2Params['middleGrey'],
- minExposure=log2Params['minExposure'],
- maxExposure=log2Params['maxExposure'])
- log2ShaperAP1.name = "%s - AP1" % log2ShaperAP1.name
- # AP1 primaries to AP0 primaries
- log2ShaperAP1.toReferenceTransforms.append({
- 'type': 'matrix',
- 'matrix': mat44FromMat33(acesAP1toAP0),
- 'direction': 'forward'
- })
- configData['colorSpaces'].append(log2ShaperAP1)
-
- #
- # Choose your shaper
- #
- rrtShaperName = log2ShaperName
- rrtShaper = log2ShaperData
-
- #
- # RRT + ODT Combinations
- #
- sortedOdts = sorted(odtInfo.iteritems(), key=lambda x: x[1])
- print(sortedOdts)
- for odt in sortedOdts:
- (odtName, odtValues) = odt
-
- # Have to handle ODTs that can generate either legal or full output
- if odtName in ['Academy.Rec2020_100nits_dim.a1.0.0',
- 'Academy.Rec709_100nits_dim.a1.0.0',
- 'Academy.Rec709_D60sim_100nits_dim.a1.0.0']:
- odtNameLegal = '%s - Legal' % odtValues['transformUserName']
- else:
- odtNameLegal = odtValues['transformUserName']
-
- odtLegal = odtValues.copy()
- odtLegal['legalRange'] = 1
-
- cs = createACESRRTplusODT(
- odtNameLegal,
- odtLegal,
- rrtShaper,
- lutResolution1d,
- lutResolution3d,
- cleanup)
- configData['colorSpaces'].append(cs)
-
- # Create a display entry using this color space
- configData['displays'][odtNameLegal] = {
- 'Linear': ACES,
- 'Log': ACEScc,
- 'Output Transform': cs}
-
- if odtName in ['Academy.Rec2020_100nits_dim.a1.0.0',
- 'Academy.Rec709_100nits_dim.a1.0.0',
- 'Academy.Rec709_D60sim_100nits_dim.a1.0.0']:
- print("Generating full range ODT for %s" % odtName)
-
- odtNameFull = "%s - Full" % odtValues['transformUserName']
- odtFull = odtValues.copy()
- odtFull['legalRange'] = 0
-
- csFull = createACESRRTplusODT(
- odtNameFull,
- odtFull,
- rrtShaper,
- lutResolution1d,
- lutResolution3d,
- cleanup)
- configData['colorSpaces'].append(csFull)
-
- # Create a display entry using this color space
- configData['displays'][odtNameFull] = {
- 'Linear': ACES,
- 'Log': ACEScc,
- 'Output Transform': csFull}
-
- #
- # Generic Matrix transform
- #
- def createGenericMatrix(name='matrix',
- fromReferenceValues=[],
- toReferenceValues=[]):
- cs = ColorSpace(name)
- cs.description = "The %s color space" % name
- cs.equalityGroup = name
- cs.family = 'Utility'
- cs.isData = False
-
- cs.toReferenceTransforms = []
- if toReferenceValues != []:
- for matrix in toReferenceValues:
- cs.toReferenceTransforms.append({
- 'type': 'matrix',
- 'matrix': mat44FromMat33(matrix),
- 'direction': 'forward'
- })
-
- cs.fromReferenceTransforms = []
- if fromReferenceValues != []:
- for matrix in fromReferenceValues:
- cs.fromReferenceTransforms.append({
- 'type': 'matrix',
- 'matrix': mat44FromMat33(matrix),
- 'direction': 'forward'
- })
-
- return cs
-
- cs = createGenericMatrix('XYZ', fromReferenceValues=[acesAP0toXYZ])
- configData['colorSpaces'].append(cs)
-
- cs = createGenericMatrix('Linear - AP1', toReferenceValues=[acesAP1toAP0])
- configData['colorSpaces'].append(cs)
-
- # ACES to Linear, P3D60 primaries
- xyzToP3D60 = [2.4027414142, -0.8974841639, -0.3880533700,
- -0.8325796487, 1.7692317536, 0.0237127115,
- 0.0388233815, -0.0824996856, 1.0363685997]
-
- cs = createGenericMatrix('Linear - P3-D60',
- fromReferenceValues=[acesAP0toXYZ, xyzToP3D60])
- configData['colorSpaces'].append(cs)
-
- # ACES to Linear, P3D60 primaries
- xyzToP3DCI = [2.7253940305, -1.0180030062, -0.4401631952,
- -0.7951680258, 1.6897320548, 0.0226471906,
- 0.0412418914, -0.0876390192, 1.1009293786]
-
- cs = createGenericMatrix('Linear - P3-DCI',
- fromReferenceValues=[acesAP0toXYZ, xyzToP3DCI])
- configData['colorSpaces'].append(cs)
-
- # ACES to Linear, Rec 709 primaries
- xyzToRec709 = [3.2409699419, -1.5373831776, -0.4986107603,
- -0.9692436363, 1.8759675015, 0.0415550574,
- 0.0556300797, -0.2039769589, 1.0569715142]
-
- cs = createGenericMatrix('Linear - Rec.709',
- fromReferenceValues=[acesAP0toXYZ, xyzToRec709])
- configData['colorSpaces'].append(cs)
-
- # ACES to Linear, Rec 2020 primaries
- xyzToRec2020 = [1.7166511880, -0.3556707838, -0.2533662814,
- -0.6666843518, 1.6164812366, 0.0157685458,
- 0.0176398574, -0.0427706133, 0.9421031212]
-
- cs = createGenericMatrix('Linear - Rec.2020',
- fromReferenceValues=[acesAP0toXYZ, xyzToRec2020])
- configData['colorSpaces'].append(cs)
-
- print("generateLUTs - end")
- return configData
-
-
-def generateBakedLUTs(odtInfo,
- shaperName,
- bakedDir,
- configPath,
- lutResolution1d,
- lutResolution3d,
- lutResolutionShaper=1024):
- # Add the legal and full variations into this list
- odtInfoC = dict(odtInfo)
- for odtCTLName, odtValues in odtInfo.iteritems():
- if odtCTLName in ['Academy.Rec2020_100nits_dim.a1.0.0',
- 'Academy.Rec709_100nits_dim.a1.0.0',
- 'Academy.Rec709_D60sim_100nits_dim.a1.0.0']:
- odtName = odtValues["transformUserName"]
-
- odtValuesLegal = dict(odtValues)
- odtValuesLegal["transformUserName"] = "%s - Legal" % odtName
- odtInfoC["%s - Legal" % odtCTLName] = odtValuesLegal
-
- odtValuesFull = dict(odtValues)
- odtValuesFull["transformUserName"] = "%s - Full" % odtName
- odtInfoC["%s - Full" % odtCTLName] = odtValuesFull
-
- del (odtInfoC[odtCTLName])
-
- for odtCTLName, odtValues in odtInfoC.iteritems():
- odtPrefix = odtValues["transformUserNamePrefix"]
- odtName = odtValues["transformUserName"]
-
- # For Photoshop
- for inputspace in ["ACEScc", "ACESproxy"]:
- args = ["--iconfig", configPath, "-v", "--inputspace", inputspace]
- args += ["--outputspace", "%s" % odtName]
- args += ["--description",
- "%s - %s for %s data" % (odtPrefix, odtName, inputspace)]
- args += ["--shaperspace", shaperName, "--shapersize",
- str(lutResolutionShaper)]
- args += ["--cubesize", str(lutResolution3d)]
- args += ["--format", "icc", "%s/photoshop/%s for %s.icc" % (
- bakedDir, odtName, inputspace)]
-
- bakeLUT = Process(description="bake a LUT", cmd="ociobakelut",
- args=args)
- bakeLUT.execute()
-
- # For Flame, Lustre
- for inputspace in ["ACEScc", "ACESproxy"]:
- args = ["--iconfig", configPath, "-v", "--inputspace", inputspace]
- args += ["--outputspace", "%s" % odtName]
- args += ["--description",
- "%s - %s for %s data" % (odtPrefix, odtName, inputspace)]
- args += ["--shaperspace", shaperName, "--shapersize",
- str(lutResolutionShaper)]
- args += ["--cubesize", str(lutResolution3d)]
-
- fargs = ["--format", "flame", "%s/flame/%s for %s Flame.3dl" % (
- bakedDir, odtName, inputspace)]
- bakeLUT = Process(description="bake a LUT", cmd="ociobakelut",
- args=(args + fargs))
- bakeLUT.execute()
-
- largs = ["--format", "lustre", "%s/lustre/%s for %s Lustre.3dl" % (
- bakedDir, odtName, inputspace)]
- bakeLUT = Process(description="bake a LUT", cmd="ociobakelut",
- args=(args + largs))
- bakeLUT.execute()
-
- # For Maya, Houdini
- for inputspace in ["ACEScg", "ACES2065-1"]:
- args = ["--iconfig", configPath, "-v", "--inputspace", inputspace]
- args += ["--outputspace", "%s" % odtName]
- args += ["--description",
- "%s - %s for %s data" % (odtPrefix, odtName, inputspace)]
- if inputspace == 'ACEScg':
- linShaperName = "%s - AP1" % shaperName
+def generate_LUTs(odt_info,
+ lmt_info,
+ shaper_name,
+ aces_ctl_directory,
+ lut_directory,
+ lut_resolution_1d=4096,
+ lut_resolution_3d=64,
+ cleanup=True):
+ """
+ Object description.
+
+ Parameters
+ ----------
+ parameter : type
+ Parameter description.
+
+ Returns
+ -------
+ dict
+ Colorspaces and transforms converting between those colorspaces and
+ the reference colorspace, *ACES*.
+ """
+
+ print('generateLUTs - begin')
+ config_data = {}
+
+ # Initialize a few variables
+ config_data['displays'] = {}
+ config_data['colorSpaces'] = []
+
+ # -------------------------------------------------------------------------
+ # *ACES Color Spaces*
+ # -------------------------------------------------------------------------
+
+ # *ACES* colorspaces
+ (aces_reference,
+ aces_colorspaces,
+ aces_displays,
+ aces_log_display_space,
+ aces_roles) = aces.create_colorspaces(aces_ctl_directory,
+ lut_directory,
+ lut_resolution_1d,
+ lut_resolution_3d,
+ lmt_info,
+ odt_info,
+ shaper_name,
+ cleanup)
+
+ config_data['referenceColorSpace'] = aces_reference
+ config_data['roles'] = aces_roles
+
+ for cs in aces_colorspaces:
+ config_data['colorSpaces'].append(cs)
+
+ for name, data in aces_displays.iteritems():
+ config_data['displays'][name] = data
+
+ config_data['linearDisplaySpace'] = aces_reference
+ config_data['logDisplaySpace'] = aces_log_display_space
+
+ # -------------------------------------------------------------------------
+ # *Camera Input Transforms*
+ # -------------------------------------------------------------------------
+
+ # *ARRI Log-C* to *ACES*.
+ arri_colorSpaces = arri.create_colorspaces(lut_directory,
+ lut_resolution_1d)
+ for cs in arri_colorSpaces:
+ config_data['colorSpaces'].append(cs)
+
+ # *Canon-Log* to *ACES*.
+ canon_colorspaces = canon.create_colorspaces(lut_directory,
+ lut_resolution_1d)
+ for cs in canon_colorspaces:
+ config_data['colorSpaces'].append(cs)
+
+ # *Panasonic V-Log* to *ACES*.
+ panasonic_colorSpaces = panasonic.create_colorspaces(lut_directory,
+ lut_resolution_1d)
+ for cs in panasonic_colorSpaces:
+ config_data['colorSpaces'].append(cs)
+
+ # *RED* colorspaces to *ACES*.
+ red_colorspaces = red.create_colorspaces(lut_directory,
+ lut_resolution_1d)
+ for cs in red_colorspaces:
+ config_data['colorSpaces'].append(cs)
+
+ # *S-Log* to *ACES*.
+ sony_colorSpaces = sony.create_colorspaces(lut_directory,
+ lut_resolution_1d)
+ for cs in sony_colorSpaces:
+ config_data['colorSpaces'].append(cs)
+
+ # -------------------------------------------------------------------------
+ # General Color Spaces
+ # -------------------------------------------------------------------------
+ general_colorSpaces = general.create_colorspaces(lut_directory,
+ lut_resolution_1d,
+ lut_resolution_3d)
+ for cs in general_colorSpaces:
+ config_data['colorSpaces'].append(cs)
+
+ # The *Raw* color space
+ raw = general.create_raw()
+ config_data['colorSpaces'].append(raw)
+
+ # Override 'linear' display
+ config_data['linearDisplaySpace'] = raw
+
+ # Override certain roles, for now
+ config_data['roles']['data'] = raw.name
+ config_data['roles']['reference'] = raw.name
+ config_data['roles']['texture_paint'] = raw.name
+
+ print('generateLUTs - end')
+ return config_data
+
+
+def generate_baked_LUTs(odt_info,
+ shaper_name,
+ baked_directory,
+ config_path,
+ lut_resolution_1d,
+ lut_resolution_3d,
+ lut_resolution_shaper=1024):
+ """
+ Object description.
+
+ Parameters
+ ----------
+ parameter : type
+ Parameter description.
+
+ Returns
+ -------
+ type
+ Return value description.
+ """
+
+ # 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():
+ 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_values_full = dict(odt_values)
+ odt_values_full['transformUserName'] = '%s - Full' % odt_name
+ odt_info_C['%s - Full' % odt_ctl_name] = odt_values_full
+
+ del (odt_info_C[odt_ctl_name])
+
+ # Generate appropriate LUTs for each ODT
+ for odt_ctl_name, odt_values in odt_info_C.iteritems():
+ odt_prefix = odt_values['transformUserNamePrefix']
+ odt_name = odt_values['transformUserName']
+
+ # *Photoshop*
+ for input_space in ['ACEScc', 'ACESproxy']:
+ args = ['--iconfig', config_path,
+ '-v',
+ '--inputspace', input_space]
+ args += ['--outputspace', '%s' % odt_name]
+ args += ['--description',
+ '%s - %s for %s data' % (odt_prefix,
+ odt_name,
+ input_space)]
+ args += ['--shaperspace', shaper_name,
+ '--shapersize', str(lut_resolution_shaper)]
+ args += ['--cubesize', str(lut_resolution_3d)]
+ args += ['--format',
+ 'icc',
+ os.path.join(baked_directory,
+ 'photoshop',
+ '%s for %s.icc' % (odt_name, input_space))]
+
+ bake_lut = Process(description='bake a LUT',
+ cmd='ociobakelut',
+ args=args)
+ bake_lut.execute()
+
+ # *Flame*, *Lustre*
+ for input_space in ['ACEScc', 'ACESproxy']:
+ args = ['--iconfig', config_path,
+ '-v',
+ '--inputspace', input_space]
+ args += ['--outputspace', '%s' % odt_name]
+ args += ['--description',
+ '%s - %s for %s data' % (
+ odt_prefix, odt_name, input_space)]
+ args += ['--shaperspace', shaper_name,
+ '--shapersize', str(lut_resolution_shaper)]
+ args += ['--cubesize', str(lut_resolution_3d)]
+
+ fargs = ['--format',
+ 'flame',
+ 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',
+ os.path.join(
+ baked_directory,
+ 'lustre',
+ '%s for %s Lustre.3dl' % (odt_name, input_space))]
+ bake_lut = Process(description='bake a LUT',
+ cmd='ociobakelut',
+ args=(args + largs))
+ bake_lut.execute()
+
+ # *Maya*, *Houdini*
+ for input_space in ['ACEScg', 'ACES2065-1']:
+ args = ['--iconfig', config_path,
+ '-v',
+ '--inputspace', input_space]
+ args += ['--outputspace', '%s' % odt_name]
+ args += ['--description',
+ '%s - %s for %s data' % (
+ odt_prefix, odt_name, input_space)]
+ if input_space == 'ACEScg':
+ lin_shaper_name = '%s - AP1' % shaper_name