41 Commits

Author SHA1 Message Date
ac4e5b2679 Release 0.1.3
### 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
2022-04-12 19:21:06 -07:00
25e74b9b08 Bump actions/setup-python from 3.1.1 to 3.1.2
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 3.1.1 to 3.1.2.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v3.1.1...v3.1.2)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-04-12 18:24:37 -07:00
a881a0a36b Add more helpful error when importing without libomp installed
Also use non-shallow clones in ci
2022-04-11 23:05:20 -07:00
3fdfc3ecaa Pretty job names 2022-04-11 21:48:22 -07:00
b440543de3 why 2022-04-11 21:18:43 -07:00
23ed54c7a2 fix conditional 2022-04-11 21:15:15 -07:00
e7e8657100 fix syntax error 2022-04-11 21:11:19 -07:00
2a07db8c8f Run arm64 linux builds on their own job for faster CI 2022-04-11 21:09:50 -07:00
b8a80235f8 Bump actions/upload-artifact from 2 to 3
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 2 to 3.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v2...v3)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-04-11 10:26:24 -07:00
4cac24798e Bump actions/download-artifact from 2 to 3
Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 2 to 3.
- [Release notes](https://github.com/actions/download-artifact/releases)
- [Commits](https://github.com/actions/download-artifact/compare/v2...v3)

---
updated-dependencies:
- dependency-name: actions/download-artifact
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-04-11 10:25:24 -07:00
9b6097373e Another attempt 2022-04-10 22:03:17 -07:00
b954ac6ccc Attempt to hint to cmake what python install to use correctly
Should fix my linux building issue?
2022-04-10 21:51:18 -07:00
593a0c3f46 Fix windows test command and install fat binaries for libomp 2022-04-10 21:08:07 -07:00
3b73bc8bce use Py_ssize_t to make msvc happy 2022-04-10 01:06:25 -07:00
abeb08fc81 Upgrade cibuildwheel to 2.4.0 2022-04-10 00:26:00 -07:00
77637f6abd Run tests in the right directory and skip linux for now 2022-04-10 00:22:13 -07:00
df6d5b1848 Use latest setuptools instead of pinning it 2022-04-10 00:09:44 -07:00
b5aea803d5 Use relative imports in tests 2022-04-10 00:04:08 -07:00
b80a6d2229 Fix arch selection and test command 2022-04-09 23:15:23 -07:00
dac7f07db4 Build for musl linux for platforms supported by Pillow
Specifically x64 for cpython 3.8-3.10
2022-04-09 22:54:06 -07:00
7dfefa3007 Skip musl linux wheel builds
Pillow appears to fail to compile on these without installing a bunch of dependencies, so... sorry alpine users
2022-04-09 22:40:05 -07:00
eaca455a08 syntax error 2022-04-09 22:24:35 -07:00
e5ccdbb4f4 Don't try to download test images 2022-04-09 22:23:00 -07:00
94d88c7e00 Remove nose dependence
Also move test images into the base repo because they're not very big anyways
2022-04-09 22:20:09 -07:00
9421a6d372 Merge branch 'main' into build-modernization 2022-04-09 20:39:43 -07:00
cab0eeebae Merge pull request #10 from drewcassidy/dependabot/github_actions/actions/checkout-3
Bump actions/checkout from 2 to 3
2022-04-09 20:21:43 -07:00
3d98b37a37 Merge pull request #13 from drewcassidy/dependabot/github_actions/actions/setup-python-3.1.1
Bump actions/setup-python from 2 to 3.1.1
2022-04-09 20:21:33 -07:00
654b6d628a Slightly modernize how project is compiled 2022-04-09 19:43:40 -07:00
1502c5318c Bump actions/setup-python from 2 to 3.1.1
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 2 to 3.1.1.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v2...v3.1.1)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-04-07 11:45:36 +00:00
421876ab0f Move more metadata to pyproject.toml 2022-04-03 20:41:02 -07:00
29590e0323 Move a good chunk of metadata to pyproject.toml 2022-04-03 16:22:47 -07:00
8b4e3c5746 Bump actions/checkout from 2 to 3
Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2...v3)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-04-03 20:15:09 +00:00
8e7b95609c Dependabot for gh actions 2022-04-03 13:12:29 -07:00
71379b7ae1 Revert to manylinux2014 2022-04-03 00:05:35 -07:00
d1346ca11d Enable macos cross-compiling in setup.py 2022-04-02 21:39:14 -07:00
e488dbcbff Fix builder version
and here I was thinking this was semver smh
2022-04-01 21:07:57 -07:00
1f7b45aa57 Compile for multiple architectures 2022-04-01 21:06:51 -07:00
70b7251eae Include build for python 3.10 (finally) 2022-04-01 20:27:00 -07:00
e8e0f4e29b Release 0.1.2
### Fixed

- Fixed sdist not including pybind
2022-03-27 14:29:57 -07:00
6d7f56476f Add manifest file 2022-03-27 14:28:17 -07:00
b4d2388615 Release 0.1.1
### Fixed

- Fixed alpha premultiplication when generating mipmaps
2021-09-28 20:42:13 -07:00
34 changed files with 211 additions and 149 deletions

9
.github/dependabot.yml vendored Normal file
View 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"

View File

