diff options
-rw-r--r-- | gallerycommon/src/com/android/gallery3d/common/BitmapUtils.java | 1 | ||||
-rw-r--r-- | src/com/android/gallery3d/app/PhotoDataAdapter.java | 26 | ||||
-rw-r--r-- | src/com/android/gallery3d/data/MediaItem.java | 6 |
3 files changed, 31 insertions, 2 deletions
diff --git a/gallerycommon/src/com/android/gallery3d/common/BitmapUtils.java b/gallerycommon/src/com/android/gallery3d/common/BitmapUtils.java index 0686fe8cf..aaf4f6665 100644 --- a/gallerycommon/src/com/android/gallery3d/common/BitmapUtils.java +++ b/gallerycommon/src/com/android/gallery3d/common/BitmapUtils.java @@ -203,6 +203,7 @@ public class BitmapUtils { } public static Bitmap rotateBitmap(Bitmap source, int rotation, boolean recycle) { + if (rotation == 0) return source; int w = source.getWidth(); int h = source.getHeight(); Matrix m = new Matrix(); diff --git a/src/com/android/gallery3d/app/PhotoDataAdapter.java b/src/com/android/gallery3d/app/PhotoDataAdapter.java index b976dec84..9b1c8c4c0 100644 --- a/src/com/android/gallery3d/app/PhotoDataAdapter.java +++ b/src/com/android/gallery3d/app/PhotoDataAdapter.java @@ -16,6 +16,7 @@ package com.android.gallery3d.app; +import com.android.gallery3d.common.BitmapUtils; import com.android.gallery3d.common.Utils; import com.android.gallery3d.data.ContentListener; import com.android.gallery3d.data.DataManager; @@ -30,6 +31,8 @@ import com.android.gallery3d.ui.TileImageViewAdapter; import com.android.gallery3d.util.Future; import com.android.gallery3d.util.FutureListener; import com.android.gallery3d.util.ThreadPool; +import com.android.gallery3d.util.ThreadPool.Job; +import com.android.gallery3d.util.ThreadPool.JobContext; import android.graphics.Bitmap; import android.graphics.BitmapRegionDecoder; @@ -487,6 +490,25 @@ public class PhotoDataAdapter implements PhotoPage.Model { } } + private static class ScreenNailJob implements Job<Bitmap> { + private MediaItem mItem; + + public ScreenNailJob(MediaItem item) { + mItem = item; + } + + @Override + public Bitmap run(JobContext jc) { + Bitmap bitmap = mItem.requestImage(MediaItem.TYPE_THUMBNAIL).run(jc); + if (jc.isCancelled()) return null; + if (bitmap != null) { + bitmap = BitmapUtils.rotateBitmap(bitmap, + mItem.getRotation() - mItem.getFullImageRotation(), true); + } + return bitmap; + } + } + // Returns the task if we started the task or the task is already started. private Future<?> startTaskIfNeeded(int index, int which) { if (index < mActiveStart || index >= mActiveEnd) return null; @@ -507,7 +529,7 @@ public class PhotoDataAdapter implements PhotoPage.Model { && (entry.requestedBits & BIT_SCREEN_NAIL) == 0) { entry.requestedBits |= BIT_SCREEN_NAIL; entry.screenNailTask = mThreadPool.submit( - item.requestImage(MediaItem.TYPE_THUMBNAIL), + new ScreenNailJob(item), new ScreenNailListener(item.getDataVersion())); // request screen nail return entry.screenNailTask; @@ -547,7 +569,7 @@ public class PhotoDataAdapter implements PhotoPage.Model { } } else { entry = new ImageEntry(); - entry.rotation = item.getRotation(); + entry.rotation = item.getFullImageRotation(); mImageCache.put(version, entry); } } diff --git a/src/com/android/gallery3d/data/MediaItem.java b/src/com/android/gallery3d/data/MediaItem.java index 430d8327d..090625192 100644 --- a/src/com/android/gallery3d/data/MediaItem.java +++ b/src/com/android/gallery3d/data/MediaItem.java @@ -63,6 +63,12 @@ public abstract class MediaItem extends MediaObject { return null; } + // The rotation of the full-resolution image. By default, it returns the value of + // getRotation(). + public int getFullImageRotation() { + return getRotation(); + } + public int getRotation() { return 0; } |