Skip to content

Commit

Permalink
Merge branch 'main' into multiline_centered_embedded_color
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Sep 16, 2022
2 parents 18bd77b + 964e0aa commit 166654d
Show file tree
Hide file tree
Showing 38 changed files with 1,419 additions and 1,284 deletions.
3 changes: 1 addition & 2 deletions .ci/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ python3 -m pip install -U pytest-timeout
python3 -m pip install pyroma

if [[ $(uname) != CYGWIN* ]]; then
# TODO Remove condition when NumPy supports 3.11
if ! [ "$GHA_PYTHON_VERSION" == "3.11-dev" ]; then python3 -m pip install numpy ; fi
python3 -m pip install numpy

# PyQt6 doesn't support PyPy3
if [[ $GHA_PYTHON_VERSION == 3.* ]]; then
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/cifuzz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ on:
- "**.h"
workflow_dispatch:

permissions:
contents: read

jobs:
Fuzzing:
runs-on: ubuntu-latest
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/macos-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ python3 -m pip install -U pytest-timeout
python3 -m pip install pyroma

echo -e "[openblas]\nlibraries = openblas\nlibrary_dirs = /usr/local/opt/openblas/lib" >> ~/.numpy-site.cfg
# TODO Remove condition when NumPy supports 3.11
if ! [ "$GHA_PYTHON_VERSION" == "3.11-dev" ]; then python3 -m pip install numpy ; fi
python3 -m pip install numpy

# extra test images
pushd depends && ./install_extra_test_images.sh && popd
3 changes: 3 additions & 0 deletions .github/workflows/test-cygwin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: Test Cygwin

on: [push, pull_request, workflow_dispatch]

permissions:
contents: read

jobs:
build:
runs-on: windows-latest
Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/psf/black
rev: 22.6.0
rev: 22.8.0
hooks:
- id: black
args: ["--target-version", "py37"]
Expand All @@ -14,18 +14,18 @@ repos:
- id: isort

- repo: https://github.com/asottile/yesqa
rev: v1.3.0
rev: v1.4.0
hooks:
- id: yesqa

- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.3.0
rev: v1.3.1
hooks:
- id: remove-tabs
exclude: (Makefile$|\.bat$|\.cmake$|\.eps$|\.fits$|\.opt$)

- repo: https://github.com/PyCQA/flake8
rev: 5.0.2
rev: 5.0.4
hooks:
- id: flake8
additional_dependencies: [flake8-2020, flake8-implicit-str-concat]
Expand Down
30 changes: 30 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,36 @@ Changelog (Pillow)
9.3.0 (unreleased)
------------------

- Corrected BMP and TGA palette size when saving #6500
[radarhere]

- Do not call load() before draft() in Image.thumbnail #6539
[radarhere]

- Copy palette when converting from P to PA #6497
[radarhere]

- Allow RGB and RGBA values for PA image putpixel #6504
[radarhere]

- Removed support for tkinter in PyPy before Python 3.6 #6551
[nulano]

- Do not use CCITTFaxDecode filter if libtiff is not available #6518
[radarhere]

- Fallback to not using mmap if buffer is not large enough #6510
[radarhere]

- Fixed writing bytes as ASCII tag #6493
[radarhere]

- Open 1 bit EPS in mode 1 #6499
[radarhere]

- Removed support for tkinter before Python 1.5.2 #6549
[radarhere]

- Allow default ImageDraw font to be set #6484
[radarhere, hugovk]

Expand Down
Binary file added Tests/images/1.eps
Binary file not shown.
Binary file added Tests/images/mmap_error.bmp
Binary file not shown.
19 changes: 19 additions & 0 deletions Tests/test_file_bmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ def test_invalid_file():
BmpImagePlugin.BmpImageFile(fp)


def test_fallback_if_mmap_errors():
# This image has been truncated,
# so that the buffer is not large enough when using mmap
with Image.open("Tests/images/mmap_error.bmp") as im:
assert_image_equal_tofile(im, "Tests/images/pal8_offset.bmp")


def test_save_to_bytes():
output = io.BytesIO()
im = hopper()
Expand All @@ -51,6 +58,18 @@ def test_save_to_bytes():
assert reloaded.format == "BMP"


def test_small_palette(tmp_path):
im = Image.new("P", (1, 1))
colors = [0, 0, 0, 125, 125, 125, 255, 255, 255]
im.putpalette(colors)

out = str(tmp_path / "temp.bmp")
im.save(out)

with Image.open(out) as reloaded:
assert reloaded.getpalette() == colors


