mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-28 02:04:36 +03:00
Merge pull request #5557 from radarhere/gif_first_frame_transparency
This commit is contained in:
commit
00303a29e9
BIN
Tests/images/first_frame_transparency.gif
Normal file
BIN
Tests/images/first_frame_transparency.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 972 B |
BIN
Tests/images/transparent_dispose.gif
Normal file
BIN
Tests/images/transparent_dispose.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 95 B |
|
@ -298,6 +298,12 @@ def test_eoferror():
|
||||||
im.seek(n_frames - 1)
|
im.seek(n_frames - 1)
|
||||||
|
|
||||||
|
|
||||||
|
def test_first_frame_transparency():
|
||||||
|
with Image.open("Tests/images/first_frame_transparency.gif") as im:
|
||||||
|
px = im.load()
|
||||||
|
assert px[0, 0] == im.info["transparency"]
|
||||||
|
|
||||||
|
|
||||||
def test_dispose_none():
|
def test_dispose_none():
|
||||||
with Image.open("Tests/images/dispose_none.gif") as img:
|
with Image.open("Tests/images/dispose_none.gif") as img:
|
||||||
try:
|
try:
|
||||||
|
@ -331,6 +337,16 @@ def test_dispose_background():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def test_transparent_dispose():
|
||||||
|
expected_colors = [(2, 1, 2), (0, 1, 0), (2, 1, 2)]
|
||||||
|
with Image.open("Tests/images/transparent_dispose.gif") as img:
|
||||||
|
for frame in range(3):
|
||||||
|
img.seek(frame)
|
||||||
|
for x in range(3):
|
||||||
|
color = img.getpixel((x, 0))
|
||||||
|
assert color == expected_colors[frame][x]
|
||||||
|
|
||||||
|
|
||||||
def test_dispose_previous():
|
def test_dispose_previous():
|
||||||
with Image.open("Tests/images/dispose_prev.gif") as img:
|
with Image.open("Tests/images/dispose_prev.gif") as img:
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -269,9 +269,14 @@ class GifImageFile(ImageFile.ImageFile):
|
||||||
dispose_size = (x1 - x0, y1 - y0)
|
dispose_size = (x1 - x0, y1 - y0)
|
||||||
|
|
||||||
Image._decompression_bomb_check(dispose_size)
|
Image._decompression_bomb_check(dispose_size)
|
||||||
self.dispose = Image.core.fill(
|
|
||||||
"P", dispose_size, self.info.get("background", 0)
|
# by convention, attempt to use transparency first
|
||||||
|
color = (
|
||||||
|
frame_transparency
|
||||||
|
if frame_transparency is not None
|
||||||
|
else self.info.get("background", 0)
|
||||||
)
|
)
|
||||||
|
self.dispose = Image.core.fill("P", dispose_size, color)
|
||||||
else:
|
else:
|
||||||
# replace with previous contents
|
# replace with previous contents
|
||||||
if self.im:
|
if self.im:
|
||||||
|
@ -317,6 +322,12 @@ class GifImageFile(ImageFile.ImageFile):
|
||||||
if self.palette:
|
if self.palette:
|
||||||
self.mode = "P"
|
self.mode = "P"
|
||||||
|
|
||||||
|
def load_prepare(self):
|
||||||
|
if not self.im and "transparency" in self.info:
|
||||||
|
self.im = Image.core.fill(self.mode, self.size, self.info["transparency"])
|
||||||
|
|
||||||
|
super(GifImageFile, self).load_prepare()
|
||||||
|
|
||||||
def tell(self):
|
def tell(self):
|
||||||
return self.__frame
|
return self.__frame
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user