Commit 19332acf authored by Malte Schmitz's avatar Malte Schmitz

Organise script

parent 6462ee48
from PIL import Image
import sys
def p(a):
def mapColors(rgb):
return tuple(round(v / 255.0) for v in rgb)
def encode(a):
result = 0
for i, rgb in enumerate(a):
r,g,b = [round(v / 255.0) for v in rgb]
r,g,b = rgb
result |= r << i * 3
result |= g << i * 3 + 1
result |= b << i * 3 + 2
return result
return hex(result)
if len(sys.argv) != 2:
print("Missing file name argument", file=sys.stderr)
sys.exit(1)
img = Image.open("20px-color.bmp").convert('RGB')
filename = sys.argv[1]
img = Image.open(filename).convert('RGB')
width, height = img.size
pixels = [p([img.getpixel((x,y)) for y in range(height)]) for x in range(width)]
pixels = [[mapColors(img.getpixel((x,y))) for y in range(height)] for x in range(width)]
array = "{" + ",".join([hex(p) for p in pixels]) + "}"
array = "{" + ",".join([encode(p) for p in pixels]) + "}"
code = """uint64_t[{width}] pixels = {array};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment