Last active
January 12, 2024 20:14
-
-
Save hexagon5un/3df734ad08d8dc8d9ace0491ef97cc58 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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 = open("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() | |
Thanks for putting this together. It was very helpful. I think there is a typo in line 14. Should read:
output = open("gamma.h", "w")
Thanks, and fixed.
BTW: that's no typo -- that's history! I must have written this before Python 3. Back then, open
was file
.
Surprised the rest still works, but it does. Woot.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for putting this together. It was very helpful.
I think there is a typo in line 14. Should read:
output = open("gamma.h", "w")