Skip to content

Commit

Permalink
Merge branch 'main' into libimagequant
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere authored Jan 31, 2024
2 parents feb47d9 + db43738 commit cb3b20a
Show file tree
Hide file tree
Showing 55 changed files with 238 additions and 185 deletions.
2 changes: 1 addition & 1 deletion .ci/requirements-cibw.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cibuildwheel==2.16.2
cibuildwheel==2.16.5
11 changes: 10 additions & 1 deletion .github/workflows/macos-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@

set -e

brew install libtiff libjpeg openjpeg libimagequant webp little-cms2 freetype libraqm
brew install \
freetype \
ghostscript \
libimagequant \
libjpeg \
libraqm \
libtiff \
little-cms2 \
openjpeg \
webp
export PKG_CONFIG_PATH="/usr/local/opt/openblas/lib/pkgconfig"

# TODO Update condition when cffi supports 3.13
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/test-cygwin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
uses: actions/checkout@v4

- name: Install Cygwin
uses: cygwin/cygwin-install-action@v4
uses: egor-tensin/setup-cygwin@v4
with:
platform: x86_64
packages: >
Expand All @@ -69,6 +69,7 @@ jobs:
make
netpbm
perl
python39=3.9.16-1
python3${{ matrix.python-minor-version }}-cffi
python3${{ matrix.python-minor-version }}-cython
python3${{ matrix.python-minor-version }}-devel
Expand All @@ -86,7 +87,7 @@ jobs:

- name: Select Python version
run: |
ln -sf c:/cygwin/bin/python3.${{ matrix.python-minor-version }} c:/cygwin/bin/python3
ln -sf c:/tools/cygwin/bin/python3.${{ matrix.python-minor-version }} c:/tools/cygwin/bin/python3
- name: Get latest NumPy version
id: latest-numpy
Expand Down
18 changes: 14 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
fail-fast: false
matrix:
os: [
"macos-latest",
"macos-14",
"ubuntu-latest",
]
python-version: [
Expand All @@ -50,11 +50,21 @@ jobs:
"3.8",
]
include:
- python-version: "3.9"
- python-version: "3.11"
PYTHONOPTIMIZE: 1
REVERSE: "--reverse"
- python-version: "3.8"
- python-version: "3.10"
PYTHONOPTIMIZE: 2
# M1 only available for 3.10+
- os: "macos-latest"
python-version: "3.9"
- os: "macos-latest"
python-version: "3.8"
exclude:
- os: "macos-14"
python-version: "3.9"
- os: "macos-14"
python-version: "3.8"

runs-on: ${{ matrix.os }}
name: ${{ matrix.os }} Python ${{ matrix.python-version }}
Expand Down Expand Up @@ -141,7 +151,7 @@ jobs:
- name: Upload coverage
uses: codecov/codecov-action@v3
with:
flags: ${{ matrix.os == 'macos-latest' && 'GHA_macOS' || 'GHA_Ubuntu' }}
flags: ${{ matrix.os == 'ubuntu-latest' && 'GHA_Ubuntu' || 'GHA_macOS' }}
name: ${{ matrix.os }} Python ${{ matrix.python-version }}
gcov: true

Expand Down
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ repos:
rev: v4.5.0
hooks:
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- id: check-merge-conflict
- id: check-json
- id: check-toml
Expand Down
1 change: 0 additions & 1 deletion Tests/check_fli_oob.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
from __future__ import annotations

from PIL import Image
Expand Down
2 changes: 0 additions & 2 deletions Tests/check_jp2_overflow.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env python3

# Reproductions/tests for OOB read errors in FliDecode.c

# When run in python, all of these images should fail for
Expand Down
2 changes: 0 additions & 2 deletions Tests/images/create_eps.gnuplot
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/gnuplot

#This is the script that was used to create our sample EPS files
#We used the following version of the gnuplot program
#G N U P L O T
Expand Down
2 changes: 0 additions & 2 deletions Tests/oss-fuzz/fuzz_pillow.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/python3

# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_000_sanity.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from PIL import Image


def test_sanity():
def test_sanity() -> None:
# Make sure we have the binary extension
Image.core.new("L", (100, 100))

