Skip to content

Instantly share code, notes, and snippets.

@hexagon5un
Created August 21, 2016 21:03
Embed
What would you like to do?
## Creates a gamma-corrected lookup table
import math
def gamma(nsteps, gamma):
gammaedUp = [math.pow(x, gamma) for x in range(nsteps)]
return [x/max(gammaedUp) for x in gammaedUp]
def rounder(topValue, gammas):
return [min(topValue, round(x*topValue)) for x in gammas]
if __name__ == "__main__":
myGamma = 2.3
steps = 16
output = file("gamma.h", "w")
output.write("/* %d-step brightness table: gamma = %s */ \n\n" % (steps, myGamma))
output.write("const uint8_t gamma_table[%d] = {\n" % steps)
for value in rounder(255, gamma(steps, myGamma)):
output.write("\t %d,\n" % value)
output.write("};\n")
output.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment