mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +03:00
Invert alpha bit for map depth 16
This commit is contained in:
parent
e5c6d883d4
commit
3840255486
Binary file not shown.
Before Width: | Height: | Size: 378 B After Width: | Height: | Size: 414 B |
|
@ -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:
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue
Block a user