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) 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: def test_colors() -> None:
im = hopper() im = hopper()
colors = 2 colors = 2

View File

@ -1745,19 +1745,23 @@ ImagingQuantize(Imaging im, int colors, int mode, int kmeans) {
for (i = y = 0; y < im->ysize; y++) { for (i = y = 0; y < im->ysize; y++) {
for (x = 0; x < im->xsize; x++, i++) { for (x = 0; x < im->xsize; x++, i++) {
p[i].v = im->image32[y][x]; p[i].v = im->image32[y][x];
if (withAlpha && p[i].c.a == 0) { if (withAlpha) {
if (transparency == 0) { if (p[i].c.a == 0) {
transparency = 1; if (transparency == 0) {
r = p[i].c.r; transparency = 1;
g = p[i].c.g; r = p[i].c.r;
b = p[i].c.b; g = p[i].c.g;
} else { b = p[i].c.b;
/* Set all subsequent transparent pixels } else {
to the same colour as the first */ /* Set all subsequent transparent pixels
p[i].c.r = r; to the same colour as the first */
p[i].c.g = g; p[i].c.r = r;
p[i].c.b = b; p[i].c.g = g;
p[i].c.b = b;
}
} }
} else {
p[i].c.a = 255;
} }
} }
} }