mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-05-06 00:43:41 +03:00
Merge pull request #1239 from juztin/master
Setting transparency value to 0 when the tRNS contains only null byte(s)
This commit is contained in:
commit
b350a2ac95
|
@ -71,6 +71,7 @@ _MODES = {
|
||||||
|
|
||||||
|
|
||||||
_simple_palette = re.compile(b'^\xff+\x00\xff*$')
|
_simple_palette = re.compile(b'^\xff+\x00\xff*$')
|
||||||
|
_null_palette = re.compile(b'^\x00*$')
|
||||||
|
|
||||||
# Maximum decompressed size for a iTXt or zTXt chunk.
|
# Maximum decompressed size for a iTXt or zTXt chunk.
|
||||||
# Eliminates decompression bombs where compressed chunks can expand 1000x
|
# Eliminates decompression bombs where compressed chunks can expand 1000x
|
||||||
|
@ -350,6 +351,8 @@ class PngStream(ChunkStream):
|
||||||
i = s.find(b"\0")
|
i = s.find(b"\0")
|
||||||
if i >= 0:
|
if i >= 0:
|
||||||
self.im_info["transparency"] = i
|
self.im_info["transparency"] = i
|
||||||
|
elif _null_palette.match(s):
|
||||||
|
self.im_info["transparency"] = 0
|
||||||
else:
|
else:
|
||||||
self.im_info["transparency"] = s
|
self.im_info["transparency"] = s
|
||||||
elif self.im_mode == "L":
|
elif self.im_mode == "L":
|
||||||
|
|
BIN
Tests/images/tRNS_null_1x1.png
Normal file
BIN
Tests/images/tRNS_null_1x1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 96 B |
|
@ -354,6 +354,13 @@ class TestFilePng(PillowTestCase):
|
||||||
self.assert_image_equal(im2.convert('RGBA'),
|
self.assert_image_equal(im2.convert('RGBA'),
|
||||||
im.convert('RGBA'))
|
im.convert('RGBA'))
|
||||||
|
|
||||||
|
def test_trns_null(self):
|
||||||
|
# Check reading images with null tRNS value, issue #1239
|
||||||
|
test_file = "Tests/images/tRNS_null_1x1.png"
|
||||||
|
im = Image.open(test_file)
|
||||||
|
|
||||||
|
self.assertEqual(im.info["transparency"], 0)
|
||||||
|
|
||||||
def test_save_icc_profile_none(self):
|
def test_save_icc_profile_none(self):
|
||||||
# check saving files with an ICC profile set to None (omit profile)
|
# check saving files with an ICC profile set to None (omit profile)
|
||||||
in_file = "Tests/images/icc_profile_none.png"
|
in_file = "Tests/images/icc_profile_none.png"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user