OSDN Git Service

Set the thumbnail/screennail sizes based on screensize
authorBobby Georgescu <georgescu@google.com>
Thu, 4 Oct 2012 21:04:13 +0000 (14:04 -0700)
committerBobby Georgescu <georgescu@google.com>
Fri, 5 Oct 2012 22:28:08 +0000 (15:28 -0700)
Bug: 7232758
Prior to this CL, the thumbnail and screennail sizes were
hardcoded which resulted in mediocre image quality when
using the Gallery in general and the camera filmstrip.
Now, we set the size of these items based on the resolution
of the display. Because high-resolution devices tend to
have higher-performance graphics to drive their large
displays, we expect that this will not introduce any
significant performance impact.

Change-Id: I90e08f7aca670e275c913fd9e21e4459c8bf9fcf

src/com/android/gallery3d/data/ImageCacheService.java
src/com/android/gallery3d/data/MediaItem.java
src/com/android/gallery3d/ui/BitmapScreenNail.java
src/com/android/gallery3d/util/GalleryUtils.java

index 0e79313..f10a7b3 100644 (file)
@@ -35,7 +35,7 @@ public class ImageCacheService {
     private static final String IMAGE_CACHE_FILE = "imgcache";
     private static final int IMAGE_CACHE_MAX_ENTRIES = 5000;
     private static final int IMAGE_CACHE_MAX_BYTES = 200 * 1024 * 1024;
-    private static final int IMAGE_CACHE_VERSION = 4;
+    private static final int IMAGE_CACHE_VERSION = 5;
 
     private BlobCache mCache;
 
index 9d2040a..77b86b8 100644 (file)
@@ -30,8 +30,6 @@ public abstract class MediaItem extends MediaObject {
     public static final int TYPE_THUMBNAIL = 1;
     public static final int TYPE_MICROTHUMBNAIL = 2;
 
-    public static final int THUMBNAIL_TARGET_SIZE = 640;
-    public static final int MICROTHUMBNAIL_TARGET_SIZE = 200;
     public static final int CACHED_IMAGE_QUALITY = 95;
 
     public static final int IMAGE_READY = 0;
@@ -43,19 +41,17 @@ public abstract class MediaItem extends MediaObject {
     private static final int BYTESBUFFE_POOL_SIZE = 4;
     private static final int BYTESBUFFER_SIZE = 200 * 1024;
 
-    private static final BitmapPool sMicroThumbPool =
-            ApiHelper.HAS_REUSING_BITMAP_IN_BITMAP_FACTORY
-            ? new BitmapPool(MICROTHUMBNAIL_TARGET_SIZE, MICROTHUMBNAIL_TARGET_SIZE, 16)
-            : null;
+    private static int sMicrothumbnailTargetSize = 200;
+    private static BitmapPool sMicroThumbPool;
+    private static final BytesBufferPool sMicroThumbBufferPool =
+            new BytesBufferPool(BYTESBUFFE_POOL_SIZE, BYTESBUFFER_SIZE);
 
+    private static int sThumbnailTargetSize = 640;
     private static final BitmapPool sThumbPool =
             ApiHelper.HAS_REUSING_BITMAP_IN_BITMAP_FACTORY
             ? new BitmapPool(4)
             : null;
 
-    private static final BytesBufferPool sMicroThumbBufferPool =
-            new BytesBufferPool(BYTESBUFFE_POOL_SIZE, BYTESBUFFER_SIZE);
-
     // TODO: fix default value for latlng and change this.
     public static final double INVALID_LATLNG = 0f;
 
@@ -125,9 +121,9 @@ public abstract class MediaItem extends MediaObject {
     public static int getTargetSize(int type) {
         switch (type) {
             case TYPE_THUMBNAIL:
-                return THUMBNAIL_TARGET_SIZE;
+                return sThumbnailTargetSize;
             case TYPE_MICROTHUMBNAIL:
-                return MICROTHUMBNAIL_TARGET_SIZE;
+                return sMicrothumbnailTargetSize;
             default:
                 throw new RuntimeException(
                     "should only request thumb/microthumb from cache");
@@ -135,6 +131,9 @@ public abstract class MediaItem extends MediaObject {
     }
 
     public static BitmapPool getMicroThumbPool() {
+        if (ApiHelper.HAS_REUSING_BITMAP_IN_BITMAP_FACTORY && sMicroThumbPool == null) {
+            initializeMicroThumbPool();
+        }
         return sMicroThumbPool;
     }
 
@@ -145,4 +144,19 @@ public abstract class MediaItem extends MediaObject {
     public static BytesBufferPool getBytesBufferPool() {
         return sMicroThumbBufferPool;
     }
+
+    private static void initializeMicroThumbPool() {
+        sMicroThumbPool =
+                ApiHelper.HAS_REUSING_BITMAP_IN_BITMAP_FACTORY
+                ? new BitmapPool(sMicrothumbnailTargetSize, sMicrothumbnailTargetSize, 16)
+                : null;
+    }
+
+    public static void setThumbnailSizes(int size, int microSize) {
+        sThumbnailTargetSize = size;
+        if (sMicrothumbnailTargetSize != microSize) {
+            sMicrothumbnailTargetSize = microSize;
+            initializeMicroThumbPool();
+        }
+    }
 }
index 25f88a1..9b62916 100644 (file)
@@ -37,7 +37,7 @@ public class BitmapScreenNail implements ScreenNail {
     // The duration of the fading animation in milliseconds
     private static final int DURATION = 180;
 
-    private static final int MAX_SIDE = 640;
+    private static int sMaxSide = 640;
 
     // These are special values for mAnimationStartTime
     private static final long ANIMATION_NOT_NEEDED = -1;
@@ -73,10 +73,10 @@ public class BitmapScreenNail implements ScreenNail {
 
     private void setSize(int width, int height) {
         if (width == 0 || height == 0) {
-            width = 640;
-            height = 480;
+            width = sMaxSide;
+            height = sMaxSide * 3 / 4;
         }
-        float scale = Math.min(1, (float) MAX_SIDE / Math.max(width, height));
+        float scale = Math.min(1, (float) sMaxSide / Math.max(width, height));
         mWidth = Math.round(scale * width);
         mHeight = Math.round(scale * height);
     }
@@ -209,4 +209,8 @@ public class BitmapScreenNail implements ScreenNail {
     public TiledTexture getTexture() {
         return mTexture;
     }
+
+    public static void setMaxSide(int size) {
+        sMaxSide = size;
+    }
 }
index efa0614..05bd3de 100644 (file)
@@ -75,16 +75,25 @@ public class GalleryUtils {
     private static boolean sCameraAvailable;
 
     public static void initialize(Context context) {
-        if (sPixelDensity < 0) {
-            DisplayMetrics metrics = new DisplayMetrics();
-            WindowManager wm = (WindowManager)
-                    context.getSystemService(Context.WINDOW_SERVICE);
-            wm.getDefaultDisplay().getMetrics(metrics);
-            sPixelDensity = metrics.density;
-        }
+        DisplayMetrics metrics = new DisplayMetrics();
+        WindowManager wm = (WindowManager)
+                context.getSystemService(Context.WINDOW_SERVICE);
+        wm.getDefaultDisplay().getMetrics(metrics);
+        sPixelDensity = metrics.density;
         Resources r = context.getResources();
         BitmapScreenNail.setPlaceholderColor(r.getColor(
                 R.color.bitmap_screennail_placeholder));
+        initializeThumbnailSizes(metrics, r);
+    }
+
+    private static void initializeThumbnailSizes(DisplayMetrics metrics, Resources r) {
+        int minRows = Math.min(r.getInteger(R.integer.album_rows_land),
+                r.getInteger(R.integer.albumset_rows_land));
+        int maxDimensionPixels = Math.max(metrics.heightPixels, metrics.widthPixels);
+        // Never need to completely fill the screen
+        maxDimensionPixels = maxDimensionPixels * 3/4;
+        MediaItem.setThumbnailSizes(maxDimensionPixels, maxDimensionPixels / minRows);
+        BitmapScreenNail.setMaxSide(maxDimensionPixels);
     }
 
     public static boolean isHighResolution(Context context) {