diff --git a/Tests/images/p_16.png b/Tests/images/p_16.png new file mode 100644 index 000000000..e35886412 Binary files /dev/null and b/Tests/images/p_16.png differ diff --git a/Tests/images/p_16.tga b/Tests/images/p_16.tga new file mode 100644 index 000000000..2b2ca4c70 Binary files /dev/null and b/Tests/images/p_16.tga differ diff --git a/Tests/test_file_tga.py b/Tests/test_file_tga.py index 465e13316..eb76cf125 100644 --- a/Tests/test_file_tga.py +++ b/Tests/test_file_tga.py @@ -6,7 +6,7 @@ import pytest from PIL import Image -from .helper import assert_image_equal, hopper +from .helper import assert_image_equal, assert_image_equal_tofile, hopper _TGA_DIR = os.path.join("Tests", "images", "tga") _TGA_DIR_COMMON = os.path.join(_TGA_DIR, "common") @@ -65,6 +65,11 @@ def test_sanity(tmp_path): roundtrip(original_im) +def test_palette_depth_16(): + with Image.open("Tests/images/p_16.tga") as im: + assert_image_equal_tofile(im.convert("RGB"), "Tests/images/p_16.png") + + def test_id_field(): # tga file with id field test_file = "Tests/images/tga_id_field.tga" diff --git a/src/PIL/TgaImagePlugin.py b/src/PIL/TgaImagePlugin.py index 2b936d687..ce67beed8 100644 --- a/src/PIL/TgaImagePlugin.py +++ b/src/PIL/TgaImagePlugin.py @@ -113,7 +113,7 @@ class TgaImageFile(ImageFile.ImageFile): start, size, mapdepth = i16(s, 3), i16(s, 5), i16(s, 7) if mapdepth == 16: self.palette = ImagePalette.raw( - "BGR;16", b"\0" * 2 * start + self.fp.read(2 * size) + "BGR;15", b"\0" * 2 * start + self.fp.read(2 * size) ) elif mapdepth == 24: self.palette = ImagePalette.raw(