cie1931.py 713 B

123456789101112131415161718192021222324252627
  1. # http://jared.geek.nz/2013/feb/linear-led-pwm
  2. INPUT_SIZE = 255 # Input integer size
  3. OUTPUT_SIZE = 255 # Output integer size
  4. INT_TYPE = 'const unsigned char'
  5. TABLE_NAME = 'cie';
  6. def cie1931(L):
  7. L = L*100.0
  8. if L <= 8:
  9. return (L/902.3)
  10. else:
  11. return ((L+16.0)/116.0)**3
  12. x = range(0,int(INPUT_SIZE+1))
  13. y = [round(cie1931(float(L)/INPUT_SIZE)*OUTPUT_SIZE) for L in x]
  14. f = open('cie1931.h', 'w')
  15. f.write('// CIE1931 correction table\n')
  16. f.write('// Automatically generated\n\n')
  17. f.write('%s %s[%d] = {\n' % (INT_TYPE, TABLE_NAME, INPUT_SIZE+1))
  18. f.write('\t')
  19. for i,L in enumerate(y):
  20. f.write('%d, ' % int(L))
  21. if i % 10 == 9:
  22. f.write('\n\t')
  23. f.write('\n};\n\n')