OSDN Git Service

Fix picasa images rotate incorrectly.
authorOwen Lin <owenlin@google.com>
Mon, 12 Sep 2011 04:45:16 +0000 (12:45 +0800)
committerOwen Lin <owenlin@google.com>
Mon, 12 Sep 2011 08:07:55 +0000 (16:07 +0800)
fix: 5268469

Change-Id: I58fc4a6d4a10c2952040eedee5936efa949b66e2

gallerycommon/src/com/android/gallery3d/common/BitmapUtils.java
src/com/android/gallery3d/app/PhotoDataAdapter.java
src/com/android/gallery3d/data/MediaItem.java

index 0686fe8..aaf4f66 100644 (file)
@@ -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();
index b976dec..9b1c8c4 100644 (file)
@@ -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);
             }
         }
index 430d832..0906251 100644 (file)
@@ -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;
     }