Skip to content

Instantly share code, notes, and snippets.

@fclairamb
Last active December 25, 2015 06:19
Show Gist options
  • Save fclairamb/6931438 to your computer and use it in GitHub Desktop.
Save fclairamb/6931438 to your computer and use it in GitHub Desktop.
RGB 24 --> 16 bits
def rgb16(r, g, b):
r = (r & 255) >> 3 # RED (5 bits)
g = (g & 255) >> 2 # GREEN (6 bits)
b = (b & 255) >> 3 # BLUE (5 bits)
c = (r << (6+5)) | (g << 5) | b
return "0x{0:04x}".format(c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment