Merge pull request #5869 from radarhere/quantize_palette

Fixed palette index for zeroed color in FASTOCTREE quantize
This commit is contained in:
Hugo van Kemenade 2021-12-28 10:05:58 +02:00 committed by GitHub
commit cc670c940e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -85,3 +85,20 @@ def test_transparent_colors_equal():
converted = im.quantize()
converted_px = converted.load()
assert converted_px[0, 0] == converted_px[0, 1]
@pytest.mark.parametrize(
"method, color",
(
(Image.MEDIANCUT, (0, 0, 0)),
(Image.MAXCOVERAGE, (0, 0, 0)),
(Image.FASTOCTREE, (0, 0, 0)),
(Image.FASTOCTREE, (0, 0, 0, 0)),
),
)
def test_palette(method, color):
im = Image.new("RGBA" if len(color) == 4 else "RGB", (1, 1), color)
converted = im.quantize(method=method)
converted_px = converted.load()
assert converted_px[0, 0] == converted.palette.colors[color]

View File

@ -317,7 +317,7 @@ void
add_lookup_buckets(ColorCube cube, ColorBucket palette, long nColors, long offset) {
long i;
Pixel p;
for (i = offset; i < offset + nColors; i++) {
for (i = offset + nColors - 1; i >= offset; i--) {
avg_color_from_color_bucket(&palette[i], &p);
set_lookup_value(cube, &p, i);
}