CLI scaffolding

hotfix/mipmap-alpha-fix
Andrew Cassidy 3 years ago
parent 2244b2117d
commit e5f60ec030

@ -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()

@ -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"

@ -0,0 +1,6 @@
import click
@click.group()
def encode():
"""Encode an input image to a texture file of the given format"""

@ -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

@ -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

@ -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,
)

Loading…
Cancel
Save