Skip to content

Commit 2fc9588

Browse files
committed
Remove palette if no longer relevant after seek
1 parent 3e2ab96 commit 2fc9588

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

Tests/test_file_libtiff.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,15 @@ def test_multipage_compression(self) -> None:
865865
assert im.size == (10, 10)
866866
im.load()
867867

868+
def test_seek_remove_palette(self) -> None:
869+
with Image.open("Tests/images/no_rows_per_strip.tif") as im:
870+
assert im.mode == "P"
871+
assert im.palette is not None
872+
873+
im.seek(1)
874+
assert im.mode == "F"
875+
assert im.palette is None
876+
868877
def test_save_tiff_with_jpegtables(self, tmp_path: Path) -> None:
869878
# Arrange
870879
outfile = tmp_path / "temp.tif"

src/PIL/TiffImagePlugin.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,6 +1673,8 @@ def _setup(self) -> None:
16731673
if self.mode in ["P", "PA"]:
16741674
palette = [o8(b // 256) for b in self.tag_v2[COLORMAP]]
16751675
self.palette = ImagePalette.raw("RGB;L", b"".join(palette))
1676+
else:
1677+
self.palette = None
16761678

16771679

16781680
#

0 commit comments

Comments
 (0)