# Convert png image to 256 palette image for Pokitto. # # author: Miloslav Ciz # license: CC0 import sys from PIL import Image def rgbToIndex(r, g, b): return (r & 0b00000111) | ((g & 0b00000111) << 3) | ((b & 0b00000011) << 6) image = Image.open(sys.argv[1]) pixels = image.load() sys.stdout.write("const unsigned char image[] =\n{ ") sys.stdout.write(str(image.size[0]) + ", " + str(image.size[1]) + " // width, height") count = 0 for y in range(image.size[1]): for x in range(image.size[0]): if count % 14 == 0: sys.stdout.write("\n "); p = pixels[x,y] sys.stdout.write(",0x{:02x}".format(rgbToIndex(p[0] / 32, p[1] / 32, p[2] / 85))) count += 1 print("\n};")