mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 18:06:18 +03:00
Only use an RGBA palette for images with an alpha channel
This commit is contained in:
parent
7005e66f00
commit
804183c248
|
@ -249,8 +249,8 @@ def test_apng_mode():
|
|||
assert im.mode == "P"
|
||||
im.seek(im.n_frames - 1)
|
||||
im = im.convert("RGBA")
|
||||
assert im.getpixel((0, 0)) == (0, 255, 0, 255)
|
||||
assert im.getpixel((64, 32)) == (0, 255, 0, 255)
|
||||
assert im.getpixel((0, 0)) == (255, 0, 0, 0)
|
||||
assert im.getpixel((64, 32)) == (255, 0, 0, 0)
|
||||
|
||||
with Image.open("Tests/images/apng/mode_palette_1bit_alpha.png") as im:
|
||||
assert im.mode == "P"
|
||||
|
|
|
@ -167,7 +167,7 @@ def test_gif_with_rgba_palette_to_p():
|
|||
with Image.open("Tests/images/hopper.gif") as im:
|
||||
im.info["transparency"] = 255
|
||||
im.load()
|
||||
assert im.palette.mode == "RGBA"
|
||||
assert im.palette.mode == "RGB"
|
||||
im_p = im.convert("P")
|
||||
|
||||
# Should not raise ValueError: unrecognized raw mode
|
||||
|
|
|
@ -833,7 +833,7 @@ class Image:
|
|||
palette_length = self.im.putpalette(mode, arr)
|
||||
self.palette.dirty = 0
|
||||
self.palette.rawmode = None
|
||||
if "transparency" in self.info:
|
||||
if "transparency" in self.info and mode in ("RGBA", "LA", "PA"):
|
||||
if isinstance(self.info["transparency"], int):
|
||||
self.im.putpalettealpha(self.info["transparency"], 0)
|
||||
else:
|
||||
|
|
|
@ -320,7 +320,7 @@ def _save(im, fp, filename):
|
|||
alpha = (
|
||||
"A" in im.mode
|
||||
or "a" in im.mode
|
||||
or (im.mode == "P" and "A" in im.im.getpalettemode())
|
||||
or (im.mode == "P" and "transparency" in im.info)
|
||||
)
|
||||
im = im.convert("RGBA" if alpha else "RGB")
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user