summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWei-Ta Chen <weita@google.com>2009-08-12 21:00:23 +0800
committerWei-Ta Chen <weita@google.com>2009-08-13 14:49:00 +0800
commit3c21008c953cf6177f7771c176fa81d336e74ed8 (patch)
tree9211ba1d2c909607fa5016da60d64b74b2d87a16 /src
parent781f55b23ec3c3f97189efaba9d214183109f769 (diff)
downloadpackages_apps_LegacyCamera-3c21008c953cf6177f7771c176fa81d336e74ed8.zip
packages_apps_LegacyCamera-3c21008c953cf6177f7771c176fa81d336e74ed8.tar.gz
packages_apps_LegacyCamera-3c21008c953cf6177f7771c176fa81d336e74ed8.tar.bz2
Fix http://b/issue?id=2048408.
(1) Set default maximum numbers of pixels for thumbails and mini thumbnails. (2) Enfore computeSampleSize() to return a sample size that is either power of 2 or multiple of 8.
Diffstat (limited to 'src')
-rw-r--r--src/com/android/camera/BitmapManager.java1
-rw-r--r--src/com/android/camera/Util.java30
-rw-r--r--src/com/android/camera/gallery/BaseImageList.java7
-rw-r--r--src/com/android/camera/gallery/DrmImageList.java4
-rw-r--r--src/com/android/camera/gallery/IImage.java3
-rw-r--r--src/com/android/camera/gallery/Image.java4
-rw-r--r--src/com/android/camera/gallery/UriImage.java2
-rw-r--r--src/com/android/camera/gallery/VideoObject.java3
8 files changed, 39 insertions, 15 deletions
diff --git a/src/com/android/camera/BitmapManager.java b/src/com/android/camera/BitmapManager.java
index eb05d3e..cb327e8 100644
--- a/src/com/android/camera/BitmapManager.java
+++ b/src/com/android/camera/BitmapManager.java
@@ -22,7 +22,6 @@ import android.util.Log;
import java.io.FileDescriptor;
import java.util.Iterator;
-import java.util.Map;
import java.util.WeakHashMap;
/**
diff --git a/src/com/android/camera/Util.java b/src/com/android/camera/Util.java
index 9e5c74e..61e1923 100644
--- a/src/com/android/camera/Util.java
+++ b/src/com/android/camera/Util.java
@@ -74,18 +74,42 @@ public class Util {
/*
* Compute the sample size as a function of minSideLength
* and maxNumOfPixels.
- * minSideLength is used to specify that minimal width or height of a bitmap.
- * maxNumOfPixels is used to specify the maximal size in pixels that are tolerable
- * in terms of memory usage.
+ * minSideLength is used to specify that minimal width or height of a
+ * bitmap.
+ * maxNumOfPixels is used to specify the maximal size in pixels that is
+ * tolerable in terms of memory usage.
*
* The function returns a sample size based on the constraints.
* Both size and minSideLength can be passed in as IImage.UNCONSTRAINED,
* which indicates no care of the corresponding constraint.
* The functions prefers returning a sample size that
* generates a smaller bitmap, unless minSideLength = IImage.UNCONSTRAINED.
+ *
+ * Also, the function rounds up the sample size to a power of 2 or multiple
+ * of 8 because BitmapFactory only honors sample size this way.
+ * For example, BitmapFactory downsamples an image by 2 even though the
+ * request is 3. So we round up the sample size to avoid OOM.
*/
public static int computeSampleSize(BitmapFactory.Options options,
int minSideLength, int maxNumOfPixels) {
+ int initialSize = computeInitialSampleSize(options, minSideLength,
+ maxNumOfPixels);
+
+ int roundedSize;
+ if (initialSize <= 8 ) {
+ roundedSize = 1;
+ while (roundedSize < initialSize) {
+ roundedSize <<= 1;
+ }
+ } else {
+ roundedSize = (initialSize + 7) / 8 * 8;
+ }
+
+ return roundedSize;
+ }
+
+ private static int computeInitialSampleSize(BitmapFactory.Options options,
+ int minSideLength, int maxNumOfPixels) {
double w = options.outWidth;
double h = options.outHeight;
diff --git a/src/com/android/camera/gallery/BaseImageList.java b/src/com/android/camera/gallery/BaseImageList.java
index 55a12c0..b440130 100644
--- a/src/com/android/camera/gallery/BaseImageList.java
+++ b/src/com/android/camera/gallery/BaseImageList.java
@@ -231,7 +231,8 @@ public abstract class BaseImageList implements IImageList {
// and is significantly faster.
options.inSampleSize =
Util.computeSampleSize(options,
- IImage.MINI_THUMB_TARGET_SIZE, IImage.UNCONSTRAINED);
+ IImage.MINI_THUMB_TARGET_SIZE,
+ IImage.MINI_THUMB_MAX_NUM_PIXELS);
options.inDither = false;
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
options.inJustDecodeBounds = false;
@@ -246,12 +247,12 @@ public abstract class BaseImageList implements IImageList {
// create the minithumb from it.
private Bitmap createThumbnailFromUri(Uri uri, long id) {
Bitmap bitmap = Util.makeBitmap(IImage.THUMBNAIL_TARGET_SIZE,
- IImage.UNCONSTRAINED, uri, mContentResolver);
+ IImage.THUMBNAIL_MAX_NUM_PIXELS, uri, mContentResolver);
if (bitmap != null) {
storeThumbnail(bitmap, id);
} else {
bitmap = Util.makeBitmap(IImage.MINI_THUMB_TARGET_SIZE,
- IImage.UNCONSTRAINED, uri, mContentResolver);
+ IImage.MINI_THUMB_MAX_NUM_PIXELS, uri, mContentResolver);
}
return bitmap;
}
diff --git a/src/com/android/camera/gallery/DrmImageList.java b/src/com/android/camera/gallery/DrmImageList.java
index 445d867..feea00c 100644
--- a/src/com/android/camera/gallery/DrmImageList.java
+++ b/src/com/android/camera/gallery/DrmImageList.java
@@ -99,13 +99,13 @@ public class DrmImageList extends ImageList implements IImageList {
@Override
public Bitmap miniThumbBitmap() {
return fullSizeBitmap(IImage.MINI_THUMB_TARGET_SIZE,
- IImage.UNCONSTRAINED);
+ IImage.MINI_THUMB_MAX_NUM_PIXELS);
}
@Override
public Bitmap thumbBitmap(boolean rotateAsNeeded) {
return fullSizeBitmap(IImage.THUMBNAIL_TARGET_SIZE,
- IImage.UNCONSTRAINED);
+ IImage.THUMBNAIL_MAX_NUM_PIXELS);
}
@Override
diff --git a/src/com/android/camera/gallery/IImage.java b/src/com/android/camera/gallery/IImage.java
index 50a3aba..f93d539 100644
--- a/src/com/android/camera/gallery/IImage.java
+++ b/src/com/android/camera/gallery/IImage.java
@@ -17,7 +17,6 @@
package com.android.camera.gallery;
import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
import android.net.Uri;
import java.io.InputStream;
@@ -28,6 +27,8 @@ import java.io.InputStream;
public interface IImage {
static final int THUMBNAIL_TARGET_SIZE = 320;
static final int MINI_THUMB_TARGET_SIZE = 96;
+ static final int THUMBNAIL_MAX_NUM_PIXELS = 512 * 384;
+ static final int MINI_THUMB_MAX_NUM_PIXELS = 128 * 128;
static final int UNCONSTRAINED = -1;
/** Get the image list which contains this image. */
diff --git a/src/com/android/camera/gallery/Image.java b/src/com/android/camera/gallery/Image.java
index aab9545..3102a7b 100644
--- a/src/com/android/camera/gallery/Image.java
+++ b/src/com/android/camera/gallery/Image.java
@@ -217,8 +217,8 @@ public class Image extends BaseImage implements IImage {
}
if (bitmap == null) {
- bitmap = fullSizeBitmap(THUMBNAIL_TARGET_SIZE, IImage.UNCONSTRAINED,
- IImage.NO_ROTATE, IImage.NO_NATIVE);
+ bitmap = fullSizeBitmap(THUMBNAIL_TARGET_SIZE,
+ THUMBNAIL_MAX_NUM_PIXELS, NO_ROTATE, NO_NATIVE);
// No thumbnail found... storing the new one.
bitmap = mContainer.storeThumbnail(bitmap, mId);
}
diff --git a/src/com/android/camera/gallery/UriImage.java b/src/com/android/camera/gallery/UriImage.java
index a53dd79..e09dae7 100644
--- a/src/com/android/camera/gallery/UriImage.java
+++ b/src/com/android/camera/gallery/UriImage.java
@@ -122,7 +122,7 @@ class UriImage implements IImage {
}
public Bitmap thumbBitmap(boolean rotateAsNeeded) {
- return fullSizeBitmap(THUMBNAIL_TARGET_SIZE, IImage.UNCONSTRAINED,
+ return fullSizeBitmap(THUMBNAIL_TARGET_SIZE, THUMBNAIL_MAX_NUM_PIXELS,
rotateAsNeeded);
}
diff --git a/src/com/android/camera/gallery/VideoObject.java b/src/com/android/camera/gallery/VideoObject.java
index bb499f9..61dbd8e 100644
--- a/src/com/android/camera/gallery/VideoObject.java
+++ b/src/com/android/camera/gallery/VideoObject.java
@@ -20,7 +20,6 @@ import com.android.camera.Util;
import android.content.ContentResolver;
import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
import android.net.Uri;
import java.io.IOException;
@@ -108,7 +107,7 @@ public class VideoObject extends BaseImage implements IImage {
}
public Bitmap thumbBitmap(boolean rotateAsNeeded) {
- return fullSizeBitmap(THUMBNAIL_TARGET_SIZE, UNCONSTRAINED);
+ return fullSizeBitmap(THUMBNAIL_TARGET_SIZE, THUMBNAIL_MAX_NUM_PIXELS);
}
@Override