From f1e484acb594a726fb57ad0ae4cfe902c7f35858 Mon Sep 17 00:00:00 2001 From: The Android Open Source Project Date: Thu, 22 Jan 2009 00:13:42 -0800 Subject: auto import from //branches/cupcake/...@127436 --- graphics/java/android/graphics/Bitmap.java | 32 ++++++++++++++++++++++ graphics/java/android/graphics/BitmapFactory.java | 5 ---- .../android/graphics/drawable/LayerDrawable.java | 8 +++--- 3 files changed, 36 insertions(+), 9 deletions(-) (limited to 'graphics/java') diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java index 501c99f..dc16c39 100644 --- a/graphics/java/android/graphics/Bitmap.java +++ b/graphics/java/android/graphics/Bitmap.java @@ -184,6 +184,37 @@ public final class Bitmap implements Parcelable { } /** + * Copy the pixels from the buffer, beginning at the current position, + * overwriting the bitmap's pixels. The data in the buffer is not changed + * in any way (unlike setPixels(), which converts from unpremultipled 32bit + * to whatever the bitmap's native format is. + */ + public void copyPixelsFromBuffer(Buffer src) { + checkRecycled("copyPixelsFromBuffer called on recycled bitmap"); + + int elements = src.remaining(); + int shift; + if (src instanceof ByteBuffer) { + shift = 0; + } else if (src instanceof ShortBuffer) { + shift = 1; + } else if (src instanceof IntBuffer) { + shift = 2; + } else { + throw new RuntimeException("unsupported Buffer subclass"); + } + + long bufferBytes = (long)elements << shift; + long bitmapBytes = (long)getRowBytes() * getHeight(); + + if (bufferBytes < bitmapBytes) { + throw new RuntimeException("Buffer not large enough for pixels"); + } + + nativeCopyPixelsFromBuffer(mNativeBitmap, src); + } + + /** * Tries to make a new bitmap based on the dimensions of this bitmap, * setting the new bitmap's config to the one specified, and then copying * this bitmap's pixels into the new bitmap. If the conversion is not @@ -794,6 +825,7 @@ public final class Bitmap implements Parcelable { int y, int width, int height); private static native void nativeCopyPixelsToBuffer(int nativeBitmap, Buffer dst); + private static native void nativeCopyPixelsFromBuffer(int nb, Buffer src); private static native Bitmap nativeCreateFromParcel(Parcel p); // returns true on success diff --git a/graphics/java/android/graphics/BitmapFactory.java b/graphics/java/android/graphics/BitmapFactory.java index d1e6090..2c3f543 100644 --- a/graphics/java/android/graphics/BitmapFactory.java +++ b/graphics/java/android/graphics/BitmapFactory.java @@ -304,11 +304,6 @@ public class BitmapFactory { bm = nativeDecodeStream(is, tempStorage, outPadding, opts); } - try { - is.reset(); - } catch (IOException ex) { - // ignore - } return bm; } diff --git a/graphics/java/android/graphics/drawable/LayerDrawable.java b/graphics/java/android/graphics/drawable/LayerDrawable.java index fa5ed0a..59dfbd4 100644 --- a/graphics/java/android/graphics/drawable/LayerDrawable.java +++ b/graphics/java/android/graphics/drawable/LayerDrawable.java @@ -340,10 +340,10 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { final int N = mLayerState.mNum; for (int i=0; i