39 lines
658 B
Python
Executable File
39 lines
658 B
Python
Executable File
#!/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("")
|
|
|