mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 01:16:16 +03:00
Merge pull request #6576 from radarhere/gif
This commit is contained in:
commit
745dc33525
BIN
Tests/images/no_palette_after_rgb.gif
Normal file
BIN
Tests/images/no_palette_after_rgb.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 101 B |
BIN
Tests/images/palette_not_needed_for_second_frame.gif
Normal file
BIN
Tests/images/palette_not_needed_for_second_frame.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 28 KiB |
|
@ -83,6 +83,21 @@ def test_l_mode_transparency():
|
||||||
assert im.load()[0, 0] == 128
|
assert im.load()[0, 0] == 128
|
||||||
|
|
||||||
|
|
||||||
|
def test_l_mode_after_rgb():
|
||||||
|
with Image.open("Tests/images/no_palette_after_rgb.gif") as im:
|
||||||
|
im.seek(1)
|
||||||
|
assert im.mode == "RGB"
|
||||||
|
|
||||||
|
im.seek(2)
|
||||||
|
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():
|
def test_strategy():
|
||||||
with Image.open("Tests/images/iss634.gif") as im:
|
with Image.open("Tests/images/iss634.gif") as im:
|
||||||
expected_rgb_always = im.convert("RGB")
|
expected_rgb_always = im.convert("RGB")
|
||||||
|
|
|
@ -274,6 +274,8 @@ class GifImageFile(ImageFile.ImageFile):
|
||||||
p = self.fp.read(3 << bits)
|
p = self.fp.read(3 << bits)
|
||||||
if self._is_palette_needed(p):
|
if self._is_palette_needed(p):
|
||||||
palette = ImagePalette.raw("RGB", p)
|
palette = ImagePalette.raw("RGB", p)
|
||||||
|
else:
|
||||||
|
palette = False
|
||||||
|
|
||||||
# image data
|
# image data
|
||||||
bits = self.fp.read(1)[0]
|
bits = self.fp.read(1)[0]
|
||||||
|
@ -298,7 +300,7 @@ class GifImageFile(ImageFile.ImageFile):
|
||||||
if self.dispose:
|
if self.dispose:
|
||||||
self.im.paste(self.dispose, self.dispose_extent)
|
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
|
||||||
self._frame_transparency = frame_transparency
|
self._frame_transparency = frame_transparency
|
||||||
if frame == 0:
|
if frame == 0:
|
||||||
if self._frame_palette:
|
if self._frame_palette:
|
||||||
|
@ -438,16 +440,13 @@ class GifImageFile(ImageFile.ImageFile):
|
||||||
self.mode = "RGB"
|
self.mode = "RGB"
|
||||||
self.im = self.im.convert(self.mode, Image.Dither.FLOYDSTEINBERG)
|
self.im = self.im.convert(self.mode, Image.Dither.FLOYDSTEINBERG)
|
||||||
return
|
return
|
||||||
if self.mode == "P" and self._prev_im:
|
if not self._prev_im:
|
||||||
|
return
|
||||||
if self._frame_transparency is not None:
|
if self._frame_transparency is not None:
|
||||||
self.im.putpalettealpha(self._frame_transparency, 0)
|
self.im.putpalettealpha(self._frame_transparency, 0)
|
||||||
frame_im = self.im.convert("RGBA")
|
frame_im = self.im.convert("RGBA")
|
||||||
else:
|
else:
|
||||||
frame_im = self.im.convert("RGB")
|
frame_im = self.im.convert("RGB")
|
||||||
else:
|
|
||||||
if not self._prev_im:
|
|
||||||
return
|
|
||||||
frame_im = self.im
|
|
||||||
frame_im = self._crop(frame_im, self.dispose_extent)
|
frame_im = self._crop(frame_im, self.dispose_extent)
|
||||||
|
|
||||||
self.im = self._prev_im
|
self.im = self._prev_im
|
||||||
|
|
Loading…
Reference in New Issue
Block a user