Skip to content

Commit

Permalink
Merge branch 'main' into xmp
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere authored Jun 18, 2024
2 parents eba2694 + b1d5d7f commit 7ab3aee
Show file tree
Hide file tree
Showing 100 changed files with 1,102 additions and 680 deletions.
6 changes: 3 additions & 3 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ install:
- curl -fsSL -o pillow-test-images.zip https://github.com/python-pillow/test-images/archive/main.zip
- 7z x pillow-test-images.zip -oc:\
- xcopy /S /Y c:\test-images-main\* c:\pillow\tests\images
- curl -fsSL -o nasm-win64.zip https://raw.githubusercontent.com/python-pillow/pillow-depends/main/nasm-2.16.01-win64.zip
- curl -fsSL -o nasm-win64.zip https://raw.githubusercontent.com/python-pillow/pillow-depends/main/nasm-2.16.03-win64.zip
- 7z x nasm-win64.zip -oc:\
- choco install ghostscript --version=10.3.0
- path c:\nasm-2.16.01;C:\Program Files\gs\gs10.00.0\bin;%PATH%
- choco install ghostscript --version=10.3.1
- path c:\nasm-2.16.03;C:\Program Files\gs\gs10.03.1\bin;%PATH%
- cd c:\pillow\winbuild\
- ps: |
c:\python38\python.exe c:\pillow\winbuild\build_prepare.py -v --depends=C:\pillow-depends\
Expand Down
2 changes: 1 addition & 1 deletion .ci/requirements-cibw.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cibuildwheel==2.18.1
cibuildwheel==2.19.1
6 changes: 5 additions & 1 deletion .github/workflows/macos-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ brew install \
ghostscript \
libimagequant \
libjpeg \
libraqm \
libtiff \
little-cms2 \
openjpeg \
webp
if [[ "$ImageOS" == "macos13" ]]; then
brew install --ignore-dependencies libraqm
else
brew install libraqm
fi
export PKG_CONFIG_PATH="/usr/local/opt/openblas/lib/pkgconfig"

# TODO Update condition when cffi supports 3.13
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:
choco install nasm --no-progress
echo "C:\Program Files\NASM" >> $env:GITHUB_PATH
choco install ghostscript --version=10.3.0 --no-progress
choco install ghostscript --version=10.3.1 --no-progress
echo "C:\Program Files\gs\gs10.00.0\bin" >> $env:GITHUB_PATH
# Install extra test images
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/wheels-dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ ARCHIVE_SDIR=pillow-depends-main

# Package versions for fresh source builds
FREETYPE_VERSION=2.13.2
HARFBUZZ_VERSION=8.4.0
HARFBUZZ_VERSION=8.5.0
LIBPNG_VERSION=1.6.43
JPEGTURBO_VERSION=3.0.2
JPEGTURBO_VERSION=3.0.3
OPENJPEG_VERSION=2.5.2
XZ_VERSION=5.4.5
TIFF_VERSION=4.6.0
Expand All @@ -33,9 +33,9 @@ if [[ -n "$IS_MACOS" ]] || [[ "$MB_ML_VER" != 2014 ]]; then
else
ZLIB_VERSION=1.2.8
fi
LIBWEBP_VERSION=1.3.2
LIBWEBP_VERSION=1.4.0
BZIP2_VERSION=1.0.8
LIBXCB_VERSION=1.16.1
LIBXCB_VERSION=1.17.0
BROTLI_VERSION=1.1.0

if [[ -n "$IS_MACOS" ]] && [[ "$CIBW_ARCHS" == "x86_64" ]]; then
Expand Down Expand Up @@ -70,7 +70,7 @@ function build {
fi
build_new_zlib

build_simple xcb-proto 1.16.0 https://xorg.freedesktop.org/archive/individual/proto
build_simple xcb-proto 1.17.0 https://xorg.freedesktop.org/archive/individual/proto
if [ -n "$IS_MACOS" ]; then
build_simple xorgproto 2024.1 https://www.x.org/pub/individual/proto
build_simple libXau 1.0.11 https://www.x.org/pub/individual/lib
Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2
formats: [pdf]

build:
os: ubuntu-22.04
os: ubuntu-lts-latest
tools:
python: "3"
jobs:
Expand Down
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ Changelog (Pillow)
10.4.0 (unreleased)
-------------------

- Accept 't' suffix for libtiff version #8126, #8129
[radarhere]

- Deprecate ImageDraw.getdraw hints parameter #8124
[radarhere, hugovk]

- Added ImageDraw circle() #8085
[void4, hugovk, radarhere]

Expand Down
1 change: 1 addition & 0 deletions Tests/bench_cffi_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def test_direct() -> None:
caccess = im.im.pixel_access(False)
access = PyAccess.new(im, False)

assert access is not None
assert caccess[(0, 0)] == access[(0, 0)]

print(f"Size: {im.width}x{im.height}")
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_decompression_bomb.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


class TestDecompressionBomb:
def teardown_method(self, method) -> None:
def teardown_method(self) -> None:
Image.MAX_IMAGE_PIXELS = ORIGINAL_LIMIT

def test_no_warning_small_file(self) -> None:
Expand Down
6 changes: 4 additions & 2 deletions Tests/test_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ def test(name: str, function: Callable[[str], str | None]) -> None:
assert function(name) == version
if name != "PIL":
if name == "zlib" and version is not None:
version = version.replace(".zlib-ng", "")
version = re.sub(".zlib-ng$", "", version)
elif name == "libtiff" and version is not None:
version = re.sub("t$", "", version)
assert version is None or re.search(r"\d+(\.\d+)*$", version)

for module in features.modules:
Expand Down Expand Up @@ -124,7 +126,7 @@ def test_unsupported_module() -> None:


@pytest.mark.parametrize("supported_formats", (True, False))
def test_pilinfo(supported_formats) -> None:
def test_pilinfo(supported_formats: bool) -> None:
buf = io.StringIO()
features.pilinfo(buf, supported_formats=supported_formats)
out = buf.getvalue()
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_file_bmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def test_load_dib() -> None:
(124, "g/pal8v5.bmp"),
),
)
def test_dib_header_size(header_size, path):
def test_dib_header_size(header_size: int, path: str) -> None:
image_path = "Tests/images/bmp/" + path
with open(image_path, "rb") as fp:
data = fp.read()[14:]
Expand Down
11 changes: 6 additions & 5 deletions Tests/test_file_bufrstub.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from __future__ import annotations

