You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.6 KiB
Python
38 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import sys
|
|
import os
|
|
import os.path
|
|
import tempfile
|
|
import argparse
|
|
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)")
|
|
|
|
args = parser.parse_args()
|
|
|
|
dds.convertcmd = args.convertcmd
|
|
dds.compresscmd = args.compresscmd
|
|
|
|
with tempfile.TemporaryDirectory() as tempDir:
|
|
for argv in args.files:
|
|
print(f'[{argv}]: converting to dds')
|
|
file = os.path.abspath(argv)
|
|
tmpOutput = os.path.join(tempDir, os.path.basename(file))
|
|
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, args.mips)
|
|
if os.path.basename(file) != os.path.basename(output):
|
|
os.remove(file) |