lw35-upgrade/display/tools/mkimage.py

39 lines
658 B
Python
Raw Normal View History

2018-04-30 09:08:47 +02:00
#!/usr/bin/env python
# This script generates a memory initialization file for Lattice Diamond.
import sys
from PIL import Image
im = Image.open(sys.argv[1]);
pix = im.load()
buf=[""] * 4
block=0
extra=""
pixcnt=0
foo=0
for y in range(0, im.size[1]):
for x in range(0,im.size[0]):
foo=foo+1
if block == 4:
buf[pixcnt] = buf[pixcnt] + str(pix[x,y])
if pixcnt == 3:
for i in range(0,4):
print(buf[i])
buf[i] = ""
block = 0
pixcnt = 0
else:
pixcnt = pixcnt + 1
else:
buf[block] = buf[block] + str(pix[x,y])
if (pixcnt == 7):
block = block + 1
pixcnt = 0
else:
pixcnt = pixcnt + 1
print("")