1 from __future__ import print_function
7 BIT_LENGTH = int(math.pow(2, BIT_DEPTH))
8 COLOR_DEPTH = BIT_LENGTH - 1
12 Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 /* This file is auto-generated by the build scripts; edits will be lost
37 cc = open('src/lut.cc', 'w')
41 print("#include \"lut.h\"", file=cc)
44 /* sRGB color matrix for XYZ -> RGB */
45 float color_matrix[3][3] = {
46 { 3.240454836, -1.537138850, -0.498531547},
47 {-0.969266390, 1.876010929, 0.041556082},
48 { 0.055643420, -0.204025854, 1.057225162}
53 float lut_in[COLOR_DEPTH + 1] = {\n
55 \t * Reference white: DCI
58 """ % (BIT_DEPTH, DCI_GAMMA), file=cc)
61 for i in range(0, BIT_LENGTH):
62 v = math.pow (i / (BIT_LENGTH - 1.0), DCI_GAMMA);
65 print(" ", end='', file=cc)
67 if i < BIT_LENGTH - 1:
68 print("%06f, " % v, end="", file=cc)
75 print("%06f" % v, file=cc)
80 int lut_out[COLOR_DEPTH + 1] = {
82 \t * Reference white: sRGB
88 for i in range (0, BIT_LENGTH):
89 v = i / (BIT_LENGTH - 1.0)
91 if (v < (0.04045 / 12.92)):
94 v = (1.055 * pow (v, (1 / SRGB_GAMMA))) - 0.055
99 print(" ", end="", file=cc)
101 if i < BIT_LENGTH - 1:
102 print("%d, " % v, end="", file=cc)
109 print("%d" % v, file=cc)
113 h = open('src/lut.h', 'w')
118 #define COLOR_DEPTH (%d)
119 #define DCI_COEFFICIENT (48.0/52.37)
121 extern float color_matrix[3][3];
122 extern int lut_out[COLOR_DEPTH + 1];
123 extern float lut_in[COLOR_DEPTH + 1];
124 """ % COLOR_DEPTH, file=h)
126 if __name__ == "__main__":