Move Wu check for max colors earlier.

This has no impact. However, after going through the quantizers line by
line for other bug fixes, after getting a break from looking at them
in-depth for a couple weeks, it was much more readable/felt safer to
adjust mMaxColors at the top.

Bug: 182333325
Test: Verify output remains constant,
atest CtsAppTestCases:android.app.cts.WallpaperColorsTest#fromDrawableTest
passes.

Change-Id: I561ba44bca392634a956992fd946f3310aa1c8ee
This commit is contained in:
James O'Leary
2021-03-11 11:50:40 -05:00
parent 9b9276849b
commit 7ef64c0787

View File

@@ -78,7 +78,12 @@ public class WuQuantizer implements Quantizer {
// All of the sample Wu implementations are reimplementations of a snippet of C code from
// the early 90s. They all cap the maximum # of colors at 256, and it is impossible to tell
// if this is a requirement, a consequence of QUANT_SIZE, or arbitrary.
this.mMaxColors = Math.min(MAX_COLORS, maxColorCount);
//
// Also, the number of maximum colors should be capped at the number of pixels - otherwise,
// If extraction is run on a set of pixels whose count is less than max colors,
// then colors.length < max colors, and accesses to colors[index] throw an
// ArrayOutOfBoundsException.
this.mMaxColors = Math.min(Math.min(MAX_COLORS, maxColorCount), colors.length);
Box[] cube = new Box[mMaxColors];
int red, green, blue;
@@ -119,11 +124,7 @@ public class WuQuantizer implements Quantizer {
}
}
// If extraction is run on a set of pixels whose count is less than the
// number of max colors, then colors.length < max colors, and accesses
// to colors[index] inside the for loop throw an ArrayOutOfBoundsException.
int numColorsToCreate = (int) Math.min(mMaxColors, colors.length);
for (k = 0; k < numColorsToCreate; ++k) {
for (k = 0; k < mMaxColors; ++k) {
weight = getVolume(cube[k], mWt);
if (weight > 0) {
red = (int) (getVolume(cube[k], mMr) / weight);