diff --git a/.appveyor.yml b/.appveyor.yml
index 60132a9a3..cc4d56d0b 100644
--- a/.appveyor.yml
+++ b/.appveyor.yml
@@ -21,13 +21,11 @@ environment:
install:
- '%PYTHON%\%EXECUTABLE% --version'
- '%PYTHON%\%EXECUTABLE% -m pip install --upgrade pip'
-- curl -fsSL -o pillow-depends.zip https://github.com/python-pillow/pillow-depends/archive/main.zip
- curl -fsSL -o pillow-test-images.zip https://github.com/python-pillow/test-images/archive/main.zip
-- 7z x pillow-depends.zip -oc:\
- 7z x pillow-test-images.zip -oc:\
-- mv c:\pillow-depends-main c:\pillow-depends
- xcopy /S /Y c:\test-images-main\* c:\pillow\tests\images
-- 7z x ..\pillow-depends\nasm-2.16.01-win64.zip -oc:\
+- curl -fsSL -o nasm-win64.zip https://raw.githubusercontent.com/python-pillow/pillow-depends/main/nasm-2.16.01-win64.zip
+- 7z x nasm-win64.zip -oc:\
- choco install ghostscript --version=10.0.0.20230317
- path c:\nasm-2.16.01;C:\Program Files\gs\gs10.00.0\bin;%PATH%
- cd c:\pillow\winbuild\
diff --git a/.ci/install.sh b/.ci/install.sh
index 6e87d386d..4748feb3d 100755
--- a/.ci/install.sh
+++ b/.ci/install.sh
@@ -23,7 +23,7 @@ if [[ $(uname) != CYGWIN* ]]; then
sudo apt-get -qq install libfreetype6-dev liblcms2-dev python3-tk\
ghostscript libffi-dev libjpeg-turbo-progs libopenjp2-7-dev\
cmake meson imagemagick libharfbuzz-dev libfribidi-dev\
- sway wl-clipboard
+ sway wl-clipboard libopenblas-dev
fi
python3 -m pip install --upgrade pip
@@ -38,11 +38,10 @@ python3 -m pip install -U pytest-timeout
python3 -m pip install pyroma
if [[ $(uname) != CYGWIN* ]]; then
- # TODO Remove condition when NumPy supports 3.12
- if ! [ "$GHA_PYTHON_VERSION" == "3.12-dev" ]; then python3 -m pip install numpy ; fi
+ python3 -m pip install numpy
# PyQt6 doesn't support PyPy3
- if [[ "$GHA_PYTHON_VERSION" != "3.12-dev" && $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
python3 -m pip install pyqt6
fi
diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml
index 81ba8ef15..844c7c1ec 100644
--- a/.github/workflows/docs.yml
+++ b/.github/workflows/docs.yml
@@ -28,7 +28,7 @@ jobs:
name: Docs
steps:
- - uses: actions/checkout@v3
+ - uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
index 49611e287..78b80d26e 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -17,7 +17,7 @@ jobs:
name: Lint
steps:
- - uses: actions/checkout@v3
+ - uses: actions/checkout@v4
- name: pre-commit cache
uses: actions/cache@v3
diff --git a/.github/workflows/macos-install.sh b/.github/workflows/macos-install.sh
index 1fc6262f4..a20838a15 100755
--- a/.github/workflows/macos-install.sh
+++ b/.github/workflows/macos-install.sh
@@ -3,6 +3,7 @@
set -e
brew install libtiff libjpeg openjpeg libimagequant webp little-cms2 freetype libraqm
+export PKG_CONFIG_PATH="/usr/local/opt/openblas/lib/pkgconfig"
PYTHONOPTIMIZE=0 python3 -m pip install cffi
python3 -m pip install coverage
@@ -13,8 +14,7 @@ python3 -m pip install -U pytest-cov
python3 -m pip install -U pytest-timeout
python3 -m pip install pyroma
-# TODO Remove condition when NumPy supports 3.12
-if ! [ "$GHA_PYTHON_VERSION" == "3.12-dev" ]; then python3 -m pip install numpy ; fi
+python3 -m pip install numpy
# extra test images
pushd depends && ./install_extra_test_images.sh && popd
diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml
index 9e2fdc096..8fc7bd379 100644
--- a/.github/workflows/release-drafter.yml
+++ b/.github/workflows/release-drafter.yml
@@ -10,7 +10,7 @@ on:
permissions:
contents: read
-concurrency:
+concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml
index 24b8f85d1..31f63e1c6 100644
--- a/.github/workflows/stale.yml
+++ b/.github/workflows/stale.yml
@@ -8,7 +8,7 @@ on:
permissions:
issues: write
-concurrency:
+concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
diff --git a/.github/workflows/test-cygwin.yml b/.github/workflows/test-cygwin.yml
index 2ba5e741e..5caa9faa4 100644
--- a/.github/workflows/test-cygwin.yml
+++ b/.github/workflows/test-cygwin.yml
@@ -4,11 +4,19 @@ on:
push:
paths-ignore:
- ".github/workflows/docs.yml"
+ - ".github/workflows/wheels*"
+ - ".gitmodules"
+ - ".travis.yml"
- "docs/**"
+ - "wheels/**"
pull_request:
paths-ignore:
- ".github/workflows/docs.yml"
+ - ".github/workflows/wheels*"
+ - ".gitmodules"
+ - ".travis.yml"
- "docs/**"
+ - "wheels/**"
workflow_dispatch:
permissions:
@@ -36,7 +44,7 @@ jobs:
git config --global core.autocrlf input
- name: Checkout Pillow
- uses: actions/checkout@v3
+ uses: actions/checkout@v4
- name: Install Cygwin
uses: cygwin/cygwin-install-action@v4
@@ -102,10 +110,10 @@ jobs:
run: |
bash.exe .ci/install.sh
- - name: Install latest NumPy
+ - name: Upgrade NumPy
shell: dash.exe -l "{0}"
run: |
- python3 -m pip install -U numpy
+ python3 -m pip install -U "numpy<1.26"
- name: Build
shell: bash.exe -eo pipefail -o igncr "{0}"
diff --git a/.github/workflows/test-docker.yml b/.github/workflows/test-docker.yml
index 36d9c131d..98a5de158 100644
--- a/.github/workflows/test-docker.yml
+++ b/.github/workflows/test-docker.yml
@@ -4,11 +4,19 @@ on:
push:
paths-ignore:
- ".github/workflows/docs.yml"
+ - ".github/workflows/wheels*"
+ - ".gitmodules"
+ - ".travis.yml"
- "docs/**"
+ - "wheels/**"
pull_request:
paths-ignore:
- ".github/workflows/docs.yml"
+ - ".github/workflows/wheels*"
+ - ".gitmodules"
+ - ".travis.yml"
- "docs/**"
+ - "wheels/**"
workflow_dispatch:
permissions:
@@ -59,7 +67,7 @@ jobs:
name: ${{ matrix.docker }}
steps:
- - uses: actions/checkout@v3
+ - uses: actions/checkout@v4
- name: Build system information
run: python3 .github/workflows/system-info.py
diff --git a/.github/workflows/test-mingw.yml b/.github/workflows/test-mingw.yml
index 36bb38cd7..76e02ae92 100644
--- a/.github/workflows/test-mingw.yml
+++ b/.github/workflows/test-mingw.yml
@@ -4,11 +4,19 @@ on:
push:
paths-ignore:
- ".github/workflows/docs.yml"
+ - ".github/workflows/wheels*"
+ - ".gitmodules"
+ - ".travis.yml"
- "docs/**"
+ - "wheels/**"
pull_request:
paths-ignore:
- ".github/workflows/docs.yml"
+ - ".github/workflows/wheels*"
+ - ".gitmodules"
+ - ".travis.yml"
- "docs/**"
+ - "wheels/**"
workflow_dispatch:
permissions:
@@ -34,7 +42,7 @@ jobs:
steps:
- name: Checkout Pillow
- uses: actions/checkout@v3
+ uses: actions/checkout@v4
- name: Set up shell
run: echo "C:\msys64\usr\bin\" >> $env:GITHUB_PATH
diff --git a/.github/workflows/test-valgrind.yml b/.github/workflows/test-valgrind.yml
index 6fab0ecd2..21968ad5a 100644
--- a/.github/workflows/test-valgrind.yml
+++ b/.github/workflows/test-valgrind.yml
@@ -37,7 +37,7 @@ jobs:
name: ${{ matrix.docker }}
steps:
- - uses: actions/checkout@v3
+ - uses: actions/checkout@v4
- name: Build system information
run: python3 .github/workflows/system-info.py
diff --git a/.github/workflows/test-windows.yml b/.github/workflows/test-windows.yml
index 70afbab24..3d7ec8e67 100644
--- a/.github/workflows/test-windows.yml
+++ b/.github/workflows/test-windows.yml
@@ -4,11 +4,19 @@ on:
push:
paths-ignore:
- ".github/workflows/docs.yml"
+ - ".github/workflows/wheels*"
+ - ".gitmodules"
+ - ".travis.yml"
- "docs/**"
+ - "wheels/**"
pull_request:
paths-ignore:
- ".github/workflows/docs.yml"
+ - ".github/workflows/wheels*"
+ - ".gitmodules"
+ - ".travis.yml"
- "docs/**"
+ - "wheels/**"
workflow_dispatch:
permissions:
@@ -24,7 +32,7 @@ jobs:
strategy:
fail-fast: false
matrix:
- python-version: ["pypy3.10", "pypy3.9", "3.8", "3.9", "3.10", "3.11", "3.12-dev"]
+ python-version: ["pypy3.10", "pypy3.9", "3.8", "3.9", "3.10", "3.11", "3.12"]
timeout-minutes: 30
@@ -32,16 +40,16 @@ jobs:
steps:
- name: Checkout Pillow
- uses: actions/checkout@v3
+ uses: actions/checkout@v4
- name: Checkout cached dependencies
- uses: actions/checkout@v3
+ uses: actions/checkout@v4
with:
repository: python-pillow/pillow-depends
path: winbuild\depends
- name: Checkout extra test images
- uses: actions/checkout@v3
+ uses: actions/checkout@v4
with:
repository: python-pillow/test-images
path: Tests\test-images
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 893c0d12c..926fe2de6 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -4,11 +4,19 @@ on:
push:
paths-ignore:
- ".github/workflows/docs.yml"
+ - ".github/workflows/wheels*"
+ - ".gitmodules"
+ - ".travis.yml"
- "docs/**"
+ - "wheels/**"
pull_request:
paths-ignore:
- ".github/workflows/docs.yml"
+ - ".github/workflows/wheels*"
+ - ".gitmodules"
+ - ".travis.yml"
- "docs/**"
+ - "wheels/**"
workflow_dispatch:
permissions:
@@ -31,7 +39,7 @@ jobs:
python-version: [
"pypy3.10",
"pypy3.9",
- "3.12-dev",
+ "3.12",
"3.11",
"3.10",
"3.9",
@@ -48,7 +56,7 @@ jobs:
name: ${{ matrix.os }} Python ${{ matrix.python-version }}
steps:
- - uses: actions/checkout@v3
+ - uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
diff --git a/.github/workflows/wheels-build.sh b/.github/workflows/wheels-build.sh
new file mode 100755
index 000000000..0aeec6b96
--- /dev/null
+++ b/.github/workflows/wheels-build.sh
@@ -0,0 +1,40 @@
+#!/bin/bash
+
+if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
+ # webp, zstd, xz, libtiff, libxcb cause a conflict with building webp, libtiff, libxcb
+ # libxdmcp causes an issue on macOS < 11
+ # curl from brew requires zstd, use system curl
+ # if php is installed, brew tries to reinstall these after installing openblas
+ # remove lcms2 and libpng to fix building openjpeg on arm64
+ brew remove --ignore-dependencies webp zstd xz libpng libtiff libxcb libxdmcp curl php lcms2 ghostscript
+
+ brew install pkg-config
+
+ if [[ "$PLAT" == "arm64" ]]; then
+ export MACOSX_DEPLOYMENT_TARGET="11.0"
+ else
+ export MACOSX_DEPLOYMENT_TARGET="10.10"
+ fi
+fi
+
+if [[ "$MB_PYTHON_VERSION" == pypy3* ]]; then
+ MB_PYTHON_OSX_VER="10.9"
+fi
+
+echo "::group::Install a virtualenv"
+ source wheels/multibuild/common_utils.sh
+ source wheels/multibuild/travis_steps.sh
+ python3 -m pip install virtualenv
+ before_install
+echo "::endgroup::"
+
+echo "::group::Build wheel"
+ build_wheel
+ ls -l "${GITHUB_WORKSPACE}/${WHEEL_SDIR}/"
+echo "::endgroup::"
+
+if [[ $MACOSX_DEPLOYMENT_TARGET != "11.0" ]]; then
+ echo "::group::Test wheel"
+ install_run
+ echo "::endgroup::"
+fi
diff --git a/.github/workflows/wheels-linux.yml b/.github/workflows/wheels-linux.yml
new file mode 100644
index 000000000..8b2d9d451
--- /dev/null
+++ b/.github/workflows/wheels-linux.yml
@@ -0,0 +1,69 @@
+name: Build Linux wheels
+
+on:
+ workflow_call:
+ inputs:
+ artifacts-name:
+ required: true
+ type: string
+
+env:
+ CONFIG_PATH: "wheels/config.sh"
+ REPO_DIR: "."
+ TEST_DEPENDS: "pytest pytest-timeout"
+
+jobs:
+ build:
+ name: ${{ matrix.python }} ${{ matrix.mb-ml-libc }}${{ matrix.mb-ml-ver }}
+ runs-on: "ubuntu-latest"
+ strategy:
+ fail-fast: false
+ matrix:
+ python: [
+ "pypy3.9-7.3.13",
+ "pypy3.10-7.3.13",
+ "3.8",
+ "3.9",
+ "3.10",
+ "3.11",
+ "3.12",
+ ]
+ mb-ml-libc: [ "manylinux" ]
+ mb-ml-ver: [ 2014, "_2_28" ]
+ include:
+ - python: "3.8"
+ mb-ml-libc: "musllinux"
+ mb-ml-ver: "_1_1"
+ - python: "3.9"
+ mb-ml-libc: "musllinux"
+ mb-ml-ver: "_1_1"
+ - python: "3.10"
+ mb-ml-libc: "musllinux"
+ mb-ml-ver: "_1_1"
+ - python: "3.11"
+ mb-ml-libc: "musllinux"
+ mb-ml-ver: "_1_1"
+ - python: "3.12"
+ mb-ml-libc: "musllinux"
+ mb-ml-ver: "_1_1"
+ env:
+ MB_PYTHON_VERSION: ${{ matrix.python }}
+ MB_ML_LIBC: ${{ matrix.mb-ml-libc }}
+ MB_ML_VER: ${{ matrix.mb-ml-ver }}
+ steps:
+ - uses: actions/checkout@v4
+ with:
+ submodules: true
+ - uses: actions/setup-python@v4
+ with:
+ python-version: "3.x"
+ - name: Build Wheel
+ run: .github/workflows/wheels-build.sh
+ - uses: actions/upload-artifact@v3
+ with:
+ name: ${{ inputs.artifacts-name }}
+ path: wheelhouse/*.whl
+ # Uncomment to get SSH access for testing
+ # - name: Setup tmate session
+ # if: failure()
+ # uses: mxschmitt/action-tmate@v3
diff --git a/.github/workflows/wheels-macos.yml b/.github/workflows/wheels-macos.yml
new file mode 100644
index 000000000..c51abf39a
--- /dev/null
+++ b/.github/workflows/wheels-macos.yml
@@ -0,0 +1,57 @@
+name: Build macOS wheels
+
+on:
+ workflow_call:
+ inputs:
+ artifacts-name:
+ required: true
+ type: string
+
+env:
+ CONFIG_PATH: "wheels/config.sh"
+ REPO_DIR: "."
+ TEST_DEPENDS: "pytest pytest-timeout"
+
+jobs:
+ build:
+ name: ${{ matrix.python }} ${{ matrix.platform }}
+ runs-on: "macos-latest"
+ strategy:
+ fail-fast: false
+ matrix:
+ python: [
+ "pypy3.9-7.3.13",
+ "pypy3.10-7.3.13",
+ "3.8",
+ "3.9",
+ "3.10",
+ "3.11",
+ "3.12",
+ ]
+ platform: [ "x86_64", "arm64" ]
+ exclude:
+ - python: "pypy3.9-7.3.13"
+ platform: "arm64"
+ - python: "pypy3.10-7.3.13"
+ platform: "arm64"
+ env:
+ PLAT: ${{ matrix.platform }}
+ MB_PYTHON_VERSION: ${{ matrix.python }}
+ TRAVIS_OS_NAME: "osx"
+ steps:
+ - uses: actions/checkout@v4
+ with:
+ submodules: true
+ - uses: actions/setup-python@v4
+ with:
+ python-version: "3.x"
+ - name: Build Wheel
+ run: .github/workflows/wheels-build.sh
+ - uses: actions/upload-artifact@v3
+ with:
+ name: ${{ inputs.artifacts-name }}
+ path: wheelhouse/*.whl
+ # Uncomment to get SSH access for testing
+ # - name: Setup tmate session
+ # if: failure()
+ # uses: mxschmitt/action-tmate@v3
diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml
new file mode 100644
index 000000000..4381a9856
--- /dev/null
+++ b/.github/workflows/wheels.yml
@@ -0,0 +1,42 @@
+name: Wheels
+
+on:
+ push:
+ paths:
+ - ".github/workflows/wheels*.yml"
+ - "wheels/*"
+ tags:
+ - "*"
+ pull_request:
+ paths:
+ - ".github/workflows/wheels*.yml"
+ - "wheels/*"
+ workflow_dispatch:
+
+permissions:
+ contents: read
+
+concurrency:
+ group: ${{ github.workflow }}-${{ github.ref }}
+ cancel-in-progress: true
+
+jobs:
+ macos:
+ uses: ./.github/workflows/wheels-macos.yml
+ with:
+ artifacts-name: "wheels"
+
+ linux:
+ uses: ./.github/workflows/wheels-linux.yml
+ with:
+ artifacts-name: "wheels"
+
+ success:
+ permissions:
+ contents: none
+ needs: [macos, linux]
+ runs-on: ubuntu-latest
+ name: Wheels Successful
+ steps:
+ - name: Success
+ run: echo Wheels Successful
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 000000000..80d5ab16c
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "multibuild"]
+ path = wheels/multibuild
+ url = https://github.com/multi-build/multibuild.git
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 5354509d4..a8c7696df 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -1,6 +1,12 @@
repos:
- - repo: https://github.com/psf/black
- rev: 23.7.0
+ - repo: https://github.com/asottile/pyupgrade
+ rev: v3.13.0
+ hooks:
+ - id: pyupgrade
+ args: [--py38-plus]
+
+ - repo: https://github.com/psf/black-pre-commit-mirror
+ rev: 23.9.1
hooks:
- id: black
args: [--target-version=py38]
@@ -23,7 +29,7 @@ repos:
- id: yesqa
- repo: https://github.com/Lucas-C/pre-commit-hooks
- rev: v1.5.3
+ rev: v1.5.4
hooks:
- id: remove-tabs
exclude: (Makefile$|\.bat$|\.cmake$|\.eps$|\.fits$|\.gd$|\.opt$)
@@ -33,7 +39,7 @@ repos:
hooks:
- id: flake8
additional_dependencies:
- [flake8-2020, flake8-errmsg, flake8-implicit-str-concat]
+ [flake8-2020, flake8-errmsg, flake8-implicit-str-concat, flake8-logging]
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
@@ -44,23 +50,28 @@ repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
+ - id: check-executables-have-shebangs
- id: check-merge-conflict
- id: check-json
- id: check-toml
- id: check-yaml
+ - id: end-of-file-fixer
+ exclude: ^Tests/images/
+ - id: trailing-whitespace
+ exclude: ^.github/.*TEMPLATE|^Tests/(fonts|images)/
- repo: https://github.com/sphinx-contrib/sphinx-lint
- rev: v0.6.7
+ rev: v0.6.8
hooks:
- id: sphinx-lint
- repo: https://github.com/tox-dev/pyproject-fmt
- rev: 0.13.0
+ rev: 1.2.0
hooks:
- id: pyproject-fmt
- repo: https://github.com/abravalheri/validate-pyproject
- rev: v0.13
+ rev: v0.14
hooks:
- id: validate-pyproject
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 000000000..e4584ec88
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,135 @@
+if: tag IS present OR type = api
+
+env:
+ global:
+ - CONFIG_PATH=wheels/config.sh
+ - REPO_DIR=.
+ - PLAT=aarch64
+ - TEST_DEPENDS=pytest-timeout
+
+language: python
+# Default Python version is usually 3.6
+python: "3.11"
+dist: focal
+services: docker
+
+jobs:
+ include:
+ - name: "3.8 Focal manylinux2014 aarch64"
+ os: linux
+ arch: arm64
+ env:
+ - MB_ML_VER=2014
+ - MB_PYTHON_VERSION=3.8
+ - name: "3.8 Focal manylinux_2_28 aarch64"
+ os: linux
+ arch: arm64
+ env:
+ - MB_ML_VER="_2_28"
+ - MB_PYTHON_VERSION=3.8
+ - name: "3.8 musllinux_1_1 aarch64"
+ os: linux
+ arch: arm64
+ env:
+ - MB_ML_VER="_1_1"
+ - MB_ML_LIBC="musllinux"
+ - MB_PYTHON_VERSION=3.8
+ - name: "3.9 Focal manylinux2014 aarch64"
+ os: linux
+ arch: arm64
+ env:
+ - MB_ML_VER=2014
+ - MB_PYTHON_VERSION=3.9
+ - name: "3.9 Focal manylinux_2_28 aarch64"
+ os: linux
+ arch: arm64
+ env:
+ - MB_ML_VER="_2_28"
+ - MB_PYTHON_VERSION=3.9
+ - name: "3.9 musllinux_1_1 aarch64"
+ os: linux
+ arch: arm64
+ env:
+ - MB_ML_VER="_1_1"
+ - MB_ML_LIBC="musllinux"
+ - MB_PYTHON_VERSION=3.9
+ - name: "3.10 Focal manylinux2014 aarch64"
+ os: linux
+ arch: arm64
+ env:
+ - MB_ML_VER=2014
+ - MB_PYTHON_VERSION=3.10
+ - name: "3.10 Focal manylinux_2_28 aarch64"
+ os: linux
+ arch: arm64
+ env:
+ - MB_ML_VER="_2_28"
+ - MB_PYTHON_VERSION=3.10
+ - name: "3.10 musllinux_1_1 aarch64"
+ os: linux
+ arch: arm64
+ env:
+ - MB_ML_VER="_1_1"
+ - MB_ML_LIBC="musllinux"
+ - MB_PYTHON_VERSION=3.10
+ - name: "3.11 Focal manylinux_2_28 aarch64"
+ os: linux
+ arch: arm64
+ env:
+ - MB_ML_VER=2014
+ - MB_PYTHON_VERSION=3.11
+ - name: "3.11 Focal manylinux_2_28 aarch64"
+ os: linux
+ arch: arm64
+ env:
+ - MB_ML_VER="_2_28"
+ - MB_PYTHON_VERSION=3.11
+ - name: "3.11 musllinux_1_1 aarch64"
+ os: linux
+ arch: arm64
+ env:
+ - MB_ML_VER="_1_1"
+ - MB_ML_LIBC="musllinux"
+ - MB_PYTHON_VERSION=3.11
+ - name: "3.12 Focal manylinux_2_28 aarch64"
+ os: linux
+ arch: arm64
+ env:
+ - MB_ML_VER=2014
+ - MB_PYTHON_VERSION=3.12
+ - name: "3.12 Focal manylinux_2_28 aarch64"
+ os: linux
+ arch: arm64
+ env:
+ - MB_ML_VER="_2_28"
+ - MB_PYTHON_VERSION=3.12
+ - name: "3.12 musllinux_1_1 aarch64"
+ os: linux
+ arch: arm64
+ env:
+ - MB_ML_VER="_1_1"
+ - MB_ML_LIBC="musllinux"
+ - MB_PYTHON_VERSION=3.12
+
+before_install:
+ - source wheels/multibuild/common_utils.sh
+ - source wheels/multibuild/travis_steps.sh
+ - before_install
+
+install:
+ - build_multilinux aarch64 build_wheel
+ - ls -l "${TRAVIS_BUILD_DIR}/${WHEEL_SDIR}/"
+
+script:
+ - install_run
+
+# Upload wheels to GitHub Releases
+deploy:
+ provider: releases
+ api_key: $GITHUB_RELEASE_TOKEN
+ file_glob: true
+ file: "${TRAVIS_BUILD_DIR}/${WHEEL_SDIR}/*.whl"
+ on:
+ repo: python-pillow/Pillow
+ tags: true
+ skip_cleanup: true
diff --git a/CHANGES.rst b/CHANGES.rst
index cbacf5bde..b83de7edb 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -5,15 +5,78 @@ Changelog (Pillow)
10.1.0 (unreleased)
-------------------
+- Added ImageOps cover method #7412
+ [radarhere, hugovk]
+
+- Catch struct.error from truncated EXIF when reading JPEG DPI #7458
+ [radarhere]
+
+- Consider default image when selecting mode for PNG save_all #7437
+ [radarhere]
+
+- Support BGR;15, BGR;16 and BGR;24 access, unpacking and putdata #7303
+ [radarhere]
+
+- Added CMYK to RGB unpacker #7310
+ [radarhere]
+
+- Improved flexibility of XMP parsing #7274
+ [radarhere]
+
+- Support reading 8-bit YCbCr TIFF images #7415
+ [radarhere]
+
+- Allow saving I;16B images as PNG #7302
+ [radarhere]
+
+- Corrected drawing I;16 points and writing I;16 text #7257
+ [radarhere]
+
+- Set blue channel to 128 for BC5S #7413
+ [radarhere]
+
+- Increase flexibility when reading IPTC fields #7319
+ [radarhere]
+
+- Set C palette to be empty by default #7289
+ [radarhere]
+
+- Added gs_binary to control Ghostscript use on all platforms #7392
+ [radarhere]
+
+- Read bounding box information from the trailer of EPS files if specified #7382
+ [nopperl, radarhere]
+
+- Added reading 8-bit color DDS images #7426
+ [radarhere]
+
+- Added has_transparency_data #7420
+ [radarhere, hugovk]
+
+- Fixed bug when reading BC5S DDS images #7401
+ [radarhere]
+
+- Prevent TIFF orientation from being applied more than once #7383
+ [radarhere]
+
+- Use previous pixel alpha for QOI_OP_RGB #7357
+ [radarhere]
+
+- Added BC5U reading #7358
+ [radarhere]
+
+- Allow getpixel() to accept a list #7355
+ [radarhere, homm]
+
- Allow GaussianBlur and BoxBlur to accept a sequence of x and y radii #7336
[radarhere]
+- Expand JPEG buffer size when saving optimized or progressive #7345
+ [radarhere]
+
- Added session type check for Linux in ImageGrab.grabclipboard() #7332
[TheNooB2706, radarhere, hugovk]
-- Read WebP duration after opening #7311
- [k128, radarhere]
-
- Allow "loop=None" when saving GIF images #7329
[radarhere]
@@ -38,6 +101,15 @@ Changelog (Pillow)
- Fix missing symbols when libtiff depends on libjpeg #7270
[heitbaum]
+10.0.1 (2023-09-15)
+-------------------
+
+- Updated libwebp to 1.3.2 #7395
+ [radarhere]
+
+- Updated zlib to 1.3 #7344
+ [radarhere]
+
10.0.0 (2023-07-01)
-------------------
@@ -5765,8 +5837,8 @@ http://svn.effbot.org/public/pil/
a polyline, independent of line angle.
- Fixed bearing calculation and clipping in the ImageFont truetype
- renderer; this could lead to clipped text, or crashes in the low-
- level _imagingft module. (based on input from Adam Twardoch and
+ renderer; this could lead to clipped text, or crashes in the low-level
+ _imagingft module. (based on input from Adam Twardoch and
others).
- Added ImageQt wrapper module, for converting PIL Image objects to
@@ -5847,8 +5919,7 @@ http://svn.effbot.org/public/pil/
1.1.5c2 and 1.1.5 final
-----------------------
-- Added experimental PERSPECTIVE transform method (from Jeff Breiden-
- bach).
+- Added experimental PERSPECTIVE transform method (from Jeff Breidenbach).
1.1.5c1
-------
@@ -5920,8 +5991,8 @@ http://svn.effbot.org/public/pil/
- Fixed BILINEAR/BICUBIC/ANTIALIAS filtering for mode "LA".
-- Added "getcolors()" method. This is similar to the existing histo-
- gram method, but looks at color values instead of individual layers,
+- Added "getcolors()" method. This is similar to the existing histogram
+ method, but looks at color values instead of individual layers,
and returns an unsorted list of (count, color) tuples.
By default, the method returns None if finds more than 256 colors.
@@ -6137,8 +6208,8 @@ http://svn.effbot.org/public/pil/
- Added limited support for "bitfield compression" in BMP files
and DIB buffers, for 15-bit, 16-bit, and 32-bit images. This
- also fixes a problem with ImageGrab module when copying screen-
- dumps from the clipboard on 15/16/32-bit displays.
+ also fixes a problem with ImageGrab module when copying screendumps
+ from the clipboard on 15/16/32-bit displays.
- Added experimental WAL (Quake 2 textures) loader. To use this
loader, import WalImageFile and call the "open" method in that
@@ -6249,8 +6320,8 @@ http://svn.effbot.org/public/pil/
1.1.3 final
-----------
-- Made setup.py look for old versions of zlib. For some back-
- ground, see: https://zlib.net/advisory-2002-03-11.txt
+- Made setup.py look for old versions of zlib. For some background,
+ see: https://zlib.net/advisory-2002-03-11.txt
1.1.3c2
-------
@@ -6441,8 +6512,8 @@ http://svn.effbot.org/public/pil/
supports all major PIL image modes (including F and I).
- The ImageFile module now includes a Parser class, which can
- be used to incrementally decode an image file (while down-
- loading it from the net, for example). See the handbook for
+ be used to incrementally decode an image file (while downloading
+ it from the net, for example). See the handbook for
details.
- "show" now converts non-standard modes to "L" or "RGB" (as
@@ -6580,8 +6651,8 @@ http://svn.effbot.org/public/pil/
- The Image "transform" method now supports Image.QUAD transforms.
The data argument is an 8-tuple giving the upper left, lower
- left, lower right, and upper right corner of the source quadri-
- lateral. Also added Image.MESH transform which takes a list
+ left, lower right, and upper right corner of the source quadrilateral.
+ Also added Image.MESH transform which takes a list
of quadrilaterals.
- The Image "resize", "rotate", and "transform" methods now support
@@ -6806,8 +6877,8 @@ The test suite includes 400 individual tests.
neither "short", "int" nor "long" are 32-bit wide.
- Added file= and data= keyword arguments to PhotoImage and BitmapImage.
- This allows you to use them as drop-in replacements for the corre-
- sponding Tkinter classes.
+ This allows you to use them as drop-in replacements for the corresponding
+ Tkinter classes.
- Removed bogus references to the crack coder (ImagingCrack).
diff --git a/MANIFEST.in b/MANIFEST.in
index 606e7e074..2bbddefa3 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -29,3 +29,4 @@ global-exclude .git*
global-exclude *.pyc
global-exclude *.so
prune .ci
+prune wheels
diff --git a/README.md b/README.md
index af1ca57c2..e11bd2faa 100644
--- a/README.md
+++ b/README.md
@@ -45,12 +45,12 @@ As of 2019, Pillow development is
-
- ![]()
+
+ src="https://img.shields.io/travis/com/python-pillow/Pillow/main.svg?label=aarch64%20wheels">
@@ -74,9 +74,9 @@ As of 2019, Pillow development is
- ![]()
+ src="https://www.bestpractices.dev/projects/6331/badge">
diff --git a/RELEASING.md b/RELEASING.md
index 604bb1b8c..0229dbbc1 100644
--- a/RELEASING.md
+++ b/RELEASING.md
@@ -10,7 +10,7 @@ Released quarterly on January 2nd, April 1st, July 1st and October 15th.
* [ ] Open a release ticket e.g. https://github.com/python-pillow/Pillow/issues/3154
* [ ] Develop and prepare release in `main` branch.
* [ ] Check [GitHub Actions](https://github.com/python-pillow/Pillow/actions) and [AppVeyor](https://ci.appveyor.com/project/python-pillow/Pillow) to confirm passing tests in `main` branch.
-* [ ] Check that all of the wheel builds [Pillow Wheel Builder](https://github.com/python-pillow/pillow-wheels) pass the tests in Travis CI and GitHub Actions.
+* [ ] Check that all of the wheel builds pass the tests in the [GitHub Actions "Wheels" workflow](https://github.com/python-pillow/Pillow/actions/workflows/wheels.yml) and [Travis CI](https://app.travis-ci.com/github/python-pillow/pillow) jobs by manually triggering them.
* [ ] In compliance with [PEP 440](https://peps.python.org/pep-0440/), update version identifier in `src/PIL/_version.py`
* [ ] Update `CHANGES.rst`.
* [ ] Run pre-release check via `make release-test` in a freshly cloned repo.
@@ -99,17 +99,14 @@ Released as needed privately to individual vendors for critical security-related
## Binary Distributions
### macOS and Linux
-* [ ] Use the [Pillow Wheel Builder](https://github.com/python-pillow/pillow-wheels):
+* [ ] Download wheels from the [GitHub Actions "Wheels" workflow](https://github.com/python-pillow/Pillow/actions/workflows/wheels.yml)
+ and copy into `dist/`. For example using [GitHub CLI](https://github.com/cli/cli):
```bash
- git clone https://github.com/python-pillow/pillow-wheels
- cd pillow-wheels
- ./update-pillow-tag.sh [[release tag]]
- ```
-* [ ] Download wheels from the [Pillow Wheel Builder release](https://github.com/python-pillow/pillow-wheels/releases)
- and copy into `dist/`. For example using [GitHub CLI](https://github.com/cli/cli) from the main repo:
- ```bash
- gh release download --dir dist --pattern "*.whl" --repo python-pillow/pillow-wheels
+ gh run download --dir dist
+ # select dist-x.y.z
```
+* [ ] Download the Linux aarch64 wheels created by Travis CI from [GitHub releases](https://github.com/python-pillow/Pillow/releases)
+ and copy into `dist`.
### Windows
* [ ] Download the artifacts from the [GitHub Actions "Test Windows" workflow](https://github.com/python-pillow/Pillow/actions/workflows/test-windows.yml)
diff --git a/Tests/check_j2k_leaks.py b/Tests/check_j2k_leaks.py
old mode 100755
new mode 100644
diff --git a/Tests/fonts/DejaVuSans/LICENSE.txt b/Tests/fonts/DejaVuSans/LICENSE.txt
index 30516578f..be6a4d84c 100644
--- a/Tests/fonts/DejaVuSans/LICENSE.txt
+++ b/Tests/fonts/DejaVuSans/LICENSE.txt
@@ -37,4 +37,4 @@ The Font Software may be sold as part of a larger software package but no copy o
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL TAVMJONG BAH BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.
-Except as contained in this notice, the name of Tavmjong Bah shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Font Software without prior written authorization from Tavmjong Bah. For further information, contact: tavmjong @ free . fr.
\ No newline at end of file
+Except as contained in this notice, the name of Tavmjong Bah shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Font Software without prior written authorization from Tavmjong Bah. For further information, contact: tavmjong @ free . fr.
diff --git a/Tests/helper.py b/Tests/helper.py
index 69246bfcf..de5468d84 100644
--- a/Tests/helper.py
+++ b/Tests/helper.py
@@ -91,7 +91,7 @@ def assert_image_equal(a, b, msg=None):
if HAS_UPLOADER:
try:
url = test_image_results.upload(a, b)
- logger.error(f"Url for test images: {url}")
+ logger.error("URL for test images: %s", url)
except Exception:
pass
@@ -126,7 +126,7 @@ def assert_image_similar(a, b, epsilon, msg=None):
if HAS_UPLOADER:
try:
url = test_image_results.upload(a, b)
- logger.error(f"Url for test images: {url}")
+ logger.exception("URL for test images: %s", url)
except Exception:
pass
raise e
diff --git a/Tests/icc/LICENSE.txt b/Tests/icc/LICENSE.txt
index 7d289c331..7119461ed 100644
--- a/Tests/icc/LICENSE.txt
+++ b/Tests/icc/LICENSE.txt
@@ -22,4 +22,3 @@ and that the name of ICC shall not be used in advertising or publicity
pertaining to distribution of the software without specific, written
prior permission. ICC makes no representations about the suitability
of this software for any purpose.
-
diff --git a/Tests/images/bc5s.png b/Tests/images/bc5s.png
index 39d7811bf..5e7a1b95e 100644
Binary files a/Tests/images/bc5s.png and b/Tests/images/bc5s.png differ
diff --git a/Tests/images/bc5u.dds b/Tests/images/bc5u.dds
new file mode 100644
index 000000000..4e4773cd7
Binary files /dev/null and b/Tests/images/bc5u.dds differ
diff --git a/Tests/images/imagedraw_rectangle_I.png b/Tests/images/imagedraw_rectangle_I.png
index 4e94f6943..a75f12c2e 100644
Binary files a/Tests/images/imagedraw_rectangle_I.png and b/Tests/images/imagedraw_rectangle_I.png differ
diff --git a/Tests/images/negative_size.ppm b/Tests/images/negative_size.ppm
old mode 100755
new mode 100644
diff --git a/Tests/images/palette.dds b/Tests/images/palette.dds
new file mode 100644
index 000000000..7171cb1f2
Binary files /dev/null and b/Tests/images/palette.dds differ
diff --git a/Tests/images/truncated_exif_dpi.jpg b/Tests/images/truncated_exif_dpi.jpg
new file mode 100644
index 000000000..b41ab4004
Binary files /dev/null and b/Tests/images/truncated_exif_dpi.jpg differ
diff --git a/Tests/images/xmp_no_prefix.jpg b/Tests/images/xmp_no_prefix.jpg
new file mode 100644
index 000000000..bcd78c7ed
Binary files /dev/null and b/Tests/images/xmp_no_prefix.jpg differ
diff --git a/Tests/images/xmp_padded.jpg b/Tests/images/xmp_padded.jpg
new file mode 100644
index 000000000..9ecfb3efe
Binary files /dev/null and b/Tests/images/xmp_padded.jpg differ
diff --git a/Tests/images/zero_bb_eof_before_boundingbox.eps b/Tests/images/zero_bb_eof_before_boundingbox.eps
new file mode 100644
index 000000000..c268bffd1
Binary files /dev/null and b/Tests/images/zero_bb_eof_before_boundingbox.eps differ
diff --git a/Tests/images/zero_bb_trailer.eps b/Tests/images/zero_bb_trailer.eps
new file mode 100644
index 000000000..964889965
Binary files /dev/null and b/Tests/images/zero_bb_trailer.eps differ
diff --git a/Tests/test_file_apng.py b/Tests/test_file_apng.py
index 8cb9a814e..579288808 100644
--- a/Tests/test_file_apng.py
+++ b/Tests/test_file_apng.py
@@ -673,10 +673,16 @@ def test_seek_after_close():
@pytest.mark.parametrize("mode", ("RGBA", "RGB", "P"))
-def test_different_modes_in_later_frames(mode, tmp_path):
+@pytest.mark.parametrize("default_image", (True, False))
+def test_different_modes_in_later_frames(mode, default_image, tmp_path):
test_file = str(tmp_path / "temp.png")
im = Image.new("L", (1, 1))
- im.save(test_file, save_all=True, append_images=[Image.new(mode, (1, 1))])
+ im.save(
+ test_file,
+ save_all=True,
+ default_image=default_image,
+ append_images=[Image.new(mode, (1, 1))],
+ )
with Image.open(test_file) as reloaded:
assert reloaded.mode == mode
diff --git a/Tests/test_file_dds.py b/Tests/test_file_dds.py
index cac4108a8..bb9af7967 100644
--- a/Tests/test_file_dds.py
+++ b/Tests/test_file_dds.py
@@ -16,6 +16,7 @@ TEST_FILE_DX10_BC5_TYPELESS = "Tests/images/bc5_typeless.dds"
TEST_FILE_DX10_BC5_UNORM = "Tests/images/bc5_unorm.dds"
TEST_FILE_DX10_BC5_SNORM = "Tests/images/bc5_snorm.dds"
TEST_FILE_BC5S = "Tests/images/bc5s.dds"
+TEST_FILE_BC5U = "Tests/images/bc5u.dds"
TEST_FILE_BC6H = "Tests/images/bc6h.dds"
TEST_FILE_BC6HS = "Tests/images/bc6h_sf.dds"
TEST_FILE_DX10_BC7 = "Tests/images/bc7-argb-8bpp_MipMaps-1.dds"
@@ -81,10 +82,18 @@ def test_sanity_ati1():
assert_image_equal_tofile(im, TEST_FILE_ATI1.replace(".dds", ".png"))
-def test_sanity_ati2():
- """Check ATI2 images can be opened"""
+@pytest.mark.parametrize(
+ "image_path",
+ (
+ TEST_FILE_ATI2,
+ # hexeditted to use BC5U FourCC
+ TEST_FILE_BC5U,
+ ),
+)
+def test_sanity_ati2_bc5u(image_path):
+ """Check ATI2 and BC5U images can be opened"""
- with Image.open(TEST_FILE_ATI2) as im:
+ with Image.open(image_path) as im:
im.load()
assert im.format == "DDS"
@@ -289,6 +298,11 @@ def test_dxt5_colorblock_alpha_issue_4142():
assert px[2] != 0
+def test_palette():
+ with Image.open("Tests/images/palette.dds") as im:
+ assert_image_equal_tofile(im, "Tests/images/transparent.gif")
+
+
def test_unimplemented_pixel_format():
with pytest.raises(NotImplementedError):
with Image.open("Tests/images/unimplemented_pixel_format.dds"):
diff --git a/Tests/test_file_eps.py b/Tests/test_file_eps.py
index 26adfff87..259cf75c3 100644
--- a/Tests/test_file_eps.py
+++ b/Tests/test_file_eps.py
@@ -8,6 +8,7 @@ from .helper import (
assert_image_similar,
assert_image_similar_tofile,
hopper,
+ is_win32,
mark_if_feature_version,
skip_unless_feature,
)
@@ -98,6 +99,20 @@ def test_load():
assert im.load()[0, 0] == (255, 255, 255)
+def test_binary():
+ if HAS_GHOSTSCRIPT:
+ assert EpsImagePlugin.gs_binary is not None
+ else:
+ assert EpsImagePlugin.gs_binary is False
+
+ if not is_win32():
+ assert EpsImagePlugin.gs_windows_binary is None
+ elif not HAS_GHOSTSCRIPT:
+ assert EpsImagePlugin.gs_windows_binary is False
+ else:
+ assert EpsImagePlugin.gs_windows_binary is not None
+
+
def test_invalid_file():
invalid_file = "Tests/images/flower.jpg"
with pytest.raises(SyntaxError):
@@ -404,3 +419,18 @@ def test_timeout(test_file):
with pytest.raises(Image.UnidentifiedImageError):
with Image.open(f):
pass
+
+
+def test_bounding_box_in_trailer():
+ # Check bounding boxes are parsed in the same way
+ # when specified in the header and the trailer
+ with Image.open("Tests/images/zero_bb_trailer.eps") as trailer_image, Image.open(
+ FILE1
+ ) as header_image:
+ assert trailer_image.size == header_image.size
+
+
+def test_eof_before_bounding_box():
+ with pytest.raises(OSError):
+ with Image.open("Tests/images/zero_bb_eof_before_boundingbox.eps"):
+ pass
diff --git a/Tests/test_file_gif.py b/Tests/test_file_gif.py
index d571692b1..3c2e96356 100644
--- a/Tests/test_file_gif.py
+++ b/Tests/test_file_gif.py
@@ -205,14 +205,14 @@ def test_optimize_full_l():
def test_optimize_if_palette_can_be_reduced_by_half():
- with Image.open("Tests/images/test.colors.gif") as im:
- # Reduce dimensions because original is too big for _get_optimize()
- im = im.resize((591, 443))
- im_rgb = im.convert("RGB")
+ im = Image.new("P", (8, 1))
+ im.palette = ImagePalette.raw("RGB", bytes((0, 0, 0) * 150))
+ for i in range(8):
+ im.putpixel((i, 0), (i + 1, 0, 0))
for optimize, colors in ((False, 256), (True, 8)):
out = BytesIO()
- im_rgb.save(out, "GIF", optimize=optimize)
+ im.save(out, "GIF", optimize=optimize)
with Image.open(out) as reloaded:
assert len(reloaded.palette.palette) // 3 == colors
@@ -1180,18 +1180,17 @@ def test_palette_save_L(tmp_path):
def test_palette_save_P(tmp_path):
- # Pass in a different palette, then construct what the image would look like.
- # Forcing a non-straight grayscale palette.
-
- im = hopper("P")
- palette = bytes(255 - i // 3 for i in range(768))
+ im = Image.new("P", (1, 2))
+ im.putpixel((0, 1), 1)
out = str(tmp_path / "temp.gif")
- im.save(out, palette=palette)
+ im.save(out, palette=bytes((1, 2, 3, 4, 5, 6)))
with Image.open(out) as reloaded:
- im.putpalette(palette)
- assert_image_equal(reloaded, im)
+ reloaded_rgb = reloaded.convert("RGB")
+
+ assert reloaded_rgb.getpixel((0, 0)) == (1, 2, 3)
+ assert reloaded_rgb.getpixel((0, 1)) == (4, 5, 6)
def test_palette_save_duplicate_entries(tmp_path):
diff --git a/Tests/test_file_iptc.py b/Tests/test_file_iptc.py
index 2d99528d3..d2edcfc27 100644
--- a/Tests/test_file_iptc.py
+++ b/Tests/test_file_iptc.py
@@ -1,5 +1,5 @@
import sys
-from io import StringIO
+from io import BytesIO, StringIO
from PIL import Image, IptcImagePlugin
@@ -30,6 +30,36 @@ def test_getiptcinfo_jpg_found():
assert iptc[(2, 101)] == b"Hungary"
+def test_getiptcinfo_fotostation():
+ # Arrange
+ with open(TEST_FILE, "rb") as fp:
+ data = bytearray(fp.read())
+ data[86] = 240
+ f = BytesIO(data)
+ with Image.open(f) as im:
+ # Act
+ iptc = IptcImagePlugin.getiptcinfo(im)
+
+ # Assert
+ for tag in iptc.keys():
+ if tag[0] == 240:
+ return
+ assert False, "FotoStation tag not found"
+
+
+def test_getiptcinfo_zero_padding():
+ # Arrange
+ with Image.open(TEST_FILE) as im:
+ im.info["photoshop"][0x0404] += b"\x00\x00\x00"
+
+ # Act
+ iptc = IptcImagePlugin.getiptcinfo(im)
+
+ # Assert
+ assert isinstance(iptc, dict)
+ assert len(iptc) == 3
+
+
def test_getiptcinfo_tiff_none():
# Arrange
with Image.open("Tests/images/hopper.tif") as im:
diff --git a/Tests/test_file_jpeg.py b/Tests/test_file_jpeg.py
index b62132613..a0822d000 100644
--- a/Tests/test_file_jpeg.py
+++ b/Tests/test_file_jpeg.py
@@ -767,6 +767,13 @@ class TestFileJpeg:
# This should return the default
assert im.info.get("dpi") == (72, 72)
+ def test_dpi_exif_truncated(self):
+ # Arrange
+ with Image.open("Tests/images/truncated_exif_dpi.jpg") as im:
+ # Act / Assert
+ # This should return the default
+ assert im.info.get("dpi") == (72, 72)
+
def test_no_dpi_in_exif(self):
# Arrange
# This is photoshop-200dpi.jpg with resolution removed from EXIF:
@@ -882,7 +889,10 @@ class TestFileJpeg:
def test_getxmp(self):
with Image.open("Tests/images/xmp_test.jpg") as im:
if ElementTree is None:
- with pytest.warns(UserWarning):
+ with pytest.warns(
+ UserWarning,
+ match="XMP data cannot be read without defusedxml dependency",
+ ):
assert im.getxmp() == {}
else:
xmp = im.getxmp()
@@ -905,6 +915,28 @@ class TestFileJpeg:
with Image.open("Tests/images/hopper.jpg") as im:
assert im.getxmp() == {}
+ def test_getxmp_no_prefix(self):
+ with Image.open("Tests/images/xmp_no_prefix.jpg") as im:
+ if ElementTree is None:
+ with pytest.warns(
+ UserWarning,
+ match="XMP data cannot be read without defusedxml dependency",
+ ):
+ assert im.getxmp() == {}
+ else:
+ assert im.getxmp() == {"xmpmeta": {"key": "value"}}
+
+ def test_getxmp_padded(self):
+ with Image.open("Tests/images/xmp_padded.jpg") as im:
+ if ElementTree is None:
+ with pytest.warns(
+ UserWarning,
+ match="XMP data cannot be read without defusedxml dependency",
+ ):
+ assert im.getxmp() == {}
+ else:
+ assert im.getxmp() == {"xmpmeta": None}
+
@pytest.mark.timeout(timeout=1)
def test_eof(self):
# Even though this decoder never says that it is finished
diff --git a/Tests/test_file_libtiff.py b/Tests/test_file_libtiff.py
index ac78b0869..a7394f1bf 100644
--- a/Tests/test_file_libtiff.py
+++ b/Tests/test_file_libtiff.py
@@ -8,7 +8,7 @@ from collections import namedtuple
import pytest
-from PIL import Image, ImageFilter, TiffImagePlugin, TiffTags, features
+from PIL import Image, ImageFilter, ImageOps, TiffImagePlugin, TiffTags, features
from PIL.TiffImagePlugin import SAMPLEFORMAT, STRIPOFFSETS, SUBIFD
from .helper import (
@@ -1035,7 +1035,18 @@ class TestFileLibTiff(LibTiffTestCase):
with Image.open("Tests/images/g4_orientation_1.tif") as base_im:
for i in range(2, 9):
with Image.open("Tests/images/g4_orientation_" + str(i) + ".tif") as im:
+ assert 274 in im.tag_v2
+
im.load()
+ assert 274 not in im.tag_v2
+
+ assert_image_similar(base_im, im, 0.7)
+
+ def test_exif_transpose(self):
+ with Image.open("Tests/images/g4_orientation_1.tif") as base_im:
+ for i in range(2, 9):
+ with Image.open("Tests/images/g4_orientation_" + str(i) + ".tif") as im:
+ im = ImageOps.exif_transpose(im)
assert_image_similar(base_im, im, 0.7)
diff --git a/Tests/test_file_png.py b/Tests/test_file_png.py
index f8df88d67..40fc595ad 100644
--- a/Tests/test_file_png.py
+++ b/Tests/test_file_png.py
@@ -92,11 +92,11 @@ class TestFilePng:
assert im.format == "PNG"
assert im.get_format_mimetype() == "image/png"
- for mode in ["1", "L", "P", "RGB", "I", "I;16"]:
+ for mode in ["1", "L", "P", "RGB", "I", "I;16", "I;16B"]:
im = hopper(mode)
im.save(test_file)
with Image.open(test_file) as reloaded:
- if mode == "I;16":
+ if mode in ("I;16", "I;16B"):
reloaded = reloaded.convert(mode)
assert_image_equal(reloaded, im)
@@ -665,7 +665,10 @@ class TestFilePng:
def test_getxmp(self):
with Image.open("Tests/images/color_snakes.png") as im:
if ElementTree is None:
- with pytest.warns(UserWarning):
+ with pytest.warns(
+ UserWarning,
+ match="XMP data cannot be read without defusedxml dependency",
+ ):
assert im.getxmp() == {}
else:
xmp = im.getxmp()
diff --git a/Tests/test_file_qoi.py b/Tests/test_file_qoi.py
index f33eada61..0a835dcf6 100644
--- a/Tests/test_file_qoi.py
+++ b/Tests/test_file_qoi.py
@@ -2,7 +2,7 @@ import pytest
from PIL import Image, QoiImagePlugin
-from .helper import assert_image_equal_tofile, assert_image_similar_tofile
+from .helper import assert_image_equal_tofile
def test_sanity():
@@ -18,7 +18,7 @@ def test_sanity():
assert im.size == (162, 150)
assert im.format == "QOI"
- assert_image_similar_tofile(im, "Tests/images/pil123rgba.png", 0.03)
+ assert_image_equal_tofile(im, "Tests/images/pil123rgba.png")
def test_invalid_file():
diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py
index f13436ce8..7362c93ca 100644
--- a/Tests/test_file_tiff.py
+++ b/Tests/test_file_tiff.py
@@ -734,7 +734,10 @@ class TestFileTiff:
def test_getxmp(self):
with Image.open("Tests/images/lab.tif") as im:
if ElementTree is None:
- with pytest.warns(UserWarning):
+ with pytest.warns(
+ UserWarning,
+ match="XMP data cannot be read without defusedxml dependency",
+ ):
assert im.getxmp() == {}
else:
xmp = im.getxmp()
diff --git a/Tests/test_file_webp.py b/Tests/test_file_webp.py
index 3832441c0..30938e971 100644
--- a/Tests/test_file_webp.py
+++ b/Tests/test_file_webp.py
@@ -233,4 +233,15 @@ class TestFileWebp:
im.save(out_webp, save_all=True)
with Image.open(out_webp) as reloaded:
+ reloaded.load()
assert reloaded.info["duration"] == 1000
+
+ def test_roundtrip_rgba_palette(self, tmp_path):
+ temp_file = str(tmp_path / "temp.webp")
+ im = Image.new("RGBA", (1, 1)).convert("P")
+ assert im.mode == "P"
+ assert im.palette.mode == "RGBA"
+ im.save(temp_file)
+
+ with Image.open(temp_file) as im:
+ assert im.getpixel((0, 0)) == (0, 0, 0, 0)
diff --git a/Tests/test_file_webp_metadata.py b/Tests/test_file_webp_metadata.py
index 037479f9f..dd47be8b2 100644
--- a/Tests/test_file_webp_metadata.py
+++ b/Tests/test_file_webp_metadata.py
@@ -118,7 +118,10 @@ def test_getxmp():
with Image.open("Tests/images/flower2.webp") as im:
if ElementTree is None:
- with pytest.warns(UserWarning):
+ with pytest.warns(
+ UserWarning,
+ match="XMP data cannot be read without defusedxml dependency",
+ ):
assert im.getxmp() == {}
else:
assert (
diff --git a/Tests/test_image.py b/Tests/test_image.py
index 7df1916ef..83dac7080 100644
--- a/Tests/test_image.py
+++ b/Tests/test_image.py
@@ -638,8 +638,8 @@ class TestImage:
im.remap_palette(None)
def test_remap_palette_transparency(self):
- im = Image.new("P", (1, 2))
- im.putpixel((0, 1), 1)
+ im = Image.new("P", (1, 2), (0, 0, 0))
+ im.putpixel((0, 1), (255, 0, 0))
im.info["transparency"] = 0
im_remapped = im.remap_palette([1, 0])
@@ -906,6 +906,31 @@ class TestImage:
im = Image.new("RGB", size)
assert im.tobytes() == b""
+ def test_has_transparency_data(self):
+ for mode in ("1", "L", "P", "RGB"):
+ im = Image.new(mode, (1, 1))
+ assert not im.has_transparency_data
+
+ for mode in ("LA", "La", "PA", "RGBA", "RGBa"):
+ im = Image.new(mode, (1, 1))
+ assert im.has_transparency_data
+
+ # P mode with "transparency" info
+ with Image.open("Tests/images/first_frame_transparency.gif") as im:
+ assert "transparency" in im.info
+ assert im.has_transparency_data
+
+ # RGB mode with "transparency" info
+ with Image.open("Tests/images/rgb_trns.png") as im:
+ assert "transparency" in im.info
+ assert im.has_transparency_data
+
+ # P mode with RGBA palette
+ im = Image.new("RGBA", (1, 1)).convert("P")
+ assert im.mode == "P"
+ assert im.palette.mode == "RGBA"
+ assert im.has_transparency_data
+
def test_apply_transparency(self):
im = Image.new("P", (1, 1))
im.putpalette((0, 0, 0, 1, 1, 1))
diff --git a/Tests/test_image_access.py b/Tests/test_image_access.py
index c9db3aee7..2b4fb7733 100644
--- a/Tests/test_image_access.py
+++ b/Tests/test_image_access.py
@@ -130,9 +130,16 @@ class TestImageGetPixel(AccessTest):
bands = Image.getmodebands(mode)
if bands == 1:
return 1
+ if mode in ("BGR;15", "BGR;16"):
+ # These modes have less than 8 bits per band
+ # So (1, 2, 3) cannot be roundtripped
+ return (16, 32, 49)
return tuple(range(1, bands + 1))
def check(self, mode, expected_color=None):
+ if self._need_cffi_access and mode.startswith("BGR;"):
+ pytest.skip("Support not added to deprecated module for BGR;* modes")
+
if not expected_color:
expected_color = self.color(mode)
@@ -203,6 +210,9 @@ class TestImageGetPixel(AccessTest):
"F",
"P",
"PA",
+ "BGR;15",
+ "BGR;16",
+ "BGR;24",
"RGB",
"RGBA",
"RGBX",
@@ -213,6 +223,10 @@ class TestImageGetPixel(AccessTest):
def test_basic(self, mode):
self.check(mode)
+ def test_list(self):
+ im = hopper()
+ assert im.getpixel([0, 0]) == (20, 20, 70)
+
@pytest.mark.parametrize("mode", ("I;16", "I;16B"))
@pytest.mark.parametrize(
"expected_color", (2**15 - 1, 2**15, 2**15 + 1, 2**16 - 1)
diff --git a/Tests/test_image_convert.py b/Tests/test_image_convert.py
index 01a182cf1..f5775f09c 100644
--- a/Tests/test_image_convert.py
+++ b/Tests/test_image_convert.py
@@ -117,11 +117,11 @@ def test_trns_p(tmp_path):
f = str(tmp_path / "temp.png")
im_l = im.convert("L")
- assert im_l.info["transparency"] == 1 # undone
+ assert im_l.info["transparency"] == 0
im_l.save(f)
im_rgb = im.convert("RGB")
- assert im_rgb.info["transparency"] == (0, 1, 2) # undone
+ assert im_rgb.info["transparency"] == (0, 0, 0)
im_rgb.save(f)
diff --git a/Tests/test_image_putdata.py b/Tests/test_image_putdata.py
index 0e6293349..4e40aec74 100644
--- a/Tests/test_image_putdata.py
+++ b/Tests/test_image_putdata.py
@@ -76,6 +76,15 @@ def test_mode_F():
assert list(im.getdata()) == target
+@pytest.mark.parametrize("mode", ("BGR;15", "BGR;16", "BGR;24"))
+def test_mode_BGR(mode):
+ data = [(16, 32, 49), (32, 32, 98)]
+ im = Image.new(mode, (1, 2))
+ im.putdata(data)
+
+ assert list(im.getdata()) == data
+
+
def test_array_B():
# shouldn't segfault
# see https://github.com/python-pillow/Pillow/issues/1008
diff --git a/Tests/test_image_putpalette.py b/Tests/test_image_putpalette.py
index 665e08a7e..376553344 100644
--- a/Tests/test_image_putpalette.py
+++ b/Tests/test_image_putpalette.py
@@ -84,3 +84,14 @@ def test_rgba_palette(mode, palette):
im.putpalette(palette, mode)
assert im.getpalette() == [1, 2, 3]
assert im.palette.colors == {(1, 2, 3, 4): 0}
+
+
+def test_empty_palette():
+ im = Image.new("P", (1, 1))
+ assert im.getpalette() == []
+
+
+def test_undefined_palette_index():
+ im = Image.new("P", (1, 1), 3)
+ im.putpalette((1, 2, 3))
+ assert im.convert("RGB").getpixel((0, 0)) == (0, 0, 0)
diff --git a/Tests/test_imagedraw.py b/Tests/test_imagedraw.py
index e59ad5d43..4052c41ff 100644
--- a/Tests/test_imagedraw.py
+++ b/Tests/test_imagedraw.py
@@ -587,6 +587,18 @@ def test_point(points):
assert_image_equal_tofile(im, "Tests/images/imagedraw_point.png")
+def test_point_I16():
+ # Arrange
+ im = Image.new("I;16", (1, 1))
+ draw = ImageDraw.Draw(im)
+
+ # Act
+ draw.point((0, 0), fill=0x1234)
+
+ # Assert
+ assert im.getpixel((0, 0)) == 0x1234
+
+
@pytest.mark.parametrize("points", POINTS)
def test_polygon(points):
# Arrange
@@ -733,7 +745,7 @@ def test_rectangle_I16(bbox):
draw = ImageDraw.Draw(im)
# Act
- draw.rectangle(bbox, fill="black", outline="green")
+ draw.rectangle(bbox, outline=0xFFFF)
# Assert
assert_image_equal_tofile(im.convert("I"), "Tests/images/imagedraw_rectangle_I.png")
diff --git a/Tests/test_imagefont.py b/Tests/test_imagefont.py
index 7121530db..f2b7dedf0 100644
--- a/Tests/test_imagefont.py
+++ b/Tests/test_imagefont.py
@@ -141,7 +141,9 @@ def test_I16(font):
draw = ImageDraw.Draw(im)
txt = "Hello World!"
- draw.text((10, 10), txt, font=font)
+ draw.text((10, 10), txt, fill=0xFFFE, font=font)
+
+ assert im.getpixel((12, 14)) == 0xFFFE
target = "Tests/images/transparent_background_text_L.png"
assert_image_similar_tofile(im.convert("L"), target, 0.01)
diff --git a/Tests/test_imageops.py b/Tests/test_imageops.py
index b05785be0..6d153ccea 100644
--- a/Tests/test_imageops.py
+++ b/Tests/test_imageops.py
@@ -39,6 +39,9 @@ def test_sanity():
ImageOps.contain(hopper("L"), (128, 128))
ImageOps.contain(hopper("RGB"), (128, 128))
+ ImageOps.cover(hopper("L"), (128, 128))
+ ImageOps.cover(hopper("RGB"), (128, 128))
+
ImageOps.crop(hopper("L"), 1)
ImageOps.crop(hopper("RGB"), 1)
@@ -119,6 +122,20 @@ def test_contain_round():
assert new_im.height == 5
+@pytest.mark.parametrize(
+ "image_name, expected_size",
+ (
+ ("colr_bungee.png", (1024, 256)), # landscape
+ ("imagedraw_stroke_multiline.png", (256, 640)), # portrait
+ ("hopper.png", (256, 256)), # square
+ ),
+)
+def test_cover(image_name, expected_size):
+ with Image.open("Tests/images/" + image_name) as im:
+ new_im = ImageOps.cover(im, (256, 256))
+ assert new_im.size == expected_size
+
+
def test_pad():
# Same ratio
im = hopper()
diff --git a/Tests/test_lib_pack.py b/Tests/test_lib_pack.py
index f7812f62b..2a4d9acf4 100644
--- a/Tests/test_lib_pack.py
+++ b/Tests/test_lib_pack.py
@@ -340,6 +340,17 @@ class TestLibUnpack:
self.assert_unpack("RGB", "G;16N", 2, (0, 1, 0), (0, 3, 0), (0, 5, 0))
self.assert_unpack("RGB", "B;16N", 2, (0, 0, 1), (0, 0, 3), (0, 0, 5))
+ self.assert_unpack(
+ "RGB", "CMYK", 4, (250, 249, 248), (242, 241, 240), (234, 233, 233)
+ )
+
+ def test_BGR(self):
+ self.assert_unpack("BGR;15", "BGR;15", 3, (8, 131, 0), (24, 0, 8), (41, 131, 8))
+ self.assert_unpack(
+ "BGR;16", "BGR;16", 3, (8, 64, 0), (24, 129, 0), (41, 194, 0)
+ )
+ self.assert_unpack("BGR;24", "BGR;24", 3, (1, 2, 3), (4, 5, 6), (7, 8, 9))
+
def test_RGBA(self):
self.assert_unpack("RGBA", "LA", 2, (1, 1, 1, 2), (3, 3, 3, 4), (5, 5, 5, 6))
self.assert_unpack(
diff --git a/_custom_build/backend.py b/_custom_build/backend.py
old mode 100755
new mode 100644
diff --git a/depends/install_imagequant.sh b/depends/install_imagequant.sh
index fd6000ee1..ab94875d8 100755
--- a/depends/install_imagequant.sh
+++ b/depends/install_imagequant.sh
@@ -1,7 +1,7 @@
#!/bin/bash
# install libimagequant
-archive=libimagequant-4.2.0
+archive=libimagequant-4.2.1
./download-and-extract.sh $archive https://raw.githubusercontent.com/python-pillow/pillow-depends/main/$archive.tar.gz
diff --git a/depends/install_raqm.sh b/depends/install_raqm.sh
index 24c1f9c30..070ba23a1 100755
--- a/depends/install_raqm.sh
+++ b/depends/install_raqm.sh
@@ -11,4 +11,3 @@ pushd $archive
meson build --prefix=/usr && sudo ninja -C build install
popd
-
diff --git a/depends/install_raqm_cmake.sh b/depends/install_raqm_cmake.sh
index 7d2c399df..37d9d1160 100755
--- a/depends/install_raqm_cmake.sh
+++ b/depends/install_raqm_cmake.sh
@@ -15,4 +15,3 @@ make && sudo make install
cd ..
popd
-
diff --git a/depends/install_webp.sh b/depends/install_webp.sh
index 4636aab43..6f867ab37 100755
--- a/depends/install_webp.sh
+++ b/depends/install_webp.sh
@@ -1,7 +1,7 @@
#!/bin/bash
# install webp
-archive=libwebp-1.3.1
+archive=libwebp-1.3.2
./download-and-extract.sh $archive https://raw.githubusercontent.com/python-pillow/pillow-depends/main/$archive.tar.gz
diff --git a/depends/termux.sh b/depends/termux.sh
index 1acc09c44..d437029fd 100755
--- a/depends/termux.sh
+++ b/depends/termux.sh
@@ -2,4 +2,3 @@
pkg install -y python ndk-sysroot clang make \
libjpeg-turbo
-
diff --git a/docs/about.rst b/docs/about.rst
index 03829c133..872ac0ea6 100644
--- a/docs/about.rst
+++ b/docs/about.rst
@@ -12,7 +12,7 @@ The fork author's goal is to foster and support active development of PIL throug
.. _GitHub Actions: https://github.com/python-pillow/Pillow/actions
.. _AppVeyor: https://ci.appveyor.com/project/Python-pillow/pillow
-.. _Travis CI: https://app.travis-ci.com/github/python-pillow/pillow-wheels
+.. _Travis CI: https://app.travis-ci.com/github/python-pillow/Pillow
.. _GitHub: https://github.com/python-pillow/Pillow
.. _Python Package Index: https://pypi.org/project/Pillow/
diff --git a/docs/conf.py b/docs/conf.py
index a2c825292..7dffcfae2 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -318,7 +318,7 @@ def setup(app):
linkcheck_allowed_redirects = {
- r"https://bestpractices.coreinfrastructure.org/projects/6331": r"https://bestpractices.coreinfrastructure.org/en/.*", # noqa: E501
+ r"https://www.bestpractices.dev/projects/6331": r"https://www.bestpractices.dev/en/.*", # noqa: E501
r"https://badges.gitter.im/python-pillow/Pillow.svg": r"https://badges.gitter.im/repo.svg", # noqa: E501
r"https://gitter.im/python-pillow/Pillow?.*": r"https://app.gitter.im/#/room/#python-pillow_Pillow:gitter.im?.*", # noqa: E501
r"https://pillow.readthedocs.io/?badge=latest": r"https://pillow.readthedocs.io/en/stable/?badge=latest", # noqa: E501
diff --git a/docs/example/image_thumbnail.png b/docs/example/image_thumbnail.png
new file mode 100644
index 000000000..293b05794
Binary files /dev/null and b/docs/example/image_thumbnail.png differ
diff --git a/docs/example/imageops_contain.png b/docs/example/imageops_contain.png
new file mode 100644
index 000000000..293b05794
Binary files /dev/null and b/docs/example/imageops_contain.png differ
diff --git a/docs/example/imageops_cover.png b/docs/example/imageops_cover.png
new file mode 100644
index 000000000..929e1d874
Binary files /dev/null and b/docs/example/imageops_cover.png differ
diff --git a/docs/example/imageops_fit.png b/docs/example/imageops_fit.png
new file mode 100644
index 000000000..13a3d5e3f
Binary files /dev/null and b/docs/example/imageops_fit.png differ
diff --git a/docs/example/imageops_pad.png b/docs/example/imageops_pad.png
new file mode 100644
index 000000000..69649d6e5
Binary files /dev/null and b/docs/example/imageops_pad.png differ
diff --git a/docs/handbook/image-file-formats.rst b/docs/handbook/image-file-formats.rst
index 2a42bdacb..d5d95d3ce 100644
--- a/docs/handbook/image-file-formats.rst
+++ b/docs/handbook/image-file-formats.rst
@@ -63,8 +63,35 @@ DDS
^^^
DDS is a popular container texture format used in video games and natively supported
-by DirectX. Uncompressed RGB and RGBA can be read, and (since 8.3.0) written. DXT1,
-DXT3 (since 3.4.0) and DXT5 pixel formats can be read, only in ``RGBA`` mode.
+by DirectX.
+
+DXT1 and DXT5 pixel formats can be read, only in ``RGBA`` mode.
+
+.. versionadded:: 3.4.0
+ DXT3 images can be read in ``RGB`` mode and DX10 images can be read in
+ ``RGB`` and ``RGBA`` mode.
+
+.. versionadded:: 6.0.0
+ Uncompressed ``RGBA`` images can be read.
+
+
+.. versionadded:: 8.3.0
+ BC5S images can be opened in ``RGB`` mode, and uncompressed ``RGB`` images
+ can be read. Uncompressed data can also be saved to image files.
+
+
+.. versionadded:: 9.3.0
+ ATI1 images can be opened in ``L`` mode and ATI2 images can be opened in
+ ``RGB`` mode.
+
+.. versionadded:: 9.4.0
+ Uncompressed ``L`` ("luminance") and ``LA`` images can be opened and saved.
+
+
+.. versionadded:: 10.1.0
+ BC5U can be read in ``RGB`` mode, and 8-bit color indexed images can be read
+ in ``P`` mode.
+
DIB
^^^
@@ -88,8 +115,13 @@ in ``L``, ``RGB`` and ``CMYK`` modes.
Loading
~~~~~~~
+To use Ghostscript, Pillow searches for the "gs" executable. On Windows, it
+also searches for "gswin32c" and "gswin64c". To customise this behaviour,
+``EpsImagePlugin.gs_binary = "gswin64"`` will set the name of the executable to
+use. ``EpsImagePlugin.gs_binary = False`` will prevent Ghostscript use.
+
If Ghostscript is available, you can call the :py:meth:`~PIL.Image.Image.load`
-method with the following parameters to affect how Ghostscript renders the EPS
+method with the following parameters to affect how Ghostscript renders the EPS.
**scale**
Affects the scale of the resultant rasterized image. If the EPS suggests
diff --git a/docs/handbook/tutorial.rst b/docs/handbook/tutorial.rst
index 50133f15e..a65443dcb 100644
--- a/docs/handbook/tutorial.rst
+++ b/docs/handbook/tutorial.rst
@@ -268,6 +268,37 @@ true, to provide for the same changes to the image's size.
A more general form of image transformations can be carried out via the
:py:meth:`~PIL.Image.Image.transform` method.
+Relative resizing
+^^^^^^^^^^^^^^^^^
+
+Instead of calculating the size of the new image when resizing, you can also
+choose to resize relative to a given size.
+
+::
+
+ from PIL import Image, ImageOps
+ size = (100, 150)
+ with Image.open("Tests/images/hopper.png") as im:
+ ImageOps.contain(im, size).save("imageops_contain.png")
+ ImageOps.cover(im, size).save("imageops_cover.png")
+ ImageOps.fit(im, size).save("imageops_fit.png")
+ ImageOps.pad(im, size, color="#f00").save("imageops_pad.png")
+
+ # thumbnail() can also be used,
+ # but will modify the image object in place
+ im.thumbnail(size)
+ im.save("imageops_thumbnail.png")
+
++----------------+-------------------------------------------+--------------------------------------------+------------------------------------------+----------------------------------------+----------------------------------------+
+| | :py:meth:`~PIL.Image.Image.thumbnail` | :py:meth:`~PIL.ImageOps.contain` | :py:meth:`~PIL.ImageOps.cover` | :py:meth:`~PIL.ImageOps.fit` | :py:meth:`~PIL.ImageOps.pad` |
++================+===========================================+============================================+==========================================+========================================+========================================+
+|Given size | ``(150, 100)`` | ``(150, 100)`` | ``(150, 150)`` | ``(150, 100)`` | ``(150, 100)`` |
++----------------+-------------------------------------------+--------------------------------------------+------------------------------------------+----------------------------------------+----------------------------------------+
+|Resulting image | .. image:: ../example/image_thumbnail.png | .. image:: ../example/imageops_contain.png | .. image:: ../example/imageops_cover.png | .. image:: ../example/imageops_fit.png | .. image:: ../example/imageops_pad.png |
++----------------+-------------------------------------------+--------------------------------------------+------------------------------------------+----------------------------------------+----------------------------------------+
+|Resulting size | ``100×100`` | ``100×100`` | ``150×150`` | ``150×100`` | ``150×100`` |
++----------------+-------------------------------------------+--------------------------------------------+------------------------------------------+----------------------------------------+----------------------------------------+
+
.. _color-transforms:
Color transforms
diff --git a/docs/index.rst b/docs/index.rst
index 418844ba7..4f577fe9c 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -37,12 +37,12 @@ Pillow for enterprise is available via the Tidelift Subscription. `Learn more 9.5.0 no longer includes 32-bit wheels.
+
We provide Pillow binaries for Windows compiled for the matrix of
supported Pythons in 64-bit versions in the wheel format. These binaries include
support for all optional libraries except libimagequant and libxcb. Raqm support
@@ -154,7 +156,7 @@ Many of Pillow's features require external libraries:
* **libtiff** provides compressed TIFF functionality
- * Pillow has been tested with libtiff versions **3.x** and **4.0-4.5.1**
+ * Pillow has been tested with libtiff versions **3.x** and **4.0-4.6.0**
* **libfreetype** provides type related services
@@ -180,7 +182,7 @@ Many of Pillow's features require external libraries:
* **libimagequant** provides improved color quantization
- * Pillow has been tested with libimagequant **2.6-4.2**
+ * Pillow has been tested with libimagequant **2.6-4.2.1**
* Libimagequant is licensed GPLv3, which is more restrictive than
the Pillow license, therefore we will not be distributing binaries
with libimagequant support enabled.
@@ -498,11 +500,13 @@ These platforms have been reported to work at the versions mentioned.
| Operating system | | Tested Python | | Latest tested | | Tested |
| | | versions | | Pillow version | | processors |
+==================================+===========================+==================+==============+
-| macOS 13 Ventura | 3.8, 3.9, 3.10, 3.11 | 10.0.0 |arm |
-| +---------------------------+------------------+ |
-| | 3.7, 3.8, 3.9, 3.10, 3.11 | 9.5.0 | |
+| macOS 14 Sonoma | 3.8, 3.9, 3.10, 3.11 | 10.0.1 |arm |
+----------------------------------+---------------------------+------------------+--------------+
-| macOS 12 Big Sur | 3.7, 3.8, 3.9, 3.10, 3.11 | 9.3.0 |arm |
+| macOS 13 Ventura | 3.8, 3.9, 3.10, 3.11 | 10.0.1 |arm |
+| +---------------------------+------------------+ |
+| | 3.7 | 9.5.0 | |
++----------------------------------+---------------------------+------------------+--------------+
+| macOS 12 Monterey | 3.7, 3.8, 3.9, 3.10, 3.11 | 9.3.0 |arm |
+----------------------------------+---------------------------+------------------+--------------+
| macOS 11 Big Sur | 3.7, 3.8, 3.9, 3.10 | 8.4.0 |arm |
| +---------------------------+------------------+--------------+
diff --git a/docs/newer-versions.csv b/docs/newer-versions.csv
index 1457d59de..e21caf520 100644
--- a/docs/newer-versions.csv
+++ b/docs/newer-versions.csv
@@ -5,4 +5,4 @@ Pillow 9.3 - 9.5,,Yes,Yes,Yes,Yes,Yes,,
Pillow 9.0 - 9.2,,,Yes,Yes,Yes,Yes,,
Pillow 8.3.2 - 8.4,,,Yes,Yes,Yes,Yes,Yes,
Pillow 8.0 - 8.3.1,,,,Yes,Yes,Yes,Yes,
-Pillow 7.0 - 7.2,,,,,Yes,Yes,Yes,Yes
\ No newline at end of file
+Pillow 7.0 - 7.2,,,,,Yes,Yes,Yes,Yes
diff --git a/docs/older-versions.csv b/docs/older-versions.csv
index 6058f0524..aa696bc18 100644
--- a/docs/older-versions.csv
+++ b/docs/older-versions.csv
@@ -5,4 +5,4 @@ Pillow 5.2 - 5.4,,Yes,Yes,Yes,Yes,,,Yes,,,
Pillow 5.0 - 5.1,,,Yes,Yes,Yes,,,Yes,,,
Pillow 4,,,Yes,Yes,Yes,Yes,,Yes,,,
Pillow 2 - 3,,,,Yes,Yes,Yes,Yes,Yes,Yes,,
-Pillow < 2,,,,,,,,Yes,Yes,Yes,Yes
\ No newline at end of file
+Pillow < 2,,,,,,,,Yes,Yes,Yes,Yes
diff --git a/docs/reference/Image.rst b/docs/reference/Image.rst
index 41d3b8fce..4281b182c 100644
--- a/docs/reference/Image.rst
+++ b/docs/reference/Image.rst
@@ -93,10 +93,14 @@ Generating images
Registering plugins
^^^^^^^^^^^^^^^^^^^
+.. autofunction:: preinit
+.. autofunction:: init
+
.. note::
- These functions are for use by plugin authors. Application authors can
- ignore them.
+ These functions are for use by plugin authors. They are called when a
+ plugin is loaded as part of :py:meth:`~preinit()` or :py:meth:`~init()`.
+ Application authors can ignore them.
.. autofunction:: register_open
.. autofunction:: register_mime
@@ -347,6 +351,8 @@ Instances of the :py:class:`Image` class have the following attributes:
.. seealso:: :attr:`~Image.is_animated`, :func:`~Image.seek` and :func:`~Image.tell`
+.. autoattribute:: PIL.Image.Image.has_transparency_data
+
Classes
-------
diff --git a/docs/reference/ImageOps.rst b/docs/reference/ImageOps.rst
index d1c43cf60..b4cf89f26 100644
--- a/docs/reference/ImageOps.rst
+++ b/docs/reference/ImageOps.rst
@@ -12,14 +12,11 @@ only work on L and RGB images.
.. autofunction:: autocontrast
.. autofunction:: colorize
-.. autofunction:: contain
-.. autofunction:: pad
.. autofunction:: crop
.. autofunction:: scale
.. autofunction:: deform
.. autofunction:: equalize
.. autofunction:: expand
-.. autofunction:: fit
.. autofunction:: flip
.. autofunction:: grayscale
.. autofunction:: invert
@@ -27,3 +24,38 @@ only work on L and RGB images.
.. autofunction:: posterize
.. autofunction:: solarize
.. autofunction:: exif_transpose
+
+.. _relative-resize:
+
+Resize relative to a given size
+-------------------------------
+
+::
+
+ from PIL import Image, ImageOps
+ size = (100, 150)
+ with Image.open("Tests/images/hopper.png") as im:
+ ImageOps.contain(im, size).save("imageops_contain.png")
+ ImageOps.cover(im, size).save("imageops_cover.png")
+ ImageOps.fit(im, size).save("imageops_fit.png")
+ ImageOps.pad(im, size, color="#f00").save("imageops_pad.png")
+
+ # thumbnail() can also be used,
+ # but will modify the image object in place
+ im.thumbnail(size)
+ im.save("imageops_thumbnail.png")
+
++----------------+-------------------------------------------+--------------------------------------------+------------------------------------------+----------------------------------------+----------------------------------------+
+| | :py:meth:`~PIL.Image.Image.thumbnail` | :py:meth:`~PIL.ImageOps.contain` | :py:meth:`~PIL.ImageOps.cover` | :py:meth:`~PIL.ImageOps.fit` | :py:meth:`~PIL.ImageOps.pad` |
++================+===========================================+============================================+==========================================+========================================+========================================+
+|Given size | ``(150, 100)`` | ``(150, 100)`` | ``(150, 150)`` | ``(150, 100)`` | ``(150, 100)`` |
++----------------+-------------------------------------------+--------------------------------------------+------------------------------------------+----------------------------------------+----------------------------------------+
+|Resulting image | .. image:: ../example/image_thumbnail.png | .. image:: ../example/imageops_contain.png | .. image:: ../example/imageops_cover.png | .. image:: ../example/imageops_fit.png | .. image:: ../example/imageops_pad.png |
++----------------+-------------------------------------------+--------------------------------------------+------------------------------------------+----------------------------------------+----------------------------------------+
+|Resulting size | ``100×100`` | ``100×100`` | ``150×150`` | ``150×100`` | ``150×100`` |
++----------------+-------------------------------------------+--------------------------------------------+------------------------------------------+----------------------------------------+----------------------------------------+
+
+.. autofunction:: contain
+.. autofunction:: cover
+.. autofunction:: fit
+.. autofunction:: pad
diff --git a/docs/releasenotes/10.0.1.rst b/docs/releasenotes/10.0.1.rst
new file mode 100644
index 000000000..6ac30e7fc
--- /dev/null
+++ b/docs/releasenotes/10.0.1.rst
@@ -0,0 +1,14 @@
+10.0.1
+------
+
+Security
+========
+
+This release addresses :cve:`2023-4863`, by providing an updated install script and
+updated wheels to include libwebp 1.3.2, preventing a potential heap buffer overflow
+in WebP.
+
+Updated tests to pass with latest zlib version
+==============================================
+
+The release of zlib 1.3 caused one of the tests in the Pillow test suite to fail.
diff --git a/docs/releasenotes/10.1.0.rst b/docs/releasenotes/10.1.0.rst
index da5153cce..6d3c72f55 100644
--- a/docs/releasenotes/10.1.0.rst
+++ b/docs/releasenotes/10.1.0.rst
@@ -13,42 +13,73 @@ not about removing existing functionality, but instead about raising an
explicit error to prevent later consequences. The ``convert`` method is the
correct way to change an image's mode.
-Deprecations
-============
-
-TODO
-^^^^
-
-TODO
-
API Changes
===========
-TODO
-^^^^
+Accept a list in getpixel()
+^^^^^^^^^^^^^^^^^^^^^^^^^^^
-TODO
+:py:meth:`~PIL.Image.Image.getpixel` now accepts a list of coordinates, as well
+as a tuple. ::
+
+ from PIL import Image
+ im = Image.new("RGB", (1, 1))
+ im.getpixel((0, 0))
+ im.getpixel([0, 0])
+
+BoxBlur and GaussianBlur allow for different x and y radii
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+:py:class:`~PIL.ImageFilter.BoxBlur` and
+:py:class:`~PIL.ImageFilter.GaussianBlur` now allow a sequence of x and y radii
+to be specified, rather than a single number for both dimensions. ::
+
+ from PIL import ImageFilter
+ ImageFilter.BoxBlur((2, 5))
+ ImageFilter.GaussianBlur((2, 5))
API Additions
=============
-TODO
-^^^^
+ImageOps.cover
+^^^^^^^^^^^^^^
-TODO
+Returns a resized version of the image, so that the requested size is covered,
+while maintaining the original aspect ratio.
-Security
-========
+See :ref:`relative-resize` for a comparison between this and similar ``ImageOps``
+methods.
-TODO
-^^^^
+EpsImagePlugin.gs_binary
+^^^^^^^^^^^^^^^^^^^^^^^^
-TODO
+``EpsImagePlugin.gs_windows_binary`` stores the name of the Ghostscript
+executable on Windows. ``EpsImagePlugin.gs_binary`` has now been added for all
+platforms, and can be used to customise the name of the executable, or disable
+use entirely through ``EpsImagePlugin.gs_binary = False``.
+
+has_transparency_data
+^^^^^^^^^^^^^^^^^^^^^
+
+Images now have :py:attr:`~PIL.Image.Image.has_transparency_data` to indicate
+whether the image has transparency data, whether in the form of an alpha
+channel, a palette with an alpha channel, or a "transparency" key in the
+:py:attr:`~PIL.Image.Image.info` dictionary.
+
+Even if this attribute is true, the image might still appear solid, if all of
+the values shown within are opaque.
Other Changes
=============
-TODO
-^^^^
+Added support for DDS BC5U and 8-bit color indexed images
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-TODO
+Support has been added to read BC5U DDS files as RGB images, and
+PALETTEINDEXED8 DDS files as P mode images.
+
+Support reading signed 8-bit YCbCr TIFF images
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+TIFF images with unsigned integer data, 8 bits per sample and a photometric
+interpretation of YCbCr can now be read.
diff --git a/docs/releasenotes/3.0.0.rst b/docs/releasenotes/3.0.0.rst
index 67569d337..e8eada73c 100644
--- a/docs/releasenotes/3.0.0.rst
+++ b/docs/releasenotes/3.0.0.rst
@@ -49,4 +49,3 @@ The external dependencies on libjpeg and zlib are now required by default.
If the headers or libraries are not found, then installation will abort
with an error. This behaviour can be disabled with the ``--disable-libjpeg``
and ``--disable-zlib`` flags.
-
diff --git a/docs/releasenotes/3.3.2.rst b/docs/releasenotes/3.3.2.rst
index 68a09a3c8..8845b976a 100644
--- a/docs/releasenotes/3.3.2.rst
+++ b/docs/releasenotes/3.3.2.rst
@@ -34,7 +34,3 @@ image size can lead to a smaller allocation than expected, leading to
arbitrary writes.
This issue was found by Cris Neckar at Divergent Security.
-
-
-
-
diff --git a/docs/releasenotes/4.1.1.rst b/docs/releasenotes/4.1.1.rst
index 7aa3c1fbf..1b5757015 100644
--- a/docs/releasenotes/4.1.1.rst
+++ b/docs/releasenotes/4.1.1.rst
@@ -20,5 +20,3 @@ CPython 3.6.1 to not work on installations of C-Python 3.6.0. This fix
undefines PySlice_GetIndicesEx if it exists to restore compatibility
with both 3.6.0 and 3.6.1. See https://bugs.python.org/issue29943 for
more details.
-
-
diff --git a/docs/releasenotes/4.2.1.rst b/docs/releasenotes/4.2.1.rst
index c9e953da4..0730936fe 100644
--- a/docs/releasenotes/4.2.1.rst
+++ b/docs/releasenotes/4.2.1.rst
@@ -8,4 +8,3 @@ Fixed Windows PyPy Build
A change in the 4.2.0 cycle broke the Windows PyPy build. This has
been fixed, and PyPy is now part of the Windows CI matrix.
-
diff --git a/docs/releasenotes/8.0.0.rst b/docs/releasenotes/8.0.0.rst
index fe2658047..00c691a74 100644
--- a/docs/releasenotes/8.0.0.rst
+++ b/docs/releasenotes/8.0.0.rst
@@ -175,6 +175,3 @@ Dark theme for docs
^^^^^^^^^^^^^^^^^^^
The https://pillow.readthedocs.io documentation will use a dark theme if the user has requested the system use one. Uses the ``prefers-color-scheme`` CSS media query.
-
-
-
diff --git a/docs/releasenotes/index.rst b/docs/releasenotes/index.rst
index a843ddd72..1b1c353fd 100644
--- a/docs/releasenotes/index.rst
+++ b/docs/releasenotes/index.rst
@@ -15,6 +15,7 @@ expected to be backported to earlier versions.
:maxdepth: 2
10.1.0
+ 10.0.1
10.0.0
9.5.0
9.4.0
diff --git a/src/PIL/BdfFontFile.py b/src/PIL/BdfFontFile.py
index 075d46290..161954831 100644
--- a/src/PIL/BdfFontFile.py
+++ b/src/PIL/BdfFontFile.py
@@ -68,11 +68,11 @@ def bdf_char(f):
# followed by the width in x (BBw), height in y (BBh),
# and x and y displacement (BBxoff0, BByoff0)
# of the lower left corner from the origin of the character.
- width, height, x_disp, y_disp = [int(p) for p in props["BBX"].split()]
+ width, height, x_disp, y_disp = (int(p) for p in props["BBX"].split())
# The word DWIDTH
# followed by the width in x and y of the character in device pixels.
- dwx, dwy = [int(p) for p in props["DWIDTH"].split()]
+ dwx, dwy = (int(p) for p in props["DWIDTH"].split())
bbox = (
(dwx, dwy),
diff --git a/src/PIL/BlpImagePlugin.py b/src/PIL/BlpImagePlugin.py
index a5cfad5f4..398696d5c 100644
--- a/src/PIL/BlpImagePlugin.py
+++ b/src/PIL/BlpImagePlugin.py
@@ -419,9 +419,11 @@ class BLPEncoder(ImageFile.PyEncoder):
def _write_palette(self):
data = b""
palette = self.im.getpalette("RGBA", "RGBA")
- for i in range(256):
+ for i in range(len(palette) // 4):
r, g, b, a = palette[i * 4 : (i + 1) * 4]
data += struct.pack("<4B", b, g, r, a)
+ while len(data) < 256 * 4:
+ data += b"\x00" * 4
return data
def encode(self, bufsize):
@@ -442,7 +444,7 @@ class BLPEncoder(ImageFile.PyEncoder):
return len(data), 0, data
-def _save(im, fp, filename, save_all=False):
+def _save(im, fp, filename):
if im.mode != "P":
msg = "Unsupported BLP image mode"
raise ValueError(msg)
diff --git a/src/PIL/DdsImagePlugin.py b/src/PIL/DdsImagePlugin.py
index 1368ae24e..54f358c7f 100644
--- a/src/PIL/DdsImagePlugin.py
+++ b/src/PIL/DdsImagePlugin.py
@@ -13,7 +13,7 @@ Full text of the CC0 license:
import struct
from io import BytesIO
-from . import Image, ImageFile
+from . import Image, ImageFile, ImagePalette
from ._binary import o32le as o32
# Magic ("DDS ")
@@ -157,6 +157,10 @@ class DdsImageFile(ImageFile.ImageFile):
rawmode += masks[0xFF0000] + masks[0xFF00] + masks[0xFF]
self.tile = [("raw", (0, 0) + self.size, 0, (rawmode[::-1], 0, 1))]
+ elif pfflags & DDPF_PALETTEINDEXED8:
+ self._mode = "P"
+ self.palette = ImagePalette.raw("RGBA", self.fp.read(1024))
+ self.tile = [("raw", (0, 0) + self.size, 0, "L")]
else:
data_start = header_size + 4
n = 0
@@ -173,7 +177,7 @@ class DdsImageFile(ImageFile.ImageFile):
self.pixel_format = "BC4"
n = 4
self._mode = "L"
- elif fourcc == b"ATI2":
+ elif fourcc in (b"ATI2", b"BC5U"):
self.pixel_format = "BC5"
n = 5
self._mode = "RGB"
diff --git a/src/PIL/EpsImagePlugin.py b/src/PIL/EpsImagePlugin.py
index b96ce9603..9b2fce0ac 100644
--- a/src/PIL/EpsImagePlugin.py
+++ b/src/PIL/EpsImagePlugin.py
@@ -37,33 +37,39 @@ from ._deprecate import deprecate
split = re.compile(r"^%%([^:]*):[ \t]*(.*)[ \t]*$")
field = re.compile(r"^%[%!\w]([^:]*)[ \t]*$")
+gs_binary = None
gs_windows_binary = None
-if sys.platform.startswith("win"):
- import shutil
-
- for binary in ("gswin32c", "gswin64c", "gs"):
- if shutil.which(binary) is not None:
- gs_windows_binary = binary
- break
- else:
- gs_windows_binary = False
def has_ghostscript():
- if gs_windows_binary:
- return True
- if not sys.platform.startswith("win"):
- try:
- subprocess.check_call(["gs", "--version"], stdout=subprocess.DEVNULL)
- return True
- except OSError:
- # No Ghostscript
- pass
- return False
+ global gs_binary, gs_windows_binary
+ if gs_binary is None:
+ if sys.platform.startswith("win"):
+ if gs_windows_binary is None:
+ import shutil
+
+ for binary in ("gswin32c", "gswin64c", "gs"):
+ if shutil.which(binary) is not None:
+ gs_windows_binary = binary
+ break
+ else:
+ gs_windows_binary = False
+ gs_binary = gs_windows_binary
+ else:
+ try:
+ subprocess.check_call(["gs", "--version"], stdout=subprocess.DEVNULL)
+ gs_binary = "gs"
+ except OSError:
+ gs_binary = False
+ return gs_binary is not False
def Ghostscript(tile, size, fp, scale=1, transparency=False):
"""Render an image using Ghostscript"""
+ global gs_binary
+ if not has_ghostscript():
+ msg = "Unable to locate Ghostscript on paths"
+ raise OSError(msg)
# Unpack decoder tile
decoder, tile, offset, data = tile[0]
@@ -113,7 +119,7 @@ def Ghostscript(tile, size, fp, scale=1, transparency=False):
# Build Ghostscript command
command = [
- "gs",
+ gs_binary,
"-q", # quiet mode
"-g%dx%d" % size, # set output geometry (pixels)
"-r%fx%f" % res, # set input DPI (dots per inch)
@@ -132,19 +138,6 @@ def Ghostscript(tile, size, fp, scale=1, transparency=False):
"showpage",
]
- if gs_windows_binary is not None:
- if not gs_windows_binary:
- try:
- os.unlink(outfile)
- if infile_temp:
- os.unlink(infile_temp)
- except OSError:
- pass
-
- msg = "Unable to locate Ghostscript on paths"
- raise OSError(msg)
- command[0] = gs_windows_binary
-
# push data through Ghostscript
try:
startupinfo = None
@@ -233,7 +226,9 @@ class EpsImageFile(ImageFile.ImageFile):
byte_arr = bytearray(255)
bytes_mv = memoryview(byte_arr)
bytes_read = 0
- reading_comments = True
+ reading_header_comments = True
+ reading_trailer_comments = False
+ trailer_reached = False
def check_required_header_comments():
if "PS-Adobe" not in self.info:
@@ -243,6 +238,36 @@ class EpsImageFile(ImageFile.ImageFile):
msg = 'EPS header missing "%%BoundingBox" comment'
raise SyntaxError(msg)
+ def _read_comment(s):
+ nonlocal reading_trailer_comments
+ try:
+ m = split.match(s)
+ except re.error as e:
+ msg = "not an EPS file"
+ raise SyntaxError(msg) from e
+
+ if m:
+ k, v = m.group(1, 2)
+ self.info[k] = v
+ if k == "BoundingBox":
+ if v == "(atend)":
+ reading_trailer_comments = True
+ elif not self._size or (
+ trailer_reached and reading_trailer_comments
+ ):
+ try:
+ # Note: The DSC spec says that BoundingBox
+ # fields should be integers, but some drivers
+ # put floating point values there anyway.
+ box = [int(float(i)) for i in v.split()]
+ self._size = box[2] - box[0], box[3] - box[1]
+ self.tile = [
+ ("eps", (0, 0) + self.size, offset, (length, box))
+ ]
+ except Exception:
+ pass
+ return True
+
while True:
byte = self.fp.read(1)
if byte == b"":
@@ -265,9 +290,9 @@ class EpsImageFile(ImageFile.ImageFile):
msg = "not an EPS file"
raise SyntaxError(msg)
else:
- if reading_comments:
+ if reading_header_comments:
check_required_header_comments()
- reading_comments = False
+ reading_header_comments = False
# reset bytes_read so we can keep reading
# data until the end of the line
bytes_read = 0
@@ -275,7 +300,7 @@ class EpsImageFile(ImageFile.ImageFile):
bytes_read += 1
continue
- if reading_comments:
+ if reading_header_comments:
# Load EPS header
# if this line doesn't start with a "%",
@@ -283,33 +308,11 @@ class EpsImageFile(ImageFile.ImageFile):
# then we've reached the end of the header/comments
if byte_arr[0] != ord("%") or bytes_mv[:13] == b"%%EndComments":
check_required_header_comments()
- reading_comments = False
+ reading_header_comments = False
continue
s = str(bytes_mv[:bytes_read], "latin-1")
-
- try:
- m = split.match(s)
- except re.error as e:
- msg = "not an EPS file"
- raise SyntaxError(msg) from e
-
- if m:
- k, v = m.group(1, 2)
- self.info[k] = v
- if k == "BoundingBox":
- try:
- # Note: The DSC spec says that BoundingBox
- # fields should be integers, but some drivers
- # put floating point values there anyway.
- box = [int(float(i)) for i in v.split()]
- self._size = box[2] - box[0], box[3] - box[1]
- self.tile = [
- ("eps", (0, 0) + self.size, offset, (length, box))
- ]
- except Exception:
- pass
- else:
+ if not _read_comment(s):
m = field.match(s)
if m:
k = m.group(1)
@@ -339,9 +342,9 @@ class EpsImageFile(ImageFile.ImageFile):
# data start identifier (the image data follows after a single line
# consisting only of this quoted value)
image_data_values = byte_arr[11:bytes_read].split(None, 7)
- columns, rows, bit_depth, mode_id = [
+ columns, rows, bit_depth, mode_id = (
int(value) for value in image_data_values[:4]
- ]
+ )
if bit_depth == 1:
self._mode = "1"
@@ -355,7 +358,18 @@ class EpsImageFile(ImageFile.ImageFile):
self._size = columns, rows
return
+ elif trailer_reached and reading_trailer_comments:
+ # Load EPS trailer
+ # if this line starts with "%%EOF",
+ # then we've reached the end of the file
+ if bytes_mv[:5] == b"%%EOF":
+ break
+
+ s = str(bytes_mv[:bytes_read], "latin-1")
+ _read_comment(s)
+ elif bytes_mv[:9] == b"%%Trailer":
+ trailer_reached = True
bytes_read = 0
check_required_header_comments()
diff --git a/src/PIL/Image.py b/src/PIL/Image.py
index 476ed0122..1adca9ad5 100644
--- a/src/PIL/Image.py
+++ b/src/PIL/Image.py
@@ -298,7 +298,11 @@ _initialized = 0
def preinit():
- """Explicitly load standard file format drivers."""
+ """
+ Explicitly loads BMP, GIF, JPEG, PPM and PPM file format drivers.
+
+ It is called when opening or saving images.
+ """
global _initialized
if _initialized >= 1:
@@ -334,11 +338,6 @@ def preinit():
assert PngImagePlugin
except ImportError:
pass
- # try:
- # import TiffImagePlugin
- # assert TiffImagePlugin
- # except ImportError:
- # pass
_initialized = 1
@@ -347,6 +346,9 @@ def init():
"""
Explicitly initializes the Python Imaging Library. This function
loads all available file format drivers.
+
+ It is called when opening or saving images if :py:meth:`~preinit()` is
+ insufficient, and by :py:meth:`~PIL.features.pilinfo`.
"""
global _initialized
@@ -913,7 +915,7 @@ class Image:
self.load()
- has_transparency = self.info.get("transparency") is not None
+ has_transparency = "transparency" in self.info
if not mode and self.mode == "P":
# determine default mode
if self.palette:
@@ -931,9 +933,9 @@ class Image:
msg = "illegal conversion"
raise ValueError(msg)
im = self.im.convert_matrix(mode, matrix)
- new = self._new(im)
+ new_im = self._new(im)
if has_transparency and self.im.bands == 3:
- transparency = new.info["transparency"]
+ transparency = new_im.info["transparency"]
def convert_transparency(m, v):
v = m[0] * v[0] + m[1] * v[1] + m[2] * v[2] + m[3] * 0.5
@@ -946,8 +948,8 @@ class Image:
convert_transparency(matrix[i * 4 : i * 4 + 4], transparency)
for i in range(0, len(transparency))
)
- new.info["transparency"] = transparency
- return new
+ new_im.info["transparency"] = transparency
+ return new_im
if mode == "P" and self.mode == "RGBA":
return self.quantize(colors)
@@ -978,7 +980,7 @@ class Image:
else:
# get the new transparency color.
# use existing conversions
- trns_im = Image()._new(core.new(self.mode, (1, 1)))
+ trns_im = new(self.mode, (1, 1))
if self.mode == "P":
trns_im.putpalette(self.palette)
if isinstance(t, tuple):
@@ -1019,23 +1021,25 @@ class Image:
if mode == "P" and palette == Palette.ADAPTIVE:
im = self.im.quantize(colors)
- new = self._new(im)
+ new_im = self._new(im)
from . import ImagePalette
- new.palette = ImagePalette.ImagePalette("RGB", new.im.getpalette("RGB"))
+ new_im.palette = ImagePalette.ImagePalette(
+ "RGB", new_im.im.getpalette("RGB")
+ )
if delete_trns:
# This could possibly happen if we requantize to fewer colors.
# The transparency would be totally off in that case.
- del new.info["transparency"]
+ del new_im.info["transparency"]
if trns is not None:
try:
- new.info["transparency"] = new.palette.getcolor(trns, new)
+ new_im.info["transparency"] = new_im.palette.getcolor(trns, new_im)
except Exception:
# if we can't make a transparent color, don't leave the old
# transparency hanging around to mess us up.
- del new.info["transparency"]
+ del new_im.info["transparency"]
warnings.warn("Couldn't allocate palette entry for transparency")
- return new
+ return new_im
if "LAB" in (self.mode, mode):
other_mode = mode if self.mode == "LAB" else self.mode
@@ -1072,7 +1076,7 @@ class Image:
if mode == "P" and palette != Palette.ADAPTIVE:
from . import ImagePalette
- new_im.palette = ImagePalette.ImagePalette("RGB", list(range(256)) * 3)
+ new_im.palette = ImagePalette.ImagePalette("RGB", im.getpalette("RGB"))
if delete_trns:
# crash fail if we leave a bytes transparency in an rgb/l mode.
del new_im.info["transparency"]
@@ -1383,7 +1387,7 @@ class Image:
def _getxmp(self, xmp_tags):
def get_name(tag):
- return tag.split("}")[1]
+ return re.sub("^{[^}]+}", "", tag)
def get_value(element):
value = {get_name(k): v for k, v in element.attrib.items()}
@@ -1529,6 +1533,24 @@ class Image:
rawmode = mode
return list(self.im.getpalette(mode, rawmode))
+ @property
+ def has_transparency_data(self) -> bool:
+ """
+ Determine if an image has transparency data, whether in the form of an
+ alpha channel, a palette with an alpha channel, or a "transparency" key
+ in the info dictionary.
+
+ Note the image might still appear solid, if all of the values shown
+ within are opaque.
+
+ :returns: A boolean.
+ """
+ return (
+ self.mode in ("LA", "La", "PA", "RGBA", "RGBa")
+ or (self.mode == "P" and self.palette.mode.endswith("A"))
+ or "transparency" in self.info
+ )
+
def apply_transparency(self):
"""
If a P mode image has a "transparency" key in the info dictionary,
@@ -1565,7 +1587,7 @@ class Image:
self.load()
if self.pyaccess:
return self.pyaccess.getpixel(xy)
- return self.im.getpixel(xy)
+ return self.im.getpixel(tuple(xy))
def getprojection(self):
"""
@@ -3000,7 +3022,7 @@ def frombuffer(mode, size, data, decoder_name="raw", *args):
if args == ():
args = mode, 0, 1
if args[0] in _MAPMODES:
- im = new(mode, (1, 1))
+ im = new(mode, (0, 0))
im = im._new(core.map_buffer(data, size, decoder_name, 0, args))
if mode == "P":
from . import ImagePalette
@@ -3407,8 +3429,12 @@ def register_open(id, factory, accept=None):
def register_mime(id, mimetype):
"""
- Registers an image MIME type. This function should not be used
- in application code.
+ Registers an image MIME type by populating ``Image.MIME``. This function
+ should not be used in application code.
+
+ ``Image.MIME`` provides a mapping from image format identifiers to mime
+ formats, but :py:meth:`~PIL.ImageFile.ImageFile.get_format_mimetype` can
+ provide a different result for specific images.
:param id: An image format identifier.
:param mimetype: The image MIME type for this format.
@@ -3725,6 +3751,7 @@ class Exif(MutableMapping):
self.endian = self._info._endian
if offset is None:
offset = self._info.next
+ self.fp.tell()
self.fp.seek(offset)
self._info.load(self.fp)
diff --git a/src/PIL/ImageFont.py b/src/PIL/ImageFont.py
index 7e69df8a7..a7495a5c6 100644
--- a/src/PIL/ImageFont.py
+++ b/src/PIL/ImageFont.py
@@ -563,14 +563,21 @@ class FreeTypeFont:
if start is None:
start = (0, 0)
im = None
+ size = None
- def fill(mode, size):
- nonlocal im
+ def fill(mode, im_size):
+ nonlocal im, size
+
+ size = im_size
+ if Image.MAX_IMAGE_PIXELS is not None:
+ pixels = max(1, size[0]) * max(1, size[1])
+ if pixels > 2 * Image.MAX_IMAGE_PIXELS:
+ return
im = Image.core.fill(mode, size)
return im
- size, offset = self.font.render(
+ offset = self.font.render(
text,
fill,
mode,
@@ -582,7 +589,6 @@ class FreeTypeFont:
ink,
start[0],
start[1],
- Image.MAX_IMAGE_PIXELS,
)
Image._decompression_bomb_check(size)
return im, offset
diff --git a/src/PIL/ImageGrab.py b/src/PIL/ImageGrab.py
index 43019f74a..bcfffc3dc 100644
--- a/src/PIL/ImageGrab.py
+++ b/src/PIL/ImageGrab.py
@@ -166,7 +166,7 @@ def grabclipboard():
msg = "wl-paste or xclip is required for ImageGrab.grabclipboard() on Linux"
raise NotImplementedError(msg)
- p = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ p = subprocess.run(args, capture_output=True)
err = p.stderr
if err:
msg = f"{args[0]} error: {err.strip().decode()}"
diff --git a/src/PIL/ImageOps.py b/src/PIL/ImageOps.py
index 17702778c..42f2152b3 100644
--- a/src/PIL/ImageOps.py
+++ b/src/PIL/ImageOps.py
@@ -242,7 +242,7 @@ def contain(image, size, method=Image.Resampling.BICUBIC):
Returns a resized version of the image, set to the maximum width and height
within the requested size, while maintaining the original aspect ratio.
- :param image: The image to resize and crop.
+ :param image: The image to resize.
:param size: The requested output size in pixels, given as a
(width, height) tuple.
:param method: Resampling method to use. Default is
@@ -266,6 +266,35 @@ def contain(image, size, method=Image.Resampling.BICUBIC):
return image.resize(size, resample=method)
+def cover(image, size, method=Image.Resampling.BICUBIC):
+ """
+ Returns a resized version of the image, so that the requested size is
+ covered, while maintaining the original aspect ratio.
+
+ :param image: The image to resize.
+ :param size: The requested output size in pixels, given as a
+ (width, height) tuple.
+ :param method: Resampling method to use. Default is
+ :py:attr:`~PIL.Image.Resampling.BICUBIC`.
+ See :ref:`concept-filters`.
+ :return: An image.
+ """
+
+ im_ratio = image.width / image.height
+ dest_ratio = size[0] / size[1]
+
+ if im_ratio != dest_ratio:
+ if im_ratio < dest_ratio:
+ new_height = round(image.height / image.width * size[0])
+ if new_height != size[1]:
+ size = (size[0], new_height)
+ else:
+ new_width = round(image.width / image.height * size[1])
+ if new_width != size[0]:
+ size = (new_width, size[1])
+ return image.resize(size, resample=method)
+
+
def pad(image, size, method=Image.Resampling.BICUBIC, color=None, centering=(0.5, 0.5)):
"""
Returns a resized and padded version of the image, expanded to fill the
@@ -588,6 +617,7 @@ def exif_transpose(image, *, in_place=False):
with the transposition applied. If there is no transposition, a copy of the
image will be returned.
"""
+ image.load()
image_exif = image.getexif()
orientation = image_exif.get(ExifTags.Base.Orientation)
method = {
diff --git a/src/PIL/IptcImagePlugin.py b/src/PIL/IptcImagePlugin.py
index 6ce4975c0..316cd17c7 100644
--- a/src/PIL/IptcImagePlugin.py
+++ b/src/PIL/IptcImagePlugin.py
@@ -58,13 +58,13 @@ class IptcImageFile(ImageFile.ImageFile):
#
# get a IPTC field header
s = self.fp.read(5)
- if not len(s):
+ if not s.strip(b"\x00"):
return None, 0
tag = s[1], s[2]
# syntax
- if s[0] != 0x1C or tag[0] < 1 or tag[0] > 9:
+ if s[0] != 0x1C or tag[0] not in [1, 2, 3, 4, 5, 6, 7, 8, 9, 240]:
msg = "invalid IPTC/NAA file"
raise SyntaxError(msg)
diff --git a/src/PIL/JpegImagePlugin.py b/src/PIL/JpegImagePlugin.py
index 74130854f..917bbf39f 100644
--- a/src/PIL/JpegImagePlugin.py
+++ b/src/PIL/JpegImagePlugin.py
@@ -170,11 +170,19 @@ def APP(self, marker):
# 1 dpcm = 2.54 dpi
dpi *= 2.54
self.info["dpi"] = dpi, dpi
- except (TypeError, KeyError, SyntaxError, ValueError, ZeroDivisionError):
- # SyntaxError for invalid/unreadable EXIF
+ except (
+ struct.error,
+ KeyError,
+ SyntaxError,
+ TypeError,
+ ValueError,
+ ZeroDivisionError,
+ ):
+ # struct.error for truncated EXIF
# KeyError for dpi not included
- # ZeroDivisionError for invalid dpi rational value
+ # SyntaxError for invalid/unreadable EXIF
# ValueError or TypeError for dpi being an invalid float
+ # ZeroDivisionError for invalid dpi rational value
self.info["dpi"] = 72, 72
@@ -496,7 +504,7 @@ class JpegImageFile(ImageFile.ImageFile):
for segment, content in self.applist:
if segment == "APP1":
- marker, xmp_tags = content.rsplit(b"\x00", 1)
+ marker, xmp_tags = content.split(b"\x00")[:2]
if marker == b"http://ns.adobe.com/xap/1.0/":
return self._getxmp(xmp_tags)
return {}
diff --git a/src/PIL/PngImagePlugin.py b/src/PIL/PngImagePlugin.py
index 2ed182d32..5e5a8cf6a 100644
--- a/src/PIL/PngImagePlugin.py
+++ b/src/PIL/PngImagePlugin.py
@@ -1042,6 +1042,7 @@ _OUTMODES = {
"LA": ("LA", b"\x08\x04"),
"I": ("I;16B", b"\x10\x00"),
"I;16": ("I;16B", b"\x10\x00"),
+ "I;16B": ("I;16B", b"\x10\x00"),
"P;1": ("P;1", b"\x01\x03"),
"P;2": ("P;2", b"\x02\x03"),
"P;4": ("P;4", b"\x04\x03"),
@@ -1104,10 +1105,7 @@ def _write_multiple_frames(im, fp, chunk, rawmode, default_image, append_images)
if im_frame.mode == rawmode:
im_frame = im_frame.copy()
else:
- if rawmode == "P":
- im_frame = im_frame.convert(rawmode, palette=im.palette)
- else:
- im_frame = im_frame.convert(rawmode)
+ im_frame = im_frame.convert(rawmode)
encoderinfo = im.encoderinfo.copy()
if isinstance(duration, (list, tuple)):
encoderinfo["duration"] = duration[frame_count]
@@ -1166,6 +1164,8 @@ def _write_multiple_frames(im, fp, chunk, rawmode, default_image, append_images)
# default image IDAT (if it exists)
if default_image:
+ if im.mode != rawmode:
+ im = im.convert(rawmode)
ImageFile._save(im, _idat(fp, chunk), [("zip", (0, 0) + im.size, 0, rawmode)])
seq_num = 0
@@ -1227,11 +1227,7 @@ def _save(im, fp, filename, chunk=putchunk, save_all=False):
)
modes = set()
append_images = im.encoderinfo.get("append_images", [])
- if default_image:
- chain = itertools.chain(append_images)
- else:
- chain = itertools.chain([im], append_images)
- for im_seq in chain:
+ for im_seq in itertools.chain([im], append_images):
for im_frame in ImageSequence.Iterator(im_seq):
modes.add(im_frame.mode)
for mode in ("RGBA", "RGB", "P"):
diff --git a/src/PIL/QoiImagePlugin.py b/src/PIL/QoiImagePlugin.py
index 5c3407503..66344faac 100644
--- a/src/PIL/QoiImagePlugin.py
+++ b/src/PIL/QoiImagePlugin.py
@@ -55,7 +55,7 @@ class QoiDecoder(ImageFile.PyDecoder):
while len(data) < self.state.xsize * self.state.ysize * bands:
byte = self.fd.read(1)[0]
if byte == 0b11111110: # QOI_OP_RGB
- value = self.fd.read(3) + o8(255)
+ value = self.fd.read(3) + self._previous_pixel[3:]
elif byte == 0b11111111: # QOI_OP_RGBA
value = self.fd.read(4)
else:
diff --git a/src/PIL/TiffImagePlugin.py b/src/PIL/TiffImagePlugin.py
index 99c23ad4b..dabf8dbfb 100644
--- a/src/PIL/TiffImagePlugin.py
+++ b/src/PIL/TiffImagePlugin.py
@@ -251,6 +251,8 @@ OPEN_INFO = {
(II, 5, (1,), 1, (8, 8, 8, 8, 8, 8), (0, 0)): ("CMYK", "CMYKXX"),
(MM, 5, (1,), 1, (8, 8, 8, 8, 8, 8), (0, 0)): ("CMYK", "CMYKXX"),
(II, 5, (1,), 1, (16, 16, 16, 16), ()): ("CMYK", "CMYK;16L"),
+ (II, 6, (1,), 1, (8,), ()): ("L", "L"),
+ (MM, 6, (1,), 1, (8,), ()): ("L", "L"),
# JPEG compressed images handled by LibTiff and auto-converted to RGBX
# Minimal Baseline TIFF requires YCbCr images to have 3 SamplesPerPixel
(II, 6, (1,), 1, (8, 8, 8), ()): ("RGB", "RGBX"),
@@ -823,7 +825,7 @@ class ImageFileDirectory_v2(MutableMapping):
try:
unit_size, handler = self._load_dispatch[typ]
except KeyError:
- logger.debug(msg + f" - unsupported type {typ}")
+ logger.debug("%s - unsupported type %s", msg, typ)
continue # ignore unsupported type
size = count * unit_size
if size > (8 if self._bigtiff else 4):
@@ -880,7 +882,7 @@ class ImageFileDirectory_v2(MutableMapping):
if tag == STRIPOFFSETS:
stripoffsets = len(entries)
typ = self.tagtype.get(tag)
- logger.debug(f"Tag {tag}, Type: {typ}, Value: {repr(value)}")
+ logger.debug("Tag %s, Type: %s, Value: %s", tag, typ, repr(value))
is_ifd = typ == TiffTags.LONG and isinstance(value, dict)
if is_ifd:
if self._endian == "<":
@@ -929,7 +931,7 @@ class ImageFileDirectory_v2(MutableMapping):
# pass 2: write entries to file
for tag, typ, count, value, data in entries:
- logger.debug(f"{tag} {typ} {count} {repr(value)} {repr(data)}")
+ logger.debug("%s %s %s %s %s", tag, typ, count, repr(value), repr(data))
result += self._pack("HHL4s", tag, typ, count, value)
# -- overwrite here for multi-page --
@@ -1098,8 +1100,8 @@ class TiffImageFile(ImageFile.ImageFile):
self._n_frames = None
logger.debug("*** TiffImageFile._open ***")
- logger.debug(f"- __first: {self.__first}")
- logger.debug(f"- ifh: {repr(ifh)}") # Use repr to avoid str(bytes)
+ logger.debug("- __first: %s", self.__first)
+ logger.debug("- ifh: %s", repr(ifh)) # Use repr to avoid str(bytes)
# and load the first frame
self._seek(0)
@@ -1137,12 +1139,15 @@ class TiffImageFile(ImageFile.ImageFile):
msg = "no more images in TIFF file"
raise EOFError(msg)
logger.debug(
- f"Seeking to frame {frame}, on frame {self.__frame}, "
- f"__next {self.__next}, location: {self.fp.tell()}"
+ "Seeking to frame %s, on frame %s, __next %s, location: %s",
+ frame,
+ self.__frame,
+ self.__next,
+ self.fp.tell(),
)
self.fp.seek(self.__next)
self._frame_pos.append(self.__next)
- logger.debug("Loading tags, location: %s" % self.fp.tell())
+ logger.debug("Loading tags, location: %s", self.fp.tell())
self.tag_v2.load(self.fp)
if self.tag_v2.next in self._frame_pos:
# This IFD has already been processed
@@ -1203,20 +1208,6 @@ class TiffImageFile(ImageFile.ImageFile):
return super().load()
def load_end(self):
- if self._tile_orientation:
- method = {
- 2: Image.Transpose.FLIP_LEFT_RIGHT,
- 3: Image.Transpose.ROTATE_180,
- 4: Image.Transpose.FLIP_TOP_BOTTOM,
- 5: Image.Transpose.TRANSPOSE,
- 6: Image.Transpose.ROTATE_270,
- 7: Image.Transpose.TRANSVERSE,
- 8: Image.Transpose.ROTATE_90,
- }.get(self._tile_orientation)
- if method is not None:
- self.im = self.im.transpose(method)
- self._size = self.im.size
-
# allow closing if we're on the first frame, there's no next
# This is the ImageFile.load path only, libtiff specific below.
if not self.is_animated:
@@ -1233,6 +1224,10 @@ class TiffImageFile(ImageFile.ImageFile):
continue
exif.get_ifd(key)
+ ImageOps.exif_transpose(self, in_place=True)
+ if ExifTags.Base.Orientation in self.tag_v2:
+ del self.tag_v2[ExifTags.Base.Orientation]
+
def _load_libtiff(self):
"""Overload method triggered when we detect a compressed tiff
Calls out to libtiff"""
@@ -1340,18 +1335,18 @@ class TiffImageFile(ImageFile.ImageFile):
fillorder = self.tag_v2.get(FILLORDER, 1)
logger.debug("*** Summary ***")
- logger.debug(f"- compression: {self._compression}")
- logger.debug(f"- photometric_interpretation: {photo}")
- logger.debug(f"- planar_configuration: {self._planar_configuration}")
- logger.debug(f"- fill_order: {fillorder}")
- logger.debug(f"- YCbCr subsampling: {self.tag.get(YCBCRSUBSAMPLING)}")
+ logger.debug("- compression: %s", self._compression)
+ logger.debug("- photometric_interpretation: %s", photo)
+ logger.debug("- planar_configuration: %s", self._planar_configuration)
+ logger.debug("- fill_order: %s", fillorder)
+ logger.debug("- YCbCr subsampling: %s", self.tag.get(YCBCRSUBSAMPLING))
# size
xsize = int(self.tag_v2.get(IMAGEWIDTH))
ysize = int(self.tag_v2.get(IMAGELENGTH))
self._size = xsize, ysize
- logger.debug(f"- size: {self.size}")
+ logger.debug("- size: %s", self.size)
sample_format = self.tag_v2.get(SAMPLEFORMAT, (1,))
if len(sample_format) > 1 and max(sample_format) == min(sample_format) == 1:
@@ -1407,7 +1402,7 @@ class TiffImageFile(ImageFile.ImageFile):
bps_tuple,
extra_tuple,
)
- logger.debug(f"format key: {key}")
+ logger.debug("format key: %s", key)
try:
self._mode, rawmode = OPEN_INFO[key]
except KeyError as e:
@@ -1415,8 +1410,8 @@ class TiffImageFile(ImageFile.ImageFile):
msg = "unknown pixel mode"
raise SyntaxError(msg) from e
- logger.debug(f"- raw mode: {rawmode}")
- logger.debug(f"- pil mode: {self.mode}")
+ logger.debug("- raw mode: %s", rawmode)
+ logger.debug("- pil mode: %s", self.mode)
self.info["compression"] = self._compression
@@ -1457,7 +1452,7 @@ class TiffImageFile(ImageFile.ImageFile):
if fillorder == 2:
# Replace fillorder with fillorder=1
key = key[:3] + (1,) + key[4:]
- logger.debug(f"format key: {key}")
+ logger.debug("format key: %s", key)
# this should always work, since all the
# fillorder==2 modes have a corresponding
# fillorder=1 mode
@@ -1542,8 +1537,6 @@ class TiffImageFile(ImageFile.ImageFile):
palette = [o8(b // 256) for b in self.tag_v2[COLORMAP]]
self.palette = ImagePalette.raw("RGB;L", b"".join(palette))
- self._tile_orientation = self.tag_v2.get(ExifTags.Base.Orientation)
-
#
# --------------------------------------------------------------------
@@ -1622,7 +1615,7 @@ def _save(im, fp, filename):
info = exif
else:
info = {}
- logger.debug("Tiffinfo Keys: %s" % list(info))
+ logger.debug("Tiffinfo Keys: %s", list(info))
if isinstance(info, ImageFileDirectory_v1):
info = info.to_v2()
for key in info:
@@ -1755,7 +1748,7 @@ def _save(im, fp, filename):
ifd[JPEGQUALITY] = quality
logger.debug("Saving using libtiff encoder")
- logger.debug("Items: %s" % sorted(ifd.items()))
+ logger.debug("Items: %s", sorted(ifd.items()))
_fp = 0
if hasattr(fp, "fileno"):
try:
@@ -1823,7 +1816,7 @@ def _save(im, fp, filename):
if SAMPLEFORMAT in atts and len(atts[SAMPLEFORMAT]) == 1:
atts[SAMPLEFORMAT] = atts[SAMPLEFORMAT][0]
- logger.debug("Converted items: %s" % sorted(atts.items()))
+ logger.debug("Converted items: %s", sorted(atts.items()))
# libtiff always expects the bytes in native order.
# we're storing image byte order. So, if the rawmode
diff --git a/src/PIL/WebPImagePlugin.py b/src/PIL/WebPImagePlugin.py
index a6e1a2a00..612fc0946 100644
--- a/src/PIL/WebPImagePlugin.py
+++ b/src/PIL/WebPImagePlugin.py
@@ -74,9 +74,6 @@ class WebPImageFile(ImageFile.ImageFile):
self.info["background"] = (bg_r, bg_g, bg_b, bg_a)
self.n_frames = frame_count
self.is_animated = self.n_frames > 1
- ret = self._decoder.get_next()
- if ret is not None:
- self.info["duration"] = ret[1]
self._mode = "RGB" if mode == "RGBX" else mode
self.rawmode = mode
self.tile = []
@@ -93,7 +90,7 @@ class WebPImageFile(ImageFile.ImageFile):
self.info["xmp"] = xmp
# Initialize seek state
- self._reset()
+ self._reset(reset=False)
def _getexif(self):
if "exif" not in self.info:
@@ -116,8 +113,9 @@ class WebPImageFile(ImageFile.ImageFile):
# Set logical frame to requested position
self.__logical_frame = frame
- def _reset(self):
- self._decoder.reset()
+ def _reset(self, reset=True):
+ if reset:
+ self._decoder.reset()
self.__physical_frame = 0
self.__loaded = -1
self.__timestamp = 0
@@ -332,12 +330,7 @@ def _save(im, fp, filename):
exact = 1 if im.encoderinfo.get("exact") else 0
if im.mode not in _VALID_WEBP_LEGACY_MODES:
- alpha = (
- "A" in im.mode
- or "a" in im.mode
- or (im.mode == "P" and "transparency" in im.info)
- )
- im = im.convert("RGBA" if alpha else "RGB")
+ im = im.convert("RGBA" if im.has_transparency_data else "RGB")
data = _webp.WebPEncode(
im.tobytes(),
diff --git a/src/_imaging.c b/src/_imaging.c
index 95da2772d..2270c77fe 100644
--- a/src/_imaging.c
+++ b/src/_imaging.c
@@ -475,8 +475,10 @@ getpixel(Imaging im, ImagingAccess access, int x, int y) {
case IMAGING_TYPE_FLOAT32:
return PyFloat_FromDouble(pixel.f);
case IMAGING_TYPE_SPECIAL:
- if (strncmp(im->mode, "I;16", 4) == 0) {
+ if (im->bands == 1) {
return PyLong_FromLong(pixel.h);
+ } else {
+ return Py_BuildValue("BBB", pixel.b[0], pixel.b[1], pixel.b[2]);
}
break;
}
@@ -599,7 +601,7 @@ getink(PyObject *color, Imaging im, char *ink) {
} else if (tupleSize != 3) {
PyErr_SetString(PyExc_TypeError, "color must be int, or tuple of one or three elements");
return NULL;
- } else if (!PyArg_ParseTuple(color, "Lii", &r, &g, &b)) {
+ } else if (!PyArg_ParseTuple(color, "iiL", &b, &g, &r)) {
return NULL;
}
if (!strcmp(im->mode, "BGR;15")) {
@@ -1571,21 +1573,46 @@ if (PySequence_Check(op)) { \
PyErr_SetString(PyExc_TypeError, must_be_sequence);
return NULL;
}
- int endian = strncmp(image->mode, "I;16", 4) == 0 ? (strcmp(image->mode, "I;16B") == 0 ? 2 : 1) : 0;
double value;
- for (i = x = y = 0; i < n; i++) {
- set_value_to_item(seq, i);
- if (scale != 1.0 || offset != 0.0) {
- value = value * scale + offset;
+ if (image->bands == 1) {
+ int bigendian = 0;
+ if (image->type == IMAGING_TYPE_SPECIAL) {
+ // I;16*
+ bigendian = strcmp(image->mode, "I;16B") == 0;
}
- if (endian == 0) {
- image->image8[y][x] = (UINT8)CLIP8(value);
- } else {
- image->image8[y][x * 2 + (endian == 2 ? 1 : 0)] = CLIP8((int)value % 256);
- image->image8[y][x * 2 + (endian == 2 ? 0 : 1)] = CLIP8((int)value >> 8);
+ for (i = x = y = 0; i < n; i++) {
+ set_value_to_item(seq, i);
+ if (scale != 1.0 || offset != 0.0) {
+ value = value * scale + offset;
+ }
+ if (image->type == IMAGING_TYPE_SPECIAL) {
+ image->image8[y][x * 2 + (bigendian ? 1 : 0)] = CLIP8((int)value % 256);
+ image->image8[y][x * 2 + (bigendian ? 0 : 1)] = CLIP8((int)value >> 8);
+ } else {
+ image->image8[y][x] = (UINT8)CLIP8(value);
+ }
+ if (++x >= (int)image->xsize) {
+ x = 0, y++;
+ }
}
- if (++x >= (int)image->xsize) {
- x = 0, y++;
+ } else {
+ // BGR;*
+ int b;
+ for (i = x = y = 0; i < n; i++) {
+ char ink[4];
+
+ op = PySequence_Fast_GET_ITEM(seq, i);
+ if (!op || !getink(op, image, ink)) {
+ Py_DECREF(seq);
+ return NULL;
+ }
+ /* FIXME: what about scale and offset? */
+ for (b = 0; b < image->pixelsize; b++) {
+ image->image8[y][x * image->pixelsize + b] = ink[b];
+ }
+ if (++x >= (int)image->xsize) {
+ x = 0, y++;
+ }
}
}
PyErr_Clear(); /* Avoid weird exceptions */
diff --git a/src/_imagingft.c b/src/_imagingft.c
index 2165fbc7a..64175de8b 100644
--- a/src/_imagingft.c
+++ b/src/_imagingft.c
@@ -815,7 +815,6 @@ font_render(FontObject *self, PyObject *args) {
float y_start = 0;
int width, height, x_offset, y_offset;
int horizontal_dir; /* is primary axis horizontal? */
- PyObject *max_image_pixels = Py_None;
/* render string into given buffer (the buffer *must* have
the right size, or this will crash) */
@@ -833,8 +832,7 @@ font_render(FontObject *self, PyObject *args) {
&anchor,
&foreground_ink_long,
&x_start,
- &y_start,
- &max_image_pixels)) {
+ &y_start)) {
return NULL;
}
@@ -879,15 +877,11 @@ font_render(FontObject *self, PyObject *args) {
width += stroke_width * 2 + ceil(x_start);
height += stroke_width * 2 + ceil(y_start);
- if (max_image_pixels != Py_None) {
- if ((long long)(width > 1 ? width : 1) * (height > 1 ? height : 1) > PyLong_AsLongLong(max_image_pixels) * 2) {
- PyMem_Del(glyph_info);
- return Py_BuildValue("(ii)(ii)", width, height, 0, 0);
- }
- }
-
image = PyObject_CallFunction(fill, "s(ii)", strcmp(mode, "RGBA") == 0 ? "RGBA" : "L", width, height);
- if (image == NULL) {
+ if (image == Py_None) {
+ PyMem_Del(glyph_info);
+ return Py_BuildValue("ii", 0, 0);
+ } else if (image == NULL) {
PyMem_Del(glyph_info);
return NULL;
}
@@ -898,7 +892,7 @@ font_render(FontObject *self, PyObject *args) {
y_offset -= stroke_width;
if (count == 0 || width == 0 || height == 0) {
PyMem_Del(glyph_info);
- return Py_BuildValue("(ii)(ii)", width, height, x_offset, y_offset);
+ return Py_BuildValue("ii", x_offset, y_offset);
}
if (stroke_width) {
@@ -1116,7 +1110,7 @@ font_render(FontObject *self, PyObject *args) {
Py_DECREF(image);
FT_Stroker_Done(stroker);
PyMem_Del(glyph_info);
- return Py_BuildValue("(ii)(ii)", width, height, x_offset, y_offset);
+ return Py_BuildValue("ii", x_offset, y_offset);
glyph_error:
if (im->destroy) {
diff --git a/src/libImaging/Access.c b/src/libImaging/Access.c
index dd0418696..091c84e18 100644
--- a/src/libImaging/Access.c
+++ b/src/libImaging/Access.c
@@ -12,8 +12,8 @@
#include "Imaging.h"
/* use make_hash.py from the pillow-scripts repository to calculate these values */
-#define ACCESS_TABLE_SIZE 27
-#define ACCESS_TABLE_HASH 33051
+#define ACCESS_TABLE_SIZE 35
+#define ACCESS_TABLE_HASH 8940
static struct ImagingAccessInstance access_table[ACCESS_TABLE_SIZE];
@@ -87,6 +87,31 @@ get_pixel_16(Imaging im, int x, int y, void *color) {
memcpy(color, in, sizeof(UINT16));
}
+static void
+get_pixel_BGR15(Imaging im, int x, int y, void *color) {
+ UINT8 *in = (UINT8 *)&im->image8[y][x * 2];
+ UINT16 pixel = in[0] + (in[1] << 8);
+ char *out = color;
+ out[0] = (pixel & 31) * 255 / 31;
+ out[1] = ((pixel >> 5) & 31) * 255 / 31;
+ out[2] = ((pixel >> 10) & 31) * 255 / 31;
+}
+
+static void
+get_pixel_BGR16(Imaging im, int x, int y, void *color) {
+ UINT8 *in = (UINT8 *)&im->image8[y][x * 2];
+ UINT16 pixel = in[0] + (in[1] << 8);
+ char *out = color;
+ out[0] = (pixel & 31) * 255 / 31;
+ out[1] = ((pixel >> 5) & 63) * 255 / 63;
+ out[2] = ((pixel >> 11) & 31) * 255 / 31;
+}
+
+static void
+get_pixel_BGR24(Imaging im, int x, int y, void *color) {
+ memcpy(color, &im->image8[y][x * 3], sizeof(UINT8) * 3);
+}
+
static void
get_pixel_32(Imaging im, int x, int y, void *color) {
memcpy(color, &im->image32[y][x], sizeof(INT32));
@@ -134,6 +159,16 @@ put_pixel_16B(Imaging im, int x, int y, const void *color) {
out[1] = in[0];
}
+static void
+put_pixel_BGR1516(Imaging im, int x, int y, const void *color) {
+ memcpy(&im->image8[y][x * 2], color, 2);
+}
+
+static void
+put_pixel_BGR24(Imaging im, int x, int y, const void *color) {
+ memcpy(&im->image8[y][x * 3], color, 3);
+}
+
static void
put_pixel_32L(Imaging im, int x, int y, const void *color) {
memcpy(&im->image8[y][x * 4], color, 4);
@@ -178,6 +213,9 @@ ImagingAccessInit() {
ADD("F", get_pixel_32, put_pixel_32);
ADD("P", get_pixel_8, put_pixel_8);
ADD("PA", get_pixel_32_2bands, put_pixel_32);
+ ADD("BGR;15", get_pixel_BGR15, put_pixel_BGR1516);
+ ADD("BGR;16", get_pixel_BGR16, put_pixel_BGR1516);
+ ADD("BGR;24", get_pixel_BGR24, put_pixel_BGR24);
ADD("RGB", get_pixel_32, put_pixel_32);
ADD("RGBA", get_pixel_32, put_pixel_32);
ADD("RGBa", get_pixel_32, put_pixel_32);
diff --git a/src/libImaging/BcnDecode.c b/src/libImaging/BcnDecode.c
index a57b74b61..5e4296eeb 100644
--- a/src/libImaging/BcnDecode.c
+++ b/src/libImaging/BcnDecode.c
@@ -118,8 +118,8 @@ decode_bc3_alpha(char *dst, const UINT8 *src, int stride, int o, int sign) {
if (sign == 1) {
bc5s_alpha b;
memcpy(&b, src, sizeof(bc5s_alpha));
- a0 = (b.a0 + 255) / 2;
- a1 = (b.a1 + 255) / 2;
+ a0 = b.a0 + 128;
+ a1 = b.a1 + 128;
lut1 = b.lut[0] | (b.lut[1] << 8) | (b.lut[2] << 16);
lut2 = b.lut[3] | (b.lut[4] << 8) | (b.lut[5] << 16);
} else {
@@ -850,10 +850,12 @@ decode_bcn(
DECODE_LOOP(3, 16, rgba);
DECODE_LOOP(4, 8, lum);
case 5:
+ {
+ int sign = strcmp(pixel_format, "BC5S") == 0 ? 1 : 0;
while (bytes >= 16) {
rgba col[16];
- memset(col, 0, 16 * sizeof(col[0]));
- decode_bc5_block(col, ptr, strcmp(pixel_format, "BC5S") == 0 ? 1 : 0);
+ memset(col, sign ? 128 : 0, 16 * sizeof(col[0]));
+ decode_bc5_block(col, ptr, sign);
put_block(im, state, (const char *)col, sizeof(col[0]), C);
ptr += 16;
bytes -= 16;
@@ -862,10 +864,13 @@ decode_bcn(
}
}
break;
+ }
case 6:
+ {
+ int sign = strcmp(pixel_format, "BC6HS") == 0 ? 1 : 0;
while (bytes >= 16) {
rgba col[16];
- decode_bc6_block(col, ptr, strcmp(pixel_format, "BC6HS") == 0 ? 1 : 0);
+ decode_bc6_block(col, ptr, sign);
put_block(im, state, (const char *)col, sizeof(col[0]), C);
ptr += 16;
bytes -= 16;
@@ -874,6 +879,7 @@ decode_bcn(
}
}
break;
+ }
DECODE_LOOP(7, 16, rgba);
#undef DECODE_LOOP
}
diff --git a/src/libImaging/Convert.c b/src/libImaging/Convert.c
index 7fe24a639..b08519d30 100644
--- a/src/libImaging/Convert.c
+++ b/src/libImaging/Convert.c
@@ -564,7 +564,7 @@ rgb2cmyk(UINT8 *out, const UINT8 *in, int xsize) {
}
}
-static void
+void
cmyk2rgb(UINT8 *out, const UINT8 *in, int xsize) {
int x, nk, tmp;
for (x = 0; x < xsize; x++) {
@@ -1295,7 +1295,6 @@ topalette(
int alpha;
int x, y;
ImagingPalette palette = inpalette;
- ;
/* Map L or RGB/RGBX/RGBA to palette image */
if (strcmp(imIn->mode, "L") != 0 && strncmp(imIn->mode, "RGB", 3) != 0) {
@@ -1307,7 +1306,14 @@ topalette(
if (palette == NULL) {
/* FIXME: make user configurable */
if (imIn->bands == 1) {
- palette = ImagingPaletteNew("RGB"); /* Initialised to grey ramp */
+ palette = ImagingPaletteNew("RGB");
+
+ palette->size = 256;
+ int i;
+ for (i = 0; i < 256; i++) {
+ palette->palette[i * 4] = palette->palette[i * 4 + 1] =
+ palette->palette[i * 4 + 2] = (UINT8)i;
+ }
} else {
palette = ImagingPaletteNewBrowser(); /* Standard colour cube */
}
diff --git a/src/libImaging/Convert.h b/src/libImaging/Convert.h
new file mode 100644
index 000000000..e688e3018
--- /dev/null
+++ b/src/libImaging/Convert.h
@@ -0,0 +1,2 @@
+extern void
+cmyk2rgb(UINT8 *out, const UINT8 *in, int xsize);
diff --git a/src/libImaging/Draw.c b/src/libImaging/Draw.c
index 82f290bd0..0ccf22d58 100644
--- a/src/libImaging/Draw.c
+++ b/src/libImaging/Draw.c
@@ -41,6 +41,7 @@
#define FLOOR(v) ((v) >= 0.0 ? (int)(v) : (int)floor(v))
#define INK8(ink) (*(UINT8 *)ink)
+#define INK16(ink) (*(UINT16 *)ink)
/*
* Rounds around zero (up=away from zero, down=towards zero)
@@ -68,8 +69,13 @@ static inline void
point8(Imaging im, int x, int y, int ink) {
if (x >= 0 && x < im->xsize && y >= 0 && y < im->ysize) {
if (strncmp(im->mode, "I;16", 4) == 0) {
- im->image8[y][x * 2] = (UINT8)ink;
+#ifdef WORDS_BIGENDIAN
+ im->image8[y][x * 2] = (UINT8)(ink >> 8);
im->image8[y][x * 2 + 1] = (UINT8)ink;
+#else
+ im->image8[y][x * 2] = (UINT8)ink;
+ im->image8[y][x * 2 + 1] = (UINT8)(ink >> 8);
+#endif
} else {
im->image8[y][x] = (UINT8)ink;
}
@@ -631,13 +637,17 @@ DRAW draw32rgba = {point32rgba, hline32rgba, line32rgba, polygon32rgba};
/* Interface */
/* -------------------------------------------------------------------- */
-#define DRAWINIT() \
- if (im->image8) { \
- draw = &draw8; \
- ink = INK8(ink_); \
- } else { \
- draw = (op) ? &draw32rgba : &draw32; \
- memcpy(&ink, ink_, sizeof(ink)); \
+#define DRAWINIT() \
+ if (im->image8) { \
+ draw = &draw8; \
+ if (strncmp(im->mode, "I;16", 4) == 0) { \
+ ink = INK16(ink_); \
+ } else { \
+ ink = INK8(ink_); \
+ } \
+ } else { \
+ draw = (op) ? &draw32rgba : &draw32; \
+ memcpy(&ink, ink_, sizeof(ink)); \
}
int
diff --git a/src/libImaging/Palette.c b/src/libImaging/Palette.c
index 71a095c2c..059d7b72a 100644
--- a/src/libImaging/Palette.c
+++ b/src/libImaging/Palette.c
@@ -39,11 +39,8 @@ ImagingPaletteNew(const char *mode) {
strncpy(palette->mode, mode, IMAGING_MODE_LENGTH - 1);
palette->mode[IMAGING_MODE_LENGTH - 1] = 0;
- /* Initialize to ramp */
- palette->size = 256;
+ palette->size = 0;
for (i = 0; i < 256; i++) {
- palette->palette[i * 4 + 0] = palette->palette[i * 4 + 1] =
- palette->palette[i * 4 + 2] = (UINT8)i;
palette->palette[i * 4 + 3] = 255; /* opaque */
}
@@ -62,16 +59,10 @@ ImagingPaletteNewBrowser(void) {
return NULL;
}
- /* Blank out unused entries */
/* FIXME: Add 10-level windows palette here? */
- for (i = 0; i < 10; i++) {
- palette->palette[i * 4 + 0] = palette->palette[i * 4 + 1] =
- palette->palette[i * 4 + 2] = 0;
- }
-
/* Simple 6x6x6 colour cube */
-
+ i = 10;
for (b = 0; b < 256; b += 51) {
for (g = 0; g < 256; g += 51) {
for (r = 0; r < 256; r += 51) {
@@ -82,15 +73,10 @@ ImagingPaletteNewBrowser(void) {
}
}
}
+ palette->size = i;
- /* Blank out unused entries */
/* FIXME: add 30-level greyscale wedge here? */
- for (; i < 256; i++) {
- palette->palette[i * 4 + 0] = palette->palette[i * 4 + 1] =
- palette->palette[i * 4 + 2] = 0;
- }
-
return palette;
}
diff --git a/src/libImaging/Paste.c b/src/libImaging/Paste.c
index acf5202e5..6684b11ef 100644
--- a/src/libImaging/Paste.c
+++ b/src/libImaging/Paste.c
@@ -425,7 +425,7 @@ fill_mask_L(
*out = BLEND(*mask, *out, ink[0], tmp1);
if (strncmp(imOut->mode, "I;16", 4) == 0) {
out++;
- *out = BLEND(*mask, *out, ink[0], tmp1);
+ *out = BLEND(*mask, *out, ink[1], tmp1);
}
out++, mask++;
}
diff --git a/src/libImaging/Quant.c b/src/libImaging/Quant.c
index 02a4a5c76..c84acb998 100644
--- a/src/libImaging/Quant.c
+++ b/src/libImaging/Quant.c
@@ -1825,6 +1825,7 @@ ImagingQuantize(Imaging im, int colors, int mode, int kmeans) {
free(newData);
+ imOut->palette->size = (int)paletteLength;
pp = imOut->palette->palette;
for (i = j = 0; i < (int)paletteLength; i++) {
@@ -1832,16 +1833,9 @@ ImagingQuantize(Imaging im, int colors, int mode, int kmeans) {
*pp++ = palette[i].c.g;
*pp++ = palette[i].c.b;
if (withAlpha) {
- *pp++ = palette[i].c.a;
- } else {
- *pp++ = 255;
+ *pp = palette[i].c.a;
}
- }
- for (; i < 256; i++) {
- *pp++ = 0;
- *pp++ = 0;
- *pp++ = 0;
- *pp++ = 255;
+ pp++;
}
if (withAlpha) {
diff --git a/src/libImaging/Sgi.h b/src/libImaging/Sgi.h
index 39dd68825..797e5cbf9 100644
--- a/src/libImaging/Sgi.h
+++ b/src/libImaging/Sgi.h
@@ -36,4 +36,4 @@ typedef struct {
/* image data size from file descriptor */
long bufsize;
-} SGISTATE;
\ No newline at end of file
+} SGISTATE;
diff --git a/src/libImaging/Unpack.c b/src/libImaging/Unpack.c
index 206403ba6..279bdcdc8 100644
--- a/src/libImaging/Unpack.c
+++ b/src/libImaging/Unpack.c
@@ -31,6 +31,7 @@
*/
#include "Imaging.h"
+#include "Convert.h"
#define R 0
#define G 1
@@ -1238,6 +1239,12 @@ copy2(UINT8 *out, const UINT8 *in, int pixels) {
memcpy(out, in, pixels * 2);
}
+static void
+copy3(UINT8 *out, const UINT8 *in, int pixels) {
+ /* BGR;24 */
+ memcpy(out, in, pixels * 3);
+}
+
static void
copy4(UINT8 *out, const UINT8 *in, int pixels) {
/* RGBA, CMYK quadruples */
@@ -1589,6 +1596,11 @@ static struct {
{"RGB", "R;16B", 16, band016B},
{"RGB", "G;16B", 16, band116B},
{"RGB", "B;16B", 16, band216B},
+ {"RGB", "CMYK", 32, cmyk2rgb},
+
+ {"BGR;15", "BGR;15", 16, copy2},
+ {"BGR;16", "BGR;16", 16, copy2},
+ {"BGR;24", "BGR;24", 24, copy3},
/* true colour w. alpha */
{"RGBA", "LA", 16, unpackRGBALA},
diff --git a/wheels/README.md b/wheels/README.md
new file mode 100644
index 000000000..c15c034b6
--- /dev/null
+++ b/wheels/README.md
@@ -0,0 +1,31 @@
+README
+------
+
+This directory creates wheels for tagged versions of Pillow.
+
+Archives
+--------
+
+https://github.com/python-pillow/pillow-depends contains archives for libraries
+that will be built as part of the Pillow build.
+
+In general, there is no need to put library archives there, because the
+`multibuild` scripts will download them from their respective URLs.
+
+But, the build will look in that repository before downloading from the
+URL, so if there is a library that often fails to download, or you think might
+fail to download, then download it and add it to the Git repository.
+
+See the `pre_build` in `config.sh` and the `fetch_unpack` routine in
+`multibuild/common_utils.sh` for the logic, and the build recipes in
+`multibuild/library_builders.sh` for the filename to give to the downloaded
+archive.
+
+Wheels
+------
+
+Wheels are
+[GitHub Actions artifacts created for tags, relevant changes or manual builds](https://github.com/python-pillow/Pillow/actions/workflows/wheels.yml).
+
+Windows wheels are not created here. Instead, they are
+[GitHub Actions artifacts created on each run of the Windows workflow](https://github.com/python-pillow/Pillow/actions/workflows/test-windows.yml?query=branch%3Amain).
diff --git a/wheels/config.sh b/wheels/config.sh
new file mode 100644
index 000000000..2943b0c4b
--- /dev/null
+++ b/wheels/config.sh
@@ -0,0 +1,187 @@
+# Define custom utilities
+# Test for macOS with [ -n "$IS_MACOS" ]
+
+ARCHIVE_SDIR=pillow-depends-main
+
+# Package versions for fresh source builds
+FREETYPE_VERSION=2.13.2
+HARFBUZZ_VERSION=8.2.1
+LIBPNG_VERSION=1.6.40
+JPEGTURBO_VERSION=3.0.0
+OPENJPEG_VERSION=2.5.0
+XZ_VERSION=5.4.4
+TIFF_VERSION=4.6.0
+LCMS2_VERSION=2.15
+if [[ -n "$IS_MACOS" ]]; then
+ GIFLIB_VERSION=5.1.4
+else
+ GIFLIB_VERSION=5.2.1
+fi
+if [[ -n "$IS_MACOS" ]] || [[ "$MB_ML_VER" != 2014 ]]; then
+ ZLIB_VERSION=1.3
+else
+ ZLIB_VERSION=1.2.8
+fi
+LIBWEBP_VERSION=1.3.2
+BZIP2_VERSION=1.0.8
+LIBXCB_VERSION=1.16
+BROTLI_VERSION=1.1.0
+
+if [[ -n "$IS_MACOS" ]] && [[ "$PLAT" == "x86_64" ]]; then
+ function build_openjpeg {
+ local out_dir=$(fetch_unpack https://github.com/uclouvain/openjpeg/archive/v${OPENJPEG_VERSION}.tar.gz)
+ (cd $out_dir \
+ && cmake -DCMAKE_INSTALL_PREFIX=$BUILD_PREFIX -DCMAKE_INSTALL_NAME_DIR=$BUILD_PREFIX/lib . \
+ && make install)
+ touch openjpeg-stamp
+ }
+fi
+
+function build_brotli {
+ local cmake=$(get_modern_cmake)
+ local out_dir=$(fetch_unpack https://github.com/google/brotli/archive/v$BROTLI_VERSION.tar.gz)
+ (cd $out_dir \
+ && $cmake -DCMAKE_INSTALL_PREFIX=$BUILD_PREFIX -DCMAKE_INSTALL_NAME_DIR=$BUILD_PREFIX/lib . \
+ && make install)
+ if [[ "$MB_ML_LIBC" == "manylinux" ]]; then
+ cp /usr/local/lib64/libbrotli* /usr/local/lib
+ cp /usr/local/lib64/pkgconfig/libbrotli* /usr/local/lib/pkgconfig
+ fi
+}
+
+function pre_build {
+ # Any stuff that you need to do before you start building the wheels
+ # Runs in the root directory of this repository.
+ curl -fsSL -o pillow-depends-main.zip https://github.com/python-pillow/pillow-depends/archive/main.zip
+ untar pillow-depends-main.zip
+
+ build_xz
+ if [ -z "$IS_ALPINE" ] && [ -z "$IS_MACOS" ]; then
+ yum remove -y zlib-devel
+ fi
+ build_new_zlib
+
+ if [ -n "$IS_MACOS" ]; then
+ ORIGINAL_BUILD_PREFIX=$BUILD_PREFIX
+ ORIGINAL_PKG_CONFIG_PATH=$PKG_CONFIG_PATH
+ BUILD_PREFIX=`dirname $(dirname $(which python))`
+ PKG_CONFIG_PATH="$BUILD_PREFIX/lib/pkgconfig"
+ fi
+ build_simple xcb-proto 1.16.0 https://xorg.freedesktop.org/archive/individual/proto
+ if [ -n "$IS_MACOS" ]; then
+ build_simple xorgproto 2023.2 https://www.x.org/pub/individual/proto
+ build_simple libXau 1.0.11 https://www.x.org/pub/individual/lib
+ build_simple libpthread-stubs 0.5 https://xcb.freedesktop.org/dist
+ cp venv/share/pkgconfig/xcb-proto.pc venv/lib/pkgconfig/xcb-proto.pc
+ else
+ sed s/\${pc_sysrootdir\}// /usr/local/share/pkgconfig/xcb-proto.pc > /usr/local/lib/pkgconfig/xcb-proto.pc
+ fi
+ build_simple libxcb $LIBXCB_VERSION https://www.x.org/releases/individual/lib
+ if [ -n "$IS_MACOS" ]; then
+ BUILD_PREFIX=$ORIGINAL_BUILD_PREFIX
+ PKG_CONFIG_PATH=$ORIGINAL_PKG_CONFIG_PATH
+ fi
+
+ build_libjpeg_turbo
+ if [[ -n "$IS_MACOS" ]]; then
+ rm /usr/local/lib/libjpeg.dylib
+ fi
+ build_tiff
+ build_libpng
+ build_lcms2
+ build_openjpeg
+
+ ORIGINAL_CFLAGS=$CFLAGS
+ CFLAGS="$CFLAGS -O3 -DNDEBUG"
+ if [[ -n "$IS_MACOS" ]]; then
+ CFLAGS="$CFLAGS -Wl,-headerpad_max_install_names"
+ fi
+ build_libwebp
+ CFLAGS=$ORIGINAL_CFLAGS
+
+ build_brotli
+
+ if [ -n "$IS_MACOS" ]; then
+ # Custom freetype build
+ build_simple freetype $FREETYPE_VERSION https://download.savannah.gnu.org/releases/freetype tar.gz --with-harfbuzz=no
+ else
+ build_freetype
+ fi
+
+ if [ -z "$IS_MACOS" ]; then
+ export FREETYPE_LIBS=-lfreetype
+ export FREETYPE_CFLAGS=-I/usr/local/include/freetype2/
+ fi
+ build_simple harfbuzz $HARFBUZZ_VERSION https://github.com/harfbuzz/harfbuzz/releases/download/$HARFBUZZ_VERSION tar.xz --with-freetype=yes --with-glib=no
+ if [ -z "$IS_MACOS" ]; then
+ export FREETYPE_LIBS=''
+ export FREETYPE_CFLAGS=''
+ fi
+
+ # Append licenses
+ for filename in wheels/dependency_licenses/*; do
+ echo -e "\n\n----\n\n$(basename $filename | cut -f 1 -d '.')\n" | cat >> LICENSE
+ cat $filename >> LICENSE
+ done
+}
+
+function pip_wheel_cmd {
+ local abs_wheelhouse=$1
+ if [ -z "$IS_MACOS" ]; then
+ CFLAGS="$CFLAGS --std=c99" # for Raqm
+ fi
+ python3 -m pip wheel $(pip_opts) \
+ -C raqm=enable -C raqm=vendor -C fribidi=vendor \
+ -w $abs_wheelhouse --no-deps .
+}
+
+function run_tests_in_repo {
+ # Run Pillow tests from within source repo
+ python3 selftest.py
+ python3 -m pytest
+}
+
+EXP_CODECS="jpg jpg_2000 libtiff zlib"
+EXP_MODULES="freetype2 littlecms2 pil tkinter webp"
+EXP_FEATURES="fribidi harfbuzz libjpeg_turbo raqm transp_webp webp_anim webp_mux xcb"
+
+function run_tests {
+ if [ -n "$IS_MACOS" ]; then
+ brew install fribidi
+ export PKG_CONFIG_PATH="/usr/local/opt/openblas/lib/pkgconfig"
+ elif [ -n "$IS_ALPINE" ]; then
+ apk add curl fribidi
+ else
+ apt-get update
+ apt-get install -y curl libfribidi0 libopenblas-dev pkg-config unzip
+ fi
+ if [ -z "$IS_ALPINE" ]; then
+ python3 -m pip install numpy
+ fi
+ python3 -m pip install defusedxml olefile pyroma
+
+ curl -fsSL -o pillow-test-images.zip https://github.com/python-pillow/test-images/archive/main.zip
+ untar pillow-test-images.zip
+ mv test-images-main/* ../Tests/images
+
+ # Runs tests on installed distribution from an empty directory
+ (cd .. && run_tests_in_repo)
+ # Test against expected codecs, modules and features
+ local ret=0
+ local codecs=$(python3 -c 'from PIL.features import *; print(" ".join(sorted(get_supported_codecs())))')
+ if [ "$codecs" != "$EXP_CODECS" ]; then
+ echo "Codecs should be: '$EXP_CODECS'; but are '$codecs'"
+ ret=1
+ fi
+ local modules=$(python3 -c 'from PIL.features import *; print(" ".join(sorted(get_supported_modules())))')
+ if [ "$modules" != "$EXP_MODULES" ]; then
+ echo "Modules should be: '$EXP_MODULES'; but are '$modules'"
+ ret=1
+ fi
+ local features=$(python3 -c 'from PIL.features import *; print(" ".join(sorted(get_supported_features())))')
+ if [ "$features" != "$EXP_FEATURES" ]; then
+ echo "Features should be: '$EXP_FEATURES'; but are '$features'"
+ ret=1
+ fi
+ return $ret
+}
diff --git a/wheels/dependency_licenses/BROTLI.txt b/wheels/dependency_licenses/BROTLI.txt
new file mode 100644
index 000000000..33b7cdd2d
--- /dev/null
+++ b/wheels/dependency_licenses/BROTLI.txt
@@ -0,0 +1,19 @@
+Copyright (c) 2009, 2010, 2013-2016 by the Brotli Authors.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/wheels/dependency_licenses/BZIP2.txt b/wheels/dependency_licenses/BZIP2.txt
new file mode 100644
index 000000000..d3edf477d
--- /dev/null
+++ b/wheels/dependency_licenses/BZIP2.txt
@@ -0,0 +1,42 @@
+
+--------------------------------------------------------------------------
+
+This program, "bzip2", the associated library "libbzip2", and all
+documentation, are copyright (C) 1996-2019 Julian R Seward. All
+rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+2. The origin of this software must not be misrepresented; you must
+ not claim that you wrote the original software. If you use this
+ software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+3. Altered source versions must be plainly marked as such, and must
+ not be misrepresented as being the original software.
+
+4. The name of the author may not be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+Julian Seward, jseward@acm.org
+bzip2/libbzip2 version 1.0.8 of 13 July 2019
+
+--------------------------------------------------------------------------
diff --git a/wheels/dependency_licenses/FREETYPE2.txt b/wheels/dependency_licenses/FREETYPE2.txt
new file mode 100644
index 000000000..cca8d8ce1
--- /dev/null
+++ b/wheels/dependency_licenses/FREETYPE2.txt
@@ -0,0 +1,40 @@
+The FreeType 2 font engine is copyrighted work and cannot be used
+legally without a software license. In order to make this project
+usable to a vast majority of developers, we distribute it under two
+mutually exclusive open-source licenses.
+
+This means that *you* must choose *one* of the two licenses described
+below, then obey all its terms and conditions when using FreeType 2 in
+any of your projects or products.
+
+ - The FreeType License, found in the file `docs/FTL.TXT`, which is
+ similar to the original BSD license *with* an advertising clause
+ that forces you to explicitly cite the FreeType project in your
+ product's documentation. All details are in the license file.
+ This license is suited to products which don't use the GNU General
+ Public License.
+
+ Note that this license is compatible to the GNU General Public
+ License version 3, but not version 2.
+
+ - The GNU General Public License version 2, found in
+ `docs/GPLv2.TXT` (any later version can be used also), for
+ programs which already use the GPL. Note that the FTL is
+ incompatible with GPLv2 due to its advertisement clause.
+
+The contributed BDF and PCF drivers come with a license similar to
+that of the X Window System. It is compatible to the above two
+licenses (see files `src/bdf/README` and `src/pcf/README`). The same
+holds for the source code files `src/base/fthash.c` and
+`include/freetype/internal/fthash.h`; they were part of the BDF driver
+in earlier FreeType versions.
+
+The gzip module uses the zlib license (see `src/gzip/zlib.h`) which
+too is compatible to the above two licenses.
+
+The files `src/autofit/ft-hb.c` and `src/autofit/ft-hb.h` contain code
+taken almost verbatim from the HarfBuzz file `hb-ft.cc`, which uses
+the 'Old MIT' license, compatible to the above two licenses.
+
+The MD5 checksum support (only used for debugging in development
+builds) is in the public domain.
diff --git a/wheels/dependency_licenses/HARFBUZZ.txt b/wheels/dependency_licenses/HARFBUZZ.txt
new file mode 100644
index 000000000..1dd917e9f
--- /dev/null
+++ b/wheels/dependency_licenses/HARFBUZZ.txt
@@ -0,0 +1,42 @@
+HarfBuzz is licensed under the so-called "Old MIT" license. Details follow.
+For parts of HarfBuzz that are licensed under different licenses see individual
+files names COPYING in subdirectories where applicable.
+
+Copyright © 2010-2022 Google, Inc.
+Copyright © 2015-2020 Ebrahim Byagowi
+Copyright © 2019,2020 Facebook, Inc.
+Copyright © 2012,2015 Mozilla Foundation
+Copyright © 2011 Codethink Limited
+Copyright © 2008,2010 Nokia Corporation and/or its subsidiary(-ies)
+Copyright © 2009 Keith Stribley
+Copyright © 2011 Martin Hosken and SIL International
+Copyright © 2007 Chris Wilson
+Copyright © 2005,2006,2020,2021,2022,2023 Behdad Esfahbod
+Copyright © 2004,2007,2008,2009,2010,2013,2021,2022,2023 Red Hat, Inc.
+Copyright © 1998-2005 David Turner and Werner Lemberg
+Copyright © 2016 Igalia S.L.
+Copyright © 2022 Matthias Clasen
+Copyright © 2018,2021 Khaled Hosny
+Copyright © 2018,2019,2020 Adobe, Inc
+Copyright © 2013-2015 Alexei Podtelezhnikov
+
+For full copyright notices consult the individual files in the package.
+
+
+Permission is hereby granted, without written agreement and without
+license or royalty fees, to use, copy, modify, and distribute this
+software and its documentation for any purpose, provided that the
+above copyright notice and the following two paragraphs appear in
+all copies of this software.
+
+IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
+DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
+ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
+IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGE.
+
+THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
+PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
diff --git a/wheels/dependency_licenses/LCMS2.txt b/wheels/dependency_licenses/LCMS2.txt
new file mode 100644
index 000000000..21ed6fb86
--- /dev/null
+++ b/wheels/dependency_licenses/LCMS2.txt
@@ -0,0 +1,8 @@
+Little CMS
+Copyright (c) 1998-2020 Marti Maria Saguer
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/wheels/dependency_licenses/LIBJPEG.txt b/wheels/dependency_licenses/LIBJPEG.txt
new file mode 100644
index 000000000..b5451f405
--- /dev/null
+++ b/wheels/dependency_licenses/LIBJPEG.txt
@@ -0,0 +1,43 @@
+1. We don't promise that this software works. (But if you find any bugs,
+ please let us know!)
+2. You can use this software for whatever you want. You don't have to pay us.
+3. You may not pretend that you wrote this software. If you use it in a
+ program, you must acknowledge somewhere in your documentation that
+ you've used the IJG code.
+
+In legalese:
+
+The authors make NO WARRANTY or representation, either express or implied,
+with respect to this software, its quality, accuracy, merchantability, or
+fitness for a particular purpose. This software is provided "AS IS", and you,
+its user, assume the entire risk as to its quality and accuracy.
+
+This software is copyright (C) 1991-2020, Thomas G. Lane, Guido Vollbeding.
+All Rights Reserved except as specified below.
+
+Permission is hereby granted to use, copy, modify, and distribute this
+software (or portions thereof) for any purpose, without fee, subject to these
+conditions:
+(1) If any part of the source code for this software is distributed, then this
+README file must be included, with this copyright and no-warranty notice
+unaltered; and any additions, deletions, or changes to the original files
+must be clearly indicated in accompanying documentation.
+(2) If only executable code is distributed, then the accompanying
+documentation must state that "this software is based in part on the work of
+the Independent JPEG Group".
+(3) Permission for use of this software is granted only if the user accepts
+full responsibility for any undesirable consequences; the authors accept
+NO LIABILITY for damages of any kind.
+
+These conditions apply to any software derived from or based on the IJG code,
+not just to the unmodified library. If you use our work, you ought to
+acknowledge us.
+
+Permission is NOT granted for the use of any IJG author's name or company name
+in advertising or publicity relating to this software or products derived from
+it. This software may be referred to only as "the Independent JPEG Group's
+software".
+
+We specifically permit and encourage the use of this software as the basis of
+commercial products, provided that all warranty or liability claims are
+assumed by the product vendor.
diff --git a/wheels/dependency_licenses/LIBLZMA.txt b/wheels/dependency_licenses/LIBLZMA.txt
new file mode 100644
index 000000000..43c7a23ba
--- /dev/null
+++ b/wheels/dependency_licenses/LIBLZMA.txt
@@ -0,0 +1,63 @@
+XZ Utils Licensing
+==================
+
+ Different licenses apply to different files in this package. Here
+ is a rough summary of which licenses apply to which parts of this
+ package (but check the individual files to be sure!):
+
+ - liblzma is in the public domain.
+
+ - xz, xzdec, and lzmadec command line tools are in the public
+ domain unless GNU getopt_long had to be compiled and linked
+ in from the lib directory. The getopt_long code is under
+ GNU LGPLv2.1+.
+
+ - The scripts to grep, diff, and view compressed files have been
+ adapted from gzip. These scripts and their documentation are
+ under GNU GPLv2+.
+
+ - All the documentation in the doc directory and most of the
+ XZ Utils specific documentation files in other directories
+ are in the public domain.
+
+ - Translated messages are in the public domain.
+
+ - The build system contains public domain files, and files that
+ are under GNU GPLv2+ or GNU GPLv3+. None of these files end up
+ in the binaries being built.
+
+ - Test files and test code in the tests directory, and debugging
+ utilities in the debug directory are in the public domain.
+
+ - The extra directory may contain public domain files, and files
+ that are under various free software licenses.
+
+ You can do whatever you want with the files that have been put into
+ the public domain. If you find public domain legally problematic,
+ take the previous sentence as a license grant. If you still find
+ the lack of copyright legally problematic, you have too many
+ lawyers.
+
+ As usual, this software is provided "as is", without any warranty.
+
+ If you copy significant amounts of public domain code from XZ Utils
+ into your project, acknowledging this somewhere in your software is
+ polite (especially if it is proprietary, non-free software), but
+ naturally it is not legally required. Here is an example of a good
+ notice to put into "about box" or into documentation:
+
+ This software includes code from XZ Utils .
+
+ The following license texts are included in the following files:
+ - COPYING.LGPLv2.1: GNU Lesser General Public License version 2.1
+ - COPYING.GPLv2: GNU General Public License version 2
+ - COPYING.GPLv3: GNU General Public License version 3
+
+ Note that the toolchain (compiler, linker etc.) may add some code
+ pieces that are copyrighted. Thus, it is possible that e.g. liblzma
+ binary wouldn't actually be in the public domain in its entirety
+ even though it contains no copyrighted code from the XZ Utils source
+ package.
+
+ If you have questions, don't hesitate to ask the author(s) for more
+ information.
diff --git a/wheels/dependency_licenses/LIBPNG.txt b/wheels/dependency_licenses/LIBPNG.txt
new file mode 100644
index 000000000..c8ad24eec
--- /dev/null
+++ b/wheels/dependency_licenses/LIBPNG.txt
@@ -0,0 +1,134 @@
+COPYRIGHT NOTICE, DISCLAIMER, and LICENSE
+=========================================
+
+PNG Reference Library License version 2
+---------------------------------------
+
+ * Copyright (c) 1995-2022 The PNG Reference Library Authors.
+ * Copyright (c) 2018-2022 Cosmin Truta.
+ * Copyright (c) 2000-2002, 2004, 2006-2018 Glenn Randers-Pehrson.
+ * Copyright (c) 1996-1997 Andreas Dilger.
+ * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
+
+The software is supplied "as is", without warranty of any kind,
+express or implied, including, without limitation, the warranties
+of merchantability, fitness for a particular purpose, title, and
+non-infringement. In no event shall the Copyright owners, or
+anyone distributing the software, be liable for any damages or
+other liability, whether in contract, tort or otherwise, arising
+from, out of, or in connection with the software, or the use or
+other dealings in the software, even if advised of the possibility
+of such damage.
+
+Permission is hereby granted to use, copy, modify, and distribute
+this software, or portions hereof, for any purpose, without fee,
+subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+ must not claim that you wrote the original software. If you
+ use this software in a product, an acknowledgment in the product
+ documentation would be appreciated, but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and must
+ not be misrepresented as being the original software.
+
+ 3. This Copyright notice may not be removed or altered from any
+ source or altered source distribution.
+
+
+PNG Reference Library License version 1 (for libpng 0.5 through 1.6.35)
+-----------------------------------------------------------------------
+
+libpng versions 1.0.7, July 1, 2000, through 1.6.35, July 15, 2018 are
+Copyright (c) 2000-2002, 2004, 2006-2018 Glenn Randers-Pehrson, are
+derived from libpng-1.0.6, and are distributed according to the same
+disclaimer and license as libpng-1.0.6 with the following individuals
+added to the list of Contributing Authors:
+
+ Simon-Pierre Cadieux
+ Eric S. Raymond
+ Mans Rullgard
+ Cosmin Truta
+ Gilles Vollant
+ James Yu
+ Mandar Sahastrabuddhe
+ Google Inc.
+ Vadim Barkov
+
+and with the following additions to the disclaimer:
+
+ There is no warranty against interference with your enjoyment of
+ the library or against infringement. There is no warranty that our
+ efforts or the library will fulfill any of your particular purposes
+ or needs. This library is provided with all faults, and the entire
+ risk of satisfactory quality, performance, accuracy, and effort is
+ with the user.
+
+Some files in the "contrib" directory and some configure-generated
+files that are distributed with libpng have other copyright owners, and
+are released under other open source licenses.
+
+libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are
+Copyright (c) 1998-2000 Glenn Randers-Pehrson, are derived from
+libpng-0.96, and are distributed according to the same disclaimer and
+license as libpng-0.96, with the following individuals added to the
+list of Contributing Authors:
+
+ Tom Lane
+ Glenn Randers-Pehrson
+ Willem van Schaik
+
+libpng versions 0.89, June 1996, through 0.96, May 1997, are
+Copyright (c) 1996-1997 Andreas Dilger, are derived from libpng-0.88,
+and are distributed according to the same disclaimer and license as
+libpng-0.88, with the following individuals added to the list of
+Contributing Authors:
+
+ John Bowler
+ Kevin Bracey
+ Sam Bushell
+ Magnus Holmgren
+ Greg Roelofs
+ Tom Tanner
+
+Some files in the "scripts" directory have other copyright owners,
+but are released under this license.
+
+libpng versions 0.5, May 1995, through 0.88, January 1996, are
+Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
+
+For the purposes of this copyright and license, "Contributing Authors"
+is defined as the following set of individuals:
+
+ Andreas Dilger
+ Dave Martindale
+ Guy Eric Schalnat
+ Paul Schmidt
+ Tim Wegner
+
+The PNG Reference Library is supplied "AS IS". The Contributing
+Authors and Group 42, Inc. disclaim all warranties, expressed or
+implied, including, without limitation, the warranties of
+merchantability and of fitness for any purpose. The Contributing
+Authors and Group 42, Inc. assume no liability for direct, indirect,
+incidental, special, exemplary, or consequential damages, which may
+result from the use of the PNG Reference Library, even if advised of
+the possibility of such damage.
+
+Permission is hereby granted to use, copy, modify, and distribute this
+source code, or portions hereof, for any purpose, without fee, subject
+to the following restrictions:
+
+ 1. The origin of this source code must not be misrepresented.
+
+ 2. Altered versions must be plainly marked as such and must not
+ be misrepresented as being the original source.
+
+ 3. This Copyright notice may not be removed or altered from any
+ source or altered source distribution.
+
+The Contributing Authors and Group 42, Inc. specifically permit,
+without fee, and encourage the use of this source code as a component
+to supporting the PNG file format in commercial products. If you use
+this source code in a product, acknowledgment is not required but would
+be appreciated.
diff --git a/wheels/dependency_licenses/LIBTIFF.txt b/wheels/dependency_licenses/LIBTIFF.txt
new file mode 100644
index 000000000..dc255dec6
--- /dev/null
+++ b/wheels/dependency_licenses/LIBTIFF.txt
@@ -0,0 +1,21 @@
+Copyright (c) 1988-1997 Sam Leffler
+Copyright (c) 1991-1997 Silicon Graphics, Inc.
+
+Permission to use, copy, modify, distribute, and sell this software and
+its documentation for any purpose is hereby granted without fee, provided
+that (i) the above copyright notices and this permission notice appear in
+all copies of the software and related documentation, and (ii) the names of
+Sam Leffler and Silicon Graphics may not be used in any advertising or
+publicity relating to the software without the specific, prior written
+permission of Sam Leffler and Silicon Graphics.
+
+THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
+EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
+WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
+
+IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
+ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
+OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
+LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+OF THIS SOFTWARE.
diff --git a/wheels/dependency_licenses/LIBWEBP.txt b/wheels/dependency_licenses/LIBWEBP.txt
new file mode 100644
index 000000000..83e4e6f6d
--- /dev/null
+++ b/wheels/dependency_licenses/LIBWEBP.txt
@@ -0,0 +1,29 @@
+Copyright (c) 2010, Google Inc. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of Google nor the names of its contributors may
+ be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/wheels/dependency_licenses/OPENJPEG.txt b/wheels/dependency_licenses/OPENJPEG.txt
new file mode 100644
index 000000000..c41fc21d8
--- /dev/null
+++ b/wheels/dependency_licenses/OPENJPEG.txt
@@ -0,0 +1,39 @@
+*
+ * The copyright in this software is being made available under the 2-clauses
+ * BSD License, included below. This software may be subject to other third
+ * party and contributor rights, including patent rights, and no such rights
+ * are granted under this license.
+ *
+ * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
+ * Copyright (c) 2002-2014, Professor Benoit Macq
+ * Copyright (c) 2003-2014, Antonin Descampe
+ * Copyright (c) 2003-2009, Francois-Olivier Devaux
+ * Copyright (c) 2005, Herve Drolon, FreeImage Team
+ * Copyright (c) 2002-2003, Yannick Verschueren
+ * Copyright (c) 2001-2003, David Janssens
+ * Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France
+ * Copyright (c) 2012, CS Systemes d'Information, France
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
diff --git a/wheels/dependency_licenses/RAQM.txt b/wheels/dependency_licenses/RAQM.txt
new file mode 100644
index 000000000..196511ef6
--- /dev/null
+++ b/wheels/dependency_licenses/RAQM.txt
@@ -0,0 +1,22 @@
+The MIT License (MIT)
+
+Copyright © 2015 Information Technology Authority (ITA)
+Copyright © 2016 Khaled Hosny
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/wheels/dependency_licenses/XAU.txt b/wheels/dependency_licenses/XAU.txt
new file mode 100644
index 000000000..64492ad80
--- /dev/null
+++ b/wheels/dependency_licenses/XAU.txt
@@ -0,0 +1,21 @@
+Copyright 1988, 1993, 1994, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
diff --git a/wheels/dependency_licenses/XCB.txt b/wheels/dependency_licenses/XCB.txt
new file mode 100644
index 000000000..54bfbe5b0
--- /dev/null
+++ b/wheels/dependency_licenses/XCB.txt
@@ -0,0 +1,30 @@
+Copyright (C) 2001-2006 Bart Massey, Jamey Sharp, and Josh Triplett.
+All Rights Reserved.
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated
+documentation files (the "Software"), to deal in the
+Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute,
+sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall
+be included in all copies or substantial portions of the
+Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
+BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the names of the authors
+or their institutions shall not be used in advertising or
+otherwise to promote the sale, use or other dealings in this
+Software without prior written authorization from the
+authors.
diff --git a/wheels/dependency_licenses/XDMCP.txt b/wheels/dependency_licenses/XDMCP.txt
new file mode 100644
index 000000000..5532d143c
--- /dev/null
+++ b/wheels/dependency_licenses/XDMCP.txt
@@ -0,0 +1,23 @@
+Copyright 1989, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+Author: Keith Packard, MIT X Consortium
diff --git a/wheels/dependency_licenses/ZLIB.txt b/wheels/dependency_licenses/ZLIB.txt
new file mode 100644
index 000000000..84def6dc6
--- /dev/null
+++ b/wheels/dependency_licenses/ZLIB.txt
@@ -0,0 +1,29 @@
+ (C) 1995-2017 Jean-loup Gailly and Mark Adler
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+
+ Jean-loup Gailly Mark Adler
+ jloup@gzip.org madler@alumni.caltech.edu
+
+If you use the zlib library in a product, we would appreciate *not* receiving
+lengthy legal documents to sign. The sources are provided for free but without
+warranty of any kind. The library has been entirely written by Jean-loup
+Gailly and Mark Adler; it does not include third-party code.
+
+If you redistribute modified sources, we would appreciate that you include in
+the file ChangeLog history information documenting your changes. Please read
+the FAQ for more information on the distribution of modified source versions.
diff --git a/wheels/multibuild b/wheels/multibuild
new file mode 160000
index 000000000..452dd2d17
--- /dev/null
+++ b/wheels/multibuild
@@ -0,0 +1 @@
+Subproject commit 452dd2d1705f6b2375369a6570c415beb3163f70
diff --git a/winbuild/build_prepare.py b/winbuild/build_prepare.py
index c94d8a363..22b5a3056 100644
--- a/winbuild/build_prepare.py
+++ b/winbuild/build_prepare.py
@@ -1,3 +1,5 @@
+from __future__ import annotations
+
import argparse
import os
import platform
@@ -7,42 +9,41 @@ import struct
import subprocess
-def cmd_cd(path):
+def cmd_cd(path: str) -> str:
return f"cd /D {path}"
-def cmd_set(name, value):
+def cmd_set(name: str, value: str) -> str:
return f"set {name}={value}"
-def cmd_append(name, value):
+def cmd_append(name: str, value: str) -> str:
op = "path " if name == "PATH" else f"set {name}="
return op + f"%{name}%;{value}"
-def cmd_copy(src, tgt):
+def cmd_copy(src: str, tgt: str) -> str:
return f'copy /Y /B "{src}" "{tgt}"'
-def cmd_xcopy(src, tgt):
+def cmd_xcopy(src: str, tgt: str) -> str:
return f'xcopy /Y /E "{src}" "{tgt}"'
-def cmd_mkdir(path):
+def cmd_mkdir(path: str) -> str:
return f'mkdir "{path}"'
-def cmd_rmdir(path):
+def cmd_rmdir(path: str) -> str:
return f'rmdir /S /Q "{path}"'
-def cmd_nmake(makefile=None, target="", params=None):
- if params is None:
- params = ""
- elif isinstance(params, (list, tuple)):
- params = " ".join(params)
- else:
- params = str(params)
+def cmd_nmake(
+ makefile: str | None = None,
+ target: str = "",
+ params: list[str] | None = None,
+) -> str:
+ params = "" if params is None else " ".join(params)
return " ".join(
[
@@ -55,7 +56,7 @@ def cmd_nmake(makefile=None, target="", params=None):
)
-def cmds_cmake(target, *params):
+def cmds_cmake(target: str | tuple[str, ...] | list[str], *params) -> list[str]:
if not isinstance(target, str):
target = " ".join(target)
@@ -80,8 +81,11 @@ def cmds_cmake(target, *params):
def cmd_msbuild(
- file, configuration="Release", target="Build", platform="{msbuild_arch}"
-):
+ file: str,
+ configuration: str = "Release",
+ target: str = "Build",
+ platform: str = "{msbuild_arch}",
+) -> str:
return " ".join(
[
"{msbuild}",
@@ -96,14 +100,14 @@ def cmd_msbuild(
SF_PROJECTS = "https://sourceforge.net/projects"
-architectures = {
+ARCHITECTURES = {
"x86": {"vcvars_arch": "x86", "msbuild_arch": "Win32"},
"x64": {"vcvars_arch": "x86_amd64", "msbuild_arch": "x64"},
"ARM64": {"vcvars_arch": "x86_arm64", "msbuild_arch": "ARM64"},
}
# dependencies, listed in order of compilation
-deps = {
+DEPS = {
"libjpeg": {
"url": SF_PROJECTS
+ "/libjpeg-turbo/files/3.0.0/libjpeg-turbo-3.0.0.tar.gz/download",
@@ -157,9 +161,9 @@ deps = {
"libs": [r"liblzma.lib"],
},
"libwebp": {
- "url": "http://downloads.webmproject.org/releases/webp/libwebp-1.3.1.tar.gz",
- "filename": "libwebp-1.3.1.tar.gz",
- "dir": "libwebp-1.3.1",
+ "url": "http://downloads.webmproject.org/releases/webp/libwebp-1.3.2.tar.gz",
+ "filename": "libwebp-1.3.2.tar.gz",
+ "dir": "libwebp-1.3.2",
"license": "COPYING",
"build": [
cmd_rmdir(r"output\release-static"), # clean
@@ -180,9 +184,9 @@ deps = {
"libs": [r"output\release-static\{architecture}\lib\*.lib"],
},
"libtiff": {
- "url": "https://download.osgeo.org/libtiff/tiff-4.5.1.tar.gz",
- "filename": "tiff-4.5.1.tar.gz",
- "dir": "tiff-4.5.1",
+ "url": "https://download.osgeo.org/libtiff/tiff-4.6.0.tar.gz",
+ "filename": "tiff-4.6.0.tar.gz",
+ "dir": "tiff-4.6.0",
"license": "LICENSE.md",
"patch": {
r"libtiff\tif_lzma.c": {
@@ -224,20 +228,20 @@ deps = {
"libs": [r"libpng16.lib"],
},
"brotli": {
- "url": "https://github.com/google/brotli/archive/refs/tags/v1.0.9.tar.gz",
- "filename": "brotli-1.0.9.tar.gz",
- "dir": "brotli-1.0.9",
+ "url": "https://github.com/google/brotli/archive/refs/tags/v1.1.0.tar.gz",
+ "filename": "brotli-1.1.0.tar.gz",
+ "dir": "brotli-1.1.0",
"license": "LICENSE",
"build": [
- *cmds_cmake(("brotlicommon-static", "brotlidec-static")),
+ *cmds_cmake(("brotlicommon", "brotlidec"), "-DBUILD_SHARED_LIBS:BOOL=OFF"),
cmd_xcopy(r"c\include", "{inc_dir}"),
],
"libs": ["*.lib"],
},
"freetype": {
- "url": "https://download.savannah.gnu.org/releases/freetype/freetype-2.13.1.tar.gz", # noqa: E501
- "filename": "freetype-2.13.1.tar.gz",
- "dir": "freetype-2.13.1",
+ "url": "https://download.savannah.gnu.org/releases/freetype/freetype-2.13.2.tar.gz", # noqa: E501
+ "filename": "freetype-2.13.2.tar.gz",
+ "dir": "freetype-2.13.2",
"license": ["LICENSE.TXT", r"docs\FTL.TXT", r"docs\GPLv2.TXT"],
"patch": {
r"builds\windows\vc2010\freetype.vcxproj": {
@@ -250,7 +254,7 @@ deps = {
"": "FT_CONFIG_OPTION_SYSTEM_ZLIB;FT_CONFIG_OPTION_USE_PNG;FT_CONFIG_OPTION_USE_HARFBUZZ;FT_CONFIG_OPTION_USE_BROTLI", # noqa: E501
"": r"{dir_harfbuzz}\src;{inc_dir}", # noqa: E501
"": "{lib_dir}", # noqa: E501
- "": "zlib.lib;libpng16.lib;brotlicommon-static.lib;brotlidec-static.lib", # noqa: E501
+ "": "zlib.lib;libpng16.lib;brotlicommon.lib;brotlidec.lib", # noqa: E501
},
r"src/autofit/afshaper.c": {
# link against harfbuzz.lib
@@ -335,9 +339,9 @@ deps = {
"libs": [r"imagequant.lib"],
},
"harfbuzz": {
- "url": "https://github.com/harfbuzz/harfbuzz/archive/8.1.1.zip",
- "filename": "harfbuzz-8.1.1.zip",
- "dir": "harfbuzz-8.1.1",
+ "url": "https://github.com/harfbuzz/harfbuzz/archive/8.2.1.zip",
+ "filename": "harfbuzz-8.2.1.zip",
+ "dir": "harfbuzz-8.2.1",
"license": "COPYING",
"build": [
*cmds_cmake(
@@ -365,7 +369,7 @@ deps = {
# based on distutils._msvccompiler from CPython 3.7.4
-def find_msvs():
+def find_msvs() -> dict[str, str] | None:
root = os.environ.get("ProgramFiles(x86)") or os.environ.get("ProgramFiles")
if not root:
print("Program Files not found")
@@ -421,25 +425,40 @@ def find_msvs():
}
-def extract_dep(url, filename):
- import tarfile
+def download_dep(url: str, file: str) -> None:
import urllib.request
+
+ ex = None
+ for i in range(3):
+ try:
+ print(f"Fetching {url} (attempt {i + 1})...")
+ content = urllib.request.urlopen(url).read()
+ with open(file, "wb") as f:
+ f.write(content)
+ break
+ except urllib.error.URLError as e:
+ ex = e
+ else:
+ raise RuntimeError(ex)
+
+
+def extract_dep(url: str, filename: str) -> None:
+ import tarfile
import zipfile
file = os.path.join(args.depends_dir, filename)
if not os.path.exists(file):
- ex = None
- for i in range(3):
- try:
- print("Fetching %s (attempt %d)..." % (url, i + 1))
- content = urllib.request.urlopen(url).read()
- with open(file, "wb") as f:
- f.write(content)
- break
- except urllib.error.URLError as e:
- ex = e
- else:
- raise RuntimeError(ex)
+ # First try our mirror
+ mirror_url = (
+ f"https://raw.githubusercontent.com/"
+ f"python-pillow/pillow-depends/main/{filename}"
+ )
+ try:
+ download_dep(mirror_url, file)
+ except RuntimeError as exc:
+ # Otherwise try upstream
+ print(exc)
+ download_dep(url, file)
print("Extracting " + filename)
sources_dir_abs = os.path.abspath(sources_dir)
@@ -466,7 +485,7 @@ def extract_dep(url, filename):
raise RuntimeError(msg)
-def write_script(name, lines):
+def write_script(name: str, lines: list[str]) -> None:
name = os.path.join(args.build_dir, name)
lines = [line.format(**prefs) for line in lines]
print("Writing " + name)
@@ -477,7 +496,7 @@ def write_script(name, lines):
print(" " + line)
-def get_footer(dep):
+def get_footer(dep: dict) -> list[str]:
lines = []
for out in dep.get("headers", []):
lines.append(cmd_copy(out, "{inc_dir}"))
@@ -488,7 +507,7 @@ def get_footer(dep):
return lines
-def build_env():
+def build_env() -> None:
lines = [
"if defined DISTUTILS_USE_SDK goto end",
cmd_set("INCLUDE", "{inc_dir}"),
@@ -504,8 +523,8 @@ def build_env():
write_script("build_env.cmd", lines)
-def build_dep(name):
- dep = deps[name]
+def build_dep(name: str) -> str:
+ dep = DEPS[name]
dir = dep["dir"]
file = f"build_dep_{name}.cmd"
@@ -554,9 +573,9 @@ def build_dep(name):
return file
-def build_dep_all():
+def build_dep_all() -> None:
lines = [r'call "{build_dir}\build_env.cmd"']
- for dep_name in deps:
+ for dep_name in DEPS:
print()
if dep_name in disabled:
print(f"Skipping disabled dependency {dep_name}")
@@ -602,7 +621,7 @@ if __name__ == "__main__":
)
parser.add_argument(
"--architecture",
- choices=architectures,
+ choices=ARCHITECTURES,
default=os.environ.get(
"ARCHITECTURE",
(
@@ -634,7 +653,7 @@ if __name__ == "__main__":
)
args = parser.parse_args()
- arch_prefs = architectures[args.architecture]
+ arch_prefs = ARCHITECTURES[args.architecture]
print("Target architecture:", args.architecture)
msvs = find_msvs()
@@ -693,7 +712,7 @@ if __name__ == "__main__":
# TODO find NASM automatically
}
- for k, v in deps.items():
+ for k, v in DEPS.items():
prefs[f"dir_{k}"] = os.path.join(sources_dir, v["dir"])
print()