This commit is contained in:
Andrew Murray 2025-08-12 12:19:29 +03:00 committed by GitHub
commit e859f01043
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 12 deletions

View File

@ -116,6 +116,15 @@ def test_quantize_kmeans(method: Image.Quantize) -> None:
im.quantize(kmeans=-1, method=method)
@skip_unless_feature("libimagequant")
def test_resize() -> None:
im = hopper().resize((100, 100))
converted = im.quantize(100, Image.Quantize.LIBIMAGEQUANT)
colors = converted.getcolors()
assert colors is not None
assert len(colors) == 100
def test_colors() -> None:
im = hopper()
colors = 2

View File

@ -1745,7 +1745,8 @@ ImagingQuantize(Imaging im, int colors, int mode, int kmeans) {
for (i = y = 0; y < im->ysize; y++) {
for (x = 0; x < im->xsize; x++, i++) {
p[i].v = im->image32[y][x];
if (withAlpha && p[i].c.a == 0) {
if (withAlpha) {
if (p[i].c.a == 0) {
if (transparency == 0) {
transparency = 1;
r = p[i].c.r;
@ -1759,6 +1760,9 @@ ImagingQuantize(Imaging im, int colors, int mode, int kmeans) {
p[i].c.b = b;
}
}
} else {
p[i].c.a = 255;
}
}
}