Research
This commit is contained in:
parent
28cbbe3470
commit
a9153546ae
56 changed files with 6731 additions and 258 deletions
57
tools/vertical_strip_crops.py
Normal file
57
tools/vertical_strip_crops.py
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
import struct, zlib, os
|
||||
IN_BIN = r"K:\ghidra\Crusader_Decomp\binary\Crusader - No Remorse Memdump Weapons.bin"
|
||||
OUT_DIR = r"K:\ghidra\Crusader_Decomp\binary\vstrip_crops"
|
||||
W,H = 1024,512
|
||||
x0 = 956
|
||||
x1 = 1023
|
||||
w = x1 - x0 + 1
|
||||
step_h = 48
|
||||
import math
|
||||
os.makedirs(OUT_DIR, exist_ok=True)
|
||||
with open(IN_BIN,'rb') as f:
|
||||
data = f.read()
|
||||
count = min(len(data)//2, W*H)
|
||||
# build full RGB rows
|
||||
rows = []
|
||||
for y in range(H):
|
||||
row = bytearray()
|
||||
for x in range(W):
|
||||
i = y*W + x
|
||||
if i < count:
|
||||
off = i*2
|
||||
val = data[off] | (data[off+1]<<8)
|
||||
b = (val & 0x1F) << 3
|
||||
g = ((val >>5) & 0x1F) << 3
|
||||
r = ((val >>10) & 0x1F) << 3
|
||||
else:
|
||||
r=g=b=0
|
||||
row.extend([r,g,b])
|
||||
rows.append(bytes(row))
|
||||
# produce crops
|
||||
import struct, zlib
|
||||
def chunk(t,d):
|
||||
out = struct.pack('>I', len(d)) + t + d
|
||||
crc = zlib.crc32(t + d) & 0xffffffff
|
||||
out += struct.pack('>I', crc)
|
||||
return out
|
||||
for i in range(0, H, step_h):
|
||||
y0 = i
|
||||
y1 = min(H-1, i+step_h-1)
|
||||
h = y1 - y0 + 1
|
||||
rawrows = []
|
||||
for y in range(y0, y1+1):
|
||||
rawrows.append(b"\x00" + rows[y][x0*3:(x0+w)*3])
|
||||
raw = b"".join(rawrows)
|
||||
comp = zlib.compress(raw,9)
|
||||
png = b"\x89PNG\r\n\x1a\n"
|
||||
png += chunk(b'IHDR', struct.pack('>IIBBBBB', w, h, 8, 2, 0, 0, 0))
|
||||
png += chunk(b'IDAT', comp)
|
||||
png += chunk(b'IEND', b'')
|
||||
out = os.path.join(OUT_DIR, f'vstrip_{y0:03d}_{y1:03d}.png')
|
||||
with open(out,'wb') as f:
|
||||
f.write(png)
|
||||
start_idx = y0*W + x0
|
||||
end_idx = y1*W + x1
|
||||
so = start_idx*2
|
||||
eo = (end_idx+1)*2 -1
|
||||
print(out, f'box=({x0},{y0})-({x1},{y1}) bytes=0x{so:06x}-0x{eo:06x}')
|
||||
Loading…
Add table
Add a link
Reference in a new issue