mirror of
https://github.com/drewcassidy/quicktex.git
synced 2024-09-13 06:37:34 +00:00
Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
b4d2388615 | |||
f7d57aa859 | |||
24b064e6b4 | |||
28930d89d5 | |||
4f25e0f750 | |||
433e728424 | |||
4939171d5d | |||
f0f132328c | |||
7a11901aa6 | |||
cb8b251baf | |||
463956b63b | |||
22cc5f6148 | |||
0478532cb9 | |||
f2873f3a38 | |||
2618faadfc |
172
.github/workflows/python-package.yml
vendored
172
.github/workflows/python-package.yml
vendored
@ -6,11 +6,49 @@ name: Python Package
|
||||
on: [ push, pull_request ]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
build-sdist:
|
||||
name: Build SDist
|
||||
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'
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v2
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
python -m pip install flake8
|
||||
python -m pip install setuptools twine build
|
||||
|
||||
- name: Lint with flake8
|
||||
run: |
|
||||
# stop the build if there are Python syntax errors or undefined names
|
||||
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
|
||||
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
|
||||
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
|
||||
|
||||
- name: Build SDist
|
||||
run: python -m build --sdist
|
||||
|
||||
- name: Check metadata
|
||||
run: python -m twine check dist/*
|
||||
|
||||
- name: Upload SDist
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
path: dist/*.tar.gz
|
||||
|
||||
build-wheels:
|
||||
name: Build Wheels for ${{ matrix.os }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
python-version: [ 3.7, 3.8, 3.9 ]
|
||||
os: [ macos-latest, windows-latest, ubuntu-latest ]
|
||||
|
||||
steps:
|
||||
@ -20,95 +58,32 @@ jobs:
|
||||
# recursively checkout submodules.
|
||||
submodules: 'true'
|
||||
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
|
||||
- name: Set linux compiler
|
||||
if: runner.os == 'Linux'
|
||||
run: |
|
||||
echo "CC=gcc-10" >> $GITHUB_ENV
|
||||
echo "CXX=g++-10" >> $GITHUB_ENV
|
||||
|
||||
- name: Install libomp
|
||||
if: runner.os == 'macOS'
|
||||
# openMP isnt part of core apple clang for some reason?
|
||||
run: brew install libomp
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
python -m pip install flake8
|
||||
|
||||
- name: Install test images
|
||||
run: git clone https://git.pileof.rocks/drewcassidy/quicktex-test-images.git tests/images
|
||||
|
||||
- name: Lint with flake8
|
||||
run: |
|
||||
# stop the build if there are Python syntax errors or undefined names
|
||||
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
|
||||
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
|
||||
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
|
||||
- name: Build wheels
|
||||
uses: joerick/cibuildwheel@v1.11.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
|
||||
|
||||
- name: Compile and install
|
||||
run: python -m pip install -e .[tests]
|
||||
|
||||
- name: Test with nose
|
||||
run: nosetests tests -d
|
||||
|
||||
build:
|
||||
needs: test
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
env:
|
||||
MACOSX_DEPLOYMENT_TARGET: 10.15
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
python-version: [ 3.7, 3.8, 3.9 ]
|
||||
os: [ macos-latest, windows-latest ]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
# Whether to checkout submodules: `true` to checkout submodules or `recursive` to
|
||||
# recursively checkout submodules.
|
||||
submodules: 'true'
|
||||
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
|
||||
- name: Set linux compiler
|
||||
if: runner.os == 'Linux'
|
||||
run: |
|
||||
echo "CC=gcc-10" >> $GITHUB_ENV
|
||||
echo "CXX=g++-10" >> $GITHUB_ENV
|
||||
|
||||
- name: Install libomp
|
||||
if: runner.os == 'macOS'
|
||||
# openMP isnt part of core apple clang for some reason?
|
||||
run: brew install libomp
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
python -m pip install setuptools wheel twine build
|
||||
|
||||
- name: Build a binary wheel
|
||||
run: python -m build --wheel --outdir dist/
|
||||
|
||||
- name: Upload wheel as artifact
|
||||
- name: Upload Wheels
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: dist
|
||||
path: dist
|
||||
path: ./wheelhouse/*.whl
|
||||
|
||||
publish:
|
||||
needs: build
|
||||
name: Publish to PyPI and Github
|
||||
needs: [build-wheels, build-sdist]
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
@ -121,25 +96,42 @@ jobs:
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: '3.x'
|
||||
|
||||
- name: Download artifacts
|
||||
uses: actions/download-artifact@v2
|
||||
|
||||
- name: List artifacts
|
||||
run: ls -l dist
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
python -m pip install setuptools wheel twine build
|
||||
python -m pip install yaclog
|
||||
|
||||
- name: Build a source tarball
|
||||
run: python -m build --sdist --outdir dist/
|
||||
- name: Get version name and body
|
||||
run: |
|
||||
echo "VERSION_TILE=Version $(yaclog show -n)" >> $GITHUB_ENV
|
||||
echo "$(yaclog show -mb)" >> RELEASE.md
|
||||
|
||||
- name: Download Artifacts
|
||||
uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: artifact
|
||||
path: dist
|
||||
|
||||
- name: List artifacts
|
||||
run: ls -l dist
|
||||
|
||||
- name: Publish to Test PyPI
|
||||
uses: pypa/gh-action-pypi-publish@release/v1
|
||||
with:
|
||||
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
|
||||
repository_url: https://test.pypi.org/legacy/
|
||||
repository_url: https://test.pypi.org/legacy/
|
||||
|
||||
- name: Publish to PyPI
|
||||
uses: pypa/gh-action-pypi-publish@release/v1
|
||||
with:
|
||||
password: ${{ secrets.PYPI_API_TOKEN }}
|
||||
|
||||
- name: Publish to Github
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
files: dist/*
|
||||
name: ${{ env.VERSION_TITLE }}
|
||||
body_path: RELEASE.md
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
21
CHANGELOG.md
Normal file
21
CHANGELOG.md
Normal file
@ -0,0 +1,21 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file
|
||||
|
||||
## 0.1.1 - 2021-09-29
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed alpha premultiplication when generating mipmaps
|
||||
|
||||
|
||||
## 0.1.0 - 2021-05-10
|
||||
|
||||
### Added
|
||||
|
||||
- Began publishing to PyPI
|
||||
|
||||
### Changed
|
||||
|
||||
- Rewrote CI workflow to include ManyLinux2014 builds
|
||||
- Reverted project to C++17 for better compiler compatibility
|
@ -5,7 +5,7 @@ include(tools/CompilerWarnings.cmake)
|
||||
project(quicktex)
|
||||
|
||||
# Find dependencies
|
||||
find_package(Python COMPONENTS Interpreter Development REQUIRED)
|
||||
find_package(Python COMPONENTS Interpreter Development)
|
||||
find_package(OpenMP)
|
||||
add_subdirectory(extern/pybind11)
|
||||
|
||||
@ -59,8 +59,8 @@ if (OpenMP_CXX_FOUND)
|
||||
endif ()
|
||||
|
||||
# Set module features, like C/C++ standards
|
||||
target_compile_features(_quicktex PUBLIC cxx_std_20 c_std_11)
|
||||
target_compile_features(test_quicktex PUBLIC cxx_std_20 c_std_11)
|
||||
target_compile_features(_quicktex PUBLIC cxx_std_17 c_std_11)
|
||||
target_compile_features(test_quicktex PUBLIC cxx_std_17 c_std_11)
|
||||
|
||||
set_project_warnings(_quicktex)
|
||||
set_project_warnings(test_quicktex)
|
||||
|
@ -122,4 +122,7 @@ uint16_t Color::Pack565Unscaled() const { return Pack565Unscaled(r, g, b); }
|
||||
Color Color::ScaleTo565() const { return Color(scale8To5(r), scale8To6(g), scale8To5(b)); }
|
||||
Color Color::ScaleFrom565() const { return Color(scale5To8(r), scale6To8(g), scale5To8(b)); }
|
||||
|
||||
bool Color::operator==(const Color &Rhs) const { return r == Rhs.r && g == Rhs.g && b == Rhs.b && a == Rhs.a; }
|
||||
bool Color::operator!=(const Color &Rhs) const { return !(Rhs == *this); }
|
||||
|
||||
} // namespace quicktex
|
@ -51,7 +51,8 @@ class Color {
|
||||
static Color Min(const Color &A, const Color &B);
|
||||
static Color Max(const Color &A, const Color &B);
|
||||
|
||||
bool operator==(const Color &Rhs) const { return r == Rhs.r && g == Rhs.g && b == Rhs.b && a == Rhs.a; }
|
||||
bool operator==(const Color &Rhs) const;
|
||||
bool operator!=(const Color &Rhs) const;
|
||||
|
||||
uint8_t operator[](size_t index) const {
|
||||
assert(index < 4);
|
||||
|
@ -166,7 +166,7 @@ class DDSFile:
|
||||
|
||||
# WRITE HEADER
|
||||
file.write(struct.pack('<7I44x', DDSFile.header_bytes, int(self.flags), self.size[1], self.size[0], self.pitch, self.depth, self.mipmap_count))
|
||||
file.write(struct.pack('<2I4s5I', 32, int(self.pfflags), bytes(self.four_cc, 'ascii'), self.pixel_size, *self.pixel_bitmasks))
|
||||
file.write(struct.pack('<2I4s5I', 32, int(self.pf_flags), bytes(self.four_cc, 'ascii'), self.pixel_size, *self.pixel_bitmasks))
|
||||
file.write(struct.pack('<4I4x', *self.caps))
|
||||
|
||||
assert file.tell() == 4 + DDSFile.header_bytes, 'error writing file: incorrect header size'
|
||||
@ -256,7 +256,7 @@ def encode(image: Image.Image, encoder, four_cc: str, mip_count: typing.Optional
|
||||
image = image.convert(mode)
|
||||
|
||||
sizes = quicktex.image_utils.mip_sizes(image.size, mip_count)
|
||||
images = [image] + [image.resize(size, Image.BILINEAR) for size in sizes[1:]]
|
||||
images = [image] + [quicktex.image_utils.resize_no_premultiply(image, size) for size in sizes[1:]]
|
||||
dds = DDSFile()
|
||||
|
||||
for i in images:
|
||||
|
@ -32,3 +32,20 @@ def mip_sizes(dimensions: Tuple[int, int], mip_count: Optional[int] = None) -> L
|
||||
dimensions = tuple([max(dim // 2, 1) for dim in dimensions])
|
||||
|
||||
return chain
|
||||
|
||||
|
||||
def resize_no_premultiply(image: Image.Image, size: Tuple[int, int]) -> Image.Image:
|
||||
"""
|
||||
Resize an image without premulitplying the alpha. Required due to a quick in Pillow
|
||||
|
||||
:param image: Image to resize
|
||||
:param size: Size to resize to
|
||||
:return: The resized image
|
||||
"""
|
||||
if image.mode == 'RGBA':
|
||||
rgb = image.convert('RGB').resize(size, Image.BILINEAR)
|
||||
a = image.getchannel('A').resize(size, Image.BILINEAR)
|
||||
rgb.putalpha(a)
|
||||
return rgb
|
||||
else:
|
||||
return image.resize(size, Image.BILINEAR)
|
||||
|
@ -41,4 +41,7 @@ void BC1Block::SetSelectors(const BC1Block::SelectorArray& unpacked) {
|
||||
_selectors = MapArray(unpacked, Pack<uint8_t, uint8_t, SelectorBits, Width>);
|
||||
}
|
||||
|
||||
bool BC1Block::operator==(const BC1Block& Rhs) const { return _color0 == Rhs._color0 && _color1 == Rhs._color1 && _selectors == Rhs._selectors; }
|
||||
bool BC1Block::operator!=(const BC1Block& Rhs) const { return !(Rhs == *this); }
|
||||
|
||||
} // namespace quicktex::s3tc
|
||||
|
@ -121,7 +121,7 @@ class alignas(8) BC1Block {
|
||||
|
||||
bool Is3Color() const { return GetColor0Raw() <= GetColor1Raw(); }
|
||||
|
||||
bool operator==(const BC1Block& other) const = default;
|
||||
bool operator!=(const BC1Block& other) const = default;
|
||||
bool operator==(const BC1Block& Rhs) const;
|
||||
bool operator!=(const BC1Block& Rhs) const;
|
||||
};
|
||||
} // namespace quicktex::s3tc
|
@ -54,7 +54,7 @@ class alignas(8) BC3Block {
|
||||
color_block = blocks.second;
|
||||
}
|
||||
|
||||
bool operator==(const BC3Block &other) const = default;
|
||||
bool operator!=(const BC3Block &other) const = default;
|
||||
bool operator==(const BC3Block &Rhs) const { return alpha_block == Rhs.alpha_block && color_block == Rhs.color_block; }
|
||||
bool operator!=(const BC3Block &Rhs) const { return !(Rhs == *this); }
|
||||
};
|
||||
} // namespace quicktex::s3tc
|
@ -19,8 +19,8 @@
|
||||
|
||||
#include "BC4Block.h"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "../../util.h"
|
||||
|
||||
@ -63,4 +63,7 @@ std::array<uint8_t, 8> BC4Block::GetValues8() const {
|
||||
static_cast<uint8_t>((alpha0 * 2 + alpha1 * 5) / 7),
|
||||
static_cast<uint8_t>((alpha0 + alpha1 * 6) / 7)};
|
||||
}
|
||||
|
||||
bool BC4Block::operator==(const BC4Block& Rhs) const { return alpha0 == Rhs.alpha0 && alpha1 == Rhs.alpha1 && _selectors == Rhs._selectors; }
|
||||
bool BC4Block::operator!=(const BC4Block& Rhs) const { return !(Rhs == *this); }
|
||||
} // namespace quicktex::s3tc
|
||||
|
@ -97,8 +97,8 @@ class alignas(8) BC4Block {
|
||||
/// The interpolated values of this block as an array of 8 integers.
|
||||
std::array<uint8_t, 8> GetValues() const { return Is6Value() ? GetValues6() : GetValues8(); }
|
||||
|
||||
bool operator==(const BC4Block& other) const = default;
|
||||
bool operator!=(const BC4Block& other) const = default;
|
||||
bool operator==(const BC4Block& Rhs) const;
|
||||
bool operator!=(const BC4Block& Rhs) const;
|
||||
|
||||
private:
|
||||
std::array<uint8_t, 8> GetValues6() const;
|
||||
|
@ -53,7 +53,7 @@ class alignas(8) BC5Block {
|
||||
chan1_block = pair.second;
|
||||
}
|
||||
|
||||
bool operator==(const BC5Block &other) const = default;
|
||||
bool operator!=(const BC5Block &other) const = default;
|
||||
bool operator==(const BC5Block &Rhs) const { return chan0_block == Rhs.chan0_block && chan1_block == Rhs.chan1_block; }
|
||||
bool operator!=(const BC5Block &Rhs) const { return !(Rhs == *this); }
|
||||
};
|
||||
} // namespace quicktex::s3tc
|
2
setup.py
2
setup.py
@ -121,7 +121,7 @@ setup(
|
||||
python_requires=">=3.7",
|
||||
ext_modules=[CMakeExtension("_quicktex")],
|
||||
cmdclass={"build_ext": CMakeBuild},
|
||||
packages=['quicktex'],
|
||||
packages=find_packages(where='.', include=['quicktex*']),
|
||||
package_dir={'': '.'},
|
||||
package_data={'': ['py.typed'] + stubs},
|
||||
include_package_data=True,
|
||||
|
Reference in New Issue
Block a user