Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Tests/test_tiff_palette.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from __future__ import annotations

import io

from PIL import Image, ImageDraw


def test_tiff_palette() -> None:
image = Image.new("P", (3, 1))
file = io.BytesIO()
image.save(file, "tiff")

image = Image.open(file)
draw = ImageDraw.Draw(image)
COLOR_0 = (1, 2, 3)
COLOR_1 = (127, 128, 129)
COLOR_2 = (252, 253, 254)
draw.point((0, 0), fill=COLOR_0)
draw.point((1, 0), fill=COLOR_1)
draw.point((2, 0), fill=COLOR_2)

converted_data = list(image.convert("RGB").getdata())
assert len(converted_data) == 3
assert converted_data[0] == COLOR_0
assert converted_data[1] == COLOR_1
assert converted_data[2] == COLOR_2
2 changes: 1 addition & 1 deletion src/PIL/ImagePalette.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def getcolor(
except KeyError as e:
# allocate new color slot
index = self._new_color_index(image, e)
assert isinstance(self._palette, bytearray)
assert isinstance(self._palette, (bytes, bytearray))
self.colors[color] = index
if index * 3 < len(self.palette):
self._palette = (
Expand Down
Loading