openmv/util/gen_rainbow.py
Kwabena W. Agyeman 6699ea4d0e Added RGB LUT.
And modified the rainbow table so that the RGB888 to RGB565 translation
is done using a rounding technique versus hard floor. This is also used
for the RGB565<->RGB888 LUTs.

Additionally, I added a bunch of stuff to the image library to make
working with images easier. I will using these helpers in the future.

Finally, I cleaned up trailing space in the font stuff (pet peeve).
2016-02-15 22:12:25 -05:00

28 lines
800 B
Python
Executable File

#!/usr/bin/env python
# -*- coding: utf-8 -*-
NUM_COL=256
SAT=1.0
VAL=1.0
OFFSET=220
import sys, colorsys
sys.stdout.write("#include <stdint.h>\n")
tup = [colorsys.hsv_to_rgb(1.0-(i/float(NUM_COL+OFFSET)), SAT, VAL) for i in range(OFFSET, NUM_COL+OFFSET)]
col = [(int((((r*255)*31)+127.5)/255)&0x1F)<<11 |
(int((((g*255)*63)+127.5)/255)&0x3F)<<5 |
(int((((b*255)*31)+127.5)/255)&0x1F) for r,g,b in tup]
sys.stdout.write("const uint16_t rainbow_table[%d] = {\n" % NUM_COL)
for i in range(NUM_COL):
if not (i % 8):
sys.stdout.write(" ")
sys.stdout.write("0x%04X" % (((col[i]&0x00ff)<<8)|((col[i]&0xff00)>>8)))
if (i + 1) % 8:
sys.stdout.write(", ")
elif i != (NUM_COL-1):
sys.stdout.write(",\n")
else:
sys.stdout.write("\n};\n")