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',
30 name = "%s (EI%s) - %s" % (transferFunction, exposureIndex, gamut)
31 if transferFunction == "":
32 name = "Linear - %s" % gamut
34 name = "%s (EI%s)" % (transferFunction, exposureIndex)
43 IDT_maker_version = "0.08"
46 blackSignal = 0.003907
48 encodingGain = 0.256598
49 encodingOffset = 0.391007
52 return (math.log(EI / nominalEI) / math.log(2) * (
53 0.89 - 1) / 3 + 1) * encodingGain
55 def LogCInverseParametersForEI(EI):
57 slope = 1.0 / (cut * math.log(10))
58 offset = math.log10(cut) - slope * cut
60 gray = midGraySignal / gain
61 # The higher the EI, the lower the gamma
62 encGain = gainForEI(EI)
63 encOffset = encodingOffset
65 nz = ((95.0 / 1023.0 - encOffset) / encGain - offset) / slope
66 encOffset = encodingOffset - math.log10(1 + nz) * encGain
67 # Calculate some intermediate values
69 b = nz - blackSignal / gray
70 e = slope * a * encGain
71 f = encGain * (slope * b + offset) + encOffset
72 # Manipulations so we can return relative exposure
87 def logCtoLinear(codeValue, exposureIndex):
88 p = LogCInverseParametersForEI(exposureIndex)
89 breakpoint = p['e'] * p['cut'] + p['f']
90 if (codeValue > breakpoint):
91 linear = ((pow(10, (codeValue / 1023.0 - p['d']) / p['c']) -
94 linear = (codeValue / 1023.0 - p['f']) / p['e']
96 # print(codeValue, linear)
100 cs.toReferenceTransforms = []
102 if transferFunction == "V3 LogC":
103 data = array.array('f', "\0" * lutResolution1d * 4)
104 for c in range(lutResolution1d):
105 data[c] = logCtoLinear(1023.0 * c / (lutResolution1d - 1),
108 lut = "%s_to_linear.spi1d" % (
109 "%s_%s" % (transferFunction, exposureIndex))
111 # Remove spaces and parentheses
112 lut = lut.replace(' ', '_').replace(')', '_').replace('(', '_')
114 genlut.writeSPI1D(lutDir + "/" + lut,
121 # print("Writing %s" % lut)
122 cs.toReferenceTransforms.append({
125 'interpolation': 'linear',
126 'direction': 'forward'
129 if gamut == 'Wide Gamut':
130 cs.toReferenceTransforms.append({
132 'matrix': mat44FromMat33([0.680206, 0.236137, 0.083658,
133 0.085415, 1.017471, -0.102886,
134 0.002057, -0.062563, 1.060506]),
135 'direction': 'forward'
138 cs.fromReferenceTransforms = []
142 def createColorSpaces(lutDir, lutResolution1d):
145 transferFunction = "V3 LogC"
147 # EIs = [160.0, 200.0, 250.0, 320.0, 400.0, 500.0, 640.0, 800.0,
148 # 1000.0, 1280.0, 1600.0, 2000.0, 2560.0, 3200.0]
149 EIs = [160, 200, 250, 320, 400, 500, 640, 800,
150 1000, 1280, 1600, 2000, 2560, 3200]
155 LogCEIfull = createLogC(
156 gamut, transferFunction, EI, "LogC", lutDir, lutResolution1d)
157 colorspaces.append(LogCEIfull)
161 LogCEIlinearization = createLogC(
162 "", transferFunction, EI, "LogC", lutDir, lutResolution1d)
163 colorspaces.append(LogCEIlinearization)
166 LogCEIprimaries = createLogC(
167 gamut, "", defaultEI, "LogC", lutDir, lutResolution1d)
168 colorspaces.append(LogCEIprimaries)