def test_save_too_large(tmp_path):
outfile = str(tmp_path / "temp.bmp")
with Image.new("RGB", (1, 1)) as im:
Expand Down
5 changes: 5 additions & 0 deletions Tests/test_file_eps.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ def test_bytesio_object():
assert_image_similar(img, image1_scale1_compare, 5)


def test_1_mode():
with Image.open("Tests/images/1.eps") as im:
assert im.mode == "1"


def test_image_mode_not_supported(tmp_path):
im = hopper("RGBA")
tmpfile = str(tmp_path / "temp.eps")
Expand Down
4 changes: 2 additions & 2 deletions Tests/test_file_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import pytest

from PIL import Image, PdfParser
from PIL import Image, PdfParser, features

from .helper import hopper, mark_if_feature_version

Expand Down Expand Up @@ -44,7 +44,7 @@ def test_monochrome(tmp_path):

# Act / Assert
outfile = helper_save_as_pdf(tmp_path, mode)
assert os.path.getsize(outfile) < 5000
assert os.path.getsize(outfile) < (5000 if features.check("libtiff") else 15000)


def test_greyscale(tmp_path):
Expand Down
12 changes: 12 additions & 0 deletions Tests/test_file_tga.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ def test_save(tmp_path):
assert test_im.size == (100, 100)


def test_small_palette(tmp_path):
im = Image.new("P", (1, 1))
colors = [0, 0, 0]
im.putpalette(colors)

out = str(tmp_path / "temp.tga")
im.save(out)

with Image.open(out) as reloaded:
assert reloaded.getpalette() == colors


def test_save_wrong_mode(tmp_path):
im = hopper("PA")
out = str(tmp_path / "temp.tga")
Expand Down
16 changes: 16 additions & 0 deletions Tests/test_file_tiff_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,22 @@ def test_iptc(tmp_path):
im.save(out)


def test_writing_bytes_to_ascii(tmp_path):
im = hopper()
info = TiffImagePlugin.ImageFileDirectory_v2()

tag = TiffTags.TAGS_V2[271]
assert tag.type == TiffTags.ASCII

info[271] = b"test"

out = str(tmp_path / "temp.tiff")
im.save(out, tiffinfo=info)

with Image.open(out) as reloaded:
assert reloaded.tag_v2[271] == "test"


def test_undefined_zero(tmp_path):
# Check that the tag has not been changed since this test was created
tag = TiffTags.TAGS_V2[45059]
Expand Down
20 changes: 13 additions & 7 deletions Tests/test_image_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,14 @@ def test_signedness(self, mode):
self.check(mode, 2**15 + 1)
self.check(mode, 2**16 - 1)

@pytest.mark.parametrize("mode", ("P", "PA"))
@pytest.mark.parametrize("color", ((255, 0, 0), (255, 0, 0, 255)))
def test_p_putpixel_rgb_rgba(self, color):
im = Image.new("P", (1, 1), 0)
def test_p_putpixel_rgb_rgba(self, mode, color):
im = Image.new(mode, (1, 1))
im.putpixel((0, 0), color)
assert im.convert("RGB").getpixel((0, 0)) == (255, 0, 0)

alpha = color[3] if len(color) == 4 and mode == "PA" else 255
assert im.convert("RGBA").getpixel((0, 0)) == (255, 0, 0, alpha)


@pytest.mark.skipif(cffi is None, reason="No CFFI")
Expand Down Expand Up @@ -340,12 +343,15 @@ def test_reference_counting(self):
# pixels can contain garbage if image is released
assert px[i, 0] == 0

def test_p_putpixel_rgb_rgba(self):
for color in [(255, 0, 0), (255, 0, 0, 255)]:
im = Image.new("P", (1, 1), 0)
@pytest.mark.parametrize("mode", ("P", "PA"))
def test_p_putpixel_rgb_rgba(self, mode):
for color in [(255, 0, 0), (255, 0, 0, 127)]:
im = Image.new(mode, (1, 1))
access = PyAccess.new(im, False)
access.putpixel((0, 0), color)
assert im.convert("RGB").getpixel((0, 0)) == (255, 0, 0)

alpha = color[3] if len(color) == 4 and mode == "PA" else 255
assert im.convert("RGBA").getpixel((0, 0)) == (255, 0, 0, alpha)


class TestImagePutPixelError(AccessTest):
Expand Down
6 changes: 6 additions & 0 deletions Tests/test_image_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,12 @@ def test_p2pa_alpha():
assert im_a.getpixel((x, y)) == alpha


def test_p2pa_palette():
with Image.open("Tests/images/tiny.png") as im:
im_pa = im.convert("PA")
assert im_pa.getpalette() == im.getpalette()


def test_matrix_illegal_conversion():
# Arrange
im = hopper("CMYK")
Expand Down
Loading

0 comments on commit 166654d

Please sign in to comment.