Merge pull request #3721 from radarhere/quantize

Update palette in quantize
This commit is contained in:
Hugo 2019-03-30 12:07:38 +02:00 committed by GitHub
commit 4f8cfd536b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 2 deletions

View File

@ -38,9 +38,10 @@ class TestImageQuantize(PillowTestCase):
def test_rgba_quantize(self):
image = hopper('RGBA')
image.quantize()
self.assertRaises(ValueError, image.quantize, method=0)
self.assertEqual(image.quantize().convert().mode, "RGBA")
def test_quantize(self):
image = Image.open('Tests/images/caption_6_33_22.png').convert('RGB')
converted = image.quantize()

View File

@ -1096,7 +1096,13 @@ class Image(object):
im = self.im.convert("P", dither, palette.im)
return self._new(im)
return self._new(self.im.quantize(colors, method, kmeans))
im = self._new(self.im.quantize(colors, method, kmeans))
from . import ImagePalette
mode = im.im.getpalettemode()
im.palette = ImagePalette.ImagePalette(mode, im.im.getpalette(mode, mode))
return im
def copy(self):
"""

View File

@ -1331,6 +1331,7 @@ static struct {
{"RGB", "BGR;5", 16, ImagingUnpackBGR15}, /* compat */
{"RGB", "RGBX", 32, copy4},
{"RGB", "RGBX;L", 32, unpackRGBAL},
{"RGB", "RGBA;L", 32, unpackRGBAL},
{"RGB", "BGRX", 32, ImagingUnpackBGRX},
{"RGB", "XRGB", 24, ImagingUnpackXRGB},
{"RGB", "XBGR", 32, ImagingUnpackXBGR},