mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +03:00
fix FLI/FLC decoder for files with a prefix chunk
This commit is contained in:
parent
47eaf0937f
commit
e45477e507
BIN
Tests/images/2422.flc
Normal file
BIN
Tests/images/2422.flc
Normal file
Binary file not shown.
|
@ -4,7 +4,7 @@ import warnings
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from PIL import FliImagePlugin, Image
|
from PIL import FliImagePlugin, Image, ImageFile
|
||||||
|
|
||||||
from .helper import assert_image_equal, assert_image_equal_tofile, is_pypy
|
from .helper import assert_image_equal, assert_image_equal_tofile, is_pypy
|
||||||
|
|
||||||
|
@ -12,9 +12,12 @@ from .helper import assert_image_equal, assert_image_equal_tofile, is_pypy
|
||||||
# save as...-> hopper.fli, default options.
|
# save as...-> hopper.fli, default options.
|
||||||
static_test_file = "Tests/images/hopper.fli"
|
static_test_file = "Tests/images/hopper.fli"
|
||||||
|
|
||||||
# From https://samples.libav.org/fli-flc/
|
# From https://samples.ffmpeg.org/fli-flc/
|
||||||
animated_test_file = "Tests/images/a.fli"
|
animated_test_file = "Tests/images/a.fli"
|
||||||
|
|
||||||
|
# From https://samples.ffmpeg.org/fli-flc/
|
||||||
|
animated_test_file_with_prefix_chunk = "Tests/images/2422.flc"
|
||||||
|
|
||||||
|
|
||||||
def test_sanity() -> None:
|
def test_sanity() -> None:
|
||||||
with Image.open(static_test_file) as im:
|
with Image.open(static_test_file) as im:
|
||||||
|
@ -32,6 +35,24 @@ def test_sanity() -> None:
|
||||||
assert im.is_animated
|
assert im.is_animated
|
||||||
|
|
||||||
|
|
||||||
|
def test_prefix_chunk() -> None:
|
||||||
|
ImageFile.LOAD_TRUNCATED_IMAGES = True
|
||||||
|
try:
|
||||||
|
with Image.open(animated_test_file_with_prefix_chunk) as im:
|
||||||
|
assert im.mode == "P"
|
||||||
|
assert im.size == (320, 200)
|
||||||
|
assert im.format == "FLI"
|
||||||
|
assert im.info["duration"] == 171
|
||||||
|
assert im.is_animated
|
||||||
|
|
||||||
|
palette = im.getpalette()
|
||||||
|
assert palette[3:6] == [255, 255, 255]
|
||||||
|
assert palette[381:384] == [204, 204, 12]
|
||||||
|
assert palette[765:] == [252, 0, 0]
|
||||||
|
finally:
|
||||||
|
ImageFile.LOAD_TRUNCATED_IMAGES = False
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(is_pypy(), reason="Requires CPython")
|
@pytest.mark.skipif(is_pypy(), reason="Requires CPython")
|
||||||
def test_unclosed_file() -> None:
|
def test_unclosed_file() -> None:
|
||||||
def open() -> None:
|
def open() -> None:
|
||||||
|
|
|
@ -77,6 +77,7 @@ class FliImageFile(ImageFile.ImageFile):
|
||||||
if i16(s, 4) == 0xF100:
|
if i16(s, 4) == 0xF100:
|
||||||
# prefix chunk; ignore it
|
# prefix chunk; ignore it
|
||||||
self.__offset = self.__offset + i32(s)
|
self.__offset = self.__offset + i32(s)
|
||||||
|
self.fp.seek(self.__offset)
|
||||||
s = self.fp.read(16)
|
s = self.fp.read(16)
|
||||||
|
|
||||||
if i16(s, 4) == 0xF1FA:
|
if i16(s, 4) == 0xF1FA:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user