toolchain: add initial retro-embedimage.py (#33)
FossilOrigin-Name: 41f9df0b112454e37aae00ad0c9d1bcc054331f7e5eb9b038733884d82c3e143
This commit is contained in:
parent
370868e4d3
commit
dd7e9ea809
1 changed files with 31 additions and 0 deletions
31
tools/retro-embedimage.py
Executable file
31
tools/retro-embedimage.py
Executable file
|
@ -0,0 +1,31 @@
|
|||
#!/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)
|
||||
f = open("ngaImage", "rb")
|
||||
memory = list(struct.unpack(cells * "i", f.read()))
|
||||
f.close()
|
||||
count = 0
|
||||
print('Image = [')
|
||||
for cell in memory:
|
||||
print(cell, end=', ')
|
||||
count = count + 1
|
||||
if count > 10:
|
||||
print('')
|
||||
count = 0
|
||||
print(']')
|
Loading…
Reference in a new issue