diff options
author | nicolasroard <nicolasroard@google.com> | 2013-07-02 15:02:43 -0700 |
---|---|---|
committer | nicolasroard <nicolasroard@google.com> | 2013-07-02 15:12:27 -0700 |
commit | be84355fddceb9690eef752707c42457ea251e77 (patch) | |
tree | 5414dec1295733226726626a8ecda745b6d1ee99 /src/com/android/gallery3d/filtershow/cache/ImageLoader.java | |
parent | 6a2491c0afff0243b2174743937ea4be463a22b0 (diff) | |
download | android_packages_apps_Gallery2-be84355fddceb9690eef752707c42457ea251e77.tar.gz android_packages_apps_Gallery2-be84355fddceb9690eef752707c42457ea251e77.tar.bz2 android_packages_apps_Gallery2-be84355fddceb9690eef752707c42457ea251e77.zip |
Speed up load times
Compute the small res image on the fly
Load the high res preview image after first load
Change-Id: Icc556c2204cb4fd25766d90064a5756c877b11cc
Diffstat (limited to 'src/com/android/gallery3d/filtershow/cache/ImageLoader.java')
-rw-r--r-- | src/com/android/gallery3d/filtershow/cache/ImageLoader.java | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/src/com/android/gallery3d/filtershow/cache/ImageLoader.java b/src/com/android/gallery3d/filtershow/cache/ImageLoader.java index 8513b1c71..a7149d1f0 100644 --- a/src/com/android/gallery3d/filtershow/cache/ImageLoader.java +++ b/src/com/android/gallery3d/filtershow/cache/ImageLoader.java @@ -88,6 +88,7 @@ public class ImageLoader { private static int mZoomOrientation = ORI_NORMAL; static final int MAX_BITMAP_DIM = 900; + static final int SMALL_BITMAP_DIM = 160; private ReentrantLock mLoadingLock = new ReentrantLock(); @@ -104,28 +105,29 @@ public class ImageLoader { return mActivity; } + public void loadHighResBitmap() { + if (MasterImage.getImage().supportsHighRes()) { + int highresPreviewSize = mOriginalBitmapLarge.getWidth() * 2; + if (highresPreviewSize > mOriginalBounds.width()) { + highresPreviewSize = mOriginalBounds.width(); + } + mOriginalBitmapHighres = loadScaledBitmap(mUri, highresPreviewSize, false); + if (mOrientation > 1 && mOriginalBitmapHighres != null) { + mOriginalBitmapHighres = rotateToPortrait(mOriginalBitmapHighres, mOrientation); + } + warnListeners(); + } + } + public boolean loadBitmap(Uri uri, int size) { mLoadingLock.lock(); mUri = uri; mOrientation = getOrientation(mContext, uri); - mOriginalBitmapSmall = loadScaledBitmap(uri, 160); - if (mOriginalBitmapSmall == null) { - // Couldn't read the bitmap, let's exit - mLoadingLock.unlock(); - return false; - } mOriginalBitmapLarge = loadScaledBitmap(uri, size); if (mOriginalBitmapLarge == null) { mLoadingLock.unlock(); return false; } - if (MasterImage.getImage().supportsHighRes()) { - int highresPreviewSize = mOriginalBitmapLarge.getWidth() * 2; - if (highresPreviewSize > mOriginalBounds.width()) { - highresPreviewSize = mOriginalBounds.width(); - } - mOriginalBitmapHighres = loadScaledBitmap(uri, highresPreviewSize, false); - } updateBitmaps(); mLoadingLock.unlock(); return true; @@ -194,12 +196,11 @@ public class ImageLoader { private void updateBitmaps() { if (mOrientation > 1) { - mOriginalBitmapSmall = rotateToPortrait(mOriginalBitmapSmall, mOrientation); mOriginalBitmapLarge = rotateToPortrait(mOriginalBitmapLarge, mOrientation); - if (mOriginalBitmapHighres != null) { - mOriginalBitmapHighres = rotateToPortrait(mOriginalBitmapHighres, mOrientation); - } } + int sw = SMALL_BITMAP_DIM; + int sh = (int) (sw * (float) mOriginalBitmapLarge.getHeight() / (float) mOriginalBitmapLarge.getWidth()); + mOriginalBitmapSmall = Bitmap.createScaledBitmap(mOriginalBitmapLarge, sw, sh, true); mZoomOrientation = mOrientation; warnListeners(); } @@ -369,6 +370,7 @@ public class ImageLoader { ImageShow imageShow = mListeners.elementAt(i); imageShow.imageLoaded(); } + MasterImage.getImage().invalidatePreview(); } }; |