From 14c6e6fcf512f74bf83ee6724045af4f8840dfc6 Mon Sep 17 00:00:00 2001 From: James O'Leary Date: Fri, 12 Mar 2021 13:30:22 -0500 Subject: [PATCH] Fix crash when quantizing Incoming pixels are negative numbers. Performing this operation ensures we receive an accurate alpha value, without it, all pixels have negative alphas. Fixes: 182523380 Test: Add logs, see that alphas _before_ this patch are logged as negative numbers, causing all pixels to be marked as transparent and ignored in quantization. Add patch, see logs indicate valid alphas. Change-Id: Ice7b7db245de9dd089cffc490b2e24780f9c025b --- .../com/android/internal/graphics/palette/WSMeansQuantizer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/java/com/android/internal/graphics/palette/WSMeansQuantizer.java b/core/java/com/android/internal/graphics/palette/WSMeansQuantizer.java index b4f216ba87fa6..1d865c2513cf1 100644 --- a/core/java/com/android/internal/graphics/palette/WSMeansQuantizer.java +++ b/core/java/com/android/internal/graphics/palette/WSMeansQuantizer.java @@ -75,7 +75,7 @@ public class WSMeansQuantizer implements Quantizer { // 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); + int alpha = (pixel >> 24) & 0xff; if (alpha < 255) { continue; }