Skip to content

Commit

Permalink
Merge branch 'main' into vtf-support
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Aug 26, 2022
2 parents 0398b2c + ba98fe7 commit 1c7b86a
Show file tree
Hide file tree
Showing 38 changed files with 1,227 additions and 1,135 deletions.
1 change: 0 additions & 1 deletion .ci/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ python3 -m pip install -U pytest
python3 -m pip install -U pytest-cov
python3 -m pip install -U pytest-timeout
python3 -m pip install pyroma
python3 -m pip install test-image-results

if [[ $(uname) != CYGWIN* ]]; then
# TODO Remove condition when NumPy supports 3.11
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/macos-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ python3 -m pip install -U pytest
python3 -m pip install -U pytest-cov
python3 -m pip install -U pytest-timeout
python3 -m pip install pyroma
python3 -m pip install test-image-results

echo -e "[openblas]\nlibraries = openblas\nlibrary_dirs = /usr/local/opt/openblas/lib" >> ~/.numpy-site.cfg
# TODO Remove condition when NumPy supports 3.11
Expand Down
9 changes: 9 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ Changelog (Pillow)
9.3.0 (unreleased)
------------------

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

- Save 1 mode PDF using CCITTFaxDecode filter #6470
[radarhere]

- Added support for RGBA PSD images #6481
[radarhere]

- Parse orientation from XMP tag contents #6463
[bigcat88, radarhere]

Expand Down
Binary file added Tests/images/rgba.psd
Binary file not shown.
18 changes: 10 additions & 8 deletions Tests/test_file_apng.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,21 +325,23 @@ def open():
pytest.warns(UserWarning, open)


def test_apng_sequence_errors():
test_files = [
@pytest.mark.parametrize(
"test_file",
(
"sequence_start.png",
"sequence_gap.png",
"sequence_repeat.png",
"sequence_repeat_chunk.png",
"sequence_reorder.png",
"sequence_reorder_chunk.png",
"sequence_fdat_fctl.png",
]
for f in test_files:
with pytest.raises(SyntaxError):
with Image.open(f"Tests/images/apng/{f}") as im:
im.seek(im.n_frames - 1)
im.load()
),
)
def test_apng_sequence_errors(test_file):
with pytest.raises(SyntaxError):
with Image.open(f"Tests/images/apng/{test_file}") as im:
im.seek(im.n_frames - 1)
im.load()


def test_apng_save(tmp_path):
Expand Down
132 changes: 67 additions & 65 deletions Tests/test_file_container.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pytest

from PIL import ContainerIO, Image

from .helper import hopper
Expand Down Expand Up @@ -59,89 +61,89 @@ def test_seek_mode_2():
assert container.tell() == 100


def test_read_n0():
@pytest.mark.parametrize("bytesmode", (True, False))
def test_read_n0(bytesmode):
# Arrange
for bytesmode in (True, False):
with open(TEST_FILE, "rb" if bytesmode else "r") as fh:
container = ContainerIO.ContainerIO(fh, 22, 100)
with open(TEST_FILE, "rb" if bytesmode else "r") as fh:
container = ContainerIO.ContainerIO(fh, 22, 100)

# Act
container.seek(81)
data = container.read()
# Act
container.seek(81)
data = container.read()

# Assert
if bytesmode:
data = data.decode()
assert data == "7\nThis is line 8\n"
# Assert
if bytesmode:
data = data.decode()
assert data == "7\nThis is line 8\n"


def test_read_n():
@pytest.mark.parametrize("bytesmode", (True, False))
def test_read_n(bytesmode):
# Arrange
for bytesmode in (True, False):
with open(TEST_FILE, "rb" if bytesmode else "r") as fh:
container = ContainerIO.ContainerIO(fh, 22, 100)
with open(TEST_FILE, "rb" if bytesmode else "r") as fh:
container = ContainerIO.ContainerIO(fh, 22, 100)

# Act
container.seek(81)
data = container.read(3)
# Act
container.seek(81)
data = container.read(3)

# Assert
if bytesmode:
data = data.decode()
assert data == "7\nT"
# Assert
if bytesmode:
data = data.decode()
assert data == "7\nT"


def test_read_eof():
@pytest.mark.parametrize("bytesmode", (True, False))
def test_read_eof(bytesmode):
# Arrange
for bytesmode in (True, False):
with open(TEST_FILE, "rb" if bytesmode else "r") as fh:
container = ContainerIO.ContainerIO(fh, 22, 100)
with open(TEST_FILE, "rb" if bytesmode else "r") as fh:
container = ContainerIO.ContainerIO(fh, 22, 100)

# Act
container.seek(100)
data = container.read()
# Act
container.seek(100)
data = container.read()

# Assert
if bytesmode:
data = data.decode()
assert data == ""
# Assert
if bytesmode:
data = data.decode()
assert data == ""


def test_readline():
@pytest.mark.parametrize("bytesmode", (True, False))
def test_readline(bytesmode):
# Arrange
for bytesmode in (True, False):
with open(TEST_FILE, "rb" if bytesmode else "r") as fh:
container = ContainerIO.ContainerIO(fh, 0, 120)
with open(TEST_FILE, "rb" if bytesmode else "r") as fh:
container = ContainerIO.ContainerIO(fh, 0, 120)

# Act
data = container.readline()
# Act
data = container.readline()

# Assert
if bytesmode:
data = data.decode()
assert data == "This is line 1\n"
# Assert
if bytesmode:
data = data.decode()
assert data == "This is line 1\n"


