From b60402ba7551478d324fb777bb5f45b11dffe37c Mon Sep 17 00:00:00 2001 From: Owen Lin Date: Mon, 29 Aug 2011 15:29:56 +0800 Subject: 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 --- .../gallery3d/app/SinglePhotoDataAdapter.java | 51 ++++++++++++---------- 1 file changed, 29 insertions(+), 22 deletions(-) (limited to 'src/com/android/gallery3d/app/SinglePhotoDataAdapter.java') 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) - message.obj); + onDecodeLargeComplete((ImageBundle) message.obj); } else { onDecodeThumbComplete((Future) 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 mLargeListener = new FutureListener() { public void onFutureDone(Future 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 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 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) { -- cgit v1.2.3