diff options
Diffstat (limited to 'src/com/android/gallery3d/data')
-rw-r--r-- | src/com/android/gallery3d/data/DecodeUtils.java | 25 | ||||
-rw-r--r-- | src/com/android/gallery3d/data/LocalImage.java | 22 |
2 files changed, 46 insertions, 1 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(); diff --git a/src/com/android/gallery3d/data/LocalImage.java b/src/com/android/gallery3d/data/LocalImage.java index f3dedf037..7ab04c568 100644 --- a/src/com/android/gallery3d/data/LocalImage.java +++ b/src/com/android/gallery3d/data/LocalImage.java @@ -18,10 +18,10 @@ package com.android.gallery3d.data; import com.android.gallery3d.app.GalleryApp; import com.android.gallery3d.common.BitmapUtils; -import com.android.gallery3d.util.UpdateHelper; import com.android.gallery3d.util.GalleryUtils; import com.android.gallery3d.util.ThreadPool.Job; import com.android.gallery3d.util.ThreadPool.JobContext; +import com.android.gallery3d.util.UpdateHelper; import android.content.ContentResolver; import android.content.ContentValues; @@ -33,6 +33,7 @@ import android.media.ExifInterface; import android.net.Uri; import android.provider.MediaStore.Images; import android.provider.MediaStore.Images.ImageColumns; +import android.util.Log; import java.io.File; import java.io.IOException; @@ -158,6 +159,25 @@ public class LocalImage extends LocalMediaItem { public Bitmap onDecodeOriginal(JobContext jc, int type) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Bitmap.Config.ARGB_8888; + + // try to decode from JPEG EXIF + if (type == MediaItem.TYPE_MICROTHUMBNAIL) { + ExifInterface exif = null; + byte [] thumbData = null; + try { + exif = new ExifInterface(mLocalFilePath); + if (exif != null) { + thumbData = exif.getThumbnail(); + } + } catch (Throwable t) { + Log.w(TAG, "fail to get exif thumb", t); + } + if (thumbData != null) { + Bitmap bitmap = DecodeUtils.requestDecodeIfBigEnough( + jc, thumbData, options, getTargetSize(type)); + if (bitmap != null) return bitmap; + } + } return DecodeUtils.requestDecode( jc, mLocalFilePath, options, getTargetSize(type)); } |