from pathlib import Path
from typing import IO

import pytest

from PIL import BufrStubImagePlugin, Image
from PIL import BufrStubImagePlugin, Image, ImageFile

from .helper import hopper

Expand Down Expand Up @@ -50,20 +51,20 @@ def test_save(tmp_path: Path) -> None:


def test_handler(tmp_path: Path) -> None:
class TestHandler:
class TestHandler(ImageFile.StubHandler):
opened = False
loaded = False
saved = False

def open(self, im) -> None:
def open(self, im: ImageFile.StubImageFile) -> None:
self.opened = True

def load(self, im):
def load(self, im: ImageFile.StubImageFile) -> Image.Image:
self.loaded = True
im.fp.close()
return Image.new("RGB", (1, 1))

def save(self, im, fp, filename) -> None:
def save(self, im: Image.Image, fp: IO[bytes], filename: str) -> None:
self.saved = True

handler = TestHandler()
Expand Down
9 changes: 6 additions & 3 deletions Tests/test_file_gif.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def test_closed_file() -> None:

def test_seek_after_close() -> None:
im = Image.open("Tests/images/iss634.gif")
assert isinstance(im, GifImagePlugin.GifImageFile)
im.load()
im.close()

Expand Down Expand Up @@ -377,7 +378,8 @@ def test_save_netpbm_bmp_mode(tmp_path: Path) -> None:
img = img.convert("RGB")

tempfile = str(tmp_path / "temp.gif")
GifImagePlugin._save_netpbm(img, 0, tempfile)
b = BytesIO()
GifImagePlugin._save_netpbm(img, b, tempfile)
with Image.open(tempfile) as reloaded:
assert_image_similar(img, reloaded.convert("RGB"), 0)

Expand All @@ -388,7 +390,8 @@ def test_save_netpbm_l_mode(tmp_path: Path) -> None:
img = img.convert("L")

tempfile = str(tmp_path / "temp.gif")
GifImagePlugin._save_netpbm(img, 0, tempfile)
b = BytesIO()
GifImagePlugin._save_netpbm(img, b, tempfile)
with Image.open(tempfile) as reloaded:
assert_image_similar(img, reloaded.convert("L"), 0)

Expand Down Expand Up @@ -648,7 +651,7 @@ def test_dispose2_palette(tmp_path: Path) -> None:
assert rgb_img.getpixel((50, 50)) == circle

# Check that frame transparency wasn't added unnecessarily
assert img._frame_transparency is None
assert getattr(img, "_frame_transparency") is None


def test_dispose2_diff(tmp_path: Path) -> None:
Expand Down
4 changes: 2 additions & 2 deletions Tests/test_file_gribstub.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import pytest

from PIL import GribStubImagePlugin, Image
from PIL import GribStubImagePlugin, Image, ImageFile

from .helper import hopper

Expand Down Expand Up @@ -51,7 +51,7 @@ def test_save(tmp_path: Path) -> None:


def test_handler(tmp_path: Path) -> None:
class TestHandler:
class TestHandler(ImageFile.StubHandler):
opened = False
loaded = False
saved = False
Expand Down
7 changes: 4 additions & 3 deletions Tests/test_file_hdf5stub.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from __future__ import annotations

from io import BytesIO
from pathlib import Path
from typing import IO

import pytest

from PIL import Hdf5StubImagePlugin, Image
from PIL import Hdf5StubImagePlugin, Image, ImageFile

TEST_FILE = "Tests/images/hdf5.h5"

Expand Down Expand Up @@ -41,7 +42,7 @@ def test_load() -> None:
def test_save() -> None:
# Arrange
with Image.open(TEST_FILE) as im:
dummy_fp = None
dummy_fp = BytesIO()
dummy_filename = "dummy.filename"

