Set mode to L if palette is missing

This commit is contained in:
Andrew Murray 2024-02-14 06:55:13 +11:00
parent 50e9a92c98
commit 63987b7aba
2 changed files with 6 additions and 1 deletions

View File

@ -133,6 +133,11 @@ def test_small_palette(tmp_path: Path) -> None:
assert reloaded.getpalette() == colors
def test_missing_palette() -> None:
with Image.open("Tests/images/dilation4.lut") as im:
assert im.mode == "L"
def test_save_wrong_mode(tmp_path: Path) -> None:
im = hopper("PA")
out = str(tmp_path / "temp.tga")

View File

@ -85,7 +85,7 @@ class TgaImageFile(ImageFile.ImageFile):
elif depth == 16:
self._mode = "LA"
elif imagetype in (1, 9):
self._mode = "P"
self._mode = "P" if colormaptype else "L"
elif imagetype in (2, 10):
self._mode = "RGB"
if depth == 32: