Tools: Spit out dotcodes that mGBA can read
This commit is contained in:
parent
4bb8744cd5
commit
2e0c245e2d
@ -34,8 +34,6 @@ for i in range(16):
|
||||
for i in range(16):
|
||||
gg[i] = rev[gg[i]]
|
||||
|
||||
print(*[hex(x) for x in gg])
|
||||
|
||||
def interleave(data, header):
|
||||
data = data.reshape([-1, 48]).T
|
||||
new_data = np.zeros((64, data.shape[1]), dtype=data.dtype)
|
||||
@ -88,28 +86,25 @@ def bin2raw(data):
|
||||
new_data = interleave(np.frombuffer(data, np.uint8), header)
|
||||
return new_data.tobytes()
|
||||
|
||||
with open(sys.argv[1], 'rb') as f:
|
||||
data = f.read()
|
||||
def make_dotcode(data):
|
||||
size = len(data)
|
||||
|
||||
if size in (1344, 2112):
|
||||
data = bin2raw(data)
|
||||
size = len(data)
|
||||
with open('dotcode.raw', 'wb') as f:
|
||||
f.write(data)
|
||||
|
||||
blocks = size // blocksize
|
||||
height = 36
|
||||
width = 35
|
||||
margin = 2
|
||||
|
||||
dots = np.zeros((width * blocks + margin * 2 + 1, height + margin * 2), dtype=np.bool)
|
||||
dots = np.zeros((width * blocks + margin * 2 + 1, height + margin * 2), dtype=bool)
|
||||
anchor = np.array([[0, 1, 1, 1, 0],
|
||||
[1, 1, 1, 1, 1],
|
||||
[1, 1, 1, 1, 1],
|
||||
[1, 1, 1, 1, 1],
|
||||
[0, 1, 1, 1, 0]], dtype=np.bool)
|
||||
alignment = np.array([1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0], dtype=np.bool)
|
||||
[0, 1, 1, 1, 0]], dtype=bool)
|
||||
alignment = np.array([1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0], dtype=bool)
|
||||
nybbles = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 1], [0, 0, 0, 1, 0], [1, 0, 0, 1, 0],
|
||||
[0, 0, 1, 0, 0], [0, 0, 1, 0, 1], [0, 0, 1, 1, 0], [1, 0, 1, 1, 0],
|
||||
[0, 1, 0, 0, 0], [0, 1, 0, 0, 1], [0, 1, 0, 1, 0], [1, 0, 1, 0, 0],
|
||||
@ -149,6 +144,11 @@ for i in range(blocks):
|
||||
for y in range(3):
|
||||
dots[i * width + margin + 5:i * width + margin + 31, margin + 31 + y] = block[j:j + 26]
|
||||
j += 26
|
||||
im = PIL.Image.fromarray(dots.T)
|
||||
return np.pad(dots.T, 2)
|
||||
|
||||
with open(sys.argv[1], 'rb') as f:
|
||||
dots = make_dotcode(f.read())
|
||||
|
||||
im = PIL.Image.fromarray(dots)
|
||||
im = PIL.ImageChops.invert(im)
|
||||
im.save('dotcode.png')
|
||||
im.save('dotcode.bmp')
|
||||
|
Loading…
x
Reference in New Issue
Block a user