mirror of
https://github.com/pret/pokemon-reverse-engineering-tools.git
synced 2026-09-26 11:29:34 -05:00
gfx: Decompress graphics that can be converted to png.
Before, converting a .2bpp.lz file required calling decompress and convert_to_png
on the compressed and decompressed files respectively.
gfx.py unlz {}.lz
gfx.py png {}
Putting a .lz file into convert_to_png would raise an exception.
Instead, passing compressed graphics into convert_to_png will decompress them first.
This skips the (now optional) manual decompress step.
This commit is contained in:
@@ -1834,7 +1834,7 @@ def expand_pic_palettes():
|
||||
|
||||
def convert_to_2bpp(filenames=[]):
|
||||
for filename in filenames:
|
||||
name, extension = os.path.splitext(filename)
|
||||
filename, name, extension = try_decompress(filename)
|
||||
if extension == '.1bpp':
|
||||
export_1bpp_to_2bpp(filename)
|
||||
elif extension == '.2bpp':
|
||||
@@ -1846,7 +1846,7 @@ def convert_to_2bpp(filenames=[]):
|
||||
|
||||
def convert_to_1bpp(filenames=[]):
|
||||
for filename in filenames:
|
||||
name, extension = os.path.splitext(filename)
|
||||
filename, name, extension = try_decompress(filename)
|
||||
if extension == '.1bpp':
|
||||
pass
|
||||
elif extension == '.2bpp':
|
||||
@@ -1858,7 +1858,7 @@ def convert_to_1bpp(filenames=[]):
|
||||
|
||||
def convert_to_png(filenames=[]):
|
||||
for filename in filenames:
|
||||
name, extension = os.path.splitext(filename)
|
||||
filename, name, extension = try_decompress(filename)
|
||||
if extension == '.1bpp':
|
||||
export_1bpp_to_png(filename)
|
||||
elif extension == '.2bpp':
|
||||
@@ -1881,6 +1881,19 @@ def decompress(filenames=[]):
|
||||
data = Decompressed(lz_data).output
|
||||
to_file(name, data)
|
||||
|
||||
def try_decompress(filename):
|
||||
"""
|
||||
Try to decompress a graphic when determining the filetype.
|
||||
This skips the manual unlz step when attempting
|
||||
to convert lz-compressed graphics to png.
|
||||
"""
|
||||
name, extension = os.path.splitext(filename)
|
||||
if extension == '.lz':
|
||||
decompress([filename])
|
||||
filename = name
|
||||
name, extension = os.path.splitext(filename)
|
||||
return filename, name, extension
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser()
|
||||
|
||||
Reference in New Issue
Block a user