diff options
Diffstat (limited to 'graphics/java/android/renderscript/Allocation.java')
-rw-r--r-- | graphics/java/android/renderscript/Allocation.java | 113 |
1 files changed, 91 insertions, 22 deletions
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java index 5f0844a..7e43a9a 100644 --- a/graphics/java/android/renderscript/Allocation.java +++ b/graphics/java/android/renderscript/Allocation.java @@ -488,7 +488,11 @@ public class Allocation extends BaseObj { */ public void copyFromUnchecked(int[] d) { mRS.validate(); - copy1DRangeFromUnchecked(0, mCurrentCount, d); + if (mCurrentDimY > 0) { + copy2DRangeFromUnchecked(0, 0, mCurrentDimX, mCurrentDimY, d); + } else { + copy1DRangeFromUnchecked(0, mCurrentCount, d); + } } /** * Copy an allocation from an array. This variant is not type @@ -499,7 +503,11 @@ public class Allocation extends BaseObj { */ public void copyFromUnchecked(short[] d) { mRS.validate(); - copy1DRangeFromUnchecked(0, mCurrentCount, d); + if (mCurrentDimY > 0) { + copy2DRangeFromUnchecked(0, 0, mCurrentDimX, mCurrentDimY, d); + } else { + copy1DRangeFromUnchecked(0, mCurrentCount, d); + } } /** * Copy an allocation from an array. This variant is not type @@ -510,7 +518,11 @@ public class Allocation extends BaseObj { */ public void copyFromUnchecked(byte[] d) { mRS.validate(); - copy1DRangeFromUnchecked(0, mCurrentCount, d); + if (mCurrentDimY > 0) { + copy2DRangeFromUnchecked(0, 0, mCurrentDimX, mCurrentDimY, d); + } else { + copy1DRangeFromUnchecked(0, mCurrentCount, d); + } } /** * Copy an allocation from an array. This variant is not type @@ -521,7 +533,11 @@ public class Allocation extends BaseObj { */ public void copyFromUnchecked(float[] d) { mRS.validate(); - copy1DRangeFromUnchecked(0, mCurrentCount, d); + if (mCurrentDimY > 0) { + copy2DRangeFromUnchecked(0, 0, mCurrentDimX, mCurrentDimY, d); + } else { + copy1DRangeFromUnchecked(0, mCurrentCount, d); + } } /** @@ -533,7 +549,11 @@ public class Allocation extends BaseObj { */ public void copyFrom(int[] d) { mRS.validate(); - copy1DRangeFrom(0, mCurrentCount, d); + if (mCurrentDimY > 0) { + copy2DRangeFrom(0, 0, mCurrentDimX, mCurrentDimY, d); + } else { + copy1DRangeFrom(0, mCurrentCount, d); + } } /** @@ -545,7 +565,11 @@ public class Allocation extends BaseObj { */ public void copyFrom(short[] d) { mRS.validate(); - copy1DRangeFrom(0, mCurrentCount, d); + if (mCurrentDimY > 0) { + copy2DRangeFrom(0, 0, mCurrentDimX, mCurrentDimY, d); + } else { + copy1DRangeFrom(0, mCurrentCount, d); + } } /** @@ -557,7 +581,11 @@ public class Allocation extends BaseObj { */ public void copyFrom(byte[] d) { mRS.validate(); - copy1DRangeFrom(0, mCurrentCount, d); + if (mCurrentDimY > 0) { + copy2DRangeFrom(0, 0, mCurrentDimX, mCurrentDimY, d); + } else { + copy1DRangeFrom(0, mCurrentCount, d); + } } /** @@ -569,7 +597,11 @@ public class Allocation extends BaseObj { */ public void copyFrom(float[] d) { mRS.validate(); - copy1DRangeFrom(0, mCurrentCount, d); + if (mCurrentDimY > 0) { + copy2DRangeFrom(0, 0, mCurrentDimX, mCurrentDimY, d); + } else { + copy1DRangeFrom(0, mCurrentCount, d); + } } /** @@ -827,44 +859,81 @@ public class Allocation extends BaseObj { } } - /** - * Copy a rectangular region from the array into the allocation. - * The incoming array is assumed to be tightly packed. - * - * @param xoff X offset of the region to update - * @param yoff Y offset of the region to update - * @param w Width of the incoming region to update - * @param h Height of the incoming region to update - * @param data to be placed into the allocation - */ - public void copy2DRangeFrom(int xoff, int yoff, int w, int h, byte[] data) { + void copy2DRangeFromUnchecked(int xoff, int yoff, int w, int h, byte[] data) { mRS.validate(); validate2DRange(xoff, yoff, w, h); mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, w, h, data, data.length); } - public void copy2DRangeFrom(int xoff, int yoff, int w, int h, short[] data) { + void copy2DRangeFromUnchecked(int xoff, int yoff, int w, int h, short[] data) { mRS.validate(); validate2DRange(xoff, yoff, w, h); mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, w, h, data, data.length * 2); } - public void copy2DRangeFrom(int xoff, int yoff, int w, int h, int[] data) { + void copy2DRangeFromUnchecked(int xoff, int yoff, int w, int h, int[] data) { mRS.validate(); validate2DRange(xoff, yoff, w, h); mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, w, h, data, data.length * 4); } - public void copy2DRangeFrom(int xoff, int yoff, int w, int h, float[] data) { + void copy2DRangeFromUnchecked(int xoff, int yoff, int w, int h, float[] data) { mRS.validate(); validate2DRange(xoff, yoff, w, h); mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, w, h, data, data.length * 4); } + + /** + * Copy a rectangular region from the array into the allocation. + * The incoming array is assumed to be tightly packed. + * + * @param xoff X offset of the region to update + * @param yoff Y offset of the region to update + * @param w Width of the incoming region to update + * @param h Height of the incoming region to update + * @param data to be placed into the allocation + */ + public void copy2DRangeFrom(int xoff, int yoff, int w, int h, byte[] data) { + // We can only validate the type on API 18+, since this check was not present in + // earlier releases. + if (mRS.getApplicationContext().getApplicationInfo().targetSdkVersion >= 18) { + validateIsInt8(); + } + copy2DRangeFromUnchecked(xoff, yoff, w, h, data); + } + + public void copy2DRangeFrom(int xoff, int yoff, int w, int h, short[] data) { + // We can only validate the type on API 18+, since this check was not present in + // earlier releases. + if (mRS.getApplicationContext().getApplicationInfo().targetSdkVersion >= 18) { + validateIsInt16(); + } + copy2DRangeFromUnchecked(xoff, yoff, w, h, data); + } + + public void copy2DRangeFrom(int xoff, int yoff, int w, int h, int[] data) { + // We can only validate the type on API 18+, since this check was not present in + // earlier releases. + if (mRS.getApplicationContext().getApplicationInfo().targetSdkVersion >= 18) { + validateIsInt32(); + } + copy2DRangeFromUnchecked(xoff, yoff, w, h, data); + } + + public void copy2DRangeFrom(int xoff, int yoff, int w, int h, float[] data) { + // We can only validate the type on API 18+, since this check was not present in + // earlier releases. + if (mRS.getApplicationContext().getApplicationInfo().targetSdkVersion >= 18) { + validateIsFloat32(); + } + copy2DRangeFromUnchecked(xoff, yoff, w, h, data); + } + /** * Copy a rectangular region into the allocation from another * allocation. |