summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/data/DecodeUtils.java
diff options
context:
space:
mode:
authorOwen Lin <owenlin@google.com>2011-08-30 10:38:59 +0800
committerOwen Lin <owenlin@google.com>2011-09-05 11:28:18 +0800
commitace280a70fd1ead67039b9667d3905c85703c094 (patch)
treeadd5ae4895e61f13a9b55c91b9890bb6ecc9a58e /src/com/android/gallery3d/data/DecodeUtils.java
parent9c12d7512df688131384328fb6ffb89b36cc4393 (diff)
downloadandroid_packages_apps_Snap-ace280a70fd1ead67039b9667d3905c85703c094.tar.gz
android_packages_apps_Snap-ace280a70fd1ead67039b9667d3905c85703c094.tar.bz2
android_packages_apps_Snap-ace280a70fd1ead67039b9667d3905c85703c094.zip
Improve the performance of Reviewing a photo.
fix: 5144370 There is two componenet in the photo page. One is the large photo and the other is the thumbnail strip. They idenpendently load their own data and images. This change fixes several issues here: 1. Prevent sending to many jobs to ThreadPool and block others. In a worse case, if the thumbnail strip send image requests first, it may block the ThreadPool very long. 2. Improve the performance of extracting thumbnails from local files. Now we try to extract the thumbnails from EXIF data first. Change-Id: I45100d4daa025efb479f47c4f105de2b4731b498
Diffstat (limited to 'src/com/android/gallery3d/data/DecodeUtils.java')
-rw-r--r--src/com/android/gallery3d/data/DecodeUtils.java25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/com/android/gallery3d/data/DecodeUtils.java b/src/com/android/gallery3d/data/DecodeUtils.java
index da2d3e0ee..d2b4ebc4e 100644
--- a/src/com/android/gallery3d/data/DecodeUtils.java
+++ b/src/com/android/gallery3d/data/DecodeUtils.java
@@ -106,6 +106,31 @@ public class DecodeUtils {
BitmapFactory.decodeFileDescriptor(fd, null, options));
}
+ /**
+ * Decodes the bitmap from the given byte array if the image size is larger than the given
+ * requirement.
+ *
+ * Note: The returned image may be resized down. However, both width and heigh must be
+ * larger than the <code>targetSize</code>.
+ */
+ public static Bitmap requestDecodeIfBigEnough(JobContext jc, byte[] data,
+ Options options, int targetSize) {
+ if (options == null) options = new Options();
+ jc.setCancelListener(new DecodeCanceller(options));
+
+ options.inJustDecodeBounds = true;
+ BitmapFactory.decodeByteArray(data, 0, data.length, options);
+ if (jc.isCancelled()) return null;
+ if (options.outWidth < targetSize || options.outHeight < targetSize) {
+ return null;
+ }
+ options.inSampleSize = BitmapUtils.computeSampleSizeLarger(
+ options.outWidth, options.outHeight, targetSize);
+ options.inJustDecodeBounds = false;
+ return ensureGLCompatibleBitmap(
+ BitmapFactory.decodeByteArray(data, 0, data.length, options));
+ }
+
public static Bitmap requestDecode(JobContext jc,
FileDescriptor fileDescriptor, Rect paddings, Options options) {
if (options == null) options = new Options();