Loading core/java/android/content/ContentResolver.java +13 −13 Original line number Diff line number Diff line Loading @@ -3658,7 +3658,7 @@ public abstract class ContentResolver implements ContentInterface { // returned something giant, so defensively scale down as needed. final int widthSample = info.getSize().getWidth() / size.getWidth(); final int heightSample = info.getSize().getHeight() / size.getHeight(); final int sample = Math.min(widthSample, heightSample); final int sample = Math.max(widthSample, heightSample); if (sample > 1) { decoder.setTargetSampleSize(sample); } Loading core/tests/coretests/src/android/content/ContentResolverTest.java +26 −10 Original line number Diff line number Diff line Loading @@ -86,19 +86,19 @@ public class ContentResolverTest { afd); } private static void assertImageAspectAndContents(Bitmap bitmap) { private static void assertImageAspectAndContents(int width, int height, Bitmap bitmap) { // And correct aspect ratio final int before = (100 * 1280) / 960; final int before = (100 * width) / height; final int after = (100 * bitmap.getWidth()) / bitmap.getHeight(); assertEquals(before, after); // And scaled correctly final int halfX = bitmap.getWidth() / 2; final int halfY = bitmap.getHeight() / 2; assertEquals(Color.BLUE, bitmap.getPixel(halfX - 10, halfY - 10)); assertEquals(Color.RED, bitmap.getPixel(halfX + 10, halfY - 10)); assertEquals(Color.RED, bitmap.getPixel(halfX - 10, halfY + 10)); assertEquals(Color.RED, bitmap.getPixel(halfX + 10, halfY + 10)); assertEquals(Color.BLUE, bitmap.getPixel(halfX - 5, halfY - 5)); assertEquals(Color.RED, bitmap.getPixel(halfX + 5, halfY - 5)); assertEquals(Color.RED, bitmap.getPixel(halfX - 5, halfY + 5)); assertEquals(Color.RED, bitmap.getPixel(halfX + 5, halfY + 5)); } @Test Loading @@ -113,7 +113,7 @@ public class ContentResolverTest { assertEquals(1280, res.getWidth()); assertEquals(960, res.getHeight()); assertImageAspectAndContents(res); assertImageAspectAndContents(1280, 960, res); } @Test Loading @@ -128,7 +128,7 @@ public class ContentResolverTest { assertTrue(res.getWidth() <= 640); assertTrue(res.getHeight() <= 480); assertImageAspectAndContents(res); assertImageAspectAndContents(1280, 960, res); } @Test Loading @@ -143,7 +143,7 @@ public class ContentResolverTest { assertTrue(res.getWidth() <= 640); assertTrue(res.getHeight() <= 480); assertImageAspectAndContents(res); assertImageAspectAndContents(1280, 960, res); } @Test Loading @@ -158,7 +158,23 @@ public class ContentResolverTest { assertEquals(32, res.getWidth()); assertEquals(24, res.getHeight()); assertImageAspectAndContents(res); assertImageAspectAndContents(32, 24, res); } @Test public void testLoadThumbnail_Large() throws Exception { // Test very large and extreme ratio image initImage(1080, 30000); Bitmap res = ContentResolver.loadThumbnail(mClient, Uri.parse("content://com.example/"), new Size(1080, 540), null, ImageDecoder.ALLOCATOR_SOFTWARE); // Size should be much smaller assertTrue(res.getWidth() <= 2160); assertTrue(res.getHeight() <= 1080); assertImageAspectAndContents(1080, 30000, res); } @Test Loading Loading
core/java/android/content/ContentResolver.java +13 −13 Original line number Diff line number Diff line Loading @@ -3658,7 +3658,7 @@ public abstract class ContentResolver implements ContentInterface { // returned something giant, so defensively scale down as needed. final int widthSample = info.getSize().getWidth() / size.getWidth(); final int heightSample = info.getSize().getHeight() / size.getHeight(); final int sample = Math.min(widthSample, heightSample); final int sample = Math.max(widthSample, heightSample); if (sample > 1) { decoder.setTargetSampleSize(sample); } Loading
core/tests/coretests/src/android/content/ContentResolverTest.java +26 −10 Original line number Diff line number Diff line Loading @@ -86,19 +86,19 @@ public class ContentResolverTest { afd); } private static void assertImageAspectAndContents(Bitmap bitmap) { private static void assertImageAspectAndContents(int width, int height, Bitmap bitmap) { // And correct aspect ratio final int before = (100 * 1280) / 960; final int before = (100 * width) / height; final int after = (100 * bitmap.getWidth()) / bitmap.getHeight(); assertEquals(before, after); // And scaled correctly final int halfX = bitmap.getWidth() / 2; final int halfY = bitmap.getHeight() / 2; assertEquals(Color.BLUE, bitmap.getPixel(halfX - 10, halfY - 10)); assertEquals(Color.RED, bitmap.getPixel(halfX + 10, halfY - 10)); assertEquals(Color.RED, bitmap.getPixel(halfX - 10, halfY + 10)); assertEquals(Color.RED, bitmap.getPixel(halfX + 10, halfY + 10)); assertEquals(Color.BLUE, bitmap.getPixel(halfX - 5, halfY - 5)); assertEquals(Color.RED, bitmap.getPixel(halfX + 5, halfY - 5)); assertEquals(Color.RED, bitmap.getPixel(halfX - 5, halfY + 5)); assertEquals(Color.RED, bitmap.getPixel(halfX + 5, halfY + 5)); } @Test Loading @@ -113,7 +113,7 @@ public class ContentResolverTest { assertEquals(1280, res.getWidth()); assertEquals(960, res.getHeight()); assertImageAspectAndContents(res); assertImageAspectAndContents(1280, 960, res); } @Test Loading @@ -128,7 +128,7 @@ public class ContentResolverTest { assertTrue(res.getWidth() <= 640); assertTrue(res.getHeight() <= 480); assertImageAspectAndContents(res); assertImageAspectAndContents(1280, 960, res); } @Test Loading @@ -143,7 +143,7 @@ public class ContentResolverTest { assertTrue(res.getWidth() <= 640); assertTrue(res.getHeight() <= 480); assertImageAspectAndContents(res); assertImageAspectAndContents(1280, 960, res); } @Test Loading @@ -158,7 +158,23 @@ public class ContentResolverTest { assertEquals(32, res.getWidth()); assertEquals(24, res.getHeight()); assertImageAspectAndContents(res); assertImageAspectAndContents(32, 24, res); } @Test public void testLoadThumbnail_Large() throws Exception { // Test very large and extreme ratio image initImage(1080, 30000); Bitmap res = ContentResolver.loadThumbnail(mClient, Uri.parse("content://com.example/"), new Size(1080, 540), null, ImageDecoder.ALLOCATOR_SOFTWARE); // Size should be much smaller assertTrue(res.getWidth() <= 2160); assertTrue(res.getHeight() <= 1080); assertImageAspectAndContents(1080, 30000, res); } @Test Loading