diff options
| author | Carl Hetherington <cth@carlh.net> | 2012-12-22 13:11:58 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2012-12-22 13:11:58 +0000 |
| commit | 7a65df0fe4232ff0bb150b9e1568f9064fdc6de6 (patch) | |
| tree | 77d27d4e5673bc18c542f00301f0d6b8b5cddd7b | |
| parent | 20c2c5768c231ceec70e7900abf7c26257bd9c86 (diff) | |
Make wscript work on python 2 and 3.
| -rw-r--r-- | lut.py | 55 |
1 files changed, 28 insertions, 27 deletions
@@ -1,3 +1,4 @@ +from __future__ import print_function import math BIT_DEPTH = 12 @@ -7,7 +8,7 @@ BIT_LENGTH = int(math.pow(2, BIT_DEPTH)) COLOR_DEPTH = BIT_LENGTH - 1 def boilerplate(f): - print >>f, """/* + print("""/* Copyright (C) 2012 Carl Hetherington <cth@carlh.net> This program is free software; you can redistribute it and/or modify @@ -30,97 +31,97 @@ def boilerplate(f): /* This file is auto-generated by the build scripts; edits will be lost on ./waf configure. */ -""" +""", file=f) def make_luts(): cc = open('src/lut.cc', 'w') boilerplate(cc) - print >>cc,"#include \"lut.h\"" + print("#include \"lut.h\"", file=cc) - print >>cc, """ + print(""" /* sRGB color matrix for XYZ -> RGB */ float color_matrix[3][3] = { { 3.240454836, -1.537138850, -0.498531547}, {-0.969266390, 1.876010929, 0.041556082}, { 0.055643420, -0.204025854, 1.057225162} };\n\n -""" +""", file=cc) - print >>cc, """ + print(""" float lut_in[COLOR_DEPTH + 1] = {\n \t/* Bit depth: %d \t * Reference white: DCI \t * Gamma: %f \t */ -""" % (BIT_DEPTH, DCI_GAMMA) +""" % (BIT_DEPTH, DCI_GAMMA), file=cc) c = 0 for i in range(0, BIT_LENGTH): - v = math.pow (i / (BIT_LENGTH - 1.0), DCI_GAMMA); + v = math.pow (i / (BIT_LENGTH - 1.0), DCI_GAMMA); if (c == 0): - print >> cc," ", + print(" ", end='', file=cc) if i < BIT_LENGTH - 1: - print >> cc,"%06f, " % v, + print("%06f, " % v, end="", file=cc) if c == 12: c = 0; - print >> cc,"" + print("", file=cc) else: c += 1 else: - print >> cc,"%06f" % v + print("%06f" % v, file=cc) - print >>cc,"};" + print("};", file=cc) - print >>cc, """ + print(""" int lut_out[COLOR_DEPTH + 1] = { \t/* Bit depth: %d \t * Reference white: sRGB \t * Gamma: %f \t */ -""" +""", file=cc) c = 0 for i in range (0, BIT_LENGTH): v = i / (BIT_LENGTH - 1.0) - if (v < (0.04045 / 12.92)): - v *= 12.92 - else: - v = (1.055 * pow (v, (1 / SRGB_GAMMA))) - 0.055; + if (v < (0.04045 / 12.92)): + v *= 12.92 + else: + v = (1.055 * pow (v, (1 / SRGB_GAMMA))) - 0.055 - v *= 255 + v *= 255 if c == 0: - print >> cc," ", + print(" ", end="", file=cc) if i < BIT_LENGTH - 1: - print >> cc, "%d, " % v, + print("%d, " % v, end="", file=cc) if c == 12: c = 0; - print >> cc,"" + print("", file=cc) else: c += 1 else: - print >> cc,"%d" % v + print("%d" % v, file=cc) - print >>cc,"};" + print("};", file=cc) h = open('src/lut.h', 'w') boilerplate(h) - print >> h,""" + print(""" #define COLOR_DEPTH (%d) #define DCI_COEFFICIENT (48.0/52.37) extern float color_matrix[3][3]; extern int lut_out[COLOR_DEPTH + 1]; extern float lut_in[COLOR_DEPTH + 1]; -""" % COLOR_DEPTH +""" % COLOR_DEPTH, file=h) if __name__ == "__main__": make_luts() |
