mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
Convert subsequent frames of L mode GIF to LA if transparency is present
This commit is contained in:
parent
37d28ce514
commit
5c6212052c
BIN
Tests/images/no_palette_with_transparency.gif
Normal file
BIN
Tests/images/no_palette_with_transparency.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 64 B |
|
@ -59,6 +59,17 @@ def test_invalid_file():
|
|||
GifImagePlugin.GifImageFile(invalid_file)
|
||||
|
||||
|
||||
def test_l_mode_transparency():
|
||||
with Image.open("Tests/images/no_palette_with_transparency.gif") as im:
|
||||
assert im.mode == "L"
|
||||
assert im.load()[0, 0] == 0
|
||||
assert im.info["transparency"] == 255
|
||||
|
||||
im.seek(1)
|
||||
assert im.mode == "LA"
|
||||
assert im.load()[0, 0] == (0, 255)
|
||||
|
||||
|
||||
def test_optimize():
|
||||
def test_grayscale(optimize):
|
||||
im = Image.new("L", (1, 1), 0)
|
||||
|
|
|
@ -167,9 +167,15 @@ class GifImageFile(ImageFile.ImageFile):
|
|||
if self.__frame == 1:
|
||||
self.pyaccess = None
|
||||
if "transparency" in self.info:
|
||||
self.mode = "RGBA"
|
||||
self.im.putpalettealpha(self.info["transparency"], 0)
|
||||
self.im = self.im.convert("RGBA", Image.Dither.FLOYDSTEINBERG)
|
||||
if self.mode == "P":
|
||||
self.im.putpalettealpha(self.info["transparency"], 0)
|
||||
self.im = self.im.convert("RGBA", Image.Dither.FLOYDSTEINBERG)
|
||||
self.mode = "RGBA"
|
||||
else:
|
||||
self.im = self.im.convert_transparent(
|
||||
"LA", self.info["transparency"]
|
||||
)
|
||||
self.mode = "LA"
|
||||
|
||||
del self.info["transparency"]
|
||||
else:
|
||||
|
@ -368,8 +374,11 @@ class GifImageFile(ImageFile.ImageFile):
|
|||
if self.__frame == 0:
|
||||
return
|
||||
if self._frame_transparency is not None:
|
||||
self.im.putpalettealpha(self._frame_transparency, 0)
|
||||
frame_im = self.im.convert("RGBA")
|
||||
if self.mode == "P":
|
||||
self.im.putpalettealpha(self._frame_transparency, 0)
|
||||
frame_im = self.im.convert("RGBA")
|
||||
else:
|
||||
frame_im = self.im.convert_transparent("LA", self._frame_transparency)
|
||||
else:
|
||||
frame_im = self.im.convert("RGB")
|
||||
frame_im = self._crop(frame_im, self.dispose_extent)
|
||||
|
|
Loading…
Reference in New Issue
Block a user