summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
authorChet Haase <chet@google.com>2010-12-10 16:44:41 -0800
committerChet Haase <chet@google.com>2010-12-10 16:56:53 -0800
commitdecc8cd41eca3770c8f5ee13d81b9cd5f0c25ccd (patch)
treebf93b241857b5603ad6107bb0d9f2ba5f3953c4f /graphics
parent37f74cad46c6f1799aec3c52e8f47598237f43d4 (diff)
downloadframeworks_base-decc8cd41eca3770c8f5ee13d81b9cd5f0c25ccd.zip
frameworks_base-decc8cd41eca3770c8f5ee13d81b9cd5f0c25ccd.tar.gz
frameworks_base-decc8cd41eca3770c8f5ee13d81b9cd5f0c25ccd.tar.bz2
Add ability to reuse bitmaps when decoding PNG content
Change-Id: Ic74b62c6280954ff80bcf64f3989a36c7c0b5615
Diffstat (limited to 'graphics')
-rw-r--r--graphics/java/android/graphics/BitmapFactory.java23
1 files changed, 19 insertions, 4 deletions
diff --git a/graphics/java/android/graphics/BitmapFactory.java b/graphics/java/android/graphics/BitmapFactory.java
index f6a9c63..fe723f2 100644
--- a/graphics/java/android/graphics/BitmapFactory.java
+++ b/graphics/java/android/graphics/BitmapFactory.java
@@ -44,10 +44,11 @@ public class BitmapFactory {
/**
* If set, decode methods that take the Options object will attempt to
- * reuse this bitmap when loading content. This is a hint to the decoder
- * only, and the decoder may choose to create a new Bitmap instead. The
+ * reuse this bitmap when loading content. If the decode operation cannot
+ * use this bitmap, the decode method will return <code>null</code> and
+ * will throw an IllegalArgumentException. The
* current implementation necessitates that the reused bitmap be of the
- * same size as the source content and in jpeg format (whether as a
+ * same size as the source content and in jpeg or png format (whether as a
* resource or as a stream). The {@link android.graphics.Bitmap.Config
* configuration} of the reused bitmap will override the setting of
* {@link #inPreferredConfig}, if set.
@@ -389,6 +390,10 @@ public class BitmapFactory {
}
}
+ if (bm == null && opts != null && opts.inBitmap != null) {
+ throw new IllegalArgumentException("Problem decoding into existing bitmap");
+ }
+
return bm;
}
@@ -421,7 +426,11 @@ public class BitmapFactory {
if ((offset | length) < 0 || data.length < offset + length) {
throw new ArrayIndexOutOfBoundsException();
}
- return nativeDecodeByteArray(data, offset, length, opts);
+ Bitmap bm = nativeDecodeByteArray(data, offset, length, opts);
+ if (bm == null && opts != null && opts.inBitmap != null) {
+ throw new IllegalArgumentException("Problem decoding into existing bitmap");
+ }
+ return bm;
}
/**
@@ -488,6 +497,9 @@ public class BitmapFactory {
if (tempStorage == null) tempStorage = new byte[16 * 1024];
bm = nativeDecodeStream(is, tempStorage, outPadding, opts);
}
+ if (bm == null && opts != null && opts.inBitmap != null) {
+ throw new IllegalArgumentException("Problem decoding into existing bitmap");
+ }
return finishDecode(bm, outPadding, opts);
}
@@ -558,6 +570,9 @@ public class BitmapFactory {
*/
public static Bitmap decodeFileDescriptor(FileDescriptor fd, Rect outPadding, Options opts) {
Bitmap bm = nativeDecodeFileDescriptor(fd, outPadding, opts);
+ if (bm == null && opts != null && opts.inBitmap != null) {
+ throw new IllegalArgumentException("Problem decoding into existing bitmap");
+ }
return finishDecode(bm, outPadding, opts);
}