Skip to content

Commit 0b7fcbb

Browse files
authored
Merge branch 'master' into patch-2
2 parents b5d6a73 + b34430b commit 0b7fcbb

File tree

15 files changed

+124
-47
lines changed

15 files changed

+124
-47
lines changed

.github/workflows/test-windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
strategy:
99
fail-fast: false
1010
matrix:
11-
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10-dev"]
11+
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
1212
architecture: ["x86", "x64"]
1313
include:
1414
# PyPy3.6 only ships 32-bit binaries for Windows

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
python-version: [
1616
"pypy-3.7",
1717
"pypy-3.6",
18-
"3.10-dev",
18+
"3.10",
1919
"3.9",
2020
"3.8",
2121
"3.7",

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/psf/black
3-
rev: e3000ace2fd1fcb1c181bb7a8285f1f976bcbdc7 # frozen: 21.7b0
3+
rev: 911470a610e47d9da5ea938b0887c3df62819b85 # frozen: 21.9b0
44
hooks:
55
- id: black
66
args: ["--target-version", "py36"]
@@ -24,7 +24,7 @@ repos:
2424
- id: remove-tabs
2525
exclude: (Makefile$|\.bat$|\.cmake$|\.eps$|\.fits$|\.opt$)
2626

27-
- repo: https://gitlab.com/pycqa/flake8
27+
- repo: https://github.com/PyCQA/flake8
2828
rev: dcd740bc0ebaf2b3d43e59a0060d157c97de13f3 # frozen: 3.9.2
2929
hooks:
3030
- id: flake8

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ Changelog (Pillow)
55
8.4.0 (unreleased)
66
------------------
77

8+
- Prefer global transparency in GIF when replacing with background color #5756
9+
[radarhere]
10+
811
- Added "exif" keyword argument to TIFF saving #5575
912
[radarhere]
1013

5.48 KB
Loading

Tests/test_file_gif.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,13 @@ def test_dispose_background():
337337
pass
338338

339339

340+
def test_dispose_background_transparency():
341+
with Image.open("Tests/images/dispose_bgnd_transparency.gif") as img:
342+
img.seek(2)
343+
px = img.convert("RGBA").load()
344+
assert px[35, 30][3] == 0
345+
346+
340347
def test_transparent_dispose():
341348
expected_colors = [(2, 1, 2), (0, 1, 0), (2, 1, 2)]
342349
with Image.open("Tests/images/transparent_dispose.gif") as img:

Tests/test_file_libtiff.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,3 +999,10 @@ def test_save_single_strip(self, tmp_path):
999999
assert len(im.tag_v2[STRIPOFFSETS]) == 1
10001000
finally:
10011001
TiffImagePlugin.STRIP_SIZE = 65536
1002+
1003+
@pytest.mark.parametrize("compression", ("tiff_adobe_deflate", None))
1004+
def test_save_zero(self, compression, tmp_path):
1005+
im = Image.new("RGB", (0, 0))
1006+
out = str(tmp_path / "temp.tif")
1007+
with pytest.raises(SystemError):
1008+
im.save(out, compression=compression)

src/PIL/GifImagePlugin.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,9 @@ def _seek(self, frame):
271271
Image._decompression_bomb_check(dispose_size)
272272

273273
# by convention, attempt to use transparency first
274-
color = (
275-
frame_transparency
276-
if frame_transparency is not None
277-
else self.info.get("background", 0)
278-
)
274+
color = self.info.get("transparency", frame_transparency)
275+
if color is None:
276+
color = self.info.get("background", 0)
279277
self.dispose = Image.core.fill("P", dispose_size, color)
280278
else:
281279
# replace with previous contents

src/PIL/ImageShow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def get_command(self, file, **options):
133133

134134

135135
class MacViewer(Viewer):
136-
"""The default viewer on MacOS using ``Preview.app``."""
136+
"""The default viewer on macOS using ``Preview.app``."""
137137

138138
format = "PNG"
139139
options = {"compress_level": 1}

src/PIL/TiffImagePlugin.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,13 +1620,15 @@ def _save(im, fp, filename):
16201620
stride = len(bits) * ((im.size[0] * bits[0] + 7) // 8)
16211621
# aim for given strip size (64 KB by default) when using libtiff writer
16221622
if libtiff:
1623-
rows_per_strip = min(STRIP_SIZE // stride, im.size[1])
1623+
rows_per_strip = 1 if stride == 0 else min(STRIP_SIZE // stride, im.size[1])
16241624
# JPEG encoder expects multiple of 8 rows
16251625
if compression == "jpeg":
16261626
rows_per_strip = min(((rows_per_strip + 7) // 8) * 8, im.size[1])
16271627
else:
16281628
rows_per_strip = im.size[1]
1629-
strip_byte_counts = stride * rows_per_strip
1629+
if rows_per_strip == 0:
1630+
rows_per_strip = 1
1631+
strip_byte_counts = 1 if stride == 0 else stride * rows_per_strip
16301632
strips_per_image = (im.size[1] + rows_per_strip - 1) // rows_per_strip
16311633
ifd[ROWSPERSTRIP] = rows_per_strip
16321634
if strip_byte_counts >= 2 ** 16:

0 commit comments

Comments
 (0)