mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-15 17:54:46 +03:00
Merge branch 'main' into fromarray_mode
This commit is contained in:
commit
94a32628f3
|
@ -13,24 +13,21 @@ aptget_update()
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
if [[ $(uname) != CYGWIN* ]]; then
|
|
||||||
aptget_update || aptget_update retry || aptget_update retry
|
aptget_update || aptget_update retry || aptget_update retry
|
||||||
fi
|
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
if [[ $(uname) != CYGWIN* ]]; then
|
|
||||||
sudo apt-get -qq install libfreetype6-dev liblcms2-dev libtiff-dev python3-tk\
|
sudo apt-get -qq install libfreetype6-dev liblcms2-dev libtiff-dev python3-tk\
|
||||||
ghostscript libjpeg-turbo8-dev libopenjp2-7-dev\
|
ghostscript libjpeg-turbo8-dev libopenjp2-7-dev\
|
||||||
cmake meson imagemagick libharfbuzz-dev libfribidi-dev\
|
cmake meson imagemagick libharfbuzz-dev libfribidi-dev\
|
||||||
sway wl-clipboard libopenblas-dev nasm
|
sway wl-clipboard libopenblas-dev nasm
|
||||||
fi
|
|
||||||
|
|
||||||
python3 -m pip install --upgrade pip
|
python3 -m pip install --upgrade pip
|
||||||
python3 -m pip install --upgrade wheel
|
python3 -m pip install --upgrade wheel
|
||||||
python3 -m pip install coverage
|
python3 -m pip install coverage
|
||||||
python3 -m pip install defusedxml
|
python3 -m pip install defusedxml
|
||||||
python3 -m pip install ipython
|
python3 -m pip install ipython
|
||||||
|
python3 -m pip install numpy
|
||||||
python3 -m pip install olefile
|
python3 -m pip install olefile
|
||||||
python3 -m pip install -U pytest
|
python3 -m pip install -U pytest
|
||||||
python3 -m pip install -U pytest-cov
|
python3 -m pip install -U pytest-cov
|
||||||
|
@ -40,9 +37,6 @@ python3 -m pip install pyroma
|
||||||
# fails on beta 3.14 and PyPy
|
# fails on beta 3.14 and PyPy
|
||||||
python3 -m pip install --only-binary=:all: pyarrow || true
|
python3 -m pip install --only-binary=:all: pyarrow || true
|
||||||
|
|
||||||
if [[ $(uname) != CYGWIN* ]]; then
|
|
||||||
python3 -m pip install numpy
|
|
||||||
|
|
||||||
# PyQt6 doesn't support PyPy3
|
# PyQt6 doesn't support PyPy3
|
||||||
if [[ $GHA_PYTHON_VERSION == 3.* ]]; then
|
if [[ $GHA_PYTHON_VERSION == 3.* ]]; then
|
||||||
sudo apt-get -qq install libegl1 libxcb-cursor0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-shape0 libxkbcommon-x11-0
|
sudo apt-get -qq install libegl1 libxcb-cursor0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-shape0 libxkbcommon-x11-0
|
||||||
|
@ -50,12 +44,6 @@ if [[ $(uname) != CYGWIN* ]]; then
|
||||||
if ! [[ "$PYTHON_GIL" == "0" ]]; then python3 -m pip install pyqt6 ; fi
|
if ! [[ "$PYTHON_GIL" == "0" ]]; then python3 -m pip install pyqt6 ; fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Pyroma uses non-isolated build and fails with old setuptools
|
|
||||||
if [[ $GHA_PYTHON_VERSION == 3.9 ]]; then
|
|
||||||
# To match pyproject.toml
|
|
||||||
python3 -m pip install "setuptools>=77"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# webp
|
# webp
|
||||||
pushd depends && ./install_webp.sh && popd
|
pushd depends && ./install_webp.sh && popd
|
||||||
|
|
||||||
|
@ -70,6 +58,3 @@ if [[ $(uname) != CYGWIN* ]]; then
|
||||||
|
|
||||||
# extra test images
|
# extra test images
|
||||||
pushd depends && ./install_extra_test_images.sh && popd
|
pushd depends && ./install_extra_test_images.sh && popd
|
||||||
else
|
|
||||||
cd depends && ./install_extra_test_images.sh && cd ..
|
|
||||||
fi
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
cibuildwheel==3.0.0
|
cibuildwheel==3.1.2
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
mypy==1.16.1
|
mypy==1.17.0
|
||||||
IceSpringPySideStubs-PyQt6
|
IceSpringPySideStubs-PyQt6
|
||||||
IceSpringPySideStubs-PySide6
|
IceSpringPySideStubs-PySide6
|
||||||
ipython
|
ipython
|
||||||
numpy
|
numpy
|
||||||
packaging
|
packaging
|
||||||
pyarrow-stubs
|
pyarrow-stubs
|
||||||
|
pybind11
|
||||||
pytest
|
pytest
|
||||||
sphinx
|
sphinx
|
||||||
types-atheris
|
types-atheris
|
||||||
|
|
1
.github/mergify.yml
vendored
1
.github/mergify.yml
vendored
|
@ -8,7 +8,6 @@ pull_request_rules:
|
||||||
- status-success=Docker Test Successful
|
- status-success=Docker Test Successful
|
||||||
- status-success=Windows Test Successful
|
- status-success=Windows Test Successful
|
||||||
- status-success=MinGW
|
- status-success=MinGW
|
||||||
- status-success=Cygwin Test Successful
|
|
||||||
actions:
|
actions:
|
||||||
merge:
|
merge:
|
||||||
method: merge
|
method: merge
|
||||||
|
|
154
.github/workflows/test-cygwin.yml
vendored
154
.github/workflows/test-cygwin.yml
vendored
|
@ -1,154 +0,0 @@
|
||||||
name: Test Cygwin
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- "**"
|
|
||||||
paths-ignore:
|
|
||||||
- ".github/workflows/docs.yml"
|
|
||||||
- ".github/workflows/wheels*"
|
|
||||||
- ".gitmodules"
|
|
||||||
- "docs/**"
|
|
||||||
- "wheels/**"
|
|
||||||
pull_request:
|
|
||||||
paths-ignore:
|
|
||||||
- ".github/workflows/docs.yml"
|
|
||||||
- ".github/workflows/wheels*"
|
|
||||||
- ".gitmodules"
|
|
||||||
- "docs/**"
|
|
||||||
- "wheels/**"
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
|
|
||||||
concurrency:
|
|
||||||
group: ${{ github.workflow }}-${{ github.ref }}
|
|
||||||
cancel-in-progress: true
|
|
||||||
|
|
||||||
env:
|
|
||||||
COVERAGE_CORE: sysmon
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: windows-latest
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
python-minor-version: [9]
|
|
||||||
|
|
||||||
timeout-minutes: 40
|
|
||||||
|
|
||||||
name: Python 3.${{ matrix.python-minor-version }}
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Fix line endings
|
|
||||||
run: |
|
|
||||||
git config --global core.autocrlf input
|
|
||||||
|
|
||||||
- name: Checkout Pillow
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
|
|
||||||
- name: Install Cygwin
|
|
||||||
uses: cygwin/cygwin-install-action@v5
|
|
||||||
with:
|
|
||||||
packages: >
|
|
||||||
gcc-g++
|
|
||||||
ghostscript
|
|
||||||
git
|
|
||||||
ImageMagick
|
|
||||||
jpeg
|
|
||||||
libfreetype-devel
|
|
||||||
libimagequant-devel
|
|
||||||
libjpeg-devel
|
|
||||||
liblapack-devel
|
|
||||||
liblcms2-devel
|
|
||||||
libopenjp2-devel
|
|
||||||
libraqm-devel
|
|
||||||
libtiff-devel
|
|
||||||
libwebp-devel
|
|
||||||
libxcb-devel
|
|
||||||
libxcb-xinerama0
|
|
||||||
make
|
|
||||||
netpbm
|
|
||||||
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
|
|
||||||
wget
|
|
||||||
xorg-server-extra
|
|
||||||
zlib-devel
|
|
||||||
|
|
||||||
- name: Add Lapack to PATH
|
|
||||||
uses: egor-tensin/cleanup-path@v4
|
|
||||||
with:
|
|
||||||
dirs: 'C:\cygwin\bin;C:\cygwin\lib\lapack'
|
|
||||||
|
|
||||||
- name: Select Python version
|
|
||||||
run: |
|
|
||||||
ln -sf c:/cygwin/bin/python3.${{ matrix.python-minor-version }} c:/cygwin/bin/python3
|
|
||||||
|
|
||||||
- name: pip cache
|
|
||||||
uses: actions/cache@v4
|
|
||||||
with:
|
|
||||||
path: 'C:\cygwin\home\runneradmin\.cache\pip'
|
|
||||||
key: ${{ runner.os }}-cygwin-pip3.${{ matrix.python-minor-version }}-${{ hashFiles('.ci/install.sh') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-cygwin-pip3.${{ matrix.python-minor-version }}-
|
|
||||||
|
|
||||||
- name: Build system information
|
|
||||||
run: |
|
|
||||||
dash.exe -c "python3 .github/workflows/system-info.py"
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: |
|
|
||||||
bash.exe .ci/install.sh
|
|
||||||
|
|
||||||
- name: Build
|
|
||||||
shell: bash.exe -eo pipefail -o igncr "{0}"
|
|
||||||
run: |
|
|
||||||
.ci/build.sh
|
|
||||||
|
|
||||||
- name: Test
|
|
||||||
run: |
|
|
||||||
bash.exe xvfb-run -s '-screen 0 1024x768x24' .ci/test.sh
|
|
||||||
|
|
||||||
- name: Prepare to upload errors
|
|
||||||
if: failure()
|
|
||||||
run: |
|
|
||||||
dash.exe -c "mkdir -p Tests/errors"
|
|
||||||
|
|
||||||
- name: Upload errors
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
if: failure()
|
|
||||||
with:
|
|
||||||
name: errors
|
|
||||||
path: Tests/errors
|
|
||||||
|
|
||||||
- name: After success
|
|
||||||
run: |
|
|
||||||
bash.exe .ci/after_success.sh
|
|
||||||
rm C:\cygwin\bin\bash.EXE
|
|
||||||
|
|
||||||
- name: Upload coverage
|
|
||||||
uses: codecov/codecov-action@v5
|
|
||||||
with:
|
|
||||||
files: ./coverage.xml
|
|
||||||
flags: GHA_Cygwin
|
|
||||||
name: Cygwin Python 3.${{ matrix.python-minor-version }}
|
|
||||||
token: ${{ secrets.CODECOV_ORG_TOKEN }}
|
|
||||||
|
|
||||||
success:
|
|
||||||
permissions:
|
|
||||||
contents: none
|
|
||||||
needs: build
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
name: Cygwin Test Successful
|
|
||||||
steps:
|
|
||||||
- name: Success
|
|
||||||
run: echo Cygwin Test Successful
|
|
4
.github/workflows/test-windows.yml
vendored
4
.github/workflows/test-windows.yml
vendored
|
@ -35,11 +35,11 @@ jobs:
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
python-version: ["pypy3.11", "pypy3.10", "3.10", "3.11", "3.12", ">=3.13.5", "3.14"]
|
python-version: ["pypy3.11", "3.11", "3.12", "3.13", "3.14"]
|
||||||
architecture: ["x64"]
|
architecture: ["x64"]
|
||||||
include:
|
include:
|
||||||
# Test the oldest Python on 32-bit
|
# Test the oldest Python on 32-bit
|
||||||
- { python-version: "3.9", architecture: "x86" }
|
- { python-version: "3.10", architecture: "x86" }
|
||||||
|
|
||||||
timeout-minutes: 45
|
timeout-minutes: 45
|
||||||
|
|
||||||
|
|
12
.github/workflows/test.yml
vendored
12
.github/workflows/test.yml
vendored
|
@ -42,7 +42,6 @@ jobs:
|
||||||
]
|
]
|
||||||
python-version: [
|
python-version: [
|
||||||
"pypy3.11",
|
"pypy3.11",
|
||||||
"pypy3.10",
|
|
||||||
"3.14t",
|
"3.14t",
|
||||||
"3.14",
|
"3.14",
|
||||||
"3.13t",
|
"3.13t",
|
||||||
|
@ -50,18 +49,17 @@ jobs:
|
||||||
"3.12",
|
"3.12",
|
||||||
"3.11",
|
"3.11",
|
||||||
"3.10",
|
"3.10",
|
||||||
"3.9",
|
|
||||||
]
|
]
|
||||||
include:
|
include:
|
||||||
- { python-version: "3.11", PYTHONOPTIMIZE: 1, REVERSE: "--reverse" }
|
- { python-version: "3.12", PYTHONOPTIMIZE: 1, REVERSE: "--reverse" }
|
||||||
- { python-version: "3.10", PYTHONOPTIMIZE: 2 }
|
- { python-version: "3.11", PYTHONOPTIMIZE: 2 }
|
||||||
# Free-threaded
|
# Free-threaded
|
||||||
- { python-version: "3.14t", disable-gil: true }
|
- { python-version: "3.14t", disable-gil: true }
|
||||||
- { python-version: "3.13t", disable-gil: true }
|
- { python-version: "3.13t", disable-gil: true }
|
||||||
# M1 only available for 3.10+
|
# Intel
|
||||||
- { os: "macos-13", python-version: "3.9" }
|
- { os: "macos-13", python-version: "3.10" }
|
||||||
exclude:
|
exclude:
|
||||||
- { os: "macos-latest", python-version: "3.9" }
|
- { os: "macos-latest", python-version: "3.10" }
|
||||||
|
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
name: ${{ matrix.os }} Python ${{ matrix.python-version }}
|
name: ${{ matrix.os }} Python ${{ matrix.python-version }}
|
||||||
|
|
58
.github/workflows/wheels-dependencies.sh
vendored
58
.github/workflows/wheels-dependencies.sh
vendored
|
@ -60,7 +60,7 @@ if [[ "$CIBW_PLATFORM" == "ios" ]]; then
|
||||||
# on using the Xcode builder, which isn't very helpful for most of Pillow's
|
# on using the Xcode builder, which isn't very helpful for most of Pillow's
|
||||||
# dependencies. Therefore, we lean on the OSX configurations, plus CC, CFLAGS
|
# dependencies. Therefore, we lean on the OSX configurations, plus CC, CFLAGS
|
||||||
# etc. to ensure the right sysroot is selected.
|
# etc. to ensure the right sysroot is selected.
|
||||||
HOST_CMAKE_FLAGS="-DCMAKE_SYSTEM_NAME=$CMAKE_SYSTEM_NAME -DCMAKE_SYSTEM_PROCESSOR=$GNU_ARCH -DCMAKE_OSX_DEPLOYMENT_TARGET=$IPHONEOS_DEPLOYMENT_TARGET -DCMAKE_OSX_SYSROOT=$IOS_SDK_PATH -DBUILD_SHARED_LIBS=NO"
|
HOST_CMAKE_FLAGS="-DCMAKE_SYSTEM_NAME=$CMAKE_SYSTEM_NAME -DCMAKE_SYSTEM_PROCESSOR=$GNU_ARCH -DCMAKE_OSX_DEPLOYMENT_TARGET=$IPHONEOS_DEPLOYMENT_TARGET -DCMAKE_OSX_SYSROOT=$IOS_SDK_PATH -DBUILD_SHARED_LIBS=NO -DENABLE_SHARED=NO"
|
||||||
|
|
||||||
# Meson needs to be pointed at a cross-platform configuration file
|
# Meson needs to be pointed at a cross-platform configuration file
|
||||||
# This will be generated once CC etc. have been evaluated.
|
# This will be generated once CC etc. have been evaluated.
|
||||||
|
@ -95,7 +95,7 @@ ARCHIVE_SDIR=pillow-depends-main
|
||||||
# you change those versions, ensure the patch is also updated.
|
# you change those versions, ensure the patch is also updated.
|
||||||
FREETYPE_VERSION=2.13.3
|
FREETYPE_VERSION=2.13.3
|
||||||
HARFBUZZ_VERSION=11.2.1
|
HARFBUZZ_VERSION=11.2.1
|
||||||
LIBPNG_VERSION=1.6.49
|
LIBPNG_VERSION=1.6.50
|
||||||
JPEGTURBO_VERSION=3.1.1
|
JPEGTURBO_VERSION=3.1.1
|
||||||
OPENJPEG_VERSION=2.5.3
|
OPENJPEG_VERSION=2.5.3
|
||||||
XZ_VERSION=5.8.1
|
XZ_VERSION=5.8.1
|
||||||
|
@ -103,7 +103,7 @@ TIFF_VERSION=4.7.0
|
||||||
LCMS2_VERSION=2.17
|
LCMS2_VERSION=2.17
|
||||||
ZLIB_VERSION=1.3.1
|
ZLIB_VERSION=1.3.1
|
||||||
ZLIB_NG_VERSION=2.2.4
|
ZLIB_NG_VERSION=2.2.4
|
||||||
LIBWEBP_VERSION=1.5.0 # Patched; next release won't need patching. See patch file.
|
LIBWEBP_VERSION=1.6.0
|
||||||
BZIP2_VERSION=1.0.8
|
BZIP2_VERSION=1.0.8
|
||||||
LIBXCB_VERSION=1.17.0
|
LIBXCB_VERSION=1.17.0
|
||||||
BROTLI_VERSION=1.1.0 # Patched; next release won't need patching. See patch file.
|
BROTLI_VERSION=1.1.0 # Patched; next release won't need patching. See patch file.
|
||||||
|
@ -186,30 +186,43 @@ function build_libavif {
|
||||||
|
|
||||||
python3 -m pip install meson ninja
|
python3 -m pip install meson ninja
|
||||||
|
|
||||||
if [[ "$PLAT" == "x86_64" ]] || [ -n "$SANITIZER" ]; then
|
if ([[ "$PLAT" == "x86_64" ]] && [[ -z "$IOS_SDK" ]]) || [ -n "$SANITIZER" ]; then
|
||||||
build_simple nasm 2.16.03 https://www.nasm.us/pub/nasm/releasebuilds/2.16.03
|
build_simple nasm 2.16.03 https://www.nasm.us/pub/nasm/releasebuilds/2.16.03
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local build_type=MinSizeRel
|
local build_type=MinSizeRel
|
||||||
|
local build_shared=ON
|
||||||
local lto=ON
|
local lto=ON
|
||||||
|
|
||||||
local libavif_cmake_flags
|
local libavif_cmake_flags
|
||||||
|
|
||||||
if [ -n "$IS_MACOS" ]; then
|
if [[ -n "$IS_MACOS" ]]; then
|
||||||
lto=OFF
|
lto=OFF
|
||||||
libavif_cmake_flags=(
|
libavif_cmake_flags=(
|
||||||
-DCMAKE_C_FLAGS_MINSIZEREL="-Oz -DNDEBUG -flto" \
|
-DCMAKE_C_FLAGS_MINSIZEREL="-Oz -DNDEBUG -flto" \
|
||||||
-DCMAKE_CXX_FLAGS_MINSIZEREL="-Oz -DNDEBUG -flto" \
|
-DCMAKE_CXX_FLAGS_MINSIZEREL="-Oz -DNDEBUG -flto" \
|
||||||
-DCMAKE_SHARED_LINKER_FLAGS_INIT="-Wl,-S,-x,-dead_strip_dylibs" \
|
-DCMAKE_SHARED_LINKER_FLAGS_INIT="-Wl,-S,-x,-dead_strip_dylibs" \
|
||||||
)
|
)
|
||||||
|
if [[ -n "$IOS_SDK" ]]; then
|
||||||
|
build_shared=OFF
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
if [[ "$MB_ML_VER" == 2014 ]] && [[ "$PLAT" == "x86_64" ]]; then
|
if [[ "$MB_ML_VER" == 2014 ]] && [[ "$PLAT" == "x86_64" ]]; then
|
||||||
build_type=Release
|
build_type=Release
|
||||||
fi
|
fi
|
||||||
libavif_cmake_flags=(-DCMAKE_SHARED_LINKER_FLAGS_INIT="-Wl,--strip-all,-z,relro,-z,now")
|
libavif_cmake_flags=(-DCMAKE_SHARED_LINKER_FLAGS_INIT="-Wl,--strip-all,-z,relro,-z,now")
|
||||||
fi
|
fi
|
||||||
|
if [[ -n "$IOS_SDK" ]] && [[ "$PLAT" == "x86_64" ]]; then
|
||||||
|
libavif_cmake_flags+=(-DAOM_TARGET_CPU=generic)
|
||||||
|
else
|
||||||
|
libavif_cmake_flags+=(
|
||||||
|
-DAVIF_CODEC_AOM_DECODE=OFF \
|
||||||
|
-DAVIF_CODEC_DAV1D=LOCAL
|
||||||
|
)
|
||||||
|
fi
|
||||||
|
|
||||||
local out_dir=$(fetch_unpack https://github.com/AOMediaCodec/libavif/archive/refs/tags/v$LIBAVIF_VERSION.tar.gz libavif-$LIBAVIF_VERSION.tar.gz)
|
local out_dir=$(fetch_unpack https://github.com/AOMediaCodec/libavif/archive/refs/tags/v$LIBAVIF_VERSION.tar.gz libavif-$LIBAVIF_VERSION.tar.gz)
|
||||||
|
|
||||||
# CONFIG_AV1_HIGHBITDEPTH=0 is a flag for libaom (included as a subproject
|
# CONFIG_AV1_HIGHBITDEPTH=0 is a flag for libaom (included as a subproject
|
||||||
# of libavif) that disables support for encoding high bit depth images.
|
# of libavif) that disables support for encoding high bit depth images.
|
||||||
(cd $out_dir \
|
(cd $out_dir \
|
||||||
|
@ -217,20 +230,27 @@ function build_libavif {
|
||||||
-DCMAKE_INSTALL_PREFIX=$BUILD_PREFIX \
|
-DCMAKE_INSTALL_PREFIX=$BUILD_PREFIX \
|
||||||
-DCMAKE_INSTALL_LIBDIR=$BUILD_PREFIX/lib \
|
-DCMAKE_INSTALL_LIBDIR=$BUILD_PREFIX/lib \
|
||||||
-DCMAKE_INSTALL_NAME_DIR=$BUILD_PREFIX/lib \
|
-DCMAKE_INSTALL_NAME_DIR=$BUILD_PREFIX/lib \
|
||||||
-DBUILD_SHARED_LIBS=ON \
|
-DBUILD_SHARED_LIBS=$build_shared \
|
||||||
-DAVIF_LIBSHARPYUV=LOCAL \
|
-DAVIF_LIBSHARPYUV=LOCAL \
|
||||||
-DAVIF_LIBYUV=LOCAL \
|
-DAVIF_LIBYUV=LOCAL \
|
||||||
-DAVIF_CODEC_AOM=LOCAL \
|
-DAVIF_CODEC_AOM=LOCAL \
|
||||||
-DCONFIG_AV1_HIGHBITDEPTH=0 \
|
-DCONFIG_AV1_HIGHBITDEPTH=0 \
|
||||||
-DAVIF_CODEC_AOM_DECODE=OFF \
|
|
||||||
-DAVIF_CODEC_DAV1D=LOCAL \
|
|
||||||
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=$lto \
|
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=$lto \
|
||||||
-DCMAKE_C_VISIBILITY_PRESET=hidden \
|
-DCMAKE_C_VISIBILITY_PRESET=hidden \
|
||||||
-DCMAKE_CXX_VISIBILITY_PRESET=hidden \
|
-DCMAKE_CXX_VISIBILITY_PRESET=hidden \
|
||||||
-DCMAKE_BUILD_TYPE=$build_type \
|
-DCMAKE_BUILD_TYPE=$build_type \
|
||||||
"${libavif_cmake_flags[@]}" \
|
"${libavif_cmake_flags[@]}" \
|
||||||
. \
|
$HOST_CMAKE_FLAGS . )
|
||||||
&& make install)
|
|
||||||
|
if [[ -n "$IOS_SDK" ]]; then
|
||||||
|
# libavif's CMake configuration generates a meson cross file... but it
|
||||||
|
# doesn't work for iOS cross-compilation. Copy in Pillow-generated
|
||||||
|
# meson-cross config to replace the cmake-generated version.
|
||||||
|
cp $WORKDIR/meson-cross.txt $out_dir/crossfile-apple.meson
|
||||||
|
fi
|
||||||
|
|
||||||
|
(cd $out_dir && make install)
|
||||||
|
|
||||||
touch libavif-stamp
|
touch libavif-stamp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,10 +288,7 @@ function build {
|
||||||
build_tiff
|
build_tiff
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -z "$IOS_SDK" ]]; then
|
|
||||||
# Short term workaround; don't build libavif on iOS
|
|
||||||
build_libavif
|
build_libavif
|
||||||
fi
|
|
||||||
build_libpng
|
build_libpng
|
||||||
build_lcms2
|
build_lcms2
|
||||||
build_openjpeg
|
build_openjpeg
|
||||||
|
@ -280,7 +297,11 @@ function build {
|
||||||
if [[ -n "$IS_MACOS" ]]; then
|
if [[ -n "$IS_MACOS" ]]; then
|
||||||
webp_cflags="$webp_cflags -Wl,-headerpad_max_install_names"
|
webp_cflags="$webp_cflags -Wl,-headerpad_max_install_names"
|
||||||
fi
|
fi
|
||||||
CFLAGS="$CFLAGS $webp_cflags" build_simple libwebp $LIBWEBP_VERSION \
|
webp_ldflags=""
|
||||||
|
if [[ -n "$IOS_SDK" ]]; then
|
||||||
|
webp_ldflags="$webp_ldflags -llzma -lz"
|
||||||
|
fi
|
||||||
|
CFLAGS="$CFLAGS $webp_cflags" LDFLAGS="$LDFLAGS $webp_ldflags" build_simple libwebp $LIBWEBP_VERSION \
|
||||||
https://storage.googleapis.com/downloads.webmproject.org/releases/webp tar.gz \
|
https://storage.googleapis.com/downloads.webmproject.org/releases/webp tar.gz \
|
||||||
--enable-libwebpmux --enable-libwebpdemux
|
--enable-libwebpmux --enable-libwebpdemux
|
||||||
|
|
||||||
|
@ -380,6 +401,15 @@ fi
|
||||||
|
|
||||||
wrap_wheel_builder build
|
wrap_wheel_builder build
|
||||||
|
|
||||||
|
# A safety catch for iOS. iOS can't use dynamic libraries, but clang will prefer
|
||||||
|
# to link dynamic libraries to static libraries. The only way to reliably
|
||||||
|
# prevent this is to not have dynamic libraries available in the first place.
|
||||||
|
# The build process *shouldn't* generate any dylibs... but just in case, purge
|
||||||
|
# any dylibs that *have* been installed into the build prefix directory.
|
||||||
|
if [[ -n "$IOS_SDK" ]]; then
|
||||||
|
find "$BUILD_PREFIX" -name "*.dylib" -exec rm -rf {} \;
|
||||||
|
fi
|
||||||
|
|
||||||
# Return to the project root to finish the build
|
# Return to the project root to finish the build
|
||||||
popd > /dev/null
|
popd > /dev/null
|
||||||
|
|
||||||
|
|
4
.github/workflows/wheels.yml
vendored
4
.github/workflows/wheels.yml
vendored
|
@ -77,22 +77,22 @@ jobs:
|
||||||
platform: linux
|
platform: linux
|
||||||
os: ubuntu-latest
|
os: ubuntu-latest
|
||||||
cibw_arch: x86_64
|
cibw_arch: x86_64
|
||||||
|
manylinux: "manylinux2014"
|
||||||
- name: "manylinux_2_28 x86_64"
|
- name: "manylinux_2_28 x86_64"
|
||||||
platform: linux
|
platform: linux
|
||||||
os: ubuntu-latest
|
os: ubuntu-latest
|
||||||
cibw_arch: x86_64
|
cibw_arch: x86_64
|
||||||
build: "*manylinux*"
|
build: "*manylinux*"
|
||||||
manylinux: "manylinux_2_28"
|
|
||||||
- name: "manylinux2014 and musllinux aarch64"
|
- name: "manylinux2014 and musllinux aarch64"
|
||||||
platform: linux
|
platform: linux
|
||||||
os: ubuntu-24.04-arm
|
os: ubuntu-24.04-arm
|
||||||
cibw_arch: aarch64
|
cibw_arch: aarch64
|
||||||
|
manylinux: "manylinux2014"
|
||||||
- name: "manylinux_2_28 aarch64"
|
- name: "manylinux_2_28 aarch64"
|
||||||
platform: linux
|
platform: linux
|
||||||
os: ubuntu-24.04-arm
|
os: ubuntu-24.04-arm
|
||||||
cibw_arch: aarch64
|
cibw_arch: aarch64
|
||||||
build: "*manylinux*"
|
build: "*manylinux*"
|
||||||
manylinux: "manylinux_2_28"
|
|
||||||
- name: "iOS arm64 device"
|
- name: "iOS arm64 device"
|
||||||
platform: ios
|
platform: ios
|
||||||
os: macos-latest
|
os: macos-latest
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
repos:
|
repos:
|
||||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||||
rev: v0.12.0
|
rev: v0.12.2
|
||||||
hooks:
|
hooks:
|
||||||
- id: ruff-check
|
- id: ruff-check
|
||||||
args: [--exit-non-zero-on-fix]
|
args: [--exit-non-zero-on-fix]
|
||||||
|
@ -11,7 +11,7 @@ repos:
|
||||||
- id: black
|
- id: black
|
||||||
|
|
||||||
- repo: https://github.com/PyCQA/bandit
|
- repo: https://github.com/PyCQA/bandit
|
||||||
rev: 1.8.5
|
rev: 1.8.6
|
||||||
hooks:
|
hooks:
|
||||||
- id: bandit
|
- id: bandit
|
||||||
args: [--severity-level=high]
|
args: [--severity-level=high]
|
||||||
|
@ -24,7 +24,7 @@ repos:
|
||||||
exclude: (Makefile$|\.bat$|\.cmake$|\.eps$|\.fits$|\.gd$|\.opt$|\.patch$)
|
exclude: (Makefile$|\.bat$|\.cmake$|\.eps$|\.fits$|\.gd$|\.opt$|\.patch$)
|
||||||
|
|
||||||
- repo: https://github.com/pre-commit/mirrors-clang-format
|
- repo: https://github.com/pre-commit/mirrors-clang-format
|
||||||
rev: v20.1.6
|
rev: v20.1.7
|
||||||
hooks:
|
hooks:
|
||||||
- id: clang-format
|
- id: clang-format
|
||||||
types: [c]
|
types: [c]
|
||||||
|
@ -51,14 +51,14 @@ repos:
|
||||||
exclude: ^.github/.*TEMPLATE|^Tests/(fonts|images)/|\.patch$
|
exclude: ^.github/.*TEMPLATE|^Tests/(fonts|images)/|\.patch$
|
||||||
|
|
||||||
- repo: https://github.com/python-jsonschema/check-jsonschema
|
- repo: https://github.com/python-jsonschema/check-jsonschema
|
||||||
rev: 0.33.1
|
rev: 0.33.2
|
||||||
hooks:
|
hooks:
|
||||||
- id: check-github-workflows
|
- id: check-github-workflows
|
||||||
- id: check-readthedocs
|
- id: check-readthedocs
|
||||||
- id: check-renovate
|
- id: check-renovate
|
||||||
|
|
||||||
- repo: https://github.com/woodruffw/zizmor-pre-commit
|
- repo: https://github.com/woodruffw/zizmor-pre-commit
|
||||||
rev: v1.9.0
|
rev: v1.11.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: zizmor
|
- id: zizmor
|
||||||
|
|
||||||
|
|
12
MANIFEST.in
12
MANIFEST.in
|
@ -13,6 +13,7 @@ include LICENSE
|
||||||
include Makefile
|
include Makefile
|
||||||
include tox.ini
|
include tox.ini
|
||||||
graft Tests
|
graft Tests
|
||||||
|
graft Tests/images
|
||||||
graft checks
|
graft checks
|
||||||
graft patches
|
graft patches
|
||||||
graft src
|
graft src
|
||||||
|
@ -28,8 +29,19 @@ exclude .editorconfig
|
||||||
exclude .readthedocs.yml
|
exclude .readthedocs.yml
|
||||||
exclude codecov.yml
|
exclude codecov.yml
|
||||||
exclude renovate.json
|
exclude renovate.json
|
||||||
|
exclude Tests/images/README.md
|
||||||
|
exclude Tests/images/crash*.tif
|
||||||
|
exclude Tests/images/string_dimension.tiff
|
||||||
global-exclude .git*
|
global-exclude .git*
|
||||||
global-exclude *.pyc
|
global-exclude *.pyc
|
||||||
global-exclude *.so
|
global-exclude *.so
|
||||||
prune .ci
|
prune .ci
|
||||||
prune wheels
|
prune wheels
|
||||||
|
prune winbuild/build
|
||||||
|
prune winbuild/depends
|
||||||
|
prune Tests/errors
|
||||||
|
prune Tests/images/jpeg2000
|
||||||
|
prune Tests/images/msp
|
||||||
|
prune Tests/images/picins
|
||||||
|
prune Tests/images/sunraster
|
||||||
|
prune Tests/test-images
|
||||||
|
|
|
@ -36,9 +36,6 @@ As of 2019, Pillow development is
|
||||||
<a href="https://github.com/python-pillow/Pillow/actions/workflows/test-mingw.yml"><img
|
<a href="https://github.com/python-pillow/Pillow/actions/workflows/test-mingw.yml"><img
|
||||||
alt="GitHub Actions build status (Test MinGW)"
|
alt="GitHub Actions build status (Test MinGW)"
|
||||||
src="https://github.com/python-pillow/Pillow/workflows/Test%20MinGW/badge.svg"></a>
|
src="https://github.com/python-pillow/Pillow/workflows/Test%20MinGW/badge.svg"></a>
|
||||||
<a href="https://github.com/python-pillow/Pillow/actions/workflows/test-cygwin.yml"><img
|
|
||||||
alt="GitHub Actions build status (Test Cygwin)"
|
|
||||||
src="https://github.com/python-pillow/Pillow/workflows/Test%20Cygwin/badge.svg"></a>
|
|
||||||
<a href="https://github.com/python-pillow/Pillow/actions/workflows/test-docker.yml"><img
|
<a href="https://github.com/python-pillow/Pillow/actions/workflows/test-docker.yml"><img
|
||||||
alt="GitHub Actions build status (Test Docker)"
|
alt="GitHub Actions build status (Test Docker)"
|
||||||
src="https://github.com/python-pillow/Pillow/workflows/Test%20Docker/badge.svg"></a>
|
src="https://github.com/python-pillow/Pillow/workflows/Test%20Docker/badge.svg"></a>
|
||||||
|
|
|
@ -10,17 +10,20 @@ import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
from collections.abc import Sequence
|
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from pathlib import Path
|
|
||||||
from typing import Any, Callable
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from packaging.version import parse as parse_version
|
from packaging.version import parse as parse_version
|
||||||
|
|
||||||
from PIL import Image, ImageFile, ImageMath, features
|
from PIL import Image, ImageFile, ImageMath, features
|
||||||
|
|
||||||
|
TYPE_CHECKING = False
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Callable, Sequence
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
uploader = None
|
uploader = None
|
||||||
|
@ -291,16 +294,6 @@ def djpeg_available() -> bool:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def cjpeg_available() -> bool:
|
|
||||||
if shutil.which("cjpeg"):
|
|
||||||
try:
|
|
||||||
subprocess.check_call(["cjpeg", "-version"])
|
|
||||||
return True
|
|
||||||
except subprocess.CalledProcessError: # pragma: no cover
|
|
||||||
return False
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def netpbm_available() -> bool:
|
def netpbm_available() -> bool:
|
||||||
return bool(shutil.which("ppmquant") and shutil.which("ppmtogif"))
|
return bool(shutil.which("ppmquant") and shutil.which("ppmtogif"))
|
||||||
|
|
||||||
|
|
BIN
Tests/images/unimplemented_pixel_format.dds
Normal file
BIN
Tests/images/unimplemented_pixel_format.dds
Normal file
Binary file not shown.
|
@ -2,7 +2,6 @@ from __future__ import annotations
|
||||||
|
|
||||||
import io
|
import io
|
||||||
import re
|
import re
|
||||||
from typing import Callable
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
@ -10,6 +9,10 @@ from PIL import features
|
||||||
|
|
||||||
from .helper import skip_unless_feature
|
from .helper import skip_unless_feature
|
||||||
|
|
||||||
|
TYPE_CHECKING = False
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Callable
|
||||||
|
|
||||||
|
|
||||||
def test_check() -> None:
|
def test_check() -> None:
|
||||||
# Check the correctness of the convenience function
|
# Check the correctness of the convenience function
|
||||||
|
@ -18,10 +21,6 @@ def test_check() -> None:
|
||||||
for codec in features.codecs:
|
for codec in features.codecs:
|
||||||
assert features.check_codec(codec) == features.check(codec)
|
assert features.check_codec(codec) == features.check(codec)
|
||||||
for feature in features.features:
|
for feature in features.features:
|
||||||
if "webp" in feature:
|
|
||||||
with pytest.warns(DeprecationWarning, match="webp"):
|
|
||||||
assert features.check_feature(feature) == features.check(feature)
|
|
||||||
else:
|
|
||||||
assert features.check_feature(feature) == features.check(feature)
|
assert features.check_feature(feature) == features.check(feature)
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,10 +47,6 @@ def test_version() -> None:
|
||||||
for codec in features.codecs:
|
for codec in features.codecs:
|
||||||
test(codec, features.version_codec)
|
test(codec, features.version_codec)
|
||||||
for feature in features.features:
|
for feature in features.features:
|
||||||
if "webp" in feature:
|
|
||||||
with pytest.warns(DeprecationWarning, match="webp"):
|
|
||||||
test(feature, features.version_feature)
|
|
||||||
else:
|
|
||||||
test(feature, features.version_feature)
|
test(feature, features.version_feature)
|
||||||
|
|
||||||
|
|
||||||
|
@ -112,6 +107,25 @@ def test_unsupported_module() -> None:
|
||||||
features.version_module(module)
|
features.version_module(module)
|
||||||
|
|
||||||
|
|
||||||
|
def test_unsupported_feature() -> None:
|
||||||
|
# Arrange
|
||||||
|
feature = "unsupported_feature"
|
||||||
|
# Act / Assert
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
features.check_feature(feature)
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
features.version_feature(feature)
|
||||||
|
|
||||||
|
|
||||||
|
def test_unsupported_version() -> None:
|
||||||
|
assert features.version("unsupported_version") is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_modulenotfound(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||||
|
monkeypatch.setattr(features, "features", {"test": ("PIL._test", "", "")})
|
||||||
|
assert features.check_feature("test") is None
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("supported_formats", (True, False))
|
@pytest.mark.parametrize("supported_formats", (True, False))
|
||||||
def test_pilinfo(supported_formats: bool) -> None:
|
def test_pilinfo(supported_formats: bool) -> None:
|
||||||
buf = io.StringIO()
|
buf = io.StringIO()
|
||||||
|
|
|
@ -380,21 +380,28 @@ def test_palette() -> None:
|
||||||
assert_image_equal_tofile(im, "Tests/images/transparent.gif")
|
assert_image_equal_tofile(im, "Tests/images/transparent.gif")
|
||||||
|
|
||||||
|
|
||||||
|
def test_unsupported_header_size() -> None:
|
||||||
|
with pytest.raises(OSError, match="Unsupported header size 0"):
|
||||||
|
with Image.open(BytesIO(b"DDS " + b"\x00" * 4)):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def test_unsupported_bitcount() -> None:
|
def test_unsupported_bitcount() -> None:
|
||||||
with pytest.raises(OSError):
|
with pytest.raises(OSError, match="Unsupported bitcount 24 for 131072"):
|
||||||
with Image.open("Tests/images/unsupported_bitcount.dds"):
|
with Image.open("Tests/images/unsupported_bitcount.dds"):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"test_file",
|
"test_file, message",
|
||||||
(
|
(
|
||||||
"Tests/images/unimplemented_dxgi_format.dds",
|
("Tests/images/unimplemented_dxgi_format.dds", "Unimplemented DXGI format 93"),
|
||||||
"Tests/images/unimplemented_pfflags.dds",
|
("Tests/images/unimplemented_pixel_format.dds", "Unimplemented pixel format 0"),
|
||||||
|
("Tests/images/unimplemented_pfflags.dds", "Unknown pixel format flags 8"),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
def test_not_implemented(test_file: str) -> None:
|
def test_not_implemented(test_file: str, message: str) -> None:
|
||||||
with pytest.raises(NotImplementedError):
|
with pytest.raises(NotImplementedError, match=message):
|
||||||
with Image.open(test_file):
|
with Image.open(test_file):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,6 @@ from .helper import (
|
||||||
assert_image_equal_tofile,
|
assert_image_equal_tofile,
|
||||||
assert_image_similar,
|
assert_image_similar,
|
||||||
assert_image_similar_tofile,
|
assert_image_similar_tofile,
|
||||||
cjpeg_available,
|
|
||||||
djpeg_available,
|
djpeg_available,
|
||||||
hopper,
|
hopper,
|
||||||
is_win32,
|
is_win32,
|
||||||
|
@ -731,14 +730,6 @@ class TestFileJpeg:
|
||||||
img.load_djpeg()
|
img.load_djpeg()
|
||||||
assert_image_similar_tofile(img, TEST_FILE, 5)
|
assert_image_similar_tofile(img, TEST_FILE, 5)
|
||||||
|
|
||||||
@pytest.mark.skipif(not cjpeg_available(), reason="cjpeg not available")
|
|
||||||
def test_save_cjpeg(self, tmp_path: Path) -> None:
|
|
||||||
with Image.open(TEST_FILE) as img:
|
|
||||||
tempfile = str(tmp_path / "temp.jpg")
|
|
||||||
JpegImagePlugin._save_cjpeg(img, BytesIO(), tempfile)
|
|
||||||
# Default save quality is 75%, so a tiny bit of difference is alright
|
|
||||||
assert_image_similar_tofile(img, tempfile, 17)
|
|
||||||
|
|
||||||
def test_no_duplicate_0x1001_tag(self) -> None:
|
def test_no_duplicate_0x1001_tag(self) -> None:
|
||||||
# Arrange
|
# Arrange
|
||||||
tag_ids = {v: k for k, v in ExifTags.TAGS.items()}
|
tag_ids = {v: k for k, v in ExifTags.TAGS.items()}
|
||||||
|
|
|
@ -873,7 +873,7 @@ class TestFileLibTiff(LibTiffTestCase):
|
||||||
assert im.mode == "RGB"
|
assert im.mode == "RGB"
|
||||||
assert im.size == (128, 128)
|
assert im.size == (128, 128)
|
||||||
assert im.format == "TIFF"
|
assert im.format == "TIFF"
|
||||||
im2 = hopper()
|
with hopper() as im2:
|
||||||
assert_image_similar(im, im2, 5)
|
assert_image_similar(im, im2, 5)
|
||||||
except OSError:
|
except OSError:
|
||||||
captured = capfd.readouterr()
|
captured = capfd.readouterr()
|
||||||
|
|
|
@ -44,6 +44,18 @@ def test_load_zero_inch() -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def test_load_unsupported_wmf() -> None:
|
||||||
|
b = BytesIO(b"\xd7\xcd\xc6\x9a\x00\x00" + b"\x01" * 10)
|
||||||
|
with pytest.raises(SyntaxError, match="Unsupported WMF file format"):
|
||||||
|
WmfImagePlugin.WmfStubImageFile(b)
|
||||||
|
|
||||||
|
|
||||||
|
def test_load_unsupported() -> None:
|
||||||
|
b = BytesIO(b"\x01\x00\x00\x00")
|
||||||
|
with pytest.raises(SyntaxError, match="Unsupported file format"):
|
||||||
|
WmfImagePlugin.WmfStubImageFile(b)
|
||||||
|
|
||||||
|
|
||||||
def test_render() -> None:
|
def test_render() -> None:
|
||||||
with open("Tests/images/drawing.emf", "rb") as fp:
|
with open("Tests/images/drawing.emf", "rb") as fp:
|
||||||
data = fp.read()
|
data = fp.read()
|
||||||
|
|
|
@ -2,12 +2,15 @@ from __future__ import annotations
|
||||||
|
|
||||||
import colorsys
|
import colorsys
|
||||||
import itertools
|
import itertools
|
||||||
from typing import Callable
|
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
from .helper import assert_image_similar, hopper
|
from .helper import assert_image_similar, hopper
|
||||||
|
|
||||||
|
TYPE_CHECKING = False
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Callable
|
||||||
|
|
||||||
|
|
||||||
def int_to_float(i: int) -> float:
|
def int_to_float(i: int) -> float:
|
||||||
return i / 255
|
return i / 255
|
||||||
|
|
|
@ -315,3 +315,10 @@ int main(int argc, char* argv[])
|
||||||
process = subprocess.Popen(["embed_pil.exe"], env=env)
|
process = subprocess.Popen(["embed_pil.exe"], env=env)
|
||||||
process.communicate()
|
process.communicate()
|
||||||
assert process.returncode == 0
|
assert process.returncode == 0
|
||||||
|
|
||||||
|
def teardown_method(self) -> None:
|
||||||
|
try:
|
||||||
|
os.remove("embed_pil.c")
|
||||||
|
except FileNotFoundError:
|
||||||
|
# If the test was skipped or failed, the file won't exist
|
||||||
|
pass
|
||||||
|
|
|
@ -10,9 +10,12 @@ def test_histogram() -> None:
|
||||||
|
|
||||||
assert histogram("1") == (256, 0, 10994)
|
assert histogram("1") == (256, 0, 10994)
|
||||||
assert histogram("L") == (256, 0, 662)
|
assert histogram("L") == (256, 0, 662)
|
||||||
|
assert histogram("LA") == (512, 0, 16384)
|
||||||
|
assert histogram("La") == (512, 0, 16384)
|
||||||
assert histogram("I") == (256, 0, 662)
|
assert histogram("I") == (256, 0, 662)
|
||||||
assert histogram("F") == (256, 0, 662)
|
assert histogram("F") == (256, 0, 662)
|
||||||
assert histogram("P") == (256, 0, 1551)
|
assert histogram("P") == (256, 0, 1551)
|
||||||
|
assert histogram("PA") == (512, 0, 16384)
|
||||||
assert histogram("RGB") == (768, 4, 675)
|
assert histogram("RGB") == (768, 4, 675)
|
||||||
assert histogram("RGBA") == (1024, 0, 16384)
|
assert histogram("RGBA") == (1024, 0, 16384)
|
||||||
assert histogram("CMYK") == (1024, 0, 16384)
|
assert histogram("CMYK") == (1024, 0, 16384)
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import math
|
import math
|
||||||
from typing import Callable
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
@ -9,6 +8,10 @@ from PIL import Image, ImageTransform
|
||||||
|
|
||||||
from .helper import assert_image_equal, assert_image_similar, hopper
|
from .helper import assert_image_equal, assert_image_similar, hopper
|
||||||
|
|
||||||
|
TYPE_CHECKING = False
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Callable
|
||||||
|
|
||||||
|
|
||||||
class TestImageTransform:
|
class TestImageTransform:
|
||||||
def test_sanity(self) -> None:
|
def test_sanity(self) -> None:
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Callable
|
|
||||||
|
|
||||||
from PIL import Image, ImageChops
|
from PIL import Image, ImageChops
|
||||||
|
|
||||||
from .helper import assert_image_equal, hopper
|
from .helper import assert_image_equal, hopper
|
||||||
|
|
||||||
|
TYPE_CHECKING = False
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Callable
|
||||||
|
|
||||||
BLACK = (0, 0, 0)
|
BLACK = (0, 0, 0)
|
||||||
BROWN = (127, 64, 0)
|
BROWN = (127, 64, 0)
|
||||||
CYAN = (0, 255, 255)
|
CYAN = (0, 255, 255)
|
||||||
|
|
|
@ -7,7 +7,7 @@ import shutil
|
||||||
import sys
|
import sys
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Literal, cast
|
from typing import Literal, cast
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
@ -31,6 +31,9 @@ except ImportError:
|
||||||
# Skipped via setup_module()
|
# Skipped via setup_module()
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
TYPE_CHECKING = False
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
SRGB = "Tests/icc/sRGB_IEC61966-2-1_black_scaled.icc"
|
SRGB = "Tests/icc/sRGB_IEC61966-2-1_black_scaled.icc"
|
||||||
HAVE_PROFILE = os.path.exists(SRGB)
|
HAVE_PROFILE = os.path.exists(SRGB)
|
||||||
|
@ -208,9 +211,10 @@ def test_exceptions() -> None:
|
||||||
ImageCms.getProfileName(None) # type: ignore[arg-type]
|
ImageCms.getProfileName(None) # type: ignore[arg-type]
|
||||||
skip_missing()
|
skip_missing()
|
||||||
|
|
||||||
# Python <= 3.9: "an integer is required (got type NoneType)"
|
with pytest.raises(
|
||||||
# Python > 3.9: "'NoneType' object cannot be interpreted as an integer"
|
ImageCms.PyCMSError,
|
||||||
with pytest.raises(ImageCms.PyCMSError, match="integer"):
|
match="'NoneType' object cannot be interpreted as an integer",
|
||||||
|
):
|
||||||
ImageCms.isIntentSupported(SRGB, None, None) # type: ignore[arg-type]
|
ImageCms.isIntentSupported(SRGB, None, None) # type: ignore[arg-type]
|
||||||
|
|
||||||
|
|
||||||
|
@ -690,3 +694,17 @@ def test_cmyk_lab() -> None:
|
||||||
im = Image.new("CMYK", (1, 1))
|
im = Image.new("CMYK", (1, 1))
|
||||||
converted_im = im.convert("LAB")
|
converted_im = im.convert("LAB")
|
||||||
assert converted_im.getpixel((0, 0)) == (255, 128, 128)
|
assert converted_im.getpixel((0, 0)) == (255, 128, 128)
|
||||||
|
|
||||||
|
|
||||||
|
def test_deprecation() -> None:
|
||||||
|
profile = ImageCmsProfile(ImageCms.createProfile("sRGB"))
|
||||||
|
with pytest.warns(
|
||||||
|
DeprecationWarning, match="ImageCms.ImageCmsProfile.product_name"
|
||||||
|
):
|
||||||
|
profile.product_name
|
||||||
|
with pytest.warns(
|
||||||
|
DeprecationWarning, match="ImageCms.ImageCmsProfile.product_info"
|
||||||
|
):
|
||||||
|
profile.product_info
|
||||||
|
with pytest.raises(AttributeError):
|
||||||
|
profile.this_attribute_does_not_exist
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import os.path
|
import os.path
|
||||||
from collections.abc import Sequence
|
|
||||||
from typing import Callable
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from PIL import Image, ImageColor, ImageDraw, ImageFont, features
|
from PIL import Image, ImageColor, ImageDraw, ImageFont, features
|
||||||
from PIL._typing import Coords
|
|
||||||
|
|
||||||
from .helper import (
|
from .helper import (
|
||||||
assert_image_equal,
|
assert_image_equal,
|
||||||
|
@ -17,6 +14,12 @@ from .helper import (
|
||||||
skip_unless_feature,
|
skip_unless_feature,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
TYPE_CHECKING = False
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Callable, Sequence
|
||||||
|
|
||||||
|
from PIL._typing import Coords
|
||||||
|
|
||||||
BLACK = (0, 0, 0)
|
BLACK = (0, 0, 0)
|
||||||
WHITE = (255, 255, 255)
|
WHITE = (255, 255, 255)
|
||||||
GRAY = (190, 190, 190)
|
GRAY = (190, 190, 190)
|
||||||
|
|
|
@ -2,7 +2,9 @@ from __future__ import annotations
|
||||||
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from PIL import Image, ImageMath
|
import pytest
|
||||||
|
|
||||||
|
from PIL import Image, ImageMath, _imagingmath
|
||||||
|
|
||||||
|
|
||||||
def pixel(im: Image.Image | int) -> str | int:
|
def pixel(im: Image.Image | int) -> str | int:
|
||||||
|
@ -498,3 +500,31 @@ def test_logical_not_equal() -> None:
|
||||||
)
|
)
|
||||||
== "I 1"
|
== "I 1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_reflected_operands() -> None:
|
||||||
|
assert pixel(ImageMath.lambda_eval(lambda args: 1 + args["A"], **images)) == "I 2"
|
||||||
|
assert pixel(ImageMath.lambda_eval(lambda args: 1 - args["A"], **images)) == "I 0"
|
||||||
|
assert pixel(ImageMath.lambda_eval(lambda args: 1 * args["A"], **images)) == "I 1"
|
||||||
|
assert pixel(ImageMath.lambda_eval(lambda args: 1 / args["A"], **images)) == "I 1"
|
||||||
|
assert pixel(ImageMath.lambda_eval(lambda args: 1 % args["A"], **images)) == "I 0"
|
||||||
|
assert pixel(ImageMath.lambda_eval(lambda args: 1 ** args["A"], **images)) == "I 1"
|
||||||
|
assert pixel(ImageMath.lambda_eval(lambda args: 1 & args["A"], **images)) == "I 1"
|
||||||
|
assert pixel(ImageMath.lambda_eval(lambda args: 1 | args["A"], **images)) == "I 1"
|
||||||
|
assert pixel(ImageMath.lambda_eval(lambda args: 1 ^ args["A"], **images)) == "I 0"
|
||||||
|
|
||||||
|
|
||||||
|
def test_unsupported_mode() -> None:
|
||||||
|
im = Image.new("RGB", (1, 1))
|
||||||
|
with pytest.raises(ValueError, match="unsupported mode: RGB"):
|
||||||
|
ImageMath.lambda_eval(lambda args: args["im"] + 1, im=im)
|
||||||
|
|
||||||
|
|
||||||
|
def test_bad_operand_type(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||||
|
monkeypatch.delattr(_imagingmath, "abs_I")
|
||||||
|
with pytest.raises(TypeError, match="bad operand type for 'abs'"):
|
||||||
|
ImageMath.lambda_eval(lambda args: abs(args["I"]), I=I)
|
||||||
|
|
||||||
|
monkeypatch.delattr(_imagingmath, "max_F")
|
||||||
|
with pytest.raises(TypeError, match="bad operand type for 'max'"):
|
||||||
|
ImageMath.lambda_eval(lambda args: args["max"](args["I"], args["F"]), I=I, F=F)
|
||||||
|
|
|
@ -9,9 +9,30 @@ from PIL import __version__
|
||||||
pyroma = pytest.importorskip("pyroma", reason="Pyroma not installed")
|
pyroma = pytest.importorskip("pyroma", reason="Pyroma not installed")
|
||||||
|
|
||||||
|
|
||||||
|
def map_metadata_keys(metadata):
|
||||||
|
# Convert installed wheel metadata into canonical Core Metadata 2.4 format.
|
||||||
|
# This was a utility method in pyroma 4.3.3; it was removed in 5.0.
|
||||||
|
# This implementation is constructed from the relevant logic from
|
||||||
|
# Pyroma 5.0's `build_metadata()` implementation. This has been submitted
|
||||||
|
# upstream to Pyroma as https://github.com/regebro/pyroma/pull/116,
|
||||||
|
# so it may be possible to simplify this test in future.
|
||||||
|
data = {}
|
||||||
|
for key in set(metadata.keys()):
|
||||||
|
value = metadata.get_all(key)
|
||||||
|
key = pyroma.projectdata.normalize(key)
|
||||||
|
|
||||||
|
if len(value) == 1:
|
||||||
|
value = value[0]
|
||||||
|
if value.strip() == "UNKNOWN":
|
||||||
|
continue
|
||||||
|
|
||||||
|
data[key] = value
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
def test_pyroma() -> None:
|
def test_pyroma() -> None:
|
||||||
# Arrange
|
# Arrange
|
||||||
data = pyroma.projectdata.map_metadata_keys(metadata("Pillow"))
|
data = map_metadata_keys(metadata("Pillow"))
|
||||||
|
|
||||||
# Act
|
# Act
|
||||||
rating = pyroma.ratings.rate(data)
|
rating = pyroma.ratings.rate(data)
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from pathlib import Path
|
|
||||||
from typing import Union
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from PIL import Image, ImageQt
|
from PIL import Image, ImageQt
|
||||||
|
@ -11,18 +8,8 @@ from .helper import assert_image_equal_tofile, assert_image_similar, hopper
|
||||||
|
|
||||||
TYPE_CHECKING = False
|
TYPE_CHECKING = False
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
import PyQt6
|
from pathlib import Path
|
||||||
import PySide6
|
|
||||||
|
|
||||||
QApplication = Union[PyQt6.QtWidgets.QApplication, PySide6.QtWidgets.QApplication]
|
|
||||||
QHBoxLayout = Union[PyQt6.QtWidgets.QHBoxLayout, PySide6.QtWidgets.QHBoxLayout]
|
|
||||||
QImage = Union[PyQt6.QtGui.QImage, PySide6.QtGui.QImage]
|
|
||||||
QLabel = Union[PyQt6.QtWidgets.QLabel, PySide6.QtWidgets.QLabel]
|
|
||||||
QPainter = Union[PyQt6.QtGui.QPainter, PySide6.QtGui.QPainter]
|
|
||||||
QPixmap = Union[PyQt6.QtGui.QPixmap, PySide6.QtGui.QPixmap]
|
|
||||||
QPoint = Union[PyQt6.QtCore.QPoint, PySide6.QtCore.QPoint]
|
|
||||||
QRegion = Union[PyQt6.QtGui.QRegion, PySide6.QtGui.QRegion]
|
|
||||||
QWidget = Union[PyQt6.QtWidgets.QWidget, PySide6.QtWidgets.QWidget]
|
|
||||||
|
|
||||||
if ImageQt.qt_is_installed:
|
if ImageQt.qt_is_installed:
|
||||||
from PIL.ImageQt import QPixmap
|
from PIL.ImageQt import QPixmap
|
||||||
|
@ -32,11 +19,16 @@ if ImageQt.qt_is_installed:
|
||||||
from PyQt6.QtGui import QImage, QPainter, QRegion
|
from PyQt6.QtGui import QImage, QPainter, QRegion
|
||||||
from PyQt6.QtWidgets import QApplication, QHBoxLayout, QLabel, QWidget
|
from PyQt6.QtWidgets import QApplication, QHBoxLayout, QLabel, QWidget
|
||||||
elif ImageQt.qt_version == "side6":
|
elif ImageQt.qt_version == "side6":
|
||||||
from PySide6.QtCore import QPoint
|
from PySide6.QtCore import QPoint # type: ignore[assignment]
|
||||||
from PySide6.QtGui import QImage, QPainter, QRegion
|
from PySide6.QtGui import QImage, QPainter, QRegion # type: ignore[assignment]
|
||||||
from PySide6.QtWidgets import QApplication, QHBoxLayout, QLabel, QWidget
|
from PySide6.QtWidgets import ( # type: ignore[assignment]
|
||||||
|
QApplication,
|
||||||
|
QHBoxLayout,
|
||||||
|
QLabel,
|
||||||
|
QWidget,
|
||||||
|
)
|
||||||
|
|
||||||
class Example(QWidget): # type: ignore[misc]
|
class Example(QWidget):
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
@ -47,9 +39,9 @@ if ImageQt.qt_is_installed:
|
||||||
pixmap1 = getattr(ImageQt.QPixmap, "fromImage")(qimage)
|
pixmap1 = getattr(ImageQt.QPixmap, "fromImage")(qimage)
|
||||||
|
|
||||||
# hbox
|
# hbox
|
||||||
QHBoxLayout(self) # type: ignore[operator]
|
QHBoxLayout(self)
|
||||||
|
|
||||||
lbl = QLabel(self) # type: ignore[operator]
|
lbl = QLabel(self)
|
||||||
# Segfault in the problem
|
# Segfault in the problem
|
||||||
lbl.setPixmap(pixmap1.copy())
|
lbl.setPixmap(pixmap1.copy())
|
||||||
|
|
||||||
|
@ -63,7 +55,7 @@ def roundtrip(expected: Image.Image) -> None:
|
||||||
@pytest.mark.skipif(not ImageQt.qt_is_installed, reason="Qt bindings are not installed")
|
@pytest.mark.skipif(not ImageQt.qt_is_installed, reason="Qt bindings are not installed")
|
||||||
def test_sanity(tmp_path: Path) -> None:
|
def test_sanity(tmp_path: Path) -> None:
|
||||||
# Segfault test
|
# Segfault test
|
||||||
app: QApplication | None = QApplication([]) # type: ignore[operator]
|
app: QApplication | None = QApplication([])
|
||||||
ex = Example()
|
ex = Example()
|
||||||
assert app # Silence warning
|
assert app # Silence warning
|
||||||
assert ex # Silence warning
|
assert ex # Silence warning
|
||||||
|
@ -84,11 +76,11 @@ def test_sanity(tmp_path: Path) -> None:
|
||||||
imageqt = ImageQt.ImageQt(im)
|
imageqt = ImageQt.ImageQt(im)
|
||||||
data = getattr(QPixmap, "fromImage")(imageqt)
|
data = getattr(QPixmap, "fromImage")(imageqt)
|
||||||
qt_format = getattr(QImage, "Format") if ImageQt.qt_version == "6" else QImage
|
qt_format = getattr(QImage, "Format") if ImageQt.qt_version == "6" else QImage
|
||||||
qimage = QImage(128, 128, getattr(qt_format, "Format_ARGB32")) # type: ignore[operator]
|
qimage = QImage(128, 128, getattr(qt_format, "Format_ARGB32"))
|
||||||
painter = QPainter(qimage) # type: ignore[operator]
|
painter = QPainter(qimage)
|
||||||
image_label = QLabel() # type: ignore[operator]
|
image_label = QLabel()
|
||||||
image_label.setPixmap(data)
|
image_label.setPixmap(data)
|
||||||
image_label.render(painter, QPoint(0, 0), QRegion(0, 0, 128, 128)) # type: ignore[operator]
|
image_label.render(painter, QPoint(0, 0), QRegion(0, 0, 128, 128))
|
||||||
painter.end()
|
painter.end()
|
||||||
rendered_tempfile = str(tmp_path / f"temp_rendered_{mode}.png")
|
rendered_tempfile = str(tmp_path / f"temp_rendered_{mode}.png")
|
||||||
qimage.save(rendered_tempfile)
|
qimage.save(rendered_tempfile)
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from PIL import ImageQt
|
from PIL import ImageQt
|
||||||
|
|
||||||
from .helper import assert_image_equal, assert_image_equal_tofile, hopper
|
from .helper import assert_image_equal, assert_image_equal_tofile, hopper
|
||||||
|
|
||||||
|
TYPE_CHECKING = False
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
pytestmark = pytest.mark.skipif(
|
pytestmark = pytest.mark.skipif(
|
||||||
not ImageQt.qt_is_installed, reason="Qt bindings are not installed"
|
not ImageQt.qt_is_installed, reason="Qt bindings are not installed"
|
||||||
)
|
)
|
||||||
|
@ -21,7 +23,7 @@ def test_sanity(mode: str, tmp_path: Path) -> None:
|
||||||
src = hopper(mode)
|
src = hopper(mode)
|
||||||
data = ImageQt.toqimage(src)
|
data = ImageQt.toqimage(src)
|
||||||
|
|
||||||
assert isinstance(data, QImage) # type: ignore[arg-type, misc]
|
assert isinstance(data, QImage)
|
||||||
assert not data.isNull()
|
assert not data.isNull()
|
||||||
|
|
||||||
# reload directly from the qimage
|
# reload directly from the qimage
|
||||||
|
|
|
@ -2,14 +2,18 @@ from __future__ import annotations
|
||||||
|
|
||||||
import shutil
|
import shutil
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from pathlib import Path
|
|
||||||
from typing import IO, Callable
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from PIL import GifImagePlugin, Image, JpegImagePlugin
|
from PIL import GifImagePlugin, Image, JpegImagePlugin
|
||||||
|
|
||||||
from .helper import cjpeg_available, djpeg_available, is_win32, netpbm_available
|
from .helper import djpeg_available, is_win32, netpbm_available
|
||||||
|
|
||||||
|
TYPE_CHECKING = False
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Callable
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import IO
|
||||||
|
|
||||||
TEST_JPG = "Tests/images/hopper.jpg"
|
TEST_JPG = "Tests/images/hopper.jpg"
|
||||||
TEST_GIF = "Tests/images/hopper.gif"
|
TEST_GIF = "Tests/images/hopper.gif"
|
||||||
|
@ -42,11 +46,6 @@ class TestShellInjection:
|
||||||
assert isinstance(im, JpegImagePlugin.JpegImageFile)
|
assert isinstance(im, JpegImagePlugin.JpegImageFile)
|
||||||
im.load_djpeg()
|
im.load_djpeg()
|
||||||
|
|
||||||
@pytest.mark.skipif(not cjpeg_available(), reason="cjpeg not available")
|
|
||||||
def test_save_cjpeg_filename(self, tmp_path: Path) -> None:
|
|
||||||
with Image.open(TEST_JPG) as im:
|
|
||||||
self.assert_save_filename_check(tmp_path, im, JpegImagePlugin._save_cjpeg)
|
|
||||||
|
|
||||||
@pytest.mark.skipif(not netpbm_available(), reason="Netpbm not available")
|
@pytest.mark.skipif(not netpbm_available(), reason="Netpbm not available")
|
||||||
def test_save_netpbm_filename_bmp_mode(self, tmp_path: Path) -> None:
|
def test_save_netpbm_filename_bmp_mode(self, tmp_path: Path) -> None:
|
||||||
with Image.open(TEST_GIF) as im:
|
with Image.open(TEST_GIF) as im:
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Any, Callable
|
from collections.abc import Callable
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,7 @@ def test_wheel_modules() -> None:
|
||||||
|
|
||||||
elif sys.platform == "ios":
|
elif sys.platform == "ios":
|
||||||
# tkinter is not available on iOS
|
# tkinter is not available on iOS
|
||||||
# libavif is not available on iOS (for now)
|
expected_modules.remove("tkinter")
|
||||||
expected_modules -= {"tkinter", "avif"}
|
|
||||||
|
|
||||||
assert set(features.get_supported_modules()) == expected_modules
|
assert set(features.get_supported_modules()) == expected_modules
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# install webp
|
# install webp
|
||||||
|
|
||||||
archive=libwebp-1.5.0
|
archive=libwebp-1.6.0
|
||||||
|
|
||||||
./download-and-extract.sh $archive https://raw.githubusercontent.com/python-pillow/pillow-depends/main/$archive.tar.gz
|
./download-and-extract.sh $archive https://raw.githubusercontent.com/python-pillow/pillow-depends/main/$archive.tar.gz
|
||||||
|
|
||||||
|
|
|
@ -12,13 +12,6 @@ Deprecated features
|
||||||
Below are features which are considered deprecated. Where appropriate,
|
Below are features which are considered deprecated. Where appropriate,
|
||||||
a :py:exc:`DeprecationWarning` is issued.
|
a :py:exc:`DeprecationWarning` is issued.
|
||||||
|
|
||||||
ImageDraw.getdraw hints parameter
|
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
.. deprecated:: 10.4.0
|
|
||||||
|
|
||||||
The ``hints`` parameter in :py:meth:`~PIL.ImageDraw.getdraw()` has been deprecated.
|
|
||||||
|
|
||||||
ExifTags.IFD.Makernote
|
ExifTags.IFD.Makernote
|
||||||
^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
@ -62,6 +55,15 @@ another mode before saving::
|
||||||
im = Image.new("I", (1, 1))
|
im = Image.new("I", (1, 1))
|
||||||
im.convert("I;16").save("out.png")
|
im.convert("I;16").save("out.png")
|
||||||
|
|
||||||
|
ImageCms.ImageCmsProfile.product_name and .product_info
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
.. deprecated:: 12.0.0
|
||||||
|
|
||||||
|
``ImageCms.ImageCmsProfile.product_name`` and the corresponding
|
||||||
|
``.product_info`` attributes have been deprecated, and will be removed in
|
||||||
|
Pillow 13 (2026-10-15). They have been set to ``None`` since Pillow 2.3.0.
|
||||||
|
|
||||||
Removed features
|
Removed features
|
||||||
----------------
|
----------------
|
||||||
|
|
||||||
|
@ -189,6 +191,7 @@ ICNS (width, height, scale) sizes
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
.. deprecated:: 11.0.0
|
.. deprecated:: 11.0.0
|
||||||
|
.. versionremoved:: 12.0.0
|
||||||
|
|
||||||
Setting an ICNS image size to ``(width, height, scale)`` before loading has been
|
Setting an ICNS image size to ``(width, height, scale)`` before loading has been
|
||||||
removed. Instead, ``load(scale)`` can be used.
|
removed. Instead, ``load(scale)`` can be used.
|
||||||
|
|
|
@ -101,6 +101,28 @@ Palette
|
||||||
The palette mode (``P``) uses a color palette to define the actual color for
|
The palette mode (``P``) uses a color palette to define the actual color for
|
||||||
each pixel.
|
each pixel.
|
||||||
|
|
||||||
|
.. _colors:
|
||||||
|
|
||||||
|
Colors
|
||||||
|
------
|
||||||
|
|
||||||
|
To specify colors, you can use tuples with a value for each channel in the image, e.g.
|
||||||
|
``Image.new("RGB", (1, 1), (255, 0, 0))``.
|
||||||
|
|
||||||
|
If an image has a single channel, you can use a single number instead, e.g.
|
||||||
|
``Image.new("L", (1, 1), 255)``. For "F" mode images, floating point values are also
|
||||||
|
accepted. In the case of "P" mode images, these will be indexes for the color palette.
|
||||||
|
|
||||||
|
If a single value is used for an image with more than one channel, it will still be
|
||||||
|
parsed::
|
||||||
|
|
||||||
|
>>> from PIL import Image
|
||||||
|
>>> im = Image.new("RGBA", (1, 1), 0x04030201)
|
||||||
|
>>> im.getpixel((0, 0))
|
||||||
|
(1, 2, 3, 4)
|
||||||
|
|
||||||
|
Some methods accept other forms, such as color names. See :ref:`color-names`.
|
||||||
|
|
||||||
Info
|
Info
|
||||||
----
|
----
|
||||||
|
|
||||||
|
|
|
@ -29,10 +29,6 @@ Pillow for enterprise is available via the Tidelift Subscription. `Learn more <h
|
||||||
:target: https://github.com/python-pillow/Pillow/actions/workflows/test-mingw.yml
|
:target: https://github.com/python-pillow/Pillow/actions/workflows/test-mingw.yml
|
||||||
:alt: GitHub Actions build status (Test MinGW)
|
:alt: GitHub Actions build status (Test MinGW)
|
||||||
|
|
||||||
.. image:: https://github.com/python-pillow/Pillow/workflows/Test%20Cygwin/badge.svg
|
|
||||||
:target: https://github.com/python-pillow/Pillow/actions/workflows/test-cygwin.yml
|
|
||||||
:alt: GitHub Actions build status (Test Cygwin)
|
|
||||||
|
|
||||||
.. image:: https://github.com/python-pillow/Pillow/workflows/Wheels/badge.svg
|
.. image:: https://github.com/python-pillow/Pillow/workflows/Wheels/badge.svg
|
||||||
:target: https://github.com/python-pillow/Pillow/actions/workflows/wheels.yml
|
:target: https://github.com/python-pillow/Pillow/actions/workflows/wheels.yml
|
||||||
:alt: GitHub Actions build status (Wheels)
|
:alt: GitHub Actions build status (Wheels)
|
||||||
|
|
|
@ -44,7 +44,7 @@ Many of Pillow's features require external libraries:
|
||||||
|
|
||||||
* **libtiff** provides compressed TIFF functionality
|
* **libtiff** provides compressed TIFF functionality
|
||||||
|
|
||||||
* Pillow has been tested with libtiff versions **3.x** and **4.0-4.7.0**
|
* Pillow has been tested with libtiff versions **4.0-4.7.0**
|
||||||
|
|
||||||
* **libfreetype** provides type related services
|
* **libfreetype** provides type related services
|
||||||
|
|
||||||
|
@ -276,10 +276,9 @@ Build options
|
||||||
|
|
||||||
* Config setting: ``-C parallel=n``. Can also be given
|
* Config setting: ``-C parallel=n``. Can also be given
|
||||||
with environment variable: ``MAX_CONCURRENCY=n``. Pillow can use
|
with environment variable: ``MAX_CONCURRENCY=n``. Pillow can use
|
||||||
multiprocessing to build the extension. Setting ``-C parallel=n``
|
multiprocessing to build the extensions. Setting ``-C parallel=n``
|
||||||
sets the number of CPUs to use to ``n``, or can disable parallel building by
|
sets the number of CPUs to use to ``n``, or can disable parallel building by
|
||||||
using a setting of 1. By default, it uses 4 CPUs, or if 4 are not
|
using a setting of 1. By default, it uses as many CPUs as are present.
|
||||||
available, as many as are present.
|
|
||||||
|
|
||||||
* Config settings: ``-C zlib=disable``, ``-C jpeg=disable``,
|
* Config settings: ``-C zlib=disable``, ``-C jpeg=disable``,
|
||||||
``-C tiff=disable``, ``-C freetype=disable``, ``-C raqm=disable``,
|
``-C tiff=disable``, ``-C freetype=disable``, ``-C raqm=disable``,
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
Python,3.13,3.12,3.11,3.10,3.9,3.8,3.7,3.6,3.5
|
Python,3.14,3.13,3.12,3.11,3.10,3.9,3.8,3.7,3.6,3.5
|
||||||
Pillow >= 11,Yes,Yes,Yes,Yes,Yes,,,,
|
Pillow 12,Yes,Yes,Yes,Yes,Yes,,,,,
|
||||||
Pillow 10.1 - 10.4,,Yes,Yes,Yes,Yes,Yes,,,
|
Pillow 11,,Yes,Yes,Yes,Yes,Yes,,,,
|
||||||
Pillow 10.0,,,Yes,Yes,Yes,Yes,,,
|
Pillow 10.1 - 10.4,,,Yes,Yes,Yes,Yes,Yes,,,
|
||||||
Pillow 9.3 - 9.5,,,Yes,Yes,Yes,Yes,Yes,,
|
Pillow 10.0,,,,Yes,Yes,Yes,Yes,,,
|
||||||
Pillow 9.0 - 9.2,,,,Yes,Yes,Yes,Yes,,
|
Pillow 9.3 - 9.5,,,,Yes,Yes,Yes,Yes,Yes,,
|
||||||
Pillow 8.3.2 - 8.4,,,,Yes,Yes,Yes,Yes,Yes,
|
Pillow 9.0 - 9.2,,,,,Yes,Yes,Yes,Yes,,
|
||||||
Pillow 8.0 - 8.3.1,,,,,Yes,Yes,Yes,Yes,
|
Pillow 8.3.2 - 8.4,,,,,Yes,Yes,Yes,Yes,Yes,
|
||||||
Pillow 7.0 - 7.2,,,,,,Yes,Yes,Yes,Yes
|
Pillow 8.0 - 8.3.1,,,,,,Yes,Yes,Yes,Yes,
|
||||||
|
Pillow 7.0 - 7.2,,,,,,,Yes,Yes,Yes,Yes
|
||||||
|
|
|
|
@ -19,13 +19,13 @@ These platforms are built and tested for every change.
|
||||||
+==================================+============================+=====================+
|
+==================================+============================+=====================+
|
||||||
| Alpine | 3.12 | x86-64 |
|
| Alpine | 3.12 | x86-64 |
|
||||||
+----------------------------------+----------------------------+---------------------+
|
+----------------------------------+----------------------------+---------------------+
|
||||||
| Amazon Linux 2 | 3.9 | x86-64 |
|
| Amazon Linux 2 | 3.10 | x86-64 |
|
||||||
+----------------------------------+----------------------------+---------------------+
|
+----------------------------------+----------------------------+---------------------+
|
||||||
| Amazon Linux 2023 | 3.9 | x86-64 |
|
| Amazon Linux 2023 | 3.11 | x86-64 |
|
||||||
+----------------------------------+----------------------------+---------------------+
|
+----------------------------------+----------------------------+---------------------+
|
||||||
| Arch | 3.13 | x86-64 |
|
| Arch | 3.13 | x86-64 |
|
||||||
+----------------------------------+----------------------------+---------------------+
|
+----------------------------------+----------------------------+---------------------+
|
||||||
| CentOS Stream 9 | 3.9 | x86-64 |
|
| CentOS Stream 9 | 3.10 | x86-64 |
|
||||||
+----------------------------------+----------------------------+---------------------+
|
+----------------------------------+----------------------------+---------------------+
|
||||||
| CentOS Stream 10 | 3.12 | x86-64 |
|
| CentOS Stream 10 | 3.12 | x86-64 |
|
||||||
+----------------------------------+----------------------------+---------------------+
|
+----------------------------------+----------------------------+---------------------+
|
||||||
|
@ -37,27 +37,25 @@ These platforms are built and tested for every change.
|
||||||
+----------------------------------+----------------------------+---------------------+
|
+----------------------------------+----------------------------+---------------------+
|
||||||
| Gentoo | 3.12 | x86-64 |
|
| Gentoo | 3.12 | x86-64 |
|
||||||
+----------------------------------+----------------------------+---------------------+
|
+----------------------------------+----------------------------+---------------------+
|
||||||
| macOS 13 Ventura | 3.9 | x86-64 |
|
| macOS 13 Ventura | 3.10 | x86-64 |
|
||||||
+----------------------------------+----------------------------+---------------------+
|
+----------------------------------+----------------------------+---------------------+
|
||||||
| macOS 14 Sonoma | 3.10, 3.11, 3.12, 3.13, | arm64 |
|
| macOS 14 Sonoma | 3.11, 3.12, 3.13, 3.14 | arm64 |
|
||||||
| | 3.14, PyPy3 | |
|
| | PyPy3 | |
|
||||||
+----------------------------------+----------------------------+---------------------+
|
+----------------------------------+----------------------------+---------------------+
|
||||||
| Ubuntu Linux 22.04 LTS (Jammy) | 3.10 | x86-64 |
|
| Ubuntu Linux 22.04 LTS (Jammy) | 3.10 | x86-64 |
|
||||||
+----------------------------------+----------------------------+---------------------+
|
+----------------------------------+----------------------------+---------------------+
|
||||||
| Ubuntu Linux 24.04 LTS (Noble) | 3.9, 3.10, 3.11, | x86-64 |
|
| Ubuntu Linux 24.04 LTS (Noble) | 3.10, 3.11, 3.12, 3.13, | x86-64 |
|
||||||
| | 3.12, 3.13, 3.14, PyPy3 | |
|
| | 3.14, PyPy3 | |
|
||||||
| +----------------------------+---------------------+
|
| +----------------------------+---------------------+
|
||||||
| | 3.12 | arm64v8, ppc64le, |
|
| | 3.12 | arm64v8, ppc64le, |
|
||||||
| | | s390x |
|
| | | s390x |
|
||||||
+----------------------------------+----------------------------+---------------------+
|
+----------------------------------+----------------------------+---------------------+
|
||||||
| Windows Server 2022 | 3.9 | x86 |
|
| Windows Server 2022 | 3.10 | x86 |
|
||||||
| +----------------------------+---------------------+
|
| +----------------------------+---------------------+
|
||||||
| | 3.10, 3.11, 3.12, 3.13, | x86-64 |
|
| | 3.11, 3.12, 3.13, 3.14, | x86-64 |
|
||||||
| | 3.14, PyPy3 | |
|
| | PyPy3 | |
|
||||||
| +----------------------------+---------------------+
|
| +----------------------------+---------------------+
|
||||||
| | 3.12 (MinGW) | x86-64 |
|
| | 3.12 (MinGW) | x86-64 |
|
||||||
| +----------------------------+---------------------+
|
|
||||||
| | 3.9 (Cygwin) | x86-64 |
|
|
||||||
+----------------------------------+----------------------------+---------------------+
|
+----------------------------------+----------------------------+---------------------+
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -45,9 +45,7 @@ Colors
|
||||||
^^^^^^
|
^^^^^^
|
||||||
|
|
||||||
To specify colors, you can use numbers or tuples just as you would use with
|
To specify colors, you can use numbers or tuples just as you would use with
|
||||||
:py:meth:`PIL.Image.new` or :py:meth:`PIL.Image.Image.putpixel`. For “1”,
|
:py:meth:`PIL.Image.new`. See :ref:`colors` for more information.
|
||||||
“L”, and “I” images, use integers. For “RGB” images, use a 3-tuple containing
|
|
||||||
integer values. For “F” images, use integer or floating point values.
|
|
||||||
|
|
||||||
For palette images (mode “P”), use integers as color indexes. In 1.1.4 and
|
For palette images (mode “P”), use integers as color indexes. In 1.1.4 and
|
||||||
later, you can also use RGB 3-tuples or color names (see below). The drawing
|
later, you can also use RGB 3-tuples or color names (see below). The drawing
|
||||||
|
|
|
@ -59,7 +59,7 @@ Access using negative indexes is also possible. ::
|
||||||
|
|
||||||
Modifies the pixel at x,y. The color is given as a single
|
Modifies the pixel at x,y. The color is given as a single
|
||||||
numerical value for single band images, and a tuple for
|
numerical value for single band images, and a tuple for
|
||||||
multi-band images.
|
multi-band images. See :ref:`colors` for more information.
|
||||||
|
|
||||||
:param xy: The pixel coordinate, given as (x, y).
|
:param xy: The pixel coordinate, given as (x, y).
|
||||||
:param color: The pixel value according to its mode,
|
:param color: The pixel value according to its mode,
|
||||||
|
|
|
@ -53,11 +53,6 @@ on some Python versions.
|
||||||
|
|
||||||
An object that supports the read method.
|
An object that supports the read method.
|
||||||
|
|
||||||
.. py:data:: TypeGuard
|
|
||||||
:value: typing.TypeGuard
|
|
||||||
|
|
||||||
See :py:obj:`typing.TypeGuard`.
|
|
||||||
|
|
||||||
:mod:`~PIL._util` module
|
:mod:`~PIL._util` module
|
||||||
------------------------
|
------------------------
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,12 @@ TODO
|
||||||
Backwards incompatible changes
|
Backwards incompatible changes
|
||||||
==============================
|
==============================
|
||||||
|
|
||||||
|
Python 3.9
|
||||||
|
^^^^^^^^^^
|
||||||
|
|
||||||
|
Pillow has dropped support for Python 3.9,
|
||||||
|
which reached end-of-life in October 2025.
|
||||||
|
|
||||||
ImageFile.raise_oserror
|
ImageFile.raise_oserror
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
@ -110,10 +116,12 @@ vulnerability introduced in FreeType 2.6 (:cve:`2020-15999`).
|
||||||
Deprecations
|
Deprecations
|
||||||
============
|
============
|
||||||
|
|
||||||
TODO
|
ImageCms.ImageCmsProfile.product_name and .product_info
|
||||||
^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
TODO
|
``ImageCms.ImageCmsProfile.product_name`` and the corresponding
|
||||||
|
``.product_info`` attributes have been deprecated, and will be removed in
|
||||||
|
Pillow 13 (2026-10-15). They have been set to ``None`` since Pillow 2.3.0.
|
||||||
|
|
||||||
API changes
|
API changes
|
||||||
===========
|
===========
|
||||||
|
@ -134,6 +142,15 @@ TODO
|
||||||
Other changes
|
Other changes
|
||||||
=============
|
=============
|
||||||
|
|
||||||
|
Python 3.14
|
||||||
|
^^^^^^^^^^^
|
||||||
|
|
||||||
|
Pillow 11.3.0 had wheels built against Python 3.14 beta, available as a preview to help
|
||||||
|
others prepare for 3.14, and to ensure Pillow could be used immediately at the release
|
||||||
|
of 3.14.0 final (2025-10-07, :pep:`745`).
|
||||||
|
|
||||||
|
Pillow 12.0.0 now officially supports Python 3.14.
|
||||||
|
|
||||||
Image.fromarray mode parameter
|
Image.fromarray mode parameter
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
|
|
@ -1,42 +0,0 @@
|
||||||
# libwebp example binaries require dependencies that aren't available for iOS builds.
|
|
||||||
# There's also no easy way to invoke the build to *exclude* the example builds.
|
|
||||||
# Since we don't need the examples anyway, remove them from the Makefile.
|
|
||||||
#
|
|
||||||
# As a point of reference, libwebp provides an XCFramework build script that involves
|
|
||||||
# 7 separate invocations of make to avoid building the examples. Patching the Makefile
|
|
||||||
# to remove the examples is a simpler approach, and one that is more compatible with
|
|
||||||
# the existing multibuild infrastructure.
|
|
||||||
#
|
|
||||||
# In the next release, it should be possible to pass --disable-libwebpexamples
|
|
||||||
# instead of applying this patch.
|
|
||||||
#
|
|
||||||
diff -ur libwebp-1.5.0-orig/Makefile.am libwebp-1.5.0/Makefile.am
|
|
||||||
--- libwebp-1.5.0-orig/Makefile.am 2024-12-20 09:17:50
|
|
||||||
+++ libwebp-1.5.0/Makefile.am 2025-01-09 11:24:17
|
|
||||||
@@ -5,5 +5,3 @@
|
|
||||||
if BUILD_EXTRAS
|
|
||||||
SUBDIRS += extras
|
|
||||||
endif
|
|
||||||
-
|
|
||||||
-SUBDIRS += examples
|
|
||||||
diff -ur libwebp-1.5.0-orig/Makefile.in libwebp-1.5.0/Makefile.in
|
|
||||||
--- libwebp-1.5.0-orig/Makefile.in 2024-12-20 09:52:53
|
|
||||||
+++ libwebp-1.5.0/Makefile.in 2025-01-09 11:24:17
|
|
||||||
@@ -156,7 +156,7 @@
|
|
||||||
unique=`for i in $$list; do \
|
|
||||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
|
||||||
done | $(am__uniquify_input)`
|
|
||||||
-DIST_SUBDIRS = sharpyuv src imageio man extras examples
|
|
||||||
+DIST_SUBDIRS = sharpyuv src imageio man extras
|
|
||||||
am__DIST_COMMON = $(srcdir)/Makefile.in \
|
|
||||||
$(top_srcdir)/src/webp/config.h.in AUTHORS COPYING ChangeLog \
|
|
||||||
NEWS README.md ar-lib compile config.guess config.sub \
|
|
||||||
@@ -351,7 +351,7 @@
|
|
||||||
top_srcdir = @top_srcdir@
|
|
||||||
webp_libname_prefix = @webp_libname_prefix@
|
|
||||||
ACLOCAL_AMFLAGS = -I m4
|
|
||||||
-SUBDIRS = sharpyuv src imageio man $(am__append_1) examples
|
|
||||||
+SUBDIRS = sharpyuv src imageio man $(am__append_1)
|
|
||||||
EXTRA_DIST = COPYING autogen.sh
|
|
||||||
all: all-recursive
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
[build-system]
|
[build-system]
|
||||||
build-backend = "backend"
|
build-backend = "backend"
|
||||||
requires = [
|
requires = [
|
||||||
|
"pybind11",
|
||||||
"setuptools>=77",
|
"setuptools>=77",
|
||||||
]
|
]
|
||||||
backend-path = [
|
backend-path = [
|
||||||
|
@ -19,15 +20,15 @@ license-files = [ "LICENSE" ]
|
||||||
authors = [
|
authors = [
|
||||||
{ name = "Jeffrey A. Clark", email = "aclark@aclark.net" },
|
{ name = "Jeffrey A. Clark", email = "aclark@aclark.net" },
|
||||||
]
|
]
|
||||||
requires-python = ">=3.9"
|
requires-python = ">=3.10"
|
||||||
classifiers = [
|
classifiers = [
|
||||||
"Development Status :: 6 - Mature",
|
"Development Status :: 6 - Mature",
|
||||||
"Programming Language :: Python :: 3 :: Only",
|
"Programming Language :: Python :: 3 :: Only",
|
||||||
"Programming Language :: Python :: 3.9",
|
|
||||||
"Programming Language :: Python :: 3.10",
|
"Programming Language :: Python :: 3.10",
|
||||||
"Programming Language :: Python :: 3.11",
|
"Programming Language :: Python :: 3.11",
|
||||||
"Programming Language :: Python :: 3.12",
|
"Programming Language :: Python :: 3.12",
|
||||||
"Programming Language :: Python :: 3.13",
|
"Programming Language :: Python :: 3.13",
|
||||||
|
"Programming Language :: Python :: 3.14",
|
||||||
"Programming Language :: Python :: Implementation :: CPython",
|
"Programming Language :: Python :: Implementation :: CPython",
|
||||||
"Programming Language :: Python :: Implementation :: PyPy",
|
"Programming Language :: Python :: Implementation :: PyPy",
|
||||||
"Topic :: Multimedia :: Graphics",
|
"Topic :: Multimedia :: Graphics",
|
||||||
|
@ -66,7 +67,7 @@ optional-dependencies.tests = [
|
||||||
"markdown2",
|
"markdown2",
|
||||||
"olefile",
|
"olefile",
|
||||||
"packaging",
|
"packaging",
|
||||||
"pyroma",
|
"pyroma>=5",
|
||||||
"pytest",
|
"pytest",
|
||||||
"pytest-cov",
|
"pytest-cov",
|
||||||
"pytest-timeout",
|
"pytest-timeout",
|
||||||
|
@ -74,9 +75,6 @@ optional-dependencies.tests = [
|
||||||
"trove-classifiers>=2024.10.12",
|
"trove-classifiers>=2024.10.12",
|
||||||
]
|
]
|
||||||
|
|
||||||
optional-dependencies.typing = [
|
|
||||||
"typing-extensions; python_version<'3.10'",
|
|
||||||
]
|
|
||||||
optional-dependencies.xmp = [
|
optional-dependencies.xmp = [
|
||||||
"defusedxml",
|
"defusedxml",
|
||||||
]
|
]
|
||||||
|
@ -187,8 +185,8 @@ lint.ignore = [
|
||||||
"PT011", # pytest-raises-too-broad
|
"PT011", # pytest-raises-too-broad
|
||||||
"PT012", # pytest-raises-with-multiple-statements
|
"PT012", # pytest-raises-with-multiple-statements
|
||||||
"PT017", # pytest-assert-in-except
|
"PT017", # pytest-assert-in-except
|
||||||
"PYI026", # flake8-pyi: typing.TypeAlias added in Python 3.10
|
|
||||||
"PYI034", # flake8-pyi: typing.Self added in Python 3.11
|
"PYI034", # flake8-pyi: typing.Self added in Python 3.11
|
||||||
|
"UP038", # pyupgrade: deprecated rule
|
||||||
]
|
]
|
||||||
lint.per-file-ignores."Tests/oss-fuzz/fuzz_font.py" = [
|
lint.per-file-ignores."Tests/oss-fuzz/fuzz_font.py" = [
|
||||||
"I002",
|
"I002",
|
||||||
|
@ -205,7 +203,7 @@ lint.isort.required-imports = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[tool.pyproject-fmt]
|
[tool.pyproject-fmt]
|
||||||
max_supported_python = "3.13"
|
max_supported_python = "3.14"
|
||||||
|
|
||||||
[tool.pytest.ini_options]
|
[tool.pytest.ini_options]
|
||||||
addopts = "-ra --color=auto"
|
addopts = "-ra --color=auto"
|
||||||
|
@ -214,7 +212,7 @@ testpaths = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[tool.mypy]
|
[tool.mypy]
|
||||||
python_version = "3.9"
|
python_version = "3.10"
|
||||||
pretty = true
|
pretty = true
|
||||||
disallow_any_generics = true
|
disallow_any_generics = true
|
||||||
enable_error_code = "ignore-without-code"
|
enable_error_code = "ignore-without-code"
|
||||||
|
|
23
setup.py
23
setup.py
|
@ -17,9 +17,20 @@ import sys
|
||||||
import warnings
|
import warnings
|
||||||
from collections.abc import Iterator
|
from collections.abc import Iterator
|
||||||
|
|
||||||
|
from pybind11.setup_helpers import ParallelCompile
|
||||||
from setuptools import Extension, setup
|
from setuptools import Extension, setup
|
||||||
from setuptools.command.build_ext import build_ext
|
from setuptools.command.build_ext import build_ext
|
||||||
|
|
||||||
|
configuration: dict[str, list[str]] = {}
|
||||||
|
|
||||||
|
# parse configuration from _custom_build/backend.py
|
||||||
|
while sys.argv[-1].startswith("--pillow-configuration="):
|
||||||
|
_, key, value = sys.argv.pop().split("=", 2)
|
||||||
|
configuration.setdefault(key, []).append(value)
|
||||||
|
|
||||||
|
default = int(configuration.get("parallel", ["0"])[-1])
|
||||||
|
ParallelCompile("MAX_CONCURRENCY", default).install()
|
||||||
|
|
||||||
|
|
||||||
def get_version() -> str:
|
def get_version() -> str:
|
||||||
version_file = "src/PIL/_version.py"
|
version_file = "src/PIL/_version.py"
|
||||||
|
@ -27,9 +38,6 @@ def get_version() -> str:
|
||||||
return f.read().split('"')[1]
|
return f.read().split('"')[1]
|
||||||
|
|
||||||
|
|
||||||
configuration: dict[str, list[str]] = {}
|
|
||||||
|
|
||||||
|
|
||||||
PILLOW_VERSION = get_version()
|
PILLOW_VERSION = get_version()
|
||||||
AVIF_ROOT = None
|
AVIF_ROOT = None
|
||||||
FREETYPE_ROOT = None
|
FREETYPE_ROOT = None
|
||||||
|
@ -386,9 +394,7 @@ class pil_build_ext(build_ext):
|
||||||
cpu_count = os.cpu_count()
|
cpu_count = os.cpu_count()
|
||||||
if cpu_count is not None:
|
if cpu_count is not None:
|
||||||
try:
|
try:
|
||||||
self.parallel = int(
|
self.parallel = int(os.environ.get("MAX_CONCURRENCY", cpu_count))
|
||||||
os.environ.get("MAX_CONCURRENCY", min(4, cpu_count))
|
|
||||||
)
|
|
||||||
except TypeError:
|
except TypeError:
|
||||||
pass
|
pass
|
||||||
for x in self.feature:
|
for x in self.feature:
|
||||||
|
@ -1083,11 +1089,6 @@ ext_modules = [
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
# parse configuration from _custom_build/backend.py
|
|
||||||
while sys.argv[-1].startswith("--pillow-configuration="):
|
|
||||||
_, key, value = sys.argv.pop().split("=", 2)
|
|
||||||
configuration.setdefault(key, []).append(value)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
setup(
|
setup(
|
||||||
cmdclass={"build_ext": pil_build_ext},
|
cmdclass={"build_ext": pil_build_ext},
|
||||||
|
|
|
@ -31,7 +31,7 @@ import os
|
||||||
import subprocess
|
import subprocess
|
||||||
from enum import IntEnum
|
from enum import IntEnum
|
||||||
from functools import cached_property
|
from functools import cached_property
|
||||||
from typing import IO, Any, Literal, NamedTuple, Union, cast
|
from typing import Any, NamedTuple, cast
|
||||||
|
|
||||||
from . import (
|
from . import (
|
||||||
Image,
|
Image,
|
||||||
|
@ -49,6 +49,8 @@ from ._util import DeferredError
|
||||||
|
|
||||||
TYPE_CHECKING = False
|
TYPE_CHECKING = False
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
from typing import IO, Literal
|
||||||
|
|
||||||
from . import _imaging
|
from . import _imaging
|
||||||
from ._typing import Buffer
|
from ._typing import Buffer
|
||||||
|
|
||||||
|
@ -535,7 +537,7 @@ def _normalize_mode(im: Image.Image) -> Image.Image:
|
||||||
return im.convert("L")
|
return im.convert("L")
|
||||||
|
|
||||||
|
|
||||||
_Palette = Union[bytes, bytearray, list[int], ImagePalette.ImagePalette]
|
_Palette = bytes | bytearray | list[int] | ImagePalette.ImagePalette
|
||||||
|
|
||||||
|
|
||||||
def _normalize_palette(
|
def _normalize_palette(
|
||||||
|
|
|
@ -21,10 +21,14 @@ See the GIMP distribution for more information.)
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from math import log, pi, sin, sqrt
|
from math import log, pi, sin, sqrt
|
||||||
from typing import IO, Callable
|
|
||||||
|
|
||||||
from ._binary import o8
|
from ._binary import o8
|
||||||
|
|
||||||
|
TYPE_CHECKING = False
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Callable
|
||||||
|
from typing import IO
|
||||||
|
|
||||||
EPSILON = 1e-10
|
EPSILON = 1e-10
|
||||||
"""""" # Enable auto-doc for data member
|
"""""" # Enable auto-doc for data member
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,9 @@ from __future__ import annotations
|
||||||
|
|
||||||
import re
|
import re
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
|
TYPE_CHECKING = False
|
||||||
|
if TYPE_CHECKING:
|
||||||
from typing import IO
|
from typing import IO
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -38,10 +38,9 @@ import struct
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import warnings
|
import warnings
|
||||||
from collections.abc import Callable, Iterator, MutableMapping, Sequence
|
from collections.abc import MutableMapping
|
||||||
from enum import IntEnum
|
from enum import IntEnum
|
||||||
from types import ModuleType
|
from typing import IO, Protocol, cast
|
||||||
from typing import IO, Any, Literal, Protocol, cast
|
|
||||||
|
|
||||||
# VERSION was removed in Pillow 6.0.0.
|
# VERSION was removed in Pillow 6.0.0.
|
||||||
# PILLOW_VERSION was removed in Pillow 9.0.0.
|
# PILLOW_VERSION was removed in Pillow 9.0.0.
|
||||||
|
@ -64,6 +63,12 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
ElementTree = None
|
ElementTree = None
|
||||||
|
|
||||||
|
TYPE_CHECKING = False
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Callable, Iterator, Sequence
|
||||||
|
from types import ModuleType
|
||||||
|
from typing import Any, Literal
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1732,7 +1737,8 @@ class Image:
|
||||||
Instead of an image, the source can be a integer or tuple
|
Instead of an image, the source can be a integer or tuple
|
||||||
containing pixel values. The method then fills the region
|
containing pixel values. The method then fills the region
|
||||||
with the given color. When creating RGB images, you can
|
with the given color. When creating RGB images, you can
|
||||||
also use color strings as supported by the ImageColor module.
|
also use color strings as supported by the ImageColor module. See
|
||||||
|
:ref:`colors` for more information.
|
||||||
|
|
||||||
If a mask is given, this method updates only the regions
|
If a mask is given, this method updates only the regions
|
||||||
indicated by the mask. You can use either "1", "L", "LA", "RGBA"
|
indicated by the mask. You can use either "1", "L", "LA", "RGBA"
|
||||||
|
@ -1988,7 +1994,8 @@ class Image:
|
||||||
sequence ends. The scale and offset values are used to adjust the
|
sequence ends. The scale and offset values are used to adjust the
|
||||||
sequence values: **pixel = value*scale + offset**.
|
sequence values: **pixel = value*scale + offset**.
|
||||||
|
|
||||||
:param data: A flattened sequence object.
|
:param data: A flattened sequence object. See :ref:`colors` for more
|
||||||
|
information about values.
|
||||||
:param scale: An optional scale value. The default is 1.0.
|
:param scale: An optional scale value. The default is 1.0.
|
||||||
:param offset: An optional offset value. The default is 0.0.
|
:param offset: An optional offset value. The default is 0.0.
|
||||||
"""
|
"""
|
||||||
|
@ -2047,7 +2054,7 @@ class Image:
|
||||||
Modifies the pixel at the given position. The color is given as
|
Modifies the pixel at the given position. The color is given as
|
||||||
a single numerical value for single-band images, and a tuple for
|
a single numerical value for single-band images, and a tuple for
|
||||||
multi-band images. In addition to this, RGB and RGBA tuples are
|
multi-band images. In addition to this, RGB and RGBA tuples are
|
||||||
accepted for P and PA images.
|
accepted for P and PA images. See :ref:`colors` for more information.
|
||||||
|
|
||||||
Note that this method is relatively slow. For more extensive changes,
|
Note that this method is relatively slow. For more extensive changes,
|
||||||
use :py:meth:`~PIL.Image.Image.paste` or the :py:mod:`~PIL.ImageDraw`
|
use :py:meth:`~PIL.Image.Image.paste` or the :py:mod:`~PIL.ImageDraw`
|
||||||
|
@ -3055,12 +3062,12 @@ def new(
|
||||||
:param mode: The mode to use for the new image. See:
|
:param mode: The mode to use for the new image. See:
|
||||||
:ref:`concept-modes`.
|
:ref:`concept-modes`.
|
||||||
:param size: A 2-tuple, containing (width, height) in pixels.
|
:param size: A 2-tuple, containing (width, height) in pixels.
|
||||||
:param color: What color to use for the image. Default is black.
|
:param color: What color to use for the image. Default is black. If given,
|
||||||
If given, this should be a single integer or floating point value
|
this should be a single integer or floating point value for single-band
|
||||||
for single-band modes, and a tuple for multi-band modes (one value
|
modes, and a tuple for multi-band modes (one value per band). When
|
||||||
per band). When creating RGB or HSV images, you can also use color
|
creating RGB or HSV images, you can also use color strings as supported
|
||||||
strings as supported by the ImageColor module. If the color is
|
by the ImageColor module. See :ref:`colors` for more information. If the
|
||||||
None, the image is not initialised.
|
color is None, the image is not initialised.
|
||||||
:returns: An :py:class:`~PIL.Image.Image` object.
|
:returns: An :py:class:`~PIL.Image.Image` object.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
|
@ -23,9 +23,10 @@ import operator
|
||||||
import sys
|
import sys
|
||||||
from enum import IntEnum, IntFlag
|
from enum import IntEnum, IntFlag
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
from typing import Literal, SupportsFloat, SupportsInt, Union
|
from typing import Any, Literal, SupportsFloat, SupportsInt, Union
|
||||||
|
|
||||||
from . import Image
|
from . import Image
|
||||||
|
from ._deprecate import deprecate
|
||||||
from ._typing import SupportsRead
|
from ._typing import SupportsRead
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -233,9 +234,7 @@ class ImageCmsProfile:
|
||||||
low-level profile object
|
low-level profile object
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.filename = None
|
self.filename: str | None = None
|
||||||
self.product_name = None # profile.product_name
|
|
||||||
self.product_info = None # profile.product_info
|
|
||||||
|
|
||||||
if isinstance(profile, str):
|
if isinstance(profile, str):
|
||||||
if sys.platform == "win32":
|
if sys.platform == "win32":
|
||||||
|
@ -256,6 +255,13 @@ class ImageCmsProfile:
|
||||||
msg = "Invalid type for Profile" # type: ignore[unreachable]
|
msg = "Invalid type for Profile" # type: ignore[unreachable]
|
||||||
raise TypeError(msg)
|
raise TypeError(msg)
|
||||||
|
|
||||||
|
def __getattr__(self, name: str) -> Any:
|
||||||
|
if name in ("product_name", "product_info"):
|
||||||
|
deprecate(f"ImageCms.ImageCmsProfile.{name}", 13)
|
||||||
|
return None
|
||||||
|
msg = f"'{self.__class__.__name__}' object has no attribute '{name}'"
|
||||||
|
raise AttributeError(msg)
|
||||||
|
|
||||||
def tobytes(self) -> bytes:
|
def tobytes(self) -> bytes:
|
||||||
"""
|
"""
|
||||||
Returns the profile in a format suitable for embedding in
|
Returns the profile in a format suitable for embedding in
|
||||||
|
|
|
@ -34,20 +34,23 @@ from __future__ import annotations
|
||||||
import math
|
import math
|
||||||
import struct
|
import struct
|
||||||
from collections.abc import Sequence
|
from collections.abc import Sequence
|
||||||
from types import ModuleType
|
from typing import cast
|
||||||
from typing import Any, AnyStr, Callable, Union, cast
|
|
||||||
|
|
||||||
from . import Image, ImageColor
|
from . import Image, ImageColor
|
||||||
|
|
||||||
|
TYPE_CHECKING = False
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Callable
|
||||||
|
from types import ModuleType
|
||||||
|
from typing import Any, AnyStr
|
||||||
|
|
||||||
|
from . import ImageDraw2, ImageFont
|
||||||
from ._typing import Coords
|
from ._typing import Coords
|
||||||
|
|
||||||
# experimental access to the outline API
|
# experimental access to the outline API
|
||||||
Outline: Callable[[], Image.core._Outline] = Image.core.outline
|
Outline: Callable[[], Image.core._Outline] = Image.core.outline
|
||||||
|
|
||||||
TYPE_CHECKING = False
|
_Ink = float | tuple[int, ...] | str
|
||||||
if TYPE_CHECKING:
|
|
||||||
from . import ImageDraw2, ImageFont
|
|
||||||
|
|
||||||
_Ink = Union[float, tuple[int, ...], str]
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
A simple 2D drawing interface for PIL images.
|
A simple 2D drawing interface for PIL images.
|
||||||
|
|
|
@ -19,11 +19,14 @@ from __future__ import annotations
|
||||||
import abc
|
import abc
|
||||||
import functools
|
import functools
|
||||||
from collections.abc import Sequence
|
from collections.abc import Sequence
|
||||||
from types import ModuleType
|
from typing import cast
|
||||||
from typing import Any, Callable, cast
|
|
||||||
|
|
||||||
TYPE_CHECKING = False
|
TYPE_CHECKING = False
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Callable
|
||||||
|
from types import ModuleType
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from . import _imaging
|
from . import _imaging
|
||||||
from ._typing import NumpyArray
|
from ._typing import NumpyArray
|
||||||
|
|
||||||
|
|
|
@ -17,11 +17,15 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import builtins
|
import builtins
|
||||||
from types import CodeType
|
|
||||||
from typing import Any, Callable
|
|
||||||
|
|
||||||
from . import Image, _imagingmath
|
from . import Image, _imagingmath
|
||||||
|
|
||||||
|
TYPE_CHECKING = False
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Callable
|
||||||
|
from types import CodeType
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
class _Operand:
|
class _Operand:
|
||||||
"""Wraps an image operand, providing standard operators"""
|
"""Wraps an image operand, providing standard operators"""
|
||||||
|
|
|
@ -19,23 +19,18 @@ from __future__ import annotations
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from typing import Any, Callable, Union
|
|
||||||
|
|
||||||
from . import Image
|
from . import Image
|
||||||
from ._util import is_path
|
from ._util import is_path
|
||||||
|
|
||||||
TYPE_CHECKING = False
|
TYPE_CHECKING = False
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
import PyQt6
|
from collections.abc import Callable
|
||||||
import PySide6
|
from typing import Any
|
||||||
|
|
||||||
from . import ImageFile
|
from . import ImageFile
|
||||||
|
|
||||||
QBuffer: type
|
QBuffer: type
|
||||||
QByteArray = Union[PyQt6.QtCore.QByteArray, PySide6.QtCore.QByteArray]
|
|
||||||
QIODevice = Union[PyQt6.QtCore.QIODevice, PySide6.QtCore.QIODevice]
|
|
||||||
QImage = Union[PyQt6.QtGui.QImage, PySide6.QtGui.QImage]
|
|
||||||
QPixmap = Union[PyQt6.QtGui.QPixmap, PySide6.QtGui.QPixmap]
|
|
||||||
|
|
||||||
qt_version: str | None
|
qt_version: str | None
|
||||||
qt_versions = [
|
qt_versions = [
|
||||||
|
@ -49,11 +44,15 @@ for version, qt_module in qt_versions:
|
||||||
try:
|
try:
|
||||||
qRgba: Callable[[int, int, int, int], int]
|
qRgba: Callable[[int, int, int, int], int]
|
||||||
if qt_module == "PyQt6":
|
if qt_module == "PyQt6":
|
||||||
from PyQt6.QtCore import QBuffer, QIODevice
|
from PyQt6.QtCore import QBuffer, QByteArray, QIODevice
|
||||||
from PyQt6.QtGui import QImage, QPixmap, qRgba
|
from PyQt6.QtGui import QImage, QPixmap, qRgba
|
||||||
elif qt_module == "PySide6":
|
elif qt_module == "PySide6":
|
||||||
from PySide6.QtCore import QBuffer, QIODevice
|
from PySide6.QtCore import ( # type: ignore[assignment]
|
||||||
from PySide6.QtGui import QImage, QPixmap, qRgba
|
QBuffer,
|
||||||
|
QByteArray,
|
||||||
|
QIODevice,
|
||||||
|
)
|
||||||
|
from PySide6.QtGui import QImage, QPixmap, qRgba # type: ignore[assignment]
|
||||||
except (ImportError, RuntimeError):
|
except (ImportError, RuntimeError):
|
||||||
continue
|
continue
|
||||||
qt_is_installed = True
|
qt_is_installed = True
|
||||||
|
@ -183,7 +182,7 @@ def _toqclass_helper(im: Image.Image | str | QByteArray) -> dict[str, Any]:
|
||||||
|
|
||||||
if qt_is_installed:
|
if qt_is_installed:
|
||||||
|
|
||||||
class ImageQt(QImage): # type: ignore[misc]
|
class ImageQt(QImage):
|
||||||
def __init__(self, im: Image.Image | str | QByteArray) -> None:
|
def __init__(self, im: Image.Image | str | QByteArray) -> None:
|
||||||
"""
|
"""
|
||||||
An PIL image wrapper for Qt. This is a subclass of PyQt's QImage
|
An PIL image wrapper for Qt. This is a subclass of PyQt's QImage
|
||||||
|
|
|
@ -16,10 +16,12 @@
|
||||||
##
|
##
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Callable
|
|
||||||
|
|
||||||
from . import Image
|
from . import Image
|
||||||
|
|
||||||
|
TYPE_CHECKING = False
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Callable
|
||||||
|
|
||||||
|
|
||||||
class Iterator:
|
class Iterator:
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -18,11 +18,15 @@ from __future__ import annotations
|
||||||
import io
|
import io
|
||||||
import os
|
import os
|
||||||
import struct
|
import struct
|
||||||
from collections.abc import Callable
|
from typing import cast
|
||||||
from typing import IO, cast
|
|
||||||
|
|
||||||
from . import Image, ImageFile, ImagePalette, _binary
|
from . import Image, ImageFile, ImagePalette, _binary
|
||||||
|
|
||||||
|
TYPE_CHECKING = False
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Callable
|
||||||
|
from typing import IO
|
||||||
|
|
||||||
|
|
||||||
class BoxReader:
|
class BoxReader:
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -42,7 +42,6 @@ import subprocess
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import warnings
|
import warnings
|
||||||
from typing import IO, Any
|
|
||||||
|
|
||||||
from . import Image, ImageFile
|
from . import Image, ImageFile
|
||||||
from ._binary import i16be as i16
|
from ._binary import i16be as i16
|
||||||
|
@ -53,6 +52,8 @@ from .JpegPresets import presets
|
||||||
|
|
||||||
TYPE_CHECKING = False
|
TYPE_CHECKING = False
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
from typing import IO, Any
|
||||||
|
|
||||||
from .MpoImagePlugin import MpoImageFile
|
from .MpoImagePlugin import MpoImageFile
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -845,16 +846,6 @@ def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _save_cjpeg(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
|
|
||||||
# ALTERNATIVE: handle JPEGs via the IJG command line utilities.
|
|
||||||
tempfile = im._dump()
|
|
||||||
subprocess.check_call(["cjpeg", "-outfile", filename, tempfile])
|
|
||||||
try:
|
|
||||||
os.unlink(tempfile)
|
|
||||||
except OSError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Factory for making JPEG and MPO instances
|
# Factory for making JPEG and MPO instances
|
||||||
def jpeg_factory(
|
def jpeg_factory(
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import io
|
import io
|
||||||
from typing import BinaryIO, Callable
|
|
||||||
|
|
||||||
from . import FontFile, Image
|
from . import FontFile, Image
|
||||||
from ._binary import i8
|
from ._binary import i8
|
||||||
|
@ -27,6 +26,11 @@ from ._binary import i16le as l16
|
||||||
from ._binary import i32be as b32
|
from ._binary import i32be as b32
|
||||||
from ._binary import i32le as l32
|
from ._binary import i32le as l32
|
||||||
|
|
||||||
|
TYPE_CHECKING = False
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Callable
|
||||||
|
from typing import BinaryIO
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
# declarations
|
# declarations
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,15 @@ import os
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
import zlib
|
import zlib
|
||||||
from typing import IO, Any, NamedTuple, Union
|
from typing import Any, NamedTuple
|
||||||
|
|
||||||
|
TYPE_CHECKING = False
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from typing import IO
|
||||||
|
|
||||||
|
_DictBase = collections.UserDict[str | bytes, Any]
|
||||||
|
else:
|
||||||
|
_DictBase = collections.UserDict
|
||||||
|
|
||||||
|
|
||||||
# see 7.9.2.2 Text String Type on page 86 and D.3 PDFDocEncoding Character Set
|
# see 7.9.2.2 Text String Type on page 86 and D.3 PDFDocEncoding Character Set
|
||||||
|
@ -251,13 +259,6 @@ class PdfArray(list[Any]):
|
||||||
return b"[ " + b" ".join(pdf_repr(x) for x in self) + b" ]"
|
return b"[ " + b" ".join(pdf_repr(x) for x in self) + b" ]"
|
||||||
|
|
||||||
|
|
||||||
TYPE_CHECKING = False
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
_DictBase = collections.UserDict[Union[str, bytes], Any]
|
|
||||||
else:
|
|
||||||
_DictBase = collections.UserDict
|
|
||||||
|
|
||||||
|
|
||||||
class PdfDict(_DictBase):
|
class PdfDict(_DictBase):
|
||||||
def __setattr__(self, key: str, value: Any) -> None:
|
def __setattr__(self, key: str, value: Any) -> None:
|
||||||
if key == "data":
|
if key == "data":
|
||||||
|
|
|
@ -38,9 +38,8 @@ import re
|
||||||
import struct
|
import struct
|
||||||
import warnings
|
import warnings
|
||||||
import zlib
|
import zlib
|
||||||
from collections.abc import Callable
|
|
||||||
from enum import IntEnum
|
from enum import IntEnum
|
||||||
from typing import IO, Any, NamedTuple, NoReturn, cast
|
from typing import IO, NamedTuple, cast
|
||||||
|
|
||||||
from . import Image, ImageChops, ImageFile, ImagePalette, ImageSequence
|
from . import Image, ImageChops, ImageFile, ImagePalette, ImageSequence
|
||||||
from ._binary import i16be as i16
|
from ._binary import i16be as i16
|
||||||
|
@ -53,6 +52,9 @@ from ._util import DeferredError
|
||||||
|
|
||||||
TYPE_CHECKING = False
|
TYPE_CHECKING = False
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Callable
|
||||||
|
from typing import Any, NoReturn
|
||||||
|
|
||||||
from . import _imaging
|
from . import _imaging
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
|
@ -47,22 +47,24 @@ import math
|
||||||
import os
|
import os
|
||||||
import struct
|
import struct
|
||||||
import warnings
|
import warnings
|
||||||
from collections.abc import Iterator, MutableMapping
|
from collections.abc import Callable, MutableMapping
|
||||||
from fractions import Fraction
|
from fractions import Fraction
|
||||||
from numbers import Number, Rational
|
from numbers import Number, Rational
|
||||||
from typing import IO, Any, Callable, NoReturn, cast
|
from typing import IO, Any, cast
|
||||||
|
|
||||||
from . import ExifTags, Image, ImageFile, ImageOps, ImagePalette, TiffTags
|
from . import ExifTags, Image, ImageFile, ImageOps, ImagePalette, TiffTags
|
||||||
from ._binary import i16be as i16
|
from ._binary import i16be as i16
|
||||||
from ._binary import i32be as i32
|
from ._binary import i32be as i32
|
||||||
from ._binary import o8
|
from ._binary import o8
|
||||||
from ._typing import StrOrBytesPath
|
|
||||||
from ._util import DeferredError, is_path
|
from ._util import DeferredError, is_path
|
||||||
from .TiffTags import TYPES
|
from .TiffTags import TYPES
|
||||||
|
|
||||||
TYPE_CHECKING = False
|
TYPE_CHECKING = False
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from ._typing import Buffer, IntegralLike
|
from collections.abc import Iterator
|
||||||
|
from typing import NoReturn
|
||||||
|
|
||||||
|
from ._typing import Buffer, IntegralLike, StrOrBytesPath
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from typing import IO, Any
|
|
||||||
|
|
||||||
from . import Image, ImageFile
|
from . import Image, ImageFile
|
||||||
|
|
||||||
|
@ -12,6 +11,9 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
SUPPORTED = False
|
SUPPORTED = False
|
||||||
|
|
||||||
|
TYPE_CHECKING = False
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from typing import IO, Any
|
||||||
|
|
||||||
_VP8_MODES_BY_IDENTIFIER = {
|
_VP8_MODES_BY_IDENTIFIER = {
|
||||||
b"VP8 ": "RGB",
|
b"VP8 ": "RGB",
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
import datetime
|
import datetime
|
||||||
import sys
|
import sys
|
||||||
from typing import Literal, SupportsFloat, TypedDict
|
from typing import Literal, SupportsFloat, TypeAlias, TypedDict
|
||||||
|
|
||||||
from ._typing import CapsuleType
|
from ._typing import CapsuleType
|
||||||
|
|
||||||
littlecms_version: str | None
|
littlecms_version: str | None
|
||||||
|
|
||||||
_Tuple3f = tuple[float, float, float]
|
_Tuple3f: TypeAlias = tuple[float, float, float]
|
||||||
_Tuple2x3f = tuple[_Tuple3f, _Tuple3f]
|
_Tuple2x3f: TypeAlias = tuple[_Tuple3f, _Tuple3f]
|
||||||
_Tuple3x3f = tuple[_Tuple3f, _Tuple3f, _Tuple3f]
|
_Tuple3x3f: TypeAlias = tuple[_Tuple3f, _Tuple3f, _Tuple3f]
|
||||||
|
|
||||||
class _IccMeasurementCondition(TypedDict):
|
class _IccMeasurementCondition(TypedDict):
|
||||||
observer: int
|
observer: int
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from typing import Any, Callable
|
from collections.abc import Callable
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from . import ImageFont, _imaging
|
from . import ImageFont, _imaging
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from collections.abc import Sequence
|
from collections.abc import Sequence
|
||||||
from typing import Any, Protocol, TypeVar, Union
|
from typing import Any, Protocol, TypeVar
|
||||||
|
|
||||||
TYPE_CHECKING = False
|
TYPE_CHECKING = False
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
@ -12,8 +12,8 @@ if TYPE_CHECKING:
|
||||||
try:
|
try:
|
||||||
import numpy.typing as npt
|
import numpy.typing as npt
|
||||||
|
|
||||||
NumpyArray = npt.NDArray[Any] # requires numpy>=1.21
|
NumpyArray = npt.NDArray[Any]
|
||||||
except (ImportError, AttributeError):
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if sys.version_info >= (3, 13):
|
if sys.version_info >= (3, 13):
|
||||||
|
@ -26,19 +26,8 @@ if sys.version_info >= (3, 12):
|
||||||
else:
|
else:
|
||||||
Buffer = Any
|
Buffer = Any
|
||||||
|
|
||||||
if sys.version_info >= (3, 10):
|
|
||||||
from typing import TypeGuard
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
from typing_extensions import TypeGuard
|
|
||||||
except ImportError:
|
|
||||||
|
|
||||||
class TypeGuard: # type: ignore[no-redef]
|
Coords = Sequence[float] | Sequence[Sequence[float]]
|
||||||
def __class_getitem__(cls, item: Any) -> type[bool]:
|
|
||||||
return bool
|
|
||||||
|
|
||||||
|
|
||||||
Coords = Union[Sequence[float], Sequence[Sequence[float]]]
|
|
||||||
|
|
||||||
|
|
||||||
_T_co = TypeVar("_T_co", covariant=True)
|
_T_co = TypeVar("_T_co", covariant=True)
|
||||||
|
@ -48,7 +37,7 @@ class SupportsRead(Protocol[_T_co]):
|
||||||
def read(self, length: int = ..., /) -> _T_co: ...
|
def read(self, length: int = ..., /) -> _T_co: ...
|
||||||
|
|
||||||
|
|
||||||
StrOrBytesPath = Union[str, bytes, os.PathLike[str], os.PathLike[bytes]]
|
StrOrBytesPath = str | bytes | os.PathLike[str] | os.PathLike[bytes]
|
||||||
|
|
||||||
|
|
||||||
__all__ = ["Buffer", "IntegralLike", "StrOrBytesPath", "SupportsRead", "TypeGuard"]
|
__all__ = ["Buffer", "IntegralLike", "StrOrBytesPath", "SupportsRead"]
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from typing import Any, NoReturn
|
|
||||||
|
|
||||||
from ._typing import StrOrBytesPath, TypeGuard
|
TYPE_CHECKING = False
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from typing import Any, NoReturn, TypeGuard
|
||||||
|
|
||||||
|
from ._typing import StrOrBytesPath
|
||||||
|
|
||||||
|
|
||||||
def is_path(f: Any) -> TypeGuard[StrOrBytesPath]:
|
def is_path(f: Any) -> TypeGuard[StrOrBytesPath]:
|
||||||
|
|
|
@ -9,7 +9,6 @@ from typing import IO
|
||||||
import PIL
|
import PIL
|
||||||
|
|
||||||
from . import Image
|
from . import Image
|
||||||
from ._deprecate import deprecate
|
|
||||||
|
|
||||||
modules = {
|
modules = {
|
||||||
"pil": ("PIL._imaging", "PILLOW_VERSION"),
|
"pil": ("PIL._imaging", "PILLOW_VERSION"),
|
||||||
|
@ -120,7 +119,7 @@ def get_supported_codecs() -> list[str]:
|
||||||
return [f for f in codecs if check_codec(f)]
|
return [f for f in codecs if check_codec(f)]
|
||||||
|
|
||||||
|
|
||||||
features: dict[str, tuple[str, str | bool, str | None]] = {
|
features: dict[str, tuple[str, str, str | None]] = {
|
||||||
"raqm": ("PIL._imagingft", "HAVE_RAQM", "raqm_version"),
|
"raqm": ("PIL._imagingft", "HAVE_RAQM", "raqm_version"),
|
||||||
"fribidi": ("PIL._imagingft", "HAVE_FRIBIDI", "fribidi_version"),
|
"fribidi": ("PIL._imagingft", "HAVE_FRIBIDI", "fribidi_version"),
|
||||||
"harfbuzz": ("PIL._imagingft", "HAVE_HARFBUZZ", "harfbuzz_version"),
|
"harfbuzz": ("PIL._imagingft", "HAVE_HARFBUZZ", "harfbuzz_version"),
|
||||||
|
@ -146,12 +145,8 @@ def check_feature(feature: str) -> bool | None:
|
||||||
|
|
||||||
module, flag, ver = features[feature]
|
module, flag, ver = features[feature]
|
||||||
|
|
||||||
if isinstance(flag, bool):
|
|
||||||
deprecate(f'check_feature("{feature}")', 12)
|
|
||||||
try:
|
try:
|
||||||
imported_module = __import__(module, fromlist=["PIL"])
|
imported_module = __import__(module, fromlist=["PIL"])
|
||||||
if isinstance(flag, bool):
|
|
||||||
return flag
|
|
||||||
return getattr(imported_module, flag)
|
return getattr(imported_module, flag)
|
||||||
except ModuleNotFoundError:
|
except ModuleNotFoundError:
|
||||||
return None
|
return None
|
||||||
|
@ -181,17 +176,7 @@ def get_supported_features() -> list[str]:
|
||||||
"""
|
"""
|
||||||
:returns: A list of all supported features.
|
:returns: A list of all supported features.
|
||||||
"""
|
"""
|
||||||
supported_features = []
|
return [f for f in features if check_feature(f)]
|
||||||
for f, (module, flag, _) in features.items():
|
|
||||||
if flag is True:
|
|
||||||
for feature, (feature_module, _) in modules.items():
|
|
||||||
if feature_module == module:
|
|
||||||
if check_module(feature):
|
|
||||||
supported_features.append(f)
|
|
||||||
break
|
|
||||||
elif check_feature(f):
|
|
||||||
supported_features.append(f)
|
|
||||||
return supported_features
|
|
||||||
|
|
||||||
|
|
||||||
def check(feature: str) -> bool | None:
|
def check(feature: str) -> bool | None:
|
||||||
|
|
|
@ -132,11 +132,15 @@ ImagingGetHistogram(Imaging im, Imaging imMask, void *minmax) {
|
||||||
ImagingSectionEnter(&cookie);
|
ImagingSectionEnter(&cookie);
|
||||||
for (y = 0; y < im->ysize; y++) {
|
for (y = 0; y < im->ysize; y++) {
|
||||||
UINT8 *in = (UINT8 *)im->image[y];
|
UINT8 *in = (UINT8 *)im->image[y];
|
||||||
for (x = 0; x < im->xsize; x++) {
|
for (x = 0; x < im->xsize; x++, in += 4) {
|
||||||
h->histogram[(*in++)]++;
|
h->histogram[*in]++;
|
||||||
h->histogram[(*in++) + 256]++;
|
if (im->bands == 2) {
|
||||||
h->histogram[(*in++) + 512]++;
|
h->histogram[*(in + 3) + 256]++;
|
||||||
h->histogram[(*in++) + 768]++;
|
} else {
|
||||||
|
h->histogram[*(in + 1) + 256]++;
|
||||||
|
h->histogram[*(in + 2) + 512]++;
|
||||||
|
h->histogram[*(in + 3) + 768]++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ImagingSectionLeave(&cookie);
|
ImagingSectionLeave(&cookie);
|
||||||
|
|
4
tox.ini
4
tox.ini
|
@ -3,7 +3,7 @@ requires =
|
||||||
tox>=4.2
|
tox>=4.2
|
||||||
env_list =
|
env_list =
|
||||||
lint
|
lint
|
||||||
py{py3, 314, 313, 312, 311, 310, 39}
|
py{py3, 314, 313, 312, 311, 310}
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
deps =
|
deps =
|
||||||
|
@ -29,7 +29,5 @@ commands =
|
||||||
skip_install = true
|
skip_install = true
|
||||||
deps =
|
deps =
|
||||||
-r .ci/requirements-mypy.txt
|
-r .ci/requirements-mypy.txt
|
||||||
extras =
|
|
||||||
typing
|
|
||||||
commands =
|
commands =
|
||||||
mypy conftest.py selftest.py setup.py docs src winbuild Tests {posargs}
|
mypy conftest.py selftest.py setup.py docs src winbuild Tests {posargs}
|
||||||
|
|
|
@ -121,8 +121,8 @@ V = {
|
||||||
"LCMS2": "2.17",
|
"LCMS2": "2.17",
|
||||||
"LIBAVIF": "1.3.0",
|
"LIBAVIF": "1.3.0",
|
||||||
"LIBIMAGEQUANT": "4.3.4",
|
"LIBIMAGEQUANT": "4.3.4",
|
||||||
"LIBPNG": "1.6.49",
|
"LIBPNG": "1.6.50",
|
||||||
"LIBWEBP": "1.5.0",
|
"LIBWEBP": "1.6.0",
|
||||||
"OPENJPEG": "2.5.3",
|
"OPENJPEG": "2.5.3",
|
||||||
"TIFF": "4.7.0",
|
"TIFF": "4.7.0",
|
||||||
"XZ": "5.8.1",
|
"XZ": "5.8.1",
|
||||||
|
@ -149,18 +149,17 @@ DEPS: dict[str, dict[str, Any]] = {
|
||||||
},
|
},
|
||||||
"build": [
|
"build": [
|
||||||
*cmds_cmake(
|
*cmds_cmake(
|
||||||
("jpeg-static", "cjpeg-static", "djpeg-static"),
|
("jpeg-static", "djpeg-static"),
|
||||||
"-DENABLE_SHARED:BOOL=FALSE",
|
"-DENABLE_SHARED:BOOL=FALSE",
|
||||||
"-DWITH_JPEG8:BOOL=TRUE",
|
"-DWITH_JPEG8:BOOL=TRUE",
|
||||||
"-DWITH_CRT_DLL:BOOL=TRUE",
|
"-DWITH_CRT_DLL:BOOL=TRUE",
|
||||||
),
|
),
|
||||||
cmd_copy("jpeg-static.lib", "libjpeg.lib"),
|
cmd_copy("jpeg-static.lib", "libjpeg.lib"),
|
||||||
cmd_copy("cjpeg-static.exe", "cjpeg.exe"),
|
|
||||||
cmd_copy("djpeg-static.exe", "djpeg.exe"),
|
cmd_copy("djpeg-static.exe", "djpeg.exe"),
|
||||||
],
|
],
|
||||||
"headers": ["jconfig.h", r"src\j*.h"],
|
"headers": ["jconfig.h", r"src\j*.h"],
|
||||||
"libs": ["libjpeg.lib"],
|
"libs": ["libjpeg.lib"],
|
||||||
"bins": ["cjpeg.exe", "djpeg.exe"],
|
"bins": ["djpeg.exe"],
|
||||||
},
|
},
|
||||||
"zlib": {
|
"zlib": {
|
||||||
"url": f"https://github.com/zlib-ng/zlib-ng/archive/refs/tags/{V['ZLIBNG']}.tar.gz",
|
"url": f"https://github.com/zlib-ng/zlib-ng/archive/refs/tags/{V['ZLIBNG']}.tar.gz",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user