libstb 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- libstb-0.3.0/.github/workflows/cmake.yml +39 -0
- libstb-0.3.0/.github/workflows/orchestrator.yml +89 -0
- libstb-0.3.0/.github/workflows/release_template.md +8 -0
- libstb-0.3.0/.github/workflows/wheels.yml +70 -0
- libstb-0.3.0/.gitignore +137 -0
- libstb-0.3.0/CMakeLists.txt +105 -0
- libstb-0.3.0/LICENSE.txt +21 -0
- libstb-0.3.0/PKG-INFO +212 -0
- libstb-0.3.0/README.md +187 -0
- libstb-0.3.0/cmake/DynamicVersion.cmake +119 -0
- libstb-0.3.0/cmake/Optimize.cmake +56 -0
- libstb-0.3.0/cmake/Startup.cmake +17 -0
- libstb-0.3.0/cmake/libstbConfig.cmake.in +5 -0
- libstb-0.3.0/include/stb/error.hpp +52 -0
- libstb-0.3.0/include/stb/font.hpp +131 -0
- libstb-0.3.0/include/stb/image.hpp +157 -0
- libstb-0.3.0/include/stb/resizer.hpp +72 -0
- libstb-0.3.0/include/stb/utf8.hpp +13 -0
- libstb-0.3.0/include/stb.h +24 -0
- libstb-0.3.0/pyproject.toml +68 -0
- libstb-0.3.0/requirements-dev.txt +13 -0
- libstb-0.3.0/src/bindings/python/CMakeLists.txt +64 -0
- libstb-0.3.0/src/bindings/python/bind_font.cpp +111 -0
- libstb-0.3.0/src/bindings/python/bind_image.cpp +234 -0
- libstb-0.3.0/src/bindings/python/bind_resizer.cpp +67 -0
- libstb-0.3.0/src/bindings/python/binding.cpp +30 -0
- libstb-0.3.0/src/bindings/python/binding.hpp +13 -0
- libstb-0.3.0/src/bindings/python/libstb/__init__.py +62 -0
- libstb-0.3.0/src/bindings/python/libstb/font.py +144 -0
- libstb-0.3.0/src/bindings/python/libstb/image.py +42 -0
- libstb-0.3.0/src/core/file.hpp +51 -0
- libstb-0.3.0/src/core/font.cpp +274 -0
- libstb-0.3.0/src/core/image.cpp +259 -0
- libstb-0.3.0/src/core/resizer.cpp +149 -0
- libstb-0.3.0/src/core/utf8.cpp +42 -0
- libstb-0.3.0/src/third_party/README.md +16 -0
- libstb-0.3.0/src/third_party/stb/stb_image.h +7988 -0
- libstb-0.3.0/src/third_party/stb/stb_image_resize2.h +10679 -0
- libstb-0.3.0/src/third_party/stb/stb_image_write.h +1724 -0
- libstb-0.3.0/src/third_party/stb/stb_rect_pack.h +623 -0
- libstb-0.3.0/src/third_party/stb/stb_truetype.h +5079 -0
- libstb-0.3.0/tests/CMakeLists.txt +13 -0
- libstb-0.3.0/tests/cmake/CMakeLists.txt +22 -0
- libstb-0.3.0/tests/cmake/consumer_project/CMakeLists.txt +27 -0
- libstb-0.3.0/tests/cmake/consumer_project/main.cpp +36 -0
- libstb-0.3.0/tests/cmake/run_consumer_test.cmake +52 -0
- libstb-0.3.0/tests/cpp/CMakeLists.txt +24 -0
- libstb-0.3.0/tests/cpp/test_common.hpp +55 -0
- libstb-0.3.0/tests/cpp/test_encode.cpp +191 -0
- libstb-0.3.0/tests/cpp/test_font.cpp +190 -0
- libstb-0.3.0/tests/cpp/test_image.cpp +282 -0
- libstb-0.3.0/tests/cpp/test_resizer.cpp +190 -0
- libstb-0.3.0/tests/cpp/test_utf8.cpp +24 -0
- libstb-0.3.0/tests/data/libstb-test.ttf +0 -0
- libstb-0.3.0/tests/data/make_test_font.py +58 -0
- libstb-0.3.0/tests/python/CMakeLists.txt +26 -0
- libstb-0.3.0/tests/python/test_encode.py +146 -0
- libstb-0.3.0/tests/python/test_errors.py +25 -0
- libstb-0.3.0/tests/python/test_font.py +145 -0
- libstb-0.3.0/tests/python/test_image.py +148 -0
- libstb-0.3.0/tests/python/test_oop.py +174 -0
- libstb-0.3.0/tests/python/test_resizer.py +165 -0
- libstb-0.3.0/tests/utest/utest.h +1305 -0
- libstb-0.3.0/tests/utest/utest_main.cxx +14 -0
- libstb-0.3.0/version.py +250 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
name: cmake stuff
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
workflow_call:
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ master ]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
build-and-test:
|
|
11
|
+
strategy:
|
|
12
|
+
matrix:
|
|
13
|
+
os: [ubuntu-latest, macos-latest, windows-latest]
|
|
14
|
+
|
|
15
|
+
runs-on: ${{ matrix.os }}
|
|
16
|
+
|
|
17
|
+
steps:
|
|
18
|
+
- name: Checkout repository
|
|
19
|
+
uses: actions/checkout@v6
|
|
20
|
+
|
|
21
|
+
- name: Set up Python
|
|
22
|
+
uses: actions/setup-python@v6
|
|
23
|
+
with:
|
|
24
|
+
python-version: "3.11"
|
|
25
|
+
cache: "pip"
|
|
26
|
+
|
|
27
|
+
- name: Install python deps
|
|
28
|
+
run: pip install -r requirements-dev.txt
|
|
29
|
+
|
|
30
|
+
- name: Configure Project
|
|
31
|
+
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DLIBSTB_BUILD_TESTS=ON -DLIBSTB_BUILD_PYTHON=ON
|
|
32
|
+
|
|
33
|
+
- name: Build
|
|
34
|
+
run: cmake --build build -j4 --config Release
|
|
35
|
+
|
|
36
|
+
# C++ tests, Python tests (pytest against the freshly built package) and
|
|
37
|
+
# the find_package consumer test all run under ctest.
|
|
38
|
+
- name: Run tests
|
|
39
|
+
run: ctest --test-dir build -C Release --output-on-failure
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
name: Orchestration & Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
push:
|
|
6
|
+
branches: [ master ]
|
|
7
|
+
tags: [ "v*" ]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
init:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
outputs:
|
|
13
|
+
release_name: ${{ steps.init.outputs.release_name }}
|
|
14
|
+
is_tag: ${{ steps.init.outputs.is_tag }}
|
|
15
|
+
version_string: ${{ steps.init.outputs.version_string }}
|
|
16
|
+
steps:
|
|
17
|
+
- name: Checkout repository
|
|
18
|
+
uses: actions/checkout@v6
|
|
19
|
+
|
|
20
|
+
- name: Initalize
|
|
21
|
+
id: init
|
|
22
|
+
env:
|
|
23
|
+
GH_TOKEN: ${{ github.token }}
|
|
24
|
+
run: |
|
|
25
|
+
export version_string="$(python version.py | tr -d '\n')"
|
|
26
|
+
echo "version_string=${version_string}" | tee -a "$GITHUB_OUTPUT"
|
|
27
|
+
if [[ "${{ github.ref }}" =~ ^refs/tags/v.*$ ]]; then
|
|
28
|
+
TAG_NAME="${GITHUB_REF#refs/tags/}"
|
|
29
|
+
[[ "${version_string}" == "${GITHUB_REF#refs/tags/v}" ]] || (echo "❌ Version mismatch!" && exit 1)
|
|
30
|
+
export release_name="$TAG_NAME"
|
|
31
|
+
export is_tag="true"
|
|
32
|
+
else
|
|
33
|
+
gh api repos/${{ github.repository }}/releases/tags/__beta__ --jq '.assets[].id' 2>/dev/null | xargs -r -I {} gh api repos/${{ github.repository }}/releases/assets/{} -X DELETE 2>/dev/null || true
|
|
34
|
+
export release_name="__beta__"
|
|
35
|
+
export is_tag="false"
|
|
36
|
+
fi
|
|
37
|
+
echo "release_name=${release_name}" | tee -a "$GITHUB_OUTPUT"
|
|
38
|
+
echo "is_tag=${is_tag}" | tee -a "$GITHUB_OUTPUT"
|
|
39
|
+
sed -i -e "s/RELEASE_NAME/${release_name}/g" -e "s/VERSION_STRING/${version_string}/g" .github/workflows/release_template.md
|
|
40
|
+
|
|
41
|
+
- name: Initialize release body
|
|
42
|
+
uses: softprops/action-gh-release@v3
|
|
43
|
+
with:
|
|
44
|
+
tag_name: ${{ steps.init.outputs.release_name }}
|
|
45
|
+
name: ${{ steps.init.outputs.release_name }}
|
|
46
|
+
draft: false
|
|
47
|
+
prerelease: ${{ steps.init.outputs.is_tag == 'false' }}
|
|
48
|
+
token: ${{ secrets.GITHUB_TOKEN }}
|
|
49
|
+
body_path: .github/workflows/release_template.md
|
|
50
|
+
|
|
51
|
+
cmake:
|
|
52
|
+
uses: ./.github/workflows/cmake.yml
|
|
53
|
+
needs: [init]
|
|
54
|
+
|
|
55
|
+
wheel:
|
|
56
|
+
uses: ./.github/workflows/wheels.yml
|
|
57
|
+
needs: [init]
|
|
58
|
+
|
|
59
|
+
release-wheels:
|
|
60
|
+
needs: [wheel, init]
|
|
61
|
+
runs-on: ubuntu-latest
|
|
62
|
+
steps:
|
|
63
|
+
- name: Download all artifacts
|
|
64
|
+
uses: actions/download-artifact@v8
|
|
65
|
+
with:
|
|
66
|
+
pattern: wheelhouse-*
|
|
67
|
+
path: dist
|
|
68
|
+
merge-multiple: true
|
|
69
|
+
|
|
70
|
+
- name: List dist directory
|
|
71
|
+
run: tree --du -shaC .
|
|
72
|
+
|
|
73
|
+
- name: create release body
|
|
74
|
+
uses: softprops/action-gh-release@v3
|
|
75
|
+
with:
|
|
76
|
+
tag_name: ${{ needs.init.outputs.release_name }}
|
|
77
|
+
name: ${{ needs.init.outputs.release_name }}
|
|
78
|
+
draft: false
|
|
79
|
+
prerelease: ${{ needs.init.outputs.is_tag == 'false' }}
|
|
80
|
+
token: ${{ secrets.GITHUB_TOKEN }}
|
|
81
|
+
files: dist/*
|
|
82
|
+
generate_release_notes: true
|
|
83
|
+
|
|
84
|
+
- name: Publishing to PyPi
|
|
85
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
86
|
+
if: startsWith(github.ref, 'refs/tags/')
|
|
87
|
+
with:
|
|
88
|
+
password: ${{ secrets.PYPI_PASSWORD }}
|
|
89
|
+
user: ${{ secrets.PYPI_USERNAME }}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
|
|
2
|
+
```sh
|
|
3
|
+
pip install libstb==VERSION_STRING
|
|
4
|
+
```
|
|
5
|
+
|
|
6
|
+
Wheels: `cp312-abi3` (covers Python 3.12+) and one wheel each for cp39, cp310 and cp311, for Windows, Linux (glibc + musl) and macOS (universal2), plus the sdist. Download them from the assets of [RELEASE_NAME](https://github.com/MohammadRaziei/libstb/releases/tag/RELEASE_NAME).
|
|
7
|
+
|
|
8
|
+
---
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
name: python build wheels
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
workflow_call:
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ master ]
|
|
8
|
+
|
|
9
|
+
env:
|
|
10
|
+
FORCE_COLOR: 3
|
|
11
|
+
|
|
12
|
+
concurrency:
|
|
13
|
+
group: wheels-${{ github.ref }}
|
|
14
|
+
cancel-in-progress: true
|
|
15
|
+
|
|
16
|
+
jobs:
|
|
17
|
+
build_sdist:
|
|
18
|
+
name: Build SDist
|
|
19
|
+
runs-on: ubuntu-latest
|
|
20
|
+
steps:
|
|
21
|
+
- uses: actions/checkout@v6
|
|
22
|
+
|
|
23
|
+
- uses: actions/setup-python@v6
|
|
24
|
+
with:
|
|
25
|
+
python-version: "3.11"
|
|
26
|
+
cache: "pip"
|
|
27
|
+
|
|
28
|
+
- name: Build SDist
|
|
29
|
+
run: pipx run build --sdist
|
|
30
|
+
|
|
31
|
+
- name: Check metadata
|
|
32
|
+
run: pipx run twine check dist/*
|
|
33
|
+
|
|
34
|
+
- uses: actions/upload-artifact@v7
|
|
35
|
+
with:
|
|
36
|
+
name: wheelhouse-sdist
|
|
37
|
+
path: dist/*.tar.gz
|
|
38
|
+
overwrite: true
|
|
39
|
+
|
|
40
|
+
build_wheels:
|
|
41
|
+
name: Wheels on ${{ matrix.os }}
|
|
42
|
+
runs-on: ${{ matrix.os }}
|
|
43
|
+
strategy:
|
|
44
|
+
fail-fast: true
|
|
45
|
+
matrix:
|
|
46
|
+
os: [ubuntu-latest, macos-latest, windows-latest]
|
|
47
|
+
|
|
48
|
+
steps:
|
|
49
|
+
- uses: actions/checkout@v6
|
|
50
|
+
|
|
51
|
+
- name: Build wheels
|
|
52
|
+
uses: pypa/cibuildwheel@v3.4.1
|
|
53
|
+
env:
|
|
54
|
+
# C++17 runtime on macOS.
|
|
55
|
+
MACOSX_DEPLOYMENT_TARGET: "10.15"
|
|
56
|
+
CIBW_ARCHS_MACOS: universal2
|
|
57
|
+
# 3.9-3.11: normal per-version wheels (nanobind has no stable-ABI
|
|
58
|
+
# support below 3.12; it silently builds a regular extension there).
|
|
59
|
+
# 3.12: built once, tagged cp312-abi3 via SKBUILD_WHEEL_PY_API, and
|
|
60
|
+
# that single wheel covers every newer interpreter too - so 3.13+
|
|
61
|
+
# is skipped here to avoid building a redundant duplicate wheel.
|
|
62
|
+
CIBW_BUILD: "cp39-* cp310-* cp311-* cp312-*"
|
|
63
|
+
CIBW_ENVIRONMENT_CP312: "SKBUILD_WHEEL_PY_API=cp312"
|
|
64
|
+
CIBW_SKIP: pp*
|
|
65
|
+
|
|
66
|
+
- uses: actions/upload-artifact@v7
|
|
67
|
+
with:
|
|
68
|
+
name: wheelhouse-${{ matrix.os }}
|
|
69
|
+
path: wheelhouse/*.whl
|
|
70
|
+
overwrite: false
|
libstb-0.3.0/.gitignore
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
*.egg-info/
|
|
24
|
+
.installed.cfg
|
|
25
|
+
*.egg
|
|
26
|
+
|
|
27
|
+
# PyInstaller
|
|
28
|
+
*.manifest
|
|
29
|
+
*.spec
|
|
30
|
+
|
|
31
|
+
# Installer logs
|
|
32
|
+
pip-log.txt
|
|
33
|
+
pip-delete-this-directory.txt
|
|
34
|
+
|
|
35
|
+
# Unit test / coverage reports
|
|
36
|
+
htmlcov/
|
|
37
|
+
.tox/
|
|
38
|
+
.nox/
|
|
39
|
+
.coverage
|
|
40
|
+
.coverage.*
|
|
41
|
+
.cache
|
|
42
|
+
nosetests.xml
|
|
43
|
+
coverage.xml
|
|
44
|
+
*.cover
|
|
45
|
+
*.py,cover
|
|
46
|
+
.hypothesis/
|
|
47
|
+
.pytest_cache/
|
|
48
|
+
|
|
49
|
+
# Translations
|
|
50
|
+
*.mo
|
|
51
|
+
*.pot
|
|
52
|
+
|
|
53
|
+
# Django stuff:
|
|
54
|
+
*.log
|
|
55
|
+
local_settings.py
|
|
56
|
+
db.sqlite3
|
|
57
|
+
db.sqlite3-journal
|
|
58
|
+
|
|
59
|
+
# Flask stuff:
|
|
60
|
+
instance/
|
|
61
|
+
.webassets-cache
|
|
62
|
+
|
|
63
|
+
# Scrapy stuff:
|
|
64
|
+
.scrapy
|
|
65
|
+
|
|
66
|
+
# Sphinx documentation docs/
|
|
67
|
+
docs/_build/
|
|
68
|
+
|
|
69
|
+
# PyBuilder
|
|
70
|
+
.pybuilder/
|
|
71
|
+
target/
|
|
72
|
+
|
|
73
|
+
# Jupyter Notebook
|
|
74
|
+
.ipynb_checkpoints
|
|
75
|
+
|
|
76
|
+
# IPython
|
|
77
|
+
profile_default/
|
|
78
|
+
ipython_config.py
|
|
79
|
+
|
|
80
|
+
# pyenv
|
|
81
|
+
.python-version
|
|
82
|
+
|
|
83
|
+
# pipenv
|
|
84
|
+
Pipfile.lock
|
|
85
|
+
|
|
86
|
+
# PEP 582
|
|
87
|
+
__pypackages__/
|
|
88
|
+
|
|
89
|
+
# Celery stuff
|
|
90
|
+
celerybeat-schedule
|
|
91
|
+
celerybeat.pid
|
|
92
|
+
|
|
93
|
+
# SageMath parsed template
|
|
94
|
+
*.sage.py
|
|
95
|
+
|
|
96
|
+
# Environments
|
|
97
|
+
.env
|
|
98
|
+
.venv
|
|
99
|
+
env/
|
|
100
|
+
venv/
|
|
101
|
+
ENV/
|
|
102
|
+
env.bak/
|
|
103
|
+
venv.bak/
|
|
104
|
+
|
|
105
|
+
# Spyder project settings
|
|
106
|
+
.spyderproject
|
|
107
|
+
.spyproject
|
|
108
|
+
|
|
109
|
+
# Rope project settings
|
|
110
|
+
.ropeproject
|
|
111
|
+
|
|
112
|
+
# mkdocs documentation
|
|
113
|
+
/site
|
|
114
|
+
|
|
115
|
+
# mypy
|
|
116
|
+
.mypy_cache/
|
|
117
|
+
.dmypy.json
|
|
118
|
+
dmypy.json
|
|
119
|
+
|
|
120
|
+
# Pyre type checker
|
|
121
|
+
.pyre/
|
|
122
|
+
|
|
123
|
+
# IDEs
|
|
124
|
+
.vscode/
|
|
125
|
+
.idea/
|
|
126
|
+
|
|
127
|
+
# OS generated files
|
|
128
|
+
.DS_Store
|
|
129
|
+
.DS_Store?
|
|
130
|
+
._*
|
|
131
|
+
.Spotlight-V100
|
|
132
|
+
.Trashes
|
|
133
|
+
ehthumbs.db
|
|
134
|
+
Thumbs.db
|
|
135
|
+
|
|
136
|
+
# Build directory
|
|
137
|
+
build/
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.21)
|
|
2
|
+
|
|
3
|
+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
|
|
4
|
+
include(DynamicVersion)
|
|
5
|
+
|
|
6
|
+
extract_version_string(
|
|
7
|
+
HEADER_FILE ${CMAKE_CURRENT_LIST_DIR}/include/stb.h
|
|
8
|
+
VERSION_PREFIX LIBSTB_
|
|
9
|
+
OUTPUT_VAR PROJECT_VERSION
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
project(libstb LANGUAGES CXX VERSION ${PROJECT_VERSION})
|
|
13
|
+
message(STATUS "Project: ${PROJECT_NAME}@v${PROJECT_VERSION}")
|
|
14
|
+
include(Startup)
|
|
15
|
+
|
|
16
|
+
set(CMAKE_CXX_STANDARD 17)
|
|
17
|
+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
18
|
+
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
19
|
+
|
|
20
|
+
include(Optimize)
|
|
21
|
+
|
|
22
|
+
option(LIBSTB_BUILD_TESTS "Build tests" ${PROJECT_IS_TOP_LEVEL})
|
|
23
|
+
option(LIBSTB_BUILD_PYTHON "Build Python bindings" ${PROJECT_IS_TOP_LEVEL})
|
|
24
|
+
|
|
25
|
+
# --- libstb C++ core ---
|
|
26
|
+
# stb headers are vendored (committed) under src/third_party/stb and are only
|
|
27
|
+
# ever included from src/core/*.cpp, never from a public include/ header.
|
|
28
|
+
# STATIC (unlike httpp's SHARED core): stb is header-only, so there is nothing
|
|
29
|
+
# to gain from a DLL, and each stb header is compiled with STB_*_STATIC so no
|
|
30
|
+
# stbi_* symbol leaks out to consumers.
|
|
31
|
+
file(GLOB LIBSTB_CORE_SOURCES CONFIGURE_DEPENDS ${PROJECT_SOURCE_DIR}/src/core/*.cpp)
|
|
32
|
+
|
|
33
|
+
add_library(libstb_core STATIC ${LIBSTB_CORE_SOURCES})
|
|
34
|
+
add_library(libstb::core ALIAS libstb_core)
|
|
35
|
+
|
|
36
|
+
set_target_properties(libstb_core PROPERTIES
|
|
37
|
+
POSITION_INDEPENDENT_CODE ON # linked into the Python extension
|
|
38
|
+
CXX_VISIBILITY_PRESET hidden
|
|
39
|
+
VISIBILITY_INLINES_HIDDEN ON
|
|
40
|
+
EXPORT_NAME core # consumers link libstb::core
|
|
41
|
+
OUTPUT_NAME stb_core # libstb_core.a / stb_core.lib
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
# Install layout: the wheel carries include/, lib/ and cmake/ inside the
|
|
45
|
+
# `libstb` package (httpp's pattern, see get_cmake_dir() in the Python
|
|
46
|
+
# package); a plain `cmake --install` uses the usual prefix layout.
|
|
47
|
+
if(DEFINED SKBUILD)
|
|
48
|
+
set(_libstb_lib_dest libstb/lib)
|
|
49
|
+
set(_libstb_inc_dest libstb/include)
|
|
50
|
+
set(_libstb_cmake_dest libstb/cmake)
|
|
51
|
+
else()
|
|
52
|
+
set(_libstb_lib_dest lib)
|
|
53
|
+
set(_libstb_inc_dest include)
|
|
54
|
+
set(_libstb_cmake_dest lib/cmake/libstb)
|
|
55
|
+
endif()
|
|
56
|
+
|
|
57
|
+
target_include_directories(libstb_core
|
|
58
|
+
PUBLIC
|
|
59
|
+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
|
|
60
|
+
$<INSTALL_INTERFACE:${_libstb_inc_dest}>
|
|
61
|
+
)
|
|
62
|
+
# SYSTEM: vendored headers we don't control - their internal warnings are not
|
|
63
|
+
# ours to fix under our own -Wall/-Wextra/-W4.
|
|
64
|
+
target_include_directories(libstb_core SYSTEM PRIVATE ${PROJECT_SOURCE_DIR}/src/third_party/stb)
|
|
65
|
+
|
|
66
|
+
target_compile_options(libstb_core PRIVATE
|
|
67
|
+
$<$<CXX_COMPILER_ID:MSVC>:/W4 /EHsc>
|
|
68
|
+
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Wpedantic>
|
|
69
|
+
)
|
|
70
|
+
apply_optimization_flags(libstb_core)
|
|
71
|
+
|
|
72
|
+
# --- install (find_package(libstb) -> libstb::core) ---
|
|
73
|
+
include(CMakePackageConfigHelpers)
|
|
74
|
+
install(TARGETS libstb_core EXPORT libstbTargets ARCHIVE DESTINATION ${_libstb_lib_dest})
|
|
75
|
+
install(DIRECTORY include/ DESTINATION ${_libstb_inc_dest})
|
|
76
|
+
install(EXPORT libstbTargets FILE libstbTargets.cmake NAMESPACE libstb:: DESTINATION ${_libstb_cmake_dest})
|
|
77
|
+
configure_package_config_file(
|
|
78
|
+
${PROJECT_SOURCE_DIR}/cmake/libstbConfig.cmake.in
|
|
79
|
+
${PROJECT_BINARY_DIR}/libstbConfig.cmake
|
|
80
|
+
INSTALL_DESTINATION ${_libstb_cmake_dest}
|
|
81
|
+
)
|
|
82
|
+
write_basic_package_version_file(
|
|
83
|
+
${PROJECT_BINARY_DIR}/libstbConfigVersion.cmake
|
|
84
|
+
VERSION ${PROJECT_VERSION}
|
|
85
|
+
COMPATIBILITY SameMajorVersion
|
|
86
|
+
)
|
|
87
|
+
install(FILES
|
|
88
|
+
${PROJECT_BINARY_DIR}/libstbConfig.cmake
|
|
89
|
+
${PROJECT_BINARY_DIR}/libstbConfigVersion.cmake
|
|
90
|
+
DESTINATION ${_libstb_cmake_dest}
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
if(LIBSTB_BUILD_PYTHON OR DEFINED SKBUILD)
|
|
94
|
+
set(PYTHON_INSTALL_DIR ${CMAKE_BINARY_DIR}/python/install)
|
|
95
|
+
add_subdirectory(${PROJECT_SOURCE_DIR}/src/bindings/python)
|
|
96
|
+
if(DEFINED SKBUILD)
|
|
97
|
+
return()
|
|
98
|
+
endif()
|
|
99
|
+
endif()
|
|
100
|
+
|
|
101
|
+
if(LIBSTB_BUILD_TESTS)
|
|
102
|
+
enable_testing()
|
|
103
|
+
set(CMAKE_CTEST_ARGUMENTS "--output-on-failure" "-V")
|
|
104
|
+
add_subdirectory(${PROJECT_SOURCE_DIR}/tests)
|
|
105
|
+
endif()
|
libstb-0.3.0/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Mohammad Raziei
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
libstb-0.3.0/PKG-INFO
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: libstb
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Python bindings for the stb single-header libraries (image io, resize, fonts). Zero system dependencies.
|
|
5
|
+
Author-Email: Mohammad Raziei <mohammadraziei1375@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Classifier: Development Status :: 3 - Alpha
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Classifier: Programming Language :: C++
|
|
11
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Project-URL: Homepage, https://github.com/MohammadRaziei/libstb
|
|
19
|
+
Project-URL: Bug Tracker, https://github.com/MohammadRaziei/libstb/issues
|
|
20
|
+
Requires-Python: >=3.9
|
|
21
|
+
Requires-Dist: numpy
|
|
22
|
+
Provides-Extra: test
|
|
23
|
+
Requires-Dist: pytest; extra == "test"
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# libstb
|
|
27
|
+
|
|
28
|
+
Python bindings for the [stb](https://github.com/nothings/stb) single-header
|
|
29
|
+
libraries. `pip install libstb` and you have image/font processing with **no
|
|
30
|
+
system dependencies**. The C++ library is usable from CMake too.
|
|
31
|
+
|
|
32
|
+
| module | status |
|
|
33
|
+
| :--- | :--- |
|
|
34
|
+
| `stb_image` (read) | done |
|
|
35
|
+
| `stb_image_write` (write: png, jpg, bmp, tga) | done |
|
|
36
|
+
| `stb_image_resize2` (resize) | done |
|
|
37
|
+
| `stb_truetype` (fonts: metrics, glyphs, text, atlas) | done |
|
|
38
|
+
| `stb_rect_pack` | used internally by the atlas packer |
|
|
39
|
+
|
|
40
|
+
## Python
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
import numpy as np
|
|
44
|
+
import libstb
|
|
45
|
+
|
|
46
|
+
img = libstb.Image.open("photo.png") # or bytes; also: channels=4, flip=True
|
|
47
|
+
img.width, img.height, img.channels # 640, 480, 3
|
|
48
|
+
img.numpy() # uint8 pixels (H, W, C), no copy; np.asarray(img) works too
|
|
49
|
+
libstb.ImageInfo.read("photo.png") # header only: (width, height, channels)
|
|
50
|
+
libstb.Image(np.zeros((8, 8, 4), np.uint8)) # from your own uint8 array (no copy, see below)
|
|
51
|
+
img.copy() # an independent image (deep copy)
|
|
52
|
+
|
|
53
|
+
img.write("out.jpg") # format from the extension, default settings
|
|
54
|
+
img.write_jpg("out.jpg", quality=80) # or pick the format and its settings
|
|
55
|
+
data = img.to_png(compression=9) # -> bytes (to_png / to_jpg / to_bmp / to_tga)
|
|
56
|
+
|
|
57
|
+
small = img.resize(320, 240) # new Image; default Resizer()
|
|
58
|
+
small = img.resize(320, 240, "cubic") # filter by name (see the table below)
|
|
59
|
+
libstb.Resizer("cubic") # same name works on Resizer itself
|
|
60
|
+
libstb.Resizer(libstb.Resizer.Filter.MITCHELL, libstb.Resizer.Edge.WRAP, srgb=False)
|
|
61
|
+
img.resize(320, 240, libstb.Resizer("linear", srgb=False)) # name + other options
|
|
62
|
+
|
|
63
|
+
font = libstb.Font.open("font.ttf") # trusted fonts only, see below
|
|
64
|
+
text = font.render("Hello\nworld", 32) # RenderedText(bitmap: Image (1 channel), origin_x, origin_y)
|
|
65
|
+
text.bitmap.write("hello.png")
|
|
66
|
+
font.metrics(32), font.advance("A", 32), font.kerning("A", "V", 32), font.measure("Hello", 32)
|
|
67
|
+
font.render_glyph("A", 32) # Glyph(bitmap, x_offset, y_offset, advance)
|
|
68
|
+
atlas = font.make_atlas("ABCabc123", 32, 256, 256) # Atlas: .image and atlas["A"] -> AtlasGlyph
|
|
69
|
+
|
|
70
|
+
libstb.load("photo.png") # shortcut: Image.open(...).array
|
|
71
|
+
libstb.info("photo.png") # shortcut: ImageInfo.read(...)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
**Encoding.** Every format has a pair of methods with its own settings, all
|
|
75
|
+
defaulted: `to_png(compression=8)`, `to_jpg(quality=90)`, `to_bmp()`,
|
|
76
|
+
`to_tga(rle=True)` return the file's bytes, and `write_png(path, ...)`,
|
|
77
|
+
`write_jpg(path, ...)`, `write_bmp(path)`, `write_tga(path, ...)` do the same
|
|
78
|
+
and write it (only after encoding succeeded, so a failure never leaves a
|
|
79
|
+
truncated file). `write(path)` is the shortcut: it picks the format from the
|
|
80
|
+
extension (`.png .jpg .jpeg .bmp .tga`, case-insensitive; `ValueError` for
|
|
81
|
+
anything else) and uses the defaults. For other settings call `write_*`.
|
|
82
|
+
|
|
83
|
+
**Resize filters by name.** `Image.resize(w, h, x)` and `Resizer(x)` accept a
|
|
84
|
+
`Resizer.Filter`, or a case-insensitive name (`-` and space count as `_`). Any
|
|
85
|
+
other option (`edge`, `srgb`, `max_bytes`) is a keyword of `Resizer(...)`.
|
|
86
|
+
`Image.resize` also takes a ready-made `Resizer`, or `None` for the default.
|
|
87
|
+
|
|
88
|
+
| name | filter | note |
|
|
89
|
+
| :--- | :--- | :--- |
|
|
90
|
+
| `auto`, `automatic`, `default` | `DEFAULT` | Catmull-Rom when enlarging, Mitchell when shrinking |
|
|
91
|
+
| `nearest`, `point` | `POINT` | nearest neighbour |
|
|
92
|
+
| `linear`, `bilinear`, `triangle` | `TRIANGLE` | |
|
|
93
|
+
| `cubic`, `bicubic`, `catmull_rom` | `CATMULL_ROM` | sharp; the PIL/OpenCV meaning of "cubic" |
|
|
94
|
+
| `bspline`, `cubic_bspline` | `CUBIC_BSPLINE` | smooth, slightly blurry; scipy's meaning of "cubic" |
|
|
95
|
+
| `mitchell` | `MITCHELL` | good all-round compromise |
|
|
96
|
+
| `box`, `area` | `BOX` | |
|
|
97
|
+
|
|
98
|
+
An unknown name raises `ValueError` listing the valid ones. There is no
|
|
99
|
+
`lanczos`: stb_image_resize2 does not have it.
|
|
100
|
+
|
|
101
|
+
**Fonts: trusted files only.** stb_truetype does no bounds checking; its
|
|
102
|
+
author writes "NO SECURITY GUARANTEE -- DO NOT USE THIS ON UNTRUSTED FONT
|
|
103
|
+
FILES". Load your own or vetted system fonts, never user uploads. (Images are
|
|
104
|
+
different: `stb_image` is fuzzed, and libstb adds dimension and size limits.)
|
|
105
|
+
|
|
106
|
+
Errors mirror the C++ hierarchy: `libstb.Error` (a `RuntimeError`) with
|
|
107
|
+
`DecodeError`, `EncodeError`, `LimitError` below it, so a single
|
|
108
|
+
`except libstb.Error` catches every libstb failure. Bad arguments raise
|
|
109
|
+
`ValueError`, unreadable files `OSError` (`FileNotFoundError`, `PermissionError`,
|
|
110
|
+
... as the OS says). Images whose decoded size would
|
|
111
|
+
exceed `max_bytes` (default 512 MiB) are rejected from the header, before any
|
|
112
|
+
pixel memory is allocated.
|
|
113
|
+
|
|
114
|
+
`libstb.Image` is `stb::image` itself, not a wrapper: `open`, `resize`, `to_*` and
|
|
115
|
+
`write*` are the C++ members, run without the GIL. `img.array` / `np.asarray(img)`
|
|
116
|
+
are numpy views of its pixels (kept alive by the view).
|
|
117
|
+
|
|
118
|
+
Pixels are never copied behind your back. `Image(array)` uses a writable,
|
|
119
|
+
C-contiguous uint8 array in place, so the image and the array share their
|
|
120
|
+
pixels (changes show on both sides, and the image keeps the array alive). Any
|
|
121
|
+
other array (read-only, or strided like `arr[::-1]`) cannot be shared and is
|
|
122
|
+
copied. `Image.open` takes ownership of stb's own buffer, no copy either. When
|
|
123
|
+
you want an independent image, say so: `img.copy()` (also `copy.copy` and
|
|
124
|
+
`copy.deepcopy`).
|
|
125
|
+
|
|
126
|
+
## C++ / CMake
|
|
127
|
+
|
|
128
|
+
```cmake
|
|
129
|
+
# after `pip install libstb`
|
|
130
|
+
execute_process(COMMAND ${Python3_EXECUTABLE} -c "import libstb; print(libstb.get_cmake_dir())"
|
|
131
|
+
OUTPUT_VARIABLE libstb_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
132
|
+
find_package(libstb CONFIG REQUIRED)
|
|
133
|
+
target_link_libraries(app PRIVATE libstb::core)
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
The C++ namespace and headers are `stb` (`<stb.h>`, `<stb/*.hpp>`); the CMake
|
|
137
|
+
target (`libstb::core`) and the Python package (`libstb`) keep the project name.
|
|
138
|
+
|
|
139
|
+
```cpp
|
|
140
|
+
#include <stb.h>
|
|
141
|
+
|
|
142
|
+
stb::image img = stb::image::open("in.png"); // throws stb::error subclasses
|
|
143
|
+
img(0, 0, 1) = 255; // unchecked pixel access
|
|
144
|
+
stb::image dup = img.copy(); // image is move-only: copies are explicit
|
|
145
|
+
img.write("out.jpg"); // format from the extension, default settings
|
|
146
|
+
img.write_jpg("out.jpg", 80); // or pick the format and its settings
|
|
147
|
+
std::vector<std::uint8_t> bytes = img.to_png(9); // to_png / to_jpg / to_bmp / to_tga -> file bytes
|
|
148
|
+
|
|
149
|
+
stb::image small = img.resize(320, 240); // default resizer
|
|
150
|
+
stb::image crisp = img.resize(320, 240, "cubic"); // filter by name, or by enum:
|
|
151
|
+
stb::image soft = img.resize(320, 240, stb::resize_filter::mitchell);
|
|
152
|
+
|
|
153
|
+
stb::resize_options o; // full control: filter, edge, srgb, max_bytes
|
|
154
|
+
o.edge = stb::resize_edge::wrap;
|
|
155
|
+
stb::resizer r(o); // also: resizer("cubic"), resizer(resize_filter::box)
|
|
156
|
+
stb::image tile = img.resize(320, 240, &r); // nullptr = default resizer; r.resize(img, w, h) works too
|
|
157
|
+
|
|
158
|
+
stb::font f = stb::font::open("font.ttf"); // cheap to copy, thread-safe
|
|
159
|
+
stb::text_bitmap t = f.render("h\xC3\xA9llo", 32); // UTF-8 in, 1-channel image out
|
|
160
|
+
stb::atlas atlas = f.make_atlas(U"abc", 32, 256, 256);
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Design: stb never appears in a public header. Where a class would hold stb
|
|
164
|
+
state, it is hidden behind a pimpl: `font` keeps the font bytes and the
|
|
165
|
+
`stbtt_fontinfo` in an opaque `font::impl` (shared and immutable, so copies are
|
|
166
|
+
cheap and threads can share one). `image` and `resizer` carry no stb state at
|
|
167
|
+
all (plain ints/enums), so a pimpl there would only add indirection. `image` is
|
|
168
|
+
move-only: its pixels are a `shared_ptr<uint8_t>` whose deleter (or aliased
|
|
169
|
+
owner) decides who frees them, so the same class holds memory it allocated,
|
|
170
|
+
stb's decode buffer (adopted, not copied) or memory somebody else owns
|
|
171
|
+
(`image::wrap`, which is how a numpy array becomes an image without a copy).
|
|
172
|
+
A copy is always spelled `copy()`. The four output formats are a closed set, so there
|
|
173
|
+
is no encoder class hierarchy: each format is a `to_*` / `write_*` pair on
|
|
174
|
+
`image` with its own defaulted settings, next to decoding in `src/core/image.cpp`.
|
|
175
|
+
Runtime failures derive from
|
|
176
|
+
`stb::error` (`decode_error`, `encode_error`, `limit_error`, `io_error`);
|
|
177
|
+
programmer errors throw `std::invalid_argument`.
|
|
178
|
+
|
|
179
|
+
Or `cmake --install build` and `find_package(libstb)` as usual.
|
|
180
|
+
|
|
181
|
+
## Layout (mirrors httpp / ctoon)
|
|
182
|
+
|
|
183
|
+
```
|
|
184
|
+
include/stb.h umbrella header, owns LIBSTB_VERSION_* (single source of truth)
|
|
185
|
+
include/stb/*.hpp public API (error, image, resizer, font, utf8); never includes stb
|
|
186
|
+
src/core/*.cpp implementation; the only place stb headers are compiled
|
|
187
|
+
src/third_party/stb/ vendored stb headers (committed, no submodules)
|
|
188
|
+
src/bindings/python/ nanobind module (bind_*.cpp, one per area) + the `libstb` Python package
|
|
189
|
+
cmake/ DynamicVersion, Startup, Optimize, package config
|
|
190
|
+
tests/{cpp,python,cmake} unit tests + find_package consumer test, all run by ctest
|
|
191
|
+
tests/data/ synthetic test font (solid-rectangle glyphs) + the script that makes it
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
Each stb header is compiled with `STB_*_STATIC`, so no `stbi_*` symbol leaks
|
|
195
|
+
from `libstb_core`: it links fine next to your own copy of stb.
|
|
196
|
+
|
|
197
|
+
## Build & test
|
|
198
|
+
|
|
199
|
+
```sh
|
|
200
|
+
pip install -r requirements-dev.txt
|
|
201
|
+
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
|
|
202
|
+
cmake --build build
|
|
203
|
+
ctest --test-dir build --output-on-failure
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Wheels: abi3 (`cp312-abi3`, covers 3.12+) plus one wheel each for cp39-cp311;
|
|
207
|
+
see `.github/workflows/wheels.yml`. Free-threaded builds are not supported.
|
|
208
|
+
|
|
209
|
+
## License
|
|
210
|
+
|
|
211
|
+
MIT for libstb. The vendored stb headers are MIT / public domain (see
|
|
212
|
+
`src/third_party/README.md`).
|