am ce0e1820: am d345505a: Merge "Add error checks to bitmap uploads. Fix java side calculation for pixel sizes." into honeycomb

* commit 'ce0e1820926b3879e080ae00bffaf225815a56a2':
  Add error checks to bitmap uploads. Fix java side calculation for pixel sizes.
This commit is contained in:
Jason Sams
2011-01-11 17:54:11 -08:00
committed by Android Git Automerger
2 changed files with 50 additions and 1 deletions

View File

@@ -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) {

View File

@@ -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;