Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9b927684 authored by James O'Leary's avatar James O'Leary
Browse files

Ignore transparent pixels during WSMeans

The WSMeans quantizer uses starting clusters from a Wu quantizer as
starting points for an optimized Kmeans algorithm.

The first thing the quantizer does is assign pixels from the image being
quantized to those starting clusters. Either due to the image source or
downscaling, transparent pixels may be in the pixels. Filter those out:
they create misleading results, such as there being two colors in the
image, semi-transparent black and green, in a wallpaper that is solid
green by all accounts.

Fixes: 182333325
Test: atest CtsAppTestCases:android.app.cts.WallpaperColorsTest#fromDrawableTest
passes locally on sunfish. link: http://ab/I26300007868608112

Change-Id: Icaebd98eeba27d3dc59a698282dd3be03fce1bf9
parent fbbb5dd5
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -68,6 +68,17 @@ public class WSMeansQuantizer implements Quantizer {
        }

        for (int pixel : pixels) {
            // These are pixels from the bitmap that is being quantized.
            // Depending on the bitmap & downscaling, it may have pixels that are less than opaque
            // Ignore those pixels.
            ///
            // Note: they don't _have_ to be ignored, for example, we could instead turn them
            // opaque. Traditionally, including outside Android, quantizers ignore transparent
            // pixels, so that strategy was chosen.
            int alpha = (pixel >> 24);
            if (alpha < 255) {
                continue;
            }
            Integer currentCount = mCountByColor.get(pixel);
            if (currentCount == null) {
                currentCount = 0;