2 # -*- coding: utf-8 -*-
7 import aces_ocio.generateLUT as genlut
8 from aces_ocio.util import ColorSpace, mat44FromMat33
11 __author__ = 'ACES Developers'
12 __copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers'
14 __maintainer__ = 'ACES Developers'
15 __email__ = 'aces@oscars.org'
16 __status__ = 'Production'
18 __all__ = ['createLogC',
36 Parameter description.
41 Return value description.
44 name = "%s (EI%s) - %s" % (transferFunction, exposureIndex, gamut)
45 if transferFunction == "":
46 name = "Linear - %s" % gamut
48 name = "%s (EI%s)" % (transferFunction, exposureIndex)
57 IDT_maker_version = "0.08"
60 blackSignal = 0.003907
62 encodingGain = 0.256598
63 encodingOffset = 0.391007
66 return (math.log(EI / nominalEI) / math.log(2) * (
67 0.89 - 1) / 3 + 1) * encodingGain
69 def LogCInverseParametersForEI(EI):
71 slope = 1.0 / (cut * math.log(10))
72 offset = math.log10(cut) - slope * cut
74 gray = midGraySignal / gain
75 # The higher the EI, the lower the gamma
76 encGain = gainForEI(EI)
77 encOffset = encodingOffset
79 nz = ((95.0 / 1023.0 - encOffset) / encGain - offset) / slope
80 encOffset = encodingOffset - math.log10(1 + nz) * encGain
81 # Calculate some intermediate values
83 b = nz - blackSignal / gray
84 e = slope * a * encGain
85 f = encGain * (slope * b + offset) + encOffset
86 # Manipulations so we can return relative exposure
101 def logCtoLinear(codeValue, exposureIndex):
102 p = LogCInverseParametersForEI(exposureIndex)
103 breakpoint = p['e'] * p['cut'] + p['f']
104 if (codeValue > breakpoint):
105 linear = ((pow(10, (codeValue / 1023.0 - p['d']) / p['c']) -
108 linear = (codeValue / 1023.0 - p['f']) / p['e']
110 # print(codeValue, linear)
114 cs.toReferenceTransforms = []
116 if transferFunction == "V3 LogC":
117 data = array.array('f', "\0" * lutResolution1d * 4)
118 for c in range(lutResolution1d):
119 data[c] = logCtoLinear(1023.0 * c / (lutResolution1d - 1),
122 lut = "%s_to_linear.spi1d" % (
123 "%s_%s" % (transferFunction, exposureIndex))
125 # Remove spaces and parentheses
126 lut = lut.replace(' ', '_').replace(')', '_').replace('(', '_')
128 genlut.writeSPI1D(lutDir + "/" + lut,
135 # print("Writing %s" % lut)
136 cs.toReferenceTransforms.append({
139 'interpolation': 'linear',
140 'direction': 'forward'
143 if gamut == 'Wide Gamut':
144 cs.toReferenceTransforms.append({
146 'matrix': mat44FromMat33([0.680206, 0.236137, 0.083658,
147 0.085415, 1.017471, -0.102886,
148 0.002057, -0.062563, 1.060506]),
149 'direction': 'forward'
152 cs.fromReferenceTransforms = []
156 def createColorSpaces(lutDir, lutResolution1d):
158 Generates the colorspace conversions.
163 Parameter description.
168 Return value description.
173 transferFunction = "V3 LogC"
175 # EIs = [160.0, 200.0, 250.0, 320.0, 400.0, 500.0, 640.0, 800.0,
176 # 1000.0, 1280.0, 1600.0, 2000.0, 2560.0, 3200.0]
177 EIs = [160, 200, 250, 320, 400, 500, 640, 800,
178 1000, 1280, 1600, 2000, 2560, 3200]
183 LogCEIfull = createLogC(
184 gamut, transferFunction, EI, "LogC", lutDir, lutResolution1d)
185 colorspaces.append(LogCEIfull)
189 LogCEIlinearization = createLogC(
190 "", transferFunction, EI, "LogC", lutDir, lutResolution1d)
191 colorspaces.append(LogCEIlinearization)
194 LogCEIprimaries = createLogC(
195 gamut, "", defaultEI, "LogC", lutDir, lutResolution1d)
196 colorspaces.append(LogCEIprimaries)