mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 09:56:17 +03:00
Expand C image to match GIF frame image size
This commit is contained in:
parent
1bf9fb4e40
commit
bdc53f6c4d
BIN
Tests/images/test_extents_transparency.gif
Normal file
BIN
Tests/images/test_extents_transparency.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 415 B |
|
@ -1378,8 +1378,24 @@ def test_lzw_bits() -> None:
|
|||
im.load()
|
||||
|
||||
|
||||
def test_extents() -> None:
|
||||
with Image.open("Tests/images/test_extents.gif") as im:
|
||||
@pytest.mark.parametrize(
|
||||
"test_file, loading_strategy",
|
||||
(
|
||||
("test_extents.gif", GifImagePlugin.LoadingStrategy.RGB_AFTER_FIRST),
|
||||
(
|
||||
"test_extents.gif",
|
||||
GifImagePlugin.LoadingStrategy.RGB_AFTER_DIFFERENT_PALETTE_ONLY,
|
||||
),
|
||||
(
|
||||
"test_extents_transparency.gif",
|
||||
GifImagePlugin.LoadingStrategy.RGB_AFTER_FIRST,
|
||||
),
|
||||
),
|
||||
)
|
||||
def test_extents(test_file, loading_strategy) -> None:
|
||||
GifImagePlugin.LOADING_STRATEGY = loading_strategy
|
||||
try:
|
||||
with Image.open("Tests/images/" + test_file) as im:
|
||||
assert im.size == (100, 100)
|
||||
|
||||
# Check that n_frames does not change the size
|
||||
|
@ -1389,6 +1405,11 @@ def test_extents() -> None:
|
|||
im.seek(1)
|
||||
assert im.size == (150, 150)
|
||||
|
||||
im.load()
|
||||
assert im.im.size == (150, 150)
|
||||
finally:
|
||||
GifImagePlugin.LOADING_STRATEGY = GifImagePlugin.LoadingStrategy.RGB_AFTER_FIRST
|
||||
|
||||
|
||||
def test_missing_background() -> None:
|
||||
# The Global Color Table Flag isn't set, so there is no background color index,
|
||||
|
|
|
@ -438,6 +438,13 @@ class GifImageFile(ImageFile.ImageFile):
|
|||
self.im.putpalette("RGB", *self._frame_palette.getdata())
|
||||
else:
|
||||
self._im = None
|
||||
if not self._prev_im and self._im is not None and self.size != self.im.size:
|
||||
expanded_im = Image.core.fill(self.im.mode, self.size)
|
||||
if self._frame_palette:
|
||||
expanded_im.putpalette("RGB", *self._frame_palette.getdata())
|
||||
expanded_im.paste(self.im, (0, 0) + self.im.size)
|
||||
|
||||
self.im = expanded_im
|
||||
self._mode = temp_mode
|
||||
self._frame_palette = None
|
||||
|
||||
|
@ -455,6 +462,17 @@ class GifImageFile(ImageFile.ImageFile):
|
|||
return
|
||||
if not self._prev_im:
|
||||
return
|
||||
if self.size != self._prev_im.size:
|
||||
if self._frame_transparency is not None:
|
||||
expanded_im = Image.core.fill("RGBA", self.size)
|
||||
else:
|
||||
expanded_im = Image.core.fill("P", self.size)
|
||||
expanded_im.putpalette("RGB", "RGB", self.im.getpalette())
|
||||
expanded_im = expanded_im.convert("RGB")
|
||||
expanded_im.paste(self._prev_im, (0, 0) + self._prev_im.size)
|
||||
|
||||
self._prev_im = expanded_im
|
||||
assert self._prev_im is not None
|
||||
if self._frame_transparency is not None:
|
||||
self.im.putpalettealpha(self._frame_transparency, 0)
|
||||
frame_im = self.im.convert("RGBA")
|
||||
|
|
Loading…
Reference in New Issue
Block a user