Merge branch 'main' into debug-build
|
@ -18,7 +18,7 @@ environment:
|
|||
TEST_OPTIONS:
|
||||
DEPLOY: YES
|
||||
matrix:
|
||||
- PYTHON: C:/Python312
|
||||
- PYTHON: C:/Python313
|
||||
ARCHITECTURE: x86
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022
|
||||
- PYTHON: C:/Python39-x64
|
||||
|
@ -34,8 +34,8 @@ install:
|
|||
- xcopy /S /Y c:\test-images-main\* c:\pillow\tests\images
|
||||
- curl -fsSL -o nasm-win64.zip https://raw.githubusercontent.com/python-pillow/pillow-depends/main/nasm-2.16.03-win64.zip
|
||||
- 7z x nasm-win64.zip -oc:\
|
||||
- choco install ghostscript --version=10.3.1
|
||||
- path c:\nasm-2.16.03;C:\Program Files\gs\gs10.03.1\bin;%PATH%
|
||||
- choco install ghostscript --version=10.4.0
|
||||
- path c:\nasm-2.16.03;C:\Program Files\gs\gs10.04.0\bin;%PATH%
|
||||
- cd c:\pillow\winbuild\
|
||||
- ps: |
|
||||
c:\python39\python.exe c:\pillow\winbuild\build_prepare.py -v --depends=C:\pillow-depends\
|
||||
|
@ -51,11 +51,10 @@ build_script:
|
|||
|
||||
test_script:
|
||||
- cd c:\pillow
|
||||
- '%PYTHON%\%EXECUTABLE% -m pip install pytest pytest-cov pytest-timeout defusedxml numpy olefile pyroma'
|
||||
- '%PYTHON%\%EXECUTABLE% -m pip install pytest pytest-cov pytest-timeout defusedxml ipython numpy olefile pyroma'
|
||||
- c:\"Program Files (x86)"\"Windows Kits"\10\Debuggers\x86\gflags.exe /p /enable %PYTHON%\%EXECUTABLE%
|
||||
- '%PYTHON%\%EXECUTABLE% -c "from PIL import Image"'
|
||||
- '%PYTHON%\%EXECUTABLE% -m pytest -vx --cov PIL --cov Tests --cov-report term --cov-report xml Tests'
|
||||
#- '%PYTHON%\%EXECUTABLE% test-installed.py -v -s %TEST_OPTIONS%' TODO TEST_OPTIONS with pytest?
|
||||
- path %PYTHON%;%PATH%
|
||||
- .ci\test.cmd
|
||||
|
||||
after_test:
|
||||
- curl -Os https://uploader.codecov.io/latest/windows/codecov.exe
|
||||
|
|
|
@ -21,7 +21,7 @@ set -e
|
|||
|
||||
if [[ $(uname) != CYGWIN* ]]; then
|
||||
sudo apt-get -qq install libfreetype6-dev liblcms2-dev python3-tk\
|
||||
ghostscript libffi-dev libjpeg-turbo-progs libopenjp2-7-dev\
|
||||
ghostscript libjpeg-turbo-progs libopenjp2-7-dev\
|
||||
cmake meson imagemagick libharfbuzz-dev libfribidi-dev\
|
||||
sway wl-clipboard libopenblas-dev
|
||||
fi
|
||||
|
@ -30,6 +30,7 @@ python3 -m pip install --upgrade pip
|
|||
python3 -m pip install --upgrade wheel
|
||||
python3 -m pip install coverage
|
||||
python3 -m pip install defusedxml
|
||||
python3 -m pip install ipython
|
||||
python3 -m pip install olefile
|
||||
python3 -m pip install -U pytest
|
||||
python3 -m pip install -U pytest-cov
|
||||
|
@ -37,12 +38,7 @@ python3 -m pip install -U pytest-timeout
|
|||
python3 -m pip install pyroma
|
||||
|
||||
if [[ $(uname) != CYGWIN* ]]; then
|
||||
# TODO Update condition when NumPy supports free-threading
|
||||
if [[ "$PYTHON_GIL" == "0" ]]; then
|
||||
python3 -m pip install numpy --index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple
|
||||
else
|
||||
python3 -m pip install numpy
|
||||
fi
|
||||
python3 -m pip install numpy
|
||||
|
||||
# PyQt6 doesn't support PyPy3
|
||||
if [[ $GHA_PYTHON_VERSION == 3.* ]]; then
|
||||
|
@ -52,10 +48,7 @@ if [[ $(uname) != CYGWIN* ]]; then
|
|||
fi
|
||||
|
||||
# Pyroma uses non-isolated build and fails with old setuptools
|
||||
if [[
|
||||
$GHA_PYTHON_VERSION == pypy3.9
|
||||
|| $GHA_PYTHON_VERSION == 3.9
|
||||
]]; then
|
||||
if [[ $GHA_PYTHON_VERSION == 3.9 ]]; then
|
||||
# To match pyproject.toml
|
||||
python3 -m pip install "setuptools>=67.8"
|
||||
fi
|
||||
|
|
|
@ -1 +1 @@
|
|||
cibuildwheel==2.19.2
|
||||
cibuildwheel==2.21.3
|
||||
|
|
|
@ -1 +1,12 @@
|
|||
mypy==1.11.0
|
||||
mypy==1.13.0
|
||||
IceSpringPySideStubs-PyQt6
|
||||
IceSpringPySideStubs-PySide6
|
||||
ipython
|
||||
numpy
|
||||
packaging
|
||||
pytest
|
||||
sphinx
|
||||
types-atheris
|
||||
types-defusedxml
|
||||
types-olefile
|
||||
types-setuptools
|
||||
|
|
3
.ci/test.cmd
Normal file
|
@ -0,0 +1,3 @@
|
|||
python.exe -c "from PIL import Image"
|
||||
IF ERRORLEVEL 1 EXIT /B
|
||||
python.exe -bb -m pytest -v -x -W always --cov PIL --cov Tests --cov-report term --cov-report xml Tests
|
|
@ -4,4 +4,4 @@ set -e
|
|||
|
||||
python3 -c "from PIL import Image"
|
||||
|
||||
python3 -bb -m pytest -v -x -W always --cov PIL --cov Tests --cov-report term Tests $REVERSE
|
||||
python3 -bb -m pytest -v -x -W always --cov PIL --cov Tests --cov-report term --cov-report xml Tests $REVERSE
|
||||
|
|
1
.github/CONTRIBUTING.md
vendored
|
@ -19,7 +19,6 @@ Please send a pull request to the `main` branch. Please include [documentation](
|
|||
- Follow PEP 8.
|
||||
- When committing only documentation changes please include `[ci skip]` in the commit message to avoid running tests on AppVeyor.
|
||||
- Include [release notes](https://github.com/python-pillow/Pillow/tree/main/docs/releasenotes) as needed or appropriate with your bug fixes, feature additions and tests.
|
||||
- Do not add to the [changelog](https://github.com/python-pillow/Pillow/blob/main/CHANGES.rst) for proposed changes, as that is updated after changes are merged.
|
||||
|
||||
## Reporting Issues
|
||||
|
||||
|
|
11
.github/release-drafter.yml
vendored
|
@ -3,18 +3,19 @@ tag-template: "$NEXT_MINOR_VERSION"
|
|||
change-template: '- $TITLE #$NUMBER [@$AUTHOR]'
|
||||
|
||||
categories:
|
||||
- title: "Dependencies"
|
||||
label: "Dependency"
|
||||
- title: "Removals"
|
||||
label: "Removal"
|
||||
- title: "Deprecations"
|
||||
label: "Deprecation"
|
||||
- title: "Documentation"
|
||||
label: "Documentation"
|
||||
- title: "Removals"
|
||||
label: "Removal"
|
||||
- title: "Dependencies"
|
||||
label: "Dependency"
|
||||
- title: "Testing"
|
||||
label: "Testing"
|
||||
- title: "Type hints"
|
||||
label: "Type hints"
|
||||
- title: "Other changes"
|
||||
|
||||
exclude-labels:
|
||||
- "changelog: skip"
|
||||
|
@ -23,6 +24,4 @@ template: |
|
|||
|
||||
https://pillow.readthedocs.io/en/stable/releasenotes/$NEXT_MINOR_VERSION.html
|
||||
|
||||
## Changes
|
||||
|
||||
$CHANGES
|
||||
|
|
12
.github/renovate.json
vendored
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||
"extends": [
|
||||
"config:base"
|
||||
"config:recommended"
|
||||
],
|
||||
"labels": [
|
||||
"Dependency"
|
||||
|
@ -9,9 +9,13 @@
|
|||
"packageRules": [
|
||||
{
|
||||
"groupName": "github-actions",
|
||||
"matchManagers": ["github-actions"],
|
||||
"separateMajorMinor": "false"
|
||||
"matchManagers": [
|
||||
"github-actions"
|
||||
],
|
||||
"separateMajorMinor": false
|
||||
}
|
||||
],
|
||||
"schedule": ["on the 3rd day of the month"]
|
||||
"schedule": [
|
||||
"on the 3rd day of the month"
|
||||
]
|
||||
}
|
||||
|
|
4
.github/workflows/cifuzz.yml
vendored
|
@ -6,11 +6,13 @@ on:
|
|||
- "**"
|
||||
paths:
|
||||
- ".github/workflows/cifuzz.yml"
|
||||
- ".github/workflows/wheels-dependencies.sh"
|
||||
- "**.c"
|
||||
- "**.h"
|
||||
pull_request:
|
||||
paths:
|
||||
- ".github/workflows/cifuzz.yml"
|
||||
- ".github/workflows/wheels-dependencies.sh"
|
||||
- "**.c"
|
||||
- "**.h"
|
||||
workflow_dispatch:
|
||||
|
@ -24,8 +26,6 @@ concurrency:
|
|||
|
||||
jobs:
|
||||
Fuzzing:
|
||||
# Disabled until google/oss-fuzz#11419 upgrades Python to 3.9+
|
||||
if: false
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Build Fuzzers
|
||||
|
|
2
.github/workflows/docs.yml
vendored
|
@ -33,6 +33,8 @@ jobs:
|
|||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v5
|
||||
|
|
2
.github/workflows/lint.yml
vendored
|
@ -21,6 +21,8 @@ jobs:
|
|||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: pre-commit cache
|
||||
uses: actions/cache@v4
|
||||
|
|
4
.github/workflows/macos-install.sh
vendored
|
@ -2,6 +2,9 @@
|
|||
|
||||
set -e
|
||||
|
||||
if [[ "$ImageOS" == "macos13" ]]; then
|
||||
brew uninstall gradle maven
|
||||
fi
|
||||
brew install \
|
||||
freetype \
|
||||
ghostscript \
|
||||
|
@ -20,6 +23,7 @@ export PKG_CONFIG_PATH="/usr/local/opt/openblas/lib/pkgconfig"
|
|||
|
||||
python3 -m pip install coverage
|
||||
python3 -m pip install defusedxml
|
||||
python3 -m pip install ipython
|
||||
python3 -m pip install olefile
|
||||
python3 -m pip install -U pytest
|
||||
python3 -m pip install -U pytest-cov
|
||||
|
|
4
.github/workflows/stale.yml
vendored
|
@ -6,7 +6,7 @@ on:
|
|||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
issues: write
|
||||
contents: read
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
|
@ -15,6 +15,8 @@ concurrency:
|
|||
jobs:
|
||||
stale:
|
||||
if: github.repository_owner == 'python-pillow'
|
||||
permissions:
|
||||
issues: write
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
|
|
8
.github/workflows/test-cygwin.yml
vendored
|
@ -48,6 +48,8 @@ jobs:
|
|||
|
||||
- name: Checkout Pillow
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Install Cygwin
|
||||
uses: cygwin/cygwin-install-action@v4
|
||||
|
@ -74,6 +76,7 @@ jobs:
|
|||
perl
|
||||
python3${{ matrix.python-minor-version }}-cython
|
||||
python3${{ matrix.python-minor-version }}-devel
|
||||
python3${{ matrix.python-minor-version }}-ipython
|
||||
python3${{ matrix.python-minor-version }}-numpy
|
||||
python3${{ matrix.python-minor-version }}-sip
|
||||
python3${{ matrix.python-minor-version }}-tkinter
|
||||
|
@ -130,11 +133,12 @@ jobs:
|
|||
- name: After success
|
||||
run: |
|
||||
bash.exe .ci/after_success.sh
|
||||
rm C:\cygwin\bin\bash.EXE
|
||||
|
||||
- name: Upload coverage
|
||||
uses: codecov/codecov-action@v4
|
||||
uses: codecov/codecov-action@v5
|
||||
with:
|
||||
file: ./coverage.xml
|
||||
files: ./coverage.xml
|
||||
flags: GHA_Cygwin
|
||||
name: Cygwin Python 3.${{ matrix.python-minor-version }}
|
||||
token: ${{ secrets.CODECOV_ORG_TOKEN }}
|
||||
|
|
7
.github/workflows/test-docker.yml
vendored
|
@ -46,8 +46,8 @@ jobs:
|
|||
centos-stream-9-amd64,
|
||||
debian-12-bookworm-x86,
|
||||
debian-12-bookworm-amd64,
|
||||
fedora-39-amd64,
|
||||
fedora-40-amd64,
|
||||
fedora-41-amd64,
|
||||
gentoo,
|
||||
ubuntu-22.04-jammy-amd64,
|
||||
ubuntu-24.04-noble-amd64,
|
||||
|
@ -65,6 +65,8 @@ jobs:
|
|||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Build system information
|
||||
run: python3 .github/workflows/system-info.py
|
||||
|
@ -98,11 +100,10 @@ jobs:
|
|||
MATRIX_DOCKER: ${{ matrix.docker }}
|
||||
|
||||
- name: Upload coverage
|
||||
uses: codecov/codecov-action@v4
|
||||
uses: codecov/codecov-action@v5
|
||||
with:
|
||||
flags: GHA_Docker
|
||||
name: ${{ matrix.docker }}
|
||||
gcov: true
|
||||
token: ${{ secrets.CODECOV_ORG_TOKEN }}
|
||||
|
||||
success:
|
||||
|
|
19
.github/workflows/test-mingw.yml
vendored
|
@ -46,6 +46,8 @@ jobs:
|
|||
steps:
|
||||
- name: Checkout Pillow
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Set up shell
|
||||
run: echo "C:\msys64\usr\bin\" >> $env:GITHUB_PATH
|
||||
|
@ -66,27 +68,26 @@ jobs:
|
|||
mingw-w64-x86_64-openjpeg2 \
|
||||
mingw-w64-x86_64-python3-numpy \
|
||||
mingw-w64-x86_64-python3-olefile \
|
||||
mingw-w64-x86_64-python3-setuptools \
|
||||
mingw-w64-x86_64-python3-pip \
|
||||
mingw-w64-x86_64-python-pytest \
|
||||
mingw-w64-x86_64-python-pytest-cov \
|
||||
mingw-w64-x86_64-python-pytest-timeout \
|
||||
mingw-w64-x86_64-python-pyqt6
|
||||
|
||||
python3 -m ensurepip
|
||||
python3 -m pip install pyroma pytest pytest-cov pytest-timeout
|
||||
|
||||
pushd depends && ./install_extra_test_images.sh && popd
|
||||
|
||||
- name: Build Pillow
|
||||
run: SETUPTOOLS_USE_DISTUTILS="stdlib" CFLAGS="-coverage" python3 -m pip install .
|
||||
run: CFLAGS="-coverage" python3 -m pip install .
|
||||
|
||||
- name: Test Pillow
|
||||
run: |
|
||||
python3 selftest.py --installed
|
||||
python3 -c "from PIL import Image"
|
||||
python3 -m pytest -vx --cov PIL --cov Tests --cov-report term --cov-report xml Tests
|
||||
.ci/test.sh
|
||||
|
||||
- name: Upload coverage
|
||||
uses: codecov/codecov-action@v4
|
||||
uses: codecov/codecov-action@v5
|
||||
with:
|
||||
file: ./coverage.xml
|
||||
files: ./coverage.xml
|
||||
flags: GHA_Windows
|
||||
name: "MSYS2 MinGW"
|
||||
token: ${{ secrets.CODECOV_ORG_TOKEN }}
|
||||
|
|
2
.github/workflows/test-valgrind.yml
vendored
|
@ -40,6 +40,8 @@ jobs:
|
|||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Build system information
|
||||
run: python3 .github/workflows/system-info.py
|
||||
|
|
38
.github/workflows/test-windows.yml
vendored
|
@ -35,7 +35,7 @@ jobs:
|
|||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
python-version: ["pypy3.10", "pypy3.9", "3.9", "3.10", "3.11", "3.12", "3.13"]
|
||||
python-version: ["pypy3.10", "3.9", "3.10", "3.11", "3.12", "3.13"]
|
||||
|
||||
timeout-minutes: 30
|
||||
|
||||
|
@ -44,16 +44,20 @@ jobs:
|
|||
steps:
|
||||
- name: Checkout Pillow
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Checkout cached dependencies
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
persist-credentials: false
|
||||
repository: python-pillow/pillow-depends
|
||||
path: winbuild\depends
|
||||
|
||||
- name: Checkout extra test images
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
persist-credentials: false
|
||||
repository: python-pillow/test-images
|
||||
path: Tests\test-images
|
||||
|
||||
|
@ -69,16 +73,14 @@ jobs:
|
|||
- name: Print build system information
|
||||
run: python3 .github/workflows/system-info.py
|
||||
|
||||
- name: Install Python dependencies
|
||||
run: >
|
||||
python3 -m pip install
|
||||
coverage>=7.4.2
|
||||
defusedxml
|
||||
olefile
|
||||
pyroma
|
||||
pytest
|
||||
pytest-cov
|
||||
pytest-timeout
|
||||
- name: Upgrade pip
|
||||
run: |
|
||||
python3 -m pip install --upgrade pip
|
||||
|
||||
- name: Install CPython dependencies
|
||||
if: "!contains(matrix.python-version, 'pypy')"
|
||||
run: |
|
||||
python3 -m pip install PyQt6
|
||||
|
||||
- name: Install dependencies
|
||||
id: install
|
||||
|
@ -86,8 +88,8 @@ jobs:
|
|||
choco install nasm --no-progress
|
||||
echo "C:\Program Files\NASM" >> $env:GITHUB_PATH
|
||||
|
||||
choco install ghostscript --version=10.3.1 --no-progress
|
||||
echo "C:\Program Files\gs\gs10.00.0\bin" >> $env:GITHUB_PATH
|
||||
choco install ghostscript --version=10.4.0 --no-progress
|
||||
echo "C:\Program Files\gs\gs10.04.0\bin" >> $env:GITHUB_PATH
|
||||
|
||||
# Install extra test images
|
||||
xcopy /S /Y Tests\test-images\* Tests\images
|
||||
|
@ -178,7 +180,7 @@ jobs:
|
|||
- name: Build Pillow
|
||||
run: |
|
||||
$FLAGS="-C raqm=vendor -C fribidi=vendor"
|
||||
cmd /c "winbuild\build\build_env.cmd && $env:pythonLocation\python.exe -m pip install -v $FLAGS ."
|
||||
cmd /c "winbuild\build\build_env.cmd && $env:pythonLocation\python.exe -m pip install -v $FLAGS .[tests]"
|
||||
& $env:pythonLocation\python.exe selftest.py --installed
|
||||
shell: pwsh
|
||||
|
||||
|
@ -190,8 +192,8 @@ jobs:
|
|||
|
||||
- name: Test Pillow
|
||||
run: |
|
||||
path %GITHUB_WORKSPACE%\\winbuild\\build\\bin;%PATH%
|
||||
python.exe -m pytest -vx -W always --cov PIL --cov Tests --cov-report term --cov-report xml Tests
|
||||
path %GITHUB_WORKSPACE%\winbuild\build\bin;%PATH%
|
||||
.ci\test.cmd
|
||||
shell: cmd
|
||||
|
||||
- name: Prepare to upload errors
|
||||
|
@ -213,9 +215,9 @@ jobs:
|
|||
shell: pwsh
|
||||
|
||||
- name: Upload coverage
|
||||
uses: codecov/codecov-action@v4
|
||||
uses: codecov/codecov-action@v5
|
||||
with:
|
||||
file: ./coverage.xml
|
||||
files: ./coverage.xml
|
||||
flags: GHA_Windows
|
||||
name: ${{ runner.os }} Python ${{ matrix.python-version }}
|
||||
token: ${{ secrets.CODECOV_ORG_TOKEN }}
|
||||
|
|
27
.github/workflows/test.yml
vendored
|
@ -37,12 +37,12 @@ jobs:
|
|||
fail-fast: false
|
||||
matrix:
|
||||
os: [
|
||||
"macos-14",
|
||||
"macos-latest",
|
||||
"ubuntu-latest",
|
||||
]
|
||||
python-version: [
|
||||
"pypy3.10",
|
||||
"pypy3.9",
|
||||
"3.13t",
|
||||
"3.13",
|
||||
"3.12",
|
||||
"3.11",
|
||||
|
@ -53,21 +53,22 @@ jobs:
|
|||
- { python-version: "3.11", PYTHONOPTIMIZE: 1, REVERSE: "--reverse" }
|
||||
- { python-version: "3.10", PYTHONOPTIMIZE: 2 }
|
||||
# Free-threaded
|
||||
- { os: "ubuntu-latest", python-version: "3.13-dev", disable-gil: true }
|
||||
- { python-version: "3.13t", disable-gil: true }
|
||||
# M1 only available for 3.10+
|
||||
- { os: "macos-13", python-version: "3.9" }
|
||||
exclude:
|
||||
- { os: "macos-14", python-version: "3.9" }
|
||||
- { os: "macos-latest", python-version: "3.9" }
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
name: ${{ matrix.os }} Python ${{ matrix.python-version }} ${{ matrix.disable-gil && 'free-threaded' || '' }}
|
||||
name: ${{ matrix.os }} Python ${{ matrix.python-version }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v5
|
||||
if: "${{ !matrix.disable-gil }}"
|
||||
uses: Quansight-Labs/setup-python@v5
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
allow-prereleases: true
|
||||
|
@ -76,13 +77,6 @@ jobs:
|
|||
".ci/*.sh"
|
||||
"pyproject.toml"
|
||||
|
||||
- name: Set up Python ${{ matrix.python-version }} (free-threaded)
|
||||
uses: deadsnakes/action@v3.1.0
|
||||
if: "${{ matrix.disable-gil }}"
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
nogil: ${{ matrix.disable-gil }}
|
||||
|
||||
- name: Set PYTHON_GIL
|
||||
if: "${{ matrix.disable-gil }}"
|
||||
run: |
|
||||
|
@ -115,7 +109,7 @@ jobs:
|
|||
GHA_PYTHON_VERSION: ${{ matrix.python-version }}
|
||||
|
||||
- name: Register gcc problem matcher
|
||||
if: "matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12'"
|
||||
if: "matrix.os == 'ubuntu-latest' && matrix.python-version == '3.13'"
|
||||
run: echo "::add-matcher::.github/problem-matchers/gcc.json"
|
||||
|
||||
- name: Build
|
||||
|
@ -155,11 +149,10 @@ jobs:
|
|||
.ci/after_success.sh
|
||||
|
||||
- name: Upload coverage
|
||||
uses: codecov/codecov-action@v4
|
||||
uses: codecov/codecov-action@v5
|
||||
with:
|
||||
flags: ${{ matrix.os == 'ubuntu-latest' && 'GHA_Ubuntu' || 'GHA_macOS' }}
|
||||
name: ${{ matrix.os }} Python ${{ matrix.python-version }}
|
||||
gcov: true
|
||||
token: ${{ secrets.CODECOV_ORG_TOKEN }}
|
||||
|
||||
success:
|
||||
|
|
169
.github/workflows/wheels-dependencies.sh
vendored
|
@ -1,11 +1,33 @@
|
|||
#!/bin/bash
|
||||
# Define custom utilities
|
||||
# Test for macOS with [ -n "$IS_MACOS" ]
|
||||
if [ -z "$IS_MACOS" ]; then
|
||||
export MB_ML_LIBC=${AUDITWHEEL_POLICY::9}
|
||||
export MB_ML_VER=${AUDITWHEEL_POLICY:9}
|
||||
|
||||
# Setup that needs to be done before multibuild utils are invoked
|
||||
PROJECTDIR=$(pwd)
|
||||
if [[ "$(uname -s)" == "Darwin" ]]; then
|
||||
# Safety check - macOS builds require that CIBW_ARCHS is set, and that it
|
||||
# only contains a single value (even though cibuildwheel allows multiple
|
||||
# values in CIBW_ARCHS).
|
||||
if [[ -z "$CIBW_ARCHS" ]]; then
|
||||
echo "ERROR: Pillow macOS builds require CIBW_ARCHS be defined."
|
||||
exit 1
|
||||
fi
|
||||
if [[ "$CIBW_ARCHS" == *" "* ]]; then
|
||||
echo "ERROR: Pillow macOS builds only support a single architecture in CIBW_ARCHS."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Build macOS dependencies in `build/darwin`
|
||||
# Install them into `build/deps/darwin`
|
||||
WORKDIR=$(pwd)/build/darwin
|
||||
BUILD_PREFIX=$(pwd)/build/deps/darwin
|
||||
else
|
||||
# Build prefix will default to /usr/local
|
||||
WORKDIR=$(pwd)/build
|
||||
MB_ML_LIBC=${AUDITWHEEL_POLICY::9}
|
||||
MB_ML_VER=${AUDITWHEEL_POLICY:9}
|
||||
fi
|
||||
export PLAT=$CIBW_ARCHS
|
||||
PLAT=$CIBW_ARCHS
|
||||
|
||||
# Define custom utilities
|
||||
source wheels/multibuild/common_utils.sh
|
||||
source wheels/multibuild/library_builders.sh
|
||||
if [ -z "$IS_MACOS" ]; then
|
||||
|
@ -16,11 +38,11 @@ ARCHIVE_SDIR=pillow-depends-main
|
|||
|
||||
# Package versions for fresh source builds
|
||||
FREETYPE_VERSION=2.13.2
|
||||
HARFBUZZ_VERSION=8.5.0
|
||||
LIBPNG_VERSION=1.6.43
|
||||
JPEGTURBO_VERSION=3.0.3
|
||||
HARFBUZZ_VERSION=10.0.1
|
||||
LIBPNG_VERSION=1.6.44
|
||||
JPEGTURBO_VERSION=3.0.4
|
||||
OPENJPEG_VERSION=2.5.2
|
||||
XZ_VERSION=5.4.5
|
||||
XZ_VERSION=5.6.3
|
||||
TIFF_VERSION=4.6.0
|
||||
LCMS2_VERSION=2.16
|
||||
if [[ -n "$IS_MACOS" ]]; then
|
||||
|
@ -38,32 +60,42 @@ BZIP2_VERSION=1.0.8
|
|||
LIBXCB_VERSION=1.17.0
|
||||
BROTLI_VERSION=1.1.0
|
||||
|
||||
if [[ -n "$IS_MACOS" ]] && [[ "$CIBW_ARCHS" == "x86_64" ]]; then
|
||||
function build_openjpeg {
|
||||
local out_dir=$(fetch_unpack https://github.com/uclouvain/openjpeg/archive/v${OPENJPEG_VERSION}.tar.gz openjpeg-${OPENJPEG_VERSION}.tar.gz)
|
||||
(cd $out_dir \
|
||||
&& cmake -DCMAKE_INSTALL_PREFIX=$BUILD_PREFIX -DCMAKE_INSTALL_NAME_DIR=$BUILD_PREFIX/lib . \
|
||||
&& make install)
|
||||
touch openjpeg-stamp
|
||||
}
|
||||
fi
|
||||
function build_pkg_config {
|
||||
if [ -e pkg-config-stamp ]; then return; fi
|
||||
# This essentially duplicates the Homebrew recipe
|
||||
ORIGINAL_CFLAGS=$CFLAGS
|
||||
CFLAGS="$CFLAGS -Wno-int-conversion"
|
||||
build_simple pkg-config 0.29.2 https://pkg-config.freedesktop.org/releases tar.gz \
|
||||
--disable-debug --disable-host-tool --with-internal-glib \
|
||||
--with-pc-path=$BUILD_PREFIX/share/pkgconfig:$BUILD_PREFIX/lib/pkgconfig \
|
||||
--with-system-include-path=$(xcrun --show-sdk-path --sdk macosx)/usr/include
|
||||
CFLAGS=$ORIGINAL_CFLAGS
|
||||
export PKG_CONFIG=$BUILD_PREFIX/bin/pkg-config
|
||||
touch pkg-config-stamp
|
||||
}
|
||||
|
||||
function build_brotli {
|
||||
local cmake=$(get_modern_cmake)
|
||||
local out_dir=$(fetch_unpack https://github.com/google/brotli/archive/v$BROTLI_VERSION.tar.gz brotli-1.1.0.tar.gz)
|
||||
if [ -e brotli-stamp ]; then return; fi
|
||||
local out_dir=$(fetch_unpack https://github.com/google/brotli/archive/v$BROTLI_VERSION.tar.gz brotli-$BROTLI_VERSION.tar.gz)
|
||||
(cd $out_dir \
|
||||
&& $cmake -DCMAKE_INSTALL_PREFIX=$BUILD_PREFIX -DCMAKE_INSTALL_NAME_DIR=$BUILD_PREFIX/lib . \
|
||||
&& cmake -DCMAKE_INSTALL_PREFIX=$BUILD_PREFIX -DCMAKE_INSTALL_LIBDIR=$BUILD_PREFIX/lib -DCMAKE_INSTALL_NAME_DIR=$BUILD_PREFIX/lib . \
|
||||
&& make install)
|
||||
if [[ "$MB_ML_LIBC" == "manylinux" ]]; then
|
||||
cp /usr/local/lib64/libbrotli* /usr/local/lib
|
||||
cp /usr/local/lib64/pkgconfig/libbrotli* /usr/local/lib/pkgconfig
|
||||
fi
|
||||
touch brotli-stamp
|
||||
}
|
||||
|
||||
function build_harfbuzz {
|
||||
if [ -e harfbuzz-stamp ]; then return; fi
|
||||
python3 -m pip install meson ninja
|
||||
|
||||
local out_dir=$(fetch_unpack https://github.com/harfbuzz/harfbuzz/releases/download/$HARFBUZZ_VERSION/$HARFBUZZ_VERSION.tar.xz harfbuzz-$HARFBUZZ_VERSION.tar.xz)
|
||||
(cd $out_dir \
|
||||
&& meson setup build --prefix=$BUILD_PREFIX --libdir=$BUILD_PREFIX/lib --buildtype=release -Dfreetype=enabled -Dglib=disabled)
|
||||
(cd $out_dir/build \
|
||||
&& meson install)
|
||||
touch harfbuzz-stamp
|
||||
}
|
||||
|
||||
function build {
|
||||
if [[ -n "$IS_MACOS" ]] && [[ "$CIBW_ARCHS" == "arm64" ]]; then
|
||||
sudo chown -R runner /usr/local
|
||||
fi
|
||||
build_xz
|
||||
if [ -z "$IS_ALPINE" ] && [ -z "$IS_MACOS" ]; then
|
||||
yum remove -y zlib-devel
|
||||
|
@ -75,22 +107,27 @@ function build {
|
|||
build_simple xorgproto 2024.1 https://www.x.org/pub/individual/proto
|
||||
build_simple libXau 1.0.11 https://www.x.org/pub/individual/lib
|
||||
build_simple libpthread-stubs 0.5 https://xcb.freedesktop.org/dist
|
||||
if [[ "$CIBW_ARCHS" == "arm64" ]]; then
|
||||
cp /usr/local/share/pkgconfig/xcb-proto.pc /usr/local/lib/pkgconfig
|
||||
fi
|
||||
else
|
||||
sed s/\${pc_sysrootdir\}// /usr/local/share/pkgconfig/xcb-proto.pc > /usr/local/lib/pkgconfig/xcb-proto.pc
|
||||
sed s/\${pc_sysrootdir\}// $BUILD_PREFIX/share/pkgconfig/xcb-proto.pc > $BUILD_PREFIX/lib/pkgconfig/xcb-proto.pc
|
||||
fi
|
||||
build_simple libxcb $LIBXCB_VERSION https://www.x.org/releases/individual/lib
|
||||
|
||||
build_libjpeg_turbo
|
||||
build_tiff
|
||||
if [ -n "$IS_MACOS" ]; then
|
||||
# Custom tiff build to include jpeg; by default, configure won't include
|
||||
# headers/libs in the custom macOS prefix. Explicitly disable webp,
|
||||
# libdeflate and zstd, because on x86_64 macs, it will pick up the
|
||||
# Homebrew versions of those libraries from /usr/local.
|
||||
build_simple tiff $TIFF_VERSION https://download.osgeo.org/libtiff tar.gz \
|
||||
--with-jpeg-include-dir=$BUILD_PREFIX/include --with-jpeg-lib-dir=$BUILD_PREFIX/lib \
|
||||
--disable-webp --disable-libdeflate --disable-zstd
|
||||
else
|
||||
build_tiff
|
||||
fi
|
||||
|
||||
build_libpng
|
||||
build_lcms2
|
||||
build_openjpeg
|
||||
if [ -f /usr/local/lib64/libopenjp2.so ]; then
|
||||
cp /usr/local/lib64/libopenjp2.so /usr/local/lib
|
||||
fi
|
||||
|
||||
ORIGINAL_CFLAGS=$CFLAGS
|
||||
CFLAGS="$CFLAGS -O3 -DNDEBUG"
|
||||
|
@ -109,42 +146,50 @@ function build {
|
|||
build_freetype
|
||||
fi
|
||||
|
||||
if [ -z "$IS_MACOS" ]; then
|
||||
export FREETYPE_LIBS=-lfreetype
|
||||
export FREETYPE_CFLAGS=-I/usr/local/include/freetype2/
|
||||
fi
|
||||
build_simple harfbuzz $HARFBUZZ_VERSION https://github.com/harfbuzz/harfbuzz/releases/download/$HARFBUZZ_VERSION tar.xz --with-freetype=yes --with-glib=no
|
||||
if [ -z "$IS_MACOS" ]; then
|
||||
export FREETYPE_LIBS=""
|
||||
export FREETYPE_CFLAGS=""
|
||||
fi
|
||||
build_harfbuzz
|
||||
}
|
||||
|
||||
# Perform all dependency builds in the build subfolder.
|
||||
mkdir -p $WORKDIR
|
||||
pushd $WORKDIR > /dev/null
|
||||
|
||||
# Any stuff that you need to do before you start building the wheels
|
||||
# Runs in the root directory of this repository.
|
||||
curl -fsSL -o pillow-depends-main.zip https://github.com/python-pillow/pillow-depends/archive/main.zip
|
||||
untar pillow-depends-main.zip
|
||||
if [[ ! -d $WORKDIR/pillow-depends-main ]]; then
|
||||
if [[ ! -f $PROJECTDIR/pillow-depends-main.zip ]]; then
|
||||
echo "Download pillow dependency sources..."
|
||||
curl -fSL -o $PROJECTDIR/pillow-depends-main.zip https://github.com/python-pillow/pillow-depends/archive/main.zip
|
||||
fi
|
||||
echo "Unpacking pillow dependency sources..."
|
||||
untar $PROJECTDIR/pillow-depends-main.zip
|
||||
fi
|
||||
|
||||
if [[ -n "$IS_MACOS" ]]; then
|
||||
# libtiff and libxcb cause a conflict with building libtiff and libxcb
|
||||
# libxau and libxdmcp cause an issue on macOS < 11
|
||||
# remove cairo to fix building harfbuzz on arm64
|
||||
# remove lcms2 and libpng to fix building openjpeg on arm64
|
||||
# remove jpeg-turbo to avoid inclusion on arm64
|
||||
# remove webp and zstd to avoid inclusion on x86_64
|
||||
# curl from brew requires zstd, use system curl
|
||||
brew remove --ignore-dependencies libpng libtiff libxcb libxau libxdmcp curl cairo lcms2 zstd
|
||||
if [[ "$CIBW_ARCHS" == "arm64" ]]; then
|
||||
brew remove --ignore-dependencies jpeg-turbo
|
||||
else
|
||||
brew remove --ignore-dependencies webp
|
||||
fi
|
||||
# Homebrew (or similar packaging environments) install can contain some of
|
||||
# the libraries that we're going to build. However, they may be compiled
|
||||
# with a MACOSX_DEPLOYMENT_TARGET that doesn't match what we want to use,
|
||||
# and they may bring in other dependencies that we don't want. The same will
|
||||
# be true of any other locations on the path. To avoid conflicts, strip the
|
||||
# path down to the bare minimum (which, on macOS, won't include any
|
||||
# development dependencies).
|
||||
export PATH="$BUILD_PREFIX/bin:$(dirname $(which python3)):/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin"
|
||||
export CMAKE_PREFIX_PATH=$BUILD_PREFIX
|
||||
|
||||
brew install pkg-config
|
||||
# Ensure the basic structure of the build prefix directory exists.
|
||||
mkdir -p "$BUILD_PREFIX/bin"
|
||||
mkdir -p "$BUILD_PREFIX/lib"
|
||||
|
||||
# Ensure pkg-config is available
|
||||
build_pkg_config
|
||||
# Ensure cmake is available
|
||||
python3 -m pip install cmake
|
||||
fi
|
||||
|
||||
wrap_wheel_builder build
|
||||
|
||||
# Return to the project root to finish the build
|
||||
popd > /dev/null
|
||||
|
||||
# Append licenses
|
||||
for filename in wheels/dependency_licenses/*; do
|
||||
echo -e "\n\n----\n\n$(basename $filename | cut -f 1 -d '.')\n" | cat >> LICENSE
|
||||
|
|
29
.github/workflows/wheels-test.sh
vendored
|
@ -1,26 +1,31 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Ensure fribidi is installed by the system.
|
||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
brew install fribidi
|
||||
export PKG_CONFIG_PATH="/usr/local/opt/openblas/lib/pkgconfig"
|
||||
if [ -f /opt/homebrew/lib/libfribidi.dylib ]; then
|
||||
sudo cp /opt/homebrew/lib/libfribidi.dylib /usr/local/lib
|
||||
# If Homebrew is on the path during the build, it may leak into the wheels.
|
||||
# However, we *do* need Homebrew to provide a copy of fribidi for
|
||||
# testing purposes so that we can verify the fribidi shim works as expected.
|
||||
if [[ "$(uname -m)" == "x86_64" ]]; then
|
||||
HOMEBREW_PREFIX=/usr/local
|
||||
else
|
||||
HOMEBREW_PREFIX=/opt/homebrew
|
||||
fi
|
||||
$HOMEBREW_PREFIX/bin/brew install fribidi
|
||||
|
||||
# Add the lib folder for fribidi so that the vendored library can be found.
|
||||
# Don't use $HOMEWBREW_PREFIX/lib directly - use the lib folder where the
|
||||
# installed copy of fribidi is cellared. This ensures we don't pick up the
|
||||
# Homebrew version of any other library that we're dependent on (most notably,
|
||||
# freetype).
|
||||
export DYLD_LIBRARY_PATH=$(dirname $(realpath $HOMEBREW_PREFIX/lib/libfribidi.dylib))
|
||||
elif [ "${AUDITWHEEL_POLICY::9}" == "musllinux" ]; then
|
||||
apk add curl fribidi
|
||||
else
|
||||
yum install -y fribidi
|
||||
fi
|
||||
|
||||
if [ "${AUDITWHEEL_POLICY::9}" != "musllinux" ]; then
|
||||
# TODO Update condition when NumPy supports free-threading
|
||||
if [ $(python3 -c "import sysconfig;print(sysconfig.get_config_var('Py_GIL_DISABLED'))") == "1" ]; then
|
||||
python3 -m pip install numpy --index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple
|
||||
else
|
||||
python3 -m pip install numpy
|
||||
fi
|
||||
fi
|
||||
python3 -m pip install numpy
|
||||
|
||||
if [ ! -d "test-images-main" ]; then
|
||||
curl -fsSL -o pillow-test-images.zip https://github.com/python-pillow/test-images/archive/main.zip
|
||||
|
|
34
.github/workflows/wheels.yml
vendored
|
@ -41,14 +41,13 @@ env:
|
|||
|
||||
jobs:
|
||||
build-1-QEMU-emulated-wheels:
|
||||
if: github.event_name != 'schedule' && github.event_name != 'workflow_dispatch'
|
||||
if: github.event_name != 'schedule'
|
||||
name: aarch64 ${{ matrix.python-version }} ${{ matrix.spec }}
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
python-version:
|
||||
- pp39
|
||||
- pp310
|
||||
- cp3{9,10,11}
|
||||
- cp3{12,13}
|
||||
|
@ -57,12 +56,12 @@ jobs:
|
|||
- manylinux_2_28
|
||||
- musllinux
|
||||
exclude:
|
||||
- { python-version: pp39, spec: musllinux }
|
||||
- { python-version: pp310, spec: musllinux }
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
persist-credentials: false
|
||||
submodules: true
|
||||
|
||||
- uses: actions/setup-python@v5
|
||||
|
@ -104,12 +103,23 @@ jobs:
|
|||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- name: "macOS x86_64"
|
||||
- name: "macOS 10.10 x86_64"
|
||||
os: macos-13
|
||||
cibw_arch: x86_64
|
||||
build: "cp3{9,10,11}*"
|
||||
macosx_deployment_target: "10.10"
|
||||
- name: "macOS 10.13 x86_64"
|
||||
os: macos-13
|
||||
cibw_arch: x86_64
|
||||
build: "cp3{12,13}*"
|
||||
macosx_deployment_target: "10.13"
|
||||
- name: "macOS 10.15 x86_64"
|
||||
os: macos-13
|
||||
cibw_arch: x86_64
|
||||
build: "pp310*"
|
||||
macosx_deployment_target: "10.15"
|
||||
- name: "macOS arm64"
|
||||
os: macos-14
|
||||
os: macos-latest
|
||||
cibw_arch: arm64
|
||||
macosx_deployment_target: "11.0"
|
||||
- name: "manylinux2014 and musllinux x86_64"
|
||||
|
@ -123,6 +133,7 @@ jobs:
|
|||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
persist-credentials: false
|
||||
submodules: true
|
||||
|
||||
- uses: actions/setup-python@v5
|
||||
|
@ -143,11 +154,12 @@ jobs:
|
|||
CIBW_MANYLINUX_PYPY_X86_64_IMAGE: ${{ matrix.manylinux }}
|
||||
CIBW_MANYLINUX_X86_64_IMAGE: ${{ matrix.manylinux }}
|
||||
CIBW_PRERELEASE_PYTHONS: True
|
||||
CIBW_SKIP: pp39-*
|
||||
MACOSX_DEPLOYMENT_TARGET: ${{ matrix.macosx_deployment_target }}
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: dist-${{ matrix.os }}-${{ matrix.cibw_arch }}${{ matrix.manylinux && format('-{0}', matrix.manylinux) }}
|
||||
name: dist-${{ matrix.os }}${{ matrix.macosx_deployment_target && format('-{0}', matrix.macosx_deployment_target) }}-${{ matrix.cibw_arch }}${{ matrix.manylinux && format('-{0}', matrix.manylinux) }}
|
||||
path: ./wheelhouse/*.whl
|
||||
|
||||
windows:
|
||||
|
@ -163,10 +175,13 @@ jobs:
|
|||
- cibw_arch: ARM64
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Checkout extra test images
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
persist-credentials: false
|
||||
repository: python-pillow/test-images
|
||||
path: Tests\test-images
|
||||
|
||||
|
@ -215,6 +230,7 @@ jobs:
|
|||
CIBW_CACHE_PATH: "C:\\cibw"
|
||||
CIBW_FREE_THREADED_SUPPORT: True
|
||||
CIBW_PRERELEASE_PYTHONS: True
|
||||
CIBW_SKIP: pp39-*
|
||||
CIBW_TEST_SKIP: "*-win_arm64"
|
||||
CIBW_TEST_COMMAND: 'docker run --rm
|
||||
-v {project}:C:\pillow
|
||||
|
@ -242,6 +258,8 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v5
|
||||
|
@ -269,7 +287,7 @@ jobs:
|
|||
path: dist
|
||||
merge-multiple: true
|
||||
- name: Upload wheels to scientific-python-nightly-wheels
|
||||
uses: scientific-python/upload-nightly-action@b67d7fcc0396e1128a474d1ab2b48aa94680f9fc # 0.5.0
|
||||
uses: scientific-python/upload-nightly-action@82396a2ed4269ba06c6b2988bb4fd568ef3c3d6b # 0.6.1
|
||||
with:
|
||||
artifacts_path: dist
|
||||
anaconda_nightly_upload_token: ${{ secrets.ANACONDA_ORG_UPLOAD_TOKEN }}
|
||||
|
@ -292,3 +310,5 @@ jobs:
|
|||
merge-multiple: true
|
||||
- name: Publish to PyPI
|
||||
uses: pypa/gh-action-pypi-publish@release/v1
|
||||
with:
|
||||
attestations: true
|
||||
|
|
5
.gitignore
vendored
|
@ -19,6 +19,7 @@ lib64/
|
|||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheelhouse/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
|
@ -90,5 +91,9 @@ Tests/images/msp
|
|||
Tests/images/picins
|
||||
Tests/images/sunraster
|
||||
|
||||
# Test and dependency downloads
|
||||
pillow-depends-main.zip
|
||||
pillow-test-images.zip
|
||||
|
||||
# pyinstaller
|
||||
*.spec
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
repos:
|
||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||
rev: v0.5.0
|
||||
rev: v0.7.2
|
||||
hooks:
|
||||
- id: ruff
|
||||
args: [--exit-non-zero-on-fix]
|
||||
|
||||
- repo: https://github.com/psf/black-pre-commit-mirror
|
||||
rev: 24.4.2
|
||||
rev: 24.10.0
|
||||
hooks:
|
||||
- id: black
|
||||
|
||||
- repo: https://github.com/PyCQA/bandit
|
||||
rev: 1.7.9
|
||||
rev: 1.7.10
|
||||
hooks:
|
||||
- id: bandit
|
||||
args: [--severity-level=high]
|
||||
|
@ -24,7 +24,7 @@ repos:
|
|||
exclude: (Makefile$|\.bat$|\.cmake$|\.eps$|\.fits$|\.gd$|\.opt$)
|
||||
|
||||
- repo: https://github.com/pre-commit/mirrors-clang-format
|
||||
rev: v18.1.8
|
||||
rev: v19.1.3
|
||||
hooks:
|
||||
- id: clang-format
|
||||
types: [c]
|
||||
|
@ -36,7 +36,7 @@ repos:
|
|||
- id: rst-backticks
|
||||
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v4.6.0
|
||||
rev: v5.0.0
|
||||
hooks:
|
||||
- id: check-executables-have-shebangs
|
||||
- id: check-shebang-scripts-are-executable
|
||||
|
@ -50,29 +50,30 @@ repos:
|
|||
exclude: ^.github/.*TEMPLATE|^Tests/(fonts|images)/
|
||||
|
||||
- repo: https://github.com/python-jsonschema/check-jsonschema
|
||||
rev: 0.28.6
|
||||
rev: 0.29.4
|
||||
hooks:
|
||||
- id: check-github-workflows
|
||||
- id: check-readthedocs
|
||||
- id: check-renovate
|
||||
|
||||
- repo: https://github.com/sphinx-contrib/sphinx-lint
|
||||
rev: v0.9.1
|
||||
rev: v1.0.0
|
||||
hooks:
|
||||
- id: sphinx-lint
|
||||
|
||||
- repo: https://github.com/tox-dev/pyproject-fmt
|
||||
rev: 2.1.3
|
||||
rev: v2.5.0
|
||||
hooks:
|
||||
- id: pyproject-fmt
|
||||
|
||||
- repo: https://github.com/abravalheri/validate-pyproject
|
||||
rev: v0.18
|
||||
rev: v0.22
|
||||
hooks:
|
||||
- id: validate-pyproject
|
||||
additional_dependencies: [trove-classifiers>=2024.10.12]
|
||||
|
||||
- repo: https://github.com/tox-dev/tox-ini-fmt
|
||||
rev: 1.3.1
|
||||
rev: 1.4.1
|
||||
hooks:
|
||||
- id: tox-ini-fmt
|
||||
|
||||
|
|
150
CHANGES.rst
|
@ -2,9 +2,157 @@
|
|||
Changelog (Pillow)
|
||||
==================
|
||||
|
||||
11.0.0 (unreleased)
|
||||
11.1.0 and newer
|
||||
----------------
|
||||
|
||||
See GitHub Releases:
|
||||
|
||||
- https://github.com/python-pillow/Pillow/releases
|
||||
|
||||
11.0.0 (2024-10-15)
|
||||
-------------------
|
||||
|
||||
- Update licence to MIT-CMU #8460
|
||||
[hugovk]
|
||||
|
||||
- Conditionally define ImageCms type hint to avoid requiring core #8197
|
||||
[radarhere]
|
||||
|
||||
- Support writing LONG8 offsets in AppendingTiffWriter #8417
|
||||
[radarhere]
|
||||
|
||||
- Use ImageFile.MAXBLOCK when saving TIFF images #8461
|
||||
[radarhere]
|
||||
|
||||
- Do not close provided file handles with libtiff when saving #8458
|
||||
[radarhere]
|
||||
|
||||
- Support ImageFilter.BuiltinFilter for I;16* images #8438
|
||||
[radarhere]
|
||||
|
||||
- Use ImagingCore.ptr instead of ImagingCore.id #8341
|
||||
[homm, radarhere, hugovk]
|
||||
|
||||
- Updated EPS mode when opening images without transparency #8281
|
||||
[Yay295, radarhere]
|
||||
|
||||
- Use transparency when combining P frames from APNGs #8443
|
||||
[radarhere]
|
||||
|
||||
- Support all resampling filters when resizing I;16* images #8422
|
||||
[radarhere]
|
||||
|
||||
- Free memory on early return #8413
|
||||
[radarhere]
|
||||
|
||||
- Cast int before potentially exceeding INT_MAX #8402
|
||||
[radarhere]
|
||||
|
||||
- Check image value before use #8400
|
||||
[radarhere]
|
||||
|
||||
- Improved copying imagequant libraries #8420
|
||||
[radarhere]
|
||||
|
||||
- Use Capsule for WebP saving #8386
|
||||
[homm, radarhere]
|
||||
|
||||
- Fixed writing multiple StripOffsets to TIFF #8317
|
||||
[Yay295, radarhere]
|
||||
|
||||
- Fix dereference before checking for NULL in ImagingTransformAffine #8398
|
||||
[PavlNekrasov]
|
||||
|
||||
- Use transposed size after opening for TIFF images #8390
|
||||
[radarhere, homm]
|
||||
|
||||
- Improve ImageFont error messages #8338
|
||||
[yngvem, radarhere, hugovk]
|
||||
|
||||
- Mention MAX_TEXT_CHUNK limit in PNG error message #8391
|
||||
[radarhere]
|
||||
|
||||
- Cast Dib handle to int #8385
|
||||
[radarhere]
|
||||
|
||||
- Accept float stroke widths #8369
|
||||
[radarhere]
|
||||
|
||||
- Deprecate ICNS (width, height, scale) sizes in favour of load(scale) #8352
|
||||
[radarhere]
|
||||
|
||||
- Improved handling of RGBA palettes when saving GIF images #8366
|
||||
[radarhere]
|
||||
|
||||
- Deprecate isImageType #8364
|
||||
[radarhere]
|
||||
|
||||
- Support converting more modes to LAB by converting to RGBA first #8358
|
||||
[radarhere]
|
||||
|
||||
- Deprecate support for FreeType 2.9.0 #8356
|
||||
[hugovk, radarhere]
|
||||
|
||||
- Removed unused TiffImagePlugin IFD_LEGACY_API #8355
|
||||
[radarhere]
|
||||
|
||||
- Handle duplicate EXIF header #8350
|
||||
[zakajd, radarhere]
|
||||
|
||||
- Return early from BoxBlur if either width or height is zero #8347
|
||||
[radarhere]
|
||||
|
||||
- Check text is either string or bytes #8308
|
||||
[radarhere]
|
||||
|
||||
- Added writing XMP bytes to JPEG #8286
|
||||
[radarhere]
|
||||
|
||||
- Support JPEG2000 RGBA palettes #8256
|
||||
[radarhere]
|
||||
|
||||
- Expand C image to match GIF frame image size #8237
|
||||
[radarhere]
|
||||
|
||||
- Allow saving I;16 images as PPM #8231
|
||||
[radarhere]
|
||||
|
||||
- When IFD is missing, connect get_ifd() dictionary to Exif #8230
|
||||
[radarhere]
|
||||
|
||||
- Skip truncated ICO mask if LOAD_TRUNCATED_IMAGES is enabled #8180
|
||||
[radarhere]
|
||||
|
||||
- Treat unknown JPEG2000 colorspace as unspecified #8343
|
||||
[radarhere]
|
||||
|
||||
- Updated error message when saving WebP with invalid width or height #8322
|
||||
[radarhere, hugovk]
|
||||
|
||||
- Remove warning if NumPy failed to raise an error during conversion #8326
|
||||
[radarhere]
|
||||
|
||||
- If left and right sides meet in ImageDraw.rounded_rectangle(), do not draw rectangle to fill gap #8304
|
||||
[radarhere]
|
||||
|
||||
- Remove WebP support without anim, mux/demux, and with buggy alpha #8213
|
||||
[homm, radarhere]
|
||||
|
||||
- Add missing TIFF CMYK;16B reader #8298
|
||||
[homm]
|
||||
|
||||
- Remove all WITH_* flags from _imaging.c and other flags #8211
|
||||
[homm]
|
||||
|
||||
- Improve ImageDraw2 shape methods #8265
|
||||
[radarhere]
|
||||
|
||||
- Lock around usages of imaging memory arenas #8238
|
||||
[lysnikolaou]
|
||||
|
||||
- Deprecate JpegImageFile huffman_ac and huffman_dc #8274
|
||||
[radarhere]
|
||||
|
||||
- Deprecate ImageMath lambda_eval and unsafe_eval options argument #8242
|
||||
[radarhere]
|
||||
|
||||
|
|
2
LICENSE
|
@ -7,7 +7,7 @@ Pillow is the friendly PIL fork. It is
|
|||
|
||||
Copyright © 2010-2024 by Jeffrey A. Clark and contributors
|
||||
|
||||
Like PIL, Pillow is licensed under the open source HPND License:
|
||||
Like PIL, Pillow is licensed under the open source MIT-CMU License:
|
||||
|
||||
By obtaining, using, and/or copying this software and/or its associated
|
||||
documentation, you agree that you have read, understood, and will comply
|
||||
|
|
4
Makefile
|
@ -17,12 +17,10 @@ coverage:
|
|||
.PHONY: doc
|
||||
.PHONY: html
|
||||
doc html:
|
||||
python3 -c "import PIL" > /dev/null 2>&1 || python3 -m pip install .
|
||||
$(MAKE) -C docs html
|
||||
|
||||
.PHONY: htmlview
|
||||
htmlview:
|
||||
python3 -c "import PIL" > /dev/null 2>&1 || python3 -m pip install .
|
||||
$(MAKE) -C docs htmlview
|
||||
|
||||
.PHONY: doccheck
|
||||
|
@ -117,7 +115,7 @@ lint-fix:
|
|||
python3 -c "import black" > /dev/null 2>&1 || python3 -m pip install black
|
||||
python3 -m black .
|
||||
python3 -c "import ruff" > /dev/null 2>&1 || python3 -m pip install ruff
|
||||
python3 -m ruff --fix .
|
||||
python3 -m ruff check --fix .
|
||||
|
||||
.PHONY: mypy
|
||||
mypy:
|
||||
|
|
|
@ -51,7 +51,7 @@ As of 2019, Pillow development is
|
|||
<a href="https://app.codecov.io/gh/python-pillow/Pillow"><img
|
||||
alt="Code coverage"
|
||||
src="https://codecov.io/gh/python-pillow/Pillow/branch/main/graph/badge.svg"></a>
|
||||
<a href="https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:pillow"><img
|
||||
<a href="https://issues.oss-fuzz.com/issues?q=title:pillow"><img
|
||||
alt="Fuzzing Status"
|
||||
src="https://oss-fuzz-build-logs.storage.googleapis.com/badges/pillow.svg"></a>
|
||||
</td>
|
||||
|
@ -107,7 +107,7 @@ The core image library is designed for fast access to data stored in a few basic
|
|||
- [Issues](https://github.com/python-pillow/Pillow/issues)
|
||||
- [Pull requests](https://github.com/python-pillow/Pillow/pulls)
|
||||
- [Release notes](https://pillow.readthedocs.io/en/stable/releasenotes/index.html)
|
||||
- [Changelog](https://github.com/python-pillow/Pillow/blob/main/CHANGES.rst)
|
||||
- [Changelog](https://github.com/python-pillow/Pillow/releases)
|
||||
- [Pre-fork](https://github.com/python-pillow/Pillow/blob/main/CHANGES.rst#pre-fork)
|
||||
|
||||
## Report a Vulnerability
|
||||
|
|
|
@ -12,7 +12,6 @@ Released quarterly on January 2nd, April 1st, July 1st and October 15th.
|
|||
* [ ] Check [GitHub Actions](https://github.com/python-pillow/Pillow/actions) and [AppVeyor](https://ci.appveyor.com/project/python-pillow/Pillow) to confirm passing tests in `main` branch.
|
||||
* [ ] Check that all the wheel builds pass the tests in the [GitHub Actions "Wheels" workflow](https://github.com/python-pillow/Pillow/actions/workflows/wheels.yml) jobs by manually triggering them.
|
||||
* [ ] In compliance with [PEP 440](https://peps.python.org/pep-0440/), update version identifier in `src/PIL/_version.py`
|
||||
* [ ] Update `CHANGES.rst`.
|
||||
* [ ] Run pre-release check via `make release-test` in a freshly cloned repo.
|
||||
* [ ] Create branch and tag for release e.g.:
|
||||
```bash
|
||||
|
@ -34,7 +33,6 @@ Released quarterly on January 2nd, April 1st, July 1st and October 15th.
|
|||
Released as needed for security, installation or critical bug fixes.
|
||||
|
||||
* [ ] Make necessary changes in `main` branch.
|
||||
* [ ] Update `CHANGES.rst`.
|
||||
* [ ] Check out release branch e.g.:
|
||||
```bash
|
||||
git checkout -t remotes/origin/5.2.x
|
||||
|
|
BIN
Tests/images/eps/1.bmp
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
Tests/images/eps/1_boundingbox_after_imagedata.eps
Normal file
BIN
Tests/images/eps/1_second_imagedata.eps
Normal file
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.5 KiB |
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 5.4 KiB |
Before Width: | Height: | Size: 5.9 KiB After Width: | Height: | Size: 5.9 KiB |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 5.8 KiB |
After Width: | Height: | Size: 411 B |
BIN
Tests/images/imagedraw_stroke_float.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
Tests/images/test_extents_transparency.gif
Normal file
After Width: | Height: | Size: 415 B |
|
@ -16,8 +16,9 @@
|
|||
|
||||
|
||||
import atheris
|
||||
from atheris.import_hook import instrument_imports
|
||||
|
||||
with atheris.instrument_imports():
|
||||
with instrument_imports():
|
||||
import sys
|
||||
|
||||
import fuzzers
|
||||
|
|
|
@ -14,8 +14,9 @@
|
|||
|
||||
|
||||
import atheris
|
||||
from atheris.import_hook import instrument_imports
|
||||
|
||||
with atheris.instrument_imports():
|
||||
with instrument_imports():
|
||||
import sys
|
||||
|
||||
import fuzzers
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
<py3_8_encode_current_locale>
|
||||
<py3_10_encode_current_locale>
|
||||
Memcheck:Cond
|
||||
...
|
||||
fun:encode_current_locale
|
||||
|
|
|
@ -22,6 +22,8 @@ def test_bad() -> None:
|
|||
for f in get_files("b"):
|
||||
# Assert that there is no unclosed file warning
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("error")
|
||||
|
||||
try:
|
||||
with Image.open(f) as im:
|
||||
im.load()
|
||||
|
|
|
@ -71,6 +71,11 @@ def test_color_modes() -> None:
|
|||
box_blur(sample.convert("YCbCr"))
|
||||
|
||||
|
||||
@pytest.mark.parametrize("size", ((0, 1), (1, 0)))
|
||||
def test_zero_dimension(size: tuple[int, int]) -> None:
|
||||
assert box_blur(Image.new("L", size)).size == size
|
||||
|
||||
|
||||
def test_radius_0() -> None:
|
||||
assert_blur(
|
||||
sample,
|
||||
|
|
|
@ -105,91 +105,65 @@ class TestColorLut3DCoreAPI:
|
|||
with pytest.raises(TypeError):
|
||||
im.im.color_lut_3d("RGB", Image.Resampling.BILINEAR, 3, 2, 2, 2, 16)
|
||||
|
||||
def test_correct_args(self) -> None:
|
||||
im = Image.new("RGB", (10, 10), 0)
|
||||
|
||||
im.im.color_lut_3d(
|
||||
"RGB", Image.Resampling.BILINEAR, *self.generate_identity_table(3, 3)
|
||||
)
|
||||
|
||||
im.im.color_lut_3d(
|
||||
"CMYK", Image.Resampling.BILINEAR, *self.generate_identity_table(4, 3)
|
||||
)
|
||||
|
||||
im.im.color_lut_3d(
|
||||
"RGB",
|
||||
Image.Resampling.BILINEAR,
|
||||
*self.generate_identity_table(3, (2, 3, 3)),
|
||||
)
|
||||
|
||||
im.im.color_lut_3d(
|
||||
"RGB",
|
||||
Image.Resampling.BILINEAR,
|
||||
*self.generate_identity_table(3, (65, 3, 3)),
|
||||
)
|
||||
|
||||
im.im.color_lut_3d(
|
||||
"RGB",
|
||||
Image.Resampling.BILINEAR,
|
||||
*self.generate_identity_table(3, (3, 65, 3)),
|
||||
)
|
||||
|
||||
im.im.color_lut_3d(
|
||||
"RGB",
|
||||
Image.Resampling.BILINEAR,
|
||||
*self.generate_identity_table(3, (3, 3, 65)),
|
||||
)
|
||||
|
||||
def test_wrong_mode(self) -> None:
|
||||
with pytest.raises(ValueError, match="wrong mode"):
|
||||
im = Image.new("L", (10, 10), 0)
|
||||
im.im.color_lut_3d(
|
||||
"RGB", Image.Resampling.BILINEAR, *self.generate_identity_table(3, 3)
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError, match="wrong mode"):
|
||||
im = Image.new("RGB", (10, 10), 0)
|
||||
im.im.color_lut_3d(
|
||||
"L", Image.Resampling.BILINEAR, *self.generate_identity_table(3, 3)
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError, match="wrong mode"):
|
||||
im = Image.new("L", (10, 10), 0)
|
||||
im.im.color_lut_3d(
|
||||
"L", Image.Resampling.BILINEAR, *self.generate_identity_table(3, 3)
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError, match="wrong mode"):
|
||||
im = Image.new("RGB", (10, 10), 0)
|
||||
im.im.color_lut_3d(
|
||||
"RGBA", Image.Resampling.BILINEAR, *self.generate_identity_table(3, 3)
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError, match="wrong mode"):
|
||||
im = Image.new("RGB", (10, 10), 0)
|
||||
im.im.color_lut_3d(
|
||||
"RGB", Image.Resampling.BILINEAR, *self.generate_identity_table(4, 3)
|
||||
)
|
||||
|
||||
def test_correct_mode(self) -> None:
|
||||
im = Image.new("RGBA", (10, 10), 0)
|
||||
im.im.color_lut_3d(
|
||||
"RGBA", Image.Resampling.BILINEAR, *self.generate_identity_table(3, 3)
|
||||
)
|
||||
|
||||
im = Image.new("RGBA", (10, 10), 0)
|
||||
im.im.color_lut_3d(
|
||||
"RGBA", Image.Resampling.BILINEAR, *self.generate_identity_table(4, 3)
|
||||
)
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"lut_mode, table_channels, table_size",
|
||||
[
|
||||
("RGB", 3, 3),
|
||||
("CMYK", 4, 3),
|
||||
("RGB", 3, (2, 3, 3)),
|
||||
("RGB", 3, (65, 3, 3)),
|
||||
("RGB", 3, (3, 65, 3)),
|
||||
("RGB", 3, (2, 3, 65)),
|
||||
],
|
||||
)
|
||||
def test_correct_args(
|
||||
self, lut_mode: str, table_channels: int, table_size: int | tuple[int, int, int]
|
||||
) -> None:
|
||||
im = Image.new("RGB", (10, 10), 0)
|
||||
im.im.color_lut_3d(
|
||||
"HSV", Image.Resampling.BILINEAR, *self.generate_identity_table(3, 3)
|
||||
lut_mode,
|
||||
Image.Resampling.BILINEAR,
|
||||
*self.generate_identity_table(table_channels, table_size),
|
||||
)
|
||||
|
||||
im = Image.new("RGB", (10, 10), 0)
|
||||
@pytest.mark.parametrize(
|
||||
"image_mode, lut_mode, table_channels, table_size",
|
||||
[
|
||||
("L", "RGB", 3, 3),
|
||||
("RGB", "L", 3, 3),
|
||||
("L", "L", 3, 3),
|
||||
("RGB", "RGBA", 3, 3),
|
||||
("RGB", "RGB", 4, 3),
|
||||
],
|
||||
)
|
||||
def test_wrong_mode(
|
||||
self, image_mode: str, lut_mode: str, table_channels: int, table_size: int
|
||||
) -> None:
|
||||
with pytest.raises(ValueError, match="wrong mode"):
|
||||
im = Image.new(image_mode, (10, 10), 0)
|
||||
im.im.color_lut_3d(
|
||||
lut_mode,
|
||||
Image.Resampling.BILINEAR,
|
||||
*self.generate_identity_table(table_channels, table_size),
|
||||
)
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"image_mode, lut_mode, table_channels, table_size",
|
||||
[
|
||||
("RGBA", "RGBA", 3, 3),
|
||||
("RGBA", "RGBA", 4, 3),
|
||||
("RGB", "HSV", 3, 3),
|
||||
("RGB", "RGBA", 4, 3),
|
||||
],
|
||||
)
|
||||
def test_correct_mode(
|
||||
self, image_mode: str, lut_mode: str, table_channels: int, table_size: int
|
||||
) -> None:
|
||||
im = Image.new(image_mode, (10, 10), 0)
|
||||
im.im.color_lut_3d(
|
||||
"RGBA", Image.Resampling.BILINEAR, *self.generate_identity_table(4, 3)
|
||||
lut_mode,
|
||||
Image.Resampling.BILINEAR,
|
||||
*self.generate_identity_table(table_channels, table_size),
|
||||
)
|
||||
|
||||
def test_identities(self) -> None:
|
||||
|
|
|
@ -10,11 +10,6 @@ from PIL import features
|
|||
|
||||
from .helper import skip_unless_feature
|
||||
|
||||
try:
|
||||
from PIL import _webp
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
def test_check() -> None:
|
||||
# Check the correctness of the convenience function
|
||||
|
@ -23,7 +18,11 @@ def test_check() -> None:
|
|||
for codec in features.codecs:
|
||||
assert features.check_codec(codec) == features.check(codec)
|
||||
for feature in features.features:
|
||||
assert features.check_feature(feature) == features.check(feature)
|
||||
if "webp" in feature:
|
||||
with pytest.warns(DeprecationWarning):
|
||||
assert features.check_feature(feature) == features.check(feature)
|
||||
else:
|
||||
assert features.check_feature(feature) == features.check(feature)
|
||||
|
||||
|
||||
def test_version() -> None:
|
||||
|
@ -48,23 +47,26 @@ def test_version() -> None:
|
|||
for codec in features.codecs:
|
||||
test(codec, features.version_codec)
|
||||
for feature in features.features:
|
||||
test(feature, features.version_feature)
|
||||
if "webp" in feature:
|
||||
with pytest.warns(DeprecationWarning):
|
||||
test(feature, features.version_feature)
|
||||
else:
|
||||
test(feature, features.version_feature)
|
||||
|
||||
|
||||
@skip_unless_feature("webp")
|
||||
def test_webp_transparency() -> None:
|
||||
assert features.check("transp_webp") != _webp.WebPDecoderBuggyAlpha()
|
||||
assert features.check("transp_webp") == _webp.HAVE_TRANSPARENCY
|
||||
with pytest.warns(DeprecationWarning):
|
||||
assert (features.check("transp_webp") or False) == features.check_module("webp")
|
||||
|
||||
|
||||
@skip_unless_feature("webp")
|
||||
def test_webp_mux() -> None:
|
||||
assert features.check("webp_mux") == _webp.HAVE_WEBPMUX
|
||||
with pytest.warns(DeprecationWarning):
|
||||
assert (features.check("webp_mux") or False) == features.check_module("webp")
|
||||
|
||||
|
||||
@skip_unless_feature("webp")
|
||||
def test_webp_anim() -> None:
|
||||
assert features.check("webp_anim") == _webp.HAVE_WEBPANIM
|
||||
with pytest.warns(DeprecationWarning):
|
||||
assert (features.check("webp_anim") or False) == features.check_module("webp")
|
||||
|
||||
|
||||
@skip_unless_feature("libjpeg_turbo")
|
||||
|
|
|
@ -258,8 +258,8 @@ def test_apng_mode() -> None:
|
|||
assert im.mode == "P"
|
||||
im.seek(im.n_frames - 1)
|
||||
im = im.convert("RGBA")
|
||||
assert im.getpixel((0, 0)) == (255, 0, 0, 0)
|
||||
assert im.getpixel((64, 32)) == (255, 0, 0, 0)
|
||||
assert im.getpixel((0, 0)) == (0, 255, 0, 255)
|
||||
assert im.getpixel((64, 32)) == (0, 255, 0, 255)
|
||||
|
||||
with Image.open("Tests/images/apng/mode_palette_1bit_alpha.png") as im:
|
||||
assert im.mode == "P"
|
||||
|
|
|
@ -36,6 +36,8 @@ def test_unclosed_file() -> None:
|
|||
|
||||
def test_closed_file() -> None:
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("error")
|
||||
|
||||
im = Image.open(TEST_FILE)
|
||||
im.load()
|
||||
im.close()
|
||||
|
@ -43,6 +45,8 @@ def test_closed_file() -> None:
|
|||
|
||||
def test_context_manager() -> None:
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("error")
|
||||
|
||||
with Image.open(TEST_FILE) as im:
|
||||
im.load()
|
||||
|
||||
|
|
|
@ -152,7 +152,7 @@ def test_sanity_ati2_bc5u(image_path: str) -> None:
|
|||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("image_path", "expected_path"),
|
||||
"image_path, expected_path",
|
||||
(
|
||||
# hexeditted to be typeless
|
||||
(TEST_FILE_DX10_BC5_TYPELESS, TEST_FILE_DX10_BC5_UNORM),
|
||||
|
@ -248,7 +248,7 @@ def test_dx10_r8g8b8a8_unorm_srgb() -> None:
|
|||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("mode", "size", "test_file"),
|
||||
"mode, size, test_file",
|
||||
[
|
||||
("L", (128, 128), TEST_FILE_UNCOMPRESSED_L),
|
||||
("LA", (128, 128), TEST_FILE_UNCOMPRESSED_L_WITH_ALPHA),
|
||||
|
@ -373,7 +373,7 @@ def test_save_unsupported_mode(tmp_path: Path) -> None:
|
|||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("mode", "test_file"),
|
||||
"mode, test_file",
|
||||
[
|
||||
("L", "Tests/images/linear_gradient.png"),
|
||||
("LA", "Tests/images/uncompressed_la.png"),
|
||||
|
|
|
@ -8,6 +8,7 @@ import pytest
|
|||
from PIL import EpsImagePlugin, Image, UnidentifiedImageError, features
|
||||
|
||||
from .helper import (
|
||||
assert_image_equal_tofile,
|
||||
assert_image_similar,
|
||||
assert_image_similar_tofile,
|
||||
hopper,
|
||||
|
@ -19,18 +20,18 @@ from .helper import (
|
|||
HAS_GHOSTSCRIPT = EpsImagePlugin.has_ghostscript()
|
||||
|
||||
# Our two EPS test files (they are identical except for their bounding boxes)
|
||||
FILE1 = "Tests/images/zero_bb.eps"
|
||||
FILE2 = "Tests/images/non_zero_bb.eps"
|
||||
FILE1 = "Tests/images/eps/zero_bb.eps"
|
||||
FILE2 = "Tests/images/eps/non_zero_bb.eps"
|
||||
|
||||
# Due to palletization, we'll need to convert these to RGB after load
|
||||
FILE1_COMPARE = "Tests/images/zero_bb.png"
|
||||
FILE1_COMPARE_SCALE2 = "Tests/images/zero_bb_scale2.png"
|
||||
FILE1_COMPARE = "Tests/images/eps/zero_bb.png"
|
||||
FILE1_COMPARE_SCALE2 = "Tests/images/eps/zero_bb_scale2.png"
|
||||
|
||||
FILE2_COMPARE = "Tests/images/non_zero_bb.png"
|
||||
FILE2_COMPARE_SCALE2 = "Tests/images/non_zero_bb_scale2.png"
|
||||
FILE2_COMPARE = "Tests/images/eps/non_zero_bb.png"
|
||||
FILE2_COMPARE_SCALE2 = "Tests/images/eps/non_zero_bb_scale2.png"
|
||||
|
||||
# EPS test files with binary preview
|
||||
FILE3 = "Tests/images/binary_preview_map.eps"
|
||||
FILE3 = "Tests/images/eps/binary_preview_map.eps"
|
||||
|
||||
# Three unsigned 32bit little-endian values:
|
||||
# 0xC6D3D0C5 magic number
|
||||
|
@ -80,9 +81,7 @@ simple_eps_file_with_long_binary_data = (
|
|||
|
||||
|
||||
@pytest.mark.skipif(not HAS_GHOSTSCRIPT, reason="Ghostscript not available")
|
||||
@pytest.mark.parametrize(
|
||||
("filename", "size"), ((FILE1, (460, 352)), (FILE2, (360, 252)))
|
||||
)
|
||||
@pytest.mark.parametrize("filename, size", ((FILE1, (460, 352)), (FILE2, (360, 252))))
|
||||
@pytest.mark.parametrize("scale", (1, 2))
|
||||
def test_sanity(filename: str, size: tuple[int, int], scale: int) -> None:
|
||||
expected_size = tuple(s * scale for s in size)
|
||||
|
@ -128,6 +127,15 @@ def test_binary_header_only() -> None:
|
|||
EpsImagePlugin.EpsImageFile(data)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("prefix", (b"", simple_binary_header))
|
||||
def test_simple_eps_file(prefix: bytes) -> None:
|
||||
data = io.BytesIO(prefix + b"\n".join(simple_eps_file))
|
||||
with Image.open(data) as img:
|
||||
assert img.mode == "RGB"
|
||||
assert img.size == (100, 100)
|
||||
assert img.format == "EPS"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("prefix", (b"", simple_binary_header))
|
||||
def test_missing_version_comment(prefix: bytes) -> None:
|
||||
data = io.BytesIO(prefix + b"\n".join(simple_eps_file_without_version))
|
||||
|
@ -143,23 +151,21 @@ def test_missing_boundingbox_comment(prefix: bytes) -> None:
|
|||
|
||||
|
||||
@pytest.mark.parametrize("prefix", (b"", simple_binary_header))
|
||||
def test_invalid_boundingbox_comment(prefix: bytes) -> None:
|
||||
data = io.BytesIO(prefix + b"\n".join(simple_eps_file_with_invalid_boundingbox))
|
||||
@pytest.mark.parametrize(
|
||||
"file_lines",
|
||||
(
|
||||
simple_eps_file_with_invalid_boundingbox,
|
||||
simple_eps_file_with_invalid_boundingbox_valid_imagedata,
|
||||
),
|
||||
)
|
||||
def test_invalid_boundingbox_comment(
|
||||
prefix: bytes, file_lines: tuple[bytes, ...]
|
||||
) -> None:
|
||||
data = io.BytesIO(prefix + b"\n".join(file_lines))
|
||||
with pytest.raises(OSError, match="cannot determine EPS bounding box"):
|
||||
EpsImagePlugin.EpsImageFile(data)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("prefix", (b"", simple_binary_header))
|
||||
def test_invalid_boundingbox_comment_valid_imagedata_comment(prefix: bytes) -> None:
|
||||
data = io.BytesIO(
|
||||
prefix + b"\n".join(simple_eps_file_with_invalid_boundingbox_valid_imagedata)
|
||||
)
|
||||
with Image.open(data) as img:
|
||||
assert img.mode == "RGB"
|
||||
assert img.size == (100, 100)
|
||||
assert img.format == "EPS"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("prefix", (b"", simple_binary_header))
|
||||
def test_ascii_comment_too_long(prefix: bytes) -> None:
|
||||
data = io.BytesIO(prefix + b"\n".join(simple_eps_file_with_long_ascii_comment))
|
||||
|
@ -179,7 +185,7 @@ def test_load_long_binary_data(prefix: bytes) -> None:
|
|||
data = io.BytesIO(prefix + b"\n".join(simple_eps_file_with_long_binary_data))
|
||||
with Image.open(data) as img:
|
||||
img.load()
|
||||
assert img.mode == "RGB"
|
||||
assert img.mode == "1"
|
||||
assert img.size == (100, 100)
|
||||
assert img.format == "EPS"
|
||||
|
||||
|
@ -189,7 +195,7 @@ def test_load_long_binary_data(prefix: bytes) -> None:
|
|||
)
|
||||
@pytest.mark.skipif(not HAS_GHOSTSCRIPT, reason="Ghostscript not available")
|
||||
def test_cmyk() -> None:
|
||||
with Image.open("Tests/images/pil_sample_cmyk.eps") as cmyk_image:
|
||||
with Image.open("Tests/images/eps/pil_sample_cmyk.eps") as cmyk_image:
|
||||
assert cmyk_image.mode == "CMYK"
|
||||
assert cmyk_image.size == (100, 100)
|
||||
assert cmyk_image.format == "EPS"
|
||||
|
@ -206,8 +212,8 @@ def test_cmyk() -> None:
|
|||
@pytest.mark.skipif(not HAS_GHOSTSCRIPT, reason="Ghostscript not available")
|
||||
def test_showpage() -> None:
|
||||
# See https://github.com/python-pillow/Pillow/issues/2615
|
||||
with Image.open("Tests/images/reqd_showpage.eps") as plot_image:
|
||||
with Image.open("Tests/images/reqd_showpage.png") as target:
|
||||
with Image.open("Tests/images/eps/reqd_showpage.eps") as plot_image:
|
||||
with Image.open("Tests/images/eps/reqd_showpage.png") as target:
|
||||
# should not crash/hang
|
||||
plot_image.load()
|
||||
# fonts could be slightly different
|
||||
|
@ -216,11 +222,11 @@ def test_showpage() -> None:
|
|||
|
||||
@pytest.mark.skipif(not HAS_GHOSTSCRIPT, reason="Ghostscript not available")
|
||||
def test_transparency() -> None:
|
||||
with Image.open("Tests/images/reqd_showpage.eps") as plot_image:
|
||||
with Image.open("Tests/images/eps/reqd_showpage.eps") as plot_image:
|
||||
plot_image.load(transparency=True)
|
||||
assert plot_image.mode == "RGBA"
|
||||
|
||||
with Image.open("Tests/images/reqd_showpage_transparency.png") as target:
|
||||
with Image.open("Tests/images/eps/reqd_showpage_transparency.png") as target:
|
||||
# fonts could be slightly different
|
||||
assert_image_similar(plot_image, target, 6)
|
||||
|
||||
|
@ -247,9 +253,19 @@ def test_bytesio_object() -> None:
|
|||
assert_image_similar(img, image1_scale1_compare, 5)
|
||||
|
||||
|
||||
def test_1_mode() -> None:
|
||||
with Image.open("Tests/images/1.eps") as im:
|
||||
assert im.mode == "1"
|
||||
@pytest.mark.skipif(not HAS_GHOSTSCRIPT, reason="Ghostscript not available")
|
||||
@pytest.mark.parametrize(
|
||||
# These images have an "ImageData" descriptor.
|
||||
"filename",
|
||||
(
|
||||
"Tests/images/eps/1.eps",
|
||||
"Tests/images/eps/1_boundingbox_after_imagedata.eps",
|
||||
"Tests/images/eps/1_second_imagedata.eps",
|
||||
),
|
||||
)
|
||||
def test_1(filename: str) -> None:
|
||||
with Image.open(filename) as im:
|
||||
assert_image_equal_tofile(im, "Tests/images/eps/1.bmp")
|
||||
|
||||
|
||||
def test_image_mode_not_supported(tmp_path: Path) -> None:
|
||||
|
@ -304,7 +320,9 @@ def test_render_scale2() -> None:
|
|||
|
||||
|
||||
@pytest.mark.skipif(not HAS_GHOSTSCRIPT, reason="Ghostscript not available")
|
||||
@pytest.mark.parametrize("filename", (FILE1, FILE2, "Tests/images/illu10_preview.eps"))
|
||||
@pytest.mark.parametrize(
|
||||
"filename", (FILE1, FILE2, "Tests/images/eps/illu10_preview.eps")
|
||||
)
|
||||
def test_resize(filename: str) -> None:
|
||||
with Image.open(filename) as im:
|
||||
new_size = (100, 100)
|
||||
|
@ -346,10 +364,10 @@ def test_readline(prefix: bytes, line_ending: bytes) -> None:
|
|||
@pytest.mark.parametrize(
|
||||
"filename",
|
||||
(
|
||||
"Tests/images/illu10_no_preview.eps",
|
||||
"Tests/images/illu10_preview.eps",
|
||||
"Tests/images/illuCS6_no_preview.eps",
|
||||
"Tests/images/illuCS6_preview.eps",
|
||||
"Tests/images/eps/illu10_no_preview.eps",
|
||||
"Tests/images/eps/illu10_preview.eps",
|
||||
"Tests/images/eps/illuCS6_no_preview.eps",
|
||||
"Tests/images/eps/illuCS6_preview.eps",
|
||||
),
|
||||
)
|
||||
def test_open_eps(filename: str) -> None:
|
||||
|
@ -361,7 +379,7 @@ def test_open_eps(filename: str) -> None:
|
|||
@pytest.mark.skipif(not HAS_GHOSTSCRIPT, reason="Ghostscript not available")
|
||||
def test_emptyline() -> None:
|
||||
# Test file includes an empty line in the header data
|
||||
emptyline_file = "Tests/images/zero_bb_emptyline.eps"
|
||||
emptyline_file = "Tests/images/eps/zero_bb_emptyline.eps"
|
||||
|
||||
with Image.open(emptyline_file) as image:
|
||||
image.load()
|
||||
|
@ -373,7 +391,7 @@ def test_emptyline() -> None:
|
|||
@pytest.mark.timeout(timeout=5)
|
||||
@pytest.mark.parametrize(
|
||||
"test_file",
|
||||
["Tests/images/timeout-d675703545fee17acab56e5fec644c19979175de.eps"],
|
||||
["Tests/images/eps/timeout-d675703545fee17acab56e5fec644c19979175de.eps"],
|
||||
)
|
||||
def test_timeout(test_file: str) -> None:
|
||||
with open(test_file, "rb") as f:
|
||||
|
@ -386,7 +404,7 @@ def test_bounding_box_in_trailer() -> None:
|
|||
# Check bounding boxes are parsed in the same way
|
||||
# when specified in the header and the trailer
|
||||
with (
|
||||
Image.open("Tests/images/zero_bb_trailer.eps") as trailer_image,
|
||||
Image.open("Tests/images/eps/zero_bb_trailer.eps") as trailer_image,
|
||||
Image.open(FILE1) as header_image,
|
||||
):
|
||||
assert trailer_image.size == header_image.size
|
||||
|
@ -394,12 +412,12 @@ def test_bounding_box_in_trailer() -> None:
|
|||
|
||||
def test_eof_before_bounding_box() -> None:
|
||||
with pytest.raises(OSError):
|
||||
with Image.open("Tests/images/zero_bb_eof_before_boundingbox.eps"):
|
||||
with Image.open("Tests/images/eps/zero_bb_eof_before_boundingbox.eps"):
|
||||
pass
|
||||
|
||||
|
||||
def test_invalid_data_after_eof() -> None:
|
||||
with open("Tests/images/illuCS6_preview.eps", "rb") as f:
|
||||
with open("Tests/images/eps/illuCS6_preview.eps", "rb") as f:
|
||||
img_bytes = io.BytesIO(f.read() + b"\r\n%" + (b" " * 255))
|
||||
|
||||
with Image.open(img_bytes) as img:
|
||||
|
|
|
@ -65,6 +65,8 @@ def test_unclosed_file() -> None:
|
|||
|
||||
def test_closed_file() -> None:
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("error")
|
||||
|
||||
im = Image.open(static_test_file)
|
||||
im.load()
|
||||
im.close()
|
||||
|
@ -81,6 +83,8 @@ def test_seek_after_close() -> None:
|
|||
|
||||
def test_context_manager() -> None:
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("error")
|
||||
|
||||
with Image.open(static_test_file) as im:
|
||||
im.load()
|
||||
|
||||
|
|
|
@ -46,6 +46,8 @@ def test_unclosed_file() -> None:
|
|||
|
||||
def test_closed_file() -> None:
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("error")
|
||||
|
||||
im = Image.open(TEST_GIF)
|
||||
im.load()
|
||||
im.close()
|
||||
|
@ -67,6 +69,8 @@ def test_seek_after_close() -> None:
|
|||
|
||||
def test_context_manager() -> None:
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("error")
|
||||
|
||||
with Image.open(TEST_GIF) as im:
|
||||
im.load()
|
||||
|
||||
|
@ -978,7 +982,7 @@ def test_webp_background(tmp_path: Path) -> None:
|
|||
out = str(tmp_path / "temp.gif")
|
||||
|
||||
# Test opaque WebP background
|
||||
if features.check("webp") and features.check("webp_anim"):
|
||||
if features.check("webp"):
|
||||
with Image.open("Tests/images/hopper.webp") as im:
|
||||
assert im.info["background"] == (255, 255, 255, 255)
|
||||
im.save(out)
|
||||
|
@ -1378,16 +1382,39 @@ def test_lzw_bits() -> None:
|
|||
im.load()
|
||||
|
||||
|
||||
def test_extents() -> None:
|
||||
with Image.open("Tests/images/test_extents.gif") as im:
|
||||
assert im.size == (100, 100)
|
||||
@pytest.mark.parametrize(
|
||||
"test_file, loading_strategy",
|
||||
(
|
||||
("test_extents.gif", GifImagePlugin.LoadingStrategy.RGB_AFTER_FIRST),
|
||||
(
|
||||
"test_extents.gif",
|
||||
GifImagePlugin.LoadingStrategy.RGB_AFTER_DIFFERENT_PALETTE_ONLY,
|
||||
),
|
||||
(
|
||||
"test_extents_transparency.gif",
|
||||
GifImagePlugin.LoadingStrategy.RGB_AFTER_FIRST,
|
||||
),
|
||||
),
|
||||
)
|
||||
def test_extents(
|
||||
test_file: str, loading_strategy: GifImagePlugin.LoadingStrategy
|
||||
) -> None:
|
||||
GifImagePlugin.LOADING_STRATEGY = loading_strategy
|
||||
try:
|
||||
with Image.open("Tests/images/" + test_file) as im:
|
||||
assert im.size == (100, 100)
|
||||
|
||||
# Check that n_frames does not change the size
|
||||
assert im.n_frames == 2
|
||||
assert im.size == (100, 100)
|
||||
# Check that n_frames does not change the size
|
||||
assert im.n_frames == 2
|
||||
assert im.size == (100, 100)
|
||||
|
||||
im.seek(1)
|
||||
assert im.size == (150, 150)
|
||||
im.seek(1)
|
||||
assert im.size == (150, 150)
|
||||
|
||||
im.load()
|
||||
assert im.im.size == (150, 150)
|
||||
finally:
|
||||
GifImagePlugin.LOADING_STRATEGY = GifImagePlugin.LoadingStrategy.RGB_AFTER_FIRST
|
||||
|
||||
|
||||
def test_missing_background() -> None:
|
||||
|
@ -1406,3 +1433,21 @@ def test_saving_rgba(tmp_path: Path) -> None:
|
|||
with Image.open(out) as reloaded:
|
||||
reloaded_rgba = reloaded.convert("RGBA")
|
||||
assert reloaded_rgba.load()[0, 0][3] == 0
|
||||
|
||||
|
||||
def test_optimizing_p_rgba(tmp_path: Path) -> None:
|
||||
out = str(tmp_path / "temp.gif")
|
||||
|
||||
im1 = Image.new("P", (100, 100))
|
||||
d = ImageDraw.Draw(im1)
|
||||
d.ellipse([(40, 40), (60, 60)], fill=1)
|
||||
data = [0, 0, 0, 0, 0, 0, 0, 255] + [0, 0, 0, 0] * 254
|
||||
im1.putpalette(data, "RGBA")
|
||||
|
||||
im2 = Image.new("P", (100, 100))
|
||||
im2.putpalette(data, "RGBA")
|
||||
|
||||
im1.save(out, save_all=True, append_images=[im2])
|
||||
|
||||
with Image.open(out) as reloaded:
|
||||
assert reloaded.n_frames == 2
|
||||
|
|
|
@ -21,6 +21,8 @@ def test_sanity() -> None:
|
|||
with Image.open(TEST_FILE) as im:
|
||||
# Assert that there is no unclosed file warning
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("error")
|
||||
|
||||
im.load()
|
||||
|
||||
assert im.mode == "RGBA"
|
||||
|
@ -63,8 +65,8 @@ def test_save_append_images(tmp_path: Path) -> None:
|
|||
assert_image_similar_tofile(im, temp_file, 1)
|
||||
|
||||
with Image.open(temp_file) as reread:
|
||||
reread.size = (16, 16, 2)
|
||||
reread.load()
|
||||
reread.size = (16, 16)
|
||||
reread.load(2)
|
||||
assert_image_equal(reread, provided_im)
|
||||
|
||||
|
||||
|
@ -87,14 +89,21 @@ def test_sizes() -> None:
|
|||
for w, h, r in im.info["sizes"]:
|
||||
wr = w * r
|
||||
hr = h * r
|
||||
im.size = (w, h, r)
|
||||
with pytest.warns(DeprecationWarning):
|
||||
im.size = (w, h, r)
|
||||
im.load()
|
||||
assert im.mode == "RGBA"
|
||||
assert im.size == (wr, hr)
|
||||
|
||||
# Test using load() with scale
|
||||
im.size = (w, h)
|
||||
im.load(scale=r)
|
||||
assert im.mode == "RGBA"
|
||||
assert im.size == (wr, hr)
|
||||
|
||||
# Check that we cannot load an incorrect size
|
||||
with pytest.raises(ValueError):
|
||||
im.size = (1, 1)
|
||||
im.size = (1, 2)
|
||||
|
||||
|
||||
def test_older_icon() -> None:
|
||||
|
@ -105,8 +114,8 @@ def test_older_icon() -> None:
|
|||
wr = w * r
|
||||
hr = h * r
|
||||
with Image.open("Tests/images/pillow2.icns") as im2:
|
||||
im2.size = (w, h, r)
|
||||
im2.load()
|
||||
im2.size = (w, h)
|
||||
im2.load(r)
|
||||
assert im2.mode == "RGBA"
|
||||
assert im2.size == (wr, hr)
|
||||
|
||||
|
@ -122,8 +131,8 @@ def test_jp2_icon() -> None:
|
|||
wr = w * r
|
||||
hr = h * r
|
||||
with Image.open("Tests/images/pillow3.icns") as im2:
|
||||
im2.size = (w, h, r)
|
||||
im2.load()
|
||||
im2.size = (w, h)
|
||||
im2.load(r)
|
||||
assert im2.mode == "RGBA"
|
||||
assert im2.size == (wr, hr)
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ from pathlib import Path
|
|||
|
||||
import pytest
|
||||
|
||||
from PIL import IcoImagePlugin, Image, ImageDraw
|
||||
from PIL import IcoImagePlugin, Image, ImageDraw, ImageFile
|
||||
|
||||
from .helper import assert_image_equal, assert_image_equal_tofile, hopper
|
||||
|
||||
|
@ -241,3 +241,29 @@ def test_draw_reloaded(tmp_path: Path) -> None:
|
|||
|
||||
with Image.open(outfile) as im:
|
||||
assert_image_equal_tofile(im, "Tests/images/hopper_draw.ico")
|
||||
|
||||
|
||||
def test_truncated_mask() -> None:
|
||||
# 1 bpp
|
||||
with open("Tests/images/hopper_mask.ico", "rb") as fp:
|
||||
data = fp.read()
|
||||
|
||||
ImageFile.LOAD_TRUNCATED_IMAGES = True
|
||||
data = data[:-3]
|
||||
|
||||
try:
|
||||
with Image.open(io.BytesIO(data)) as im:
|
||||
with Image.open("Tests/images/hopper_mask.png") as expected:
|
||||
assert im.mode == "1"
|
||||
|
||||
# 32 bpp
|
||||
output = io.BytesIO()
|
||||
expected = hopper("RGBA")
|
||||
expected.save(output, "ico", bitmap_format="bmp")
|
||||
|
||||
data = output.getvalue()[:-1]
|
||||
|
||||
with Image.open(io.BytesIO(data)) as im:
|
||||
assert im.mode == "RGB"
|
||||
finally:
|
||||
ImageFile.LOAD_TRUNCATED_IMAGES = False
|
||||
|
|
|
@ -41,6 +41,8 @@ def test_unclosed_file() -> None:
|
|||
|
||||
def test_closed_file() -> None:
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("error")
|
||||
|
||||
im = Image.open(TEST_IM)
|
||||
im.load()
|
||||
im.close()
|
||||
|
@ -48,6 +50,8 @@ def test_closed_file() -> None:
|
|||
|
||||
def test_context_manager() -> None:
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("error")
|
||||
|
||||
with Image.open(TEST_IM) as im:
|
||||
im.load()
|
||||
|
||||
|
|
|
@ -57,6 +57,7 @@ def test_getiptcinfo_fotostation() -> None:
|
|||
iptc = IptcImagePlugin.getiptcinfo(im)
|
||||
|
||||
# Assert
|
||||
assert iptc is not None
|
||||
for tag in iptc.keys():
|
||||
if tag[0] == 240:
|
||||
return
|
||||
|
@ -76,6 +77,16 @@ def test_getiptcinfo_zero_padding() -> None:
|
|||
assert len(iptc) == 3
|
||||
|
||||
|
||||
def test_getiptcinfo_tiff() -> None:
|
||||
# Arrange
|
||||
with Image.open("Tests/images/hopper.Lab.tif") as im:
|
||||
# Act
|
||||
iptc = IptcImagePlugin.getiptcinfo(im)
|
||||
|
||||
# Assert
|
||||
assert iptc == {(1, 90): b"\x1b%G", (2, 0): b"\xcf\xc0"}
|
||||
|
||||
|
||||
def test_getiptcinfo_tiff_none() -> None:
|
||||
# Arrange
|
||||
with Image.open("Tests/images/hopper.tif") as im:
|
||||
|
|
|
@ -154,7 +154,7 @@ class TestFileJpeg:
|
|||
assert k > 0.9
|
||||
|
||||
def test_rgb(self) -> None:
|
||||
def getchannels(im: JpegImagePlugin.JpegImageFile) -> tuple[int, int, int]:
|
||||
def getchannels(im: JpegImagePlugin.JpegImageFile) -> tuple[int, ...]:
|
||||
return tuple(v[0] for v in im.layer)
|
||||
|
||||
im = hopper()
|
||||
|
@ -541,12 +541,12 @@ class TestFileJpeg:
|
|||
@mark_if_feature_version(
|
||||
pytest.mark.valgrind_known_error, "libjpeg_turbo", "2.0", reason="Known Failing"
|
||||
)
|
||||
def test_qtables(self, tmp_path: Path) -> None:
|
||||
def test_qtables(self) -> None:
|
||||
def _n_qtables_helper(n: int, test_file: str) -> None:
|
||||
b = BytesIO()
|
||||
with Image.open(test_file) as im:
|
||||
f = str(tmp_path / "temp.jpg")
|
||||
im.save(f, qtables=[[n] * 64] * n)
|
||||
with Image.open(f) as im:
|
||||
im.save(b, "JPEG", qtables=[[n] * 64] * n)
|
||||
with Image.open(b) as im:
|
||||
assert len(im.quantization) == n
|
||||
reloaded = self.roundtrip(im, qtables="keep")
|
||||
assert im.quantization == reloaded.quantization
|
||||
|
@ -850,6 +850,8 @@ class TestFileJpeg:
|
|||
|
||||
out = str(tmp_path / "out.jpg")
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("error")
|
||||
|
||||
im.save(out, exif=exif)
|
||||
|
||||
with Image.open(out) as reloaded:
|
||||
|
@ -991,12 +993,29 @@ class TestFileJpeg:
|
|||
else:
|
||||
assert im.getxmp() == {"xmpmeta": None}
|
||||
|
||||
def test_save_xmp(self, tmp_path: Path) -> None:
|
||||
f = str(tmp_path / "temp.jpg")
|
||||
im = hopper()
|
||||
im.save(f, xmp=b"XMP test")
|
||||
with Image.open(f) as reloaded:
|
||||
assert reloaded.info["xmp"] == b"XMP test"
|
||||
|
||||
im.info["xmp"] = b"1" * 65504
|
||||
im.save(f)
|
||||
with Image.open(f) as reloaded:
|
||||
assert reloaded.info["xmp"] == b"1" * 65504
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
im.save(f, xmp=b"1" * 65505)
|
||||
|
||||
@pytest.mark.timeout(timeout=1)
|
||||
def test_eof(self) -> None:
|
||||
# Even though this decoder never says that it is finished
|
||||
# the image should still end when there is no new data
|
||||
class InfiniteMockPyDecoder(ImageFile.PyDecoder):
|
||||
def decode(self, buffer: bytes) -> tuple[int, int]:
|
||||
def decode(
|
||||
self, buffer: bytes | Image.SupportsArrayInterface
|
||||
) -> tuple[int, int]:
|
||||
return 0, 0
|
||||
|
||||
Image.register_decoder("INFINITE", InfiniteMockPyDecoder)
|
||||
|
@ -1019,13 +1038,16 @@ class TestFileJpeg:
|
|||
|
||||
# SOI, EOI
|
||||
for marker in b"\xff\xd8", b"\xff\xd9":
|
||||
assert marker in data[1] and marker in data[2]
|
||||
assert marker in data[1]
|
||||
assert marker in data[2]
|
||||
# DHT, DQT
|
||||
for marker in b"\xff\xc4", b"\xff\xdb":
|
||||
assert marker in data[1] and marker not in data[2]
|
||||
assert marker in data[1]
|
||||
assert marker not in data[2]
|
||||
# SOF0, SOS, APP0 (JFIF header)
|
||||
for marker in b"\xff\xc0", b"\xff\xda", b"\xff\xe0":
|
||||
assert marker not in data[1] and marker in data[2]
|
||||
assert marker not in data[1]
|
||||
assert marker in data[2]
|
||||
|
||||
with Image.open(BytesIO(data[0])) as interchange_im:
|
||||
with Image.open(BytesIO(data[1] + data[2])) as combined_im:
|
||||
|
@ -1045,6 +1067,13 @@ class TestFileJpeg:
|
|||
|
||||
assert im._repr_jpeg_() is None
|
||||
|
||||
def test_deprecation(self) -> None:
|
||||
with Image.open(TEST_FILE) as im:
|
||||
with pytest.warns(DeprecationWarning):
|
||||
assert im.huffman_ac == {}
|
||||
with pytest.warns(DeprecationWarning):
|
||||
assert im.huffman_dc == {}
|
||||
|
||||
|
||||
@pytest.mark.skipif(not is_win32(), reason="Windows only")
|
||||
@skip_unless_feature("jpg")
|
||||
|
|
|
@ -2,6 +2,7 @@ from __future__ import annotations
|
|||
|
||||
import os
|
||||
import re
|
||||
from collections.abc import Generator
|
||||
from io import BytesIO
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
@ -29,8 +30,16 @@ EXTRA_DIR = "Tests/images/jpeg2000"
|
|||
|
||||
pytestmark = skip_unless_feature("jpg_2000")
|
||||
|
||||
test_card = Image.open("Tests/images/test-card.png")
|
||||
test_card.load()
|
||||
|
||||
@pytest.fixture
|
||||
def card() -> Generator[ImageFile.ImageFile, None, None]:
|
||||
with Image.open("Tests/images/test-card.png") as im:
|
||||
im.load()
|
||||
try:
|
||||
yield im
|
||||
finally:
|
||||
im.close()
|
||||
|
||||
|
||||
# OpenJPEG 2.0.0 outputs this debugging message sometimes; we should
|
||||
# ignore it---it doesn't represent a test failure.
|
||||
|
@ -74,76 +83,76 @@ def test_invalid_file() -> None:
|
|||
Jpeg2KImagePlugin.Jpeg2KImageFile(invalid_file)
|
||||
|
||||
|
||||
def test_bytesio() -> None:
|
||||
def test_bytesio(card: ImageFile.ImageFile) -> None:
|
||||
with open("Tests/images/test-card-lossless.jp2", "rb") as f:
|
||||
data = BytesIO(f.read())
|
||||
with Image.open(data) as im:
|
||||
im.load()
|
||||
assert_image_similar(im, test_card, 1.0e-3)
|
||||
assert_image_similar(im, card, 1.0e-3)
|
||||
|
||||
|
||||
# These two test pre-written JPEG 2000 files that were not written with
|
||||
# PIL (they were made using Adobe Photoshop)
|
||||
|
||||
|
||||
def test_lossless(tmp_path: Path) -> None:
|
||||
def test_lossless(card: ImageFile.ImageFile, tmp_path: Path) -> None:
|
||||
with Image.open("Tests/images/test-card-lossless.jp2") as im:
|
||||
im.load()
|
||||
outfile = str(tmp_path / "temp_test-card.png")
|
||||
im.save(outfile)
|
||||
assert_image_similar(im, test_card, 1.0e-3)
|
||||
assert_image_similar(im, card, 1.0e-3)
|
||||
|
||||
|
||||
def test_lossy_tiled() -> None:
|
||||
assert_image_similar_tofile(
|
||||
test_card, "Tests/images/test-card-lossy-tiled.jp2", 2.0
|
||||
)
|
||||
def test_lossy_tiled(card: ImageFile.ImageFile) -> None:
|
||||
assert_image_similar_tofile(card, "Tests/images/test-card-lossy-tiled.jp2", 2.0)
|
||||
|
||||
|
||||
def test_lossless_rt() -> None:
|
||||
im = roundtrip(test_card)
|
||||
assert_image_equal(im, test_card)
|
||||
def test_lossless_rt(card: ImageFile.ImageFile) -> None:
|
||||
im = roundtrip(card)
|
||||
assert_image_equal(im, card)
|
||||
|
||||
|
||||
def test_lossy_rt() -> None:
|
||||
im = roundtrip(test_card, quality_layers=[20])
|
||||
assert_image_similar(im, test_card, 2.0)
|
||||
def test_lossy_rt(card: ImageFile.ImageFile) -> None:
|
||||
im = roundtrip(card, quality_layers=[20])
|
||||
assert_image_similar(im, card, 2.0)
|
||||
|
||||
|
||||
def test_tiled_rt() -> None:
|
||||
im = roundtrip(test_card, tile_size=(128, 128))
|
||||
assert_image_equal(im, test_card)
|
||||
def test_tiled_rt(card: ImageFile.ImageFile) -> None:
|
||||
im = roundtrip(card, tile_size=(128, 128))
|
||||
assert_image_equal(im, card)
|
||||
|
||||
|
||||
def test_tiled_offset_rt() -> None:
|
||||
im = roundtrip(test_card, tile_size=(128, 128), tile_offset=(0, 0), offset=(32, 32))
|
||||
assert_image_equal(im, test_card)
|
||||
def test_tiled_offset_rt(card: ImageFile.ImageFile) -> None:
|
||||
im = roundtrip(card, tile_size=(128, 128), tile_offset=(0, 0), offset=(32, 32))
|
||||
assert_image_equal(im, card)
|
||||
|
||||
|
||||
def test_tiled_offset_too_small() -> None:
|
||||
def test_tiled_offset_too_small(card: ImageFile.ImageFile) -> None:
|
||||
with pytest.raises(ValueError):
|
||||
roundtrip(test_card, tile_size=(128, 128), tile_offset=(0, 0), offset=(128, 32))
|
||||
roundtrip(card, tile_size=(128, 128), tile_offset=(0, 0), offset=(128, 32))
|
||||
|
||||
|
||||
def test_irreversible_rt() -> None:
|
||||
im = roundtrip(test_card, irreversible=True, quality_layers=[20])
|
||||
assert_image_similar(im, test_card, 2.0)
|
||||
def test_irreversible_rt(card: ImageFile.ImageFile) -> None:
|
||||
im = roundtrip(card, irreversible=True, quality_layers=[20])
|
||||
assert_image_similar(im, card, 2.0)
|
||||
|
||||
|
||||
def test_prog_qual_rt() -> None:
|
||||
im = roundtrip(test_card, quality_layers=[60, 40, 20], progression="LRCP")
|
||||
assert_image_similar(im, test_card, 2.0)
|
||||
def test_prog_qual_rt(card: ImageFile.ImageFile) -> None:
|
||||
im = roundtrip(card, quality_layers=[60, 40, 20], progression="LRCP")
|
||||
assert_image_similar(im, card, 2.0)
|
||||
|
||||
|
||||
def test_prog_res_rt() -> None:
|
||||
im = roundtrip(test_card, num_resolutions=8, progression="RLCP")
|
||||
assert_image_equal(im, test_card)
|
||||
def test_prog_res_rt(card: ImageFile.ImageFile) -> None:
|
||||
im = roundtrip(card, num_resolutions=8, progression="RLCP")
|
||||
assert_image_equal(im, card)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("num_resolutions", range(2, 6))
|
||||
def test_default_num_resolutions(num_resolutions: int) -> None:
|
||||
def test_default_num_resolutions(
|
||||
card: ImageFile.ImageFile, num_resolutions: int
|
||||
) -> None:
|
||||
d = 1 << (num_resolutions - 1)
|
||||
im = test_card.resize((d - 1, d - 1))
|
||||
im = card.resize((d - 1, d - 1))
|
||||
with pytest.raises(OSError):
|
||||
roundtrip(im, num_resolutions=num_resolutions)
|
||||
reloaded = roundtrip(im)
|
||||
|
@ -182,6 +191,15 @@ def test_restricted_icc_profile() -> None:
|
|||
ImageFile.LOAD_TRUNCATED_IMAGES = False
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
not os.path.exists(EXTRA_DIR), reason="Extra image files not installed"
|
||||
)
|
||||
def test_unknown_colorspace() -> None:
|
||||
with Image.open(f"{EXTRA_DIR}/file8.jp2") as im:
|
||||
im.load()
|
||||
assert im.mode == "L"
|
||||
|
||||
|
||||
def test_header_errors() -> None:
|
||||
for path in (
|
||||
"Tests/images/invalid_header_length.jp2",
|
||||
|
@ -196,31 +214,31 @@ def test_header_errors() -> None:
|
|||
pass
|
||||
|
||||
|
||||
def test_layers_type(tmp_path: Path) -> None:
|
||||
def test_layers_type(card: ImageFile.ImageFile, tmp_path: Path) -> None:
|
||||
outfile = str(tmp_path / "temp_layers.jp2")
|
||||
for quality_layers in [[100, 50, 10], (100, 50, 10), None]:
|
||||
test_card.save(outfile, quality_layers=quality_layers)
|
||||
card.save(outfile, quality_layers=quality_layers)
|
||||
|
||||
for quality_layers_str in ["quality_layers", ("100", "50", "10")]:
|
||||
with pytest.raises(ValueError):
|
||||
test_card.save(outfile, quality_layers=quality_layers_str)
|
||||
card.save(outfile, quality_layers=quality_layers_str)
|
||||
|
||||
|
||||
def test_layers() -> None:
|
||||
def test_layers(card: ImageFile.ImageFile) -> None:
|
||||
out = BytesIO()
|
||||
test_card.save(out, "JPEG2000", quality_layers=[100, 50, 10], progression="LRCP")
|
||||
card.save(out, "JPEG2000", quality_layers=[100, 50, 10], progression="LRCP")
|
||||
out.seek(0)
|
||||
|
||||
with Image.open(out) as im:
|
||||
im.layers = 1
|
||||
im.load()
|
||||
assert_image_similar(im, test_card, 13)
|
||||
assert_image_similar(im, card, 13)
|
||||
|
||||
out.seek(0)
|
||||
with Image.open(out) as im:
|
||||
im.layers = 3
|
||||
im.load()
|
||||
assert_image_similar(im, test_card, 0.4)
|
||||
assert_image_similar(im, card, 0.4)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
@ -233,27 +251,33 @@ def test_layers() -> None:
|
|||
("foo.jp2", {"no_jp2": True}, 0, b"\xff\x4f"),
|
||||
("foo.j2k", {"no_jp2": False}, 0, b"\xff\x4f"),
|
||||
("foo.jp2", {"no_jp2": False}, 4, b"jP"),
|
||||
("foo.jp2", {"no_jp2": False}, 4, b"jP"),
|
||||
(None, {"no_jp2": False}, 4, b"jP"),
|
||||
),
|
||||
)
|
||||
def test_no_jp2(name: str, args: dict[str, bool], offset: int, data: bytes) -> None:
|
||||
def test_no_jp2(
|
||||
card: ImageFile.ImageFile,
|
||||
name: str,
|
||||
args: dict[str, bool],
|
||||
offset: int,
|
||||
data: bytes,
|
||||
) -> None:
|
||||
out = BytesIO()
|
||||
if name:
|
||||
out.name = name
|
||||
test_card.save(out, "JPEG2000", **args)
|
||||
card.save(out, "JPEG2000", **args)
|
||||
out.seek(offset)
|
||||
assert out.read(2) == data
|
||||
|
||||
|
||||
def test_mct() -> None:
|
||||
def test_mct(card: ImageFile.ImageFile) -> None:
|
||||
# Three component
|
||||
for val in (0, 1):
|
||||
out = BytesIO()
|
||||
test_card.save(out, "JPEG2000", mct=val, no_jp2=True)
|
||||
card.save(out, "JPEG2000", mct=val, no_jp2=True)
|
||||
|
||||
assert out.getvalue()[59] == val
|
||||
with Image.open(out) as im:
|
||||
assert_image_similar(im, test_card, 1.0e-3)
|
||||
assert_image_similar(im, card, 1.0e-3)
|
||||
|
||||
# Single component should have MCT disabled
|
||||
for val in (0, 1):
|
||||
|
@ -391,6 +415,13 @@ def test_pclr() -> None:
|
|||
assert len(im.palette.colors) == 256
|
||||
assert im.palette.colors[(255, 255, 255)] == 0
|
||||
|
||||
with Image.open(
|
||||
f"{EXTRA_DIR}/147af3f1083de4393666b7d99b01b58b_signal_sigsegv_130c531_6155_5136.jp2"
|
||||
) as im:
|
||||
assert im.mode == "P"
|
||||
assert len(im.palette.colors) == 139
|
||||
assert im.palette.colors[(0, 0, 0, 0)] == 0
|
||||
|
||||
|
||||
def test_comment() -> None:
|
||||
with Image.open("Tests/images/comment.jp2") as im:
|
||||
|
@ -403,22 +434,22 @@ def test_comment() -> None:
|
|||
pass
|
||||
|
||||
|
||||
def test_save_comment() -> None:
|
||||
def test_save_comment(card: ImageFile.ImageFile) -> None:
|
||||
for comment in ("Created by Pillow", b"Created by Pillow"):
|
||||
out = BytesIO()
|
||||
test_card.save(out, "JPEG2000", comment=comment)
|
||||
card.save(out, "JPEG2000", comment=comment)
|
||||
|
||||
with Image.open(out) as im:
|
||||
assert im.info["comment"] == b"Created by Pillow"
|
||||
|
||||
out = BytesIO()
|
||||
long_comment = b" " * 65531
|
||||
test_card.save(out, "JPEG2000", comment=long_comment)
|
||||
card.save(out, "JPEG2000", comment=long_comment)
|
||||
with Image.open(out) as im:
|
||||
assert im.info["comment"] == long_comment
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
test_card.save(out, "JPEG2000", comment=long_comment + b" ")
|
||||
card.save(out, "JPEG2000", comment=long_comment + b" ")
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
@ -441,10 +472,10 @@ def test_crashes(test_file: str) -> None:
|
|||
|
||||
|
||||
@skip_unless_feature_version("jpg_2000", "2.4.0")
|
||||
def test_plt_marker() -> None:
|
||||
def test_plt_marker(card: ImageFile.ImageFile) -> None:
|
||||
# Search the start of the codesteam for PLT
|
||||
out = BytesIO()
|
||||
test_card.save(out, "JPEG2000", no_jp2=True, plt=True)
|
||||
card.save(out, "JPEG2000", no_jp2=True, plt=True)
|
||||
out.seek(0)
|
||||
while True:
|
||||
marker = out.read(2)
|
||||
|
|
|
@ -1098,6 +1098,25 @@ class TestFileLibTiff(LibTiffTestCase):
|
|||
|
||||
assert_image_similar(base_im, im, 0.7)
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"test_file",
|
||||
[
|
||||
"Tests/images/old-style-jpeg-compression-no-samplesperpixel.tif",
|
||||
"Tests/images/old-style-jpeg-compression.tif",
|
||||
],
|
||||
)
|
||||
def test_buffering(self, test_file: str) -> None:
|
||||
# load exif first
|
||||
with Image.open(open(test_file, "rb", buffering=1048576)) as im:
|
||||
exif = dict(im.getexif())
|
||||
|
||||
# load image before exif
|
||||
with Image.open(open(test_file, "rb", buffering=1048576)) as im2:
|
||||
im2.load()
|
||||
exif_after_load = dict(im2.getexif())
|
||||
|
||||
assert exif == exif_after_load
|
||||
|
||||
@pytest.mark.valgrind_known_error(reason="Backtrace in Python Core")
|
||||
def test_sampleformat_not_corrupted(self) -> None:
|
||||
# Assert that a TIFF image with SampleFormat=UINT tag is not corrupted
|
||||
|
|
|
@ -48,6 +48,8 @@ def test_unclosed_file() -> None:
|
|||
|
||||
def test_closed_file() -> None:
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("error")
|
||||
|
||||
im = Image.open(test_files[0])
|
||||
im.load()
|
||||
im.close()
|
||||
|
@ -63,6 +65,8 @@ def test_seek_after_close() -> None:
|
|||
|
||||
def test_context_manager() -> None:
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("error")
|
||||
|
||||
with Image.open(test_files[0]) as im:
|
||||
im.load()
|
||||
|
||||
|
|
|
@ -338,6 +338,8 @@ class TestFilePng:
|
|||
with Image.open(TEST_PNG_FILE) as im:
|
||||
# Assert that there is no unclosed file warning
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("error")
|
||||
|
||||
im.verify()
|
||||
|
||||
with Image.open(TEST_PNG_FILE) as im:
|
||||
|
@ -424,8 +426,10 @@ class TestFilePng:
|
|||
im = roundtrip(im, pnginfo=info)
|
||||
assert im.info == {"spam": "Eggs", "eggs": "Spam"}
|
||||
assert im.text == {"spam": "Eggs", "eggs": "Spam"}
|
||||
assert isinstance(im.text["spam"], PngImagePlugin.iTXt)
|
||||
assert im.text["spam"].lang == "en"
|
||||
assert im.text["spam"].tkey == "Spam"
|
||||
assert isinstance(im.text["eggs"], PngImagePlugin.iTXt)
|
||||
assert im.text["eggs"].lang == "en"
|
||||
assert im.text["eggs"].tkey == "Eggs"
|
||||
|
||||
|
|
|
@ -95,7 +95,9 @@ def test_16bit_pgm_write(tmp_path: Path) -> None:
|
|||
with Image.open("Tests/images/16_bit_binary.pgm") as im:
|
||||
filename = str(tmp_path / "temp.pgm")
|
||||
im.save(filename, "PPM")
|
||||
assert_image_equal_tofile(im, filename)
|
||||
|
||||
im.convert("I;16").save(filename, "PPM")
|
||||
assert_image_equal_tofile(im, filename)
|
||||
|
||||
|
||||
|
|
|
@ -35,6 +35,8 @@ def test_unclosed_file() -> None:
|
|||
|
||||
def test_closed_file() -> None:
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("error")
|
||||
|
||||
im = Image.open(test_file)
|
||||
im.load()
|
||||
im.close()
|
||||
|
@ -42,6 +44,8 @@ def test_closed_file() -> None:
|
|||
|
||||
def test_context_manager() -> None:
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("error")
|
||||
|
||||
with Image.open(test_file) as im:
|
||||
im.load()
|
||||
|
||||
|
|
|
@ -34,6 +34,8 @@ def test_unclosed_file() -> None:
|
|||
|
||||
def test_closed_file() -> None:
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("error")
|
||||
|
||||
im = Image.open(TEST_FILE)
|
||||
im.load()
|
||||
im.close()
|
||||
|
@ -41,6 +43,8 @@ def test_closed_file() -> None:
|
|||
|
||||
def test_context_manager() -> None:
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("error")
|
||||
|
||||
with Image.open(TEST_FILE) as im:
|
||||
im.load()
|
||||
|
||||
|
|
|
@ -37,11 +37,15 @@ def test_unclosed_file() -> None:
|
|||
|
||||
def test_close() -> None:
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("error")
|
||||
|
||||
tar = TarIO.TarIO(TEST_TAR_FILE, "hopper.jpg")
|
||||
tar.close()
|
||||
|
||||
|
||||
def test_contextmanager() -> None:
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("error")
|
||||
|
||||
with TarIO.TarIO(TEST_TAR_FILE, "hopper.jpg"):
|
||||
pass
|
||||
|
|
|
@ -72,6 +72,8 @@ class TestFileTiff:
|
|||
|
||||
def test_closed_file(self) -> None:
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("error")
|
||||
|
||||
im = Image.open("Tests/images/multipage.tiff")
|
||||
im.load()
|
||||
im.close()
|
||||
|
@ -88,6 +90,8 @@ class TestFileTiff:
|
|||
|
||||
def test_context_manager(self) -> None:
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("error")
|
||||
|
||||
with Image.open("Tests/images/multipage.tiff") as im:
|
||||
im.load()
|
||||
|
||||
|
@ -108,9 +112,6 @@ class TestFileTiff:
|
|||
assert_image_equal_tofile(im, "Tests/images/hopper.tif")
|
||||
|
||||
with Image.open("Tests/images/hopper_bigtiff.tif") as im:
|
||||
# multistrip support not yet implemented
|
||||
del im.tag_v2[273]
|
||||
|
||||
outfile = str(tmp_path / "temp.tif")
|
||||
im.save(outfile, save_all=True, append_images=[im], tiffinfo=im.tag_v2)
|
||||
|
||||
|
@ -684,6 +685,13 @@ class TestFileTiff:
|
|||
with Image.open(outfile) as reloaded:
|
||||
assert_image_equal_tofile(reloaded, infile)
|
||||
|
||||
def test_invalid_tiled_dimensions(self) -> None:
|
||||
with open("Tests/images/tiff_tiled_planar_raw.tif", "rb") as fp:
|
||||
data = fp.read()
|
||||
b = BytesIO(data[:144] + b"\x02" + data[145:])
|
||||
with pytest.raises(ValueError):
|
||||
Image.open(b)
|
||||
|
||||
@pytest.mark.parametrize("mode", ("P", "PA"))
|
||||
def test_palette(self, mode: str, tmp_path: Path) -> None:
|
||||
outfile = str(tmp_path / "temp.tif")
|
||||
|
@ -724,6 +732,20 @@ class TestFileTiff:
|
|||
with Image.open(mp) as reread:
|
||||
assert reread.n_frames == 3
|
||||
|
||||
def test_fixoffsets(self) -> None:
|
||||
b = BytesIO(b"II\x2a\x00\x00\x00\x00\x00")
|
||||
with TiffImagePlugin.AppendingTiffWriter(b) as a:
|
||||
b.seek(0)
|
||||
a.fixOffsets(1, isShort=True)
|
||||
|
||||
b.seek(0)
|
||||
a.fixOffsets(1, isLong=True)
|
||||
|
||||
# Neither short nor long
|
||||
b.seek(0)
|
||||
with pytest.raises(RuntimeError):
|
||||
a.fixOffsets(1)
|
||||
|
||||
def test_saving_icc_profile(self, tmp_path: Path) -> None:
|
||||
# Tests saving TIFF with icc_profile set.
|
||||
# At the time of writing this will only work for non-compressed tiffs
|
||||
|
|
|
@ -181,6 +181,29 @@ def test_change_stripbytecounts_tag_type(tmp_path: Path) -> None:
|
|||
assert reloaded.tag_v2.tagtype[TiffImagePlugin.STRIPBYTECOUNTS] == TiffTags.LONG
|
||||
|
||||
|
||||
def test_save_multiple_stripoffsets() -> None:
|
||||
ifd = TiffImagePlugin.ImageFileDirectory_v2()
|
||||
ifd[TiffImagePlugin.STRIPOFFSETS] = (123, 456)
|
||||
assert ifd.tagtype[TiffImagePlugin.STRIPOFFSETS] == TiffTags.LONG
|
||||
|
||||
# all values are in little-endian
|
||||
assert ifd.tobytes() == (
|
||||
# number of tags == 1
|
||||
b"\x01\x00"
|
||||
# tag id (2 bytes), type (2 bytes), count (4 bytes), value (4 bytes)
|
||||
# TiffImagePlugin.STRIPOFFSETS, TiffTags.LONG, 2, 18
|
||||
# where STRIPOFFSETS is 273, LONG is 4
|
||||
# and 18 is the offset of the tag data
|
||||
b"\x11\x01\x04\x00\x02\x00\x00\x00\x12\x00\x00\x00"
|
||||
# end of entries
|
||||
b"\x00\x00\x00\x00"
|
||||
# 26 is the total number of bytes output,
|
||||
# the offset for any auxiliary strip data that will then be appended
|
||||
# (123 + 26, 456 + 26) == (149, 482)
|
||||
b"\x95\x00\x00\x00\xe2\x01\x00\x00"
|
||||
)
|
||||
|
||||
|
||||
def test_no_duplicate_50741_tag() -> None:
|
||||
assert TAG_IDS["MakerNoteSafety"] == 50741
|
||||
assert TAG_IDS["BestQualityScale"] == 50780
|
||||
|
|
|
@ -48,8 +48,6 @@ class TestFileWebp:
|
|||
self.rgb_mode = "RGB"
|
||||
|
||||
def test_version(self) -> None:
|
||||
_webp.WebPDecoderVersion()
|
||||
_webp.WebPDecoderBuggyAlpha()
|
||||
version = features.version_module("webp")
|
||||
assert version is not None
|
||||
assert re.search(r"\d+\.\d+\.\d+$", version)
|
||||
|
@ -74,7 +72,7 @@ class TestFileWebp:
|
|||
def _roundtrip(
|
||||
self, tmp_path: Path, mode: str, epsilon: float, args: dict[str, Any] = {}
|
||||
) -> None:
|
||||
temp_file = str(tmp_path / "temp.webp")
|
||||
temp_file = tmp_path / "temp.webp"
|
||||
|
||||
hopper(mode).save(temp_file, **args)
|
||||
with Image.open(temp_file) as image:
|
||||
|
@ -117,9 +115,8 @@ class TestFileWebp:
|
|||
hopper().save(buffer_method, format="WEBP", method=6)
|
||||
assert buffer_no_args.getbuffer() != buffer_method.getbuffer()
|
||||
|
||||
@skip_unless_feature("webp_anim")
|
||||
def test_save_all(self, tmp_path: Path) -> None:
|
||||
temp_file = str(tmp_path / "temp.webp")
|
||||
temp_file = tmp_path / "temp.webp"
|
||||
im = Image.new("RGB", (1, 1))
|
||||
im2 = Image.new("RGB", (1, 1), "#f00")
|
||||
im.save(temp_file, save_all=True, append_images=[im2])
|
||||
|
@ -130,12 +127,16 @@ class TestFileWebp:
|
|||
reloaded.seek(1)
|
||||
assert_image_similar(im2, reloaded, 1)
|
||||
|
||||
def test_unsupported_image_mode(self) -> None:
|
||||
im = Image.new("1", (1, 1))
|
||||
with pytest.raises(ValueError):
|
||||
_webp.WebPEncode(im.getim(), False, 0, 0, "", 4, 0, b"", "")
|
||||
|
||||
def test_icc_profile(self, tmp_path: Path) -> None:
|
||||
self._roundtrip(tmp_path, self.rgb_mode, 12.5, {"icc_profile": None})
|
||||
if _webp.HAVE_WEBPANIM:
|
||||
self._roundtrip(
|
||||
tmp_path, self.rgb_mode, 12.5, {"icc_profile": None, "save_all": True}
|
||||
)
|
||||
self._roundtrip(
|
||||
tmp_path, self.rgb_mode, 12.5, {"icc_profile": None, "save_all": True}
|
||||
)
|
||||
|
||||
def test_write_unsupported_mode_L(self, tmp_path: Path) -> None:
|
||||
"""
|
||||
|
@ -155,40 +156,44 @@ class TestFileWebp:
|
|||
|
||||
@pytest.mark.skipif(sys.maxsize <= 2**32, reason="Requires 64-bit system")
|
||||
def test_write_encoding_error_message(self, tmp_path: Path) -> None:
|
||||
temp_file = str(tmp_path / "temp.webp")
|
||||
im = Image.new("RGB", (15000, 15000))
|
||||
with pytest.raises(ValueError) as e:
|
||||
im.save(temp_file, method=0)
|
||||
im.save(tmp_path / "temp.webp", method=0)
|
||||
assert str(e.value) == "encoding error 6"
|
||||
|
||||
@pytest.mark.skipif(sys.maxsize <= 2**32, reason="Requires 64-bit system")
|
||||
def test_write_encoding_error_bad_dimension(self, tmp_path: Path) -> None:
|
||||
im = Image.new("L", (16384, 16384))
|
||||
with pytest.raises(ValueError) as e:
|
||||
im.save(tmp_path / "temp.webp")
|
||||
assert (
|
||||
str(e.value)
|
||||
== "encoding error 5: Image size exceeds WebP limit of 16383 pixels"
|
||||
)
|
||||
|
||||
def test_WebPEncode_with_invalid_args(self) -> None:
|
||||
"""
|
||||
Calling encoder functions with no arguments should result in an error.
|
||||
"""
|
||||
|
||||
if _webp.HAVE_WEBPANIM:
|
||||
with pytest.raises(TypeError):
|
||||
_webp.WebPAnimEncoder()
|
||||
with pytest.raises(TypeError):
|
||||
_webp.WebPAnimEncoder()
|
||||
with pytest.raises(TypeError):
|
||||
_webp.WebPEncode()
|
||||
|
||||
def test_WebPDecode_with_invalid_args(self) -> None:
|
||||
def test_WebPAnimDecoder_with_invalid_args(self) -> None:
|
||||
"""
|
||||
Calling decoder functions with no arguments should result in an error.
|
||||
"""
|
||||
|
||||
if _webp.HAVE_WEBPANIM:
|
||||
with pytest.raises(TypeError):
|
||||
_webp.WebPAnimDecoder()
|
||||
with pytest.raises(TypeError):
|
||||
_webp.WebPDecode()
|
||||
_webp.WebPAnimDecoder()
|
||||
|
||||
def test_no_resource_warning(self, tmp_path: Path) -> None:
|
||||
file_path = "Tests/images/hopper.webp"
|
||||
with Image.open(file_path) as image:
|
||||
temp_file = str(tmp_path / "temp.webp")
|
||||
with warnings.catch_warnings():
|
||||
image.save(temp_file)
|
||||
warnings.simplefilter("error")
|
||||
|
||||
image.save(tmp_path / "temp.webp")
|
||||
|
||||
def test_file_pointer_could_be_reused(self) -> None:
|
||||
file_path = "Tests/images/hopper.webp"
|
||||
|
@ -200,20 +205,19 @@ class TestFileWebp:
|
|||
"background",
|
||||
(0, (0,), (-1, 0, 1, 2), (253, 254, 255, 256)),
|
||||
)
|
||||
@skip_unless_feature("webp_anim")
|
||||
def test_invalid_background(
|
||||
self, background: int | tuple[int, ...], tmp_path: Path
|
||||
) -> None:
|
||||
temp_file = str(tmp_path / "temp.webp")
|
||||
temp_file = tmp_path / "temp.webp"
|
||||
im = hopper()
|
||||
with pytest.raises(OSError):
|
||||
im.save(temp_file, save_all=True, append_images=[im], background=background)
|
||||
|
||||
@skip_unless_feature("webp_anim")
|
||||
def test_background_from_gif(self, tmp_path: Path) -> None:
|
||||
out_webp = tmp_path / "temp.webp"
|
||||
|
||||
# Save L mode GIF with background
|
||||
with Image.open("Tests/images/no_palette_with_background.gif") as im:
|
||||
out_webp = str(tmp_path / "temp.webp")
|
||||
im.save(out_webp, save_all=True)
|
||||
|
||||
# Save P mode GIF with background
|
||||
|
@ -221,11 +225,10 @@ class TestFileWebp:
|
|||
original_value = im.convert("RGB").getpixel((1, 1))
|
||||
|
||||
# Save as WEBP
|
||||
out_webp = str(tmp_path / "temp.webp")
|
||||
im.save(out_webp, save_all=True)
|
||||
|
||||
# Save as GIF
|
||||
out_gif = str(tmp_path / "temp.gif")
|
||||
out_gif = tmp_path / "temp.gif"
|
||||
with Image.open(out_webp) as im:
|
||||
im.save(out_gif)
|
||||
|
||||
|
@ -234,12 +237,11 @@ class TestFileWebp:
|
|||
difference = sum(abs(original_value[i] - reread_value[i]) for i in range(0, 3))
|
||||
assert difference < 5
|
||||
|
||||
@skip_unless_feature("webp_anim")
|
||||
def test_duration(self, tmp_path: Path) -> None:
|
||||
out_webp = tmp_path / "temp.webp"
|
||||
|
||||
with Image.open("Tests/images/dispose_bgnd.gif") as im:
|
||||
assert im.info["duration"] == 1000
|
||||
|
||||
out_webp = str(tmp_path / "temp.webp")
|
||||
im.save(out_webp, save_all=True)
|
||||
|
||||
with Image.open(out_webp) as reloaded:
|
||||
|
@ -247,9 +249,10 @@ class TestFileWebp:
|
|||
assert reloaded.info["duration"] == 1000
|
||||
|
||||
def test_roundtrip_rgba_palette(self, tmp_path: Path) -> None:
|
||||
temp_file = str(tmp_path / "temp.webp")
|
||||
temp_file = tmp_path / "temp.webp"
|
||||
im = Image.new("RGBA", (1, 1)).convert("P")
|
||||
assert im.mode == "P"
|
||||
assert im.palette is not None
|
||||
assert im.palette.mode == "RGBA"
|
||||
im.save(temp_file)
|
||||
|
||||
|
|
|
@ -13,12 +13,7 @@ from .helper import (
|
|||
hopper,
|
||||
)
|
||||
|
||||
_webp = pytest.importorskip("PIL._webp", reason="WebP support not installed")
|
||||
|
||||
|
||||
def setup_module() -> None:
|
||||
if _webp.WebPDecoderBuggyAlpha():
|
||||
pytest.skip("Buggy early version of WebP installed, not testing transparency")
|
||||
pytest.importorskip("PIL._webp", reason="WebP support not installed")
|
||||
|
||||
|
||||
def test_read_rgba() -> None:
|
||||
|
@ -81,9 +76,6 @@ def test_write_rgba(tmp_path: Path) -> None:
|
|||
pil_image = Image.new("RGBA", (10, 10), (255, 0, 0, 20))
|
||||
pil_image.save(temp_file)
|
||||
|
||||
if _webp.WebPDecoderBuggyAlpha():
|
||||
return
|
||||
|
||||
with Image.open(temp_file) as image:
|
||||
image.load()
|
||||
|
||||
|
@ -93,12 +85,7 @@ def test_write_rgba(tmp_path: Path) -> None:
|
|||
image.load()
|
||||
image.getdata()
|
||||
|
||||
# Early versions of WebP are known to produce higher deviations:
|
||||
# deal with it
|
||||
if _webp.WebPDecoderVersion() <= 0x201:
|
||||
assert_image_similar(image, pil_image, 3.0)
|
||||
else:
|
||||
assert_image_similar(image, pil_image, 1.0)
|
||||
assert_image_similar(image, pil_image, 1.0)
|
||||
|
||||
|
||||
def test_keep_rgb_values_when_transparent(tmp_path: Path) -> None:
|
||||
|
|
|
@ -15,10 +15,7 @@ from .helper import (
|
|||
skip_unless_feature,
|
||||
)
|
||||
|
||||
pytestmark = [
|
||||
skip_unless_feature("webp"),
|
||||
skip_unless_feature("webp_anim"),
|
||||
]
|
||||
pytestmark = skip_unless_feature("webp")
|
||||
|
||||
|
||||
def test_n_frames() -> None:
|
||||
|
|
|
@ -8,14 +8,11 @@ from PIL import Image
|
|||
|
||||
from .helper import assert_image_equal, hopper
|
||||
|
||||
_webp = pytest.importorskip("PIL._webp", reason="WebP support not installed")
|
||||
pytest.importorskip("PIL._webp", reason="WebP support not installed")
|
||||
RGB_MODE = "RGB"
|
||||
|
||||
|
||||
def test_write_lossless_rgb(tmp_path: Path) -> None:
|
||||
if _webp.WebPDecoderVersion() < 0x0200:
|
||||
pytest.skip("lossless not included")
|
||||
|
||||
temp_file = str(tmp_path / "temp.webp")
|
||||
|
||||
hopper(RGB_MODE).save(temp_file, lossless=True)
|
||||
|
|
|
@ -10,10 +10,7 @@ from PIL import Image
|
|||
|
||||
from .helper import mark_if_feature_version, skip_unless_feature
|
||||
|
||||
pytestmark = [
|
||||
skip_unless_feature("webp"),
|
||||
skip_unless_feature("webp_mux"),
|
||||
]
|
||||
pytestmark = skip_unless_feature("webp")
|
||||
|
||||
ElementTree: ModuleType | None
|
||||
try:
|
||||
|
@ -119,7 +116,15 @@ def test_read_no_exif() -> None:
|
|||
def test_getxmp() -> None:
|
||||
with Image.open("Tests/images/flower.webp") as im:
|
||||
assert "xmp" not in im.info
|
||||
assert im.getxmp() == {}
|
||||
if ElementTree is None:
|
||||
with pytest.warns(
|
||||
UserWarning,
|
||||
match="XMP data cannot be read without defusedxml dependency",
|
||||
):
|
||||
xmp = im.getxmp()
|
||||
else:
|
||||
xmp = im.getxmp()
|
||||
assert xmp == {}
|
||||
|
||||
with Image.open("Tests/images/flower2.webp") as im:
|
||||
if ElementTree is None:
|
||||
|
@ -136,7 +141,6 @@ def test_getxmp() -> None:
|
|||
)
|
||||
|
||||
|
||||
@skip_unless_feature("webp_anim")
|
||||
def test_write_animated_metadata(tmp_path: Path) -> None:
|
||||
iccp_data = b"<iccp_data>"
|
||||
exif_data = b"<exif_data>"
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from io import BytesIO
|
||||
from pathlib import Path
|
||||
from typing import IO
|
||||
|
||||
|
@ -61,6 +62,12 @@ def test_load_float_dpi() -> None:
|
|||
with Image.open("Tests/images/drawing.emf") as im:
|
||||
assert im.info["dpi"] == 1423.7668161434979
|
||||
|
||||
with open("Tests/images/drawing.emf", "rb") as fp:
|
||||
data = fp.read()
|
||||
b = BytesIO(data[:8] + b"\x06\xFA" + data[10:])
|
||||
with Image.open(b) as im:
|
||||
assert im.info["dpi"][0] == 2540
|
||||
|
||||
|
||||
def test_load_set_dpi() -> None:
|
||||
with Image.open("Tests/images/drawing.wmf") as im:
|
||||
|
|
|
@ -2,6 +2,7 @@ from __future__ import annotations
|
|||
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import AnyStr
|
||||
|
||||
import pytest
|
||||
|
||||
|
@ -92,7 +93,7 @@ def test_textsize(request: pytest.FixtureRequest, tmp_path: Path) -> None:
|
|||
|
||||
|
||||
def _test_high_characters(
|
||||
request: pytest.FixtureRequest, tmp_path: Path, message: str | bytes
|
||||
request: pytest.FixtureRequest, tmp_path: Path, message: AnyStr
|
||||
) -> None:
|
||||
tempname = save_font(request, tmp_path)
|
||||
font = ImageFont.load(tempname)
|
||||
|
|
|
@ -42,6 +42,12 @@ try:
|
|||
except ImportError:
|
||||
ElementTree = None
|
||||
|
||||
PrettyPrinter: type | None
|
||||
try:
|
||||
from IPython.lib.pretty import PrettyPrinter
|
||||
except ImportError:
|
||||
PrettyPrinter = None
|
||||
|
||||
|
||||
# Deprecation helper
|
||||
def helper_image_new(mode: str, size: tuple[int, int]) -> Image.Image:
|
||||
|
@ -91,16 +97,15 @@ class TestImage:
|
|||
# with pytest.raises(MemoryError):
|
||||
# Image.new("L", (1000000, 1000000))
|
||||
|
||||
@pytest.mark.skipif(PrettyPrinter is None, reason="IPython is not installed")
|
||||
def test_repr_pretty(self) -> None:
|
||||
class Pretty:
|
||||
def text(self, text: str) -> None:
|
||||
self.pretty_output = text
|
||||
|
||||
im = Image.new("L", (100, 100))
|
||||
|
||||
p = Pretty()
|
||||
im._repr_pretty_(p, None)
|
||||
assert p.pretty_output == "<PIL.Image.Image image mode=L size=100x100>"
|
||||
output = io.StringIO()
|
||||
assert PrettyPrinter is not None
|
||||
p = PrettyPrinter(output)
|
||||
im._repr_pretty_(p, False)
|
||||
assert output.getvalue() == "<PIL.Image.Image image mode=L size=100x100>"
|
||||
|
||||
def test_open_formats(self) -> None:
|
||||
PNGFILE = "Tests/images/hopper.png"
|
||||
|
@ -700,6 +705,7 @@ class TestImage:
|
|||
assert new_image.size == image.size
|
||||
assert new_image.info == base_image.info
|
||||
if palette_result is not None:
|
||||
assert new_image.palette is not None
|
||||
assert new_image.palette.tobytes() == palette_result.tobytes()
|
||||
else:
|
||||
assert new_image.palette is None
|
||||
|
@ -731,6 +737,8 @@ class TestImage:
|
|||
# Act/Assert
|
||||
with Image.open(test_file) as im:
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("error")
|
||||
|
||||
im.save(temp_file)
|
||||
|
||||
def test_no_new_file_on_error(self, tmp_path: Path) -> None:
|
||||
|
@ -769,6 +777,22 @@ class TestImage:
|
|||
exif.load(b"Exif\x00\x00")
|
||||
assert not dict(exif)
|
||||
|
||||
def test_duplicate_exif_header(self) -> None:
|
||||
with Image.open("Tests/images/exif.png") as im:
|
||||
im.load()
|
||||
im.info["exif"] = b"Exif\x00\x00" + im.info["exif"]
|
||||
|
||||
exif = im.getexif()
|
||||
assert exif[274] == 1
|
||||
|
||||
def test_empty_get_ifd(self) -> None:
|
||||
exif = Image.Exif()
|
||||
ifd = exif.get_ifd(0x8769)
|
||||
assert ifd == {}
|
||||
|
||||
ifd[36864] = b"0220"
|
||||
assert exif.get_ifd(0x8769) == {36864: b"0220"}
|
||||
|
||||
@mark_if_feature_version(
|
||||
pytest.mark.valgrind_known_error, "libjpeg_turbo", "2.0", reason="Known Failing"
|
||||
)
|
||||
|
@ -817,7 +841,6 @@ class TestImage:
|
|||
assert reloaded_exif[305] == "Pillow test"
|
||||
|
||||
@skip_unless_feature("webp")
|
||||
@skip_unless_feature("webp_anim")
|
||||
def test_exif_webp(self, tmp_path: Path) -> None:
|
||||
with Image.open("Tests/images/hopper.webp") as im:
|
||||
exif = im.getexif()
|
||||
|
@ -939,7 +962,15 @@ class TestImage:
|
|||
|
||||
def test_empty_xmp(self) -> None:
|
||||
with Image.open("Tests/images/hopper.gif") as im:
|
||||
assert im.getxmp() == {}
|
||||
if ElementTree is None:
|
||||
with pytest.warns(
|
||||
UserWarning,
|
||||
match="XMP data cannot be read without defusedxml dependency",
|
||||
):
|
||||
xmp = im.getxmp()
|
||||
else:
|
||||
xmp = im.getxmp()
|
||||
assert xmp == {}
|
||||
|
||||
def test_getxmp_padded(self) -> None:
|
||||
im = Image.new("RGB", (1, 1))
|
||||
|
@ -990,12 +1021,14 @@ class TestImage:
|
|||
# P mode with RGBA palette
|
||||
im = Image.new("RGBA", (1, 1)).convert("P")
|
||||
assert im.mode == "P"
|
||||
assert im.palette is not None
|
||||
assert im.palette.mode == "RGBA"
|
||||
assert im.has_transparency_data
|
||||
|
||||
def test_apply_transparency(self) -> None:
|
||||
im = Image.new("P", (1, 1))
|
||||
im.putpalette((0, 0, 0, 1, 1, 1))
|
||||
assert im.palette is not None
|
||||
assert im.palette.colors == {(0, 0, 0): 0, (1, 1, 1): 1}
|
||||
|
||||
# Test that no transformation is applied without transparency
|
||||
|
@ -1013,13 +1046,16 @@ class TestImage:
|
|||
im.putpalette((0, 0, 0, 255, 1, 1, 1, 128), "RGBA")
|
||||
im.info["transparency"] = 0
|
||||
im.apply_transparency()
|
||||
assert im.palette is not None
|
||||
assert im.palette.colors == {(0, 0, 0, 0): 0, (1, 1, 1, 128): 1}
|
||||
|
||||
# Test that transparency bytes are applied
|
||||
with Image.open("Tests/images/pil123p.png") as im:
|
||||
assert isinstance(im.info["transparency"], bytes)
|
||||
assert im.palette is not None
|
||||
assert im.palette.colors[(27, 35, 6)] == 24
|
||||
im.apply_transparency()
|
||||
assert im.palette is not None
|
||||
assert im.palette.colors[(27, 35, 6, 214)] == 24
|
||||
|
||||
def test_constants(self) -> None:
|
||||
|
@ -1052,22 +1088,17 @@ class TestImage:
|
|||
valgrind pytest -qq Tests/test_image.py::TestImage::test_overrun | grep decode.c
|
||||
"""
|
||||
with Image.open(os.path.join("Tests/images", path)) as im:
|
||||
try:
|
||||
with pytest.raises(OSError) as e:
|
||||
im.load()
|
||||
pytest.fail()
|
||||
except OSError as e:
|
||||
buffer_overrun = str(e) == "buffer overrun when reading image file"
|
||||
truncated = "image file is truncated" in str(e)
|
||||
buffer_overrun = str(e.value) == "buffer overrun when reading image file"
|
||||
truncated = "image file is truncated" in str(e.value)
|
||||
|
||||
assert buffer_overrun or truncated
|
||||
assert buffer_overrun or truncated
|
||||
|
||||
def test_fli_overrun2(self) -> None:
|
||||
with Image.open("Tests/images/fli_overrun2.bin") as im:
|
||||
try:
|
||||
with pytest.raises(OSError, match="buffer overrun when reading image file"):
|
||||
im.seek(1)
|
||||
pytest.fail()
|
||||
except OSError as e:
|
||||
assert str(e) == "buffer overrun when reading image file"
|
||||
|
||||
def test_exit_fp(self) -> None:
|
||||
with Image.new("L", (1, 1)) as im:
|
||||
|
@ -1083,6 +1114,10 @@ class TestImage:
|
|||
assert len(caplog.records) == 0
|
||||
assert im.fp is None
|
||||
|
||||
def test_deprecation(self) -> None:
|
||||
with pytest.warns(DeprecationWarning):
|
||||
assert not Image.isImageType(None)
|
||||
|
||||
|
||||
class TestImageBytes:
|
||||
@pytest.mark.parametrize("mode", Image.MODES + ["BGR;15", "BGR;16", "BGR;24"])
|
||||
|
|
|
@ -230,7 +230,7 @@ class TestImagePutPixelError:
|
|||
im.putpixel((0, 0), v) # type: ignore[arg-type]
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("mode", "band_numbers", "match"),
|
||||
"mode, band_numbers, match",
|
||||
(
|
||||
("L", (0, 2), "color must be int or single-element tuple"),
|
||||
("LA", (0, 3), "color must be int, or tuple of one or two elements"),
|
||||
|
|
|
@ -24,7 +24,7 @@ def test_toarray() -> None:
|
|||
|
||||
def test_with_dtype(dtype: npt.DTypeLike) -> None:
|
||||
ai = numpy.array(im, dtype=dtype)
|
||||
assert ai.dtype == dtype
|
||||
assert ai.dtype.type is dtype
|
||||
|
||||
# assert test("1") == ((100, 128), '|b1', 1600))
|
||||
assert test("L") == ((100, 128), "|u1", 12800)
|
||||
|
@ -47,7 +47,7 @@ def test_toarray() -> None:
|
|||
with pytest.raises(OSError):
|
||||
numpy.array(im_truncated)
|
||||
else:
|
||||
with pytest.warns(UserWarning):
|
||||
with pytest.warns(DeprecationWarning):
|
||||
numpy.array(im_truncated)
|
||||
|
||||
|
||||
|
@ -113,4 +113,5 @@ def test_fromarray_palette() -> None:
|
|||
out = Image.fromarray(a, "P")
|
||||
|
||||
# Assert that the Python and C palettes match
|
||||
assert out.palette is not None
|
||||
assert len(out.palette.colors) == len(out.im.getpalette()) / 3
|
||||
|
|
|
@ -218,6 +218,7 @@ def test_trns_RGB(tmp_path: Path) -> None:
|
|||
def test_l_macro_rounding(convert_mode: str) -> None:
|
||||
for mode in ("P", "PA"):
|
||||
im = Image.new(mode, (1, 1))
|
||||
assert im.palette is not None
|
||||
im.palette.getcolor((0, 1, 2))
|
||||
|
||||
converted_im = im.convert(convert_mode)
|
||||
|
|
|
@ -49,5 +49,7 @@ def test_copy_zero() -> None:
|
|||
@skip_unless_feature("libtiff")
|
||||
def test_deepcopy() -> None:
|
||||
with Image.open("Tests/images/g4_orientation_5.tif") as im:
|
||||
assert im.size == (590, 88)
|
||||
|
||||
out = copy.deepcopy(im)
|
||||
assert out.size == (590, 88)
|
||||
|
|
|
@ -35,16 +35,25 @@ from .helper import assert_image_equal, hopper
|
|||
ImageFilter.UnsharpMask(10),
|
||||
),
|
||||
)
|
||||
@pytest.mark.parametrize("mode", ("L", "I", "RGB", "CMYK"))
|
||||
def test_sanity(filter_to_apply: ImageFilter.Filter, mode: str) -> None:
|
||||
@pytest.mark.parametrize(
|
||||
"mode", ("L", "I", "I;16", "I;16L", "I;16B", "I;16N", "RGB", "CMYK")
|
||||
)
|
||||
def test_sanity(
|
||||
filter_to_apply: ImageFilter.Filter | type[ImageFilter.Filter], mode: str
|
||||
) -> None:
|
||||
im = hopper(mode)
|
||||
if mode != "I" or isinstance(filter_to_apply, ImageFilter.BuiltinFilter):
|
||||
if mode[0] != "I" or (
|
||||
callable(filter_to_apply)
|
||||
and issubclass(filter_to_apply, ImageFilter.BuiltinFilter)
|
||||
):
|
||||
out = im.filter(filter_to_apply)
|
||||
assert out.mode == im.mode
|
||||
assert out.size == im.size
|
||||
|
||||
|
||||
@pytest.mark.parametrize("mode", ("L", "I", "RGB", "CMYK"))
|
||||
@pytest.mark.parametrize(
|
||||
"mode", ("L", "I", "I;16", "I;16L", "I;16B", "I;16N", "RGB", "CMYK")
|
||||
)
|
||||
def test_sanity_error(mode: str) -> None:
|
||||
im = hopper(mode)
|
||||
with pytest.raises(TypeError):
|
||||
|
@ -145,7 +154,9 @@ def test_kernel_not_enough_coefficients() -> None:
|
|||
ImageFilter.Kernel((3, 3), (0, 0))
|
||||
|
||||
|
||||
@pytest.mark.parametrize("mode", ("L", "LA", "I", "RGB", "CMYK"))
|
||||
@pytest.mark.parametrize(
|
||||
"mode", ("L", "LA", "I", "I;16", "I;16L", "I;16B", "I;16N", "RGB", "CMYK")
|
||||
)
|
||||
def test_consistency_3x3(mode: str) -> None:
|
||||
with Image.open("Tests/images/hopper.bmp") as source:
|
||||
with Image.open("Tests/images/hopper_emboss.bmp") as reference:
|
||||
|
@ -161,7 +172,9 @@ def test_consistency_3x3(mode: str) -> None:
|
|||
assert_image_equal(source.filter(kernel), reference)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("mode", ("L", "LA", "I", "RGB", "CMYK"))
|
||||
@pytest.mark.parametrize(
|
||||
"mode", ("L", "LA", "I", "I;16", "I;16L", "I;16B", "I;16N", "RGB", "CMYK")
|
||||
)
|
||||
def test_consistency_5x5(mode: str) -> None:
|
||||
with Image.open("Tests/images/hopper.bmp") as source:
|
||||
with Image.open("Tests/images/hopper_emboss_more.bmp") as reference:
|
||||
|
|
|
@ -1,11 +1,19 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from .helper import hopper
|
||||
|
||||
|
||||
def test_sanity() -> None:
|
||||
im = hopper()
|
||||
type_repr = repr(type(im.getim()))
|
||||
|
||||
type_repr = repr(type(im.getim()))
|
||||
assert "PyCapsule" in type_repr
|
||||
assert isinstance(im.im.id, int)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
assert isinstance(im.im.id, int)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
ptrs = dict(im.im.unsafe_ptrs)
|
||||
assert ptrs.keys() == {"image8", "image32", "image"}
|
||||
|
|
|
@ -86,6 +86,7 @@ def test_rgba_palette(mode: str, palette: tuple[int, ...]) -> None:
|
|||
im = Image.new("P", (1, 1))
|
||||
im.putpalette(palette, mode)
|
||||
assert im.getpalette() == [1, 2, 3]
|
||||
assert im.palette is not None
|
||||
assert im.palette.colors == {(1, 2, 3, 4): 0}
|
||||
|
||||
|
||||
|
|