mirror of
https://github.com/python-pillow/Pillow.git
synced 2026-02-21 22:50:28 +03:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5158d98c80 | ||
|
|
9000313cc5 | ||
|
|
cd0111849f |
|
|
@ -53,7 +53,7 @@ pushd depends && ./install_imagequant.sh && popd
|
|||
pushd depends && sudo ./install_raqm.sh && popd
|
||||
|
||||
# libavif
|
||||
pushd depends && ./install_libavif.sh && popd
|
||||
pushd depends && sudo ./install_libavif.sh && popd
|
||||
|
||||
# extra test images
|
||||
pushd depends && ./install_extra_test_images.sh && popd
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
cibuildwheel==3.3.1
|
||||
cibuildwheel==3.3.0
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
mypy==1.19.1
|
||||
mypy==1.19.0
|
||||
arro3-compute
|
||||
arro3-core
|
||||
IceSpringPySideStubs-PyQt6
|
||||
|
|
@ -9,6 +9,7 @@ packaging
|
|||
pyarrow-stubs
|
||||
pybind11
|
||||
pytest
|
||||
sphinx
|
||||
types-atheris
|
||||
types-defusedxml
|
||||
types-olefile
|
||||
|
|
|
|||
1
.github/renovate.json
vendored
1
.github/renovate.json
vendored
|
|
@ -6,7 +6,6 @@
|
|||
"labels": [
|
||||
"Dependency"
|
||||
],
|
||||
"minimumReleaseAge": "7 days",
|
||||
"packageRules": [
|
||||
{
|
||||
"groupName": "github-actions",
|
||||
|
|
|
|||
4
.github/workflows/cifuzz.yml
vendored
4
.github/workflows/cifuzz.yml
vendored
|
|
@ -44,13 +44,13 @@ jobs:
|
|||
language: python
|
||||
dry-run: false
|
||||
- name: Upload New Crash
|
||||
uses: actions/upload-artifact@v6
|
||||
uses: actions/upload-artifact@v5
|
||||
if: failure() && steps.build.outcome == 'success'
|
||||
with:
|
||||
name: artifacts
|
||||
path: ./out/artifacts
|
||||
- name: Upload Legacy Crash
|
||||
uses: actions/upload-artifact@v6
|
||||
uses: actions/upload-artifact@v5
|
||||
if: steps.run.outcome == 'success'
|
||||
with:
|
||||
name: crash
|
||||
|
|
|
|||
18
.github/workflows/docs.yml
vendored
18
.github/workflows/docs.yml
vendored
|
|
@ -48,35 +48,19 @@ jobs:
|
|||
- name: Build system information
|
||||
run: python3 .github/workflows/system-info.py
|
||||
|
||||
- name: Cache libavif
|
||||
uses: actions/cache@v5
|
||||
id: cache-libavif
|
||||
with:
|
||||
path: ~/cache-libavif
|
||||
key: ${{ runner.os }}-libavif-${{ hashFiles('depends/install_libavif.sh', 'depends/libavif-svt4.patch') }}
|
||||
|
||||
- name: Cache libimagequant
|
||||
uses: actions/cache@v5
|
||||
uses: actions/cache@v4
|
||||
id: cache-libimagequant
|
||||
with:
|
||||
path: ~/cache-libimagequant
|
||||
key: ${{ runner.os }}-libimagequant-${{ hashFiles('depends/install_imagequant.sh') }}
|
||||
|
||||
- name: Cache libwebp
|
||||
uses: actions/cache@v5
|
||||
id: cache-libwebp
|
||||
with:
|
||||
path: ~/cache-libwebp
|
||||
key: ${{ runner.os }}-libwebp-${{ hashFiles('depends/install_webp.sh') }}
|
||||
|
||||
- name: Install Linux dependencies
|
||||
run: |
|
||||
.ci/install.sh
|
||||
env:
|
||||
GHA_PYTHON_VERSION: "3.x"
|
||||
GHA_LIBAVIF_CACHE_HIT: ${{ steps.cache-libavif.outputs.cache-hit }}
|
||||
GHA_LIBIMAGEQUANT_CACHE_HIT: ${{ steps.cache-libimagequant.outputs.cache-hit }}
|
||||
GHA_LIBWEBP_CACHE_HIT: ${{ steps.cache-libwebp.outputs.cache-hit }}
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
|
|
|
|||
2
.github/workflows/lint.yml
vendored
2
.github/workflows/lint.yml
vendored
|
|
@ -23,7 +23,7 @@ jobs:
|
|||
persist-credentials: false
|
||||
- uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: "3.x"
|
||||
python-version: "3.10"
|
||||
- name: Install uv
|
||||
uses: astral-sh/setup-uv@v7
|
||||
- name: Lint
|
||||
|
|
|
|||
2
.github/workflows/test-docker.yml
vendored
2
.github/workflows/test-docker.yml
vendored
|
|
@ -83,7 +83,7 @@ jobs:
|
|||
|
||||
- name: Docker pull
|
||||
run: |
|
||||
docker pull ${{ matrix.qemu-arch && format('--platform=linux/{0}', matrix.qemu-arch)}} pythonpillow/${{ matrix.docker }}:${{ matrix.dockerTag }}
|
||||
docker pull pythonpillow/${{ matrix.docker }}:${{ matrix.dockerTag }}
|
||||
|
||||
- name: Docker build
|
||||
run: |
|
||||
|
|
|
|||
11
.github/workflows/test-windows.yml
vendored
11
.github/workflows/test-windows.yml
vendored
|
|
@ -112,7 +112,7 @@ jobs:
|
|||
|
||||
- name: Cache build
|
||||
id: build-cache
|
||||
uses: actions/cache@v5
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: winbuild\build
|
||||
key:
|
||||
|
|
@ -188,9 +188,8 @@ jobs:
|
|||
# trim ~150MB for each job
|
||||
- name: Optimize build cache
|
||||
if: steps.build-cache.outputs.cache-hit != 'true'
|
||||
run: |
|
||||
rm -rf winbuild\build\src
|
||||
shell: bash
|
||||
run: rmdir /S /Q winbuild\build\src
|
||||
shell: cmd
|
||||
|
||||
- name: Build Pillow
|
||||
run: |
|
||||
|
|
@ -207,7 +206,9 @@ jobs:
|
|||
|
||||
- name: Test Pillow
|
||||
run: |
|
||||
path %GITHUB_WORKSPACE%\winbuild\build\bin;%PATH%
|
||||
.ci\test.cmd
|
||||
shell: cmd
|
||||
|
||||
- name: Prepare to upload errors
|
||||
if: failure()
|
||||
|
|
@ -216,7 +217,7 @@ jobs:
|
|||
shell: bash
|
||||
|
||||
- name: Upload errors
|
||||
uses: actions/upload-artifact@v6
|
||||
uses: actions/upload-artifact@v5
|
||||
if: failure()
|
||||
with:
|
||||
name: errors
|
||||
|
|
|
|||
23
.github/workflows/test.yml
vendored
23
.github/workflows/test.yml
vendored
|
|
@ -29,7 +29,6 @@ concurrency:
|
|||
env:
|
||||
COVERAGE_CORE: sysmon
|
||||
FORCE_COLOR: 1
|
||||
PIP_DISABLE_PIP_VERSION_CHECK: 1
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
|
@ -91,39 +90,21 @@ jobs:
|
|||
- name: Build system information
|
||||
run: python3 .github/workflows/system-info.py
|
||||
|
||||
- name: Cache libavif
|
||||
if: startsWith(matrix.os, 'ubuntu')
|
||||
uses: actions/cache@v5
|
||||
id: cache-libavif
|
||||
with:
|
||||
path: ~/cache-libavif
|
||||
key: ${{ runner.os }}-libavif-${{ hashFiles('depends/install_libavif.sh', 'depends/libavif-svt4.patch') }}
|
||||
|
||||
- name: Cache libimagequant
|
||||
if: startsWith(matrix.os, 'ubuntu')
|
||||
uses: actions/cache@v5
|
||||
uses: actions/cache@v4
|
||||
id: cache-libimagequant
|
||||
with:
|
||||
path: ~/cache-libimagequant
|
||||
key: ${{ runner.os }}-libimagequant-${{ hashFiles('depends/install_imagequant.sh') }}
|
||||
|
||||
- name: Cache libwebp
|
||||
if: startsWith(matrix.os, 'ubuntu')
|
||||
uses: actions/cache@v5
|
||||
id: cache-libwebp
|
||||
with:
|
||||
path: ~/cache-libwebp
|
||||
key: ${{ runner.os }}-libwebp-${{ hashFiles('depends/install_webp.sh') }}
|
||||
|
||||
- name: Install Linux dependencies
|
||||
if: startsWith(matrix.os, 'ubuntu')
|
||||
run: |
|
||||
.ci/install.sh
|
||||
env:
|
||||
GHA_PYTHON_VERSION: ${{ matrix.python-version }}
|
||||
GHA_LIBAVIF_CACHE_HIT: ${{ steps.cache-libavif.outputs.cache-hit }}
|
||||
GHA_LIBIMAGEQUANT_CACHE_HIT: ${{ steps.cache-libimagequant.outputs.cache-hit }}
|
||||
GHA_LIBWEBP_CACHE_HIT: ${{ steps.cache-libwebp.outputs.cache-hit }}
|
||||
|
||||
- name: Install macOS dependencies
|
||||
if: startsWith(matrix.os, 'macOS')
|
||||
|
|
@ -162,7 +143,7 @@ jobs:
|
|||
mkdir -p Tests/errors
|
||||
|
||||
- name: Upload errors
|
||||
uses: actions/upload-artifact@v6
|
||||
uses: actions/upload-artifact@v5
|
||||
if: failure()
|
||||
with:
|
||||
name: errors
|
||||
|
|
|
|||
10
.github/workflows/wheels-dependencies.sh
vendored
10
.github/workflows/wheels-dependencies.sh
vendored
|
|
@ -95,15 +95,15 @@ if [[ -n "$IOS_SDK" ]]; then
|
|||
else
|
||||
FREETYPE_VERSION=2.14.1
|
||||
fi
|
||||
HARFBUZZ_VERSION=12.3.2
|
||||
LIBPNG_VERSION=1.6.54
|
||||
HARFBUZZ_VERSION=12.3.0
|
||||
LIBPNG_VERSION=1.6.53
|
||||
JPEGTURBO_VERSION=3.1.3
|
||||
OPENJPEG_VERSION=2.5.4
|
||||
XZ_VERSION=5.8.2
|
||||
ZSTD_VERSION=1.5.7
|
||||
TIFF_VERSION=4.7.1
|
||||
LCMS2_VERSION=2.18
|
||||
ZLIB_NG_VERSION=2.3.3
|
||||
LCMS2_VERSION=2.17
|
||||
ZLIB_NG_VERSION=2.3.2
|
||||
LIBWEBP_VERSION=1.6.0
|
||||
BZIP2_VERSION=1.0.8
|
||||
LIBXCB_VERSION=1.17.0
|
||||
|
|
@ -267,7 +267,7 @@ function build {
|
|||
|
||||
build_simple xcb-proto 1.17.0 https://xorg.freedesktop.org/archive/individual/proto
|
||||
if [[ -n "$IS_MACOS" ]]; then
|
||||
build_simple xorgproto 2025.1 https://www.x.org/pub/individual/proto
|
||||
build_simple xorgproto 2024.1 https://www.x.org/pub/individual/proto
|
||||
build_simple libXau 1.0.12 https://www.x.org/pub/individual/lib
|
||||
build_simple libpthread-stubs 0.5 https://xcb.freedesktop.org/dist
|
||||
else
|
||||
|
|
|
|||
48
.github/workflows/wheels.yml
vendored
48
.github/workflows/wheels.yml
vendored
|
|
@ -134,7 +134,7 @@ jobs:
|
|||
CIBW_MANYLINUX_X86_64_IMAGE: ${{ matrix.manylinux }}
|
||||
MACOSX_DEPLOYMENT_TARGET: ${{ matrix.macosx_deployment_target }}
|
||||
|
||||
- uses: actions/upload-artifact@v6
|
||||
- uses: actions/upload-artifact@v5
|
||||
with:
|
||||
name: dist-${{ matrix.name }}
|
||||
path: ./wheelhouse/*.whl
|
||||
|
|
@ -186,18 +186,24 @@ jobs:
|
|||
|
||||
- name: Build wheels
|
||||
run: |
|
||||
for f in winbuild/build/license/*; do
|
||||
name=$(basename "${f%.*}")
|
||||
# Skip FriBiDi license, it is not included in the wheel.
|
||||
[[ $name == fribidi* ]] && continue
|
||||
# Skip imagequant license, it is not included in the wheel.
|
||||
[[ $name == libimagequant* ]] && continue
|
||||
echo "" >> LICENSE
|
||||
echo "===== $name =====" >> LICENSE
|
||||
echo "" >> LICENSE
|
||||
cat "$f" >> LICENSE
|
||||
done
|
||||
cmd //c "winbuild\\build\\build_env.cmd && $pythonLocation\\python.exe -m cibuildwheel . --output-dir wheelhouse"
|
||||
setlocal EnableDelayedExpansion
|
||||
for %%f in (winbuild\build\license\*) do (
|
||||
set x=%%~nf
|
||||
rem Skip FriBiDi license, it is not included in the wheel.
|
||||
set fribidi=!x:~0,7!
|
||||
if NOT !fribidi!==fribidi (
|
||||
rem Skip imagequant license, it is not included in the wheel.
|
||||
set libimagequant=!x:~0,13!
|
||||
if NOT !libimagequant!==libimagequant (
|
||||
echo. >> LICENSE
|
||||
echo ===== %%~nf ===== >> LICENSE
|
||||
echo. >> LICENSE
|
||||
type %%f >> LICENSE
|
||||
)
|
||||
)
|
||||
)
|
||||
call winbuild\\build\\build_env.cmd
|
||||
%pythonLocation%\python.exe -m cibuildwheel . --output-dir wheelhouse
|
||||
env:
|
||||
CIBW_ARCHS: ${{ matrix.cibw_arch }}
|
||||
CIBW_BEFORE_ALL: "{package}\\winbuild\\build\\build_dep_all.cmd"
|
||||
|
|
@ -211,16 +217,16 @@ jobs:
|
|||
-e CI -e GITHUB_ACTIONS
|
||||
mcr.microsoft.com/windows/servercore:ltsc2022
|
||||
powershell C:\pillow\.github\workflows\wheels-test.ps1 %CD%\..\venv-test'
|
||||
shell: bash
|
||||
shell: cmd
|
||||
|
||||
- name: Upload wheels
|
||||
uses: actions/upload-artifact@v6
|
||||
uses: actions/upload-artifact@v5
|
||||
with:
|
||||
name: dist-windows-${{ matrix.cibw_arch }}
|
||||
path: ./wheelhouse/*.whl
|
||||
|
||||
- name: Upload fribidi.dll
|
||||
uses: actions/upload-artifact@v6
|
||||
uses: actions/upload-artifact@v5
|
||||
with:
|
||||
name: fribidi-windows-${{ matrix.cibw_arch }}
|
||||
path: winbuild\build\bin\fribidi*
|
||||
|
|
@ -240,7 +246,7 @@ jobs:
|
|||
|
||||
- run: make sdist
|
||||
|
||||
- uses: actions/upload-artifact@v6
|
||||
- uses: actions/upload-artifact@v5
|
||||
with:
|
||||
name: dist-sdist
|
||||
path: dist/*.tar.gz
|
||||
|
|
@ -250,7 +256,7 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
name: Count dists
|
||||
steps:
|
||||
- uses: actions/download-artifact@v7
|
||||
- uses: actions/download-artifact@v6
|
||||
with:
|
||||
pattern: dist-*
|
||||
path: dist
|
||||
|
|
@ -269,13 +275,13 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
name: Upload wheels to scientific-python-nightly-wheels
|
||||
steps:
|
||||
- uses: actions/download-artifact@v7
|
||||
- uses: actions/download-artifact@v6
|
||||
with:
|
||||
pattern: dist-!(sdist)*
|
||||
path: dist
|
||||
merge-multiple: true
|
||||
- name: Upload wheels to scientific-python-nightly-wheels
|
||||
uses: scientific-python/upload-nightly-action@5748273c71e2d8d3a61f3a11a16421c8954f9ecf # 0.6.3
|
||||
uses: scientific-python/upload-nightly-action@b36e8c0c10dbcfd2e05bf95f17ef8c14fd708dbf # 0.6.2
|
||||
with:
|
||||
artifacts_path: dist
|
||||
anaconda_nightly_upload_token: ${{ secrets.ANACONDA_ORG_UPLOAD_TOKEN }}
|
||||
|
|
@ -291,7 +297,7 @@ jobs:
|
|||
permissions:
|
||||
id-token: write
|
||||
steps:
|
||||
- uses: actions/download-artifact@v7
|
||||
- uses: actions/download-artifact@v6
|
||||
with:
|
||||
pattern: dist-*
|
||||
path: dist
|
||||
|
|
|
|||
2
.github/zizmor.yml
vendored
2
.github/zizmor.yml
vendored
|
|
@ -1,5 +1,7 @@
|
|||
# https://docs.zizmor.sh/configuration/
|
||||
rules:
|
||||
obfuscation:
|
||||
disable: true
|
||||
unpinned-uses:
|
||||
config:
|
||||
policies:
|
||||
|
|
|
|||
|
|
@ -1,30 +1,30 @@
|
|||
repos:
|
||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||
rev: v0.14.14
|
||||
rev: v0.14.7
|
||||
hooks:
|
||||
- id: ruff-check
|
||||
args: [--exit-non-zero-on-fix]
|
||||
|
||||
- repo: https://github.com/psf/black-pre-commit-mirror
|
||||
rev: 26.1.0
|
||||
rev: 25.11.0
|
||||
hooks:
|
||||
- id: black
|
||||
|
||||
- repo: https://github.com/PyCQA/bandit
|
||||
rev: 1.9.3
|
||||
rev: 1.9.2
|
||||
hooks:
|
||||
- id: bandit
|
||||
args: [--severity-level=high]
|
||||
files: ^src/
|
||||
|
||||
- repo: https://github.com/Lucas-C/pre-commit-hooks
|
||||
rev: v1.5.6
|
||||
rev: v1.5.5
|
||||
hooks:
|
||||
- id: remove-tabs
|
||||
exclude: (Makefile$|\.bat$|\.cmake$|\.eps$|\.fits$|\.gd$|\.opt$)
|
||||
|
||||
- repo: https://github.com/pre-commit/mirrors-clang-format
|
||||
rev: v21.1.8
|
||||
rev: v21.1.6
|
||||
hooks:
|
||||
- id: clang-format
|
||||
types: [c]
|
||||
|
|
@ -51,14 +51,14 @@ repos:
|
|||
exclude: ^\.github/.*TEMPLATE|^Tests/(fonts|images)/
|
||||
|
||||
- repo: https://github.com/python-jsonschema/check-jsonschema
|
||||
rev: 0.36.1
|
||||
rev: 0.35.0
|
||||
hooks:
|
||||
- id: check-github-workflows
|
||||
- id: check-readthedocs
|
||||
- id: check-renovate
|
||||
|
||||
- repo: https://github.com/zizmorcore/zizmor-pre-commit
|
||||
rev: v1.22.0
|
||||
rev: v1.18.0
|
||||
hooks:
|
||||
- id: zizmor
|
||||
|
||||
|
|
@ -68,7 +68,7 @@ repos:
|
|||
- id: sphinx-lint
|
||||
|
||||
- repo: https://github.com/tox-dev/pyproject-fmt
|
||||
rev: v2.12.1
|
||||
rev: v2.11.1
|
||||
hooks:
|
||||
- id: pyproject-fmt
|
||||
|
||||
|
|
@ -76,10 +76,10 @@ repos:
|
|||
rev: v0.24.1
|
||||
hooks:
|
||||
- id: validate-pyproject
|
||||
additional_dependencies: [trove-classifiers>=2024.10.12]
|
||||
additional_dependencies: [tomli, trove-classifiers>=2024.10.12]
|
||||
|
||||
- repo: https://github.com/tox-dev/tox-ini-fmt
|
||||
rev: 1.7.1
|
||||
rev: 1.7.0
|
||||
hooks:
|
||||
- id: tox-ini-fmt
|
||||
|
||||
|
|
|
|||
Binary file not shown.
|
Before Width: | Height: | Size: 456 B |
Binary file not shown.
|
Before Width: | Height: | Size: 4.0 KiB |
|
|
@ -213,7 +213,7 @@ INT32 = DataShape(
|
|||
),
|
||||
)
|
||||
def test_fromarray(mode: str, data_tp: DataShape, mask: list[int] | None) -> None:
|
||||
dtype, elt, elts_per_pixel = data_tp
|
||||
(dtype, elt, elts_per_pixel) = data_tp
|
||||
|
||||
ct_pixels = TEST_IMAGE_SIZE[0] * TEST_IMAGE_SIZE[1]
|
||||
if dtype == fl_uint8_4_type:
|
||||
|
|
@ -239,7 +239,7 @@ def test_fromarray(mode: str, data_tp: DataShape, mask: list[int] | None) -> Non
|
|||
)
|
||||
@pytest.mark.parametrize("data_tp", (UINT32, INT32))
|
||||
def test_from_int32array(mode: str, mask: list[int] | None, data_tp: DataShape) -> None:
|
||||
dtype, elt, elts_per_pixel = data_tp
|
||||
(dtype, elt, elts_per_pixel) = data_tp
|
||||
|
||||
ct_pixels = TEST_IMAGE_SIZE[0] * TEST_IMAGE_SIZE[1]
|
||||
arr = Array([elt] * (ct_pixels * elts_per_pixel), type=dtype)
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ def test_multiblock_l_image() -> None:
|
|||
img = Image.new("L", size, 128)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
schema, arr = img.__arrow_c_array__()
|
||||
(schema, arr) = img.__arrow_c_array__()
|
||||
|
||||
|
||||
def test_multiblock_rgba_image() -> None:
|
||||
|
|
@ -79,7 +79,7 @@ def test_multiblock_rgba_image() -> None:
|
|||
img = Image.new("RGBA", size, (128, 127, 126, 125))
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
schema, arr = img.__arrow_c_array__()
|
||||
(schema, arr) = img.__arrow_c_array__()
|
||||
|
||||
|
||||
def test_multiblock_l_schema() -> None:
|
||||
|
|
@ -114,7 +114,7 @@ def test_singleblock_l_image() -> None:
|
|||
img = Image.new("L", size, 128)
|
||||
assert img.im.isblock()
|
||||
|
||||
schema, arr = img.__arrow_c_array__()
|
||||
(schema, arr) = img.__arrow_c_array__()
|
||||
assert schema
|
||||
assert arr
|
||||
|
||||
|
|
@ -130,7 +130,7 @@ def test_singleblock_rgba_image() -> None:
|
|||
img = Image.new("RGBA", size, (128, 127, 126, 125))
|
||||
assert img.im.isblock()
|
||||
|
||||
schema, arr = img.__arrow_c_array__()
|
||||
(schema, arr) = img.__arrow_c_array__()
|
||||
assert schema
|
||||
assert arr
|
||||
Image.core.set_use_block_allocator(0)
|
||||
|
|
|
|||
|
|
@ -221,11 +221,6 @@ def test_rle8_eof(file_name: str, length: int) -> None:
|
|||
im.load()
|
||||
|
||||
|
||||
def test_rle_delta() -> None:
|
||||
with Image.open("Tests/images/bmp/q/pal8rletrns.bmp") as im:
|
||||
assert_image_equal_tofile(im, "Tests/images/pal8rletrns.png")
|
||||
|
||||
|
||||
def test_unsupported_bmp_bitfields_layout() -> None:
|
||||
fp = io.BytesIO(
|
||||
o32(40) # header size
|
||||
|
|
|
|||
|
|
@ -310,14 +310,6 @@ def test_roundtrip_save_all_1(tmp_path: Path) -> None:
|
|||
assert reloaded.getpixel((0, 0)) == 255
|
||||
|
||||
|
||||
@pytest.mark.parametrize("size", ((0, 1), (1, 0), (0, 0)))
|
||||
def test_save_zero(size: tuple[int, int]) -> None:
|
||||
b = BytesIO()
|
||||
im = Image.new("RGB", size)
|
||||
with pytest.raises(SystemError):
|
||||
im.save(b, "GIF")
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"path, mode",
|
||||
(
|
||||
|
|
@ -407,7 +399,7 @@ def test_save_netpbm_bmp_mode(tmp_path: Path) -> None:
|
|||
b = BytesIO()
|
||||
GifImagePlugin._save_netpbm(img_rgb, b, tempfile)
|
||||
with Image.open(tempfile) as reloaded:
|
||||
assert_image_equal(img_rgb, reloaded.convert("RGB"))
|
||||
assert_image_similar(img_rgb, reloaded.convert("RGB"), 0)
|
||||
|
||||
|
||||
@pytest.mark.skipif(not netpbm_available(), reason="Netpbm not available")
|
||||
|
|
@ -419,7 +411,7 @@ def test_save_netpbm_l_mode(tmp_path: Path) -> None:
|
|||
b = BytesIO()
|
||||
GifImagePlugin._save_netpbm(img_l, b, tempfile)
|
||||
with Image.open(tempfile) as reloaded:
|
||||
assert_image_equal(img_l, reloaded.convert("L"))
|
||||
assert_image_similar(img_l, reloaded.convert("L"), 0)
|
||||
|
||||
|
||||
def test_seek() -> None:
|
||||
|
|
@ -1441,7 +1433,7 @@ def test_getdata(monkeypatch: pytest.MonkeyPatch) -> None:
|
|||
# with open('Tests/images/gif_header_data.pkl', 'wb') as f:
|
||||
# pickle.dump((h, d), f, 1)
|
||||
with open("Tests/images/gif_header_data.pkl", "rb") as f:
|
||||
h_target, d_target = pickle.load(f)
|
||||
(h_target, d_target) = pickle.load(f)
|
||||
|
||||
assert h == h_target
|
||||
assert d == d_target
|
||||
|
|
|
|||
|
|
@ -590,7 +590,9 @@ class TestFileJpeg:
|
|||
assert im2.quantization == {0: bounds_qtable}
|
||||
|
||||
# values from wizard.txt in jpeg9-a src package.
|
||||
standard_l_qtable = [int(s) for s in """
|
||||
standard_l_qtable = [
|
||||
int(s)
|
||||
for s in """
|
||||
16 11 10 16 24 40 51 61
|
||||
12 12 14 19 26 58 60 55
|
||||
14 13 16 24 40 57 69 56
|
||||
|
|
@ -599,9 +601,14 @@ class TestFileJpeg:
|
|||
24 35 55 64 81 104 113 92
|
||||
49 64 78 87 103 121 120 101
|
||||
72 92 95 98 112 100 103 99
|
||||
""".split(None)]
|
||||
""".split(
|
||||
None
|
||||
)
|
||||
]
|
||||
|
||||
standard_chrominance_qtable = [int(s) for s in """
|
||||
standard_chrominance_qtable = [
|
||||
int(s)
|
||||
for s in """
|
||||
17 18 24 47 99 99 99 99
|
||||
18 21 26 66 99 99 99 99
|
||||
24 26 56 99 99 99 99 99
|
||||
|
|
@ -610,7 +617,10 @@ class TestFileJpeg:
|
|||
99 99 99 99 99 99 99 99
|
||||
99 99 99 99 99 99 99 99
|
||||
99 99 99 99 99 99 99 99
|
||||
""".split(None)]
|
||||
""".split(
|
||||
None
|
||||
)
|
||||
]
|
||||
|
||||
for quality in range(101):
|
||||
qtable_from_qtable_quality = self.roundtrip(
|
||||
|
|
|
|||
|
|
@ -738,7 +738,7 @@ class TestFileLibTiff(LibTiffTestCase):
|
|||
buffer_io.seek(0)
|
||||
|
||||
with Image.open(buffer_io) as saved_im:
|
||||
assert_image_equal(pilim, saved_im)
|
||||
assert_image_similar(pilim, saved_im, 0)
|
||||
|
||||
save_bytesio()
|
||||
save_bytesio("raw")
|
||||
|
|
|
|||
|
|
@ -37,14 +37,6 @@ def test_sanity(tmp_path: Path) -> None:
|
|||
im.save(f)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("size", ((0, 1), (1, 0), (0, 0)))
|
||||
def test_save_zero(size: tuple[int, int]) -> None:
|
||||
b = io.BytesIO()
|
||||
im = Image.new("1", size)
|
||||
with pytest.raises(ValueError):
|
||||
im.save(b, "PCX")
|
||||
|
||||
|
||||
def test_p_4_planes() -> None:
|
||||
with Image.open("Tests/images/p_4_planes.pcx") as im:
|
||||
assert im.getpixel((0, 0)) == 3
|
||||
|
|
@ -127,36 +119,36 @@ def test_large_count(tmp_path: Path) -> None:
|
|||
_roundtrip(tmp_path, im)
|
||||
|
||||
|
||||
def _test_buffer_overflow(
|
||||
tmp_path: Path, im: Image.Image, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
monkeypatch.setattr(ImageFile, "MAXBLOCK", 1024)
|
||||
_roundtrip(tmp_path, im)
|
||||
def _test_buffer_overflow(tmp_path: Path, im: Image.Image, size: int = 1024) -> None:
|
||||
_last = ImageFile.MAXBLOCK
|
||||
ImageFile.MAXBLOCK = size
|
||||
try:
|
||||
_roundtrip(tmp_path, im)
|
||||
finally:
|
||||
ImageFile.MAXBLOCK = _last
|
||||
|
||||
|
||||
def test_break_in_count_overflow(
|
||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
def test_break_in_count_overflow(tmp_path: Path) -> None:
|
||||
im = Image.new("L", (256, 5))
|
||||
px = im.load()
|
||||
assert px is not None
|
||||
for y in range(4):
|
||||
for x in range(256):
|
||||
px[x, y] = x % 128
|
||||
_test_buffer_overflow(tmp_path, im, monkeypatch)
|
||||
_test_buffer_overflow(tmp_path, im)
|
||||
|
||||
|
||||
def test_break_one_in_loop(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
def test_break_one_in_loop(tmp_path: Path) -> None:
|
||||
im = Image.new("L", (256, 5))
|
||||
px = im.load()
|
||||
assert px is not None
|
||||
for y in range(5):
|
||||
for x in range(256):
|
||||
px[x, y] = x % 128
|
||||
_test_buffer_overflow(tmp_path, im, monkeypatch)
|
||||
_test_buffer_overflow(tmp_path, im)
|
||||
|
||||
|
||||
def test_break_many_in_loop(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
def test_break_many_in_loop(tmp_path: Path) -> None:
|
||||
im = Image.new("L", (256, 5))
|
||||
px = im.load()
|
||||
assert px is not None
|
||||
|
|
@ -165,10 +157,10 @@ def test_break_many_in_loop(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) ->
|
|||
px[x, y] = x % 128
|
||||
for x in range(8):
|
||||
px[x, 4] = 16
|
||||
_test_buffer_overflow(tmp_path, im, monkeypatch)
|
||||
_test_buffer_overflow(tmp_path, im)
|
||||
|
||||
|
||||
def test_break_one_at_end(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
def test_break_one_at_end(tmp_path: Path) -> None:
|
||||
im = Image.new("L", (256, 5))
|
||||
px = im.load()
|
||||
assert px is not None
|
||||
|
|
@ -176,10 +168,10 @@ def test_break_one_at_end(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> No
|
|||
for x in range(256):
|
||||
px[x, y] = x % 128
|
||||
px[0, 3] = 128 + 64
|
||||
_test_buffer_overflow(tmp_path, im, monkeypatch)
|
||||
_test_buffer_overflow(tmp_path, im)
|
||||
|
||||
|
||||
def test_break_many_at_end(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
def test_break_many_at_end(tmp_path: Path) -> None:
|
||||
im = Image.new("L", (256, 5))
|
||||
px = im.load()
|
||||
assert px is not None
|
||||
|
|
@ -189,10 +181,10 @@ def test_break_many_at_end(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> N
|
|||
for x in range(4):
|
||||
px[x * 2, 3] = 128 + 64
|
||||
px[x + 256 - 4, 3] = 0
|
||||
_test_buffer_overflow(tmp_path, im, monkeypatch)
|
||||
_test_buffer_overflow(tmp_path, im)
|
||||
|
||||
|
||||
def test_break_padding(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
def test_break_padding(tmp_path: Path) -> None:
|
||||
im = Image.new("L", (257, 5))
|
||||
px = im.load()
|
||||
assert px is not None
|
||||
|
|
@ -201,4 +193,4 @@ def test_break_padding(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
|||
px[x, y] = x % 128
|
||||
for x in range(5):
|
||||
px[x, 3] = 0
|
||||
_test_buffer_overflow(tmp_path, im, monkeypatch)
|
||||
_test_buffer_overflow(tmp_path, im)
|
||||
|
|
|
|||
|
|
@ -654,17 +654,21 @@ class TestFilePng:
|
|||
with pytest.raises(SyntaxError, match="Unknown compression method"):
|
||||
PngImagePlugin.PngImageFile("Tests/images/unknown_compression_method.png")
|
||||
|
||||
def test_padded_idat(self, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
def test_padded_idat(self) -> None:
|
||||
# This image has been manually hexedited
|
||||
# so that the IDAT chunk has padding at the end
|
||||
# Set MAXBLOCK to the length of the actual data
|
||||
# so that the decoder finishes reading before the chunk ends
|
||||
monkeypatch.setattr(ImageFile, "MAXBLOCK", 45)
|
||||
monkeypatch.setattr(ImageFile, "LOAD_TRUNCATED_IMAGES", True)
|
||||
MAXBLOCK = ImageFile.MAXBLOCK
|
||||
ImageFile.MAXBLOCK = 45
|
||||
ImageFile.LOAD_TRUNCATED_IMAGES = True
|
||||
|
||||
with Image.open("Tests/images/padded_idat.png") as im:
|
||||
im.load()
|
||||
|
||||
ImageFile.MAXBLOCK = MAXBLOCK
|
||||
ImageFile.LOAD_TRUNCATED_IMAGES = False
|
||||
|
||||
assert_image_equal_tofile(im, "Tests/images/bw_gradient.png")
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ def test_seek_tell() -> None:
|
|||
|
||||
im.seek(2)
|
||||
layer_number = im.tell()
|
||||
assert layer_number == 2
|
||||
assert layer_number == 2
|
||||
|
||||
|
||||
def test_seek_eoferror() -> None:
|
||||
|
|
@ -138,7 +138,7 @@ def test_icc_profile() -> None:
|
|||
assert "icc_profile" in im.info
|
||||
|
||||
icc_profile = im.info["icc_profile"]
|
||||
assert len(icc_profile) == 3144
|
||||
assert len(icc_profile) == 3144
|
||||
|
||||
|
||||
def test_no_icc_profile() -> None:
|
||||
|
|
@ -158,16 +158,17 @@ def test_combined_larger_than_size() -> None:
|
|||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"test_file",
|
||||
"test_file,raises",
|
||||
[
|
||||
"Tests/images/timeout-c8efc3fded6426986ba867a399791bae544f59bc.psd",
|
||||
"Tests/images/timeout-dedc7a4ebd856d79b4359bbcc79e8ef231ce38f6.psd",
|
||||
("Tests/images/timeout-c8efc3fded6426986ba867a399791bae544f59bc.psd", OSError),
|
||||
("Tests/images/timeout-dedc7a4ebd856d79b4359bbcc79e8ef231ce38f6.psd", OSError),
|
||||
],
|
||||
)
|
||||
def test_crashes(test_file: str) -> None:
|
||||
with pytest.raises(OSError):
|
||||
with Image.open(test_file):
|
||||
pass
|
||||
def test_crashes(test_file: str, raises: type[Exception]) -> None:
|
||||
with open(test_file, "rb") as f:
|
||||
with pytest.raises(raises):
|
||||
with Image.open(f):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
|
@ -178,10 +179,11 @@ def test_crashes(test_file: str) -> None:
|
|||
],
|
||||
)
|
||||
def test_layer_crashes(test_file: str) -> None:
|
||||
with Image.open(test_file) as im:
|
||||
assert isinstance(im, PsdImagePlugin.PsdImageFile)
|
||||
with pytest.raises(SyntaxError):
|
||||
im.layers
|
||||
with open(test_file, "rb") as f:
|
||||
with Image.open(f) as im:
|
||||
assert isinstance(im, PsdImagePlugin.PsdImageFile)
|
||||
with pytest.raises(SyntaxError):
|
||||
im.layers
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
|
|
|||
|
|
@ -14,10 +14,6 @@ from .helper import assert_image_equal, hopper, is_pypy
|
|||
TEST_FILE = "Tests/images/hopper.spider"
|
||||
|
||||
|
||||
def teardown_module() -> None:
|
||||
del Image.EXTENSION[".spider"]
|
||||
|
||||
|
||||
def test_sanity() -> None:
|
||||
with Image.open(TEST_FILE) as im:
|
||||
im.load()
|
||||
|
|
@ -68,14 +64,6 @@ def test_save(tmp_path: Path) -> None:
|
|||
assert im2.format == "SPIDER"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("size", ((0, 1), (1, 0), (0, 0)))
|
||||
def test_save_zero(size: tuple[int, int]) -> None:
|
||||
b = BytesIO()
|
||||
im = Image.new("1", size)
|
||||
with pytest.raises(SystemError):
|
||||
im.save(b, "SPIDER")
|
||||
|
||||
|
||||
def test_tempfile() -> None:
|
||||
# Arrange
|
||||
im = hopper()
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ def test_load_raw() -> None:
|
|||
# Currently, support for WMF/EMF is Windows-only
|
||||
im.load()
|
||||
# Compare to reference rendering
|
||||
assert_image_equal_tofile(im, "Tests/images/drawing_emf_ref.png")
|
||||
assert_image_similar_tofile(im, "Tests/images/drawing_emf_ref.png", 0)
|
||||
|
||||
# Test basic WMF open and rendering
|
||||
with Image.open("Tests/images/drawing.wmf") as im:
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from PIL import Image, ImageDraw, ImageFont, _util
|
||||
|
||||
from .helper import PillowLeakTestCase, features, skip_unless_feature
|
||||
|
|
@ -9,7 +7,11 @@ from .helper import PillowLeakTestCase, features, skip_unless_feature
|
|||
original_core = ImageFont.core
|
||||
|
||||
|
||||
class TestFontLeak(PillowLeakTestCase):
|
||||
class TestTTypeFontLeak(PillowLeakTestCase):
|
||||
# fails at iteration 3 in main
|
||||
iterations = 10
|
||||
mem_limit = 4096 # k
|
||||
|
||||
def _test_font(self, font: ImageFont.FreeTypeFont | ImageFont.ImageFont) -> None:
|
||||
im = Image.new("RGB", (255, 255), "white")
|
||||
draw = ImageDraw.ImageDraw(im)
|
||||
|
|
@ -19,29 +21,23 @@ class TestFontLeak(PillowLeakTestCase):
|
|||
)
|
||||
)
|
||||
|
||||
|
||||
class TestTTypeFontLeak(TestFontLeak):
|
||||
# fails at iteration 3 in main
|
||||
iterations = 10
|
||||
mem_limit = 4096 # k
|
||||
|
||||
@skip_unless_feature("freetype2")
|
||||
def test_leak(self) -> None:
|
||||
ttype = ImageFont.truetype("Tests/fonts/FreeMono.ttf", 20)
|
||||
self._test_font(ttype)
|
||||
|
||||
|
||||
class TestDefaultFontLeak(TestFontLeak):
|
||||
class TestDefaultFontLeak(TestTTypeFontLeak):
|
||||
# fails at iteration 37 in main
|
||||
iterations = 100
|
||||
mem_limit = 1024 # k
|
||||
|
||||
def test_leak(self, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
def test_leak(self) -> None:
|
||||
if features.check_module("freetype2"):
|
||||
monkeypatch.setattr(
|
||||
ImageFont,
|
||||
"core",
|
||||
_util.DeferredError(ImportError("Disabled for testing")),
|
||||
)
|
||||
default_font = ImageFont.load_default()
|
||||
ImageFont.core = _util.DeferredError(ImportError("Disabled for testing"))
|
||||
try:
|
||||
default_font = ImageFont.load_default()
|
||||
finally:
|
||||
ImageFont.core = original_core
|
||||
|
||||
self._test_font(default_font)
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ from PIL import FontFile, Image, ImageDraw, ImageFont, PcfFontFile
|
|||
|
||||
from .helper import (
|
||||
assert_image_equal_tofile,
|
||||
assert_image_similar_tofile,
|
||||
skip_unless_feature,
|
||||
)
|
||||
|
||||
|
|
@ -72,14 +73,14 @@ def test_draw(request: pytest.FixtureRequest, tmp_path: Path) -> None:
|
|||
im = Image.new("L", (130, 30), "white")
|
||||
draw = ImageDraw.Draw(im)
|
||||
draw.text((0, 0), message, "black", font=font)
|
||||
assert_image_equal_tofile(im, "Tests/images/test_draw_pbm_target.png")
|
||||
assert_image_similar_tofile(im, "Tests/images/test_draw_pbm_target.png", 0)
|
||||
|
||||
|
||||
def test_textsize(request: pytest.FixtureRequest, tmp_path: Path) -> None:
|
||||
tempname = save_font(request, tmp_path)
|
||||
font = ImageFont.load(tempname)
|
||||
for i in range(255):
|
||||
ox, oy, dx, dy = font.getbbox(chr(i))
|
||||
(ox, oy, dx, dy) = font.getbbox(chr(i))
|
||||
assert ox == 0
|
||||
assert oy == 0
|
||||
assert dy == 20
|
||||
|
|
@ -99,7 +100,7 @@ def _test_high_characters(
|
|||
im = Image.new("L", (750, 30), "white")
|
||||
draw = ImageDraw.Draw(im)
|
||||
draw.text((0, 0), message, "black", font=font)
|
||||
assert_image_equal_tofile(im, "Tests/images/high_ascii_chars.png")
|
||||
assert_image_similar_tofile(im, "Tests/images/high_ascii_chars.png", 0)
|
||||
|
||||
|
||||
def test_high_characters(request: pytest.FixtureRequest, tmp_path: Path) -> None:
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ from PIL import FontFile, Image, ImageDraw, ImageFont, PcfFontFile
|
|||
|
||||
from .helper import (
|
||||
assert_image_equal_tofile,
|
||||
assert_image_similar_tofile,
|
||||
skip_unless_feature,
|
||||
)
|
||||
|
||||
|
|
@ -84,7 +85,7 @@ def test_draw(request: pytest.FixtureRequest, tmp_path: Path, encoding: str) ->
|
|||
draw = ImageDraw.Draw(im)
|
||||
message = charsets[encoding]["message"].encode(encoding)
|
||||
draw.text((0, 0), message, "black", font=font)
|
||||
assert_image_equal_tofile(im, charsets[encoding]["image1"])
|
||||
assert_image_similar_tofile(im, charsets[encoding]["image1"], 0)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("encoding", ("iso8859-1", "iso8859-2", "cp1250"))
|
||||
|
|
@ -94,7 +95,7 @@ def test_textsize(
|
|||
tempname = save_font(request, tmp_path, encoding)
|
||||
font = ImageFont.load(tempname)
|
||||
for i in range(255):
|
||||
ox, oy, dx, dy = font.getbbox(bytearray([i]))
|
||||
(ox, oy, dx, dy) = font.getbbox(bytearray([i]))
|
||||
assert ox == 0
|
||||
assert oy == 0
|
||||
assert dy == 20
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ def linear_gradient() -> Image.Image:
|
|||
im = Image.linear_gradient(mode="L")
|
||||
im90 = im.rotate(90)
|
||||
|
||||
px, h = im.size
|
||||
(px, h) = im.size
|
||||
|
||||
r = Image.new("L", (px * 3, h))
|
||||
g = r.copy()
|
||||
|
|
@ -54,7 +54,7 @@ def to_xxx_colorsys(
|
|||
) -> Image.Image:
|
||||
# convert the hard way using the library colorsys routines.
|
||||
|
||||
r, g, b = im.split()
|
||||
(r, g, b) = im.split()
|
||||
|
||||
conv_func = int_to_float
|
||||
|
||||
|
|
|
|||
|
|
@ -456,11 +456,9 @@ class TestImage:
|
|||
# Assert
|
||||
assert len(Image.ID) == id_length
|
||||
|
||||
def test_registered_extensions_uninitialized(
|
||||
self, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
def test_registered_extensions_uninitialized(self) -> None:
|
||||
# Arrange
|
||||
monkeypatch.setattr(Image, "_initialized", 0)
|
||||
Image._initialized = 0
|
||||
|
||||
# Act
|
||||
Image.registered_extensions()
|
||||
|
|
@ -468,9 +466,6 @@ class TestImage:
|
|||
# Assert
|
||||
assert Image._initialized == 2
|
||||
|
||||
for extension in Image.EXTENSION:
|
||||
assert extension in Image._EXTENSION_PLUGIN
|
||||
|
||||
def test_registered_extensions(self) -> None:
|
||||
# Arrange
|
||||
# Open an image to trigger plugin registration
|
||||
|
|
|
|||
|
|
@ -278,7 +278,8 @@ class TestEmbeddable:
|
|||
|
||||
with open("embed_pil.c", "w", encoding="utf-8") as fh:
|
||||
home = sys.prefix.replace("\\", "\\\\")
|
||||
fh.write(f"""
|
||||
fh.write(
|
||||
f"""
|
||||
#include "Python.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
|
|
@ -299,7 +300,8 @@ int main(int argc, char* argv[])
|
|||
|
||||
return 0;
|
||||
}}
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
objects = compiler.compile(["embed_pil.c"])
|
||||
compiler.link_executable(objects, "embed_pil")
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ class TestImageTransform:
|
|||
|
||||
def test_extent(self) -> None:
|
||||
im = hopper("RGB")
|
||||
w, h = im.size
|
||||
(w, h) = im.size
|
||||
transformed = im.transform(
|
||||
im.size,
|
||||
Image.Transform.EXTENT,
|
||||
|
|
@ -72,7 +72,7 @@ class TestImageTransform:
|
|||
def test_quad(self) -> None:
|
||||
# one simple quad transform, equivalent to scale & crop upper left quad
|
||||
im = hopper("RGB")
|
||||
w, h = im.size
|
||||
(w, h) = im.size
|
||||
transformed = im.transform(
|
||||
im.size,
|
||||
Image.Transform.QUAD,
|
||||
|
|
@ -99,7 +99,7 @@ class TestImageTransform:
|
|||
)
|
||||
def test_fill(self, mode: str, expected_pixel: tuple[int, ...]) -> None:
|
||||
im = hopper(mode)
|
||||
w, h = im.size
|
||||
(w, h) = im.size
|
||||
transformed = im.transform(
|
||||
im.size,
|
||||
Image.Transform.EXTENT,
|
||||
|
|
@ -112,7 +112,7 @@ class TestImageTransform:
|
|||
def test_mesh(self) -> None:
|
||||
# this should be a checkerboard of halfsized hoppers in ul, lr
|
||||
im = hopper("RGBA")
|
||||
w, h = im.size
|
||||
(w, h) = im.size
|
||||
transformed = im.transform(
|
||||
im.size,
|
||||
Image.Transform.MESH,
|
||||
|
|
@ -174,7 +174,7 @@ class TestImageTransform:
|
|||
|
||||
def test_alpha_premult_transform(self) -> None:
|
||||
def op(im: Image.Image, sz: tuple[int, int]) -> Image.Image:
|
||||
w, h = im.size
|
||||
(w, h) = im.size
|
||||
return im.transform(
|
||||
sz, Image.Transform.EXTENT, (0, 0, w, h), Image.Resampling.BILINEAR
|
||||
)
|
||||
|
|
@ -216,7 +216,7 @@ class TestImageTransform:
|
|||
@pytest.mark.parametrize("mode", ("RGBA", "LA"))
|
||||
def test_nearest_transform(self, mode: str) -> None:
|
||||
def op(im: Image.Image, sz: tuple[int, int]) -> Image.Image:
|
||||
w, h = im.size
|
||||
(w, h) = im.size
|
||||
return im.transform(
|
||||
sz, Image.Transform.EXTENT, (0, 0, w, h), Image.Resampling.NEAREST
|
||||
)
|
||||
|
|
@ -255,7 +255,7 @@ class TestImageTransform:
|
|||
@pytest.mark.parametrize("resample", (Image.Resampling.BOX, "unknown"))
|
||||
def test_unknown_resampling_filter(self, resample: Image.Resampling | str) -> None:
|
||||
with hopper() as im:
|
||||
w, h = im.size
|
||||
(w, h) = im.size
|
||||
with pytest.raises(ValueError):
|
||||
im.transform((100, 100), Image.Transform.EXTENT, (0, 0, w, h), resample) # type: ignore[arg-type]
|
||||
|
||||
|
|
|
|||
|
|
@ -68,22 +68,10 @@ def test_sanity() -> None:
|
|||
draw.rectangle(list(range(4)))
|
||||
|
||||
|
||||
def test_new_color() -> None:
|
||||
def test_valueerror() -> None:
|
||||
with Image.open("Tests/images/chi.gif") as im:
|
||||
draw = ImageDraw.Draw(im)
|
||||
assert im.palette is not None
|
||||
assert len(im.palette.colors) == 249
|
||||
|
||||
# Test drawing a new color onto the palette
|
||||
draw.line((0, 0), fill=(0, 0, 0))
|
||||
assert im.palette is not None
|
||||
assert len(im.palette.colors) == 250
|
||||
assert im.palette.dirty
|
||||
|
||||
# Test drawing another new color, now that the palette is dirty
|
||||
draw.point((0, 0), fill=(1, 0, 0))
|
||||
assert len(im.palette.colors) == 251
|
||||
assert im.convert("RGB").getpixel((0, 0)) == (1, 0, 0)
|
||||
|
||||
|
||||
def test_mode_mismatch() -> None:
|
||||
|
|
@ -895,18 +883,6 @@ def test_rounded_rectangle_joined_x_different_corners() -> None:
|
|||
)
|
||||
|
||||
|
||||
def test_rounded_rectangle_radius() -> None:
|
||||
# Arrange
|
||||
im = Image.new("RGB", (W, H))
|
||||
draw = ImageDraw.Draw(im, "RGB")
|
||||
|
||||
# Act
|
||||
draw.rounded_rectangle((25, 25, 75, 75), 24, fill="red", outline="green", width=5)
|
||||
|
||||
# Assert
|
||||
assert_image_equal_tofile(im, "Tests/images/imagedraw_rounded_rectangle_radius.png")
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"xy, radius, type",
|
||||
[
|
||||
|
|
@ -1485,15 +1461,21 @@ def test_stroke_multiline() -> None:
|
|||
|
||||
|
||||
@skip_unless_feature("freetype2")
|
||||
def test_setting_default_font(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
def test_setting_default_font() -> None:
|
||||
# Arrange
|
||||
im = Image.new("RGB", (100, 250))
|
||||
draw = ImageDraw.Draw(im)
|
||||
assert isinstance(draw.getfont(), ImageFont.load_default().__class__)
|
||||
|
||||
draw = ImageDraw.Draw(im)
|
||||
font = ImageFont.truetype("Tests/fonts/FreeMono.ttf", 120)
|
||||
monkeypatch.setattr(ImageDraw.ImageDraw, "font", font)
|
||||
assert draw.getfont() == font
|
||||
|
||||
# Act
|
||||
ImageDraw.ImageDraw.font = font
|
||||
|
||||
# Assert
|
||||
try:
|
||||
assert draw.getfont() == font
|
||||
finally:
|
||||
ImageDraw.ImageDraw.font = None
|
||||
assert isinstance(draw.getfont(), ImageFont.load_default().__class__)
|
||||
|
||||
|
||||
def test_default_font_size() -> None:
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ SAFEBLOCK = ImageFile.SAFEBLOCK
|
|||
|
||||
|
||||
class TestImageFile:
|
||||
def test_parser(self, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
def test_parser(self) -> None:
|
||||
def roundtrip(format: str) -> tuple[Image.Image, Image.Image]:
|
||||
im = hopper("L").resize((1000, 1000), Image.Resampling.NEAREST)
|
||||
if format in ("MSP", "XBM"):
|
||||
|
|
@ -55,9 +55,12 @@ class TestImageFile:
|
|||
assert_image_equal(*roundtrip("IM"))
|
||||
assert_image_equal(*roundtrip("MSP"))
|
||||
if features.check("zlib"):
|
||||
# force multiple blocks in PNG driver
|
||||
monkeypatch.setattr(ImageFile, "MAXBLOCK", 8192)
|
||||
assert_image_equal(*roundtrip("PNG"))
|
||||
try:
|
||||
# force multiple blocks in PNG driver
|
||||
ImageFile.MAXBLOCK = 8192
|
||||
assert_image_equal(*roundtrip("PNG"))
|
||||
finally:
|
||||
ImageFile.MAXBLOCK = MAXBLOCK
|
||||
assert_image_equal(*roundtrip("PPM"))
|
||||
assert_image_equal(*roundtrip("TIFF"))
|
||||
assert_image_equal(*roundtrip("XBM"))
|
||||
|
|
@ -117,11 +120,14 @@ class TestImageFile:
|
|||
assert (128, 128) == p.image.size
|
||||
|
||||
@skip_unless_feature("zlib")
|
||||
def test_safeblock(self, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
def test_safeblock(self) -> None:
|
||||
im1 = hopper()
|
||||
|
||||
monkeypatch.setattr(ImageFile, "SAFEBLOCK", 1)
|
||||
im2 = fromstring(tostring(im1, "PNG"))
|
||||
try:
|
||||
ImageFile.SAFEBLOCK = 1
|
||||
im2 = fromstring(tostring(im1, "PNG"))
|
||||
finally:
|
||||
ImageFile.SAFEBLOCK = SAFEBLOCK
|
||||
|
||||
assert_image_equal(im1, im2)
|
||||
|
||||
|
|
|
|||
|
|
@ -38,18 +38,20 @@ def test_invalid_mode() -> None:
|
|||
font._load_pilfont_data(fp, im)
|
||||
|
||||
|
||||
def test_without_freetype(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
def test_without_freetype() -> None:
|
||||
original_core = ImageFont.core
|
||||
if features.check_module("freetype2"):
|
||||
monkeypatch.setattr(
|
||||
ImageFont, "core", _util.DeferredError(ImportError("Disabled for testing"))
|
||||
)
|
||||
with pytest.raises(ImportError):
|
||||
ImageFont.truetype("Tests/fonts/FreeMono.ttf")
|
||||
ImageFont.core = _util.DeferredError(ImportError("Disabled for testing"))
|
||||
try:
|
||||
with pytest.raises(ImportError):
|
||||
ImageFont.truetype("Tests/fonts/FreeMono.ttf")
|
||||
|
||||
assert isinstance(ImageFont.load_default(), ImageFont.ImageFont)
|
||||
assert isinstance(ImageFont.load_default(), ImageFont.ImageFont)
|
||||
|
||||
with pytest.raises(ImportError):
|
||||
ImageFont.load_default(size=14)
|
||||
with pytest.raises(ImportError):
|
||||
ImageFont.load_default(size=14)
|
||||
finally:
|
||||
ImageFont.core = original_core
|
||||
|
||||
|
||||
@pytest.mark.parametrize("font", fonts)
|
||||
|
|
|
|||
|
|
@ -22,7 +22,8 @@ def string_to_img(image_string: str) -> Image.Image:
|
|||
return im
|
||||
|
||||
|
||||
A = string_to_img("""
|
||||
A = string_to_img(
|
||||
"""
|
||||
.......
|
||||
.......
|
||||
..111..
|
||||
|
|
@ -30,7 +31,8 @@ A = string_to_img("""
|
|||
..111..
|
||||
.......
|
||||
.......
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
def img_to_string(im: Image.Image) -> str:
|
||||
|
|
@ -229,15 +231,15 @@ def test_negate() -> None:
|
|||
|
||||
|
||||
def test_incorrect_mode() -> None:
|
||||
im = hopper()
|
||||
mop = ImageMorph.MorphOp(op_name="erosion8")
|
||||
|
||||
with hopper() as im:
|
||||
with pytest.raises(ValueError, match="Image mode must be 1 or L"):
|
||||
mop.apply(im)
|
||||
with pytest.raises(ValueError, match="Image mode must be 1 or L"):
|
||||
mop.match(im)
|
||||
with pytest.raises(ValueError, match="Image mode must be 1 or L"):
|
||||
mop.get_on_pixels(im)
|
||||
with pytest.raises(ValueError, match="Image mode must be 1 or L"):
|
||||
mop.apply(im)
|
||||
with pytest.raises(ValueError, match="Image mode must be 1 or L"):
|
||||
mop.match(im)
|
||||
with pytest.raises(ValueError, match="Image mode must be 1 or L"):
|
||||
mop.get_on_pixels(im)
|
||||
|
||||
|
||||
def test_add_patterns() -> None:
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from io import BytesIO
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from PIL import Image, ImagePalette, PaletteFile
|
||||
from PIL import Image, ImagePalette
|
||||
|
||||
from .helper import assert_image_equal, assert_image_equal_tofile
|
||||
|
||||
|
|
@ -203,19 +202,6 @@ def test_2bit_palette(tmp_path: Path) -> None:
|
|||
assert_image_equal_tofile(img, outfile)
|
||||
|
||||
|
||||
def test_getpalette() -> None:
|
||||
b = BytesIO(b"0 1\n1 2 3 4")
|
||||
p = PaletteFile.PaletteFile(b)
|
||||
|
||||
palette, rawmode = p.getpalette()
|
||||
assert palette[:6] == b"\x01\x01\x01\x02\x03\x04"
|
||||
assert rawmode == "RGB"
|
||||
|
||||
|
||||
def test_invalid_palette() -> None:
|
||||
with pytest.raises(OSError):
|
||||
ImagePalette.load("Tests/images/hopper.jpg")
|
||||
|
||||
b = BytesIO(b"1" * 101)
|
||||
with pytest.raises(SyntaxError, match="bad palette file"):
|
||||
PaletteFile.PaletteFile(b)
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ if is_win32():
|
|||
|
||||
def test_pointer(tmp_path: Path) -> None:
|
||||
im = hopper()
|
||||
width, height = im.size
|
||||
(width, height) = im.size
|
||||
opath = tmp_path / "temp.png"
|
||||
imdib = ImageWin.Dib(im)
|
||||
|
||||
|
|
|
|||
|
|
@ -208,7 +208,7 @@ INT32 = DataShape(
|
|||
),
|
||||
)
|
||||
def test_fromarray(mode: str, data_tp: DataShape, mask: list[int] | None) -> None:
|
||||
dtype, elt, elts_per_pixel = data_tp
|
||||
(dtype, elt, elts_per_pixel) = data_tp
|
||||
|
||||
ct_pixels = TEST_IMAGE_SIZE[0] * TEST_IMAGE_SIZE[1]
|
||||
if dtype == fl_uint8_4_type:
|
||||
|
|
@ -241,7 +241,7 @@ def test_fromarray(mode: str, data_tp: DataShape, mask: list[int] | None) -> Non
|
|||
)
|
||||
@pytest.mark.parametrize("data_tp", (UINT32, INT32))
|
||||
def test_from_int32array(mode: str, mask: list[int] | None, data_tp: DataShape) -> None:
|
||||
dtype, elt, elts_per_pixel = data_tp
|
||||
(dtype, elt, elts_per_pixel) = data_tp
|
||||
|
||||
ct_pixels = TEST_IMAGE_SIZE[0] * TEST_IMAGE_SIZE[1]
|
||||
arr = nanoarrow.Array(
|
||||
|
|
|
|||
|
|
@ -5,8 +5,6 @@ import sys
|
|||
from io import BytesIO
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from PIL import Image, PSDraw
|
||||
|
||||
|
||||
|
|
@ -49,16 +47,21 @@ def test_draw_postscript(tmp_path: Path) -> None:
|
|||
assert os.path.getsize(tempfile) > 0
|
||||
|
||||
|
||||
def test_stdout(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
def test_stdout() -> None:
|
||||
# Temporarily redirect stdout
|
||||
old_stdout = sys.stdout
|
||||
|
||||
class MyStdOut:
|
||||
buffer = BytesIO()
|
||||
|
||||
mystdout = MyStdOut()
|
||||
|
||||
monkeypatch.setattr(sys, "stdout", mystdout)
|
||||
sys.stdout = mystdout
|
||||
|
||||
ps = PSDraw.PSDraw()
|
||||
_create_document(ps)
|
||||
|
||||
# Reset stdout
|
||||
sys.stdout = old_stdout
|
||||
|
||||
assert mystdout.buffer.getvalue() != b""
|
||||
|
|
|
|||
|
|
@ -211,7 +211,7 @@ INT32 = DataShape(
|
|||
),
|
||||
)
|
||||
def test_fromarray(mode: str, data_tp: DataShape, mask: list[int] | None) -> None:
|
||||
dtype, elt, elts_per_pixel = data_tp
|
||||
(dtype, elt, elts_per_pixel) = data_tp
|
||||
|
||||
ct_pixels = TEST_IMAGE_SIZE[0] * TEST_IMAGE_SIZE[1]
|
||||
arr = pyarrow.array([elt] * (ct_pixels * elts_per_pixel), type=dtype)
|
||||
|
|
@ -238,7 +238,7 @@ def test_fromarray(mode: str, data_tp: DataShape, mask: list[int] | None) -> Non
|
|||
),
|
||||
)
|
||||
def test_from_int32array(mode: str, data_tp: DataShape, mask: list[int] | None) -> None:
|
||||
dtype, elt, elts_per_pixel = data_tp
|
||||
(dtype, elt, elts_per_pixel) = data_tp
|
||||
|
||||
ct_pixels = TEST_IMAGE_SIZE[0] * TEST_IMAGE_SIZE[1]
|
||||
arr = pyarrow.array([elt] * (ct_pixels * elts_per_pixel), type=dtype)
|
||||
|
|
|
|||
|
|
@ -6,15 +6,10 @@ import pytest
|
|||
|
||||
from PIL import __version__
|
||||
|
||||
TYPE_CHECKING = False
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from importlib.metadata import PackageMetadata
|
||||
|
||||
pyroma = pytest.importorskip("pyroma", reason="Pyroma not installed")
|
||||
|
||||
|
||||
def map_metadata_keys(md: PackageMetadata) -> dict[str, str | list[str] | None]:
|
||||
def map_metadata_keys(md):
|
||||
# Convert installed wheel metadata into canonical Core Metadata 2.4 format.
|
||||
# This was a utility method in pyroma 4.3.3; it was removed in 5.0.
|
||||
# This implementation is constructed from the relevant logic from
|
||||
|
|
@ -22,16 +17,16 @@ def map_metadata_keys(md: PackageMetadata) -> dict[str, str | list[str] | None]:
|
|||
# upstream to Pyroma as https://github.com/regebro/pyroma/pull/116,
|
||||
# so it may be possible to simplify this test in future.
|
||||
data = {}
|
||||
for key in set(md):
|
||||
for key in set(md.keys()):
|
||||
value = md.get_all(key)
|
||||
key = pyroma.projectdata.normalize(key)
|
||||
|
||||
if value is not None and len(value) == 1:
|
||||
first_value = value[0]
|
||||
if first_value.strip() != "UNKNOWN":
|
||||
data[key] = first_value
|
||||
else:
|
||||
data[key] = value
|
||||
if len(value) == 1:
|
||||
value = value[0]
|
||||
if value.strip() == "UNKNOWN":
|
||||
continue
|
||||
|
||||
data[key] = value
|
||||
return data
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from .helper import assert_image_equal, hopper
|
||||
from .helper import assert_image_equal, assert_image_similar, hopper
|
||||
|
||||
|
||||
def check_upload_equal() -> None:
|
||||
|
|
@ -12,4 +12,4 @@ def check_upload_equal() -> None:
|
|||
def check_upload_similar() -> None:
|
||||
result = hopper("P").convert("RGB")
|
||||
target = hopper("RGB")
|
||||
assert_image_equal(result, target)
|
||||
assert_image_similar(result, target, 0)
|
||||
|
|
|
|||
|
|
@ -3,88 +3,66 @@ set -eo pipefail
|
|||
|
||||
version=1.3.0
|
||||
|
||||
if [[ "$GHA_LIBAVIF_CACHE_HIT" == "true" ]]; then
|
||||
./download-and-extract.sh libavif-$version https://github.com/AOMediaCodec/libavif/archive/refs/tags/v$version.tar.gz
|
||||
|
||||
LIBDIR=/usr/lib/x86_64-linux-gnu
|
||||
pushd libavif-$version
|
||||
|
||||
# Copy cached files into place
|
||||
sudo cp ~/cache-libavif/lib/* $LIBDIR/
|
||||
sudo cp -r ~/cache-libavif/include/avif /usr/include/
|
||||
# Apply patch for SVT-AV1 4.0 compatibility
|
||||
# Pending release of https://github.com/AOMediaCodec/libavif/pull/2971
|
||||
patch -p1 < ../libavif-svt4.patch
|
||||
|
||||
if [ $(uname) == "Darwin" ] && [ -x "$(command -v brew)" ]; then
|
||||
PREFIX=$(brew --prefix)
|
||||
else
|
||||
|
||||
./download-and-extract.sh libavif-$version https://github.com/AOMediaCodec/libavif/archive/refs/tags/v$version.tar.gz
|
||||
|
||||
pushd libavif-$version
|
||||
|
||||
# Apply patch for SVT-AV1 4.0 compatibility
|
||||
# Pending release of https://github.com/AOMediaCodec/libavif/pull/2971
|
||||
patch -p1 < ../libavif-svt4.patch
|
||||
|
||||
if [ $(uname) == "Darwin" ] && [ -x "$(command -v brew)" ]; then
|
||||
PREFIX=$(brew --prefix)
|
||||
else
|
||||
PREFIX=/usr
|
||||
fi
|
||||
|
||||
PKGCONFIG=${PKGCONFIG:-pkg-config}
|
||||
|
||||
LIBAVIF_CMAKE_FLAGS=()
|
||||
HAS_DECODER=0
|
||||
HAS_ENCODER=0
|
||||
|
||||
if $PKGCONFIG --exists aom; then
|
||||
LIBAVIF_CMAKE_FLAGS+=(-DAVIF_CODEC_AOM=SYSTEM)
|
||||
HAS_ENCODER=1
|
||||
HAS_DECODER=1
|
||||
fi
|
||||
|
||||
if $PKGCONFIG --exists dav1d; then
|
||||
LIBAVIF_CMAKE_FLAGS+=(-DAVIF_CODEC_DAV1D=SYSTEM)
|
||||
HAS_DECODER=1
|
||||
fi
|
||||
|
||||
if $PKGCONFIG --exists libgav1; then
|
||||
LIBAVIF_CMAKE_FLAGS+=(-DAVIF_CODEC_LIBGAV1=SYSTEM)
|
||||
HAS_DECODER=1
|
||||
fi
|
||||
|
||||
if $PKGCONFIG --exists rav1e; then
|
||||
LIBAVIF_CMAKE_FLAGS+=(-DAVIF_CODEC_RAV1E=SYSTEM)
|
||||
HAS_ENCODER=1
|
||||
fi
|
||||
|
||||
if $PKGCONFIG --exists SvtAv1Enc; then
|
||||
LIBAVIF_CMAKE_FLAGS+=(-DAVIF_CODEC_SVT=SYSTEM)
|
||||
HAS_ENCODER=1
|
||||
fi
|
||||
|
||||
if [ "$HAS_ENCODER" != 1 ] || [ "$HAS_DECODER" != 1 ]; then
|
||||
LIBAVIF_CMAKE_FLAGS+=(-DAVIF_CODEC_AOM=LOCAL)
|
||||
fi
|
||||
|
||||
cmake \
|
||||
-DCMAKE_INSTALL_PREFIX=$PREFIX \
|
||||
-DCMAKE_INSTALL_NAME_DIR=$PREFIX/lib \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_MACOSX_RPATH=OFF \
|
||||
-DAVIF_LIBSHARPYUV=LOCAL \
|
||||
-DAVIF_LIBYUV=LOCAL \
|
||||
"${LIBAVIF_CMAKE_FLAGS[@]}" \
|
||||
.
|
||||
|
||||
sudo make install
|
||||
|
||||
if [ -n "$GITHUB_ACTIONS" ] && [ "$(uname)" != "Darwin" ]; then
|
||||
# Copy to cache
|
||||
LIBDIR=/usr/lib/x86_64-linux-gnu
|
||||
rm -rf ~/cache-libavif
|
||||
mkdir -p ~/cache-libavif/lib
|
||||
mkdir -p ~/cache-libavif/include
|
||||
cp $LIBDIR/libavif.so* ~/cache-libavif/lib/
|
||||
cp -r /usr/include/avif ~/cache-libavif/include/
|
||||
fi
|
||||
|
||||
popd
|
||||
|
||||
PREFIX=/usr
|
||||
fi
|
||||
|
||||
PKGCONFIG=${PKGCONFIG:-pkg-config}
|
||||
|
||||
LIBAVIF_CMAKE_FLAGS=()
|
||||
HAS_DECODER=0
|
||||
HAS_ENCODER=0
|
||||
|
||||
if $PKGCONFIG --exists aom; then
|
||||
LIBAVIF_CMAKE_FLAGS+=(-DAVIF_CODEC_AOM=SYSTEM)
|
||||
HAS_ENCODER=1
|
||||
HAS_DECODER=1
|
||||
fi
|
||||
|
||||
if $PKGCONFIG --exists dav1d; then
|
||||
LIBAVIF_CMAKE_FLAGS+=(-DAVIF_CODEC_DAV1D=SYSTEM)
|
||||
HAS_DECODER=1
|
||||
fi
|
||||
|
||||
if $PKGCONFIG --exists libgav1; then
|
||||
LIBAVIF_CMAKE_FLAGS+=(-DAVIF_CODEC_LIBGAV1=SYSTEM)
|
||||
HAS_DECODER=1
|
||||
fi
|
||||
|
||||
if $PKGCONFIG --exists rav1e; then
|
||||
LIBAVIF_CMAKE_FLAGS+=(-DAVIF_CODEC_RAV1E=SYSTEM)
|
||||
HAS_ENCODER=1
|
||||
fi
|
||||
|
||||
if $PKGCONFIG --exists SvtAv1Enc; then
|
||||
LIBAVIF_CMAKE_FLAGS+=(-DAVIF_CODEC_SVT=SYSTEM)
|
||||
HAS_ENCODER=1
|
||||
fi
|
||||
|
||||
if [ "$HAS_ENCODER" != 1 ] || [ "$HAS_DECODER" != 1 ]; then
|
||||
LIBAVIF_CMAKE_FLAGS+=(-DAVIF_CODEC_AOM=LOCAL)
|
||||
fi
|
||||
|
||||
cmake \
|
||||
-DCMAKE_INSTALL_PREFIX=$PREFIX \
|
||||
-DCMAKE_INSTALL_NAME_DIR=$PREFIX/lib \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_MACOSX_RPATH=OFF \
|
||||
-DAVIF_LIBSHARPYUV=LOCAL \
|
||||
-DAVIF_LIBYUV=LOCAL \
|
||||
"${LIBAVIF_CMAKE_FLAGS[@]}" \
|
||||
.
|
||||
|
||||
make install
|
||||
|
||||
popd
|
||||
|
|
|
|||
|
|
@ -3,30 +3,10 @@
|
|||
|
||||
archive=libwebp-1.6.0
|
||||
|
||||
if [[ "$GHA_LIBWEBP_CACHE_HIT" == "true" ]]; then
|
||||
./download-and-extract.sh $archive https://raw.githubusercontent.com/python-pillow/pillow-depends/main/$archive.tar.gz
|
||||
|
||||
# Copy cached files into place
|
||||
sudo cp ~/cache-libwebp/lib/* /usr/lib/
|
||||
sudo cp -r ~/cache-libwebp/include/webp /usr/include/
|
||||
pushd $archive
|
||||
|
||||
else
|
||||
./configure --prefix=/usr --enable-libwebpmux --enable-libwebpdemux && make -j4 && sudo make -j4 install
|
||||
|
||||
./download-and-extract.sh $archive https://raw.githubusercontent.com/python-pillow/pillow-depends/main/$archive.tar.gz
|
||||
|
||||
pushd $archive
|
||||
|
||||
./configure --prefix=/usr --enable-libwebpmux --enable-libwebpdemux && make -j4 && sudo make -j4 install
|
||||
|
||||
if [ -n "$GITHUB_ACTIONS" ]; then
|
||||
# Copy to cache
|
||||
rm -rf ~/cache-libwebp
|
||||
mkdir -p ~/cache-libwebp/lib
|
||||
mkdir -p ~/cache-libwebp/include
|
||||
cp /usr/lib/libwebp*.so* /usr/lib/libwebp*.a ~/cache-libwebp/lib/
|
||||
cp /usr/lib/libsharpyuv.so* /usr/lib/libsharpyuv.a ~/cache-libwebp/lib/
|
||||
cp -r /usr/include/webp ~/cache-libwebp/include/
|
||||
fi
|
||||
|
||||
popd
|
||||
|
||||
fi
|
||||
popd
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import subprocess
|
|||
|
||||
TYPE_CHECKING = False
|
||||
if TYPE_CHECKING:
|
||||
from typing import Any
|
||||
from sphinx.application import Sphinx
|
||||
|
||||
DOC_NAME_REGEX = re.compile(r"releasenotes/\d+\.\d+\.\d+")
|
||||
VERSION_TITLE_REGEX = re.compile(r"^(\d+\.\d+\.\d+)\n-+\n")
|
||||
|
|
@ -28,7 +28,7 @@ def get_date_for(git_version: str) -> str | None:
|
|||
return out.split()[0]
|
||||
|
||||
|
||||
def add_date(app: Any, doc_name: str, source: list[str]) -> None:
|
||||
def add_date(app: Sphinx, doc_name: str, source: list[str]) -> None:
|
||||
if DOC_NAME_REGEX.match(doc_name) and (m := VERSION_TITLE_REGEX.match(source[0])):
|
||||
old_title = m.group(1)
|
||||
|
||||
|
|
@ -43,6 +43,6 @@ def add_date(app: Any, doc_name: str, source: list[str]) -> None:
|
|||
source[0] = result
|
||||
|
||||
|
||||
def setup(app: Any) -> dict[str, bool]:
|
||||
def setup(app: Sphinx) -> dict[str, bool]:
|
||||
app.connect("source-read", add_date)
|
||||
return {"parallel_read_safe": True}
|
||||
|
|
|
|||
|
|
@ -828,6 +828,16 @@ PCX
|
|||
|
||||
Pillow reads and writes PCX files containing ``1``, ``L``, ``P``, or ``RGB`` data.
|
||||
|
||||
PFM
|
||||
^^^
|
||||
|
||||
.. versionadded:: 10.3.0
|
||||
|
||||
Pillow reads and writes grayscale (Pf format) Portable FloatMap (PFM) files
|
||||
containing ``F`` data.
|
||||
|
||||
Color (PF format) PFM files are not supported.
|
||||
|
||||
Opening
|
||||
~~~~~~~
|
||||
|
||||
|
|
@ -1071,19 +1081,12 @@ following parameters can also be set:
|
|||
PPM
|
||||
^^^
|
||||
|
||||
Pillow reads and writes PBM, PGM, PPM, PNM and PFM files containing ``1``, ``L``, ``I``,
|
||||
``RGB`` or ``F`` data.
|
||||
Pillow reads and writes PBM, PGM, PPM and PNM files containing ``1``, ``L``, ``I`` or
|
||||
``RGB`` data.
|
||||
|
||||
"Raw" (P4 to P6) formats can be read, and are used when writing.
|
||||
|
||||
.. versionadded:: 9.2.0
|
||||
"Plain" (P1 to P3) formats can be read.
|
||||
|
||||
.. versionadded:: 10.3.0
|
||||
Grayscale (Pf format) Portable FloatMap (PFM) files containing
|
||||
``F`` data can be read and used when writing.
|
||||
|
||||
Color (PF format) PFM files are not supported.
|
||||
Since Pillow 9.2.0, "plain" (P1 to P3) formats can be read as well.
|
||||
|
||||
QOI
|
||||
^^^
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ Many of Pillow's features require external libraries:
|
|||
* **littlecms** provides color management
|
||||
|
||||
* Pillow version 2.2.1 and below uses liblcms1, Pillow 2.3.0 and
|
||||
above uses liblcms2. Tested with **1.19** and **2.7-2.18**.
|
||||
above uses liblcms2. Tested with **1.19** and **2.7-2.17**.
|
||||
|
||||
* **libwebp** provides the WebP format.
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ These platforms are built and tested for every change.
|
|||
| Windows Server 2025 | 3.11, 3.12, 3.13, 3.14, | x86-64 |
|
||||
| | PyPy3 | |
|
||||
| +----------------------------+---------------------+
|
||||
| | 3.13 (MinGW) | x86-64 |
|
||||
| | 3.12 (MinGW) | x86-64 |
|
||||
+----------------------------------+----------------------------+---------------------+
|
||||
|
||||
|
||||
|
|
@ -75,7 +75,7 @@ These platforms have been reported to work at the versions mentioned.
|
|||
| Operating system | | Tested Python | | Latest tested | | Tested |
|
||||
| | | versions | | Pillow version | | processors |
|
||||
+==================================+=============================+==================+==============+
|
||||
| macOS 26 Tahoe | 3.10, 3.11, 3.12, 3.13, 3.14| 12.1.1 |arm |
|
||||
| macOS 26 Tahoe | 3.10, 3.11, 3.12, 3.13, 3.14| 12.0.0 |arm |
|
||||
| +-----------------------------+------------------+ |
|
||||
| | 3.9 | 11.3.0 | |
|
||||
+----------------------------------+-----------------------------+------------------+--------------+
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
Security
|
||||
========
|
||||
|
||||
:cve:`2026-25990`: Fix OOB write with invalid tile extents
|
||||
:cve:`2021-25289`: Fix OOB write with invalid tile extents
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
Check that tile extents do not use negative x or y offsets when decoding or encoding,
|
||||
|
|
|
|||
|
|
@ -112,6 +112,14 @@ test-requires = [
|
|||
]
|
||||
xbuild-tools = [ ]
|
||||
|
||||
[tool.cibuildwheel.macos]
|
||||
# Disable platform guessing on macOS to avoid picking up Homebrew etc.
|
||||
config-settings = "raqm=enable raqm=vendor fribidi=vendor imagequant=disable platform-guessing=disable"
|
||||
|
||||
[tool.cibuildwheel.macos.environment]
|
||||
# Isolate macOS build environment from Homebrew etc.
|
||||
PATH = "$(pwd)/build/deps/darwin/bin:$(dirname $(which python3)):/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin"
|
||||
|
||||
[tool.cibuildwheel.ios]
|
||||
# Disable platform guessing on iOS, and disable raqm (since there won't be a
|
||||
# vendor version, and we can't distribute it due to licensing)
|
||||
|
|
@ -131,14 +139,6 @@ test-command = [
|
|||
# There's no numpy wheel for iOS (yet...)
|
||||
test-requires = [ ]
|
||||
|
||||
[tool.cibuildwheel.macos]
|
||||
# Disable platform guessing on macOS to avoid picking up Homebrew etc.
|
||||
config-settings = "raqm=enable raqm=vendor fribidi=vendor imagequant=disable platform-guessing=disable"
|
||||
|
||||
[tool.cibuildwheel.macos.environment]
|
||||
# Isolate macOS build environment from Homebrew etc.
|
||||
PATH = "$(pwd)/build/deps/darwin/bin:$(dirname $(which python3)):/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin"
|
||||
|
||||
[[tool.cibuildwheel.overrides]]
|
||||
# iOS environment is isolated by cibuildwheel, but needs the dependencies
|
||||
select = "*_iphoneos"
|
||||
|
|
@ -217,7 +217,6 @@ testpaths = [
|
|||
python_version = "3.10"
|
||||
pretty = true
|
||||
disallow_any_generics = true
|
||||
disallow_untyped_defs = true
|
||||
enable_error_code = "ignore-without-code"
|
||||
extra_checks = true
|
||||
follow_imports = "silent"
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ def testimage() -> None:
|
|||
('R', 'G', 'B')
|
||||
>>> im.getbbox()
|
||||
(0, 0, 128, 128)
|
||||
>>> len(im.get_flattened_data())
|
||||
>>> len(im.getdata())
|
||||
16384
|
||||
>>> im.getextrema()
|
||||
((0, 255), (0, 255), (0, 255))
|
||||
|
|
|
|||
9
setup.py
9
setup.py
|
|
@ -363,6 +363,7 @@ class pil_build_ext(build_ext):
|
|||
("disable-platform-guessing", None, "Disable platform guessing"),
|
||||
("debug", None, "Debug logging"),
|
||||
]
|
||||
+ [("add-imaging-libs=", None, "Add libs to _imaging build")]
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
|
|
@ -373,6 +374,7 @@ class pil_build_ext(build_ext):
|
|||
self.disable_platform_guessing = self.check_configuration(
|
||||
"platform-guessing", "disable"
|
||||
)
|
||||
self.add_imaging_libs = ""
|
||||
build_ext.initialize_options(self)
|
||||
for x in self.feature:
|
||||
setattr(self, f"disable_{x}", self.check_configuration(x, "disable"))
|
||||
|
|
@ -899,6 +901,7 @@ class pil_build_ext(build_ext):
|
|||
# core library
|
||||
|
||||
libs: list[str | bool | None] = []
|
||||
libs.extend(self.add_imaging_libs.split())
|
||||
defs: list[tuple[str, str | None]] = []
|
||||
if feature.get("tiff"):
|
||||
libs.append(feature.get("tiff"))
|
||||
|
|
@ -1089,11 +1092,7 @@ ext_modules = [
|
|||
Extension("PIL._webp", ["src/_webp.c"]),
|
||||
Extension("PIL._avif", ["src/_avif.c"]),
|
||||
Extension("PIL._imagingtk", ["src/_imagingtk.c", "src/Tk/tkImaging.c"]),
|
||||
Extension(
|
||||
"PIL._imagingmath",
|
||||
["src/_imagingmath.c"],
|
||||
libraries=None if sys.platform == "win32" else ["m"],
|
||||
),
|
||||
Extension("PIL._imagingmath", ["src/_imagingmath.c"]),
|
||||
Extension("PIL._imagingmorph", ["src/_imagingmorph.c"]),
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@
|
|||
"""
|
||||
Parse X Bitmap Distribution Format (BDF)
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import BinaryIO
|
||||
|
|
|
|||
|
|
@ -369,7 +369,7 @@ class BmpRleDecoder(ImageFile.PyDecoder):
|
|||
bytes_read = self.fd.read(2)
|
||||
if len(bytes_read) < 2:
|
||||
break
|
||||
right, up = bytes_read
|
||||
right, up = self.fd.read(2)
|
||||
data += b"\x00" * (right + up * self.state.xsize)
|
||||
x = len(data) % self.state.xsize
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -190,7 +190,7 @@ class EpsImageFile(ImageFile.ImageFile):
|
|||
|
||||
def _open(self) -> None:
|
||||
assert self.fp is not None
|
||||
length, offset = self._find_offset(self.fp)
|
||||
(length, offset) = self._find_offset(self.fp)
|
||||
|
||||
# go to offset - start of "%!PS"
|
||||
self.fp.seek(offset)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@
|
|||
This module provides constants and clear-text names for various
|
||||
well-known EXIF tags.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from enum import IntEnum
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ class FpxImageFile(ImageFile.ImageFile):
|
|||
|
||||
size = i32(s, 4), i32(s, 8)
|
||||
# tilecount = i32(s, 12)
|
||||
xtile, ytile = i32(s, 16), i32(s, 20)
|
||||
tilesize = i32(s, 16), i32(s, 20)
|
||||
# channels = i32(s, 24)
|
||||
offset = i32(s, 28)
|
||||
length = i32(s, 32)
|
||||
|
|
@ -156,6 +156,7 @@ class FpxImageFile(ImageFile.ImageFile):
|
|||
|
||||
x = y = 0
|
||||
xsize, ysize = size
|
||||
xtile, ytile = tilesize
|
||||
self.tile = []
|
||||
|
||||
for i in range(0, len(s), length):
|
||||
|
|
@ -223,7 +224,7 @@ class FpxImageFile(ImageFile.ImageFile):
|
|||
msg = "unknown/invalid compression"
|
||||
raise OSError(msg)
|
||||
|
||||
x += xtile
|
||||
x = x + xtile
|
||||
if x >= xsize:
|
||||
x, y = 0, y + ytile
|
||||
if y >= ysize:
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@
|
|||
implementation is provided for convenience and demonstrational
|
||||
purposes only.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import IO
|
||||
|
|
|
|||
|
|
@ -937,13 +937,7 @@ def _get_optimize(im: Image.Image, info: dict[str, Any]) -> list[int] | None:
|
|||
:param info: encoderinfo
|
||||
:returns: list of indexes of palette entries in use, or None
|
||||
"""
|
||||
if (
|
||||
im.mode in ("P", "L")
|
||||
and info
|
||||
and info.get("optimize")
|
||||
and im.width != 0
|
||||
and im.height != 0
|
||||
):
|
||||
if im.mode in ("P", "L") and info and info.get("optimize"):
|
||||
# Potentially expensive operation.
|
||||
|
||||
# The palette saves 3 bytes per color not used, but palette
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ Stuff to translate curve segments to palette values (derived from
|
|||
the corresponding code in GIMP, written by Federico Mena Quintero.
|
||||
See the GIMP distribution for more information.)
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from math import log, pi, sin, sqrt
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ def read_32t(
|
|||
fobj: IO[bytes], start_length: tuple[int, int], size: tuple[int, int, int]
|
||||
) -> dict[str, Image.Image]:
|
||||
# The 128x128 icon seems to have an extra header for some reason.
|
||||
start, length = start_length
|
||||
(start, length) = start_length
|
||||
fobj.seek(start)
|
||||
sig = fobj.read(4)
|
||||
if sig != b"\x00\x00\x00\x00":
|
||||
|
|
@ -58,7 +58,7 @@ def read_32(
|
|||
Read a 32bit RGB icon resource. Seems to be either uncompressed or
|
||||
an RLE packbits-like scheme.
|
||||
"""
|
||||
start, length = start_length
|
||||
(start, length) = start_length
|
||||
fobj.seek(start)
|
||||
pixel_size = (size[0] * size[2], size[1] * size[2])
|
||||
sizesq = pixel_size[0] * pixel_size[1]
|
||||
|
|
@ -111,7 +111,7 @@ def read_mk(
|
|||
def read_png_or_jpeg2000(
|
||||
fobj: IO[bytes], start_length: tuple[int, int], size: tuple[int, int, int]
|
||||
) -> dict[str, Image.Image]:
|
||||
start, length = start_length
|
||||
(start, length) = start_length
|
||||
fobj.seek(start)
|
||||
sig = fobj.read(12)
|
||||
|
||||
|
|
|
|||
158
src/PIL/Image.py
158
src/PIL/Image.py
|
|
@ -323,112 +323,10 @@ def getmodebands(mode: str) -> int:
|
|||
|
||||
_initialized = 0
|
||||
|
||||
# Mapping from file extension to plugin module name for lazy importing
|
||||
_EXTENSION_PLUGIN: dict[str, str] = {
|
||||
# Common formats (preinit)
|
||||
".bmp": "BmpImagePlugin",
|
||||
".dib": "BmpImagePlugin",
|
||||
".gif": "GifImagePlugin",
|
||||
".jfif": "JpegImagePlugin",
|
||||
".jpe": "JpegImagePlugin",
|
||||
".jpg": "JpegImagePlugin",
|
||||
".jpeg": "JpegImagePlugin",
|
||||
".pbm": "PpmImagePlugin",
|
||||
".pgm": "PpmImagePlugin",
|
||||
".pnm": "PpmImagePlugin",
|
||||
".ppm": "PpmImagePlugin",
|
||||
".pfm": "PpmImagePlugin",
|
||||
".png": "PngImagePlugin",
|
||||
".apng": "PngImagePlugin",
|
||||
# Less common formats (init)
|
||||
".avif": "AvifImagePlugin",
|
||||
".avifs": "AvifImagePlugin",
|
||||
".blp": "BlpImagePlugin",
|
||||
".bufr": "BufrStubImagePlugin",
|
||||
".cur": "CurImagePlugin",
|
||||
".dcx": "DcxImagePlugin",
|
||||
".dds": "DdsImagePlugin",
|
||||
".ps": "EpsImagePlugin",
|
||||
".eps": "EpsImagePlugin",
|
||||
".fit": "FitsImagePlugin",
|
||||
".fits": "FitsImagePlugin",
|
||||
".fli": "FliImagePlugin",
|
||||
".flc": "FliImagePlugin",
|
||||
".fpx": "FpxImagePlugin",
|
||||
".ftc": "FtexImagePlugin",
|
||||
".ftu": "FtexImagePlugin",
|
||||
".gbr": "GbrImagePlugin",
|
||||
".grib": "GribStubImagePlugin",
|
||||
".h5": "Hdf5StubImagePlugin",
|
||||
".hdf": "Hdf5StubImagePlugin",
|
||||
".icns": "IcnsImagePlugin",
|
||||
".ico": "IcoImagePlugin",
|
||||
".im": "ImImagePlugin",
|
||||
".iim": "IptcImagePlugin",
|
||||
".jp2": "Jpeg2KImagePlugin",
|
||||
".j2k": "Jpeg2KImagePlugin",
|
||||
".jpc": "Jpeg2KImagePlugin",
|
||||
".jpf": "Jpeg2KImagePlugin",
|
||||
".jpx": "Jpeg2KImagePlugin",
|
||||
".j2c": "Jpeg2KImagePlugin",
|
||||
".mic": "MicImagePlugin",
|
||||
".mpg": "MpegImagePlugin",
|
||||
".mpeg": "MpegImagePlugin",
|
||||
".mpo": "MpoImagePlugin",
|
||||
".msp": "MspImagePlugin",
|
||||
".palm": "PalmImagePlugin",
|
||||
".pcd": "PcdImagePlugin",
|
||||
".pcx": "PcxImagePlugin",
|
||||
".pdf": "PdfImagePlugin",
|
||||
".pxr": "PixarImagePlugin",
|
||||
".psd": "PsdImagePlugin",
|
||||
".qoi": "QoiImagePlugin",
|
||||
".bw": "SgiImagePlugin",
|
||||
".rgb": "SgiImagePlugin",
|
||||
".rgba": "SgiImagePlugin",
|
||||
".sgi": "SgiImagePlugin",
|
||||
".ras": "SunImagePlugin",
|
||||
".tga": "TgaImagePlugin",
|
||||
".icb": "TgaImagePlugin",
|
||||
".vda": "TgaImagePlugin",
|
||||
".vst": "TgaImagePlugin",
|
||||
".tif": "TiffImagePlugin",
|
||||
".tiff": "TiffImagePlugin",
|
||||
".webp": "WebPImagePlugin",
|
||||
".wmf": "WmfImagePlugin",
|
||||
".emf": "WmfImagePlugin",
|
||||
".xbm": "XbmImagePlugin",
|
||||
".xpm": "XpmImagePlugin",
|
||||
}
|
||||
|
||||
|
||||
def _import_plugin_for_extension(ext: str | bytes) -> bool:
|
||||
"""Import only the plugin needed for a specific file extension."""
|
||||
if not ext:
|
||||
return False
|
||||
|
||||
if isinstance(ext, bytes):
|
||||
ext = ext.decode()
|
||||
ext = ext.lower()
|
||||
if ext in EXTENSION:
|
||||
return True
|
||||
|
||||
plugin = _EXTENSION_PLUGIN.get(ext)
|
||||
if plugin is None:
|
||||
return False
|
||||
|
||||
try:
|
||||
logger.debug("Importing %s", plugin)
|
||||
__import__(f"{__spec__.parent}.{plugin}", globals(), locals(), [])
|
||||
return True
|
||||
except ImportError as e:
|
||||
logger.debug("Image: failed to import %s: %s", plugin, e)
|
||||
return False
|
||||
|
||||
|
||||
def preinit() -> None:
|
||||
"""
|
||||
Explicitly loads BMP, GIF, JPEG, PPM and PNG file format drivers.
|
||||
Explicitly loads BMP, GIF, JPEG, PPM and PPM file format drivers.
|
||||
|
||||
It is called when opening or saving images.
|
||||
"""
|
||||
|
|
@ -484,10 +382,11 @@ def init() -> bool:
|
|||
if _initialized >= 2:
|
||||
return False
|
||||
|
||||
parent_name = __name__.rpartition(".")[0]
|
||||
for plugin in _plugins:
|
||||
try:
|
||||
logger.debug("Importing %s", plugin)
|
||||
__import__(f"{__spec__.parent}.{plugin}", globals(), locals(), [])
|
||||
__import__(f"{parent_name}.{plugin}", globals(), locals(), [])
|
||||
except ImportError as e:
|
||||
logger.debug("Image: failed to import %s: %s", plugin, e)
|
||||
|
||||
|
|
@ -993,9 +892,7 @@ class Image:
|
|||
else:
|
||||
self.im.putpalettealphas(self.info["transparency"])
|
||||
self.palette.mode = "RGBA"
|
||||
elif self.palette.mode != mode:
|
||||
# If the palette rawmode is different to the mode,
|
||||
# then update the Python palette data
|
||||
else:
|
||||
self.palette.palette = self.im.getpalette(
|
||||
self.palette.mode, self.palette.mode
|
||||
)
|
||||
|
|
@ -2546,7 +2443,7 @@ class Image:
|
|||
]
|
||||
|
||||
def transform(x: float, y: float, matrix: list[float]) -> tuple[float, float]:
|
||||
a, b, c, d, e, f = matrix
|
||||
(a, b, c, d, e, f) = matrix
|
||||
return a * x + b * y + c, d * x + e * y + f
|
||||
|
||||
matrix[2], matrix[5] = transform(
|
||||
|
|
@ -2636,20 +2533,12 @@ class Image:
|
|||
# only set the name for metadata purposes
|
||||
filename = os.fspath(fp.name)
|
||||
|
||||
if format:
|
||||
preinit()
|
||||
else:
|
||||
filename_ext = os.path.splitext(filename)[1].lower()
|
||||
ext = (
|
||||
filename_ext.decode()
|
||||
if isinstance(filename_ext, bytes)
|
||||
else filename_ext
|
||||
)
|
||||
preinit()
|
||||
|
||||
# Try importing only the plugin for this extension first
|
||||
if not _import_plugin_for_extension(ext):
|
||||
preinit()
|
||||
filename_ext = os.path.splitext(filename)[1].lower()
|
||||
ext = filename_ext.decode() if isinstance(filename_ext, bytes) else filename_ext
|
||||
|
||||
if not format:
|
||||
if ext not in EXTENSION:
|
||||
init()
|
||||
try:
|
||||
|
|
@ -3489,7 +3378,7 @@ def fromarrow(
|
|||
msg = "arrow_c_array interface not found"
|
||||
raise ValueError(msg)
|
||||
|
||||
schema_capsule, array_capsule = obj.__arrow_c_array__()
|
||||
(schema_capsule, array_capsule) = obj.__arrow_c_array__()
|
||||
_im = core.new_arrow(mode, size, schema_capsule, array_capsule)
|
||||
if _im:
|
||||
return Image()._new(_im)
|
||||
|
|
@ -3633,11 +3522,7 @@ def open(
|
|||
|
||||
prefix = fp.read(16)
|
||||
|
||||
# Try to import just the plugin needed for this file extension
|
||||
# before falling back to preinit() which imports common plugins
|
||||
ext = os.path.splitext(filename)[1] if filename else ""
|
||||
if not _import_plugin_for_extension(ext):
|
||||
preinit()
|
||||
preinit()
|
||||
|
||||
warning_messages: list[str] = []
|
||||
|
||||
|
|
@ -3673,19 +3558,14 @@ def open(
|
|||
im = _open_core(fp, filename, prefix, formats)
|
||||
|
||||
if im is None and formats is ID:
|
||||
# Try preinit (few common plugins) then init (all plugins)
|
||||
for loader in (preinit, init):
|
||||
checked_formats = ID.copy()
|
||||
loader()
|
||||
if formats != checked_formats:
|
||||
im = _open_core(
|
||||
fp,
|
||||
filename,
|
||||
prefix,
|
||||
tuple(f for f in formats if f not in checked_formats),
|
||||
)
|
||||
if im is not None:
|
||||
break
|
||||
checked_formats = ID.copy()
|
||||
if init():
|
||||
im = _open_core(
|
||||
fp,
|
||||
filename,
|
||||
prefix,
|
||||
tuple(format for format in formats if format not in checked_formats),
|
||||
)
|
||||
|
||||
if im:
|
||||
im._exclusive_fp = exclusive_fp
|
||||
|
|
|
|||
|
|
@ -487,7 +487,7 @@ class ImageDraw:
|
|||
|
||||
if full_x:
|
||||
self.draw.draw_rectangle((x0, y0 + r + 1, x1, y1 - r - 1), fill_ink, 1)
|
||||
elif x1 - r - 1 >= x0 + r + 1:
|
||||
elif x1 - r - 1 > x0 + r + 1:
|
||||
self.draw.draw_rectangle((x0 + r + 1, y0, x1 - r - 1, y1), fill_ink, 1)
|
||||
if not full_x and not full_y:
|
||||
left = [x0, y0, x0 + r, y1]
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@
|
|||
|
||||
.. seealso:: :py:mod:`PIL.ImageDraw`
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, AnyStr, BinaryIO
|
||||
|
|
@ -118,7 +117,7 @@ class Draw:
|
|||
|
||||
def settransform(self, offset: tuple[float, float]) -> None:
|
||||
"""Sets a transformation offset."""
|
||||
xoffset, yoffset = offset
|
||||
(xoffset, yoffset) = offset
|
||||
self.transform = (1, 0, xoffset, 0, 1, yoffset)
|
||||
|
||||
def arc(
|
||||
|
|
|
|||
|
|
@ -579,7 +579,10 @@ class Parser:
|
|||
pass # not enough data
|
||||
else:
|
||||
flag = hasattr(im, "load_seek") or hasattr(im, "load_read")
|
||||
if not flag and len(im.tile) == 1:
|
||||
if flag or len(im.tile) != 1:
|
||||
# custom load code, or multiple tiles
|
||||
self.decode = None
|
||||
else:
|
||||
# initialize decoder
|
||||
im.load_prepare()
|
||||
d, e, o, a = im.tile[0]
|
||||
|
|
@ -798,9 +801,9 @@ class PyCodec:
|
|||
self.im = im
|
||||
|
||||
if extents:
|
||||
x0, y0, x1, y1 = extents
|
||||
(x0, y0, x1, y1) = extents
|
||||
else:
|
||||
x0, y0, x1, y1 = (0, 0, 0, 0)
|
||||
(x0, y0, x1, y1) = (0, 0, 0, 0)
|
||||
|
||||
if x0 == 0 and x1 == 0:
|
||||
self.state.xsize, self.state.ysize = self.im.size
|
||||
|
|
@ -811,7 +814,7 @@ class PyCodec:
|
|||
self.state.ysize = y1 - y0
|
||||
|
||||
if self.state.xsize <= 0 or self.state.ysize <= 0:
|
||||
msg = "Size must be positive"
|
||||
msg = "Size cannot be negative"
|
||||
raise ValueError(msg)
|
||||
|
||||
if (
|
||||
|
|
|
|||
|
|
@ -940,7 +940,9 @@ def load_default_imagefont() -> ImageFont:
|
|||
f = ImageFont()
|
||||
f._load_pilfont_data(
|
||||
# courB08
|
||||
BytesIO(base64.b64decode(b"""
|
||||
BytesIO(
|
||||
base64.b64decode(
|
||||
b"""
|
||||
UElMZm9udAo7Ozs7OzsxMDsKREFUQQoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
|
|
@ -1032,8 +1034,13 @@ AJsAEQAGAAAAAP/6AAX//wCbAAoAoAAPAAYAAAAA//oABQABAKAACgClABEABgAA////+AAGAAAA
|
|||
pQAKAKwAEgAGAAD////4AAYAAACsAAoAswASAAYAAP////gABgAAALMACgC6ABIABgAA////+QAG
|
||||
AAAAugAKAMEAEQAGAAD////4AAYAAgDBAAoAyAAUAAYAAP////kABQACAMgACgDOABMABgAA////
|
||||
+QAGAAIAzgAKANUAEw==
|
||||
""")),
|
||||
Image.open(BytesIO(base64.b64decode(b"""
|
||||
"""
|
||||
)
|
||||
),
|
||||
Image.open(
|
||||
BytesIO(
|
||||
base64.b64decode(
|
||||
b"""
|
||||
iVBORw0KGgoAAAANSUhEUgAAAx4AAAAUAQAAAAArMtZoAAAEwElEQVR4nABlAJr/AHVE4czCI/4u
|
||||
Mc4b7vuds/xzjz5/3/7u/n9vMe7vnfH/9++vPn/xyf5zhxzjt8GHw8+2d83u8x27199/nxuQ6Od9
|
||||
M43/5z2I+9n9ZtmDBwMQECDRQw/eQIQohJXxpBCNVE6QCCAAAAD//wBlAJr/AgALyj1t/wINwq0g
|
||||
|
|
@ -1057,7 +1064,10 @@ evta/58PTEWzr21hufPjA8N+qlnBwAAAAAD//2JiWLci5v1+HmFXDqcnULE/MxgYGBj+f6CaJQAA
|
|||
AAD//2Ji2FrkY3iYpYC5qDeGgeEMAwPDvwQBBoYvcTwOVLMEAAAA//9isDBgkP///0EOg9z35v//
|
||||
Gc/eeW7BwPj5+QGZhANUswMAAAD//2JgqGBgYGBgqEMXlvhMPUsAAAAA//8iYDd1AAAAAP//AwDR
|
||||
w7IkEbzhVQAAAABJRU5ErkJggg==
|
||||
"""))),
|
||||
"""
|
||||
)
|
||||
)
|
||||
),
|
||||
)
|
||||
return f
|
||||
|
||||
|
|
@ -1078,7 +1088,9 @@ def load_default(size: float | None = None) -> FreeTypeFont | ImageFont:
|
|||
"""
|
||||
if isinstance(core, ModuleType) or size is not None:
|
||||
return truetype(
|
||||
BytesIO(base64.b64decode(b"""
|
||||
BytesIO(
|
||||
base64.b64decode(
|
||||
b"""
|
||||
AAEAAAAPAIAAAwBwRkZUTYwDlUAAADFoAAAAHEdERUYAqADnAAAo8AAAACRHUE9ThhmITwAAKfgAA
|
||||
AduR1NVQnHxefoAACkUAAAA4k9TLzJovoHLAAABeAAAAGBjbWFw5lFQMQAAA6gAAAGqZ2FzcP//AA
|
||||
MAACjoAAAACGdseWYmRXoPAAAGQAAAHfhoZWFkE18ayQAAAPwAAAA2aGhlYQboArEAAAE0AAAAJGh
|
||||
|
|
@ -1299,7 +1311,9 @@ ABUADgAPAAAACwAQAAAAAAAAAAAAAAAAAAUAGAACAAIAAgAAAAIAGAAXAAAAGAAAABYAFgACABYAA
|
|||
gAWAAAAEQADAAoAFAAMAA0ABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAASAAAAEgAGAAEAHgAkAC
|
||||
YAJwApACoALQAuAC8AMgAzADcAOAA5ADoAPAA9AEUASABOAE8AUgBTAFUAVwBZAFoAWwBcAF0AcwA
|
||||
AAAAAAQAAAADa3tfFAAAAANAan9kAAAAA4QodoQ==
|
||||
""")),
|
||||
"""
|
||||
)
|
||||
),
|
||||
10 if size is None else size,
|
||||
layout_engine=Layout.BASIC,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ class MspDecoder(ImageFile.PyDecoder):
|
|||
runtype = row[idx]
|
||||
idx += 1
|
||||
if runtype == 0:
|
||||
runcount, runval = struct.unpack_from("Bc", row, idx)
|
||||
(runcount, runval) = struct.unpack_from("Bc", row, idx)
|
||||
img.write(runval * runcount)
|
||||
idx += 2
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -100,8 +100,7 @@ class PSDraw:
|
|||
Draws text at the given position. You must use
|
||||
:py:meth:`~PIL.PSDraw.PSDraw.setfont` before calling this method.
|
||||
"""
|
||||
# The font is loaded as ISOLatin1Encoding, so use latin-1 here.
|
||||
text_bytes = bytes(text, "latin-1")
|
||||
text_bytes = bytes(text, "UTF-8")
|
||||
text_bytes = b"\\(".join(text_bytes.split(b"("))
|
||||
text_bytes = b"\\)".join(text_bytes.split(b")"))
|
||||
self.fp.write(b"%d %d M (%s) S\n" % (xy + (text_bytes,)))
|
||||
|
|
|
|||
|
|
@ -210,8 +210,8 @@ def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
|
|||
#
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
Image.register_save("PALM", _save)
|
||||
Image.register_save("Palm", _save)
|
||||
|
||||
Image.register_extension("PALM", ".palm")
|
||||
Image.register_extension("Palm", ".palm")
|
||||
|
||||
Image.register_mime("PALM", "image/palm")
|
||||
Image.register_mime("Palm", "image/palm")
|
||||
|
|
|
|||
|
|
@ -146,10 +146,6 @@ SAVE = {
|
|||
|
||||
|
||||
def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
|
||||
if im.width == 0 or im.height == 0:
|
||||
msg = "Cannot write empty image as PCX"
|
||||
raise ValueError(msg)
|
||||
|
||||
try:
|
||||
version, bits, planes, rawmode = SAVE[im.mode]
|
||||
except KeyError as e:
|
||||
|
|
|
|||
|
|
@ -244,7 +244,7 @@ def loadImageSeries(filelist: list[str] | None = None) -> list[Image.Image] | No
|
|||
|
||||
def makeSpiderHeader(im: Image.Image) -> list[bytes]:
|
||||
nsam, nrow = im.size
|
||||
lenbyt = max(1, nsam) * 4 # There are labrec records in the header
|
||||
lenbyt = nsam * 4 # There are labrec records in the header
|
||||
labrec = int(1024 / lenbyt)
|
||||
if 1024 % lenbyt != 0:
|
||||
labrec += 1
|
||||
|
|
@ -290,9 +290,9 @@ def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
|
|||
|
||||
def _save_spider(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
|
||||
# get the filename extension and register it with Image
|
||||
if filename_ext := os.path.splitext(filename)[1]:
|
||||
ext = filename_ext.decode() if isinstance(filename_ext, bytes) else filename_ext
|
||||
Image.register_extension(SpiderImageFile.format, ext)
|
||||
filename_ext = os.path.splitext(filename)[1]
|
||||
ext = filename_ext.decode() if isinstance(filename_ext, bytes) else filename_ext
|
||||
Image.register_extension(SpiderImageFile.format, ext)
|
||||
_save(im, fp, filename)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ and has been tested with a few sample files found using google.
|
|||
is not registered for use with :py:func:`PIL.Image.open()`.
|
||||
To open a WAL file, use the :py:func:`PIL.WalImageFile.open()` function instead.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import IO
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ if hasattr(Image.core, "drawwmf"):
|
|||
|
||||
class WmfHandler(ImageFile.StubHandler):
|
||||
def open(self, im: ImageFile.StubImageFile) -> None:
|
||||
im._mode = "RGB"
|
||||
self.bbox = im.info["wmf_bbox"]
|
||||
|
||||
def load(self, im: ImageFile.StubImageFile) -> Image.Image:
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@
|
|||
|
||||
|
||||
"""Binary input/output support routines."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from struct import pack, unpack_from
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
# Master version for Pillow
|
||||
from __future__ import annotations
|
||||
|
||||
__version__ = "12.2.0.dev0"
|
||||
__version__ = "12.1.1"
|
||||
|
|
|
|||
|
|
@ -485,7 +485,7 @@ _encoder_add(AvifEncoderObject *self, PyObject *args) {
|
|||
frame = image;
|
||||
} else {
|
||||
frame = avifImageCreateEmpty();
|
||||
if (frame == NULL) {
|
||||
if (image == NULL) {
|
||||
PyErr_SetString(PyExc_ValueError, "Image creation failed");
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -116,17 +116,17 @@ V = {
|
|||
"BROTLI": "1.2.0",
|
||||
"FREETYPE": "2.14.1",
|
||||
"FRIBIDI": "1.0.16",
|
||||
"HARFBUZZ": "12.3.2",
|
||||
"HARFBUZZ": "12.3.0",
|
||||
"JPEGTURBO": "3.1.3",
|
||||
"LCMS2": "2.18",
|
||||
"LCMS2": "2.17",
|
||||
"LIBAVIF": "1.3.0",
|
||||
"LIBIMAGEQUANT": "4.4.1",
|
||||
"LIBPNG": "1.6.54",
|
||||
"LIBPNG": "1.6.53",
|
||||
"LIBWEBP": "1.6.0",
|
||||
"OPENJPEG": "2.5.4",
|
||||
"TIFF": "4.7.1",
|
||||
"XZ": "5.8.2",
|
||||
"ZLIBNG": "2.3.3",
|
||||
"ZLIBNG": "2.3.2",
|
||||
}
|
||||
V["LIBPNG_XY"] = "".join(V["LIBPNG"].split(".")[:2])
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user