|
|
@ -1,13 +1,14 @@
|
|
|
|
import click
|
|
|
|
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
import pathlib
|
|
|
|
|
|
|
|
|
|
|
|
import click
|
|
|
|
|
|
|
|
from PIL import Image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import quicktex.cli.common as common
|
|
|
|
|
|
|
|
import quicktex.dds as dds
|
|
|
|
import quicktex.s3tc.bc1
|
|
|
|
import quicktex.s3tc.bc1
|
|
|
|
import quicktex.s3tc.bc3
|
|
|
|
import quicktex.s3tc.bc3
|
|
|
|
import quicktex.s3tc.bc4
|
|
|
|
import quicktex.s3tc.bc4
|
|
|
|
import quicktex.s3tc.bc5
|
|
|
|
import quicktex.s3tc.bc5
|
|
|
|
import quicktex.dds as dds
|
|
|
|
|
|
|
|
import quicktex.cli.common as common
|
|
|
|
|
|
|
|
from PIL import Image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@click.group()
|
|
|
|
@click.group()
|
|
|
@ -16,17 +17,31 @@ def encode():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@click.command()
|
|
|
|
@click.command()
|
|
|
|
@click.option('-f/-F', '--flip/--no-flip', default=True, show_default=True, help="Vertically flip image before converting.")
|
|
|
|
@click.option(
|
|
|
|
|
|
|
|
'-f/-F', '--flip/--no-flip', default=True, show_default=True, help="Vertically flip image before converting."
|
|
|
|
|
|
|
|
)
|
|
|
|
@click.option('-r', '--remove', is_flag=True, help="Remove input images after converting.")
|
|
|
|
@click.option('-r', '--remove', is_flag=True, help="Remove input images after converting.")
|
|
|
|
@click.option('-s', '--suffix', type=str, default='', help="Suffix to append to output file(s). Ignored if output is a single file.")
|
|
|
|
@click.option(
|
|
|
|
@click.option('-o', '--output',
|
|
|
|
'-s',
|
|
|
|
type=click.Path(writable=True), default=None,
|
|
|
|
'--suffix',
|
|
|
|
help="Output file or directory. If outputting to a file, input filenames must be only a single item. By default, files are decoded in place.")
|
|
|
|
type=str,
|
|
|
|
|
|
|
|
default='',
|
|
|
|
|
|
|
|
help="Suffix to append to output file(s). Ignored if output is a single file.",
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
@click.option(
|
|
|
|
|
|
|
|
'-o',
|
|
|
|
|
|
|
|
'--output',
|
|
|
|
|
|
|
|
type=click.Path(writable=True),
|
|
|
|
|
|
|
|
default=None,
|
|
|
|
|
|
|
|
help="Output file or directory. If outputting to a file, input filenames must be only a single item. By default, files are decoded in place.",
|
|
|
|
|
|
|
|
)
|
|
|
|
@click.argument('filenames', nargs=-1, type=click.Path(exists=True, readable=True, dir_okay=False))
|
|
|
|
@click.argument('filenames', nargs=-1, type=click.Path(exists=True, readable=True, dir_okay=False))
|
|
|
|
def encode_format(encoder, four_cc, flip, remove, suffix, output, filenames):
|
|
|
|
def encode_format(encoder, four_cc, flip, remove, suffix, output, filenames):
|
|
|
|
path_pairs = common.path_pairs(filenames, output, suffix, '.dds')
|
|
|
|
path_pairs = common.path_pairs(filenames, output, suffix, '.dds')
|
|
|
|
|
|
|
|
|
|
|
|
with click.progressbar(path_pairs, show_eta=False, show_pos=True, item_show_func=lambda x: str(x[0]) if x else '') as bar:
|
|
|
|
with click.progressbar(
|
|
|
|
|
|
|
|
path_pairs, show_eta=False, show_pos=True, item_show_func=lambda x: str(x[0]) if x else ''
|
|
|
|
|
|
|
|
) as bar:
|
|
|
|
for inpath, outpath in bar:
|
|
|
|
for inpath, outpath in bar:
|
|
|
|
image = Image.open(inpath)
|
|
|
|
image = Image.open(inpath)
|
|
|
|
|
|
|
|
|
|
|
@ -40,17 +55,44 @@ def encode_format(encoder, four_cc, flip, remove, suffix, output, filenames):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@click.command('auto')
|
|
|
|
@click.command('auto')
|
|
|
|
@click.option('-l', '--level', type=click.IntRange(0, 18), default=18, help='Quality level to use. Higher values = higher quality, but slower.')
|
|
|
|
@click.option(
|
|
|
|
@click.option('-b/-B', '--black/--no-black',
|
|
|
|
'-l',
|
|
|
|
help='[BC1 only] Enable 3-color mode for blocks containing black or very dark pixels. --3color must also be enabled for this to work.'
|
|
|
|
'--level',
|
|
|
|
' (Important: engine/shader MUST ignore decoded texture alpha if this flag is enabled!)')
|
|
|
|
type=click.IntRange(0, 18),
|
|
|
|
@click.option('-3/-4', '--3color/--4color', 'threecolor', default=True, help='[BC1 only] Enable 3-color mode for non-black pixels. Higher quality, but slightly slower.')
|
|
|
|
default=18,
|
|
|
|
@click.option('-f/-F', '--flip/--no-flip', default=True, show_default=True, help="Vertically flip image before converting.")
|
|
|
|
help='Quality level to use. Higher values = higher quality, but slower.',
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
@click.option(
|
|
|
|
|
|
|
|
'-b/-B',
|
|
|
|
|
|
|
|
'--black/--no-black',
|
|
|
|
|
|
|
|
help='[BC1 only] Enable 3-color mode for blocks containing black or very dark pixels. --3color must also be enabled for this to work.'
|
|
|
|
|
|
|
|
' (Important: engine/shader MUST ignore decoded texture alpha if this flag is enabled!)',
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
@click.option(
|
|
|
|
|
|
|
|
'-3/-4',
|
|
|
|
|
|
|
|
'--3color/--4color',
|
|
|
|
|
|
|
|
'threecolor',
|
|
|
|
|
|
|
|
default=True,
|
|
|
|
|
|
|
|
help='[BC1 only] Enable 3-color mode for non-black pixels. Higher quality, but slightly slower.',
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
@click.option(
|
|
|
|
|
|
|
|
'-f/-F', '--flip/--no-flip', default=True, show_default=True, help="Vertically flip image before converting."
|
|
|
|
|
|
|
|
)
|
|
|
|
@click.option('-r', '--remove', is_flag=True, help="Remove input images after converting.")
|
|
|
|
@click.option('-r', '--remove', is_flag=True, help="Remove input images after converting.")
|
|
|
|
@click.option('-s', '--suffix', type=str, default='', help="Suffix to append to output file(s). Ignored if output is a single file.")
|
|
|
|
@click.option(
|
|
|
|
@click.option('-o', '--output',
|
|
|
|
'-s',
|
|
|
|
type=click.Path(writable=True), default=None,
|
|
|
|
'--suffix',
|
|
|
|
help="Output file or directory. If outputting to a file, input filenames must be only a single item. By default, files are decoded in place.")
|
|
|
|
type=str,
|
|
|
|
|
|
|
|
default='',
|
|
|
|
|
|
|
|
help="Suffix to append to output file(s). Ignored if output is a single file.",
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
@click.option(
|
|
|
|
|
|
|
|
'-o',
|
|
|
|
|
|
|
|
'--output',
|
|
|
|
|
|
|
|
type=click.Path(writable=True),
|
|
|
|
|
|
|
|
default=None,
|
|
|
|
|
|
|
|
help="Output file or directory. If outputting to a file, input filenames must be only a single item. By default, files are decoded in place.",
|
|
|
|
|
|
|
|
)
|
|
|
|
@click.argument('filenames', nargs=-1, type=click.Path(exists=True, readable=True, dir_okay=False))
|
|
|
|
@click.argument('filenames', nargs=-1, type=click.Path(exists=True, readable=True, dir_okay=False))
|
|
|
|
def encode_auto(level, black, threecolor, flip, remove, suffix, output, filenames):
|
|
|
|
def encode_auto(level, black, threecolor, flip, remove, suffix, output, filenames):
|
|
|
|
"""Encode images to BC1 or BC3, with the format chosen based on each image's alpha channel."""
|
|
|
|
"""Encode images to BC1 or BC3, with the format chosen based on each image's alpha channel."""
|
|
|
@ -67,7 +109,9 @@ def encode_auto(level, black, threecolor, flip, remove, suffix, output, filename
|
|
|
|
bc3_encoder = quicktex.s3tc.bc3.BC3Encoder(level)
|
|
|
|
bc3_encoder = quicktex.s3tc.bc3.BC3Encoder(level)
|
|
|
|
path_pairs = common.path_pairs(filenames, output, suffix, '.dds')
|
|
|
|
path_pairs = common.path_pairs(filenames, output, suffix, '.dds')
|
|
|
|
|
|
|
|
|
|
|
|
with click.progressbar(path_pairs, show_eta=False, show_pos=True, item_show_func=lambda x: str(x[0]) if x else '') as bar:
|
|
|
|
with click.progressbar(
|
|
|
|
|
|
|
|
path_pairs, show_eta=False, show_pos=True, item_show_func=lambda x: str(x[0]) if x else ''
|
|
|
|
|
|
|
|
) as bar:
|
|
|
|
for inpath, outpath in bar:
|
|
|
|
for inpath, outpath in bar:
|
|
|
|
image = Image.open(inpath)
|
|
|
|
image = Image.open(inpath)
|
|
|
|
|
|
|
|
|
|
|
@ -90,11 +134,26 @@ def encode_auto(level, black, threecolor, flip, remove, suffix, output, filename
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@click.command('bc1')
|
|
|
|
@click.command('bc1')
|
|
|
|
@click.option('-l', '--level', type=click.IntRange(0, 18), default=18, help='Quality level to use. Higher values = higher quality, but slower.')
|
|
|
|
@click.option(
|
|
|
|
@click.option('-b/-B', '--black/--no-black',
|
|
|
|
'-l',
|
|
|
|
help='Enable 3-color mode for blocks containing black or very dark pixels. --3color must also be enabled for this to work.'
|
|
|
|
'--level',
|
|
|
|
' (Important: engine/shader MUST ignore decoded texture alpha if this flag is enabled!)')
|
|
|
|
type=click.IntRange(0, 18),
|
|
|
|
@click.option('-3/-4', '--3color/--4color', 'threecolor', default=True, help='Enable 3-color mode for non-black pixels. Higher quality, but slightly slower.')
|
|
|
|
default=18,
|
|
|
|
|
|
|
|
help='Quality level to use. Higher values = higher quality, but slower.',
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
@click.option(
|
|
|
|
|
|
|
|
'-b/-B',
|
|
|
|
|
|
|
|
'--black/--no-black',
|
|
|
|
|
|
|
|
help='Enable 3-color mode for blocks containing black or very dark pixels. --3color must also be enabled for this to work.'
|
|
|
|
|
|
|
|
' (Important: engine/shader MUST ignore decoded texture alpha if this flag is enabled!)',
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
@click.option(
|
|
|
|
|
|
|
|
'-3/-4',
|
|
|
|
|
|
|
|
'--3color/--4color',
|
|
|
|
|
|
|
|
'threecolor',
|
|
|
|
|
|
|
|
default=True,
|
|
|
|
|
|
|
|
help='Enable 3-color mode for non-black pixels. Higher quality, but slightly slower.',
|
|
|
|
|
|
|
|
)
|
|
|
|
def encode_bc1(level, black, threecolor, **kwargs):
|
|
|
|
def encode_bc1(level, black, threecolor, **kwargs):
|
|
|
|
"""Encode images to BC1 (RGB, no alpha)."""
|
|
|
|
"""Encode images to BC1 (RGB, no alpha)."""
|
|
|
|
color_mode = quicktex.s3tc.bc1.BC1Encoder.ColorMode
|
|
|
|
color_mode = quicktex.s3tc.bc1.BC1Encoder.ColorMode
|
|
|
@ -109,7 +168,13 @@ def encode_bc1(level, black, threecolor, **kwargs):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@click.command('bc3')
|
|
|
|
@click.command('bc3')
|
|
|
|
@click.option('-l', '--level', type=click.IntRange(0, 18), default=18, help='Quality level to use. Higher values = higher quality, but slower.')
|
|
|
|
@click.option(
|
|
|
|
|
|
|
|
'-l',
|
|
|
|
|
|
|
|
'--level',
|
|
|
|
|
|
|
|
type=click.IntRange(0, 18),
|
|
|
|
|
|
|
|
default=18,
|
|
|
|
|
|
|
|
help='Quality level to use. Higher values = higher quality, but slower.',
|
|
|
|
|
|
|
|
)
|
|
|
|
def encode_bc3(level, **kwargs):
|
|
|
|
def encode_bc3(level, **kwargs):
|
|
|
|
"""Encode images to BC4 (RGBA, 8-bit interpolated alpha)."""
|
|
|
|
"""Encode images to BC4 (RGBA, 8-bit interpolated alpha)."""
|
|
|
|
encode_format.callback(quicktex.s3tc.bc3.BC3Encoder(level), 'DXT5', **kwargs)
|
|
|
|
encode_format.callback(quicktex.s3tc.bc3.BC3Encoder(level), 'DXT5', **kwargs)
|
|
|
|