mirror of
https://github.com/drewcassidy/quicktex.git
synced 2024-09-13 06:37:34 +00:00
CLI scaffolding
This commit is contained in:
parent
2244b2117d
commit
e5f60ec030
15
quicktex/cli/__init__.py
Normal file
15
quicktex/cli/__init__.py
Normal file
@ -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()
|
16
quicktex/cli/decode.py
Normal file
16
quicktex/cli/decode.py
Normal file
@ -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"
|
6
quicktex/cli/encode.py
Normal file
6
quicktex/cli/encode.py
Normal file
@ -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
|
import typing
|
||||||
|
|
||||||
|
|
||||||
|
@typing.final
|
||||||
class PixelFormat:
|
class PixelFormat:
|
||||||
"""
|
"""
|
||||||
DDS header surface format.
|
DDS header surface format.
|
||||||
@ -98,6 +99,7 @@ class PixelFormat:
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
@typing.final
|
||||||
class DDSHeader:
|
class DDSHeader:
|
||||||
"""
|
"""
|
||||||
Header for a microsoft DDS file
|
Header for a microsoft DDS file
|
||||||
@ -213,6 +215,7 @@ class DDSHeader:
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
@typing.final
|
||||||
class DDSFile:
|
class DDSFile:
|
||||||
"""
|
"""
|
||||||
A microsoft DDS file, containing header information and one or more textures
|
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.
|
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.
|
: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:
|
if not mip_count:
|
||||||
mip_count = math.ceil(math.log2(max(dimensions))) # maximum possible number of mips for a given source
|
mip_count = math.ceil(math.log2(max(dimensions))) # maximum possible number of mips for a given source
|
||||||
|
|
||||||
|
4
setup.py
4
setup.py
@ -118,5 +118,9 @@ setup(
|
|||||||
"tests": ["nose", "parameterized"],
|
"tests": ["nose", "parameterized"],
|
||||||
"docs": ["sphinx", "myst-parser", "sphinx-rtd-theme"],
|
"docs": ["sphinx", "myst-parser", "sphinx-rtd-theme"],
|
||||||
},
|
},
|
||||||
|
entry_points='''
|
||||||
|
[console_scripts]
|
||||||
|
quicktex=quicktex.cli:cli
|
||||||
|
''',
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user