iif: added slog10
[OpenColorIO-Configs.git] / iif / luts / slog.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 SLog10_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 SLog12_to_lin(x):
13     return (math.pow(10.0,(((((x*4095.0)/16.0-16.0)/219.0)-0.616596-0.03)/0.432699))-0.037584)*0.9
14
15
16 def WriteSPI1D(filename, fromMin, fromMax, data):
17     f = file(filename,'w')
18     f.write("Version 1\n")
19     f.write("From %s %s\n" % (fromMin, fromMax))
20     f.write("Length %d\n" % len(data))
21     f.write("Components 1\n")
22     f.write("{\n")
23     for value in data:
24         f.write("        %s\n" % value)
25     f.write("}\n")
26     f.close()
27
28 def Fit(value, fromMin, fromMax, toMin, toMax):
29     if fromMin == fromMax:
30         raise ValueError("fromMin == fromMax")
31     return (value - fromMin) / (fromMax - fromMin) * (toMax - toMin) + toMin
32
33 #
34 # NOTE: The ctl matrix order is transposed compared to what OCIO expects
35 #const float SGAMUT_TO_ACES_MTX[3][3] = {
36 #       { 0.754338638,  0.021198141, -0.009756991 },
37 #       #{ 0.133697046,  1.005410934,  0.004508563 },
38 #       { 0.111968437, -0.026610548,  1.005253201 }
39
40 NUM_SAMPLES = 2**11
41 RANGE = (-0.125, 1.125)
42 data = []
43 for i in xrange(NUM_SAMPLES):
44     x = i/(NUM_SAMPLES-1.0)
45     x = Fit(x, 0.0, 1.0, RANGE[0], RANGE[1])
46     data.append(SLog10_to_lin(x))
47 WriteSPI1D('slog10.spi1d', RANGE[0], RANGE[1], data)
48
49 """
50 NUM_SAMPLES = 2**13
51 RANGE = (-0.125, 1.125)
52 data = []
53 for i in xrange(NUM_SAMPLES):
54     x = i/(NUM_SAMPLES-1.0)
55     x = Fit(x, 0.0, 1.0, RANGE[0], RANGE[1])
56     data.append(SLog12_to_lin(x))
57 WriteSPI1D('slog12.spi1d', RANGE[0], RANGE[1], data)
58 """