mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-15 09:44:46 +03:00
Fill alpha channel when quantizing RGB images
This commit is contained in:
parent
cee238bcb8
commit
0465627f0c
|
@ -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
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user