Loading packages/SystemUI/src/com/android/systemui/wallpapers/WallpaperLocalColorExtractor.java +6 −6 Original line number Diff line number Diff line Loading @@ -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 = Loading Loading @@ -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; } Loading packages/SystemUI/tests/src/com/android/systemui/wallpapers/WallpaperLocalColorExtractorTest.java +9 −9 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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() { Loading @@ -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() { Loading @@ -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); } } Loading Loading
packages/SystemUI/src/com/android/systemui/wallpapers/WallpaperLocalColorExtractor.java +6 −6 Original line number Diff line number Diff line Loading @@ -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 = Loading Loading @@ -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; } Loading
packages/SystemUI/tests/src/com/android/systemui/wallpapers/WallpaperLocalColorExtractorTest.java +9 −9 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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() { Loading @@ -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() { Loading @@ -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); } } Loading