mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
Better tests, fixes for leaking RGB->P transparency
This commit is contained in:
parent
29bb882cef
commit
8adbaf8098
|
@ -809,7 +809,14 @@ class Image:
|
|||
#crash fail if we leave a bytes transparency in an rgb/l mode.
|
||||
del(new.info['transparency'])
|
||||
if trns is not None:
|
||||
new_im.info['transparency'] = trns
|
||||
if new_im.mode == 'P':
|
||||
try:
|
||||
new_im.info['transparency'] = new_im.palette.getcolor(trns)
|
||||
except:
|
||||
del(new_im.info['transparency'])
|
||||
warnings.warn("Couldn't allocate palette entry for transparency")
|
||||
else:
|
||||
new_im.info['transparency'] = trns
|
||||
return new_im
|
||||
|
||||
def quantize(self, colors=256, method=None, kmeans=0, palette=None):
|
||||
|
|
|
@ -84,6 +84,11 @@ def test_trns_l():
|
|||
assert_true('transparency' in p.info)
|
||||
assert_no_exception(lambda: p.save(f))
|
||||
|
||||
p = im.convert('P', palette = Image.ADAPTIVE)
|
||||
assert_false('transparency' in p.info)
|
||||
assert_no_exception(lambda: p.save(f))
|
||||
|
||||
|
||||
def test_trns_RGB():
|
||||
im = lena('RGB')
|
||||
im.info['transparency'] = im.getpixel((0,0))
|
||||
|
@ -97,3 +102,9 @@ def test_trns_RGB():
|
|||
p = im.convert('P')
|
||||
assert_true('transparency' in p.info)
|
||||
assert_no_exception(lambda: p.save(f))
|
||||
|
||||
p = im.convert('P', palette = Image.ADAPTIVE)
|
||||
assert_false('transparency' in p.info)
|
||||
assert_no_exception(lambda: p.save(f))
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user