diff --git a/Tests/images/p_16.png b/Tests/images/p_16.png index e35886412..458f7138e 100644 Binary files a/Tests/images/p_16.png and b/Tests/images/p_16.png differ diff --git a/Tests/test_file_tga.py b/Tests/test_file_tga.py index ff6dab00d..15c7bbdb8 100644 --- a/Tests/test_file_tga.py +++ b/Tests/test_file_tga.py @@ -72,12 +72,13 @@ def test_palette_depth_8(tmp_path: Path) -> None: 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") + assert im.palette.mode == "RGBA" + assert_image_equal_tofile(im.convert("RGBA"), "Tests/images/p_16.png") out = str(tmp_path / "temp.png") im.save(out) with Image.open(out) as reloaded: - assert_image_equal_tofile(reloaded.convert("RGB"), "Tests/images/p_16.png") + assert_image_equal_tofile(reloaded.convert("RGBA"), "Tests/images/p_16.png") def test_id_field() -> None: diff --git a/src/PIL/TgaImagePlugin.py b/src/PIL/TgaImagePlugin.py index 9bc483fc5..d158fe492 100644 --- a/src/PIL/TgaImagePlugin.py +++ b/src/PIL/TgaImagePlugin.py @@ -117,9 +117,11 @@ class TgaImageFile(ImageFile.ImageFile): # read palette start, size, mapdepth = i16(s, 3), i16(s, 5), s[7] if mapdepth == 16: - self.palette = ImagePalette.raw( - "BGRA;15", b"\0" * 2 * start + self.fp.read(2 * size) - ) + colormap = self.fp.read(2 * size) + palette_data = bytearray(b"\0" * 2 * start) + for a, b in zip(colormap[::2], colormap[1::2]): + palette_data += bytearray((a, b ^ 128)) + self.palette = ImagePalette.raw("BGRA;15", bytes(palette_data)) self.palette.mode = "RGBA" elif mapdepth == 24: self.palette = ImagePalette.raw(