From 8c320b4ede703e4a259d4e454dc5e8f4169b2dde Mon Sep 17 00:00:00 2001 From: drewcassidy Date: Wed, 20 Jan 2021 02:28:17 -0800 Subject: [PATCH] add options to not generate mipmaps and dont delete if input=output --- Scripts/dds.py | 8 ++++++-- Scripts/ddscompress.py | 8 +++++--- Scripts/ddsdecompress.py | 3 ++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Scripts/dds.py b/Scripts/dds.py index c4fa575..58ece7f 100644 --- a/Scripts/dds.py +++ b/Scripts/dds.py @@ -10,8 +10,12 @@ def flip(file, output): result = subprocess.run([convertcmd, '-flip', file, output], capture_output=True) result.check_returncode() -def nvcompress(format, file, output): - result = subprocess.run([compresscmd, format, file, output], capture_output=True) +def nvcompress(format, file, output, mips = True): + args = [format] + if not mips: + args.append('-nomips') + + result = subprocess.run([compresscmd] + args + [file, output], capture_output=True) result.check_returncode() def nvdecompress(file, output): diff --git a/Scripts/ddscompress.py b/Scripts/ddscompress.py index 9f1a104..2672a9e 100755 --- a/Scripts/ddscompress.py +++ b/Scripts/ddscompress.py @@ -10,6 +10,7 @@ import dds parser = argparse.ArgumentParser(description="Converts any number of textures to dds format. automatically chooses dxt1 or dxt5 depending on if the source image has anything in its alpha channel.") parser.add_argument('files', type=str, nargs='*', help = "input texture files") parser.add_argument('--format', type=str, choices=['auto', 'DXT1', 'DXT5'], default = "auto", help = "output texture format (default: %(default)s)") +parser.add_argument('--nomips', '-n', dest='mips', action='store_false', help = "Do not generate mipmaps") parser.add_argument('--convertcmd', type=str, metavar='CMD', default="convert", help="name of imagemagick's convert tool (default: %(default)s)") parser.add_argument('--compresscmd', type=str, metavar='CMD', default="nvcompress", help="name of the nvidia dds compress tool (default: %(default)s)") @@ -26,11 +27,12 @@ with tempfile.TemporaryDirectory() as tempDir: output = os.path.splitext(file)[0] + ".dds" dds.flip(file, tmpOutput) - + if (args.format == "auto" and dds.alpha(file) < 255) or args.format == "DXT5": format = "-bc3" else: format = "-bc1" - dds.nvcompress(format, tmpOutput, output) - os.remove(file) \ No newline at end of file + dds.nvcompress(format, tmpOutput, output, args.mips) + if os.path.basename(file) != os.path.basename(output): + os.remove(file) \ No newline at end of file diff --git a/Scripts/ddsdecompress.py b/Scripts/ddsdecompress.py index 7d9ea14..1865e29 100755 --- a/Scripts/ddsdecompress.py +++ b/Scripts/ddsdecompress.py @@ -20,4 +20,5 @@ for argv in args.files: output = os.path.splitext(file)[0] + f".tga" dds.nvdecompress(file, output) - os.remove(file) \ No newline at end of file + if os.path.basename(file) != os.path.basename(output): + os.remove(file) \ No newline at end of file