diff options
author | Owen Lin <owenlin@google.com> | 2011-08-29 15:29:56 +0800 |
---|---|---|
committer | Owen Lin <owenlin@google.com> | 2011-08-29 15:39:12 +0800 |
commit | b60402ba7551478d324fb777bb5f45b11dffe37c (patch) | |
tree | 073704bac4ebeb19d881c1dcd8496bd48f02551e /src/com/android/gallery3d/app/SinglePhotoDataAdapter.java | |
parent | ea6afaebe071ada8439ad88ee3d892cae4391bfd (diff) | |
download | android_packages_apps_Snap-b60402ba7551478d324fb777bb5f45b11dffe37c.tar.gz android_packages_apps_Snap-b60402ba7551478d324fb777bb5f45b11dffe37c.tar.bz2 android_packages_apps_Snap-b60402ba7551478d324fb777bb5f45b11dffe37c.zip |
Make sure the sides of a backup image are less than 1024.
fix: 5117367
In this case(5117367), the original backup image would be 2325x1029,
which exceeds the limit of an texture and thus shows a blank image.
Change-Id: I3176e191c68199308fe3770c10ee0ae2d310c96a
Diffstat (limited to 'src/com/android/gallery3d/app/SinglePhotoDataAdapter.java')
-rw-r--r-- | src/com/android/gallery3d/app/SinglePhotoDataAdapter.java | 51 |
1 files changed, 29 insertions, 22 deletions
diff --git a/src/com/android/gallery3d/app/SinglePhotoDataAdapter.java b/src/com/android/gallery3d/app/SinglePhotoDataAdapter.java index 11e0013cc..54183e006 100644 --- a/src/com/android/gallery3d/app/SinglePhotoDataAdapter.java +++ b/src/com/android/gallery3d/app/SinglePhotoDataAdapter.java @@ -39,14 +39,12 @@ public class SinglePhotoDataAdapter extends TileImageViewAdapter implements PhotoPage.Model { private static final String TAG = "SinglePhotoDataAdapter"; - private static final int SIZE_BACKUP = 640; + private static final int SIZE_BACKUP = 1024; private static final int MSG_UPDATE_IMAGE = 1; private MediaItem mItem; private boolean mHasFullImage; private Future<?> mTask; - private BitmapRegionDecoder mDecoder; - private Bitmap mBackup; private Handler mHandler; private PhotoView mPhotoView; @@ -64,8 +62,7 @@ public class SinglePhotoDataAdapter extends TileImageViewAdapter public void handleMessage(Message message) { Utils.assertTrue(message.what == MSG_UPDATE_IMAGE); if (mHasFullImage) { - onDecodeLargeComplete((Future<BitmapRegionDecoder>) - message.obj); + onDecodeLargeComplete((ImageBundle) message.obj); } else { onDecodeThumbComplete((Future<Bitmap>) message.obj); } @@ -74,11 +71,29 @@ public class SinglePhotoDataAdapter extends TileImageViewAdapter mThreadPool = activity.getThreadPool(); } + private static class ImageBundle { + public final BitmapRegionDecoder decoder; + public final Bitmap backupImage; + + public ImageBundle(BitmapRegionDecoder decoder, Bitmap backupImage) { + this.decoder = decoder; + this.backupImage = backupImage; + } + } + private FutureListener<BitmapRegionDecoder> mLargeListener = new FutureListener<BitmapRegionDecoder>() { public void onFutureDone(Future<BitmapRegionDecoder> future) { - mHandler.sendMessage( - mHandler.obtainMessage(MSG_UPDATE_IMAGE, future)); + BitmapRegionDecoder decoder = future.get(); + if (decoder == null) return; + int width = decoder.getWidth(); + int height = decoder.getHeight(); + BitmapFactory.Options options = new BitmapFactory.Options(); + options.inSampleSize = BitmapUtils.computeSampleSize( + (float) SIZE_BACKUP / Math.max(width, height)); + Bitmap bitmap = decoder.decodeRegion(new Rect(0, 0, width, height), options); + mHandler.sendMessage(mHandler.obtainMessage( + MSG_UPDATE_IMAGE, new ImageBundle(decoder, bitmap))); } }; @@ -98,19 +113,11 @@ public class SinglePhotoDataAdapter extends TileImageViewAdapter return mItem.getRotation(); } - private void onDecodeLargeComplete(Future<BitmapRegionDecoder> future) { + private void onDecodeLargeComplete(ImageBundle bundle) { try { - mDecoder = future.get(); - if (mDecoder == null) return; - int width = mDecoder.getWidth(); - int height = mDecoder.getHeight(); - BitmapFactory.Options options = new BitmapFactory.Options(); - options.inSampleSize = BitmapUtils.computeSampleSizeLarger( - width, height, SIZE_BACKUP); - mBackup = mDecoder.decodeRegion( - new Rect(0, 0, width, height), options); - setBackupImage(mBackup, width, height); - setRegionDecoder(mDecoder); + setBackupImage(bundle.backupImage, + bundle.decoder.getWidth(), bundle.decoder.getHeight()); + setRegionDecoder(bundle.decoder); mPhotoView.notifyImageInvalidated(0); } catch (Throwable t) { Log.w(TAG, "fail to decode large", t); @@ -119,9 +126,9 @@ public class SinglePhotoDataAdapter extends TileImageViewAdapter private void onDecodeThumbComplete(Future<Bitmap> future) { try { - mBackup = future.get(); - if (mBackup == null) return; - setBackupImage(mBackup, mBackup.getWidth(), mBackup.getHeight()); + Bitmap backup = future.get(); + if (backup == null) return; + setBackupImage(backup, backup.getWidth(), backup.getHeight()); mPhotoView.notifyOnNewImage(); mPhotoView.notifyImageInvalidated(0); // the current image } catch (Throwable t) { |