diff options
author | Chih-Chung Chang <chihchung@google.com> | 2011-09-19 19:57:35 +0800 |
---|---|---|
committer | Chih-Chung Chang <chihchung@google.com> | 2011-09-20 10:15:58 +0800 |
commit | af84ef2bc0b41c029ab1f8f589b4cf25c90331c1 (patch) | |
tree | a887966f866c036729f7247f0f75156b121e6f2e | |
parent | 9ed28cc0b7108a95aebbc3fe59671e36149d2aa7 (diff) | |
download | android_packages_apps_Snap-af84ef2bc0b41c029ab1f8f589b4cf25c90331c1.tar.gz android_packages_apps_Snap-af84ef2bc0b41c029ab1f8f589b4cf25c90331c1.tar.bz2 android_packages_apps_Snap-af84ef2bc0b41c029ab1f8f589b4cf25c90331c1.zip |
Fix 5337270: Thumbnail is not generated for large GIF images.
Change-Id: I8e2e8cafb01b2289f59b28b7e2eadae3dc5c0c50
-rw-r--r-- | gallerycommon/src/com/android/gallery3d/common/BitmapUtils.java | 11 | ||||
-rw-r--r-- | src/com/android/gallery3d/data/DecodeUtils.java | 8 |
2 files changed, 17 insertions, 2 deletions
diff --git a/gallerycommon/src/com/android/gallery3d/common/BitmapUtils.java b/gallerycommon/src/com/android/gallery3d/common/BitmapUtils.java index 060d7f32e..c34e89631 100644 --- a/gallerycommon/src/com/android/gallery3d/common/BitmapUtils.java +++ b/gallerycommon/src/com/android/gallery3d/common/BitmapUtils.java @@ -155,6 +155,17 @@ public class BitmapUtils { return resizeBitmapByScale(bitmap, scale, recycle); } + // Resize the bitmap if each side is >= targetSize * 2 + public static Bitmap resizeDownIfTooBig( + Bitmap bitmap, int targetSize, boolean recycle) { + int srcWidth = bitmap.getWidth(); + int srcHeight = bitmap.getHeight(); + float scale = Math.max( + (float) targetSize / srcWidth, (float) targetSize / srcHeight); + if (scale > 0.5f) return bitmap; + return resizeBitmapByScale(bitmap, scale, recycle); + } + // Crops a square from the center of the original image. public static Bitmap cropCenter(Bitmap bitmap, boolean recycle) { int width = bitmap.getWidth(); diff --git a/src/com/android/gallery3d/data/DecodeUtils.java b/src/com/android/gallery3d/data/DecodeUtils.java index afd5faa66..29b2aa738 100644 --- a/src/com/android/gallery3d/data/DecodeUtils.java +++ b/src/com/android/gallery3d/data/DecodeUtils.java @@ -102,8 +102,12 @@ public class DecodeUtils { options.inSampleSize = BitmapUtils.computeSampleSizeLarger( options.outWidth, options.outHeight, targetSize); options.inJustDecodeBounds = false; - return ensureGLCompatibleBitmap( - BitmapFactory.decodeFileDescriptor(fd, null, options)); + + Bitmap result = BitmapFactory.decodeFileDescriptor(fd, null, options); + // We need to resize down if the decoder does not support inSampleSize. + // (For example, GIF images.) + result = BitmapUtils.resizeDownIfTooBig(result, targetSize, true); + return ensureGLCompatibleBitmap(result); } /** |