diff options
| author | 2011-01-11 17:44:39 -0800 | |
|---|---|---|
| committer | 2011-01-11 17:44:39 -0800 | |
| commit | d345505a32f991ffb74639795451f545141b8890 (patch) | |
| tree | e682218adbc9506b4642d0e2f976de95d42594ce | |
| parent | 49c771c4da8bb7cf135e6afed3a901b1744beb67 (diff) | |
| parent | 252c07802f7039f15f723751162e64a6621e6998 (diff) | |
Merge "Add error checks to bitmap uploads. Fix java side calculation for pixel sizes." into honeycomb
| -rw-r--r-- | graphics/java/android/renderscript/Allocation.java | 43 | ||||
| -rw-r--r-- | graphics/java/android/renderscript/Element.java | 8 |
2 files changed, 50 insertions, 1 deletions
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java index 7a47c3bc88de..40c9a965fcd3 100644 --- a/graphics/java/android/renderscript/Allocation.java +++ b/graphics/java/android/renderscript/Allocation.java @@ -122,6 +122,49 @@ public class Allocation extends BaseObj { mType.getY() != b.getHeight()) { throw new RSIllegalArgumentException("Cannot update allocation from bitmap, sizes mismatch"); } + Bitmap.Config bc = b.getConfig(); + switch (bc) { + case ALPHA_8: + if (mType.getElement().mKind != Element.DataKind.PIXEL_A) { + throw new RSIllegalArgumentException("Allocation kind is " + + mType.getElement().mKind + ", type " + + mType.getElement().mType + + " of " + mType.getElement().getSizeBytes() + + " bytes, passed bitmap was " + bc); + } + break; + case ARGB_8888: + if ((mType.getElement().mKind != Element.DataKind.PIXEL_RGBA) || + (mType.getElement().getSizeBytes() != 4)) { + throw new RSIllegalArgumentException("Allocation kind is " + + mType.getElement().mKind + ", type " + + mType.getElement().mType + + " of " + mType.getElement().getSizeBytes() + + " bytes, passed bitmap was " + bc); + } + break; + case RGB_565: + if ((mType.getElement().mKind != Element.DataKind.PIXEL_RGB) || + (mType.getElement().getSizeBytes() != 2)) { + throw new RSIllegalArgumentException("Allocation kind is " + + mType.getElement().mKind + ", type " + + mType.getElement().mType + + " of " + mType.getElement().getSizeBytes() + + " bytes, passed bitmap was " + bc); + } + break; + case ARGB_4444: + if ((mType.getElement().mKind != Element.DataKind.PIXEL_RGBA) || + (mType.getElement().getSizeBytes() != 2)) { + throw new RSIllegalArgumentException("Allocation kind is " + + mType.getElement().mKind + ", type " + + mType.getElement().mType + + " of " + mType.getElement().getSizeBytes() + + " bytes, passed bitmap was " + bc); + } + break; + + } } public void copyFrom(int[] d) { diff --git a/graphics/java/android/renderscript/Element.java b/graphics/java/android/renderscript/Element.java index e07fdfb9b578..10dc35b64955 100644 --- a/graphics/java/android/renderscript/Element.java +++ b/graphics/java/android/renderscript/Element.java @@ -425,7 +425,13 @@ public class Element extends BaseObj { Element(int id, RenderScript rs, DataType dt, DataKind dk, boolean norm, int size) { super(id, rs); - mSize = dt.mSize * size; + if ((dt != DataType.UNSIGNED_5_6_5) && + (dt != DataType.UNSIGNED_4_4_4_4) && + (dt != DataType.UNSIGNED_5_5_5_1)) { + mSize = dt.mSize * size; + } else { + mSize = dt.mSize; + } mType = dt; mKind = dk; mNormalized = norm; |