diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs new file mode 100644 index 00000000000..a2be59c52e4 --- /dev/null +++ b/.git-blame-ignore-revs @@ -0,0 +1,6 @@ +# Flake8 +8de95676e0fd89f2326b3953488ab66ff29cd2d0 +# Format with Black +53a7e3500437a9fd5826bc04758f7116bd7e52dc +# Format the C code with ClangFormat +46b7e86bab79450ec0a2866c6c0c679afb659d17 diff --git a/.github/workflows/cifuzz.yml b/.github/workflows/cifuzz.yml index 55a672dd8dc..eb73fc6a7cd 100644 --- a/.github/workflows/cifuzz.yml +++ b/.github/workflows/cifuzz.yml @@ -42,13 +42,13 @@ jobs: language: python dry-run: false - name: Upload New Crash - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 if: failure() && steps.build.outcome == 'success' with: name: artifacts path: ./out/artifacts - name: Upload Legacy Crash - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 if: steps.run.outcome == 'success' with: name: crash diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index c8fda7e7f55..9069fc615f3 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -2,6 +2,9 @@ name: Lint on: [push, pull_request, workflow_dispatch] +env: + FORCE_COLOR: 1 + permissions: contents: read @@ -46,3 +49,6 @@ jobs: run: tox -e lint env: PRE_COMMIT_COLOR: always + + - name: Mypy + run: tox -e mypy diff --git a/.github/workflows/system-info.py b/.github/workflows/system-info.py index 8e840319a7d..57f28c620b7 100644 --- a/.github/workflows/system-info.py +++ b/.github/workflows/system-info.py @@ -6,6 +6,8 @@ Requested here: https://github.com/actions/virtual-environments/issues/79 """ +from __future__ import annotations + import os import platform import sys diff --git a/.github/workflows/test-cygwin.yml b/.github/workflows/test-cygwin.yml index 10de3b9fb0c..32ac6f65e76 100644 --- a/.github/workflows/test-cygwin.yml +++ b/.github/workflows/test-cygwin.yml @@ -132,7 +132,7 @@ jobs: dash.exe -c "mkdir -p Tests/errors" - name: Upload errors - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 if: failure() with: name: errors diff --git a/.github/workflows/test-windows.yml b/.github/workflows/test-windows.yml index d5f06c90872..86cd5b5fa1e 100644 --- a/.github/workflows/test-windows.yml +++ b/.github/workflows/test-windows.yml @@ -190,7 +190,7 @@ jobs: shell: bash - name: Upload errors - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 if: failure() with: name: errors diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 715417474a1..aa0e2513825 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -112,7 +112,7 @@ jobs: mkdir -p Tests/errors - name: Upload errors - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 if: failure() with: name: errors diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 55c41b595dc..c73cdb2c6c9 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -116,10 +116,7 @@ jobs: & python.exe -m pip install -r .ci/requirements-cibw.txt - # Cannot cross-compile FriBiDi (only used for tests) - $FLAGS = ("--no-imagequant", "--architecture=${{ matrix.arch }}") - if ('${{ matrix.arch }}' -eq 'ARM64') { $FLAGS += "--no-fribidi" } - & python.exe winbuild\build_prepare.py -v @FLAGS + & python.exe winbuild\build_prepare.py -v --no-imagequant --architecture=${{ matrix.arch }} shell: pwsh - name: Build wheels @@ -162,19 +159,11 @@ jobs: name: dist-${{ matrix.arch }} path: ./wheelhouse/*.whl - - name: Prepare to upload FriBiDi - if: "matrix.arch != 'ARM64'" - run: | - mkdir fribidi\${{ matrix.arch }} - copy winbuild\build\bin\fribidi* fribidi\${{ matrix.arch }} - shell: cmd - - name: Upload fribidi.dll - if: "matrix.arch != 'ARM64'" uses: actions/upload-artifact@v4 with: - name: fribidi-${{ matrix.arch }} - path: fribidi\* + name: fribidi-windows-${{ matrix.arch }} + path: winbuild\build\bin\fribidi* sdist: runs-on: ubuntu-latest diff --git a/CHANGES.rst b/CHANGES.rst index fd25b6f37f2..df4e11e0e48 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,24 @@ Changelog (Pillow) 10.2.0 (unreleased) ------------------- +- Fix incorrect color blending for overlapping glyphs #7497 + [ZachNagengast, nulano, radarhere] + +- Attempt memory mapping when tile args is a string #7565 + [radarhere] + +- Fill identical pixels with transparency in subsequent frames when saving GIF #7568 + [radarhere] + +- Corrected duration when combining multiple GIF frames into single frame #7521 + [radarhere] + +- Handle disposing GIF background from outside palette #7515 + [radarhere] + +- Seek past the data when skipping a PSD layer #7483 + [radarhere] + - Import plugins relative to the module #7576 [deliangyang, jaxx0n] diff --git a/Tests/32bit_segfault_check.py b/Tests/32bit_segfault_check.py index 2ff7f908f6d..06ed2ed2f60 100755 --- a/Tests/32bit_segfault_check.py +++ b/Tests/32bit_segfault_check.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +from __future__ import annotations import sys diff --git a/Tests/bench_cffi_access.py b/Tests/bench_cffi_access.py index 36ce63296e4..8a37c7d5157 100644 --- a/Tests/bench_cffi_access.py +++ b/Tests/bench_cffi_access.py @@ -1,3 +1,4 @@ +from __future__ import annotations import time from PIL import PyAccess diff --git a/Tests/check_fli_oob.py b/Tests/check_fli_oob.py index 7b3d4d7ee9d..ac46ff1ebc0 100644 --- a/Tests/check_fli_oob.py +++ b/Tests/check_fli_oob.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +from __future__ import annotations from PIL import Image diff --git a/Tests/check_fli_overflow.py b/Tests/check_fli_overflow.py index c600c45ed1f..0fabcb5d35f 100644 --- a/Tests/check_fli_overflow.py +++ b/Tests/check_fli_overflow.py @@ -1,3 +1,4 @@ +from __future__ import annotations from PIL import Image TEST_FILE = "Tests/images/fli_overflow.fli" diff --git a/Tests/check_icns_dos.py b/Tests/check_icns_dos.py index a34bee45c51..ac6be4869b3 100644 --- a/Tests/check_icns_dos.py +++ b/Tests/check_icns_dos.py @@ -1,5 +1,6 @@ # Tests potential DOS of IcnsImagePlugin with 0 length block. # Run from anywhere that PIL is importable. +from __future__ import annotations from io import BytesIO diff --git a/Tests/check_imaging_leaks.py b/Tests/check_imaging_leaks.py index d07082aba9f..8c17c051d4b 100755 --- a/Tests/check_imaging_leaks.py +++ b/Tests/check_imaging_leaks.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +from __future__ import annotations import pytest from PIL import Image diff --git a/Tests/check_j2k_dos.py b/Tests/check_j2k_dos.py index 71dcea4f39f..2c63c340214 100644 --- a/Tests/check_j2k_dos.py +++ b/Tests/check_j2k_dos.py @@ -1,5 +1,6 @@ # Tests potential DOS of Jpeg2kImagePlugin with 0 length block. # Run from anywhere that PIL is importable. +from __future__ import annotations from io import BytesIO diff --git a/Tests/check_j2k_leaks.py b/Tests/check_j2k_leaks.py index afe5836f3fd..83a12e2c29f 100644 --- a/Tests/check_j2k_leaks.py +++ b/Tests/check_j2k_leaks.py @@ -1,3 +1,4 @@ +from __future__ import annotations from io import BytesIO import pytest diff --git a/Tests/check_j2k_overflow.py b/Tests/check_j2k_overflow.py index b16412898f0..982f6ea74d2 100644 --- a/Tests/check_j2k_overflow.py +++ b/Tests/check_j2k_overflow.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image diff --git a/Tests/check_jp2_overflow.py b/Tests/check_jp2_overflow.py index 0210505f5fe..9afbff112b0 100755 --- a/Tests/check_jp2_overflow.py +++ b/Tests/check_jp2_overflow.py @@ -12,6 +12,7 @@ # the output should be empty. There may be python issues # in the valgrind especially if run in a debug python # version. +from __future__ import annotations from PIL import Image diff --git a/Tests/check_jpeg_leaks.py b/Tests/check_jpeg_leaks.py index 940c0b00d5b..3cd37c7af7b 100644 --- a/Tests/check_jpeg_leaks.py +++ b/Tests/check_jpeg_leaks.py @@ -1,3 +1,4 @@ +from __future__ import annotations from io import BytesIO import pytest diff --git a/Tests/check_large_memory.py b/Tests/check_large_memory.py index d98f4a694ef..9b83798d5e7 100644 --- a/Tests/check_large_memory.py +++ b/Tests/check_large_memory.py @@ -1,3 +1,4 @@ +from __future__ import annotations import sys import pytest diff --git a/Tests/check_large_memory_numpy.py b/Tests/check_large_memory_numpy.py index 24cb1f722bf..0ff3de8dcc7 100644 --- a/Tests/check_large_memory_numpy.py +++ b/Tests/check_large_memory_numpy.py @@ -1,3 +1,4 @@ +from __future__ import annotations import sys import pytest diff --git a/Tests/check_libtiff_segfault.py b/Tests/check_libtiff_segfault.py index bd7f407e4ab..ee1d7d11f0c 100644 --- a/Tests/check_libtiff_segfault.py +++ b/Tests/check_libtiff_segfault.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image diff --git a/Tests/check_png_dos.py b/Tests/check_png_dos.py index f4a129f50c6..292fe4b7f09 100644 --- a/Tests/check_png_dos.py +++ b/Tests/check_png_dos.py @@ -1,3 +1,4 @@ +from __future__ import annotations import zlib from io import BytesIO diff --git a/Tests/check_release_notes.py b/Tests/check_release_notes.py index 0a9a898d7f7..ebfaffa47e1 100644 --- a/Tests/check_release_notes.py +++ b/Tests/check_release_notes.py @@ -1,3 +1,4 @@ +from __future__ import annotations import sys from pathlib import Path diff --git a/Tests/check_wheel.py b/Tests/check_wheel.py index cc52cb75ebb..afe4cc3eeaa 100644 --- a/Tests/check_wheel.py +++ b/Tests/check_wheel.py @@ -1,3 +1,4 @@ +from __future__ import annotations import sys from PIL import features diff --git a/Tests/conftest.py b/Tests/conftest.py index 66da7593c2e..cd64bd755f0 100644 --- a/Tests/conftest.py +++ b/Tests/conftest.py @@ -1,3 +1,4 @@ +from __future__ import annotations import io diff --git a/Tests/createfontdatachunk.py b/Tests/createfontdatachunk.py index e318eb73217..2e990b70916 100755 --- a/Tests/createfontdatachunk.py +++ b/Tests/createfontdatachunk.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +from __future__ import annotations import base64 import os diff --git a/Tests/fonts/CBDTTestFont.ttf b/Tests/fonts/CBDTTestFont.ttf new file mode 100644 index 00000000000..73444e8dc4e Binary files /dev/null and b/Tests/fonts/CBDTTestFont.ttf differ diff --git a/Tests/fonts/EBDTTestFont.ttf b/Tests/fonts/EBDTTestFont.ttf new file mode 100644 index 00000000000..046e9e45cd6 Binary files /dev/null and b/Tests/fonts/EBDTTestFont.ttf differ diff --git a/Tests/fonts/LICENSE.txt b/Tests/fonts/LICENSE.txt index da559b3d3f2..3c8a23197e9 100644 --- a/Tests/fonts/LICENSE.txt +++ b/Tests/fonts/LICENSE.txt @@ -2,7 +2,6 @@ NotoNastaliqUrdu-Regular.ttf and NotoSansSymbols-Regular.ttf, from https://github.com/googlei18n/noto-fonts NotoSans-Regular.ttf, from https://www.google.com/get/noto/ NotoSansJP-Thin.otf, from https://www.google.com/get/noto/help/cjk/ -NotoColorEmoji.ttf, from https://github.com/googlefonts/noto-emoji AdobeVFPrototype.ttf, from https://github.com/adobe-fonts/adobe-variable-font-prototype TINY5x3GX.ttf, from http://velvetyne.fr/fonts/tiny ArefRuqaa-Regular.ttf, from https://github.com/google/fonts/tree/master/ofl/arefruqaa @@ -25,3 +24,5 @@ FreeMono.ttf is licensed under GPLv3. 10x20-ISO8859-1.pcf, from https://packages.ubuntu.com/xenial/xfonts-base "Public domain font. Share and enjoy." + +CBDTTestFont.ttf and EBDTTestFont.ttf from https://github.com/nulano/font-tests are public domain. diff --git a/Tests/fonts/NotoColorEmoji.ttf b/Tests/fonts/NotoColorEmoji.ttf deleted file mode 100644 index ef7b725758c..00000000000 Binary files a/Tests/fonts/NotoColorEmoji.ttf and /dev/null differ diff --git a/Tests/helper.py b/Tests/helper.py index cce7eca3a5a..b333c2fd4ef 100644 --- a/Tests/helper.py +++ b/Tests/helper.py @@ -1,6 +1,7 @@ """ Helper functions. """ +from __future__ import annotations import logging import os diff --git a/Tests/images/background_outside_palette.gif b/Tests/images/background_outside_palette.gif new file mode 100644 index 00000000000..63e767463c4 Binary files /dev/null and b/Tests/images/background_outside_palette.gif differ diff --git a/Tests/images/bitmap_font_blend.png b/Tests/images/bitmap_font_blend.png new file mode 100644 index 00000000000..a5acf366740 Binary files /dev/null and b/Tests/images/bitmap_font_blend.png differ diff --git a/Tests/images/bitmap_font_stroke_basic.png b/Tests/images/bitmap_font_stroke_basic.png index 86b2d09f66e..26aa3ab8ee7 100644 Binary files a/Tests/images/bitmap_font_stroke_basic.png and b/Tests/images/bitmap_font_stroke_basic.png differ diff --git a/Tests/images/bitmap_font_stroke_raqm.png b/Tests/images/bitmap_font_stroke_raqm.png index 08029ce34be..be273d7cb6b 100644 Binary files a/Tests/images/bitmap_font_stroke_raqm.png and b/Tests/images/bitmap_font_stroke_raqm.png differ diff --git a/Tests/images/cbdt.png b/Tests/images/cbdt.png new file mode 100644 index 00000000000..542bb812e2c Binary files /dev/null and b/Tests/images/cbdt.png differ diff --git a/Tests/images/cbdt_mask.png b/Tests/images/cbdt_mask.png new file mode 100644 index 00000000000..b0854a605e7 Binary files /dev/null and b/Tests/images/cbdt_mask.png differ diff --git a/Tests/images/cbdt_notocoloremoji.png b/Tests/images/cbdt_notocoloremoji.png deleted file mode 100644 index 1da12fba115..00000000000 Binary files a/Tests/images/cbdt_notocoloremoji.png and /dev/null differ diff --git a/Tests/images/cbdt_notocoloremoji_mask.png b/Tests/images/cbdt_notocoloremoji_mask.png deleted file mode 100644 index 6d036a0b6ba..00000000000 Binary files a/Tests/images/cbdt_notocoloremoji_mask.png and /dev/null differ diff --git a/Tests/images/default_font_freetype.png b/Tests/images/default_font_freetype.png index e00bb5d85c8..bc1654a253a 100644 Binary files a/Tests/images/default_font_freetype.png and b/Tests/images/default_font_freetype.png differ diff --git a/Tests/images/five_channels.psd b/Tests/images/five_channels.psd new file mode 100644 index 00000000000..021a5fa633b Binary files /dev/null and b/Tests/images/five_channels.psd differ diff --git a/Tests/images/test_combine_caron_below_ttb.png b/Tests/images/test_combine_caron_below_ttb.png index 5c7576de01b..2b7cc89eab3 100644 Binary files a/Tests/images/test_combine_caron_below_ttb.png and b/Tests/images/test_combine_caron_below_ttb.png differ diff --git a/Tests/images/test_combine_caron_below_ttb_lb.png b/Tests/images/test_combine_caron_below_ttb_lb.png index bacd6a141f1..3ced2dbfc88 100644 Binary files a/Tests/images/test_combine_caron_below_ttb_lb.png and b/Tests/images/test_combine_caron_below_ttb_lb.png differ diff --git a/Tests/images/test_combine_caron_ttb.png b/Tests/images/test_combine_caron_ttb.png index a94be2f0af6..569cc1ec3c8 100644 Binary files a/Tests/images/test_combine_caron_ttb.png and b/Tests/images/test_combine_caron_ttb.png differ diff --git a/Tests/images/test_combine_caron_ttb_lt.png b/Tests/images/test_combine_caron_ttb_lt.png index a94be2f0af6..569cc1ec3c8 100644 Binary files a/Tests/images/test_combine_caron_ttb_lt.png and b/Tests/images/test_combine_caron_ttb_lt.png differ diff --git a/Tests/oss-fuzz/fuzz_font.py b/Tests/oss-fuzz/fuzz_font.py index bc2ba9a7e27..4e7c7deec9c 100755 --- a/Tests/oss-fuzz/fuzz_font.py +++ b/Tests/oss-fuzz/fuzz_font.py @@ -13,6 +13,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations import atheris diff --git a/Tests/oss-fuzz/fuzz_pillow.py b/Tests/oss-fuzz/fuzz_pillow.py index 545daccb680..e7cd0474ad5 100644 --- a/Tests/oss-fuzz/fuzz_pillow.py +++ b/Tests/oss-fuzz/fuzz_pillow.py @@ -13,6 +13,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations import atheris diff --git a/Tests/oss-fuzz/fuzzers.py b/Tests/oss-fuzz/fuzzers.py index 10a172b4675..3f3c1e38833 100644 --- a/Tests/oss-fuzz/fuzzers.py +++ b/Tests/oss-fuzz/fuzzers.py @@ -1,3 +1,4 @@ +from __future__ import annotations import io import warnings diff --git a/Tests/oss-fuzz/test_fuzzers.py b/Tests/oss-fuzz/test_fuzzers.py index 0526f550ef6..68834045a52 100644 --- a/Tests/oss-fuzz/test_fuzzers.py +++ b/Tests/oss-fuzz/test_fuzzers.py @@ -1,3 +1,4 @@ +from __future__ import annotations import subprocess import sys diff --git a/Tests/test_000_sanity.py b/Tests/test_000_sanity.py index 3fd982474d4..c582dfad3e4 100644 --- a/Tests/test_000_sanity.py +++ b/Tests/test_000_sanity.py @@ -1,3 +1,4 @@ +from __future__ import annotations from PIL import Image diff --git a/Tests/test_binary.py b/Tests/test_binary.py index 4882e65e655..62da2663668 100644 --- a/Tests/test_binary.py +++ b/Tests/test_binary.py @@ -1,3 +1,4 @@ +from __future__ import annotations from PIL import _binary diff --git a/Tests/test_bmp_reference.py b/Tests/test_bmp_reference.py index 002a44a4f4d..bed8dc3a899 100644 --- a/Tests/test_bmp_reference.py +++ b/Tests/test_bmp_reference.py @@ -1,3 +1,4 @@ +from __future__ import annotations import os import warnings diff --git a/Tests/test_box_blur.py b/Tests/test_box_blur.py index 745364ddc0f..e798cba3d4f 100644 --- a/Tests/test_box_blur.py +++ b/Tests/test_box_blur.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image, ImageFilter diff --git a/Tests/test_color_lut.py b/Tests/test_color_lut.py index 6d9a6057029..448ba2fac80 100644 --- a/Tests/test_color_lut.py +++ b/Tests/test_color_lut.py @@ -1,3 +1,4 @@ +from __future__ import annotations from array import array import pytest diff --git a/Tests/test_core_resources.py b/Tests/test_core_resources.py index 9021a9fb36d..5275652f66a 100644 --- a/Tests/test_core_resources.py +++ b/Tests/test_core_resources.py @@ -1,3 +1,4 @@ +from __future__ import annotations import sys import pytest diff --git a/Tests/test_decompression_bomb.py b/Tests/test_decompression_bomb.py index 87681a0b557..391948d40c7 100644 --- a/Tests/test_decompression_bomb.py +++ b/Tests/test_decompression_bomb.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image diff --git a/Tests/test_deprecate.py b/Tests/test_deprecate.py index f175b90af16..d45a6603c54 100644 --- a/Tests/test_deprecate.py +++ b/Tests/test_deprecate.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import _deprecate diff --git a/Tests/test_features.py b/Tests/test_features.py index c4e9cd36811..8f0e4b4184a 100644 --- a/Tests/test_features.py +++ b/Tests/test_features.py @@ -1,3 +1,4 @@ +from __future__ import annotations import io import re diff --git a/Tests/test_file_apng.py b/Tests/test_file_apng.py index 1fb97a789a5..60d951636e8 100644 --- a/Tests/test_file_apng.py +++ b/Tests/test_file_apng.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image, ImageSequence, PngImagePlugin diff --git a/Tests/test_file_blp.py b/Tests/test_file_blp.py index 8b1355b6280..4c1e38d1ddf 100644 --- a/Tests/test_file_blp.py +++ b/Tests/test_file_blp.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image diff --git a/Tests/test_file_bmp.py b/Tests/test_file_bmp.py index 58a45aa0b8a..4cc92c5f684 100644 --- a/Tests/test_file_bmp.py +++ b/Tests/test_file_bmp.py @@ -1,3 +1,4 @@ +from __future__ import annotations import io import pytest diff --git a/Tests/test_file_bufrstub.py b/Tests/test_file_bufrstub.py index a7714c92cc8..5780232a2d6 100644 --- a/Tests/test_file_bufrstub.py +++ b/Tests/test_file_bufrstub.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import BufrStubImagePlugin, Image diff --git a/Tests/test_file_container.py b/Tests/test_file_container.py index 65cf6a75ea3..0da5d3824b0 100644 --- a/Tests/test_file_container.py +++ b/Tests/test_file_container.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import ContainerIO, Image diff --git a/Tests/test_file_cur.py b/Tests/test_file_cur.py index f04a20a220a..08c3257f9d1 100644 --- a/Tests/test_file_cur.py +++ b/Tests/test_file_cur.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import CurImagePlugin, Image diff --git a/Tests/test_file_dcx.py b/Tests/test_file_dcx.py index 22686af3485..25e4badbc92 100644 --- a/Tests/test_file_dcx.py +++ b/Tests/test_file_dcx.py @@ -1,3 +1,4 @@ +from __future__ import annotations import warnings import pytest diff --git a/Tests/test_file_dds.py b/Tests/test_file_dds.py index 0dd3d5bb9b0..2d60fbb6460 100644 --- a/Tests/test_file_dds.py +++ b/Tests/test_file_dds.py @@ -1,4 +1,5 @@ """Test DdsImagePlugin""" +from __future__ import annotations from io import BytesIO import pytest diff --git a/Tests/test_file_eps.py b/Tests/test_file_eps.py index 259cf75c397..c479c384a76 100644 --- a/Tests/test_file_eps.py +++ b/Tests/test_file_eps.py @@ -1,3 +1,4 @@ +from __future__ import annotations import io import pytest diff --git a/Tests/test_file_fits.py b/Tests/test_file_fits.py index 68b3eb567fd..1383f9c5ca3 100644 --- a/Tests/test_file_fits.py +++ b/Tests/test_file_fits.py @@ -1,3 +1,4 @@ +from __future__ import annotations from io import BytesIO import pytest diff --git a/Tests/test_file_fli.py b/Tests/test_file_fli.py index f96afdc95be..10bf36cc290 100644 --- a/Tests/test_file_fli.py +++ b/Tests/test_file_fli.py @@ -1,3 +1,4 @@ +from __future__ import annotations import warnings import pytest diff --git a/Tests/test_file_fpx.py b/Tests/test_file_fpx.py index 9a1784d31a7..af3b7981561 100644 --- a/Tests/test_file_fpx.py +++ b/Tests/test_file_fpx.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image diff --git a/Tests/test_file_ftex.py b/Tests/test_file_ftex.py index ac6253db056..a494c8029c9 100644 --- a/Tests/test_file_ftex.py +++ b/Tests/test_file_ftex.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import FtexImagePlugin, Image diff --git a/Tests/test_file_gbr.py b/Tests/test_file_gbr.py index 1ea8af8ee34..7dfe0539673 100644 --- a/Tests/test_file_gbr.py +++ b/Tests/test_file_gbr.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import GbrImagePlugin, Image diff --git a/Tests/test_file_gd.py b/Tests/test_file_gd.py index 5594e5bbb9e..ec80c54a122 100644 --- a/Tests/test_file_gd.py +++ b/Tests/test_file_gd.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import GdImageFile, UnidentifiedImageError diff --git a/Tests/test_file_gif.py b/Tests/test_file_gif.py index fa5d54febf8..78b77e9743a 100644 --- a/Tests/test_file_gif.py +++ b/Tests/test_file_gif.py @@ -1,3 +1,4 @@ +from __future__ import annotations import warnings from io import BytesIO @@ -217,6 +218,27 @@ def test_optimize_if_palette_can_be_reduced_by_half(): assert len(reloaded.palette.palette) // 3 == colors +def test_full_palette_second_frame(tmp_path): + out = str(tmp_path / "temp.gif") + im = Image.new("P", (1, 256)) + + full_palette_im = Image.new("P", (1, 256)) + for i in range(256): + full_palette_im.putpixel((0, i), i) + full_palette_im.palette = ImagePalette.ImagePalette( + "RGB", bytearray(i // 3 for i in range(768)) + ) + full_palette_im.palette.dirty = 1 + + im.save(out, save_all=True, append_images=[full_palette_im]) + + with Image.open(out) as reloaded: + reloaded.seek(1) + + for i in range(256): + reloaded.getpixel((0, i)) == i + + def test_roundtrip(tmp_path): out = str(tmp_path / "temp.gif") im = hopper() @@ -856,7 +878,14 @@ def test_identical_frames(tmp_path): @pytest.mark.parametrize( - "duration", ([1000, 1500, 2000, 4000], (1000, 1500, 2000, 4000), 8500) + "duration", + ( + [1000, 1500, 2000], + (1000, 1500, 2000), + # One more duration than the number of frames + [1000, 1500, 2000, 4000], + 1500, + ), ) def test_identical_frames_to_single_frame(duration, tmp_path): out = str(tmp_path / "temp.gif") @@ -872,7 +901,7 @@ def test_identical_frames_to_single_frame(duration, tmp_path): assert reread.n_frames == 1 # Assert that the new duration is the total of the identical frames - assert reread.info["duration"] == 8500 + assert reread.info["duration"] == 4500 def test_loop_none(tmp_path): @@ -1142,6 +1171,12 @@ def test_rgba_transparency(tmp_path): assert_image_equal(hopper("P").convert("RGB"), reloaded) +def test_background_outside_palettte(tmp_path): + with Image.open("Tests/images/background_outside_palette.gif") as im: + im.seek(1) + assert im.info["background"] == 255 + + def test_bbox(tmp_path): out = str(tmp_path / "temp.gif") diff --git a/Tests/test_file_gimpgradient.py b/Tests/test_file_gimpgradient.py index 3f056fdae1d..d5be46dc39e 100644 --- a/Tests/test_file_gimpgradient.py +++ b/Tests/test_file_gimpgradient.py @@ -1,3 +1,4 @@ +from __future__ import annotations from PIL import GimpGradientFile, ImagePalette diff --git a/Tests/test_file_gimppalette.py b/Tests/test_file_gimppalette.py index caec9cf2115..775d3b7cdae 100644 --- a/Tests/test_file_gimppalette.py +++ b/Tests/test_file_gimppalette.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL.GimpPaletteFile import GimpPaletteFile diff --git a/Tests/test_file_gribstub.py b/Tests/test_file_gribstub.py index dd1c5e7d281..d962e85a436 100644 --- a/Tests/test_file_gribstub.py +++ b/Tests/test_file_gribstub.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import GribStubImagePlugin, Image diff --git a/Tests/test_file_hdf5stub.py b/Tests/test_file_hdf5stub.py index 7ca10fac5dd..9c776b712ee 100644 --- a/Tests/test_file_hdf5stub.py +++ b/Tests/test_file_hdf5stub.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Hdf5StubImagePlugin, Image diff --git a/Tests/test_file_icns.py b/Tests/test_file_icns.py index 42275424d91..c62fffc5be8 100644 --- a/Tests/test_file_icns.py +++ b/Tests/test_file_icns.py @@ -1,3 +1,4 @@ +from __future__ import annotations import io import os import warnings diff --git a/Tests/test_file_ico.py b/Tests/test_file_ico.py index 4e6dbe6ede4..de9fa353adb 100644 --- a/Tests/test_file_ico.py +++ b/Tests/test_file_ico.py @@ -1,3 +1,4 @@ +from __future__ import annotations import io import os diff --git a/Tests/test_file_im.py b/Tests/test_file_im.py index fd00f260e78..0cb26d06a51 100644 --- a/Tests/test_file_im.py +++ b/Tests/test_file_im.py @@ -1,3 +1,4 @@ +from __future__ import annotations import filecmp import warnings diff --git a/Tests/test_file_imt.py b/Tests/test_file_imt.py index f56acc42949..3db4885586a 100644 --- a/Tests/test_file_imt.py +++ b/Tests/test_file_imt.py @@ -1,3 +1,4 @@ +from __future__ import annotations import io import pytest diff --git a/Tests/test_file_iptc.py b/Tests/test_file_iptc.py index dac35a8d0e8..d0ecde393a4 100644 --- a/Tests/test_file_iptc.py +++ b/Tests/test_file_iptc.py @@ -1,3 +1,4 @@ +from __future__ import annotations import sys from io import BytesIO, StringIO diff --git a/Tests/test_file_jpeg.py b/Tests/test_file_jpeg.py index ef070b6c5ba..ffaea6296ef 100644 --- a/Tests/test_file_jpeg.py +++ b/Tests/test_file_jpeg.py @@ -1,3 +1,4 @@ +from __future__ import annotations import os import re import warnings diff --git a/Tests/test_file_jpeg2k.py b/Tests/test_file_jpeg2k.py index 2016b3ccbe3..aaa4104e57c 100644 --- a/Tests/test_file_jpeg2k.py +++ b/Tests/test_file_jpeg2k.py @@ -1,3 +1,4 @@ +from __future__ import annotations import os import re from io import BytesIO diff --git a/Tests/test_file_libtiff.py b/Tests/test_file_libtiff.py index a7394f1bf5c..65adf449dcc 100644 --- a/Tests/test_file_libtiff.py +++ b/Tests/test_file_libtiff.py @@ -1,3 +1,4 @@ +from __future__ import annotations import base64 import io import itertools diff --git a/Tests/test_file_libtiff_small.py b/Tests/test_file_libtiff_small.py index 03137c8b603..9501c55a6b8 100644 --- a/Tests/test_file_libtiff_small.py +++ b/Tests/test_file_libtiff_small.py @@ -1,3 +1,4 @@ +from __future__ import annotations from io import BytesIO from PIL import Image diff --git a/Tests/test_file_mcidas.py b/Tests/test_file_mcidas.py index 41f22cf0c7d..4b31aaa7857 100644 --- a/Tests/test_file_mcidas.py +++ b/Tests/test_file_mcidas.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image, McIdasImagePlugin diff --git a/Tests/test_file_mic.py b/Tests/test_file_mic.py index 2588d3a0574..e7ea39ea918 100644 --- a/Tests/test_file_mic.py +++ b/Tests/test_file_mic.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image, ImagePalette diff --git a/Tests/test_file_mpo.py b/Tests/test_file_mpo.py index 2e921e46701..da62bc6d429 100644 --- a/Tests/test_file_mpo.py +++ b/Tests/test_file_mpo.py @@ -1,3 +1,4 @@ +from __future__ import annotations import warnings from io import BytesIO diff --git a/Tests/test_file_msp.py b/Tests/test_file_msp.py index 497052b05e9..f4e357ae0fd 100644 --- a/Tests/test_file_msp.py +++ b/Tests/test_file_msp.py @@ -1,3 +1,4 @@ +from __future__ import annotations import os import pytest diff --git a/Tests/test_file_palm.py b/Tests/test_file_palm.py index 926fdb26f6b..735840de4cb 100644 --- a/Tests/test_file_palm.py +++ b/Tests/test_file_palm.py @@ -1,3 +1,4 @@ +from __future__ import annotations import os.path import subprocess diff --git a/Tests/test_file_pcd.py b/Tests/test_file_pcd.py index dc45a48c1cb..596a3414f79 100644 --- a/Tests/test_file_pcd.py +++ b/Tests/test_file_pcd.py @@ -1,3 +1,4 @@ +from __future__ import annotations from PIL import Image diff --git a/Tests/test_file_pcx.py b/Tests/test_file_pcx.py index 485adf7853e..f42ec4a6894 100644 --- a/Tests/test_file_pcx.py +++ b/Tests/test_file_pcx.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image, ImageFile, PcxImagePlugin diff --git a/Tests/test_file_pdf.py b/Tests/test_file_pdf.py index ffc392d6b2b..9e07d9ed014 100644 --- a/Tests/test_file_pdf.py +++ b/Tests/test_file_pdf.py @@ -1,3 +1,4 @@ +from __future__ import annotations import io import os import os.path diff --git a/Tests/test_file_pixar.py b/Tests/test_file_pixar.py index 315ea4676e1..63779f202cb 100644 --- a/Tests/test_file_pixar.py +++ b/Tests/test_file_pixar.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image, PixarImagePlugin diff --git a/Tests/test_file_png.py b/Tests/test_file_png.py index b8f48140851..ff386211061 100644 --- a/Tests/test_file_png.py +++ b/Tests/test_file_png.py @@ -1,3 +1,4 @@ +from __future__ import annotations import re import sys import warnings diff --git a/Tests/test_file_ppm.py b/Tests/test_file_ppm.py index 292642ca9f8..bb49a46d376 100644 --- a/Tests/test_file_ppm.py +++ b/Tests/test_file_ppm.py @@ -1,3 +1,4 @@ +from __future__ import annotations import sys from io import BytesIO diff --git a/Tests/test_file_psd.py b/Tests/test_file_psd.py index e405834b5ca..8b06ce2b163 100644 --- a/Tests/test_file_psd.py +++ b/Tests/test_file_psd.py @@ -1,3 +1,4 @@ +from __future__ import annotations import warnings import pytest @@ -111,6 +112,11 @@ def test_rgba(): assert_image_equal_tofile(im, "Tests/images/imagedraw_square.png") +def test_layer_skip(): + with Image.open("Tests/images/five_channels.psd") as im: + assert im.n_frames == 1 + + def test_icc_profile(): with Image.open(test_file) as im: assert "icc_profile" in im.info diff --git a/Tests/test_file_qoi.py b/Tests/test_file_qoi.py index 0a835dcf61e..b7c9457294d 100644 --- a/Tests/test_file_qoi.py +++ b/Tests/test_file_qoi.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image, QoiImagePlugin diff --git a/Tests/test_file_sgi.py b/Tests/test_file_sgi.py index 6a5d8887d33..13698276b8c 100644 --- a/Tests/test_file_sgi.py +++ b/Tests/test_file_sgi.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image, SgiImagePlugin diff --git a/Tests/test_file_spider.py b/Tests/test_file_spider.py index 09f1ef8e4a6..f2109875478 100644 --- a/Tests/test_file_spider.py +++ b/Tests/test_file_spider.py @@ -1,3 +1,4 @@ +from __future__ import annotations import tempfile import warnings from io import BytesIO diff --git a/Tests/test_file_sun.py b/Tests/test_file_sun.py index edb3206038b..874b37b5285 100644 --- a/Tests/test_file_sun.py +++ b/Tests/test_file_sun.py @@ -1,3 +1,4 @@ +from __future__ import annotations import os import pytest diff --git a/Tests/test_file_tar.py b/Tests/test_file_tar.py index b27fa25f3e0..4470823cdbd 100644 --- a/Tests/test_file_tar.py +++ b/Tests/test_file_tar.py @@ -1,3 +1,4 @@ +from __future__ import annotations import warnings import pytest diff --git a/Tests/test_file_tga.py b/Tests/test_file_tga.py index 1a5730f49d9..d0f228573bb 100644 --- a/Tests/test_file_tga.py +++ b/Tests/test_file_tga.py @@ -1,3 +1,4 @@ +from __future__ import annotations import os from glob import glob from itertools import product diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py index 7362c93cac8..0851796d000 100644 --- a/Tests/test_file_tiff.py +++ b/Tests/test_file_tiff.py @@ -1,3 +1,4 @@ +from __future__ import annotations import os import warnings from io import BytesIO diff --git a/Tests/test_file_tiff_metadata.py b/Tests/test_file_tiff_metadata.py index b7d100e7a05..edd57e6b54d 100644 --- a/Tests/test_file_tiff_metadata.py +++ b/Tests/test_file_tiff_metadata.py @@ -1,3 +1,4 @@ +from __future__ import annotations import io import struct diff --git a/Tests/test_file_wal.py b/Tests/test_file_wal.py index 4be46e9d673..0b84d0320aa 100644 --- a/Tests/test_file_wal.py +++ b/Tests/test_file_wal.py @@ -1,3 +1,4 @@ +from __future__ import annotations from PIL import WalImageFile from .helper import assert_image_equal_tofile diff --git a/Tests/test_file_webp.py b/Tests/test_file_webp.py index 30938e971dd..c91818ef64e 100644 --- a/Tests/test_file_webp.py +++ b/Tests/test_file_webp.py @@ -1,3 +1,4 @@ +from __future__ import annotations import io import re import sys diff --git a/Tests/test_file_webp_alpha.py b/Tests/test_file_webp_alpha.py index 5970fd2a371..79d01a4446a 100644 --- a/Tests/test_file_webp_alpha.py +++ b/Tests/test_file_webp_alpha.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image diff --git a/Tests/test_file_webp_animated.py b/Tests/test_file_webp_animated.py index 2fd5e548406..22acb4be68f 100644 --- a/Tests/test_file_webp_animated.py +++ b/Tests/test_file_webp_animated.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from packaging.version import parse as parse_version diff --git a/Tests/test_file_webp_lossless.py b/Tests/test_file_webp_lossless.py index 2da443628d7..6acf58ac3f5 100644 --- a/Tests/test_file_webp_lossless.py +++ b/Tests/test_file_webp_lossless.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image diff --git a/Tests/test_file_webp_metadata.py b/Tests/test_file_webp_metadata.py index dd47be8b21b..a7b7bbcf6ee 100644 --- a/Tests/test_file_webp_metadata.py +++ b/Tests/test_file_webp_metadata.py @@ -1,3 +1,4 @@ +from __future__ import annotations from io import BytesIO import pytest diff --git a/Tests/test_file_wmf.py b/Tests/test_file_wmf.py index 7c8b54fd173..596dc8ba181 100644 --- a/Tests/test_file_wmf.py +++ b/Tests/test_file_wmf.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image, WmfImagePlugin diff --git a/Tests/test_file_xbm.py b/Tests/test_file_xbm.py index d2c05b78a82..b086ffd683f 100644 --- a/Tests/test_file_xbm.py +++ b/Tests/test_file_xbm.py @@ -1,3 +1,4 @@ +from __future__ import annotations from io import BytesIO import pytest diff --git a/Tests/test_file_xpm.py b/Tests/test_file_xpm.py index 8595b07eb91..265feab4294 100644 --- a/Tests/test_file_xpm.py +++ b/Tests/test_file_xpm.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image, XpmImagePlugin diff --git a/Tests/test_file_xvthumb.py b/Tests/test_file_xvthumb.py index 9efe7ec1438..5848995c1aa 100644 --- a/Tests/test_file_xvthumb.py +++ b/Tests/test_file_xvthumb.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image, XVThumbImagePlugin diff --git a/Tests/test_font_bdf.py b/Tests/test_font_bdf.py index 1e7caee3297..1e5eff2f15d 100644 --- a/Tests/test_font_bdf.py +++ b/Tests/test_font_bdf.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import BdfFontFile, FontFile diff --git a/Tests/test_font_crash.py b/Tests/test_font_crash.py index 27663f396ea..388ee711861 100644 --- a/Tests/test_font_crash.py +++ b/Tests/test_font_crash.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image, ImageDraw, ImageFont diff --git a/Tests/test_font_leaks.py b/Tests/test_font_leaks.py index 38f7ddac5de..6a038bb4038 100644 --- a/Tests/test_font_leaks.py +++ b/Tests/test_font_leaks.py @@ -1,3 +1,4 @@ +from __future__ import annotations from PIL import Image, ImageDraw, ImageFont from .helper import PillowLeakTestCase, skip_unless_feature diff --git a/Tests/test_font_pcf.py b/Tests/test_font_pcf.py index 815ef1d9254..4365b931066 100644 --- a/Tests/test_font_pcf.py +++ b/Tests/test_font_pcf.py @@ -1,3 +1,4 @@ +from __future__ import annotations import os import pytest diff --git a/Tests/test_font_pcf_charsets.py b/Tests/test_font_pcf_charsets.py index 664663fd6bb..950e5029ff5 100644 --- a/Tests/test_font_pcf_charsets.py +++ b/Tests/test_font_pcf_charsets.py @@ -1,3 +1,4 @@ +from __future__ import annotations import os import pytest diff --git a/Tests/test_format_hsv.py b/Tests/test_format_hsv.py index b485e854f52..fd47fae39ba 100644 --- a/Tests/test_format_hsv.py +++ b/Tests/test_format_hsv.py @@ -1,3 +1,4 @@ +from __future__ import annotations import colorsys import itertools diff --git a/Tests/test_format_lab.py b/Tests/test_format_lab.py index 41c8efdf316..c7610ce8a6c 100644 --- a/Tests/test_format_lab.py +++ b/Tests/test_format_lab.py @@ -1,3 +1,4 @@ +from __future__ import annotations from PIL import Image diff --git a/Tests/test_image.py b/Tests/test_image.py index f0861bb4f81..615e00e40da 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -1,3 +1,4 @@ +from __future__ import annotations import io import logging import os diff --git a/Tests/test_image_access.py b/Tests/test_image_access.py index 2b4fb773395..4a794371d67 100644 --- a/Tests/test_image_access.py +++ b/Tests/test_image_access.py @@ -1,3 +1,4 @@ +from __future__ import annotations import os import subprocess import sys diff --git a/Tests/test_image_array.py b/Tests/test_image_array.py index ae3518e44cb..b3e5d9e3e08 100644 --- a/Tests/test_image_array.py +++ b/Tests/test_image_array.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from packaging.version import parse as parse_version diff --git a/Tests/test_image_convert.py b/Tests/test_image_convert.py index f5775f09ccc..7c17040d30b 100644 --- a/Tests/test_image_convert.py +++ b/Tests/test_image_convert.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image diff --git a/Tests/test_image_copy.py b/Tests/test_image_copy.py index cd602fc76f6..abf5f846f89 100644 --- a/Tests/test_image_copy.py +++ b/Tests/test_image_copy.py @@ -1,3 +1,4 @@ +from __future__ import annotations import copy import pytest diff --git a/Tests/test_image_crop.py b/Tests/test_image_crop.py index daf8c8da13d..0bb54e5d811 100644 --- a/Tests/test_image_crop.py +++ b/Tests/test_image_crop.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image diff --git a/Tests/test_image_draft.py b/Tests/test_image_draft.py index 8b4b447688f..774272dd1f7 100644 --- a/Tests/test_image_draft.py +++ b/Tests/test_image_draft.py @@ -1,3 +1,4 @@ +from __future__ import annotations from PIL import Image from .helper import fromstring, skip_unless_feature, tostring diff --git a/Tests/test_image_entropy.py b/Tests/test_image_entropy.py index ea5886e72db..031fceda3fa 100644 --- a/Tests/test_image_entropy.py +++ b/Tests/test_image_entropy.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .helper import hopper diff --git a/Tests/test_image_filter.py b/Tests/test_image_filter.py index a7932a351b5..5bd7ee0d273 100644 --- a/Tests/test_image_filter.py +++ b/Tests/test_image_filter.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image, ImageFilter diff --git a/Tests/test_image_frombytes.py b/Tests/test_image_frombytes.py index c299e454402..017da499d2c 100644 --- a/Tests/test_image_frombytes.py +++ b/Tests/test_image_frombytes.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image diff --git a/Tests/test_image_fromqimage.py b/Tests/test_image_fromqimage.py index 7fe992353bc..b3ca43bde6d 100644 --- a/Tests/test_image_fromqimage.py +++ b/Tests/test_image_fromqimage.py @@ -1,3 +1,4 @@ +from __future__ import annotations import warnings import pytest diff --git a/Tests/test_image_getbands.py b/Tests/test_image_getbands.py index 08fc12c1cf4..e7701dbc460 100644 --- a/Tests/test_image_getbands.py +++ b/Tests/test_image_getbands.py @@ -1,3 +1,4 @@ +from __future__ import annotations from PIL import Image diff --git a/Tests/test_image_getbbox.py b/Tests/test_image_getbbox.py index afca6670305..9e792cfdf7c 100644 --- a/Tests/test_image_getbbox.py +++ b/Tests/test_image_getbbox.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image diff --git a/Tests/test_image_getcolors.py b/Tests/test_image_getcolors.py index 7fd0398f947..dea3a60a112 100644 --- a/Tests/test_image_getcolors.py +++ b/Tests/test_image_getcolors.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .helper import hopper diff --git a/Tests/test_image_getdata.py b/Tests/test_image_getdata.py index 36c81b40f07..873cc65bf91 100644 --- a/Tests/test_image_getdata.py +++ b/Tests/test_image_getdata.py @@ -1,3 +1,4 @@ +from __future__ import annotations from PIL import Image from .helper import hopper diff --git a/Tests/test_image_getextrema.py b/Tests/test_image_getextrema.py index 710794da426..b17c8a786dd 100644 --- a/Tests/test_image_getextrema.py +++ b/Tests/test_image_getextrema.py @@ -1,3 +1,4 @@ +from __future__ import annotations from PIL import Image from .helper import hopper diff --git a/Tests/test_image_getim.py b/Tests/test_image_getim.py index 746e63b1551..e969c8164a2 100644 --- a/Tests/test_image_getim.py +++ b/Tests/test_image_getim.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .helper import hopper diff --git a/Tests/test_image_getpalette.py b/Tests/test_image_getpalette.py index 58a6dacbbbb..a5be972d3ed 100644 --- a/Tests/test_image_getpalette.py +++ b/Tests/test_image_getpalette.py @@ -1,3 +1,4 @@ +from __future__ import annotations from PIL import Image from .helper import hopper diff --git a/Tests/test_image_getprojection.py b/Tests/test_image_getprojection.py index f65d40708b1..aa47be3b2e0 100644 --- a/Tests/test_image_getprojection.py +++ b/Tests/test_image_getprojection.py @@ -1,3 +1,4 @@ +from __future__ import annotations from PIL import Image from .helper import hopper diff --git a/Tests/test_image_histogram.py b/Tests/test_image_histogram.py index 0ee52e724e1..7ba2f10b765 100644 --- a/Tests/test_image_histogram.py +++ b/Tests/test_image_histogram.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .helper import hopper diff --git a/Tests/test_image_load.py b/Tests/test_image_load.py index f7fe99bb4c2..17847c4fd9c 100644 --- a/Tests/test_image_load.py +++ b/Tests/test_image_load.py @@ -1,3 +1,4 @@ +from __future__ import annotations import logging import os diff --git a/Tests/test_image_mode.py b/Tests/test_image_mode.py index e4c8bb9dfa6..ad90d1250dc 100644 --- a/Tests/test_image_mode.py +++ b/Tests/test_image_mode.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image, ImageMode diff --git a/Tests/test_image_paste.py b/Tests/test_image_paste.py index 1ab02017de1..0b87f607286 100644 --- a/Tests/test_image_paste.py +++ b/Tests/test_image_paste.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image diff --git a/Tests/test_image_point.py b/Tests/test_image_point.py index c406cb8ec26..fce45ec4f0e 100644 --- a/Tests/test_image_point.py +++ b/Tests/test_image_point.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from .helper import assert_image_equal, hopper diff --git a/Tests/test_image_putalpha.py b/Tests/test_image_putalpha.py index e2dcead34c5..0ba7e5919a5 100644 --- a/Tests/test_image_putalpha.py +++ b/Tests/test_image_putalpha.py @@ -1,3 +1,4 @@ +from __future__ import annotations from PIL import Image diff --git a/Tests/test_image_putdata.py b/Tests/test_image_putdata.py index 4e40aec7465..d3cb13e2e97 100644 --- a/Tests/test_image_putdata.py +++ b/Tests/test_image_putdata.py @@ -1,3 +1,4 @@ +from __future__ import annotations import sys from array import array diff --git a/Tests/test_image_putpalette.py b/Tests/test_image_putpalette.py index 3765533449f..de2d9024213 100644 --- a/Tests/test_image_putpalette.py +++ b/Tests/test_image_putpalette.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image, ImagePalette diff --git a/Tests/test_image_quantize.py b/Tests/test_image_quantize.py index 3bafc4c9c1d..54c567aae6c 100644 --- a/Tests/test_image_quantize.py +++ b/Tests/test_image_quantize.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from packaging.version import parse as parse_version diff --git a/Tests/test_image_reduce.py b/Tests/test_image_reduce.py index ae8d740a027..a4d0f510761 100644 --- a/Tests/test_image_reduce.py +++ b/Tests/test_image_reduce.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image, ImageMath, ImageMode diff --git a/Tests/test_image_resample.py b/Tests/test_image_resample.py index be49955dd7e..b4bf6c8df3a 100644 --- a/Tests/test_image_resample.py +++ b/Tests/test_image_resample.py @@ -1,3 +1,4 @@ +from __future__ import annotations from contextlib import contextmanager import pytest diff --git a/Tests/test_image_resize.py b/Tests/test_image_resize.py index b5bfa903fe2..0d3b43ee29f 100644 --- a/Tests/test_image_resize.py +++ b/Tests/test_image_resize.py @@ -1,6 +1,7 @@ """ Tests for resize functionality. """ +from __future__ import annotations from itertools import permutations import pytest diff --git a/Tests/test_image_rotate.py b/Tests/test_image_rotate.py index 82fe46b7d7e..0931aa32d98 100644 --- a/Tests/test_image_rotate.py +++ b/Tests/test_image_rotate.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image diff --git a/Tests/test_image_split.py b/Tests/test_image_split.py index 5cb7c9a8be8..707508250f6 100644 --- a/Tests/test_image_split.py +++ b/Tests/test_image_split.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image, features diff --git a/Tests/test_image_thumbnail.py b/Tests/test_image_thumbnail.py index 96a2c26623e..9e6796ca299 100644 --- a/Tests/test_image_thumbnail.py +++ b/Tests/test_image_thumbnail.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image diff --git a/Tests/test_image_tobitmap.py b/Tests/test_image_tobitmap.py index a12ce329fd1..156b9919d27 100644 --- a/Tests/test_image_tobitmap.py +++ b/Tests/test_image_tobitmap.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from .helper import assert_image_equal, fromstring, hopper diff --git a/Tests/test_image_tobytes.py b/Tests/test_image_tobytes.py index 31e1c0080c6..f6042bca527 100644 --- a/Tests/test_image_tobytes.py +++ b/Tests/test_image_tobytes.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .helper import hopper diff --git a/Tests/test_image_transform.py b/Tests/test_image_transform.py index 64a5c94596f..15939ef647c 100644 --- a/Tests/test_image_transform.py +++ b/Tests/test_image_transform.py @@ -1,3 +1,4 @@ +from __future__ import annotations import math import pytest diff --git a/Tests/test_image_transpose.py b/Tests/test_image_transpose.py index 877f439ca26..66a2d9e2955 100644 --- a/Tests/test_image_transpose.py +++ b/Tests/test_image_transpose.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL.Image import Transpose diff --git a/Tests/test_imagechops.py b/Tests/test_imagechops.py index e7687cc1b76..8e3a738d708 100644 --- a/Tests/test_imagechops.py +++ b/Tests/test_imagechops.py @@ -1,3 +1,4 @@ +from __future__ import annotations from PIL import Image, ImageChops from .helper import assert_image_equal, hopper diff --git a/Tests/test_imagecms.py b/Tests/test_imagecms.py index 8efe063c11d..0dde82bd748 100644 --- a/Tests/test_imagecms.py +++ b/Tests/test_imagecms.py @@ -1,3 +1,4 @@ +from __future__ import annotations import datetime import os import re diff --git a/Tests/test_imagecolor.py b/Tests/test_imagecolor.py index 2fae6151cfd..c0ffd2ebf0b 100644 --- a/Tests/test_imagecolor.py +++ b/Tests/test_imagecolor.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image, ImageColor diff --git a/Tests/test_imagedraw.py b/Tests/test_imagedraw.py index 4052c41ff07..379fe78cd8a 100644 --- a/Tests/test_imagedraw.py +++ b/Tests/test_imagedraw.py @@ -1,3 +1,4 @@ +from __future__ import annotations import contextlib import os.path diff --git a/Tests/test_imagedraw2.py b/Tests/test_imagedraw2.py index a2c2fa1f010..d729af14d3a 100644 --- a/Tests/test_imagedraw2.py +++ b/Tests/test_imagedraw2.py @@ -1,3 +1,4 @@ +from __future__ import annotations import os.path import pytest diff --git a/Tests/test_imageenhance.py b/Tests/test_imageenhance.py index 221ef8cdb26..f4e4d59be32 100644 --- a/Tests/test_imageenhance.py +++ b/Tests/test_imageenhance.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image, ImageEnhance diff --git a/Tests/test_imagefile.py b/Tests/test_imagefile.py index 2389c471748..4804a554f83 100644 --- a/Tests/test_imagefile.py +++ b/Tests/test_imagefile.py @@ -1,3 +1,4 @@ +from __future__ import annotations from io import BytesIO import pytest diff --git a/Tests/test_imagefont.py b/Tests/test_imagefont.py index 0f1c52b664f..6e04cddc748 100644 --- a/Tests/test_imagefont.py +++ b/Tests/test_imagefont.py @@ -1,3 +1,4 @@ +from __future__ import annotations import copy import os import re @@ -858,6 +859,19 @@ def test_bitmap_font_stroke(layout_engine): assert_image_similar_tofile(im, target, 0.03) +@pytest.mark.parametrize("embedded_color", (False, True)) +def test_bitmap_blend(layout_engine, embedded_color): + font = ImageFont.truetype( + "Tests/fonts/EBDTTestFont.ttf", size=64, layout_engine=layout_engine + ) + + im = Image.new("RGBA", (128, 96), "white") + d = ImageDraw.Draw(im) + d.text((16, 16), "AA", font=font, fill="#8E2F52", embedded_color=embedded_color) + + assert_image_equal_tofile(im, "Tests/images/bitmap_font_blend.png") + + def test_standard_embedded_color(layout_engine): txt = "Hello World!" ttf = ImageFont.truetype(FONT_PATH, 40, layout_engine=layout_engine) @@ -896,15 +910,15 @@ def test_float_coord(layout_engine, fontmode): def test_cbdt(layout_engine): try: font = ImageFont.truetype( - "Tests/fonts/NotoColorEmoji.ttf", size=109, layout_engine=layout_engine + "Tests/fonts/CBDTTestFont.ttf", size=64, layout_engine=layout_engine ) - im = Image.new("RGB", (150, 150), "white") + im = Image.new("RGB", (128, 96), "white") d = ImageDraw.Draw(im) - d.text((10, 10), "\U0001f469", font=font, embedded_color=True) + d.text((16, 16), "AB", font=font, embedded_color=True) - assert_image_similar_tofile(im, "Tests/images/cbdt_notocoloremoji.png", 6.2) + assert_image_equal_tofile(im, "Tests/images/cbdt.png") except OSError as e: # pragma: no cover assert str(e) in ("unimplemented feature", "unknown file format") pytest.skip("freetype compiled without libpng or CBDT support") @@ -913,17 +927,15 @@ def test_cbdt(layout_engine): def test_cbdt_mask(layout_engine): try: font = ImageFont.truetype( - "Tests/fonts/NotoColorEmoji.ttf", size=109, layout_engine=layout_engine + "Tests/fonts/CBDTTestFont.ttf", size=64, layout_engine=layout_engine ) - im = Image.new("RGB", (150, 150), "white") + im = Image.new("RGB", (128, 96), "white") d = ImageDraw.Draw(im) - d.text((10, 10), "\U0001f469", "black", font=font) + d.text((16, 16), "AB", "green", font=font) - assert_image_similar_tofile( - im, "Tests/images/cbdt_notocoloremoji_mask.png", 6.2 - ) + assert_image_equal_tofile(im, "Tests/images/cbdt_mask.png") except OSError as e: # pragma: no cover assert str(e) in ("unimplemented feature", "unknown file format") pytest.skip("freetype compiled without libpng or CBDT support") diff --git a/Tests/test_imagefontctl.py b/Tests/test_imagefontctl.py index 6099b04e44b..bea532b051e 100644 --- a/Tests/test_imagefontctl.py +++ b/Tests/test_imagefontctl.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image, ImageDraw, ImageFont diff --git a/Tests/test_imagefontpil.py b/Tests/test_imagefontpil.py index c30463e81c2..21b4dee3c4a 100644 --- a/Tests/test_imagefontpil.py +++ b/Tests/test_imagefontpil.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image, ImageDraw, ImageFont, features diff --git a/Tests/test_imagegrab.py b/Tests/test_imagegrab.py index a75cbadc4ad..b7683ec1817 100644 --- a/Tests/test_imagegrab.py +++ b/Tests/test_imagegrab.py @@ -1,3 +1,4 @@ +from __future__ import annotations import os import shutil import subprocess diff --git a/Tests/test_imagemath.py b/Tests/test_imagemath.py index fe7ac9a7a93..22de86c7cab 100644 --- a/Tests/test_imagemath.py +++ b/Tests/test_imagemath.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image, ImageMath diff --git a/Tests/test_imagemorph.py b/Tests/test_imagemorph.py index 29c71f917c4..ec55aadf9b3 100644 --- a/Tests/test_imagemorph.py +++ b/Tests/test_imagemorph.py @@ -1,4 +1,5 @@ # Test the ImageMorphology functionality +from __future__ import annotations import pytest from PIL import Image, ImageMorph, _imagingmorph diff --git a/Tests/test_imageops.py b/Tests/test_imageops.py index a3bb536cec2..7980bead0a4 100644 --- a/Tests/test_imageops.py +++ b/Tests/test_imageops.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image, ImageDraw, ImageOps, ImageStat, features diff --git a/Tests/test_imageops_usm.py b/Tests/test_imageops_usm.py index 8837ed2a262..84d3a69507a 100644 --- a/Tests/test_imageops_usm.py +++ b/Tests/test_imageops_usm.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image, ImageFilter diff --git a/Tests/test_imagepalette.py b/Tests/test_imagepalette.py index baa698bb4f4..e5b59b74a84 100644 --- a/Tests/test_imagepalette.py +++ b/Tests/test_imagepalette.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image, ImagePalette diff --git a/Tests/test_imagepath.py b/Tests/test_imagepath.py index c112cfd87aa..ac3ea3281f5 100644 --- a/Tests/test_imagepath.py +++ b/Tests/test_imagepath.py @@ -1,3 +1,4 @@ +from __future__ import annotations import array import math import struct diff --git a/Tests/test_imageqt.py b/Tests/test_imageqt.py index 2c73a209465..41d247f429f 100644 --- a/Tests/test_imageqt.py +++ b/Tests/test_imageqt.py @@ -1,3 +1,4 @@ +from __future__ import annotations import warnings import pytest diff --git a/Tests/test_imagesequence.py b/Tests/test_imagesequence.py index 62f52833227..6d71e4d87af 100644 --- a/Tests/test_imagesequence.py +++ b/Tests/test_imagesequence.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image, ImageSequence, TiffImagePlugin diff --git a/Tests/test_imageshow.py b/Tests/test_imageshow.py index 3e73339ed3f..761d28d3019 100644 --- a/Tests/test_imageshow.py +++ b/Tests/test_imageshow.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image, ImageShow diff --git a/Tests/test_imagestat.py b/Tests/test_imagestat.py index b3b5db13ff2..7b56b89cc4b 100644 --- a/Tests/test_imagestat.py +++ b/Tests/test_imagestat.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image, ImageStat diff --git a/Tests/test_imagetk.py b/Tests/test_imagetk.py index a0c9574ba94..bb20fbb6f92 100644 --- a/Tests/test_imagetk.py +++ b/Tests/test_imagetk.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image diff --git a/Tests/test_imagewin.py b/Tests/test_imagewin.py index 5e489284f2f..6927eedcf86 100644 --- a/Tests/test_imagewin.py +++ b/Tests/test_imagewin.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import ImageWin diff --git a/Tests/test_imagewin_pointers.py b/Tests/test_imagewin_pointers.py index df130565575..bd154335af7 100644 --- a/Tests/test_imagewin_pointers.py +++ b/Tests/test_imagewin_pointers.py @@ -1,3 +1,4 @@ +from __future__ import annotations from io import BytesIO from PIL import Image, ImageWin diff --git a/Tests/test_lib_image.py b/Tests/test_lib_image.py index f6818be46dc..92cad4ac1b1 100644 --- a/Tests/test_lib_image.py +++ b/Tests/test_lib_image.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image diff --git a/Tests/test_lib_pack.py b/Tests/test_lib_pack.py index 2a4d9acf447..1293f7628be 100644 --- a/Tests/test_lib_pack.py +++ b/Tests/test_lib_pack.py @@ -1,3 +1,4 @@ +from __future__ import annotations import sys import pytest diff --git a/Tests/test_locale.py b/Tests/test_locale.py index 7a07fbbe0a4..49b052fa485 100644 --- a/Tests/test_locale.py +++ b/Tests/test_locale.py @@ -1,3 +1,4 @@ +from __future__ import annotations import locale import pytest diff --git a/Tests/test_main.py b/Tests/test_main.py index 46ff63c4e97..a84e61a7b7d 100644 --- a/Tests/test_main.py +++ b/Tests/test_main.py @@ -1,3 +1,4 @@ +from __future__ import annotations import os import subprocess import sys diff --git a/Tests/test_map.py b/Tests/test_map.py index d816bddaf3d..76444f33d1c 100644 --- a/Tests/test_map.py +++ b/Tests/test_map.py @@ -1,3 +1,4 @@ +from __future__ import annotations import sys import pytest diff --git a/Tests/test_mode_i16.py b/Tests/test_mode_i16.py index 1786dba3847..3e17d8dccde 100644 --- a/Tests/test_mode_i16.py +++ b/Tests/test_mode_i16.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image diff --git a/Tests/test_numpy.py b/Tests/test_numpy.py index 147f94a71fd..6f0e99b3f93 100644 --- a/Tests/test_numpy.py +++ b/Tests/test_numpy.py @@ -1,3 +1,4 @@ +from __future__ import annotations import warnings import pytest diff --git a/Tests/test_pdfparser.py b/Tests/test_pdfparser.py index 105a838d9da..aeeafb6f1df 100644 --- a/Tests/test_pdfparser.py +++ b/Tests/test_pdfparser.py @@ -1,3 +1,4 @@ +from __future__ import annotations import time import pytest diff --git a/Tests/test_pickle.py b/Tests/test_pickle.py index 1c5d482bde0..eb687b57b62 100644 --- a/Tests/test_pickle.py +++ b/Tests/test_pickle.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pickle import pytest diff --git a/Tests/test_psdraw.py b/Tests/test_psdraw.py index e74d798282a..77c7952e912 100644 --- a/Tests/test_psdraw.py +++ b/Tests/test_psdraw.py @@ -1,3 +1,4 @@ +from __future__ import annotations import os import sys from io import BytesIO diff --git a/Tests/test_pyroma.py b/Tests/test_pyroma.py index aa05c2cfdd8..08133b6c30c 100644 --- a/Tests/test_pyroma.py +++ b/Tests/test_pyroma.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import __version__ diff --git a/Tests/test_qt_image_qapplication.py b/Tests/test_qt_image_qapplication.py index 5d2e41212f2..49ca016771f 100644 --- a/Tests/test_qt_image_qapplication.py +++ b/Tests/test_qt_image_qapplication.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import ImageQt diff --git a/Tests/test_qt_image_toqimage.py b/Tests/test_qt_image_toqimage.py index 95c13ba757b..396bd9080ca 100644 --- a/Tests/test_qt_image_toqimage.py +++ b/Tests/test_qt_image_toqimage.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import ImageQt diff --git a/Tests/test_sgi_crash.py b/Tests/test_sgi_crash.py index b5f9d442490..37d72d451de 100644 --- a/Tests/test_sgi_crash.py +++ b/Tests/test_sgi_crash.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import Image diff --git a/Tests/test_shell_injection.py b/Tests/test_shell_injection.py index d25d42dfca3..d93b0390416 100644 --- a/Tests/test_shell_injection.py +++ b/Tests/test_shell_injection.py @@ -1,3 +1,4 @@ +from __future__ import annotations import shutil import pytest diff --git a/Tests/test_tiff_crashes.py b/Tests/test_tiff_crashes.py index 143765b8eec..64e781cbada 100644 --- a/Tests/test_tiff_crashes.py +++ b/Tests/test_tiff_crashes.py @@ -10,6 +10,7 @@ # the output should be empty. There may be Python issues # in the valgrind especially if run in a debug Python # version. +from __future__ import annotations import pytest diff --git a/Tests/test_tiff_ifdrational.py b/Tests/test_tiff_ifdrational.py index 6e3fcec90e1..e7b41fb4738 100644 --- a/Tests/test_tiff_ifdrational.py +++ b/Tests/test_tiff_ifdrational.py @@ -1,3 +1,4 @@ +from __future__ import annotations from fractions import Fraction from PIL import Image, TiffImagePlugin, features diff --git a/Tests/test_uploader.py b/Tests/test_uploader.py index 720926e5377..6b693f7cd5d 100644 --- a/Tests/test_uploader.py +++ b/Tests/test_uploader.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .helper import assert_image_equal, assert_image_similar, hopper diff --git a/Tests/test_util.py b/Tests/test_util.py index 9efbdd1f380..1457d85f795 100644 --- a/Tests/test_util.py +++ b/Tests/test_util.py @@ -1,3 +1,4 @@ +from __future__ import annotations import pytest from PIL import _util diff --git a/Tests/test_webp_leaks.py b/Tests/test_webp_leaks.py index 5bd9bacdb35..28ebc7d79f1 100644 --- a/Tests/test_webp_leaks.py +++ b/Tests/test_webp_leaks.py @@ -1,3 +1,4 @@ +from __future__ import annotations from io import BytesIO from PIL import Image diff --git a/_custom_build/backend.py b/_custom_build/backend.py index 23225d6b8eb..d1537b80987 100644 --- a/_custom_build/backend.py +++ b/_custom_build/backend.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import sys from setuptools.build_meta import * # noqa: F403 diff --git a/conftest.py b/conftest.py index e123cca80fe..4dcd5e053ea 100644 --- a/conftest.py +++ b/conftest.py @@ -1 +1,3 @@ +from __future__ import annotations + pytest_plugins = ["Tests.helper"] diff --git a/docs/Guardfile b/docs/Guardfile index 6cbf07b0637..16a891a730d 100755 --- a/docs/Guardfile +++ b/docs/Guardfile @@ -1,4 +1,6 @@ #!/usr/bin/env python3 +from __future__ import annotations + from livereload.compiler import shell from livereload.task import Task diff --git a/docs/conf.py b/docs/conf.py index 833dfa215da..9974b0f2ae4 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -15,6 +15,7 @@ # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. # sys.path.insert(0, os.path.abspath('.')) +from __future__ import annotations import PIL diff --git a/docs/example/DdsImagePlugin.py b/docs/example/DdsImagePlugin.py index 61690410b6c..e98bb86806f 100644 --- a/docs/example/DdsImagePlugin.py +++ b/docs/example/DdsImagePlugin.py @@ -9,6 +9,7 @@ Full text of the CC0 license: https://creativecommons.org/publicdomain/zero/1.0/ """ +from __future__ import annotations import struct from io import BytesIO diff --git a/docs/example/anchors.py b/docs/example/anchors.py index 3447de4f74d..3a0e40b848d 100644 --- a/docs/example/anchors.py +++ b/docs/example/anchors.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from PIL import Image, ImageDraw, ImageFont font = ImageFont.truetype("Tests/fonts/NotoSans-Regular.ttf", 16) diff --git a/docs/handbook/image-file-formats.rst b/docs/handbook/image-file-formats.rst index 23da312a600..9cd65fd48cb 100644 --- a/docs/handbook/image-file-formats.rst +++ b/docs/handbook/image-file-formats.rst @@ -266,13 +266,14 @@ following options are available:: :py:class:`PIL.ImagePalette.ImagePalette` object. **optimize** - Whether to attempt to compress the palette by eliminating unused colors. + Whether to attempt to compress the palette by eliminating unused colors + (this is only useful if the palette can be compressed to the next smaller + power of 2 elements) and whether to mark all pixels that are not new in the + next frame as transparent. + This is attempted by default, unless a palette is specified as an option or as part of the first image's :py:attr:`~PIL.Image.Image.info` dictionary. - This is only useful if the palette can be compressed to the next smaller - power of 2 elements. - Note that if the image you are saving comes from an existing GIF, it may have the following properties in its :py:attr:`~PIL.Image.Image.info` dictionary. For these options, if you do not pass them in, they will default to diff --git a/pyproject.toml b/pyproject.toml index f9cea0612af..193e8c9b247 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -94,7 +94,6 @@ test-command = "cd {project} && .github/workflows/wheels-test.sh" test-extras = "tests" [tool.ruff] -line-length = 88 select = [ "C4", # flake8-comprehensions "E", # pycodestyle errors @@ -121,7 +120,39 @@ extend-ignore = [ [tool.ruff.isort] known-first-party = ["PIL"] +required-imports = ["from __future__ import annotations"] [tool.pytest.ini_options] addopts = "-ra --color=yes" testpaths = ["Tests"] + +[tool.mypy] +python_version = "3.8" +pretty = true +disallow_any_generics = true +enable_error_code = "ignore-without-code" +extra_checks = true +follow_imports = "silent" +warn_redundant_casts = true +warn_unreachable = true +warn_unused_ignores = true +exclude = [ + '^src/PIL/_tkinter_finder.py$', + '^src/PIL/DdsImagePlugin.py$', + '^src/PIL/FpxImagePlugin.py$', + '^src/PIL/Image.py$', + '^src/PIL/ImageCms.py$', + '^src/PIL/ImageFile.py$', + '^src/PIL/ImageFont.py$', + '^src/PIL/ImageMath.py$', + '^src/PIL/ImageMorph.py$', + '^src/PIL/ImageQt.py$', + '^src/PIL/ImageShow.py$', + '^src/PIL/ImImagePlugin.py$', + '^src/PIL/MicImagePlugin.py$', + '^src/PIL/PdfParser.py$', + '^src/PIL/PyAccess.py$', + '^src/PIL/TiffImagePlugin.py$', + '^src/PIL/TiffTags.py$', + '^src/PIL/WebPImagePlugin.py$', +] diff --git a/selftest.py b/selftest.py index 6eeadd1dbc6..600fd649688 100755 --- a/selftest.py +++ b/selftest.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 # minimal sanity check +from __future__ import annotations import sys diff --git a/setup.py b/setup.py index 2a364ba97eb..1bf0bcff558 100755 --- a/setup.py +++ b/setup.py @@ -7,6 +7,7 @@ # Final rating: 10/10 # Your cheese is so fresh most people think it's a cream: Mascarpone # ------------------------------ +from __future__ import annotations import os import re diff --git a/src/PIL/BdfFontFile.py b/src/PIL/BdfFontFile.py index 161954831ae..b12ddc2d4b4 100644 --- a/src/PIL/BdfFontFile.py +++ b/src/PIL/BdfFontFile.py @@ -20,7 +20,7 @@ """ Parse X Bitmap Distribution Format (BDF) """ - +from __future__ import annotations from . import FontFile, Image diff --git a/src/PIL/BlpImagePlugin.py b/src/PIL/BlpImagePlugin.py index 398696d5c77..b8f38b78a2e 100644 --- a/src/PIL/BlpImagePlugin.py +++ b/src/PIL/BlpImagePlugin.py @@ -28,6 +28,7 @@ - DXT3 compression is used if alpha_encoding == 1. - DXT5 compression is used if alpha_encoding == 7. """ +from __future__ import annotations import os import struct diff --git a/src/PIL/BmpImagePlugin.py b/src/PIL/BmpImagePlugin.py index b51019c66be..6f730cfef16 100644 --- a/src/PIL/BmpImagePlugin.py +++ b/src/PIL/BmpImagePlugin.py @@ -22,7 +22,7 @@ # # See the README file for information on usage and redistribution. # - +from __future__ import annotations import os diff --git a/src/PIL/BufrStubImagePlugin.py b/src/PIL/BufrStubImagePlugin.py index eef25aa14cf..60f3ec25b38 100644 --- a/src/PIL/BufrStubImagePlugin.py +++ b/src/PIL/BufrStubImagePlugin.py @@ -8,6 +8,7 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations from . import Image, ImageFile diff --git a/src/PIL/ContainerIO.py b/src/PIL/ContainerIO.py index 45e80b39af7..387a4c182e0 100644 --- a/src/PIL/ContainerIO.py +++ b/src/PIL/ContainerIO.py @@ -13,7 +13,7 @@ # # See the README file for information on usage and redistribution. # - +from __future__ import annotations import io diff --git a/src/PIL/CurImagePlugin.py b/src/PIL/CurImagePlugin.py index fc0dae44b9c..5fb2b0193ca 100644 --- a/src/PIL/CurImagePlugin.py +++ b/src/PIL/CurImagePlugin.py @@ -15,6 +15,8 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations + from . import BmpImagePlugin, Image from ._binary import i16le as i16 from ._binary import i32le as i32 diff --git a/src/PIL/DcxImagePlugin.py b/src/PIL/DcxImagePlugin.py index cde9d42f09f..f7344df44a7 100644 --- a/src/PIL/DcxImagePlugin.py +++ b/src/PIL/DcxImagePlugin.py @@ -20,6 +20,7 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations from . import Image from ._binary import i32le as i32 diff --git a/src/PIL/DdsImagePlugin.py b/src/PIL/DdsImagePlugin.py index 1758c9a4d13..5b6ac2ead50 100644 --- a/src/PIL/DdsImagePlugin.py +++ b/src/PIL/DdsImagePlugin.py @@ -9,6 +9,7 @@ Full text of the CC0 license: https://creativecommons.org/publicdomain/zero/1.0/ """ +from __future__ import annotations import io import struct diff --git a/src/PIL/EpsImagePlugin.py b/src/PIL/EpsImagePlugin.py index c05208c8026..d2e60aa0759 100644 --- a/src/PIL/EpsImagePlugin.py +++ b/src/PIL/EpsImagePlugin.py @@ -19,6 +19,7 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations import io import os diff --git a/src/PIL/ExifTags.py b/src/PIL/ExifTags.py index 2347c6d4c27..60a4d9774ae 100644 --- a/src/PIL/ExifTags.py +++ b/src/PIL/ExifTags.py @@ -13,6 +13,7 @@ This module provides constants and clear-text names for various well-known EXIF tags. """ +from __future__ import annotations from enum import IntEnum diff --git a/src/PIL/FitsImagePlugin.py b/src/PIL/FitsImagePlugin.py index 1ff8a7e913b..7dce2d60f76 100644 --- a/src/PIL/FitsImagePlugin.py +++ b/src/PIL/FitsImagePlugin.py @@ -8,6 +8,7 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations import math diff --git a/src/PIL/FliImagePlugin.py b/src/PIL/FliImagePlugin.py index b05a16259e6..9769761fc15 100644 --- a/src/PIL/FliImagePlugin.py +++ b/src/PIL/FliImagePlugin.py @@ -14,6 +14,7 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations import os diff --git a/src/PIL/FontFile.py b/src/PIL/FontFile.py index 085917ac38e..9621770e2a9 100644 --- a/src/PIL/FontFile.py +++ b/src/PIL/FontFile.py @@ -13,7 +13,7 @@ # # See the README file for information on usage and redistribution. # - +from __future__ import annotations import os diff --git a/src/PIL/FpxImagePlugin.py b/src/PIL/FpxImagePlugin.py index a0999130ea5..75680a94e02 100644 --- a/src/PIL/FpxImagePlugin.py +++ b/src/PIL/FpxImagePlugin.py @@ -14,6 +14,8 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations + import olefile from . import Image, ImageFile diff --git a/src/PIL/FtexImagePlugin.py b/src/PIL/FtexImagePlugin.py index c2e4ead7174..d5513a56a11 100644 --- a/src/PIL/FtexImagePlugin.py +++ b/src/PIL/FtexImagePlugin.py @@ -50,6 +50,7 @@ Note: All data is stored in little-Endian (Intel) byte order. """ +from __future__ import annotations import struct from enum import IntEnum diff --git a/src/PIL/GbrImagePlugin.py b/src/PIL/GbrImagePlugin.py index ec6e9de6e7b..6722fa2b144 100644 --- a/src/PIL/GbrImagePlugin.py +++ b/src/PIL/GbrImagePlugin.py @@ -23,6 +23,7 @@ # Version 2 files are saved by GIMP v2.8 (at least) # Version 3 files have a format specifier of 18 for 16bit floats in # the color depth field. This is currently unsupported by Pillow. +from __future__ import annotations from . import Image, ImageFile from ._binary import i32be as i32 diff --git a/src/PIL/GdImageFile.py b/src/PIL/GdImageFile.py index 3599994a8e3..d84876eb6b6 100644 --- a/src/PIL/GdImageFile.py +++ b/src/PIL/GdImageFile.py @@ -25,7 +25,7 @@ class is not registered for use with :py:func:`PIL.Image.open()`. To open a implementation is provided for convenience and demonstrational purposes only. """ - +from __future__ import annotations from . import ImageFile, ImagePalette, UnidentifiedImageError from ._binary import i16be as i16 diff --git a/src/PIL/GifImagePlugin.py b/src/PIL/GifImagePlugin.py index 0793d4b4277..57d87078bca 100644 --- a/src/PIL/GifImagePlugin.py +++ b/src/PIL/GifImagePlugin.py @@ -23,6 +23,7 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations import itertools import math @@ -30,7 +31,15 @@ import subprocess from enum import IntEnum -from . import Image, ImageChops, ImageFile, ImagePalette, ImageSequence +from . import ( + Image, + ImageChops, + ImageFile, + ImageMath, + ImageOps, + ImagePalette, + ImageSequence, +) from ._binary import i16le as i16 from ._binary import o8 from ._binary import o16le as o16 @@ -330,6 +339,8 @@ def _seek(self, frame, update_image=True): def _rgb(color): if self._frame_palette: + if color * 3 + 3 > len(self._frame_palette.palette): + color = 0 color = tuple(self._frame_palette.palette[color * 3 : color * 3 + 3]) else: color = (color, color, color) @@ -534,7 +545,15 @@ def _normalize_palette(im, palette, info): else: used_palette_colors = _get_optimize(im, info) if used_palette_colors is not None: - return im.remap_palette(used_palette_colors, source_palette) + im = im.remap_palette(used_palette_colors, source_palette) + if "transparency" in info: + try: + info["transparency"] = used_palette_colors.index( + info["transparency"] + ) + except ValueError: + del info["transparency"] + return im im.palette.palette = source_palette return im @@ -562,13 +581,11 @@ def _write_single_frame(im, fp, palette): def _getbbox(base_im, im_frame): - if _get_palette_bytes(im_frame) == _get_palette_bytes(base_im): - delta = ImageChops.subtract_modulo(im_frame, base_im) - else: - delta = ImageChops.subtract_modulo( - im_frame.convert("RGBA"), base_im.convert("RGBA") - ) - return delta.getbbox(alpha_only=False) + if _get_palette_bytes(im_frame) != _get_palette_bytes(base_im): + im_frame = im_frame.convert("RGBA") + base_im = base_im.convert("RGBA") + delta = ImageChops.subtract_modulo(im_frame, base_im) + return delta, delta.getbbox(alpha_only=False) def _write_multiple_frames(im, fp, palette): @@ -576,6 +593,7 @@ def _write_multiple_frames(im, fp, palette): disposal = im.encoderinfo.get("disposal", im.info.get("disposal")) im_frames = [] + previous_im = None frame_count = 0 background_im = None for imSequence in itertools.chain([im], im.encoderinfo.get("append_images", [])): @@ -589,9 +607,9 @@ def _write_multiple_frames(im, fp, palette): im.encoderinfo.setdefault(k, v) encoderinfo = im.encoderinfo.copy() - im_frame = _normalize_palette(im_frame, palette, encoderinfo) if "transparency" in im_frame.info: encoderinfo.setdefault("transparency", im_frame.info["transparency"]) + im_frame = _normalize_palette(im_frame, palette, encoderinfo) if isinstance(duration, (list, tuple)): encoderinfo["duration"] = duration[frame_count] elif duration is None and "duration" in im_frame.info: @@ -600,14 +618,16 @@ def _write_multiple_frames(im, fp, palette): encoderinfo["disposal"] = disposal[frame_count] frame_count += 1 + diff_frame = None if im_frames: # delta frame - previous = im_frames[-1] - bbox = _getbbox(previous["im"], im_frame) + delta, bbox = _getbbox(previous_im, im_frame) if not bbox: # This frame is identical to the previous frame if encoderinfo.get("duration"): - previous["encoderinfo"]["duration"] += encoderinfo["duration"] + im_frames[-1]["encoderinfo"]["duration"] += encoderinfo[ + "duration" + ] continue if encoderinfo.get("disposal") == 2: if background_im is None: @@ -617,33 +637,67 @@ def _write_multiple_frames(im, fp, palette): background = _get_background(im_frame, color) background_im = Image.new("P", im_frame.size, background) background_im.putpalette(im_frames[0]["im"].palette) - bbox = _getbbox(background_im, im_frame) + delta, bbox = _getbbox(background_im, im_frame) + if encoderinfo.get("optimize") and im_frame.mode != "1": + if "transparency" not in encoderinfo: + try: + encoderinfo[ + "transparency" + ] = im_frame.palette._new_color_index(im_frame) + except ValueError: + pass + if "transparency" in encoderinfo: + # When the delta is zero, fill the image with transparency + diff_frame = im_frame.copy() + fill = Image.new( + "P", diff_frame.size, encoderinfo["transparency"] + ) + if delta.mode == "RGBA": + r, g, b, a = delta.split() + mask = ImageMath.eval( + "convert(max(max(max(r, g), b), a) * 255, '1')", + r=r, + g=g, + b=b, + a=a, + ) + else: + if delta.mode == "P": + # Convert to L without considering palette + delta_l = Image.new("L", delta.size) + delta_l.putdata(delta.getdata()) + delta = delta_l + mask = ImageMath.eval("convert(im * 255, '1')", im=delta) + diff_frame.paste(fill, mask=ImageOps.invert(mask)) else: bbox = None - im_frames.append({"im": im_frame, "bbox": bbox, "encoderinfo": encoderinfo}) - - if len(im_frames) > 1: - for frame_data in im_frames: - im_frame = frame_data["im"] - if not frame_data["bbox"]: - # global header - for s in _get_global_header(im_frame, frame_data["encoderinfo"]): - fp.write(s) - offset = (0, 0) - else: - # compress difference - if not palette: - frame_data["encoderinfo"]["include_color_table"] = True - - im_frame = im_frame.crop(frame_data["bbox"]) - offset = frame_data["bbox"][:2] - _write_frame_data(fp, im_frame, offset, frame_data["encoderinfo"]) - return True - elif "duration" in im.encoderinfo and isinstance( - im.encoderinfo["duration"], (list, tuple) - ): - # Since multiple frames will not be written, add together the frame durations - im.encoderinfo["duration"] = sum(im.encoderinfo["duration"]) + previous_im = im_frame + im_frames.append( + {"im": diff_frame or im_frame, "bbox": bbox, "encoderinfo": encoderinfo} + ) + + if len(im_frames) == 1: + if "duration" in im.encoderinfo: + # Since multiple frames will not be written, use the combined duration + im.encoderinfo["duration"] = im_frames[0]["encoderinfo"]["duration"] + return + + for frame_data in im_frames: + im_frame = frame_data["im"] + if not frame_data["bbox"]: + # global header + for s in _get_global_header(im_frame, frame_data["encoderinfo"]): + fp.write(s) + offset = (0, 0) + else: + # compress difference + if not palette: + frame_data["encoderinfo"]["include_color_table"] = True + + im_frame = im_frame.crop(frame_data["bbox"]) + offset = frame_data["bbox"][:2] + _write_frame_data(fp, im_frame, offset, frame_data["encoderinfo"]) + return True def _save_all(im, fp, filename): @@ -678,22 +732,10 @@ def get_interlace(im): def _write_local_header(fp, im, offset, flags): - transparent_color_exists = False try: - transparency = int(im.encoderinfo["transparency"]) - except (KeyError, ValueError): - pass - else: - # optimize the block away if transparent color is not used - transparent_color_exists = True - - used_palette_colors = _get_optimize(im, im.encoderinfo) - if used_palette_colors is not None: - # adjust the transparency index after optimize - try: - transparency = used_palette_colors.index(transparency) - except ValueError: - transparent_color_exists = False + transparency = im.encoderinfo["transparency"] + except KeyError: + transparency = None if "duration" in im.encoderinfo: duration = int(im.encoderinfo["duration"] / 10) @@ -702,11 +744,9 @@ def _write_local_header(fp, im, offset, flags): disposal = int(im.encoderinfo.get("disposal", 0)) - if transparent_color_exists or duration != 0 or disposal: - packed_flag = 1 if transparent_color_exists else 0 + if transparency is not None or duration != 0 or disposal: + packed_flag = 1 if transparency is not None else 0 packed_flag |= disposal << 2 - if not transparent_color_exists: - transparency = 0 fp.write( b"!" @@ -714,7 +754,7 @@ def _write_local_header(fp, im, offset, flags): + o8(4) # length + o8(packed_flag) # packed fields + o16(duration) # duration - + o8(transparency) # transparency index + + o8(transparency or 0) # transparency index + o8(0) ) @@ -802,7 +842,7 @@ def _get_optimize(im, info): :param info: encoderinfo :returns: list of indexes of palette entries in use, or None """ - if im.mode in ("P", "L") and info and info.get("optimize", 0): + if im.mode in ("P", "L") and info and info.get("optimize"): # Potentially expensive operation. # The palette saves 3 bytes per color not used, but palette diff --git a/src/PIL/GimpGradientFile.py b/src/PIL/GimpGradientFile.py index 8e801be0b8a..2d8c78ea91a 100644 --- a/src/PIL/GimpGradientFile.py +++ b/src/PIL/GimpGradientFile.py @@ -18,7 +18,7 @@ the corresponding code in GIMP, written by Federico Mena Quintero. See the GIMP distribution for more information.) """ - +from __future__ import annotations from math import log, pi, sin, sqrt diff --git a/src/PIL/GimpPaletteFile.py b/src/PIL/GimpPaletteFile.py index d388928945a..a3109ebaa1b 100644 --- a/src/PIL/GimpPaletteFile.py +++ b/src/PIL/GimpPaletteFile.py @@ -13,6 +13,7 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations import re diff --git a/src/PIL/GribStubImagePlugin.py b/src/PIL/GribStubImagePlugin.py index c1c71da08c9..f8106800c42 100644 --- a/src/PIL/GribStubImagePlugin.py +++ b/src/PIL/GribStubImagePlugin.py @@ -8,6 +8,7 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations from . import Image, ImageFile diff --git a/src/PIL/Hdf5StubImagePlugin.py b/src/PIL/Hdf5StubImagePlugin.py index c26b480acf2..65409e269fc 100644 --- a/src/PIL/Hdf5StubImagePlugin.py +++ b/src/PIL/Hdf5StubImagePlugin.py @@ -8,6 +8,7 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations from . import Image, ImageFile diff --git a/src/PIL/IcnsImagePlugin.py b/src/PIL/IcnsImagePlugin.py index b415a32194d..d877b4ecba6 100644 --- a/src/PIL/IcnsImagePlugin.py +++ b/src/PIL/IcnsImagePlugin.py @@ -16,6 +16,7 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations import io import os diff --git a/src/PIL/IcoImagePlugin.py b/src/PIL/IcoImagePlugin.py index 7f0f0047cdc..1b22f8645dc 100644 --- a/src/PIL/IcoImagePlugin.py +++ b/src/PIL/IcoImagePlugin.py @@ -20,7 +20,7 @@ # Icon format references: # * https://en.wikipedia.org/wiki/ICO_(file_format) # * https://msdn.microsoft.com/en-us/library/ms997538.aspx - +from __future__ import annotations import warnings from io import BytesIO diff --git a/src/PIL/ImImagePlugin.py b/src/PIL/ImImagePlugin.py index b42ba7cac70..97d726a8a65 100644 --- a/src/PIL/ImImagePlugin.py +++ b/src/PIL/ImImagePlugin.py @@ -24,7 +24,7 @@ # # See the README file for information on usage and redistribution. # - +from __future__ import annotations import os import re diff --git a/src/PIL/Image.py b/src/PIL/Image.py index ad9df024453..d04801cba75 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -24,6 +24,8 @@ # See the README file for information on usage and redistribution. # +from __future__ import annotations + import atexit import builtins import io @@ -477,8 +479,8 @@ class Image: * :py:func:`~PIL.Image.frombytes` """ - format = None - format_description = None + format: str | None = None + format_description: str | None = None _close_exclusive_fp_after_loading = True def __init__(self): @@ -1179,7 +1181,7 @@ def quantize( return im - def copy(self): + def copy(self) -> Image: """ Copies this image. Use this method if you wish to paste things into an image, but still retain the original. @@ -2448,7 +2450,7 @@ def save(self, fp, format=None, **params): if open_fp: fp.close() - def seek(self, frame): + def seek(self, frame) -> Image: """ Seeks to the given frame in this sequence file. If you seek beyond the end of the sequence, the method raises an @@ -2535,7 +2537,7 @@ def getchannel(self, channel): return self._new(self.im.getband(channel)) - def tell(self): + def tell(self) -> int: """ Returns the current frame number. See :py:meth:`~PIL.Image.Image.seek`. diff --git a/src/PIL/ImageChops.py b/src/PIL/ImageChops.py index 0255f41b6f7..29a5c995fd8 100644 --- a/src/PIL/ImageChops.py +++ b/src/PIL/ImageChops.py @@ -15,10 +15,12 @@ # See the README file for information on usage and redistribution. # +from __future__ import annotations + from . import Image -def constant(image, value): +def constant(image: Image.Image, value: int) -> Image.Image: """Fill a channel with a given gray level. :rtype: :py:class:`~PIL.Image.Image` @@ -27,7 +29,7 @@ def constant(image, value): return Image.new("L", image.size, value) -def duplicate(image): +def duplicate(image: Image.Image) -> Image.Image: """Copy a channel. Alias for :py:meth:`PIL.Image.Image.copy`. :rtype: :py:class:`~PIL.Image.Image` @@ -36,7 +38,7 @@ def duplicate(image): return image.copy() -def invert(image): +def invert(image: Image.Image) -> Image.Image: """ Invert an image (channel). :: @@ -49,7 +51,7 @@ def invert(image): return image._new(image.im.chop_invert()) -def lighter(image1, image2): +def lighter(image1: Image.Image, image2: Image.Image) -> Image.Image: """ Compares the two images, pixel by pixel, and returns a new image containing the lighter values. :: @@ -64,7 +66,7 @@ def lighter(image1, image2): return image1._new(image1.im.chop_lighter(image2.im)) -def darker(image1, image2): +def darker(image1: Image.Image, image2: Image.Image) -> Image.Image: """ Compares the two images, pixel by pixel, and returns a new image containing the darker values. :: @@ -79,7 +81,7 @@ def darker(image1, image2): return image1._new(image1.im.chop_darker(image2.im)) -def difference(image1, image2): +def difference(image1: Image.Image, image2: Image.Image) -> Image.Image: """ Returns the absolute value of the pixel-by-pixel difference between the two images. :: @@ -94,7 +96,7 @@ def difference(image1, image2): return image1._new(image1.im.chop_difference(image2.im)) -def multiply(image1, image2): +def multiply(image1: Image.Image, image2: Image.Image) -> Image.Image: """ Superimposes two images on top of each other. @@ -111,7 +113,7 @@ def multiply(image1, image2): return image1._new(image1.im.chop_multiply(image2.im)) -def screen(image1, image2): +def screen(image1: Image.Image, image2: Image.Image) -> Image.Image: """ Superimposes two inverted images on top of each other. :: @@ -125,7 +127,7 @@ def screen(image1, image2): return image1._new(image1.im.chop_screen(image2.im)) -def soft_light(image1, image2): +def soft_light(image1: Image.Image, image2: Image.Image) -> Image.Image: """ Superimposes two images on top of each other using the Soft Light algorithm @@ -137,7 +139,7 @@ def soft_light(image1, image2): return image1._new(image1.im.chop_soft_light(image2.im)) -def hard_light(image1, image2): +def hard_light(image1: Image.Image, image2: Image.Image) -> Image.Image: """ Superimposes two images on top of each other using the Hard Light algorithm @@ -149,7 +151,7 @@ def hard_light(image1, image2): return image1._new(image1.im.chop_hard_light(image2.im)) -def overlay(image1, image2): +def overlay(image1: Image.Image, image2: Image.Image) -> Image.Image: """ Superimposes two images on top of each other using the Overlay algorithm @@ -161,7 +163,9 @@ def overlay(image1, image2): return image1._new(image1.im.chop_overlay(image2.im)) -def add(image1, image2, scale=1.0, offset=0): +def add( + image1: Image.Image, image2: Image.Image, scale: float = 1.0, offset: float = 0 +) -> Image.Image: """ Adds two images, dividing the result by scale and adding the offset. If omitted, scale defaults to 1.0, and offset to 0.0. :: @@ -176,7 +180,9 @@ def add(image1, image2, scale=1.0, offset=0): return image1._new(image1.im.chop_add(image2.im, scale, offset)) -def subtract(image1, image2, scale=1.0, offset=0): +def subtract( + image1: Image.Image, image2: Image.Image, scale: float = 1.0, offset: float = 0 +) -> Image.Image: """ Subtracts two images, dividing the result by scale and adding the offset. If omitted, scale defaults to 1.0, and offset to 0.0. :: @@ -191,7 +197,7 @@ def subtract(image1, image2, scale=1.0, offset=0): return image1._new(image1.im.chop_subtract(image2.im, scale, offset)) -def add_modulo(image1, image2): +def add_modulo(image1: Image.Image, image2: Image.Image) -> Image.Image: """Add two images, without clipping the result. :: out = ((image1 + image2) % MAX) @@ -204,7 +210,7 @@ def add_modulo(image1, image2): return image1._new(image1.im.chop_add_modulo(image2.im)) -def subtract_modulo(image1, image2): +def subtract_modulo(image1: Image.Image, image2: Image.Image) -> Image.Image: """Subtract two images, without clipping the result. :: out = ((image1 - image2) % MAX) @@ -217,7 +223,7 @@ def subtract_modulo(image1, image2): return image1._new(image1.im.chop_subtract_modulo(image2.im)) -def logical_and(image1, image2): +def logical_and(image1: Image.Image, image2: Image.Image) -> Image.Image: """Logical AND between two images. Both of the images must have mode "1". If you would like to perform a @@ -235,7 +241,7 @@ def logical_and(image1, image2): return image1._new(image1.im.chop_and(image2.im)) -def logical_or(image1, image2): +def logical_or(image1: Image.Image, image2: Image.Image) -> Image.Image: """Logical OR between two images. Both of the images must have mode "1". :: @@ -250,7 +256,7 @@ def logical_or(image1, image2): return image1._new(image1.im.chop_or(image2.im)) -def logical_xor(image1, image2): +def logical_xor(image1: Image.Image, image2: Image.Image) -> Image.Image: """Logical XOR between two images. Both of the images must have mode "1". :: @@ -265,7 +271,7 @@ def logical_xor(image1, image2): return image1._new(image1.im.chop_xor(image2.im)) -def blend(image1, image2, alpha): +def blend(image1: Image.Image, image2: Image.Image, alpha: float) -> Image.Image: """Blend images using constant transparency weight. Alias for :py:func:`PIL.Image.blend`. @@ -275,7 +281,9 @@ def blend(image1, image2, alpha): return Image.blend(image1, image2, alpha) -def composite(image1, image2, mask): +def composite( + image1: Image.Image, image2: Image.Image, mask: Image.Image +) -> Image.Image: """Create composite using transparency mask. Alias for :py:func:`PIL.Image.composite`. @@ -285,7 +293,7 @@ def composite(image1, image2, mask): return Image.composite(image1, image2, mask) -def offset(image, xoffset, yoffset=None): +def offset(image: Image.Image, xoffset: int, yoffset: int | None = None) -> Image.Image: """Returns a copy of the image where data has been offset by the given distances. Data wraps around the edges. If ``yoffset`` is omitted, it is assumed to be equal to ``xoffset``. diff --git a/src/PIL/ImageCms.py b/src/PIL/ImageCms.py index 0df3a4c6ce5..9d27f2513a7 100644 --- a/src/PIL/ImageCms.py +++ b/src/PIL/ImageCms.py @@ -14,6 +14,7 @@ # See the README file for information on usage and redistribution. See # below for the original description. +from __future__ import annotations import sys from enum import IntEnum diff --git a/src/PIL/ImageColor.py b/src/PIL/ImageColor.py index 894461c831d..bfad27c82d6 100644 --- a/src/PIL/ImageColor.py +++ b/src/PIL/ImageColor.py @@ -16,6 +16,7 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations import re diff --git a/src/PIL/ImageDraw.py b/src/PIL/ImageDraw.py index 6509d4c8e43..84665f54fff 100644 --- a/src/PIL/ImageDraw.py +++ b/src/PIL/ImageDraw.py @@ -29,9 +29,11 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations import math import numbers +import struct from . import Image, ImageColor @@ -542,7 +544,8 @@ def draw_text(ink, stroke_width=0, stroke_offset=None): # font.getmask2(mode="RGBA") returns color in RGB bands and mask in A # extract mask and set text alpha color, mask = mask, mask.getband(3) - color.fillband(3, (ink >> 24) & 0xFF) + ink_alpha = struct.pack("i", ink)[3] + color.fillband(3, ink_alpha) x, y = coord self.im.paste(color, (x, y, x + mask.size[0], y + mask.size[1]), mask) else: diff --git a/src/PIL/ImageDraw2.py b/src/PIL/ImageDraw2.py index 7ce0224a67c..35ee5834e34 100644 --- a/src/PIL/ImageDraw2.py +++ b/src/PIL/ImageDraw2.py @@ -22,7 +22,7 @@ .. seealso:: :py:mod:`PIL.ImageDraw` """ - +from __future__ import annotations from . import Image, ImageColor, ImageDraw, ImageFont, ImagePath diff --git a/src/PIL/ImageEnhance.py b/src/PIL/ImageEnhance.py index d7fdec262f4..93a50d2a2b9 100644 --- a/src/PIL/ImageEnhance.py +++ b/src/PIL/ImageEnhance.py @@ -17,6 +17,7 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations from . import Image, ImageFilter, ImageStat diff --git a/src/PIL/ImageFile.py b/src/PIL/ImageFile.py index 1bc11af0f26..ae4e23db17b 100644 --- a/src/PIL/ImageFile.py +++ b/src/PIL/ImageFile.py @@ -207,6 +207,8 @@ def load(self): if use_mmap: # try memory mapping decoder_name, extents, offset, args = self.tile[0] + if isinstance(args, str): + args = (args, 0, 1) if ( decoder_name == "raw" and len(args) >= 3 diff --git a/src/PIL/ImageFilter.py b/src/PIL/ImageFilter.py index c24f86ef38f..021b40c0ef4 100644 --- a/src/PIL/ImageFilter.py +++ b/src/PIL/ImageFilter.py @@ -14,6 +14,8 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations + import functools diff --git a/src/PIL/ImageFont.py b/src/PIL/ImageFont.py index 66749a4d5fb..6db7cc4eccb 100644 --- a/src/PIL/ImageFont.py +++ b/src/PIL/ImageFont.py @@ -585,16 +585,16 @@ def getmask2( im = None size = None - def fill(mode, im_size): + def fill(width, height): nonlocal im, size - size = im_size + size = (width, height) if Image.MAX_IMAGE_PIXELS is not None: - pixels = max(1, size[0]) * max(1, size[1]) + pixels = max(1, width) * max(1, height) if pixels > 2 * Image.MAX_IMAGE_PIXELS: return - im = Image.core.fill(mode, size) + im = Image.core.fill("RGBA" if mode == "RGBA" else "L", size) return im offset = self.font.render( @@ -732,7 +732,6 @@ def getlength(self, text, *args, **kwargs): if self.orientation in (Image.Transpose.ROTATE_90, Image.Transpose.ROTATE_270): msg = "text length is undefined for text rotated by 90 or 270 degrees" raise ValueError(msg) - _string_length_check(text) return self.font.getlength(text, *args, **kwargs) diff --git a/src/PIL/ImageGrab.py b/src/PIL/ImageGrab.py index bcfffc3dc13..a4993d3d4b8 100644 --- a/src/PIL/ImageGrab.py +++ b/src/PIL/ImageGrab.py @@ -14,6 +14,7 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations import io import os diff --git a/src/PIL/ImageMath.py b/src/PIL/ImageMath.py index 2c73acb9792..7ca512e7568 100644 --- a/src/PIL/ImageMath.py +++ b/src/PIL/ImageMath.py @@ -14,16 +14,13 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations import builtins from . import Image, _imagingmath -def _isconstant(v): - return isinstance(v, (int, float)) - - class _Operand: """Wraps an image operand, providing standard operators""" @@ -43,7 +40,7 @@ def __fixup(self, im1): raise ValueError(msg) else: # argument was a constant - if _isconstant(im1) and self.im.mode in ("1", "L", "I"): + if isinstance(im1, (int, float)) and self.im.mode in ("1", "L", "I"): return Image.new("I", self.im.size, im1) else: return Image.new("F", self.im.size, im1) diff --git a/src/PIL/ImageMode.py b/src/PIL/ImageMode.py index a0b33514296..d61dd6fead2 100644 --- a/src/PIL/ImageMode.py +++ b/src/PIL/ImageMode.py @@ -12,6 +12,7 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations import sys @@ -22,18 +23,25 @@ class ModeDescriptor: """Wrapper for mode strings.""" - def __init__(self, mode, bands, basemode, basetype, typestr): + def __init__( + self, + mode: str, + bands: tuple[str, ...], + basemode: str, + basetype: str, + typestr: str, + ) -> None: self.mode = mode self.bands = bands self.basemode = basemode self.basetype = basetype self.typestr = typestr - def __str__(self): + def __str__(self) -> str: return self.mode -def getmode(mode): +def getmode(mode: str) -> ModeDescriptor: """Gets a mode descriptor for the given mode.""" global _modes if not _modes: diff --git a/src/PIL/ImageMorph.py b/src/PIL/ImageMorph.py index 6fccc315b3d..282e7d2a54e 100644 --- a/src/PIL/ImageMorph.py +++ b/src/PIL/ImageMorph.py @@ -4,6 +4,7 @@ # 2014-06-04 Initial version. # # Copyright (c) 2014 Dov Grobgeld +from __future__ import annotations import re diff --git a/src/PIL/ImageOps.py b/src/PIL/ImageOps.py index f183c8f279e..a9e626b2b2a 100644 --- a/src/PIL/ImageOps.py +++ b/src/PIL/ImageOps.py @@ -16,6 +16,7 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations import functools import operator diff --git a/src/PIL/ImagePalette.py b/src/PIL/ImagePalette.py index f9295e299bb..fbcfa309d29 100644 --- a/src/PIL/ImagePalette.py +++ b/src/PIL/ImagePalette.py @@ -15,6 +15,7 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations import array @@ -102,6 +103,30 @@ def tobytes(self): # Declare tostring as an alias for tobytes tostring = tobytes + def _new_color_index(self, image=None, e=None): + if not isinstance(self.palette, bytearray): + self._palette = bytearray(self.palette) + index = len(self.palette) // 3 + special_colors = () + if image: + special_colors = ( + image.info.get("background"), + image.info.get("transparency"), + ) + while index in special_colors: + index += 1 + if index >= 256: + if image: + # Search for an unused index + for i, count in reversed(list(enumerate(image.histogram()))): + if count == 0 and i not in special_colors: + index = i + break + if index >= 256: + msg = "cannot allocate more than 256 colors" + raise ValueError(msg) from e + return index + def getcolor(self, color, image=None): """Given an rgb tuple, allocate palette entry. @@ -124,27 +149,7 @@ def getcolor(self, color, image=None): return self.colors[color] except KeyError as e: # allocate new color slot - if not isinstance(self.palette, bytearray): - self._palette = bytearray(self.palette) - index = len(self.palette) // 3 - special_colors = () - if image: - special_colors = ( - image.info.get("background"), - image.info.get("transparency"), - ) - while index in special_colors: - index += 1 - if index >= 256: - if image: - # Search for an unused index - for i, count in reversed(list(enumerate(image.histogram()))): - if count == 0 and i not in special_colors: - index = i - break - if index >= 256: - msg = "cannot allocate more than 256 colors" - raise ValueError(msg) from e + index = self._new_color_index(image, e) self.colors[color] = index if index * 3 < len(self.palette): self._palette = ( diff --git a/src/PIL/ImagePath.py b/src/PIL/ImagePath.py index 3d3538c97b7..77e8a609a55 100644 --- a/src/PIL/ImagePath.py +++ b/src/PIL/ImagePath.py @@ -13,6 +13,7 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations from . import Image diff --git a/src/PIL/ImageQt.py b/src/PIL/ImageQt.py index 56c1aa52576..6377c750105 100644 --- a/src/PIL/ImageQt.py +++ b/src/PIL/ImageQt.py @@ -15,6 +15,7 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations import sys from io import BytesIO diff --git a/src/PIL/ImageSequence.py b/src/PIL/ImageSequence.py index 2d96b8b1365..2c185027630 100644 --- a/src/PIL/ImageSequence.py +++ b/src/PIL/ImageSequence.py @@ -14,6 +14,11 @@ # ## +from __future__ import annotations + +from typing import Callable + +from . import Image class Iterator: @@ -28,14 +33,14 @@ class Iterator: :param im: An image object. """ - def __init__(self, im): + def __init__(self, im: Image.Image): if not hasattr(im, "seek"): msg = "im must have seek method" raise AttributeError(msg) self.im = im self.position = getattr(self.im, "_min_frame", 0) - def __getitem__(self, ix): + def __getitem__(self, ix: int) -> Image.Image: try: self.im.seek(ix) return self.im @@ -43,10 +48,10 @@ def __getitem__(self, ix): msg = "end of sequence" raise IndexError(msg) from e - def __iter__(self): + def __iter__(self) -> Iterator: return self - def __next__(self): + def __next__(self) -> Image.Image: try: self.im.seek(self.position) self.position += 1 @@ -56,7 +61,10 @@ def __next__(self): raise StopIteration(msg) from e -def all_frames(im, func=None): +def all_frames( + im: Image.Image | list[Image.Image], + func: Callable[[Image.Image], Image.Image] | None = None, +) -> list[Image.Image]: """ Applies a given function to all frames in an image or a list of images. The frames are returned as a list of separate images. diff --git a/src/PIL/ImageShow.py b/src/PIL/ImageShow.py index 3d8fa2e402f..fad3e098003 100644 --- a/src/PIL/ImageShow.py +++ b/src/PIL/ImageShow.py @@ -11,6 +11,8 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations + import os import shutil import subprocess diff --git a/src/PIL/ImageStat.py b/src/PIL/ImageStat.py index edc39fb532d..13864e59cfc 100644 --- a/src/PIL/ImageStat.py +++ b/src/PIL/ImageStat.py @@ -20,6 +20,7 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations import math diff --git a/src/PIL/ImageTk.py b/src/PIL/ImageTk.py index bf98eb2c8c2..10b2cc69a1e 100644 --- a/src/PIL/ImageTk.py +++ b/src/PIL/ImageTk.py @@ -24,6 +24,7 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations import tkinter from io import BytesIO diff --git a/src/PIL/ImageTransform.py b/src/PIL/ImageTransform.py index 7881f0d262b..1fdaa9140ff 100644 --- a/src/PIL/ImageTransform.py +++ b/src/PIL/ImageTransform.py @@ -12,6 +12,7 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations from . import Image diff --git a/src/PIL/ImageWin.py b/src/PIL/ImageWin.py index c7c64b35add..75910d2d9ab 100644 --- a/src/PIL/ImageWin.py +++ b/src/PIL/ImageWin.py @@ -16,6 +16,7 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations from . import Image diff --git a/src/PIL/ImtImagePlugin.py b/src/PIL/ImtImagePlugin.py index d409fcd59de..7469c592dd2 100644 --- a/src/PIL/ImtImagePlugin.py +++ b/src/PIL/ImtImagePlugin.py @@ -13,7 +13,7 @@ # # See the README file for information on usage and redistribution. # - +from __future__ import annotations import re diff --git a/src/PIL/IptcImagePlugin.py b/src/PIL/IptcImagePlugin.py index 3a40cf987f4..e7dc3e4e4d2 100644 --- a/src/PIL/IptcImagePlugin.py +++ b/src/PIL/IptcImagePlugin.py @@ -14,6 +14,8 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations + import os import tempfile diff --git a/src/PIL/Jpeg2KImagePlugin.py b/src/PIL/Jpeg2KImagePlugin.py index bb0cb676a2e..4b778a0d33a 100644 --- a/src/PIL/Jpeg2KImagePlugin.py +++ b/src/PIL/Jpeg2KImagePlugin.py @@ -13,6 +13,8 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations + import io import os import struct diff --git a/src/PIL/JpegImagePlugin.py b/src/PIL/JpegImagePlugin.py index 5add65f4542..59bade303f8 100644 --- a/src/PIL/JpegImagePlugin.py +++ b/src/PIL/JpegImagePlugin.py @@ -31,6 +31,8 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations + import array import io import math diff --git a/src/PIL/JpegPresets.py b/src/PIL/JpegPresets.py index a678e248e9a..9ecfdb2599a 100644 --- a/src/PIL/JpegPresets.py +++ b/src/PIL/JpegPresets.py @@ -62,6 +62,7 @@ https://web.archive.org/web/20120328125543/http://www.jpegcameras.com/libjpeg/libjpeg-3.html """ +from __future__ import annotations # fmt: off presets = { diff --git a/src/PIL/McIdasImagePlugin.py b/src/PIL/McIdasImagePlugin.py index bb79e71de5d..9a85c0d15b0 100644 --- a/src/PIL/McIdasImagePlugin.py +++ b/src/PIL/McIdasImagePlugin.py @@ -15,6 +15,7 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations import struct diff --git a/src/PIL/MicImagePlugin.py b/src/PIL/MicImagePlugin.py index 9300d354544..f4529d9ae74 100644 --- a/src/PIL/MicImagePlugin.py +++ b/src/PIL/MicImagePlugin.py @@ -15,7 +15,7 @@ # # See the README file for information on usage and redistribution. # - +from __future__ import annotations import olefile diff --git a/src/PIL/MpegImagePlugin.py b/src/PIL/MpegImagePlugin.py index bfa88fe99c4..f4e598ca3a0 100644 --- a/src/PIL/MpegImagePlugin.py +++ b/src/PIL/MpegImagePlugin.py @@ -12,7 +12,7 @@ # # See the README file for information on usage and redistribution. # - +from __future__ import annotations from . import Image, ImageFile from ._binary import i8 diff --git a/src/PIL/MpoImagePlugin.py b/src/PIL/MpoImagePlugin.py index 89083b4ff76..199a100904c 100644 --- a/src/PIL/MpoImagePlugin.py +++ b/src/PIL/MpoImagePlugin.py @@ -17,6 +17,7 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations import itertools import os diff --git a/src/PIL/MspImagePlugin.py b/src/PIL/MspImagePlugin.py index 3f3609f1c20..77dac65b6b3 100644 --- a/src/PIL/MspImagePlugin.py +++ b/src/PIL/MspImagePlugin.py @@ -22,6 +22,7 @@ # Figure 206. Windows Paint Version 2: "LinS" Format. Used in Windows V2.03 # # See also: https://www.fileformat.info/format/mspaint/egff.htm +from __future__ import annotations import io import struct diff --git a/src/PIL/PSDraw.py b/src/PIL/PSDraw.py index c01534bbf42..848fc2f716a 100644 --- a/src/PIL/PSDraw.py +++ b/src/PIL/PSDraw.py @@ -14,6 +14,7 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations import sys diff --git a/src/PIL/PaletteFile.py b/src/PIL/PaletteFile.py index 4a2c497fc49..dc31754020e 100644 --- a/src/PIL/PaletteFile.py +++ b/src/PIL/PaletteFile.py @@ -12,6 +12,7 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations from ._binary import o8 diff --git a/src/PIL/PalmImagePlugin.py b/src/PIL/PalmImagePlugin.py index 606739c8766..65be7fef7b1 100644 --- a/src/PIL/PalmImagePlugin.py +++ b/src/PIL/PalmImagePlugin.py @@ -6,6 +6,7 @@ ## # Image plugin for Palm pixmap images (output only). ## +from __future__ import annotations from . import Image, ImageFile from ._binary import o8 diff --git a/src/PIL/PcdImagePlugin.py b/src/PIL/PcdImagePlugin.py index c7cbca8c5d7..a0515b302eb 100644 --- a/src/PIL/PcdImagePlugin.py +++ b/src/PIL/PcdImagePlugin.py @@ -13,7 +13,7 @@ # # See the README file for information on usage and redistribution. # - +from __future__ import annotations from . import Image, ImageFile diff --git a/src/PIL/PcfFontFile.py b/src/PIL/PcfFontFile.py index 8b0014f3a02..d602a163349 100644 --- a/src/PIL/PcfFontFile.py +++ b/src/PIL/PcfFontFile.py @@ -15,6 +15,7 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations import io diff --git a/src/PIL/PcxImagePlugin.py b/src/PIL/PcxImagePlugin.py index 67990b0adc1..98ecefd0514 100644 --- a/src/PIL/PcxImagePlugin.py +++ b/src/PIL/PcxImagePlugin.py @@ -24,6 +24,7 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations import io import logging diff --git a/src/PIL/PdfImagePlugin.py b/src/PIL/PdfImagePlugin.py index b6bb60911aa..3506aadce83 100644 --- a/src/PIL/PdfImagePlugin.py +++ b/src/PIL/PdfImagePlugin.py @@ -19,6 +19,7 @@ ## # Image plugin for PDF images (output only). ## +from __future__ import annotations import io import math diff --git a/src/PIL/PdfParser.py b/src/PIL/PdfParser.py index 8bdb65cce23..0144600066f 100644 --- a/src/PIL/PdfParser.py +++ b/src/PIL/PdfParser.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import calendar import codecs import collections diff --git a/src/PIL/PixarImagePlugin.py b/src/PIL/PixarImagePlugin.py index 850272311de..af866feb362 100644 --- a/src/PIL/PixarImagePlugin.py +++ b/src/PIL/PixarImagePlugin.py @@ -18,6 +18,7 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations from . import Image, ImageFile from ._binary import i16le as i16 diff --git a/src/PIL/PngImagePlugin.py b/src/PIL/PngImagePlugin.py index dbcdee1c2d7..e4ed9388011 100644 --- a/src/PIL/PngImagePlugin.py +++ b/src/PIL/PngImagePlugin.py @@ -30,6 +30,7 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations import itertools import logging diff --git a/src/PIL/PpmImagePlugin.py b/src/PIL/PpmImagePlugin.py index 93f1528c5c5..25dbfa5b0bc 100644 --- a/src/PIL/PpmImagePlugin.py +++ b/src/PIL/PpmImagePlugin.py @@ -13,7 +13,7 @@ # # See the README file for information on usage and redistribution. # - +from __future__ import annotations from . import Image, ImageFile from ._binary import i16be as i16 diff --git a/src/PIL/PsdImagePlugin.py b/src/PIL/PsdImagePlugin.py index 2f019bb8c34..5cff564137d 100644 --- a/src/PIL/PsdImagePlugin.py +++ b/src/PIL/PsdImagePlugin.py @@ -15,6 +15,7 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations import io @@ -186,6 +187,9 @@ def read(size): ct_types = i16(read(2)) types = list(range(ct_types)) if len(types) > 4: + fp.seek(len(types) * 6 + 12, io.SEEK_CUR) + size = i32(read(4)) + fp.seek(size, io.SEEK_CUR) continue for _ in types: diff --git a/src/PIL/PyAccess.py b/src/PIL/PyAccess.py index 24d30d2a6eb..23ff154f6cc 100644 --- a/src/PIL/PyAccess.py +++ b/src/PIL/PyAccess.py @@ -18,6 +18,7 @@ # * Fill.c uses the integer form, but it's still going to use the old # Access.c implementation. # +from __future__ import annotations import logging import sys diff --git a/src/PIL/QoiImagePlugin.py b/src/PIL/QoiImagePlugin.py index 66344faac58..a7b9d4a9e3a 100644 --- a/src/PIL/QoiImagePlugin.py +++ b/src/PIL/QoiImagePlugin.py @@ -5,6 +5,7 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations import os diff --git a/src/PIL/SgiImagePlugin.py b/src/PIL/SgiImagePlugin.py index a2a259c890e..f9a10f6109c 100644 --- a/src/PIL/SgiImagePlugin.py +++ b/src/PIL/SgiImagePlugin.py @@ -20,7 +20,7 @@ # # See the README file for information on usage and redistribution. # - +from __future__ import annotations import os import struct diff --git a/src/PIL/SpiderImagePlugin.py b/src/PIL/SpiderImagePlugin.py index 14cad8f9ad6..86582fb128c 100644 --- a/src/PIL/SpiderImagePlugin.py +++ b/src/PIL/SpiderImagePlugin.py @@ -32,6 +32,8 @@ # Details about the Spider image format: # https://spider.wadsworth.org/spider_doc/spider/docs/image_doc.html # +from __future__ import annotations + import os import struct import sys diff --git a/src/PIL/SunImagePlugin.py b/src/PIL/SunImagePlugin.py index 6a8d5d86b73..11ce3dfefd0 100644 --- a/src/PIL/SunImagePlugin.py +++ b/src/PIL/SunImagePlugin.py @@ -15,7 +15,7 @@ # # See the README file for information on usage and redistribution. # - +from __future__ import annotations from . import Image, ImageFile, ImagePalette from ._binary import i32be as i32 diff --git a/src/PIL/TarIO.py b/src/PIL/TarIO.py index 32928f6af30..26522d93f79 100644 --- a/src/PIL/TarIO.py +++ b/src/PIL/TarIO.py @@ -13,6 +13,7 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations import io diff --git a/src/PIL/TgaImagePlugin.py b/src/PIL/TgaImagePlugin.py index f24ee4f5c31..65c7484f756 100644 --- a/src/PIL/TgaImagePlugin.py +++ b/src/PIL/TgaImagePlugin.py @@ -15,7 +15,7 @@ # # See the README file for information on usage and redistribution. # - +from __future__ import annotations import warnings diff --git a/src/PIL/TiffImagePlugin.py b/src/PIL/TiffImagePlugin.py index a78a5aef1bc..fc242ca64c2 100644 --- a/src/PIL/TiffImagePlugin.py +++ b/src/PIL/TiffImagePlugin.py @@ -38,6 +38,8 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations + import io import itertools import logging diff --git a/src/PIL/TiffTags.py b/src/PIL/TiffTags.py index b02c637b6f5..88ff2f4fcd5 100644 --- a/src/PIL/TiffTags.py +++ b/src/PIL/TiffTags.py @@ -16,6 +16,7 @@ # This module provides constants and clear-text names for various # well-known TIFF tags. ## +from __future__ import annotations from collections import namedtuple diff --git a/src/PIL/WalImageFile.py b/src/PIL/WalImageFile.py index 3d9f97f8485..c5bf3e04cf7 100644 --- a/src/PIL/WalImageFile.py +++ b/src/PIL/WalImageFile.py @@ -22,6 +22,7 @@ is not registered for use with :py:func:`PIL.Image.open()`. To open a WAL file, use the :py:func:`PIL.WalImageFile.open()` function instead. """ +from __future__ import annotations from . import Image, ImageFile from ._binary import i32le as i32 diff --git a/src/PIL/WebPImagePlugin.py b/src/PIL/WebPImagePlugin.py index 612fc09467a..59556206a3c 100644 --- a/src/PIL/WebPImagePlugin.py +++ b/src/PIL/WebPImagePlugin.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from io import BytesIO from . import Image, ImageFile @@ -168,6 +170,9 @@ def load(self): return super().load() + def load_seek(self, pos): + pass + def tell(self): if not _webp.HAVE_WEBPANIM: return super().tell() diff --git a/src/PIL/WmfImagePlugin.py b/src/PIL/WmfImagePlugin.py index 3e5fb01512d..b5b8c69b171 100644 --- a/src/PIL/WmfImagePlugin.py +++ b/src/PIL/WmfImagePlugin.py @@ -18,6 +18,7 @@ # https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-WMF/[MS-WMF].pdf # http://wvware.sourceforge.net/caolan/index.html # http://wvware.sourceforge.net/caolan/ora-wmf.html +from __future__ import annotations from . import Image, ImageFile from ._binary import i16le as word diff --git a/src/PIL/XVThumbImagePlugin.py b/src/PIL/XVThumbImagePlugin.py index eda60c5c5ca..47ba1c54803 100644 --- a/src/PIL/XVThumbImagePlugin.py +++ b/src/PIL/XVThumbImagePlugin.py @@ -16,6 +16,7 @@ # To do: # FIXME: make save work (this requires quantization support) # +from __future__ import annotations from . import Image, ImageFile, ImagePalette from ._binary import o8 diff --git a/src/PIL/XbmImagePlugin.py b/src/PIL/XbmImagePlugin.py index 71cd57d74da..566acbfe5af 100644 --- a/src/PIL/XbmImagePlugin.py +++ b/src/PIL/XbmImagePlugin.py @@ -18,6 +18,7 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations import re diff --git a/src/PIL/XpmImagePlugin.py b/src/PIL/XpmImagePlugin.py index 8491d3b7e92..bf73c9bef06 100644 --- a/src/PIL/XpmImagePlugin.py +++ b/src/PIL/XpmImagePlugin.py @@ -13,7 +13,7 @@ # # See the README file for information on usage and redistribution. # - +from __future__ import annotations import re diff --git a/src/PIL/__init__.py b/src/PIL/__init__.py index 2bb8f6d7f10..3fcac8643cb 100644 --- a/src/PIL/__init__.py +++ b/src/PIL/__init__.py @@ -12,6 +12,7 @@ ;-) """ +from __future__ import annotations from . import _version diff --git a/src/PIL/__main__.py b/src/PIL/__main__.py index a05323f93b6..943789923dc 100644 --- a/src/PIL/__main__.py +++ b/src/PIL/__main__.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from .features import pilinfo pilinfo() diff --git a/src/PIL/_binary.py b/src/PIL/_binary.py index a74ee9eb6f3..c60c9cec1b7 100644 --- a/src/PIL/_binary.py +++ b/src/PIL/_binary.py @@ -13,7 +13,7 @@ """Binary input/output support routines.""" - +from __future__ import annotations from struct import pack, unpack_from diff --git a/src/PIL/_tkinter_finder.py b/src/PIL/_tkinter_finder.py index 597c21b5e38..03a6eba44ff 100644 --- a/src/PIL/_tkinter_finder.py +++ b/src/PIL/_tkinter_finder.py @@ -1,5 +1,7 @@ """ Find compiled module linking to Tcl / Tk libraries """ +from __future__ import annotations + import sys import tkinter from tkinter import _tkinter as tk diff --git a/src/PIL/_util.py b/src/PIL/_util.py index ba27b7e49e9..4634d335bba 100644 --- a/src/PIL/_util.py +++ b/src/PIL/_util.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import os from pathlib import Path diff --git a/src/PIL/_version.py b/src/PIL/_version.py index 279b6e2289a..7d994caf4d7 100644 --- a/src/PIL/_version.py +++ b/src/PIL/_version.py @@ -1,2 +1,4 @@ # Master version for Pillow +from __future__ import annotations + __version__ = "10.2.0.dev0" diff --git a/src/PIL/features.py b/src/PIL/features.py index f14e60cf5d4..b14d6df13f2 100644 --- a/src/PIL/features.py +++ b/src/PIL/features.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import collections import os import sys diff --git a/src/_imagingft.c b/src/_imagingft.c index 7849c821d0c..68c66ac2c60 100644 --- a/src/_imagingft.c +++ b/src/_imagingft.c @@ -877,7 +877,7 @@ font_render(FontObject *self, PyObject *args) { width += stroke_width * 2 + ceil(x_start); height += stroke_width * 2 + ceil(y_start); - image = PyObject_CallFunction(fill, "s(ii)", strcmp(mode, "RGBA") == 0 ? "RGBA" : "L", width, height); + image = PyObject_CallFunction(fill, "ii", width, height); if (image == Py_None) { PyMem_Del(glyph_info); return Py_BuildValue("ii", 0, 0); @@ -1049,8 +1049,8 @@ font_render(FontObject *self, PyObject *args) { if (yy >= 0 && yy < im->ysize) { /* blend this glyph into the buffer */ int k; - unsigned char v; unsigned char *target; + unsigned int tmp; if (color) { /* target[RGB] returns the color, target[A] returns the mask */ /* target bands get split again in ImageDraw.text */ @@ -1061,34 +1061,55 @@ font_render(FontObject *self, PyObject *args) { if (color && bitmap.pixel_mode == FT_PIXEL_MODE_BGRA) { /* paste color glyph */ for (k = x0; k < x1; k++) { - if (target[k * 4 + 3] < source[k * 4 + 3]) { - /* unpremultiply BGRa to RGBA */ - target[k * 4 + 0] = CLIP8( - (255 * (int)source[k * 4 + 2]) / source[k * 4 + 3]); - target[k * 4 + 1] = CLIP8( - (255 * (int)source[k * 4 + 1]) / source[k * 4 + 3]); - target[k * 4 + 2] = CLIP8( - (255 * (int)source[k * 4 + 0]) / source[k * 4 + 3]); - target[k * 4 + 3] = source[k * 4 + 3]; + unsigned int src_alpha = source[k * 4 + 3]; + + /* paste only if source has data */ + if (src_alpha > 0) { + /* unpremultiply BGRa */ + int src_red = CLIP8((255 * (int)source[k * 4 + 2]) / src_alpha); + int src_green = CLIP8((255 * (int)source[k * 4 + 1]) / src_alpha); + int src_blue = CLIP8((255 * (int)source[k * 4 + 0]) / src_alpha); + + /* blend required if target has data */ + if (target[k * 4 + 3] > 0) { + /* blend RGBA colors */ + target[k * 4 + 0] = BLEND(src_alpha, target[k * 4 + 0], src_red, tmp); + target[k * 4 + 1] = BLEND(src_alpha, target[k * 4 + 1], src_green, tmp); + target[k * 4 + 2] = BLEND(src_alpha, target[k * 4 + 2], src_blue, tmp); + target[k * 4 + 3] = CLIP8(src_alpha + MULDIV255(target[k * 4 + 3], (255 - src_alpha), tmp)); + } else { + /* paste unpremultiplied RGBA values */ + target[k * 4 + 0] = src_red; + target[k * 4 + 1] = src_green; + target[k * 4 + 2] = src_blue; + target[k * 4 + 3] = src_alpha; + } } } } else if (bitmap.pixel_mode == FT_PIXEL_MODE_GRAY) { if (color) { unsigned char *ink = (unsigned char *)&foreground_ink; for (k = x0; k < x1; k++) { - v = source[k] * convert_scale; - if (target[k * 4 + 3] < v) { - target[k * 4 + 0] = ink[0]; - target[k * 4 + 1] = ink[1]; - target[k * 4 + 2] = ink[2]; - target[k * 4 + 3] = v; + unsigned int src_alpha = source[k] * convert_scale; + if (src_alpha > 0) { + if (target[k * 4 + 3] > 0) { + target[k * 4 + 0] = BLEND(src_alpha, target[k * 4 + 0], ink[0], tmp); + target[k * 4 + 1] = BLEND(src_alpha, target[k * 4 + 1], ink[1], tmp); + target[k * 4 + 2] = BLEND(src_alpha, target[k * 4 + 2], ink[2], tmp); + target[k * 4 + 3] = CLIP8(src_alpha + MULDIV255(target[k * 4 + 3], (255 - src_alpha), tmp)); + } else { + target[k * 4 + 0] = ink[0]; + target[k * 4 + 1] = ink[1]; + target[k * 4 + 2] = ink[2]; + target[k * 4 + 3] = src_alpha; + } } } } else { for (k = x0; k < x1; k++) { - v = source[k] * convert_scale; - if (target[k] < v) { - target[k] = v; + unsigned int src_alpha = source[k] * convert_scale; + if (src_alpha > 0) { + target[k] = target[k] > 0 ? CLIP8(src_alpha + MULDIV255(target[k], (255 - src_alpha), tmp)) : src_alpha; } } } diff --git a/tox.ini b/tox.ini index 5388ed2435b..034d893721b 100644 --- a/tox.ini +++ b/tox.ini @@ -29,3 +29,11 @@ pass_env = commands = pre-commit run --all-files --show-diff-on-failure check-manifest + +[testenv:mypy] +skip_install = true +deps = + mypy==1.7.1 + numpy +commands = + mypy src {posargs} diff --git a/winbuild/build_prepare.py b/winbuild/build_prepare.py index f7e145fb992..8e3757ca89e 100644 --- a/winbuild/build_prepare.py +++ b/winbuild/build_prepare.py @@ -56,7 +56,9 @@ def cmd_nmake( ) -def cmds_cmake(target: str | tuple[str, ...] | list[str], *params) -> list[str]: +def cmds_cmake( + target: str | tuple[str, ...] | list[str], *params, build_dir: str = "." +) -> list[str]: if not isinstance(target, str): target = " ".join(target) @@ -73,10 +75,11 @@ def cmds_cmake(target: str | tuple[str, ...] | list[str], *params) -> list[str]: "-DCMAKE_CXX_FLAGS=-nologo", *params, '-G "{cmake_generator}"', - ".", + f'-B "{build_dir}"', + "-S .", ] ), - f"{{cmake}} --build . --clean-first --parallel --target {target}", + f'{{cmake}} --build "{build_dir}" --clean-first --parallel --target {target}', ] @@ -367,7 +370,14 @@ def cmd_msbuild( "build": [ cmd_copy(r"COPYING", r"{bin_dir}\fribidi-1.0.13-COPYING"), cmd_copy(r"{winbuild_dir}\fribidi.cmake", r"CMakeLists.txt"), - *cmds_cmake("fribidi"), + # generated tab.i files cannot be cross-compiled + " ^&^& ".join( + [ + "if {architecture}==ARM64 cmd /c call {vcvarsall} x86", + *cmds_cmake("fribidi-gen", "-DARCH=x86", build_dir="build_x86"), + ] + ), + *cmds_cmake("fribidi", "-DARCH={architecture}"), ], "bins": [r"*.dll"], }, @@ -381,10 +391,9 @@ def find_msvs(architecture: str) -> dict[str, str] | None: print("Program Files not found") return None + requires = ["-requires", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64"] if architecture == "ARM64": - tools = "Microsoft.VisualStudio.Component.VC.Tools.ARM64" - else: - tools = "Microsoft.VisualStudio.Component.VC.Tools.x86.x64" + requires += ["-requires", "Microsoft.VisualStudio.Component.VC.Tools.ARM64"] try: vspath = ( @@ -395,8 +404,7 @@ def find_msvs(architecture: str) -> dict[str, str] | None: ), "-latest", "-prerelease", - "-requires", - tools, + *requires, "-property", "installationPath", "-products", @@ -707,11 +715,6 @@ def build_dep_all() -> None: disabled += ["libimagequant"] if args.no_fribidi: disabled += ["fribidi"] - elif args.architecture == "ARM64" and platform.machine() != "ARM64": - import warnings - - warnings.warn("Cross-compiling FriBiDi is currently not supported, disabling") - disabled += ["fribidi"] prefs = { "architecture": args.architecture, diff --git a/winbuild/fribidi.cmake b/winbuild/fribidi.cmake index 27b8d17a8ed..b16e0784c98 100644 --- a/winbuild/fribidi.cmake +++ b/winbuild/fribidi.cmake @@ -2,9 +2,9 @@ cmake_minimum_required(VERSION 3.12) project(fribidi) + add_definitions(-D_CRT_SECURE_NO_WARNINGS) -include_directories(${CMAKE_CURRENT_BINARY_DIR}) include_directories(lib) function(extract_regex_1 var text regex) @@ -27,12 +27,20 @@ function(fribidi_conf) set(PACKAGE_BUGREPORT "https://github.com/fribidi/fribidi/issues/new") set(SIZEOF_INT 4) set(FRIBIDI_MSVC_BUILD_PLACEHOLDER "#define FRIBIDI_BUILT_WITH_MSVC") - message("detected ${PACKAGE_NAME} version ${FRIBIDI_VERSION}") - configure_file(lib/fribidi-config.h.in lib/fribidi-config.h @ONLY) + message("Detected ${PACKAGE_NAME} version ${FRIBIDI_VERSION}") + configure_file(lib/fribidi-config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/lib/fribidi-config.h @ONLY) endfunction() fribidi_conf() +option(ARCH "Target architecture") +if(${ARCH} STREQUAL ARM64) + set(GEN FALSE) +else() + set(GEN TRUE) +endif() +message("Generate tab.i files: " ${GEN}) + function(prepend var prefix) set(out "") foreach(f ${ARGN}) @@ -56,18 +64,20 @@ macro(fribidi_definitions _TGT) endmacro() function(fribidi_gen _NAME _OUTNAME _PARAM) - set(_OUT lib/${_OUTNAME}) - prepend(_DEP "${CMAKE_CURRENT_SOURCE_DIR}/gen.tab/" ${ARGN}) - add_executable(gen-${_NAME} - gen.tab/gen-${_NAME}.c - gen.tab/packtab.c) - fribidi_definitions(gen-${_NAME}) - target_compile_definitions(gen-${_NAME} - PUBLIC DONT_HAVE_FRIBIDI_CONFIG_H) - add_custom_command( - COMMAND gen-${_NAME} ${_PARAM} ${_DEP} > ${_OUT} - DEPENDS ${_DEP} - OUTPUT ${_OUT}) + set(_OUT ${CMAKE_CURRENT_SOURCE_DIR}/lib/${_OUTNAME}) + if(GEN) + prepend(_DEP "${CMAKE_CURRENT_SOURCE_DIR}/gen.tab/" ${ARGN}) + add_executable(gen-${_NAME} + gen.tab/gen-${_NAME}.c + gen.tab/packtab.c) + fribidi_definitions(gen-${_NAME}) + target_compile_definitions(gen-${_NAME} + PUBLIC DONT_HAVE_FRIBIDI_CONFIG_H) + add_custom_command( + COMMAND gen-${_NAME} ${_PARAM} ${_DEP} > ${_OUT} + DEPENDS ${_DEP} + OUTPUT ${_OUT}) + endif(GEN) list(APPEND FRIBIDI_SOURCES_GENERATED "${_OUT}") set(FRIBIDI_SOURCES_GENERATED ${FRIBIDI_SOURCES_GENERATED} PARENT_SCOPE) endfunction() @@ -78,8 +88,10 @@ fribidi_gen(unicode-version fribidi-unicode-version.h "" macro(fribidi_tab _NAME) fribidi_gen(${_NAME}-tab ${_NAME}.tab.i 2 ${ARGN}) - target_sources(gen-${_NAME}-tab - PRIVATE lib/fribidi-unicode-version.h) + if(GEN) + target_sources(gen-${_NAME}-tab + PRIVATE lib/fribidi-unicode-version.h) + endif(GEN) endmacro() fribidi_tab(bidi-type unidata/UnicodeData.txt) @@ -89,14 +101,16 @@ fribidi_tab(mirroring unidata/BidiMirroring.txt) fribidi_tab(brackets unidata/BidiBrackets.txt unidata/UnicodeData.txt) fribidi_tab(brackets-type unidata/BidiBrackets.txt) +add_custom_target(fribidi-gen DEPENDS ${FRIBIDI_SOURCES_GENERATED}) + file(GLOB FRIBIDI_SOURCES lib/*.c) file(GLOB FRIBIDI_HEADERS lib/*.h) add_library(fribidi SHARED - ${FRIBIDI_SOURCES} - ${FRIBIDI_HEADERS} - ${FRIBIDI_SOURCES_GENERATED}) + ${FRIBIDI_SOURCES} + ${FRIBIDI_HEADERS} + ${FRIBIDI_SOURCES_GENERATED}) fribidi_definitions(fribidi) target_compile_definitions(fribidi - PUBLIC "-DFRIBIDI_BUILD") + PUBLIC "-DFRIBIDI_BUILD")