def test_readlines():
@pytest.mark.parametrize("bytesmode", (True, False))
def test_readlines(bytesmode):
# Arrange
for bytesmode in (True, False):
expected = [
"This is line 1\n",
"This is line 2\n",
"This is line 3\n",
"This is line 4\n",
"This is line 5\n",
"This is line 6\n",
"This is line 7\n",
"This is line 8\n",
]
with open(TEST_FILE, "rb" if bytesmode else "r") as fh:
container = ContainerIO.ContainerIO(fh, 0, 120)

# Act
data = container.readlines()

# Assert
if bytesmode:
data = [line.decode() for line in data]
assert data == expected
expected = [
"This is line 1\n",
"This is line 2\n",
"This is line 3\n",
"This is line 4\n",
"This is line 5\n",
"This is line 6\n",
"This is line 7\n",
"This is line 8\n",
]
with open(TEST_FILE, "rb" if bytesmode else "r") as fh:
container = ContainerIO.ContainerIO(fh, 0, 120)

# Act
data = container.readlines()

# Assert
if bytesmode:
data = [line.decode() for line in data]
assert data == expected
15 changes: 6 additions & 9 deletions Tests/test_file_im.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,12 @@ def test_eoferror():
im.seek(n_frames - 1)


def test_roundtrip(tmp_path):
def roundtrip(mode):
out = str(tmp_path / "temp.im")
im = hopper(mode)
im.save(out)
assert_image_equal_tofile(im, out)

for mode in ["RGB", "P", "PA"]:
roundtrip(mode)
@pytest.mark.parametrize("mode", ("RGB", "P", "PA"))
def test_roundtrip(mode, tmp_path):
out = str(tmp_path / "temp.im")
im = hopper(mode)
im.save(out)
assert_image_equal_tofile(im, out)


def test_save_unsupported_mode(tmp_path):
Expand Down
94 changes: 49 additions & 45 deletions Tests/test_file_libtiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,50 +135,50 @@ def test_adobe_deflate_tiff(self):

assert_image_equal_tofile(im, "Tests/images/tiff_adobe_deflate.png")

def test_write_metadata(self, tmp_path):
@pytest.mark.parametrize("legacy_api", (False, True))
def test_write_metadata(self, legacy_api, tmp_path):
"""Test metadata writing through libtiff"""
for legacy_api in [False, True]:
f = str(tmp_path / "temp.tiff")
with Image.open("Tests/images/hopper_g4.tif") as img:
img.save(f, tiffinfo=img.tag)

if legacy_api:
original = img.tag.named()
else:
original = img.tag_v2.named()

# PhotometricInterpretation is set from SAVE_INFO,
# not the original image.
ignored = [
"StripByteCounts",
"RowsPerStrip",
"PageNumber",
"PhotometricInterpretation",
]

with Image.open(f) as loaded:
if legacy_api:
reloaded = loaded.tag.named()
else:
reloaded = loaded.tag_v2.named()

for tag, value in itertools.chain(reloaded.items(), original.items()):
if tag not in ignored:
val = original[tag]
if tag.endswith("Resolution"):
if legacy_api:
assert val[0][0] / val[0][1] == (
4294967295 / 113653537
), f"{tag} didn't roundtrip"
else:
assert val == 37.79000115940079, f"{tag} didn't roundtrip"
f = str(tmp_path / "temp.tiff")
with Image.open("Tests/images/hopper_g4.tif") as img:
img.save(f, tiffinfo=img.tag)

if legacy_api:
original = img.tag.named()
else:
original = img.tag_v2.named()

# PhotometricInterpretation is set from SAVE_INFO,
# not the original image.
ignored = [
"StripByteCounts",
"RowsPerStrip",
"PageNumber",
"PhotometricInterpretation",
]

with Image.open(f) as loaded:
if legacy_api:
reloaded = loaded.tag.named()
else:
reloaded = loaded.tag_v2.named()

for tag, value in itertools.chain(reloaded.items(), original.items()):
if tag not in ignored:
val = original[tag]
if tag.endswith("Resolution"):
if legacy_api:
assert val[0][0] / val[0][1] == (
4294967295 / 113653537
), f"{tag} didn't roundtrip"
else:
assert val == value, f"{tag} didn't roundtrip"
assert val == 37.79000115940079, f"{tag} didn't roundtrip"
else:
assert val == value, f"{tag} didn't roundtrip"

# https://github.com/python-pillow/Pillow/issues/1561
requested_fields = ["StripByteCounts", "RowsPerStrip", "StripOffsets"]
for field in requested_fields:
assert field in reloaded, f"{field} not in metadata"
# https://github.com/python-pillow/Pillow/issues/1561
requested_fields = ["StripByteCounts", "RowsPerStrip", "StripOffsets"]
for field in requested_fields:
assert field in reloaded, f"{field} not in metadata"

@pytest.mark.valgrind_known_error(reason="Known invalid metadata")
def test_additional_metadata(self, tmp_path):
Expand Down Expand Up @@ -1011,14 +1011,18 @@ def test_save_multistrip(self, compression, tmp_path):
# Assert that there are multiple strips
assert len(im.tag_v2[STRIPOFFSETS]) > 1

def test_save_single_strip(self, tmp_path):
@pytest.mark.parametrize("argument", (True, False))
def test_save_single_strip(self, argument, tmp_path):
im = hopper("RGB").resize((256, 256))
out = str(tmp_path / "temp.tif")

TiffImagePlugin.STRIP_SIZE = 2**18
if not argument:
TiffImagePlugin.STRIP_SIZE = 2**18
try:

im.save(out, compression="tiff_adobe_deflate")
arguments = {"compression": "tiff_adobe_deflate"}
if argument:
arguments["strip_size"] = 2**18
im.save(out, **arguments)

with Image.open(out) as im:
assert len(im.tag_v2[STRIPOFFSETS]) == 1
Expand Down
Loading

0 comments on commit 1c7b86a

Please sign in to comment.