mirror of
https://github.com/ACreTeam/ac-decomp
synced 2026-05-23 06:34:18 -04:00
speedup pal16 and vtx extraction
This commit is contained in:
@@ -5,15 +5,11 @@ import struct
|
||||
def convert_binary_to_vtx_c_source(src_path, dest_path):
|
||||
# Load data
|
||||
with open(src_path, "rb") as binary_file, open(dest_path, "w") as c_file:
|
||||
while True:
|
||||
chunk = binary_file.read(2) # 2 bytes for each 16-bit palette entry
|
||||
|
||||
if len(chunk) < 2:
|
||||
break
|
||||
|
||||
pal = struct.unpack(">H", chunk[0:2]) # 2 bytes
|
||||
|
||||
c_file.write(f"{hex(pal[0])}, ")
|
||||
all_bin = binary_file.read()
|
||||
# parse all data as an array of u16,
|
||||
# use tuple's str method to create "(1, 2, 3)", and then sub-string to remove the parentheses
|
||||
c_file.write(
|
||||
str(struct.unpack(">" + "H" * (len(all_bin) // 2), all_bin))[1:-1])
|
||||
|
||||
|
||||
def main():
|
||||
@@ -21,7 +17,8 @@ def main():
|
||||
description="Converts a binary file to an array of u16 type"
|
||||
)
|
||||
parser.add_argument("src_path", type=str, help="Binary source file path")
|
||||
parser.add_argument("dest_path", type=str, help="Destination C include file path")
|
||||
parser.add_argument("dest_path", type=str,
|
||||
help="Destination C include file path")
|
||||
|
||||
args = parser.parse_args()
|
||||
convert_binary_to_vtx_c_source(args.src_path, args.dest_path)
|
||||
|
||||
@@ -5,20 +5,10 @@ import struct
|
||||
def convert_binary_to_vtx_c_source(src_path, dest_path):
|
||||
# Load data
|
||||
with open(src_path, "rb") as binary_file, open(dest_path, "w") as c_file:
|
||||
while True:
|
||||
chunk = binary_file.read(16) # 16 bytes for each Vtx struct
|
||||
|
||||
if len(chunk) < 16:
|
||||
break
|
||||
|
||||
ob = struct.unpack(">hhh", chunk[0:6]) # 3 * 2 bytes
|
||||
flag = struct.unpack(">H", chunk[6:8]) # 2 bytes
|
||||
tc = struct.unpack(">hh", chunk[8:12]) # 2 * 2 bytes
|
||||
cn = struct.unpack(">BBBB", chunk[12:16]) # 4 * 1 byte
|
||||
|
||||
c_file.write(
|
||||
f" {{{ob[0]}, {ob[1]}, {ob[2]}, {flag[0]}, {tc[0]}, {tc[1]}, {cn[0]}, {cn[1]}, {cn[2]}, {cn[3]}}},\n"
|
||||
)
|
||||
# iter through all data, consuming one vtx at a time
|
||||
for vtx_tuple in struct.iter_unpack(">hhhHhhBBBB", binary_file.read()):
|
||||
# use tuple's str method to create "(1, 2, 3)", and then sub-string to remove the parentheses
|
||||
c_file.write(f" {{{str(vtx_tuple)[1:-1]}}},\n")
|
||||
|
||||
|
||||
def main():
|
||||
@@ -26,7 +16,8 @@ def main():
|
||||
description="Converts a binary file to an array of N64 Vtx type"
|
||||
)
|
||||
parser.add_argument("src_path", type=str, help="Binary source file path")
|
||||
parser.add_argument("dest_path", type=str, help="Destination C include file path")
|
||||
parser.add_argument("dest_path", type=str,
|
||||
help="Destination C include file path")
|
||||
|
||||
args = parser.parse_args()
|
||||
convert_binary_to_vtx_c_source(args.src_path, args.dest_path)
|
||||
|
||||
Reference in New Issue
Block a user