Start QOI decoding with a zero-initialized array of previously seen pixels (#9008)

This commit is contained in:
Andrew Murray 2025-06-11 22:56:57 +10:00 committed by GitHub
commit 7f7c27f66a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7 additions and 1 deletions

BIN
Tests/images/op_index.qoi Normal file

Binary file not shown.

View File

@ -28,3 +28,9 @@ def test_invalid_file() -> None:
with pytest.raises(SyntaxError):
QoiImagePlugin.QoiImageFile(invalid_file)
def test_op_index() -> None:
# QOI_OP_INDEX as the first chunk
with Image.open("Tests/images/op_index.qoi") as im:
assert im.getpixel((0, 0)) == (0, 0, 0, 0)

View File

@ -51,7 +51,7 @@ class QoiDecoder(ImageFile.PyDecoder):
assert self.fd is not None
self._previously_seen_pixels = {}
self._add_to_previous_pixels(bytearray((0, 0, 0, 255)))
self._previous_pixel = bytearray((0, 0, 0, 255))
data = bytearray()
bands = Image.getmodebands(self.mode)