diff --git a/src/PIL/QoiImagePlugin.py b/src/PIL/QoiImagePlugin.py index 6f2c9c5c6..b8c631ed3 100644 --- a/src/PIL/QoiImagePlugin.py +++ b/src/PIL/QoiImagePlugin.py @@ -113,7 +113,7 @@ class QoiDecoder(ImageFile.PyDecoder): return -1, 0 -def _save(im: Image.image, fp: IO[bytes], filename: str | bytes) -> None: +def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None: if im.mode == "RGB": channels = 3 elif im.mode == "RGBA": @@ -138,8 +138,8 @@ def _save(im: Image.image, fp: IO[bytes], filename: str | bytes) -> None: class QoiEncoder(ImageFile.PyEncoder): _pushes_fd = True - _previous_pixel: tuple[int] | None = None - _previously_seen_pixels: dict[int, tuple[int]] = {} + _previous_pixel: tuple[int, int, int, int] | None = None + _previously_seen_pixels: dict[int, tuple[int, int, int, int]] = {} def _write_run(self, run): return o8(0xC0 | (run - 1)) # QOI_OP_RUN @@ -181,7 +181,7 @@ class QoiEncoder(ImageFile.PyEncoder): hash_value = (r * 3 + g * 5 + b * 7 + a * 11) % 64 if self._previously_seen_pixels.get(hash_value) == pixel: data += o8(hash_value) # QOI_OP_INDEX - else: + elif self._previous_pixel: self._previously_seen_pixels[hash_value] = pixel pr, pg, pb, pa = self._previous_pixel