summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicolasroard <nicolasroard@google.com>2013-07-02 15:02:43 -0700
committernicolasroard <nicolasroard@google.com>2013-07-02 15:12:27 -0700
commit68ce09f03fdf73c48295d3d2b6615b21d72b1399 (patch)
tree98c0ca3cf2766fdee0b41f6f355a7ff11ad91a0a
parentdbc7b1ebe939d68cbc7f01878e038ca3e9c35f89 (diff)
downloadandroid_packages_apps_Snap-68ce09f03fdf73c48295d3d2b6615b21d72b1399.zip
android_packages_apps_Snap-68ce09f03fdf73c48295d3d2b6615b21d72b1399.tar.gz
android_packages_apps_Snap-68ce09f03fdf73c48295d3d2b6615b21d72b1399.tar.bz2
Speed up load times
Compute the small res image on the fly Load the high res preview image after first load Change-Id: Icc556c2204cb4fd25766d90064a5756c877b11cc
-rw-r--r--src/com/android/gallery3d/filtershow/FilterShowActivity.java25
-rw-r--r--src/com/android/gallery3d/filtershow/cache/CachingPipeline.java4
-rw-r--r--src/com/android/gallery3d/filtershow/cache/FilteringPipeline.java4
-rw-r--r--src/com/android/gallery3d/filtershow/cache/ImageLoader.java36
4 files changed, 46 insertions, 23 deletions
diff --git a/src/com/android/gallery3d/filtershow/FilterShowActivity.java b/src/com/android/gallery3d/filtershow/FilterShowActivity.java
index 8302893..0d9205a 100644
--- a/src/com/android/gallery3d/filtershow/FilterShowActivity.java
+++ b/src/com/android/gallery3d/filtershow/FilterShowActivity.java
@@ -498,6 +498,24 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
mCategoryBordersAdapter.reflectImagePreset(preset);
}
+ private class LoadHighresBitmapTask extends AsyncTask<Void, Void, Boolean> {
+ @Override
+ protected Boolean doInBackground(Void... params) {
+ mImageLoader.loadHighResBitmap();
+ return true;
+ }
+
+ @Override
+ protected void onPostExecute(Boolean result) {
+ Bitmap highresBitmap = mImageLoader.getOriginalBitmapHighres();
+ if (highresBitmap != null) {
+ FilteringPipeline pipeline = FilteringPipeline.getPipeline();
+ float highResPreviewScale = (float) highresBitmap.getWidth() / (float) mImageLoader.getOriginalBounds().width();
+ pipeline.setHighResPreviewScaleFactor(highResPreviewScale);
+ }
+ }
+ }
+
private class LoadBitmapTask extends AsyncTask<Uri, Boolean, Boolean> {
int mBitmapSize;
@@ -550,11 +568,6 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
pipeline.setOriginal(largeBitmap);
float previewScale = (float) largeBitmap.getWidth() / (float) mImageLoader.getOriginalBounds().width();
pipeline.setPreviewScaleFactor(previewScale);
- Bitmap highresBitmap = mImageLoader.getOriginalBitmapHighres();
- if (highresBitmap != null) {
- float highResPreviewScale = (float) highresBitmap.getWidth() / (float) mImageLoader.getOriginalBounds().width();
- pipeline.setHighResPreviewScaleFactor(highResPreviewScale);
- }
if (!mShowingTinyPlanet) {
mCategoryFiltersAdapter.removeTinyPlanet();
}
@@ -578,6 +591,8 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
}
mLoading = false;
MasterImage.getImage().notifyGeometryChange();
+ LoadHighresBitmapTask highresLoad = new LoadHighresBitmapTask();
+ highresLoad.execute();
super.onPostExecute(result);
}
diff --git a/src/com/android/gallery3d/filtershow/cache/CachingPipeline.java b/src/com/android/gallery3d/filtershow/cache/CachingPipeline.java
index dfba3f7..5a4267e 100644
--- a/src/com/android/gallery3d/filtershow/cache/CachingPipeline.java
+++ b/src/com/android/gallery3d/filtershow/cache/CachingPipeline.java
@@ -257,7 +257,9 @@ public class CachingPipeline implements PipelineInterface {
if (request.getType() == RenderingRequest.HIGHRES_RENDERING) {
ImageLoader loader = MasterImage.getImage().getImageLoader();
bitmap = loader.getOriginalBitmapHighres();
- bitmap = preset.applyGeometry(bitmap, mEnvironment);
+ if (bitmap != null) {
+ bitmap = preset.applyGeometry(bitmap, mEnvironment);
+ }
}
if (request.getType() == RenderingRequest.FULL_RENDERING
diff --git a/src/com/android/gallery3d/filtershow/cache/FilteringPipeline.java b/src/com/android/gallery3d/filtershow/cache/FilteringPipeline.java
index 7d8481f..3232db7 100644
--- a/src/com/android/gallery3d/filtershow/cache/FilteringPipeline.java
+++ b/src/com/android/gallery3d/filtershow/cache/FilteringPipeline.java
@@ -174,6 +174,10 @@ public class FilteringPipeline implements Handler.Callback {
}
if (request.getType() == RenderingRequest.HIGHRES_RENDERING) {
type = COMPUTE_HIGHRES_RENDERING_REQUEST;
+ ImageLoader imageLoader = MasterImage.getImage().getImageLoader();
+ if (imageLoader.getOriginalBitmapHighres() == null) {
+ return;
+ }
}
Message msg = mProcessingHandler.obtainMessage(type);
msg.obj = request;
diff --git a/src/com/android/gallery3d/filtershow/cache/ImageLoader.java b/src/com/android/gallery3d/filtershow/cache/ImageLoader.java
index 8513b1c..a7149d1 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();
}
};