mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-05 20:33:24 +03:00
Merge pull request #6068 from radarhere/quantize
Changed quantize default dither to FLOYDSTEINBERG
This commit is contained in:
commit
de06aba8f1
|
@ -60,7 +60,7 @@ def test_quantize_no_dither():
|
||||||
with Image.open("Tests/images/caption_6_33_22.png") as palette:
|
with Image.open("Tests/images/caption_6_33_22.png") as palette:
|
||||||
palette = palette.convert("P")
|
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.mode == "P"
|
||||||
assert converted.palette.palette == palette.palette.palette
|
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:
|
with Image.open("Tests/images/caption_6_33_22.png") as palette:
|
||||||
palette = palette.convert("P")
|
palette = palette.convert("P")
|
||||||
|
|
||||||
dither = image.quantize(dither=1, palette=palette)
|
dither = image.quantize(dither=Image.Dither.FLOYDSTEINBERG, palette=palette)
|
||||||
nodither = image.quantize(dither=0, palette=palette)
|
nodither = image.quantize(dither=Image.Dither.NONE, palette=palette)
|
||||||
|
|
||||||
assert dither.tobytes() != nodither.tobytes()
|
assert dither.tobytes() != nodither.tobytes()
|
||||||
|
|
||||||
|
|
|
@ -1091,7 +1091,14 @@ class Image:
|
||||||
new_im.info["transparency"] = trns
|
new_im.info["transparency"] = trns
|
||||||
return new_im
|
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
|
Convert the image to 'P' mode with the specified number
|
||||||
of colors.
|
of colors.
|
||||||
|
@ -1116,7 +1123,6 @@ class Image:
|
||||||
mode "RGB" to "P" or from "RGB" or "L" to "1".
|
mode "RGB" to "P" or from "RGB" or "L" to "1".
|
||||||
Available methods are :data:`Dither.NONE` or :data:`Dither.FLOYDSTEINBERG`
|
Available methods are :data:`Dither.NONE` or :data:`Dither.FLOYDSTEINBERG`
|
||||||
(default).
|
(default).
|
||||||
Default: 1 (legacy setting)
|
|
||||||
:returns: A new image
|
:returns: A new image
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -1447,7 +1447,7 @@ topalette(
|
||||||
}
|
}
|
||||||
|
|
||||||
static Imaging
|
static Imaging
|
||||||
tobilevel(Imaging imOut, Imaging imIn, int dither) {
|
tobilevel(Imaging imOut, Imaging imIn) {
|
||||||
ImagingSectionCookie cookie;
|
ImagingSectionCookie cookie;
|
||||||
int x, y;
|
int x, y;
|
||||||
int *errors;
|
int *errors;
|
||||||
|
@ -1574,7 +1574,7 @@ convert(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dither && strcmp(mode, "1") == 0) {
|
if (dither && strcmp(mode, "1") == 0) {
|
||||||
return tobilevel(imOut, imIn, dither);
|
return tobilevel(imOut, imIn);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* standard conversion machinery */
|
/* standard conversion machinery */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user