Skip to content

Do not update palette for L mode GIF frame #8924

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

radarhere
Copy link
Member

Resolves #8921

When a GIF frame doesn't have a global palette, and an individual frame has a palette where the colours sequentially move from (0, 0, 0) to (255, 255, 255), or even if the palette is less than 256 colours in length and still follows that progression, Pillow reads that as an L mode frame.

def _is_palette_needed(self, p: bytes) -> bool:
for i in range(0, len(p), 3):
if not (i // 3 == p[i] == p[i + 1] == p[i + 2]):
return True
return False

if self._is_palette_needed(p):
palette = ImagePalette.raw("RGB", p)
else:
palette = False

self._frame_palette = palette if palette is not None else self.global_palette

temp_mode = "P" if self._frame_palette else "L"

GIF frames may have transparency though, and

if self._frame_transparency is not None:
self.im.putpalettealpha(self._frame_transparency, 0)

is not able to accomodate an L mode frame with transparency.

This fixes that.

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.

ValueError: image has no palette when show GIF
1 participant