# Act / Assert: stub cannot save without an implemented handler
Expand All @@ -52,7 +53,7 @@ def test_save() -> None:


def test_handler(tmp_path: Path) -> None:
class TestHandler:
class TestHandler(ImageFile.StubHandler):
opened = False
loaded = False
saved = False
Expand Down
21 changes: 12 additions & 9 deletions Tests/test_file_jpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def getchannels(im: JpegImagePlugin.JpegImageFile) -> tuple[int, int, int]:
[TEST_FILE, "Tests/images/pil_sample_cmyk.jpg"],
)
def test_dpi(self, test_image_path: str) -> None:
def test(xdpi: int, ydpi: int | None = None):
def test(xdpi: int, ydpi: int | None = None) -> tuple[int, int] | None:
with Image.open(test_image_path) as im:
im = self.roundtrip(im, dpi=(xdpi, ydpi or xdpi))
return im.info.get("dpi")
Expand Down Expand Up @@ -443,7 +443,9 @@ def test_smooth(self) -> None:
assert_image(im1, im2.mode, im2.size)

def test_subsampling(self) -> None:
def getsampling(im: JpegImagePlugin.JpegImageFile):
def getsampling(
im: JpegImagePlugin.JpegImageFile,
) -> tuple[int, int, int, int, int, int]:
layer = im.layer
return layer[0][1:3] + layer[1][1:3] + layer[2][1:3]

Expand Down Expand Up @@ -699,7 +701,7 @@ def test_load_djpeg(self) -> None:
def test_save_cjpeg(self, tmp_path: Path) -> None:
with Image.open(TEST_FILE) as img:
tempfile = str(tmp_path / "temp.jpg")
JpegImagePlugin._save_cjpeg(img, 0, tempfile)
JpegImagePlugin._save_cjpeg(img, BytesIO(), tempfile)
# Default save quality is 75%, so a tiny bit of difference is alright
assert_image_similar_tofile(img, tempfile, 17)

Expand Down Expand Up @@ -917,24 +919,25 @@ def test_icc_after_SOF(self) -> None:
with Image.open("Tests/images/icc-after-SOF.jpg") as im:
assert im.info["icc_profile"] == b"profile"

def test_jpeg_magic_number(self) -> None:
def test_jpeg_magic_number(self, monkeypatch: pytest.MonkeyPatch) -> None:
size = 4097
buffer = BytesIO(b"\xFF" * size) # Many xFF bytes
buffer.max_pos = 0
max_pos = 0
orig_read = buffer.read

def read(n=-1):
def read(n: int | None = -1) -> bytes:
nonlocal max_pos
res = orig_read(n)
buffer.max_pos = max(buffer.max_pos, buffer.tell())
max_pos = max(max_pos, buffer.tell())
return res

buffer.read = read
monkeypatch.setattr(buffer, "read", read)
with pytest.raises(UnidentifiedImageError):
with Image.open(buffer):
pass

# Assert the entire file has not been read
assert 0 < buffer.max_pos < size
assert 0 < max_pos < size

def test_getxmp(self) -> None:
with Image.open("Tests/images/xmp_test.jpg") as im:
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_file_jpeg2k.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def test_plt_marker() -> None:
out.seek(length - 2, os.SEEK_CUR)


def test_9bit():
def test_9bit() -> None:
with Image.open("Tests/images/9bit.j2k") as im:
assert im.mode == "I;16"
assert im.size == (128, 128)
2 changes: 1 addition & 1 deletion Tests/test_file_libtiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class TestFileLibTiff(LibTiffTestCase):
def test_version(self) -> None:
version = features.version_codec("libtiff")
assert version is not None
assert re.search(r"\d+\.\d+\.\d+$", version)
assert re.search(r"\d+\.\d+\.\d+t?$", version)

def test_g4_tiff(self, tmp_path: Path) -> None:
"""Test the ordinary file path load path"""
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_file_tiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def test_bigtiff(self, tmp_path: Path) -> None:
outfile = str(tmp_path / "temp.tif")
im.save(outfile, save_all=True, append_images=[im], tiffinfo=im.tag_v2)

def test_seek_too_large(self):
def test_seek_too_large(self) -> None:
with pytest.raises(ValueError, match="Unable to seek to frame"):
Image.open("Tests/images/seek_too_large.tif")

Expand Down
4 changes: 3 additions & 1 deletion Tests/test_file_webp.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ def test_file_pointer_could_be_reused(self) -> None:
(0, (0,), (-1, 0, 1, 2), (253, 254, 255, 256)),
)
@skip_unless_feature("webp_anim")
def test_invalid_background(self, background, tmp_path: Path) -> None:
def test_invalid_background(
self, background: int | tuple[int, ...], tmp_path: Path
) -> None:
temp_file = str(tmp_path / "temp.webp")
im = hopper()
with pytest.raises(OSError):
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_file_webp_animated.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_write_animation_RGB(tmp_path: Path) -> None:
are visually similar to the originals.
"""

def check(temp_file) -> None:
def check(temp_file: str) -> None:
with Image.open(temp_file) as im:
assert im.n_frames == 2

Expand Down
Loading

0 comments on commit 7ab3aee

Please sign in to comment.