Skip to content

Commit

Permalink
If palette is present but not needed, do not use global palette
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Oct 5, 2022
1 parent ae6520c commit e6ffbfd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions Tests/test_file_gif.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ def test_l_mode_after_rgb():
assert im.mode == "RGB"


def test_palette_not_needed_for_second_frame():
with Image.open("Tests/images/palette_not_needed_for_second_frame.gif") as im:
im.seek(1)
assert_image_similar(im, hopper("L").convert("RGB"), 8)


def test_strategy():
with Image.open("Tests/images/chi.gif") as im:
expected_zero = im.convert("RGB")
Expand Down
4 changes: 3 additions & 1 deletion src/PIL/GifImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ def _seek(self, frame, update_image=True):
p = self.fp.read(3 << bits)
if self._is_palette_needed(p):
palette = ImagePalette.raw("RGB", p)
else:
palette = False

# image data
bits = self.fp.read(1)[0]
Expand All @@ -298,7 +300,7 @@ def _seek(self, frame, update_image=True):
if self.dispose:
self.im.paste(self.dispose, self.dispose_extent)

self._frame_palette = palette or self.global_palette
self._frame_palette = palette if palette is not None else self.global_palette
if frame == 0:
if self._frame_palette:
self.mode = (
Expand Down

0 comments on commit e6ffbfd

Please sign in to comment.