Do not update palette for L mode GIF frame by radarhere · Pull Request #8924 · python-pillow/Pillow
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.