1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
#!/bin/python3
# read packed tilemap file from stdin and output png on stdout
import sys
import io
import struct
from PIL import Image
color_map = (
(0x00, 0x00, 0x00),
(0x24, 0x24, 0x24),
(0x49, 0x49, 0x49),
(0x6d, 0x6d, 0x6d),
(0x92, 0x92, 0x92),
(0xb6, 0xb6, 0xb6),
(0xda, 0xda, 0xda),
(0xff, 0xff, 0xff),
)
buf = []
for byte in sys.stdin.buffer.read():
buf.append(byte)
size_horizontal = 16 * 16
size_vertical = ((len(buf) // 104) // 16 + 1) * 16
img = Image.new('RGB', (size_horizontal, size_vertical))
i = 0
sprite_idx = 0
for x in range(0, len(buf), 2):
word = 0x0000
word |= buf[x]
word |= buf[x+1] << 8
for p in range(5):
img.putpixel(((i % 16) + (16 * (sprite_idx % 16)), (i // 16) + (16 * (sprite_idx // 16))), color_map[(word >> (p * 3)) & 0b111])
i += 1
if i > 0xff:
i = 0
sprite_idx += 1
break
with io.BytesIO() as out:
img.save(out, format="PNG")
sys.stdout.buffer.write(out.getvalue())
sys.stdout.buffer.flush()
|