Expand Down
6 changes: 3 additions & 3 deletions Tests/test_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
from PIL import _binary


def test_standard():
def test_standard() -> None:
assert _binary.i8(b"*") == 42
assert _binary.o8(42) == b"*"


def test_little_endian():
def test_little_endian() -> None:
assert _binary.i16le(b"\xff\xff\x00\x00") == 65535
assert _binary.i32le(b"\xff\xff\x00\x00") == 65535

assert _binary.o16le(65535) == b"\xff\xff"
assert _binary.o32le(65535) == b"\xff\xff\x00\x00"


def test_big_endian():
def test_big_endian() -> None:
assert _binary.i16be(b"\x00\x00\xff\xff") == 0
assert _binary.i32be(b"\x00\x00\xff\xff") == 65535

Expand Down
4 changes: 2 additions & 2 deletions Tests/test_file_cur.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
TEST_FILE = "Tests/images/deerstalker.cur"


def test_sanity():
def test_sanity() -> None:
with Image.open(TEST_FILE) as im:
assert im.size == (32, 32)
assert isinstance(im, CurImagePlugin.CurImageFile)
Expand All @@ -17,7 +17,7 @@ def test_sanity():
assert im.getpixel((16, 16)) == (84, 87, 86, 255)


def test_invalid_file():
def test_invalid_file() -> None:
invalid_file = "Tests/images/flower.jpg"

with pytest.raises(SyntaxError):
Expand Down
6 changes: 3 additions & 3 deletions Tests/test_file_ftex.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
from .helper import assert_image_equal_tofile, assert_image_similar


def test_load_raw():
def test_load_raw() -> None:
with Image.open("Tests/images/ftex_uncompressed.ftu") as im:
assert_image_equal_tofile(im, "Tests/images/ftex_uncompressed.png")


def test_load_dxt1():
def test_load_dxt1() -> None:
with Image.open("Tests/images/ftex_dxt1.ftc") as im:
with Image.open("Tests/images/ftex_dxt1.png") as target:
assert_image_similar(im, target.convert("RGBA"), 15)


def test_invalid_file():
def test_invalid_file() -> None:
invalid_file = "Tests/images/flower.jpg"

with pytest.raises(SyntaxError):
Expand Down
8 changes: 4 additions & 4 deletions Tests/test_file_gbr.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@
from .helper import assert_image_equal_tofile


def test_gbr_file():
def test_gbr_file() -> None:
with Image.open("Tests/images/gbr.gbr") as im:
assert_image_equal_tofile(im, "Tests/images/gbr.png")


def test_load():
def test_load() -> None:
with Image.open("Tests/images/gbr.gbr") as im:
assert im.load()[0, 0] == (0, 0, 0, 0)

# Test again now that it has already been loaded once
assert im.load()[0, 0] == (0, 0, 0, 0)


def test_multiple_load_operations():
def test_multiple_load_operations() -> None:
with Image.open("Tests/images/gbr.gbr") as im:
im.load()
im.load()
assert_image_equal_tofile(im, "Tests/images/gbr.png")


def test_invalid_file():
def test_invalid_file() -> None:
invalid_file = "Tests/images/flower.jpg"

with pytest.raises(SyntaxError):
Expand Down
6 changes: 3 additions & 3 deletions Tests/test_file_gd.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
TEST_GD_FILE = "Tests/images/hopper.gd"


def test_sanity():
def test_sanity() -> None:
with GdImageFile.open(TEST_GD_FILE) as im:
assert im.size == (128, 128)
assert im.format == "GD"


def test_bad_mode():
def test_bad_mode() -> None:
with pytest.raises(ValueError):
GdImageFile.open(TEST_GD_FILE, "bad mode")


def test_invalid_file():
def test_invalid_file() -> None:
invalid_file = "Tests/images/flower.jpg"

with pytest.raises(UnidentifiedImageError):
Expand Down
4 changes: 2 additions & 2 deletions Tests/test_file_gimppalette.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from PIL.GimpPaletteFile import GimpPaletteFile


def test_sanity():
def test_sanity() -> None:
with open("Tests/images/test.gpl", "rb") as fp:
GimpPaletteFile(fp)

