Updated __init__.py to reflect version no. and new LUT defaults
[OpenColorIO-Configs.git] / aces_0.7.1 / luts / slog2.py
1 #!/usr/bin/env python
2
3 import math
4
5 # IT's annoying that the 1023,4 and 4095,16 almost, but dont exactly, cancel. UGH
6 # The intent is clearly to have the same mapping, but it's not done very well.
7 # Sony engineers and/or the Academy should pick one of these mappings for both.
8
9 def SLog_to_lin(x):
10     return (math.pow(10.0,(((((x*1023.0)/4.0-16.0)/219.0)-0.616596-0.03)/0.432699))-0.037584)*0.9
11
12 def SLog2_to_lin(x):
13     if x < 0.030001222851889303:
14         return (x-0.030001222851889303 ) * 0.28258064516129
15     return (219.0*(math.pow(10.0, ((x-0.616596-0.03)/0.432699)) - 0.037584) /155.0)
16
17 steps = 21
18 for i in xrange(steps):
19     x = i/(steps-1.0)
20     print x, SLog_to_lin(x), SLog2_to_lin(x)
21
22 def WriteSPI1D(filename, fromMin, fromMax, data):
23     f = file(filename,'w')
24     f.write("Version 1\n")
25     f.write("From %s %s\n" % (fromMin, fromMax))
26     f.write("Length %d\n" % len(data))
27     f.write("Components 1\n")
28     f.write("{\n")
29     for value in data:
30         f.write("        %s\n" % value)
31     f.write("}\n")
32     f.close()
33
34 def Fit(value, fromMin, fromMax, toMin, toMax):
35     if fromMin == fromMax:
36         raise ValueError("fromMin == fromMax")
37     return (value - fromMin) / (fromMax - fromMin) * (toMax - toMin) + toMin
38
39 """
40 5500K:
41
42 ACESR = 0.8764457030 * Rraw +  0.0145411681 * Graw +  0.1090131290 * Braw;
43 ACESG = 0.0774075345 * Rraw +  0.9529571767 * Graw + -0.0303647111 * Braw;
44 ACESB = 0.0573564351 * Rraw + -0.1151066335 * Graw +  1.0577501984 * Braw;
45
46 3200K:
47
48 ACESR = 1.0110238740 * Rraw +  -0.1362526051 * Graw +  0.1252287310 * Braw;
49 ACESG = 0.1011994504 * Rraw +   0.9562196265 * Graw + -0.0574190769 * Braw;
50 ACESB = 0.0600766530 * Rraw +  -0.1010185315 * Graw +  1.0409418785 * Braw;
51 """
52
53 """
54 NUM_SAMPLES = 2**11
55 RANGE = (-0.125, 1.125)
56 data = []
57 for i in xrange(NUM_SAMPLES):
58     x = i/(NUM_SAMPLES-1.0)
59     x = Fit(x, 0.0, 1.0, RANGE[0], RANGE[1])
60     data.append(SLog10_to_lin(x))
61 WriteSPI1D('slog2.spi1d', RANGE[0], RANGE[1], data)
62 """