Skip to content

Commit

Permalink
Merge branch 'main' into registered_extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Dec 21, 2022
2 parents 2a86d73 + fff0760 commit c6d1fdd
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:

steps:
- name: "Check issues"
uses: actions/stale@v6
uses: actions/stale@v7
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
only-labels: "Awaiting OP Action"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-cygwin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-minor-version: [7, 8, 9]
python-minor-version: [8, 9]

timeout-minutes: 40

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)
9.4.0 (unreleased)
------------------

- Ignore non-opaque WebP background when saving as GIF #6792
[radarhere]

- Only set tile in ImageFile __setstate__ #6793
[radarhere]

- When reading BLP, do not trust JPEG decoder to determine image is CMYK #6767
[radarhere]

Expand Down
13 changes: 11 additions & 2 deletions Tests/test_file_gif.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,14 +875,23 @@ def test_background(tmp_path):
im.info["background"] = 1
im.save(out)
with Image.open(out) as reread:

assert reread.info["background"] == im.info["background"]


def test_webp_background(tmp_path):
out = str(tmp_path / "temp.gif")

# Test opaque WebP background
if features.check("webp") and features.check("webp_anim"):
with Image.open("Tests/images/hopper.webp") as im:
assert isinstance(im.info["background"], tuple)
assert im.info["background"] == (255, 255, 255, 255)
im.save(out)

# Test non-opaque WebP background
im = Image.new("L", (100, 100), "#000")
im.info["background"] = (0, 0, 0, 0)
im.save(out)


def test_comment(tmp_path):
with Image.open(TEST_GIF) as im:
Expand Down
4 changes: 2 additions & 2 deletions Tests/test_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def to_image(dtype, bands=1, boolean=0):

# Check supported 1-bit integer formats
assert_image(to_image(bool, 1, 1), "1", TEST_IMAGE_SIZE)
assert_image(to_image(numpy.bool8, 1, 1), "1", TEST_IMAGE_SIZE)
assert_image(to_image(numpy.bool_, 1, 1), "1", TEST_IMAGE_SIZE)

# Check supported 8-bit integer formats
assert_image(to_image(numpy.uint8), "L", TEST_IMAGE_SIZE)
Expand Down Expand Up @@ -193,7 +193,7 @@ def test_putdata():
"dtype",
(
bool,
numpy.bool8,
numpy.bool_,
numpy.int8,
numpy.int16,
numpy.int32,
Expand Down
2 changes: 1 addition & 1 deletion docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ These platforms are built and tested for every change.
| +----------------------------+---------------------+
| | 3.9 (MinGW) | x86, x86-64 |
| +----------------------------+---------------------+
| | 3.7, 3.8, 3.9 (Cygwin) | x86-64 |
| | 3.8, 3.9 (Cygwin) | x86-64 |
+----------------------------------+----------------------------+---------------------+


Expand Down
15 changes: 9 additions & 6 deletions src/PIL/GifImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -886,20 +886,23 @@ def _get_palette_bytes(im):
def _get_background(im, info_background):
background = 0
if info_background:
background = info_background
if isinstance(background, tuple):
if isinstance(info_background, tuple):
# WebPImagePlugin stores an RGBA value in info["background"]
# So it must be converted to the same format as GifImagePlugin's
# info["background"] - a global color table index
try:
background = im.palette.getcolor(background, im)
background = im.palette.getcolor(info_background, im)
except ValueError as e:
if str(e) == "cannot allocate more than 256 colors":
if str(e) not in (
# If all 256 colors are in use,
# then there is no need for the background color
return 0
else:
"cannot allocate more than 256 colors",
# Ignore non-opaque WebP background
"cannot add non-opaque RGBA color to RGB palette",
):
raise
else:
background = info_background
return background


Expand Down
1 change: 0 additions & 1 deletion src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,6 @@ def __getstate__(self):

def __setstate__(self, state):
Image.__init__(self)
self.tile = []
info, mode, size, palette, data = state
self.info = info
self.mode = mode
Expand Down
4 changes: 4 additions & 0 deletions src/PIL/ImageFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ def get_format_mimetype(self):
if self.format is not None:
return Image.MIME.get(self.format.upper())

def __setstate__(self, state):
self.tile = []
super().__setstate__(state)

def verify(self):
"""Check file integrity"""

Expand Down
8 changes: 5 additions & 3 deletions src/PIL/PpmImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ def _decode_bitonal(self):
tokens = b"".join(block.split())
for token in tokens:
if token not in (48, 49):
raise ValueError(f"Invalid token for this mode: {bytes([token])}")
raise ValueError(
b"Invalid token for this mode: %s" % bytes([token])
)
data = (data + tokens)[:total_bytes]
invert = bytes.maketrans(b"01", b"\xFF\x00")
return data.translate(invert)
Expand Down Expand Up @@ -242,13 +244,13 @@ def _decode_blocks(self, maxval):
half_token = tokens.pop() # save half token for later
if len(half_token) > max_len: # prevent buildup of half_token
raise ValueError(
f"Token too long found in data: {half_token[:max_len + 1]}"
b"Token too long found in data: %s" % half_token[: max_len + 1]
)

for token in tokens:
if len(token) > max_len:
raise ValueError(
f"Token too long found in data: {token[:max_len + 1]}"
b"Token too long found in data: %s" % token[: max_len + 1]
)
value = int(token)
if value > maxval:
Expand Down
6 changes: 3 additions & 3 deletions winbuild/build_prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,9 @@ def cmd_msbuild(
"libs": [r"imagequant.lib"],
},
"harfbuzz": {
"url": "https://github.com/harfbuzz/harfbuzz/archive/5.3.1.zip",
"filename": "harfbuzz-5.3.1.zip",
"dir": "harfbuzz-5.3.1",
"url": "https://github.com/harfbuzz/harfbuzz/archive/6.0.0.zip",
"filename": "harfbuzz-6.0.0.zip",
"dir": "harfbuzz-6.0.0",
"license": "COPYING",
"build": [
cmd_set("CXXFLAGS", "-d2FH4-"),
Expand Down

0 comments on commit c6d1fdd

Please sign in to comment.