From 5b9c11b426546cffb85859ce79be734ebdffba3c Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 16 Mar 2019 13:36:58 +1100 Subject: [PATCH] Update palette in quantize --- Tests/test_image_quantize.py | 3 ++- src/PIL/Image.py | 8 +++++++- src/libImaging/Unpack.c | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Tests/test_image_quantize.py b/Tests/test_image_quantize.py index 762b4bcab..5f2318574 100644 --- a/Tests/test_image_quantize.py +++ b/Tests/test_image_quantize.py @@ -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() diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 51d6e8466..f1a83c47c 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -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): """ diff --git a/src/libImaging/Unpack.c b/src/libImaging/Unpack.c index e9921d2ca..ccfeabaf9 100644 --- a/src/libImaging/Unpack.c +++ b/src/libImaging/Unpack.c @@ -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},