diff --git a/quicktex/cli/__init__.py b/quicktex/cli/__init__.py new file mode 100644 index 0000000..ac236ca --- /dev/null +++ b/quicktex/cli/__init__.py @@ -0,0 +1,15 @@ +import click +from encode import encode +from decode import decode + + +@click.group() +def cli(): + """Encode and Decode various image formats""" + + +cli.add_command(encode) +cli.add_command(decode) + +if __name__ == '__main__': + cli() diff --git a/quicktex/cli/decode.py b/quicktex/cli/decode.py new file mode 100644 index 0000000..d31a881 --- /dev/null +++ b/quicktex/cli/decode.py @@ -0,0 +1,16 @@ +import click +import io +import os +from PIL import Image + + +@click.command() +@click.option('-f', '--flip', type=bool, default=True, show_default=True, help="vertically flip image after converting") +@click.option('-r', '--remove', help="remove input images after converting") +@click.option('-o', '--output', help="output file name. Must only specify one input image.") +@click.option('-s', '--suffix', type=str, default='', help="suffix to append to output file(s).") +@click.argument('filenames', nargs=-1, type=click.Path(exists=True)) +def decode(flip, remove, output, suffix, filenames): + """Decode an input texture file to an image""" + for filename in filenames: + assert filename.endswith(".dds"), "Incorrect file extension" diff --git a/quicktex/cli/encode.py b/quicktex/cli/encode.py new file mode 100644 index 0000000..5a77d0e --- /dev/null +++ b/quicktex/cli/encode.py @@ -0,0 +1,6 @@ +import click + + +@click.group() +def encode(): + """Encode an input image to a texture file of the given format""" diff --git a/quicktex/dds.py b/quicktex/dds.py index 3794f18..f4be690 100644 --- a/quicktex/dds.py +++ b/quicktex/dds.py @@ -5,6 +5,7 @@ import struct import typing +@typing.final class PixelFormat: """ DDS header surface format. @@ -98,6 +99,7 @@ class PixelFormat: return data +@typing.final class DDSHeader: """ Header for a microsoft DDS file @@ -213,6 +215,7 @@ class DDSHeader: return data +@typing.final class DDSFile: """ A microsoft DDS file, containing header information and one or more textures diff --git a/quicktex/image_utils.py b/quicktex/image_utils.py index 183556a..8b4919d 100644 --- a/quicktex/image_utils.py +++ b/quicktex/image_utils.py @@ -46,7 +46,7 @@ def mip_sizes(dimensions: typing.Tuple[int, int], mip_count: typing.Optional[int Resulting mip chain will be smaller if a 1x1 mip level is reached before this value. :return: A list of 2-tuples representing the dimensions of each mip level, including ``dimensions`` at element 0. """ - assert all([dim > 0 for dim in dimensions]), "Invalid source size" + assert all([dim > 0 for dim in dimensions]), "Invalid source dimensions" if not mip_count: mip_count = math.ceil(math.log2(max(dimensions))) # maximum possible number of mips for a given source diff --git a/setup.py b/setup.py index a313f4c..e91d9af 100644 --- a/setup.py +++ b/setup.py @@ -118,5 +118,9 @@ setup( "tests": ["nose", "parameterized"], "docs": ["sphinx", "myst-parser", "sphinx-rtd-theme"], }, + entry_points=''' + [console_scripts] + quicktex=quicktex.cli:cli + ''', zip_safe=False, )