41 lines
1.0 KiB
Python
Executable File
41 lines
1.0 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""converts DXT5 dds files to DXT1 without generation loss."""
|
|
|
|
import sys
|
|
import os
|
|
import os.path
|
|
import argparse
|
|
import dds
|
|
|
|
parser = argparse.ArgumentParser(
|
|
description=__doc__)
|
|
parser.add_argument('files', type=str, nargs='*',
|
|
help = "input dds files. Paths are read from stdin if none are given")
|
|
|
|
args = parser.parse_args()
|
|
|
|
if len(args.files) < 1 and not sys.stdin.isatty():
|
|
args.files = sys.stdin.read().splitlines()
|
|
|
|
for argv in args.files:
|
|
path = os.path.abspath(argv)
|
|
|
|
# read DDS file
|
|
with open(path, 'rb') as file:
|
|
ddsfile = dds.DDSFile(file)
|
|
|
|
# check its actually dxt5
|
|
if ddsfile.four_cc != 'DXT5':
|
|
print(f'[{argv}] file is not DXT5, aborting.')
|
|
continue
|
|
print(f'[{argv}] converting to DXT1')
|
|
|
|
# make modifications
|
|
ddsfile.four_cc = 'DXT1'
|
|
ddsfile.textures = [tex.to_dxt1() for tex in ddsfile.textures]
|
|
ddsfile.linear_size //= 2
|
|
|
|
# write DDS file
|
|
with open(path, 'wb') as file:
|
|
ddsfile.write(file)
|