mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-12-03 16:24:24 +03:00
Read all non-zero transparency from mode 1 PNG images as 255 (#9282)
This commit is contained in:
commit
2150f088ed
|
|
@ -338,6 +338,15 @@ class TestFilePng:
|
|||
assert colors is not None
|
||||
assert colors[0][0] == num_transparent
|
||||
|
||||
def test_save_1_transparency(self, tmp_path: Path) -> None:
|
||||
out = tmp_path / "temp.png"
|
||||
|
||||
im = Image.new("1", (1, 1), 1)
|
||||
im.save(out, transparency=1)
|
||||
|
||||
with Image.open(out) as reloaded:
|
||||
assert reloaded.info["transparency"] == 255
|
||||
|
||||
def test_save_rgb_single_transparency(self, tmp_path: Path) -> None:
|
||||
in_file = "Tests/images/caption_6_33_22.png"
|
||||
with Image.open(in_file) as im:
|
||||
|
|
|
|||
|
|
@ -509,7 +509,9 @@ class PngStream(ChunkStream):
|
|||
# otherwise, we have a byte string with one alpha value
|
||||
# for each palette entry
|
||||
self.im_info["transparency"] = s
|
||||
elif self.im_mode in ("1", "L", "I;16"):
|
||||
elif self.im_mode == "1":
|
||||
self.im_info["transparency"] = 255 if i16(s) else 0
|
||||
elif self.im_mode in ("L", "I;16"):
|
||||
self.im_info["transparency"] = i16(s)
|
||||
elif self.im_mode == "RGB":
|
||||
self.im_info["transparency"] = i16(s), i16(s, 2), i16(s, 4)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user