add more options for ddsck and ddscompress
This commit is contained in:
parent
8c320b4ede
commit
e410f0c15c
@ -11,7 +11,7 @@ All files require python3 to be installed.
|
||||
## Usage
|
||||
|
||||
### ddscompress.py
|
||||
usage: `ddscompress.py [-h] [--format {auto,DXT1,DXT5}] [--convertcmd CMD] [--compresscmd CMD] [files ...]`
|
||||
usage: ` ddscompress.py [-h] [--format {auto,DXT1,DXT5}] [--nomips] [--noflip] [--keep] [--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`
|
||||
|
||||
@ -21,6 +21,9 @@ Converts any number of files to `.dds` format, automatically choosing dxt1 or dx
|
||||
##### optional arguments:
|
||||
* `-h, --help `: show this help message and exit
|
||||
* `--format {auto,DXT1,DXT5}`: output texture format (default: auto)
|
||||
* `--nomips, -m`: Do not generate mipmaps
|
||||
* `--noflip, -f`: Do not flip the image
|
||||
* `--keep, -k`: Do not delete originals
|
||||
* `--convertcmd CMD`: name of imagemagick's convert tool (default: `convert`)
|
||||
* `--compresscmd CMD`: name of the nvidia dds compress tool (default: `nvcompress`)
|
||||
|
||||
@ -37,7 +40,7 @@ Converts any number of files to `.tga` from `.dds`. Designed to be used with a g
|
||||
* `--decompresscmd CMD`: name of the nvidia dds decompress tool (default: `nvdecompress`)
|
||||
|
||||
### ddsck.py
|
||||
usage: `ddsck.py [-h] [--convertcmd CMD] [--infocmd CMD] [files ...]`
|
||||
usage: `ddsck.py [-h] [--transparency | --format] [--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`
|
||||
|
||||
@ -46,5 +49,7 @@ Checks any number of dds files for common issues, including formats not supporte
|
||||
|
||||
##### optional arguments:
|
||||
* `-h, --help`: show this help message and exit
|
||||
* `--transparency, -t`: Generate a list of files that fail the transparency check
|
||||
* `--format, -f`: Generate a list of files that fail the format check
|
||||
* `--convertcmd CMD`: name of imagemagick's convert tool (default: `convert`)
|
||||
* `--infocmd CMD`: name of the nvidia dds info tool (default: `nvddsinfo`)
|
@ -8,6 +8,11 @@ import dds
|
||||
|
||||
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")
|
||||
|
||||
modes = parser.add_mutually_exclusive_group()
|
||||
modes.add_argument('--transparency', '-t', dest='mode', action='store_const', const="transparency", default="none", help = "Generate a list of files that fail the transparency check")
|
||||
modes.add_argument('--format', '-f', dest='mode', action='store_const', const="format", default="none", help = "Generate a list of files that fail the format check")
|
||||
|
||||
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)")
|
||||
|
||||
@ -26,7 +31,13 @@ for argv in args.files:
|
||||
if format == "DXT1":
|
||||
pass
|
||||
elif format == "DXT5":
|
||||
if alpha > 254:
|
||||
print(f'[{argv}]: Image is DXT5 but has no alpha channel')
|
||||
if alpha > 254:
|
||||
if args.mode == 'none':
|
||||
print(f'[{argv}]: Image is DXT5 but has no alpha channel')
|
||||
elif args.mode == 'transparency':
|
||||
print(file)
|
||||
else:
|
||||
print(f'[{argv}]: incompatible format')
|
||||
if args.mode == 'none':
|
||||
print(f'[{argv}]: incompatible format')
|
||||
elif args.mode == 'format':
|
||||
print(file)
|
@ -3,6 +3,7 @@
|
||||
import sys
|
||||
import os
|
||||
import os.path
|
||||
import shutil
|
||||
import tempfile
|
||||
import argparse
|
||||
import dds
|
||||
@ -10,7 +11,9 @@ 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('--nomips', '-m', dest='mips', action='store_false', help = "Do not generate mipmaps")
|
||||
parser.add_argument('--noflip', '-f', dest='flip', action='store_false', help = "Do not flip the image")
|
||||
parser.add_argument('--keep', '-k', dest='delete', action='store_false', help = "Do not delete originals")
|
||||
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)")
|
||||
|
||||
@ -23,10 +26,13 @@ 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 (os.path.splitext(file)[1] != ".dds") and args.flip:
|
||||
tmpOutput = os.path.join(tempDir, os.path.basename(file))
|
||||
dds.flip(file, tmpOutput)
|
||||
else:
|
||||
tmpOutput = file
|
||||
|
||||
if (args.format == "auto" and dds.alpha(file) < 255) or args.format == "DXT5":
|
||||
format = "-bc3"
|
||||
@ -34,5 +40,5 @@ with tempfile.TemporaryDirectory() as tempDir:
|
||||
format = "-bc1"
|
||||
|
||||
dds.nvcompress(format, tmpOutput, output, args.mips)
|
||||
if os.path.basename(file) != os.path.basename(output):
|
||||
if (os.path.basename(file) != os.path.basename(output)) and args.delete:
|
||||
os.remove(file)
|
Loading…
Reference in New Issue
Block a user