use argparse
This commit is contained in:
parent
8b5ed4e24b
commit
ce2ea3be61
@ -11,13 +11,38 @@ All files require python3 to be installed.
|
||||
## Usage
|
||||
|
||||
### ddscompress.py
|
||||
usage: `ddscompress.py [-h] [--convertcmd CMD] [--compresscmd CMD] [files ...]`
|
||||
|
||||
Converts any number of files to `.dds` format, automatically choosing dxt1 or dxt5 depending on if the source image has anything in its alpha channel. Designed to be used with a glob, e.g: `ddscompress.py *.png`
|
||||
|
||||
### ddsdecompress.py
|
||||
positional arguments:
|
||||
`files`: input texture files
|
||||
|
||||
Converts any number of files to `.png` from `.dds`. Designed to be used with a glob, e.g: `ddsdecompress.py *.dds`
|
||||
optional arguments:
|
||||
`-h, --help `: show this help message and exit
|
||||
`--convertcmd CMD`: name of imagemagick's convert tool (default: `convert`)
|
||||
`--compresscmd CMD`: name of the nvidia dds compress tool (default: `nvcompress`)
|
||||
|
||||
### ddsdecompress.py
|
||||
usage: `ddsdecompress.py [-h] [--decompresscmd CMD] [files ...]`
|
||||
|
||||
Converts any number of files to `.tga` from `.dds`. Designed to be used with a glob, e.g: `ddsdecompress.py *.dds`
|
||||
positional arguments:
|
||||
`files`: input dds files
|
||||
|
||||
optional arguments:
|
||||
`-h, --help`: show this help message and exit
|
||||
`--decompresscmd CMD`: name of the nvidia dds decompress tool (default: `nvdecompress`)
|
||||
|
||||
### ddsck.py
|
||||
usage: `ddsck.py [-h] [--convertcmd CMD] [--infocmd CMD] [files ...]`
|
||||
|
||||
Checks any number of dds files for common issues, including formats not supported by KSP, and DXT5 textures that don't use the alpha channel. Designed to be used with a glob, e.g: `ddsck.py *.dds`
|
||||
Checks any number of dds files for common issues, including formats not supported by KSP, and DXT5 textures that don't use the alpha channel. Designed to be used with a glob, e.g: `ddsck.py *.dds`
|
||||
|
||||
positional arguments:
|
||||
`files`: input dds files
|
||||
|
||||
optional arguments:
|
||||
`-h, --help`: show this help message and exit
|
||||
`--convertcmd CMD`: name of imagemagick's convert tool (default: `convert`)
|
||||
`--infocmd CMD`: name of the nvidia dds info tool (default: `nvddsinfo`)
|
@ -2,25 +2,24 @@ import subprocess
|
||||
import re
|
||||
|
||||
def alpha(file):
|
||||
result = subprocess.run(["convert", file, "-resize", "1x1", "-format", "%[fx:int(255*a+.5)]", "info:-"], capture_output=True)
|
||||
result = subprocess.run([convertcmd, file, "-resize", "1x1", "-format", "%[fx:int(255*a+.5)]", "info:-"], capture_output=True)
|
||||
result.check_returncode()
|
||||
return int(result.stdout)
|
||||
|
||||
def flip(file, output):
|
||||
result = subprocess.run(['convert', '-flip', file, output], capture_output=True)
|
||||
result = subprocess.run([convertcmd, '-flip', file, output], capture_output=True)
|
||||
result.check_returncode()
|
||||
|
||||
def nvcompress(format, file, output):
|
||||
result = subprocess.run(['nvcompress', format, file, output], capture_output=True)
|
||||
result = subprocess.run([compresscmd, format, file, output], capture_output=True)
|
||||
result.check_returncode()
|
||||
print(result)
|
||||
|
||||
def nvdecompress(file, output):
|
||||
result = subprocess.run(['nvdecompress', '-format', 'png', file, output], capture_output=True)
|
||||
result = subprocess.run([decompresscmd, file, output], capture_output=True)
|
||||
result.check_returncode()
|
||||
|
||||
def nvinfo(file):
|
||||
result = subprocess.run(['nvddsinfo', file], capture_output=True)
|
||||
result = subprocess.run([infocmd, file], capture_output=True)
|
||||
result.check_returncode()
|
||||
|
||||
info = {
|
||||
|
@ -3,11 +3,21 @@
|
||||
import sys
|
||||
import os
|
||||
import os.path
|
||||
import argparse
|
||||
import dds
|
||||
|
||||
for argv in sys.argv[1:]:
|
||||
parser = argparse.ArgumentParser(description="Checks any number of dds files for common issues, including formats not supported by KSP, and DXT5 textures that don't use the alpha channel.")
|
||||
parser.add_argument('files', type=str, nargs='*', help = "input dds files")
|
||||
parser.add_argument('--convertcmd', type=str, metavar='CMD', default="convert", help="name of imagemagick's convert tool (default: %(default)s)")
|
||||
parser.add_argument('--infocmd', type=str, metavar='CMD', default="nvddsinfo", help="name of the nvidia dds info tool (default: %(default)s)")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
dds.convertcmd = args.convertcmd
|
||||
dds.infocmd = args.infocmd
|
||||
|
||||
for argv in args.files:
|
||||
file = os.path.abspath(argv)
|
||||
output = os.path.splitext(file)[0] + ".png"
|
||||
|
||||
info = dds.nvinfo(file)
|
||||
format = info["format"]
|
||||
|
@ -4,10 +4,21 @@ import sys
|
||||
import os
|
||||
import os.path
|
||||
import tempfile
|
||||
import argparse
|
||||
import dds
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="dds") as tempDir:
|
||||
for argv in sys.argv[1:]:
|
||||
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('--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))
|
||||
@ -16,11 +27,9 @@ with tempfile.TemporaryDirectory(prefix="dds") as tempDir:
|
||||
alpha = dds.alpha(file)
|
||||
dds.flip(file, tmpOutput)
|
||||
|
||||
print(alpha)
|
||||
if alpha < 255:
|
||||
format = "-bc3"
|
||||
else:
|
||||
format = "-bc1"
|
||||
print(format)
|
||||
dds.nvcompress(format, tmpOutput, output)
|
||||
os.remove(file)
|
@ -3,12 +3,21 @@
|
||||
import sys
|
||||
import os
|
||||
import os.path
|
||||
import argparse
|
||||
import dds
|
||||
|
||||
for argv in sys.argv[1:]:
|
||||
print(f'[{argv}]: converting from dds')
|
||||
parser = argparse.ArgumentParser(description="Converts any number of files from dds to tga.")
|
||||
parser.add_argument('files', type=str, nargs='*', help = "input dds files")
|
||||
parser.add_argument('--decompresscmd', type=str, metavar='CMD', default="nvdecompress", help="name of the nvidia dds decompress tool (default: %(default)s)")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
dds.decompresscmd = args.decompresscmd
|
||||
|
||||
for argv in args.files:
|
||||
print(f'[{argv}]: converting from dds to tga')
|
||||
file = os.path.abspath(argv)
|
||||
output = os.path.splitext(file)[0] + ".png"
|
||||
output = os.path.splitext(file)[0] + f".tga"
|
||||
|
||||
dds.nvdecompress(file, output)
|
||||
os.remove(file)
|
Loading…
Reference in New Issue
Block a user