From f6e024212cbe7187622d37a0ce92d5e7c32a9e8a Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 19 Feb 2022 10:49:23 +1100 Subject: [PATCH 1/3] Use enums for quantize instead of raw values --- Tests/test_image_quantize.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/test_image_quantize.py b/Tests/test_image_quantize.py index d48ee6c86c3..e9afd91189c 100644 --- a/Tests/test_image_quantize.py +++ b/Tests/test_image_quantize.py @@ -60,7 +60,7 @@ def test_quantize_no_dither(): with Image.open("Tests/images/caption_6_33_22.png") as palette: palette = palette.convert("P") - converted = image.quantize(dither=0, palette=palette) + converted = image.quantize(dither=Image.Dither.NONE, palette=palette) assert converted.mode == "P" assert converted.palette.palette == palette.palette.palette @@ -70,8 +70,8 @@ def test_quantize_dither_diff(): with Image.open("Tests/images/caption_6_33_22.png") as palette: palette = palette.convert("P") - dither = image.quantize(dither=1, palette=palette) - nodither = image.quantize(dither=0, palette=palette) + dither = image.quantize(dither=Image.Dither.FLOYDSTEINBERG, palette=palette) + nodither = image.quantize(dither=Image.Dither.NONE, palette=palette) assert dither.tobytes() != nodither.tobytes() From 753886483909103eac6af9d33b343bda5d411b95 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 19 Feb 2022 10:49:46 +1100 Subject: [PATCH 2/3] Changed quantize default dither to FLOYDSTEINBERG --- src/PIL/Image.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 9c35d332881..1ad70a7000f 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -1123,7 +1123,14 @@ def convert_transparency(m, v): new_im.info["transparency"] = trns return new_im - def quantize(self, colors=256, method=None, kmeans=0, palette=None, dither=1): + def quantize( + self, + colors=256, + method=None, + kmeans=0, + palette=None, + dither=Dither.FLOYDSTEINBERG, + ): """ Convert the image to 'P' mode with the specified number of colors. @@ -1148,7 +1155,6 @@ def quantize(self, colors=256, method=None, kmeans=0, palette=None, dither=1): mode "RGB" to "P" or from "RGB" or "L" to "1". Available methods are :data:`Dither.NONE` or :data:`Dither.FLOYDSTEINBERG` (default). - Default: 1 (legacy setting) :returns: A new image """ From 341802c2dcfd4672ccc7a687cec7a6cb6e207b8f Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 19 Feb 2022 10:50:07 +1100 Subject: [PATCH 3/3] Removed unused argument --- src/libImaging/Convert.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libImaging/Convert.c b/src/libImaging/Convert.c index 3f59a7e8817..0f200af6b16 100644 --- a/src/libImaging/Convert.c +++ b/src/libImaging/Convert.c @@ -1447,7 +1447,7 @@ topalette( } static Imaging -tobilevel(Imaging imOut, Imaging imIn, int dither) { +tobilevel(Imaging imOut, Imaging imIn) { ImagingSectionCookie cookie; int x, y; int *errors; @@ -1574,7 +1574,7 @@ convert( } if (dither && strcmp(mode, "1") == 0) { - return tobilevel(imOut, imIn, dither); + return tobilevel(imOut, imIn); } /* standard conversion machinery */