@ -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,62 +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 }}
name: Build Wheels on ${{ matrix.os }} ${{ matrix.arch[0] }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ macos-latest, windows-latest, ubuntu-latest ]
os: [ macos-11, windows-latest, ubuntu-latest ]
arch: [ ['x86', 'x86_64', 'AMD64', 'x86_64' ] ] #[suffix, mac, windows, linux] arch names
include:
- 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 test images
run: git clone https://git.pileof.rocks/drewcassidy/quicktex-test-images.git tests/images
- name: Install QEMU
# install QEMU if building for arm linux
uses: docker/setup-qemu-action@v1
if: runner.os == 'linux' && matrix.arch[3] == 'aarch64'
with:
platforms: arm64
- name: Build wheels
uses: joerick/cibuildwheel@v1.11.0
uses: pypa/cibuildwheel@v2.4.0
env:
MACOSX_DEPLOYMENT_TARGET: "10.15"
CIBW_BUILD: "cp{37,38,39}-*"
CIBW_SKIP: "*-win32 *-manylinux_i686"
CIBW_MANYLINUX_X86_64_IMAGE: "manylinux2014"
CIBW_TEST_EXTRAS: "tests"
CIBW_TEST_COMMAND: nosetests {project}/tests -d
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: |
@ -108,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

3
.gitignore vendored
View File

@ -12,9 +12,6 @@ docs/_build/
#mypy
out
# Test images
tests/images/
# IDEs
**/.idea

4
.gitmodules vendored
View File

@ -1,4 +0,0 @@
[submodule "extern/pybind11"]
path = extern/pybind11
url = https://github.com/pybind/pybind11.git
branch = stable

View File

@ -2,7 +2,27 @@
All notable changes to this project will be documented in this file
## Unreleased
## 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
- Fixed sdist not including pybind
## 0.1.1 - 2021-09-29
### Fixed

View File

@ -1,13 +1,13 @@
cmake_minimum_required(VERSION 3.17)
cmake_minimum_required(VERSION 3.18)
include(CheckIPOSupported)
include(tools/CompilerWarnings.cmake)
project(quicktex)
# Find dependencies
find_package(Python COMPONENTS Interpreter Development)
find_package(Python COMPONENTS Interpreter Development.Module)
find_package(pybind11 CONFIG REQUIRED)
find_package(OpenMP)
add_subdirectory(extern/pybind11)
# Collect source files
file(GLOB SOURCE_FILES

1
extern/pybind11 vendored

Submodule extern/pybind11 deleted from 8de7772cc7

View File

@ -1,11 +1,75 @@
[build-system]
requires = [
"setuptools>=42",
"setuptools>=61",
"setuptools_scm>=6.2",
"wheel",
"cmake>=3.18",
"pybind11~=2.6.1",
"ninja; sys_platform != 'win32'",
"cmake>=3.12",
"setuptools_scm[toml]>=3.4"
]
build-backend = "setuptools.build_meta"
[project]
name = "quicktex"
description = "A fast block compression library for python"
readme = "README.md"
authors = [{ name = "Andrew Cassidy", email = "drewcassidy@me.com" }]
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Topic :: Multimedia :: Graphics :: Graphics Conversion",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: C++",
]
requires-python = ">=3.7"
dependencies = ["Pillow", "click"]
dynamic = ["version"]
[project.optional-dependencies]
tests = ["parameterized"]
docs = ["sphinx", "myst-parser", "sphinx-rtd-theme"]
stubs = ["pybind11-stubgen"]
[project.urls]
Source = "https://github.com/drewcassidy/quicktex"
Changelog = "https://github.com/drewcassidy/quicktex/blob/main/CHANGELOG.md"
[project.scripts]
quicktex = "quicktex.__main__:main"
[tool.setuptools]
zip-safe = false
packages = { find = { include = ["quicktex*"] } } # only include quicktex and not tests
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"

View File

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

View File

@ -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.");

View File

@ -1,16 +1,14 @@
import os
import re
import sys
import glob
import subprocess
import pybind11
from setuptools import setup, Extension, find_packages
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
project_path = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(project_path, 'README.md')) as f:
readme = f.read()
# A CMakeExtension needs a sourcedir instead of a file list.
# The name must be the _single_ output extension from the CMake build.
@ -41,9 +39,13 @@ class CMakeBuild(build_ext):
# 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 = []
@ -84,6 +86,12 @@ class CMakeBuild(build_ext):
]
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:
@ -104,49 +112,10 @@ class CMakeBuild(build_ext):
)
# Find stub files
stubs = [path.replace('quicktex/', '') for path in glob.glob('quicktex/**/*.pyi', recursive=True)]
# 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(
name="quicktex",
use_scm_version=True,
author="Andrew Cassidy",
author_email="drewcassidy@me.com",
description="A fast block compression library for python",
url='https://github.com/drewcassidy/quicktex',
long_description=readme,
long_description_content_type='text/markdown',
python_requires=">=3.7",
ext_modules=[CMakeExtension("_quicktex")],
cmdclass={"build_ext": CMakeBuild},
packages=find_packages(where='.', include=['quicktex*']),
package_dir={'': '.'},
package_data={'': ['py.typed'] + stubs},
include_package_data=True,
install_requires=["Pillow", "click"],
extras_require={
"tests": ["nose", "parameterized"],
"docs": ["sphinx", "myst-parser", "sphinx-rtd-theme"],
"stubs": ["pybind11-stubgen"],
},
entry_points={
'console_scripts': ['quicktex = quicktex.__main__:main']
},
zip_safe=False,
classifiers=[
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
"Topic :: Multimedia :: Graphics :: Graphics Conversion",
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: C++'
],
)

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 934 KiB

BIN
tests/images/Bun.afdesign Normal file

Binary file not shown.

BIN
tests/images/Bun.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 375 KiB

32
tests/images/__init__.py Normal file
View 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

Binary file not shown.

BIN
tests/images/bc1/3color.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 B

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 B

BIN
tests/images/bc4/6value.dds Normal file

Binary file not shown.

BIN
tests/images/bc4/6value.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 513 B

BIN
tests/images/bc4/8value.dds Normal file

Binary file not shown.

BIN
tests/images/bc4/8value.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 509 B

Binary file not shown.

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

View File

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

View File

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

View File

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