Compare commits
31 Commits
scikit-bui
...
0.1.3
Author | SHA1 | Date | |
---|---|---|---|
ac4e5b2679 | |||
25e74b9b08 | |||
a881a0a36b | |||
3fdfc3ecaa | |||
b440543de3 | |||
23ed54c7a2 | |||
e7e8657100 | |||
2a07db8c8f | |||
b8a80235f8 | |||
4cac24798e | |||
9b6097373e | |||
b954ac6ccc | |||
593a0c3f46 | |||
3b73bc8bce | |||
abeb08fc81 | |||
77637f6abd | |||
df6d5b1848 | |||
b5aea803d5 | |||
b80a6d2229 | |||
dac7f07db4 | |||
7dfefa3007 | |||
eaca455a08 | |||
e5ccdbb4f4 | |||
94d88c7e00 | |||
9421a6d372 | |||
cab0eeebae | |||
3d98b37a37 | |||
654b6d628a | |||
1502c5318c | |||
8b4e3c5746 | |||
8e7b95609c |
9
.github/dependabot.yml
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
# Set update schedule for GitHub Actions
|
||||
version: 2
|
||||
updates:
|
||||
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
# Check for updates to GitHub Actions every weekday
|
||||
interval: "daily"
|
67
.github/workflows/python-package.yml
vendored
@ -11,14 +11,12 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
# Whether to checkout submodules: `true` to checkout submodules or `recursive` to
|
||||
# recursively checkout submodules.
|
||||
submodules: 'true'
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v2
|
||||
uses: actions/setup-python@v3.1.2
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
@ -40,80 +38,65 @@ jobs:
|
||||
run: python -m twine check dist/*
|
||||
|
||||
- name: Upload SDist
|
||||
uses: actions/upload-artifact@v2
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
path: dist/*.tar.gz
|
||||
|
||||
build-wheels:
|
||||
name: Build Wheels for ${{ matrix.os }}-${{ matrix.arch }}
|
||||
name: Build Wheels on ${{ matrix.os }} ${{ matrix.arch[0] }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ macos-latest, windows-latest, ubuntu-latest ]
|
||||
arch: [ x86_64 ]
|
||||
os: [ macos-11, windows-latest, ubuntu-latest ]
|
||||
arch: [ ['x86', 'x86_64', 'AMD64', 'x86_64' ] ] #[suffix, mac, windows, linux] arch names
|
||||
include:
|
||||
- arch: arm64
|
||||
os: macos-latest
|
||||
- arch: aarch64
|
||||
os: ubuntu-latest
|
||||
qemu: true
|
||||
- os: ubuntu-latest
|
||||
arch: [ 'ARM', 'arm64', 'ARM64', 'aarch64' ]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
# Whether to checkout submodules: `true` to checkout submodules or `recursive` to
|
||||
# recursively checkout submodules.
|
||||
submodules: 'true'
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Install libomp
|
||||
if: runner.os == 'macOS'
|
||||
# openMP isnt part of core apple clang for some reason?
|
||||
run: brew install libomp
|
||||
# libomp is in homebrew, which works for end users but its not a fat binary
|
||||
# so we have to install it manually
|
||||
# compiled dylibs courtesy of https://mac.r-project.org/openmp/ and mirrored on my own server
|
||||
run: |
|
||||
wget https://pileof.rocks/openmp-13.0.0-darwin21-Release.tar.gz
|
||||
sudo tar fvxz openmp-*.tar.gz -C /
|
||||
|
||||
- name: Install QEMU
|
||||
# install QEMU if building for arm linux
|
||||
uses: docker/setup-qemu-action@v1
|
||||
if: matrix.qemu
|
||||
if: runner.os == 'linux' && matrix.arch[3] == 'aarch64'
|
||||
with:
|
||||
platforms: arm64
|
||||
|
||||
- name: Install test images
|
||||
run: git clone https://git.pileof.rocks/drewcassidy/quicktex-test-images.git tests/images
|
||||
|
||||
- name: Build wheels
|
||||
uses: joerick/cibuildwheel@v2.3.1
|
||||
uses: pypa/cibuildwheel@v2.4.0
|
||||
env:
|
||||
MACOSX_DEPLOYMENT_TARGET: "10.15"
|
||||
CIBW_BUILD: "cp{37,38,39,310}-*"
|
||||
CIBW_ARCHS_MACOS: ${{ matrix.arch }}
|
||||
CIBW_ARCHS_LINUX: ${{ matrix.arch }}
|
||||
CIBW_ARCHS_WINDOWS: "auto64"
|
||||
CIBW_MANYLINUX_X86_64_IMAGE: "manylinux2014"
|
||||
CIBW_MANYLINUX_AARCH64_IMAGE: "manylinux2014"
|
||||
CIBW_TEST_EXTRAS: "tests"
|
||||
CIBW_TEST_COMMAND: nosetests {project}/tests -d
|
||||
CIBW_TEST_SKIP: "*-macosx_arm64"
|
||||
CIBW_ARCHS_LINUX: ${{ matrix.arch[3] }}
|
||||
|
||||
- name: Upload Wheels
|
||||
uses: actions/upload-artifact@v2
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
path: ./wheelhouse/*.whl
|
||||
|
||||
publish:
|
||||
name: Publish to PyPI and Github
|
||||
needs: [build-wheels, build-sdist]
|
||||
needs: [ build-wheels, build-sdist ]
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
# Whether to checkout submodules: `true` to checkout submodules or `recursive` to
|
||||
# recursively checkout submodules.
|
||||
submodules: 'true'
|
||||
- uses: actions/checkout@v3 # just need the changelog
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v2
|
||||
uses: actions/setup-python@v3.1.2
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
@ -126,7 +109,7 @@ jobs:
|
||||
echo "$(yaclog show -mb)" >> RELEASE.md
|
||||
|
||||
- name: Download Artifacts
|
||||
uses: actions/download-artifact@v2
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: artifact
|
||||
path: dist
|
||||
|
4
.gitignore
vendored
@ -12,9 +12,6 @@ docs/_build/
|
||||
#mypy
|
||||
out
|
||||
|
||||
# Test images
|
||||
tests/images/
|
||||
|
||||
# IDEs
|
||||
**/.idea
|
||||
|
||||
@ -34,4 +31,3 @@ compile_commands.json
|
||||
CTestTestfile.cmake
|
||||
_deps
|
||||
cmake-build-*
|
||||
_skbuild
|
||||
|
4
.gitmodules
vendored
@ -1,4 +0,0 @@
|
||||
[submodule "extern/pybind11"]
|
||||
path = extern/pybind11
|
||||
url = https://github.com/pybind/pybind11.git
|
||||
branch = stable
|
13
CHANGELOG.md
@ -2,6 +2,19 @@
|
||||
|
||||
All notable changes to this project will be documented in this file
|
||||
|
||||
## 0.1.3 - 2022-04-13
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed quicktex not compiling for python 3.10 on Windows
|
||||
|
||||
### Changed
|
||||
|
||||
- Reworked CI job, adding wheels for ARM macOS, ARM Linux, and x86 musl Linux.
|
||||
- Added wheels for python 3.10
|
||||
- Added a more useful error message when importing quicktex on macOS when libomp.dylib isn't installed
|
||||
|
||||
|
||||
## 0.1.2 - 2022-03-27
|
||||
|
||||
### Fixed
|
||||
|
@ -1,23 +1,11 @@
|
||||
cmake_minimum_required(VERSION 3.17)
|
||||
cmake_minimum_required(VERSION 3.18)
|
||||
include(CheckIPOSupported)
|
||||
include(tools/CompilerWarnings.cmake)
|
||||
|
||||
project(quicktex)
|
||||
|
||||
if (SKBUILD)
|
||||
# Scikit-Build does not add your site-packages to the search path
|
||||
# automatically, so we need to add it _or_ the pybind11 specific directory
|
||||
# here.
|
||||
execute_process(
|
||||
COMMAND "${PYTHON_EXECUTABLE}" -c
|
||||
"import pybind11; print(pybind11.get_cmake_dir())"
|
||||
OUTPUT_VARIABLE _tmp_dir
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ECHO STDOUT)
|
||||
list(APPEND CMAKE_PREFIX_PATH "${_tmp_dir}")
|
||||
endif ()
|
||||
|
||||
# Find dependencies
|
||||
find_package(Python COMPONENTS Interpreter Development)
|
||||
find_package(Python COMPONENTS Interpreter Development.Module)
|
||||
find_package(pybind11 CONFIG REQUIRED)
|
||||
find_package(OpenMP)
|
||||
|
||||
@ -85,5 +73,3 @@ if (CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -stdlib=libc++ -fsanitize=undefined")
|
||||
set(PROJECT_WARNINGS ${CLANG_WARNINGS})
|
||||
endif ()
|
||||
|
||||
install(TARGETS _quicktex LIBRARY DESTINATION quicktex)
|
||||
|
@ -1 +0,0 @@
|
||||
graft extern
|
@ -3,9 +3,8 @@ requires = [
|
||||
"setuptools>=61",
|
||||
"setuptools_scm>=6.2",
|
||||
"wheel",
|
||||
"pybind11>=2.9.0",
|
||||
"cmake>=3.22",
|
||||
"scikit-build>0.13",
|
||||
"cmake>=3.18",
|
||||
"pybind11~=2.6.1",
|
||||
"ninja; sys_platform != 'win32'",
|
||||
]
|
||||
build-backend = "setuptools.build_meta"
|
||||
@ -14,7 +13,6 @@ build-backend = "setuptools.build_meta"
|
||||
name = "quicktex"
|
||||
description = "A fast block compression library for python"
|
||||
readme = "README.md"
|
||||
license = { file = "LICENSE.md" }
|
||||
authors = [{ name = "Andrew Cassidy", email = "drewcassidy@me.com" }]
|
||||
|
||||
classifiers = [
|
||||
@ -38,13 +36,13 @@ dependencies = ["Pillow", "click"]
|
||||
dynamic = ["version"]
|
||||
|
||||
[project.optional-dependencies]
|
||||
tests = ["nose", "parameterized"]
|
||||
tests = ["parameterized"]
|
||||
docs = ["sphinx", "myst-parser", "sphinx-rtd-theme"]
|
||||
stubs = ["pybind11-stubgen"]
|
||||
|
||||
[project.urls]
|
||||
repository = "https://github.com/drewcassidy/quicktex"
|
||||
changelog = "https://github.com/drewcassidy/quicktex/blob/main/CHANGELOG.md"
|
||||
Source = "https://github.com/drewcassidy/quicktex"
|
||||
Changelog = "https://github.com/drewcassidy/quicktex/blob/main/CHANGELOG.md"
|
||||
|
||||
[project.scripts]
|
||||
quicktex = "quicktex.__main__:main"
|
||||
@ -56,3 +54,22 @@ package-data = { '*' = ['py.typed', '*.pyi'] } # include stubs
|
||||
package-dir = { '' = '.' } # without this line, C++ source files get included in the bdist
|
||||
|
||||
[tool.setuptools_scm]
|
||||
|
||||
[tool.cibuildwheel]
|
||||
build = "cp*" # only build wheels for cpython.
|
||||
build-frontend = "build"
|
||||
test-command = "cd {project} && python -m unittest --verbose"
|
||||
test-extras = ["tests"]
|
||||
|
||||
[tool.cibuildwheel.macos]
|
||||
archs = ["x86_64", "universal2"] # build fat binaries, or x86-64 for python 3.7
|
||||
skip = ["cp{38,39,31*}-macosx_x86_64"] # skip x86-only builds where fat binaries are supported
|
||||
|
||||
[tool.cibuildwheel.windows]
|
||||
archs = ["auto64"] # arm64 windows builds not yet supported
|
||||
test-command = "cd /d {project} && python -m unittest --verbose" # windows why is this flag required
|
||||
|
||||
[tool.cibuildwheel.linux]
|
||||
skip = ["cp37-musllinux*", "*musllinux_aarch64*"] # skip targets without available Pillow wheels
|
||||
manylinux-x86_64-image = "manylinux2014"
|
||||
manylinux-aarch64-image = "manylinux2014"
|
||||
|
@ -1,2 +1,8 @@
|
||||
from _quicktex import *
|
||||
from _quicktex import __version__
|
||||
try:
|
||||
from _quicktex import *
|
||||
from _quicktex import __version__
|
||||
except ImportError as e:
|
||||
if 'libomp.dylib' in e.msg:
|
||||
print('\033[41m\033[01mERROR: LIBOMP NOT FOUND! PLEASE INSTALL IT WITH \033[04m`brew install libomp`\033[0m')
|
||||
print('original error message:')
|
||||
raise e
|
||||
|
@ -96,9 +96,9 @@ template <typename T> T BufferToTexture(py::buffer buf, int width, int height) {
|
||||
auto dst_size = output.NBytes();
|
||||
|
||||
if (info.format != py::format_descriptor<uint8_t>::format()) throw std::runtime_error("Incompatible format in python buffer: expected a byte array.");
|
||||
if (info.size < (ssize_t)dst_size) std::runtime_error("Incompatible format in python buffer: Input data is smaller than texture size.");
|
||||
if (info.size < (Py_ssize_t)dst_size) std::runtime_error("Incompatible format in python buffer: Input data is smaller than texture size.");
|
||||
if (info.ndim == 1) {
|
||||
if (info.shape[0] < (ssize_t)dst_size) throw std::runtime_error("Incompatible format in python buffer: 1-D buffer has incorrect length.");
|
||||
if (info.shape[0] < (Py_ssize_t)dst_size) throw std::runtime_error("Incompatible format in python buffer: 1-D buffer has incorrect length.");
|
||||
if (info.strides[0] != 1) throw std::runtime_error("Incompatible format in python buffer: 1-D buffer is not contiguous.");
|
||||
} else {
|
||||
throw std::runtime_error("Incompatible format in python buffer: Incorrect number of dimensions.");
|
||||
@ -115,9 +115,9 @@ template <typename T> T BufferToPOD(py::buffer buf) {
|
||||
auto info = buf.request(false);
|
||||
|
||||
if (info.format != py::format_descriptor<uint8_t>::format()) throw std::runtime_error("Incompatible format in python buffer: expected a byte array.");
|
||||
if (info.size < (ssize_t)sizeof(T)) std::runtime_error("Incompatible format in python buffer: Input data is smaller than texture size.");
|
||||
if (info.size < (Py_ssize_t)sizeof(T)) std::runtime_error("Incompatible format in python buffer: Input data is smaller than texture size.");
|
||||
if (info.ndim == 1) {
|
||||
if (info.shape[0] < (ssize_t)sizeof(T)) throw std::runtime_error("Incompatible format in python buffer: 1-D buffer has incorrect length.");
|
||||
if (info.shape[0] < (Py_ssize_t)sizeof(T)) throw std::runtime_error("Incompatible format in python buffer: 1-D buffer has incorrect length.");
|
||||
if (info.strides[0] != 1) throw std::runtime_error("Incompatible format in python buffer: 1-D buffer is not contiguous.");
|
||||
} else {
|
||||
throw std::runtime_error("Incompatible format in python buffer: Incorrect number of dimensions.");
|
||||
|
126
setup.py
@ -1,15 +1,121 @@
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import subprocess
|
||||
import pybind11
|
||||
|
||||
try:
|
||||
from skbuild import setup
|
||||
except ImportError:
|
||||
print(
|
||||
"Please update pip, you need pip 10 or greater,\n"
|
||||
" or you need to install the PEP 518 requirements in pyproject.toml yourself",
|
||||
file=sys.stderr,
|
||||
)
|
||||
raise
|
||||
from setuptools import setup, Extension
|
||||
from setuptools.command.build_ext import build_ext
|
||||
|
||||
project_path = os.path.dirname(os.path.realpath(__file__))
|
||||
|
||||
|
||||
# A CMakeExtension needs a sourcedir instead of a file list.
|
||||
# The name must be the _single_ output extension from the CMake build.
|
||||
# If you need multiple extensions, see scikit-build.
|
||||
class CMakeExtension(Extension):
|
||||
def __init__(self, name, sourcedir=""):
|
||||
Extension.__init__(self, name, sources=[])
|
||||
self.sourcedir = os.path.abspath(sourcedir)
|
||||
|
||||
|
||||
class CMakeBuild(build_ext):
|
||||
def build_extension(self, ext):
|
||||
from setuptools_scm import get_version
|
||||
version = get_version(root='.', relative_to=__file__)
|
||||
|
||||
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
|
||||
|
||||
# required for auto-detection of auxiliary "native" libs
|
||||
if not extdir.endswith(os.path.sep):
|
||||
extdir += os.path.sep
|
||||
|
||||
cfg = "Debug" if self.debug else "Release"
|
||||
|
||||
# CMake lets you override the generator - we need to check this.
|
||||
# Can be set with Conda-Build, for example.
|
||||
cmake_generator = os.environ.get("CMAKE_GENERATOR", "")
|
||||
|
||||
# Set Python_EXECUTABLE instead if you use PYBIND11_FINDPYTHON
|
||||
cmake_args = [
|
||||
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={}".format(extdir),
|
||||
"-Dpybind11_DIR={}".format(pybind11.get_cmake_dir()),
|
||||
"-DPython_EXECUTABLE={}".format(sys.executable),
|
||||
"-DPython_ROOT_DIR={}".format(os.path.dirname(sys.executable)),
|
||||
"-DQUICKTEX_VERSION_INFO={}".format(version),
|
||||
"-DCMAKE_BUILD_TYPE={}".format(cfg), # not used on MSVC, but no harm
|
||||
# clear cached make program binary, see https://github.com/pypa/setuptools/issues/2912
|
||||
"-U", "CMAKE_MAKE_PROGRAM",
|
||||
]
|
||||
build_args = []
|
||||
|
||||
if self.compiler.compiler_type != "msvc":
|
||||
# Using Ninja-build since it a) is available as a wheel and b)
|
||||
# multithreads automatically. MSVC would require all variables be
|
||||
# exported for Ninja to pick it up, which is a little tricky to do.
|
||||
# Users can override the generator with CMAKE_GENERATOR in CMake
|
||||
# 3.15+.
|
||||
if not cmake_generator:
|
||||
cmake_args += ["-GNinja"]
|
||||
|
||||
else:
|
||||
# Single config generators are handled "normally"
|
||||
single_config = any(x in cmake_generator for x in {"NMake", "Ninja"})
|
||||
|
||||
# CMake allows an arch-in-generator style for backward compatibility
|
||||
contains_arch = any(x in cmake_generator for x in {"ARM", "Win64"})
|
||||
|
||||
# Convert distutils Windows platform specifiers to CMake -A arguments
|
||||
plat_to_cmake = {
|
||||
"win32": "Win32",
|
||||
"win-amd64": "x64",
|
||||
"win-arm32": "ARM",
|
||||
"win-arm64": "ARM64",
|
||||
}
|
||||
|
||||
# Specify the arch if using MSVC generator, but only if it doesn't
|
||||
# contain a backward-compatibility arch spec already in the
|
||||
# generator name.
|
||||
if not single_config and not contains_arch:
|
||||
cmake_args += ["-A", plat_to_cmake[self.plat_name]]
|
||||
|
||||
# Multi-config generators have a different way to specify configs
|
||||
if not single_config:
|
||||
cmake_args += [
|
||||
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}".format(cfg.upper(), extdir)
|
||||
]
|
||||
build_args += ["--config", cfg]
|
||||
|
||||
if sys.platform.startswith("darwin"):
|
||||
# Cross-compile support for macOS - respect ARCHFLAGS if set
|
||||
archs = re.findall(r"-arch (\S+)", os.environ.get("ARCHFLAGS", ""))
|
||||
if archs:
|
||||
cmake_args += ["-DCMAKE_OSX_ARCHITECTURES={}".format(";".join(archs))]
|
||||
|
||||
# Set CMAKE_BUILD_PARALLEL_LEVEL to control the parallel build level
|
||||
# across all generators.
|
||||
if "CMAKE_BUILD_PARALLEL_LEVEL" not in os.environ:
|
||||
# self.parallel is a Python 3 only way to set parallel jobs by hand
|
||||
# using -j in the build_ext call, not supported by pip or PyPA-build.
|
||||
if hasattr(self, "parallel") and self.parallel:
|
||||
# CMake 3.12+ only.
|
||||
build_args += ["-j{}".format(self.parallel)]
|
||||
|
||||
if not os.path.exists(self.build_temp):
|
||||
os.makedirs(self.build_temp)
|
||||
|
||||
subprocess.check_call(
|
||||
["cmake", ext.sourcedir] + cmake_args, cwd=self.build_temp
|
||||
)
|
||||
subprocess.check_call(
|
||||
["cmake", "--build", ".", "--target", ext.name] + build_args, cwd=self.build_temp
|
||||
)
|
||||
|
||||
|
||||
# The information here can also be placed in setup.cfg - better separation of
|
||||
# logic and declaration, and simpler if you include description/version in a file.
|
||||
setup(
|
||||
cmake_install_dir='.'
|
||||
use_scm_version=True,
|
||||
ext_modules=[CMakeExtension("_quicktex")],
|
||||
cmdclass={"build_ext": CMakeBuild},
|
||||
)
|
||||
|
@ -1,9 +1,3 @@
|
||||
import os.path
|
||||
|
||||
# Some checks to run before tests can begin
|
||||
images_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'images')
|
||||
|
||||
assert os.path.isdir(images_path), 'test images repo not present'
|
||||
assert os.path.isfile(os.path.join(images_path, '__init__.py')), 'images __init__.py not present, is the test image repo present?'
|
||||
bp_size = os.path.getsize(os.path.join(images_path, 'Boilerplate.png'))
|
||||
assert bp_size == 955989, 'Boilerplate.png is the wrong size, is the test image repo checked out with LFS enabled?'
|
||||
|
BIN
tests/images/Boilerplate.png
Normal file
After Width: | Height: | Size: 934 KiB |
BIN
tests/images/Bun.afdesign
Normal file
BIN
tests/images/Bun.png
Normal file
After Width: | Height: | Size: 375 KiB |
32
tests/images/__init__.py
Normal file
@ -0,0 +1,32 @@
|
||||
from PIL import Image
|
||||
from quicktex.s3tc.bc1 import BC1Block
|
||||
from quicktex.s3tc.bc4 import BC4Block
|
||||
from quicktex import RawTexture
|
||||
import os.path
|
||||
|
||||
image_path = os.path.dirname(os.path.realpath(__file__))
|
||||
|
||||
|
||||
class BC1Blocks:
|
||||
class Entry:
|
||||
def __init__(self, filename, block):
|
||||
path = os.path.join(image_path, 'bc1', filename)
|
||||
self.image = Image.open(path).convert('RGBA')
|
||||
self.texture = RawTexture.frombytes(self.image.tobytes('raw', 'RGBA'), *self.image.size)
|
||||
self.block = block
|
||||
|
||||
greyscale = Entry('greyscale_unpacked.png', BC1Block.frombytes(b'\xFF\xFF\x49\x4A\x78\x78\x78\x78'))
|
||||
three_color = Entry('3color_unpacked.png', BC1Block.frombytes(b'\xE0\x07\x00\xF8\x29\x29\x29\x29'))
|
||||
three_color_black = Entry('3color_black_unpacked.png', BC1Block.frombytes(b'\xE0\x07\x00\xF8\x27\x27\x27\x27'))
|
||||
|
||||
|
||||
class BC4Blocks:
|
||||
class Entry:
|
||||
def __init__(self, filename, block):
|
||||
path = os.path.join(image_path, 'bc4', filename)
|
||||
self.image = Image.open(path).convert('RGBA')
|
||||
self.texture = RawTexture.frombytes(self.image.tobytes('raw', 'RGBA'), *self.image.size)
|
||||
self.block = block
|
||||
|
||||
six_value = Entry('6value.png', BC4Block(8, 248, [[0, 1, 2, 3]] * 2 + [[4, 5, 6, 7]] * 2))
|
||||
eight_value = Entry('8value.png', BC4Block(240, 16, [[0, 1, 2, 3]] * 2 + [[4, 5, 6, 7]] * 2))
|
BIN
tests/images/bc1/3color.dds
Normal file
BIN
tests/images/bc1/3color.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
tests/images/bc1/3color_black.dds
Normal file
BIN
tests/images/bc1/3color_black.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
tests/images/bc1/3color_black_unpacked.png
Normal file
After Width: | Height: | Size: 103 B |
BIN
tests/images/bc1/3color_unpacked.png
Normal file
After Width: | Height: | Size: 100 B |
BIN
tests/images/bc1/greyscale.dds
Normal file
BIN
tests/images/bc1/greyscale.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
tests/images/bc1/greyscale_unpacked.png
Normal file
After Width: | Height: | Size: 103 B |
BIN
tests/images/bc4/6value.dds
Normal file
BIN
tests/images/bc4/6value.png
Normal file
After Width: | Height: | Size: 513 B |
BIN
tests/images/bc4/8value.dds
Normal file
BIN
tests/images/bc4/8value.png
Normal file
After Width: | Height: | Size: 509 B |
BIN
tests/images/blocks.afdesign
Normal file
@ -1,10 +1,7 @@
|
||||
import unittest
|
||||
import nose
|
||||
import os.path
|
||||
from parameterized import parameterized, parameterized_class
|
||||
import quicktex
|
||||
from quicktex.s3tc.bc1 import BC1Block, BC1Texture, BC1Encoder, BC1Decoder
|
||||
from tests.images import BC1Blocks, image_path
|
||||
from .images import BC1Blocks
|
||||
from PIL import Image, ImageChops
|
||||
|
||||
in_endpoints = ((253, 254, 255), (65, 70, 67)) # has some small changes that should encode the same
|
||||
@ -108,9 +105,9 @@ class TestBC1Texture(unittest.TestCase):
|
||||
self.assertEqual(self.tex[-1, -1], self.tex[self.wb - 1, self.hb - 1], 'incorrect negative subscripting')
|
||||
|
||||
with self.assertRaises(IndexError):
|
||||
thing = self.tex[self.wb, self.hb]
|
||||
_ = self.tex[self.wb, self.hb]
|
||||
with self.assertRaises(IndexError):
|
||||
thing = self.tex[-1 - self.wb, -1 - self.hb]
|
||||
_ = self.tex[-1 - self.wb, -1 - self.hb]
|
||||
|
||||
def test_buffer(self):
|
||||
"""Test the buffer protocol of BC1Texture"""
|
||||
@ -158,7 +155,8 @@ class TestBC1Encoder(unittest.TestCase):
|
||||
|
||||
out_block = out_tex[0, 0]
|
||||
|
||||
if self.color_mode != BC1Encoder.ColorMode.FourColor: # we only care about the selectors if we are in 3 color mode
|
||||
if self.color_mode != BC1Encoder.ColorMode.FourColor:
|
||||
# we only care about the selectors if we are in 3 color mode
|
||||
self.assertTrue(out_block.is_3color, 'returned 4-color block for 3 color test block')
|
||||
self.assertEqual(out_block, BC1Blocks.three_color.block, 'encoded block is incorrect')
|
||||
else:
|
||||
@ -173,7 +171,8 @@ class TestBC1Encoder(unittest.TestCase):
|
||||
out_block = out_tex[0, 0]
|
||||
has_black = 3 in [j for row in out_block.selectors for j in row]
|
||||
|
||||
if self.color_mode == BC1Encoder.ColorMode.ThreeColorBlack: # we only care about the selectors if we are in 3 color black mode
|
||||
if self.color_mode == BC1Encoder.ColorMode.ThreeColorBlack:
|
||||
# we only care about the selectors if we are in 3 color black mode
|
||||
self.assertTrue(out_block.is_3color, 'returned 4-color block for 3 color test block with black')
|
||||
self.assertTrue(has_black, 'block does not have black pixels as expected')
|
||||
self.assertEqual(out_block, BC1Blocks.three_color_black.block, "encoded block is incorrect")
|
||||
@ -207,7 +206,3 @@ class TestBC1Decoder(unittest.TestCase):
|
||||
img_diff = ImageChops.difference(out_img, image).convert('L')
|
||||
img_hist = img_diff.histogram()
|
||||
self.assertEqual(16, img_hist[0], 'decoded block is incorrect')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
nose.main()
|
||||
|
@ -1,13 +1,9 @@
|
||||
import unittest
|
||||
import nose
|
||||
from parameterized import parameterized, parameterized_class
|
||||
from quicktex.s3tc.bc4 import BC4Block, BC4Texture, BC4Encoder, BC4Decoder
|
||||
from tests.images import BC4Blocks
|
||||
from .images import BC4Blocks
|
||||
from PIL import Image, ImageChops
|
||||
|
||||
if __name__ == '__main__':
|
||||
nose.main()
|
||||
|
||||
|
||||
class TestBC4Block(unittest.TestCase):
|
||||
"""Tests for the BC1Block class"""
|
||||
@ -119,9 +115,9 @@ class TestBC4Texture(unittest.TestCase):
|
||||
self.assertEqual(self.tex[-1, -1], self.tex[self.wb - 1, self.hb - 1], 'incorrect negative subscripting')
|
||||
|
||||
with self.assertRaises(IndexError):
|
||||
thing = self.tex[self.wb, self.hb]
|
||||
_ = self.tex[self.wb, self.hb]
|
||||
with self.assertRaises(IndexError):
|
||||
thing = self.tex[-1 - self.wb, -1 - self.hb]
|
||||
_ = self.tex[-1 - self.wb, -1 - self.hb]
|
||||
|
||||
def test_buffer(self):
|
||||
"""Test the buffer protocol of BC4Texture"""
|
||||
|
@ -3,32 +3,21 @@
|
||||
import unittest
|
||||
import os.path
|
||||
import quicktex
|
||||
import nose
|
||||
|
||||
tests_path = os.path.dirname(os.path.realpath(__file__))
|
||||
|
||||
|
||||
def test_images():
|
||||
"""Test for the images submodule"""
|
||||
class TestInstall(unittest.TestCase):
|
||||
def test_version(self):
|
||||
"""Test if the extension module version matches what setuptools returns"""
|
||||
try:
|
||||
from importlib import metadata
|
||||
except ImportError:
|
||||
# Python < 3.8, so we cant get the metadata, so just check if it exists
|
||||
assert quicktex.__version__
|
||||
print(f'Cannot check version in python < 3.8. __version__ is {quicktex.__version__}')
|
||||
return
|
||||
|
||||
images_path = os.path.join(tests_path, 'images')
|
||||
version = metadata.version('quicktex')
|
||||
|
||||
assert os.path.isdir(images_path), 'test images repo not present. run "git clone https://git.pileof.rocks/drewcassidy/quicktex-test-images.git tests/images" to download them'
|
||||
assert os.path.isfile(os.path.join(images_path, '__init__.py')), 'images __init__.py not present, is the test image repo present?'
|
||||
bp_size = os.path.getsize(os.path.join(images_path, 'Boilerplate.png'))
|
||||
assert bp_size == 955989, 'Boilerplate.png is the wrong size, is the test image repo checked out with LFS enabled?'
|
||||
|
||||
|
||||
def test_version():
|
||||
"""Test if the extension module version matches what setuptools returns"""
|
||||
try:
|
||||
from importlib import metadata
|
||||
except ImportError:
|
||||
# Python < 3.8, so we cant get the metadata, so just check if it exists
|
||||
assert quicktex.__version__
|
||||
print(f'Cannot check version in python < 3.8. __version__ is {quicktex.__version__}')
|
||||
return
|
||||
|
||||
version = metadata.version('quicktex')
|
||||
|
||||
assert version == quicktex.__version__, 'incorrect version string from extension module'
|
||||
assert version == quicktex.__version__, 'incorrect version string from extension module'
|
||||
|
@ -1,7 +1,6 @@
|
||||
import unittest
|
||||
import nose
|
||||
import os.path
|
||||
from tests.images import image_path
|
||||
from .images import image_path
|
||||
from quicktex import RawTexture
|
||||
from PIL import Image
|
||||
|
||||
@ -57,7 +56,3 @@ class TestRawTexture(unittest.TestCase):
|
||||
"""Test the frombytes factory function"""
|
||||
bytetex = RawTexture.frombytes(self.boilerplate_bytes, *self.boilerplate.size)
|
||||
self.assertEqual(self.boilerplate_bytes, bytetex.tobytes(), 'Incorrect bytes after writing to buffer')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
nose.main()
|
||||
|