forked from projectpokemon/PPRE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathndsbanner.py
27 lines (25 loc) · 879 Bytes
/
ndsbanner.py
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
from gen import *
import os, sys, struct
from PIL import Image
if "--dump-banner" in sys.argv:
for game in games:
os.system("./ndstool -x local/roms/%s.nds -t %s%s/banner.bin"%(game, DATA_DIR, game))
for game in games:
banner = open(DATA_DIR+game+"/banner.bin", "rb")
oname = STATIC_DIR+game+"/banner.png"
banner.seek(32)
im = Image.new("P", (32, 32))
data = im.load()
for i in range(4):
for j in range(4):
for k in range(8):
for l in range(4):
p = ord(banner.read(1))
data[j*8+l*2+1, i*8+k] = p>>4
data[j*8+l*2, i*8+k] = p&0xF
colors = []
for i in range(16):
p = struct.unpack("H", banner.read(2))[0]
colors.extend([((p>>0)&0x1F)<<3, ((p>>5)&0x1F)<<3, ((p>>10)&0x1F)<<3])
im.putpalette(colors)
im.save(oname)