Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed seeking to an L frame in a GIF #6576

Merged
merged 3 commits into from
Oct 18, 2022
Merged

Conversation

radarhere
Copy link
Member

Resolves #6571

When pasting an L frame onto an RGB(A) GIF, convert the frame to RGB(A) first.

The test image was created using a modified Pillow, so that there is no global palette, and the image is comprised of a frame with a palette, and then two frames without. This means that the first frame is P mode, the second is L mode, combining to make RGB, and then there is an L mode frame pasted onto that RGB frame.

@radarhere radarhere added the GIF label Sep 13, 2022
@radarhere radarhere changed the title Fixed pasting an L frame onto an RGB(A) GIF Fixed seek to an L frame from an RGB(A) GIF Sep 13, 2022
@radarhere radarhere changed the title Fixed seek to an L frame from an RGB(A) GIF Fixed seeking to an L frame from an RGB(A) GIF Sep 13, 2022
@radarhere
Copy link
Member Author

I've added a commit to address #6610 (comment)

That comment found a GIF where on a later frame, the palette is "not needed" because the frame is grayscale. The problem is that Pillow then concludes that since there isn't a palette, it should fallback to the global palette.

if self._is_palette_needed(p):
palette = ImagePalette.raw("RGB", p)
# image data
bits = self.fp.read(1)[0]
self.__offset = self.fp.tell()
break
else:
pass
# raise OSError, "illegal GIF tag `%x`" % s[0]
s = None
if interlace is None:
# self._fp = None
raise EOFError
self.__frame = frame
if not update_image:
return
self.tile = []
if self.dispose:
self.im.paste(self.dispose, self.dispose_extent)
self._frame_palette = palette or self.global_palette

This is incorrect, as the frame is specifying custom palette behaviour, it's just that custom behaviour is to have a grayscale palette.

@radarhere radarhere changed the title Fixed seeking to an L frame from an RGB(A) GIF Fixed seeking to an L frame in a GIF Oct 5, 2022
@hugovk hugovk merged commit 745dc33 into python-pillow:main Oct 18, 2022
@radarhere radarhere deleted the gif branch October 18, 2022 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exception using "seek" on GIF that contains frames with different modes
2 participants