Expand All @@ -22,7 +22,7 @@ def test_sanity():
GimpPaletteFile(fp)


def test_get_palette():
def test_get_palette() -> None:
# Arrange
with open("Tests/images/custom_gimp_palette.gpl", "rb") as fp:
palette_file = GimpPaletteFile(fp)
Expand Down
4 changes: 2 additions & 2 deletions Tests/test_file_imt.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
from .helper import assert_image_equal_tofile


def test_sanity():
def test_sanity() -> None:
with Image.open("Tests/images/bw_gradient.imt") as im:
assert_image_equal_tofile(im, "Tests/images/bw_gradient.png")


@pytest.mark.parametrize("data", (b"\n", b"\n-", b"width 1\n"))
def test_invalid_file(data):
def test_invalid_file(data: bytes) -> None:
with io.BytesIO(data) as fp:
with pytest.raises(SyntaxError):
ImtImagePlugin.ImtImageFile(fp)
4 changes: 2 additions & 2 deletions Tests/test_file_mcidas.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
from .helper import assert_image_equal_tofile


def test_invalid_file():
def test_invalid_file() -> None:
invalid_file = "Tests/images/flower.jpg"

with pytest.raises(SyntaxError):
McIdasImagePlugin.McIdasImageFile(invalid_file)


def test_valid_file():
def test_valid_file() -> None:
# Arrange
# https://ghrc.nsstc.nasa.gov/hydro/details/cmx3g8
# https://ghrc.nsstc.nasa.gov/pub/fieldCampaigns/camex3/cmx3g8/browse/
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_file_pcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from PIL import Image


def test_load_raw():
def test_load_raw() -> None:
with Image.open("Tests/images/hopper.pcd") as im:
im.load() # should not segfault.

Expand Down
4 changes: 2 additions & 2 deletions Tests/test_file_pixar.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
TEST_FILE = "Tests/images/hopper.pxr"


def test_sanity():
def test_sanity() -> None:
with Image.open(TEST_FILE) as im:
im.load()
assert im.mode == "RGB"
Expand All @@ -21,7 +21,7 @@ def test_sanity():
assert_image_similar(im, im2, 4.8)


def test_invalid_file():
def test_invalid_file() -> None:
invalid_file = "Tests/images/flower.jpg"

with pytest.raises(SyntaxError):
Expand Down
4 changes: 2 additions & 2 deletions Tests/test_file_qoi.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .helper import assert_image_equal_tofile


def test_sanity():
def test_sanity() -> None:
with Image.open("Tests/images/hopper.qoi") as im:
assert im.mode == "RGB"
assert im.size == (128, 128)
Expand All @@ -23,7 +23,7 @@ def test_sanity():
assert_image_equal_tofile(im, "Tests/images/pil123rgba.png")


def test_invalid_file():
def test_invalid_file() -> None:
invalid_file = "Tests/images/flower.jpg"

with pytest.raises(SyntaxError):
Expand Down
4 changes: 2 additions & 2 deletions Tests/test_file_wal.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
TEST_FILE = "Tests/images/hopper.wal"


def test_open():
def test_open() -> None:
with WalImageFile.open(TEST_FILE) as im:
assert im.format == "WAL"
assert im.format_description == "Quake2 Texture"
Expand All @@ -19,7 +19,7 @@ def test_open():
assert_image_equal_tofile(im, "Tests/images/hopper_wal.png")


def test_load():
def test_load() -> None:
with WalImageFile.open(TEST_FILE) as im:
assert im.load()[0, 0] == 122

Expand Down
4 changes: 3 additions & 1 deletion Tests/test_file_webp_lossless.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from pathlib import Path

import pytest

from PIL import Image
Expand All @@ -10,7 +12,7 @@
RGB_MODE = "RGB"


def test_write_lossless_rgb(tmp_path):
def test_write_lossless_rgb(tmp_path: Path) -> None:
if _webp.WebPDecoderVersion() < 0x0200:
pytest.skip("lossless not included")

Expand Down
Loading

0 comments on commit cb3b20a

Please sign in to comment.