2020-12-24 16:01:26 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
# retro-embedimage
|
|
|
|
#
|
|
|
|
# This takes an ngaImage and generates a version that provides the
|
|
|
|
# image as a Python list. Output is written to stdout.
|
|
|
|
#
|
|
|
|
# Copyright (c) 2020, Charles Childers
|
|
|
|
#
|
|
|
|
# Usage:
|
|
|
|
#
|
|
|
|
# retro-embedimage.py [image]
|
|
|
|
|
|
|
|
|
|
|
|
import os, sys, struct
|
|
|
|
from struct import pack, unpack
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
cells = int(os.path.getsize(sys.argv[1]) / 4)
|
2020-12-25 05:30:14 +01:00
|
|
|
f = open(sys.argv[1], "rb")
|
2020-12-24 16:01:26 +01:00
|
|
|
memory = list(struct.unpack(cells * "i", f.read()))
|
|
|
|
f.close()
|
|
|
|
count = 0
|
2020-12-25 05:30:14 +01:00
|
|
|
print('InitialImage = [')
|
2020-12-24 16:01:26 +01:00
|
|
|
for cell in memory:
|
|
|
|
print(cell, end=', ')
|
|
|
|
count = count + 1
|
|
|
|
if count > 10:
|
|
|
|
print('')
|
|
|
|
count = 0
|
|
|
|
print(']')
|