Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed quantize default dither to FLOYDSTEINBERG #6068

Merged
merged 3 commits into from Feb 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions Tests/test_image_quantize.py
Expand Up @@ -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

Expand All @@ -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()

Expand Down
10 changes: 8 additions & 2 deletions src/PIL/Image.py
Expand Up @@ -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.
Expand All @@ -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

"""
Expand Down
4 changes: 2 additions & 2 deletions src/libImaging/Convert.c
Expand Up @@ -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;
Expand Down Expand Up @@ -1574,7 +1574,7 @@ convert(
}

if (dither && strcmp(mode, "1") == 0) {
return tobilevel(imOut, imIn, dither);
return tobilevel(imOut, imIn);
}

/* standard conversion machinery */
Expand Down