mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-27 10:26:19 +03:00
Remove palettes from non-palette modes in _new #2702
This commit is contained in:
parent
8600f1840d
commit
e422f92e52
|
@ -527,9 +527,10 @@ class Image(object):
|
||||||
new.im = im
|
new.im = im
|
||||||
new.mode = im.mode
|
new.mode = im.mode
|
||||||
new.size = im.size
|
new.size = im.size
|
||||||
|
if im.mode in ('P', 'PA'):
|
||||||
if self.palette:
|
if self.palette:
|
||||||
new.palette = self.palette.copy()
|
new.palette = self.palette.copy()
|
||||||
if im.mode == "P" and not new.palette:
|
else:
|
||||||
from . import ImagePalette
|
from . import ImagePalette
|
||||||
new.palette = ImagePalette.ImagePalette()
|
new.palette = ImagePalette.ImagePalette()
|
||||||
new.info = self.info.copy()
|
new.info = self.info.copy()
|
||||||
|
|
|
@ -446,6 +446,33 @@ class TestImage(PillowTestCase):
|
||||||
self.assert_image_equal(im, target)
|
self.assert_image_equal(im, target)
|
||||||
|
|
||||||
|
|
||||||
|
def test__new(self):
|
||||||
|
from PIL import ImagePalette
|
||||||
|
|
||||||
|
im = hopper('RGB')
|
||||||
|
im_p = hopper('P')
|
||||||
|
|
||||||
|
blank_p = Image.new('P', (10,10))
|
||||||
|
blank_pa = Image.new('PA', (10,10))
|
||||||
|
blank_p.palette = None
|
||||||
|
blank_pa.palette = None
|
||||||
|
|
||||||
|
def _make_new(base_image, im, palette_result=None):
|
||||||
|
new_im = base_image._new(im)
|
||||||
|
self.assertEqual(new_im.mode, im.mode)
|
||||||
|
self.assertEqual(new_im.size, im.size)
|
||||||
|
self.assertEqual(new_im.info, base_image.info)
|
||||||
|
if palette_result is not None:
|
||||||
|
self.assertEqual(new_im.palette.tobytes(), palette_result.tobytes())
|
||||||
|
else:
|
||||||
|
self.assertEqual(new_im.palette, None)
|
||||||
|
|
||||||
|
_make_new(im, im_p, im_p.palette)
|
||||||
|
_make_new(im_p, im, None)
|
||||||
|
_make_new(im, blank_p, ImagePalette.ImagePalette())
|
||||||
|
_make_new(im, blank_pa, ImagePalette.ImagePalette())
|
||||||
|
|
||||||
|
|
||||||
class MockEncoder(object):
|
class MockEncoder(object):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -87,6 +87,9 @@ class TestImageConvert(PillowTestCase):
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
self.assertNotIn('transparency', rgba.info)
|
self.assertNotIn('transparency', rgba.info)
|
||||||
|
# https://github.com/python-pillow/Pillow/issues/2702
|
||||||
|
self.assertEqual(rgba.palette, None)
|
||||||
|
|
||||||
|
|
||||||
def test_trns_l(self):
|
def test_trns_l(self):
|
||||||
im = hopper('L')
|
im = hopper('L')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user