Skip to content

Instantly share code, notes, and snippets.

@qbx2
Created January 4, 2017 06:08
Show Gist options
  • Save qbx2/ed2c836085fd3f93d69d11dbc5cf7692 to your computer and use it in GitHub Desktop.
Save qbx2/ed2c836085fd3f93d69d11dbc5cf7692 to your computer and use it in GitHub Desktop.
from PIL import Image
from struct import unpack
from sys import argv
def rgb565torgb888(c):
return ((c&0xf800) >> 8, (c&0x07e0) >> 3, (c&0x001f) << 3)
if len(argv) < 2:
print('Usage: {} <filename>'.format(argv[0]))
exit()
img = Image.new('RGB', (128, 160))
pixels = img.load()
with open(argv[1],"rb") as f:
for j in range(img.size[1]):
for i in range(img.size[0]):
pixels[i,j]=rgb565torgb888(unpack('<H', f.read(2))[0])
img.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment