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
|
2021-01-20 18:41:34 +01:00
|
|
|
print("InitialImage = [")
|
2020-12-24 16:01:26 +01:00
|
|
|
for cell in memory:
|
2021-01-20 18:41:34 +01:00
|
|
|
print(cell, end=", ")
|
2020-12-24 16:01:26 +01:00
|
|
|
count = count + 1
|
|
|
|
if count > 10:
|
2021-01-20 18:41:34 +01:00
|
|
|
print("")
|
2020-12-24 16:01:26 +01:00
|
|
|
count = 0
|
2021-01-20 18:41:34 +01:00
|
|
|
print("]")
|