mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +03:00
Merge pull request #7797 from radarhere/tga_palette
This commit is contained in:
commit
d8c8075061
BIN
Tests/images/p_8.tga
Normal file
BIN
Tests/images/p_8.tga
Normal file
Binary file not shown.
|
@ -7,7 +7,7 @@ from pathlib import Path
|
|||
|
||||
import pytest
|
||||
|
||||
from PIL import Image
|
||||
from PIL import Image, UnidentifiedImageError
|
||||
|
||||
from .helper import assert_image_equal, assert_image_equal_tofile, hopper
|
||||
|
||||
|
@ -65,6 +65,11 @@ def test_sanity(mode: str, tmp_path: Path) -> None:
|
|||
roundtrip(original_im)
|
||||
|
||||
|
||||
def test_palette_depth_8(tmp_path: Path) -> None:
|
||||
with pytest.raises(UnidentifiedImageError):
|
||||
Image.open("Tests/images/p_8.tga")
|
||||
|
||||
|
||||
def test_palette_depth_16(tmp_path: Path) -> None:
|
||||
with Image.open("Tests/images/p_16.tga") as im:
|
||||
assert_image_equal_tofile(im.convert("RGB"), "Tests/images/p_16.png")
|
||||
|
@ -133,6 +138,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")
|
||||
|
|
|
@ -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:
|
||||
|
@ -128,6 +128,9 @@ class TgaImageFile(ImageFile.ImageFile):
|
|||
self.palette = ImagePalette.raw(
|
||||
"BGRA", b"\0" * 4 * start + self.fp.read(4 * size)
|
||||
)
|
||||
else:
|
||||
msg = "unknown TGA map depth"
|
||||
raise SyntaxError(msg)
|
||||
|
||||
# setup tile descriptor
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue
Block a user