diff options
| author | 2024-04-23 11:21:15 +0000 | |
|---|---|---|
| committer | 2024-04-25 15:21:34 +0000 | |
| commit | 426852a672a01bdd94e29dc15a5be7734d5979ff (patch) | |
| tree | 5c91ecabcecf1e226d04842cf24646b6fab1af3f | |
| parent | d03906d57992997fbb4ee50fad1437aa56ce1ee2 (diff) | |
Adjust mini bitmap size for color extraction
Make sure that ImageWallpaper's color extractor rescales the bitmap
exactly like WallapperColors#fromBitmap does.
This should avoid slightly changing the colors and failing some
screenshot tests when totally moving the color extraction logic to
ImageWallpaper.
Flag: NA, currently the mini bitmap is unused
Bug: 328791519
Test: atest WallpaperLocalColorExtractorTest
Change-Id: I9f90b452106c0f6a84ee50ab0559ef868b79941b
2 files changed, 15 insertions, 15 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/wallpapers/WallpaperLocalColorExtractor.java b/packages/SystemUI/src/com/android/systemui/wallpapers/WallpaperLocalColorExtractor.java index d37dfb49c5e5..3c9259c233fc 100644 --- a/packages/SystemUI/src/com/android/systemui/wallpapers/WallpaperLocalColorExtractor.java +++ b/packages/SystemUI/src/com/android/systemui/wallpapers/WallpaperLocalColorExtractor.java @@ -51,7 +51,7 @@ public class WallpaperLocalColorExtractor { private Bitmap mMiniBitmap; @VisibleForTesting - static final int SMALL_SIDE = 128; + static final int MINI_BITMAP_MAX_AREA = 112 * 112; private static final String TAG = WallpaperLocalColorExtractor.class.getSimpleName(); private static final @NonNull RectF LOCAL_COLOR_BOUNDS = @@ -326,12 +326,12 @@ public class WallpaperLocalColorExtractor { private Bitmap createMiniBitmap(@NonNull Bitmap bitmap) { Trace.beginSection("WallpaperLocalColorExtractor#createMiniBitmap"); - // if both sides of the image are larger than SMALL_SIDE, downscale the bitmap. - int smallestSide = Math.min(bitmap.getWidth(), bitmap.getHeight()); - float scale = Math.min(1.0f, (float) SMALL_SIDE / smallestSide); + // if the area of the image is greater than MINI_BITMAP_MAX_AREA, downscale the bitmap. + int area = bitmap.getWidth() * bitmap.getHeight(); + double scale = Math.min(1, Math.sqrt((double) MINI_BITMAP_MAX_AREA / area)); Bitmap result = createMiniBitmap(bitmap, - (int) (scale * bitmap.getWidth()), - (int) (scale * bitmap.getHeight())); + Math.max(1, (int) (scale * bitmap.getWidth())), + Math.max(1, (int) (scale * bitmap.getHeight()))); Trace.endSection(); return result; } diff --git a/packages/SystemUI/tests/src/com/android/systemui/wallpapers/WallpaperLocalColorExtractorTest.java b/packages/SystemUI/tests/src/com/android/systemui/wallpapers/WallpaperLocalColorExtractorTest.java index 0eba21ada789..33d09c1be696 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/wallpapers/WallpaperLocalColorExtractorTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/wallpapers/WallpaperLocalColorExtractorTest.java @@ -59,8 +59,8 @@ import java.util.concurrent.Executor; @RunWith(AndroidTestingRunner.class) @TestableLooper.RunWithLooper public class WallpaperLocalColorExtractorTest extends SysuiTestCase { - private static final int LOW_BMP_WIDTH = 128; - private static final int LOW_BMP_HEIGHT = 128; + private static final int LOW_BMP_WIDTH = 112; + private static final int LOW_BMP_HEIGHT = 112; private static final int HIGH_BMP_WIDTH = 3000; private static final int HIGH_BMP_HEIGHT = 4000; private static final int VERY_LOW_BMP_WIDTH = 1; @@ -189,7 +189,7 @@ public class WallpaperLocalColorExtractorTest extends SysuiTestCase { /** * Test that for bitmaps of random dimensions, the mini bitmap is always created - * with either a width <= SMALL_SIDE or a height <= SMALL_SIDE + * with an area <= MINI_BITMAP_MAX_AREA */ @Test public void testMiniBitmapCreation() { @@ -203,14 +203,14 @@ public class WallpaperLocalColorExtractorTest extends SysuiTestCase { spyColorExtractor.onBitmapChanged(bitmap); assertThat(mMiniBitmapUpdatedCount).isEqualTo(1); - assertThat(Math.min(mMiniBitmapWidth, mMiniBitmapHeight)) - .isAtMost(WallpaperLocalColorExtractor.SMALL_SIDE); + assertThat(mMiniBitmapWidth * mMiniBitmapHeight) + .isAtMost(WallpaperLocalColorExtractor.MINI_BITMAP_MAX_AREA); } } /** - * Test that for bitmaps with both width and height <= SMALL_SIDE, - * the mini bitmap is always created with both width and height <= SMALL_SIDE + * Test that for bitmaps with both width and height <= LOW_BMP_WIDTH, + * the mini bitmap is always created with an area <= MINI_BITMAP_MAX_AREA */ @Test public void testSmallMiniBitmapCreation() { @@ -224,8 +224,8 @@ public class WallpaperLocalColorExtractorTest extends SysuiTestCase { spyColorExtractor.onBitmapChanged(bitmap); assertThat(mMiniBitmapUpdatedCount).isEqualTo(1); - assertThat(Math.max(mMiniBitmapWidth, mMiniBitmapHeight)) - .isAtMost(WallpaperLocalColorExtractor.SMALL_SIDE); + assertThat(mMiniBitmapWidth * mMiniBitmapHeight) + .isAtMost(WallpaperLocalColorExtractor.MINI_BITMAP_MAX_AREA); } } |