summaryrefslogtreecommitdiff
path: root/graphics/java/android/renderscript/Byte4.java
diff options
context:
space:
mode:
authorMatthieu Delahaye <matthieu@multicorewareinc.com>2013-09-10 15:11:35 -0500
committerMatthieu Delahaye <matthieu@multicorewareinc.com>2013-10-23 16:02:03 -0500
commit6a5875cf96a6eebf4ef2e176176868ecbf17122f (patch)
tree009b6a091811feaab8e3e2b39e3c28e00887aca4 /graphics/java/android/renderscript/Byte4.java
parenta1b4d97b6920d3cd84fe19b07512a0de6996bb4c (diff)
Adding operations to reflected Renderscript class
Renderscript expose its native types back to the Android system through a set of classes defined within the renderscript package. These classes provides no easy mean to manipulate data they represent. It would be convinient to be able to manipulate the data stored within an allocation via these classes directly instead of having to marshall them into native Java objects. This commit adds such operations to the existing exposed vector types. Change-Id: I1845df1368a82f0d39b36416c83938c7160f6a3f
Diffstat (limited to 'graphics/java/android/renderscript/Byte4.java')
-rw-r--r--graphics/java/android/renderscript/Byte4.java420
1 files changed, 416 insertions, 4 deletions
diff --git a/graphics/java/android/renderscript/Byte4.java b/graphics/java/android/renderscript/Byte4.java
index 68c8f52a7862..b8a8a6b1ebfa 100644
--- a/graphics/java/android/renderscript/Byte4.java
+++ b/graphics/java/android/renderscript/Byte4.java
@@ -25,6 +25,11 @@ import android.util.Log;
*
**/
public class Byte4 {
+ public byte x;
+ public byte y;
+ public byte z;
+ public byte w;
+
public Byte4() {
}
@@ -34,11 +39,418 @@ public class Byte4 {
z = initZ;
w = initW;
}
+ /** @hide */
+ public Byte4(Byte4 source) {
+ this.x = source.x;
+ this.y = source.y;
+ this.z = source.z;
+ this.w = source.w;
+ }
- public byte x;
- public byte y;
- public byte z;
- public byte w;
+ /** @hide
+ * Vector add
+ *
+ * @param a
+ */
+ public void add(Byte4 a) {
+ this.x += a.x;
+ this.y += a.y;
+ this.z += a.z;
+ this.w += a.w;
+ }
+
+ /** @hide
+ * Vector add
+ *
+ * @param a
+ * @param b
+ * @return
+ */
+ public static Byte4 add(Byte4 a, Byte4 b) {
+ Byte4 result = new Byte4();
+ result.x = (byte)(a.x + b.x);
+ result.y = (byte)(a.y + b.y);
+ result.z = (byte)(a.z + b.z);
+ result.w = (byte)(a.w + b.w);
+
+ return result;
+ }
+
+ /** @hide
+ * Vector add
+ *
+ * @param value
+ */
+ public void add(byte value) {
+ x += value;
+ y += value;
+ z += value;
+ w += value;
+ }
+
+ /** @hide
+ * Vector add
+ *
+ * @param a
+ * @param b
+ * @return
+ */
+ public static Byte4 add(Byte4 a, byte b) {
+ Byte4 result = new Byte4();
+ result.x = (byte)(a.x + b);
+ result.y = (byte)(a.y + b);
+ result.z = (byte)(a.z + b);
+ result.w = (byte)(a.w + b);
+
+ return result;
+ }
+
+ /** @hide
+ * Vector subtraction
+ *
+ * @param a
+ */
+ public void sub(Byte4 a) {
+ this.x -= a.x;
+ this.y -= a.y;
+ this.z -= a.z;
+ this.w -= a.w;
+ }
+
+ /** @hide
+ * Vector subtraction
+ *
+ * @param a
+ * @param b
+ * @return
+ */
+ public static Byte4 sub(Byte4 a, Byte4 b) {
+ Byte4 result = new Byte4();
+ result.x = (byte)(a.x - b.x);
+ result.y = (byte)(a.y - b.y);
+ result.z = (byte)(a.z - b.z);
+ result.w = (byte)(a.w - b.w);
+
+ return result;
+ }
+
+ /** @hide
+ * Vector subtraction
+ *
+ * @param value
+ */
+ public void sub(byte value) {
+ x -= value;
+ y -= value;
+ z -= value;
+ w -= value;
+ }
+
+ /** @hide
+ * Vector subtraction
+ *
+ * @param a
+ * @param b
+ * @return
+ */
+ public static Byte4 sub(Byte4 a, byte b) {
+ Byte4 result = new Byte4();
+ result.x = (byte)(a.x - b);
+ result.y = (byte)(a.y - b);
+ result.z = (byte)(a.z - b);
+ result.w = (byte)(a.w - b);
+
+ return result;
+ }
+
+ /** @hide
+ * Vector multiplication
+ *
+ * @param a
+ */
+ public void mul(Byte4 a) {
+ this.x *= a.x;
+ this.y *= a.y;
+ this.z *= a.z;
+ this.w *= a.w;
+ }
+
+ /** @hide
+ * Vector multiplication
+ *
+ * @param a
+ * @param b
+ * @return
+ */
+ public static Byte4 mul(Byte4 a, Byte4 b) {
+ Byte4 result = new Byte4();
+ result.x = (byte)(a.x * b.x);
+ result.y = (byte)(a.y * b.y);
+ result.z = (byte)(a.z * b.z);
+ result.w = (byte)(a.w * b.w);
+
+ return result;
+ }
+
+ /** @hide
+ * Vector multiplication
+ *
+ * @param value
+ */
+ public void mul(byte value) {
+ x *= value;
+ y *= value;
+ z *= value;
+ w *= value;
+ }
+
+ /** @hide
+ * Vector multiplication
+ *
+ * @param a
+ * @param b
+ * @return
+ */
+ public static Byte4 mul(Byte4 a, byte b) {
+ Byte4 result = new Byte4();
+ result.x = (byte)(a.x * b);
+ result.y = (byte)(a.y * b);
+ result.z = (byte)(a.z * b);
+ result.w = (byte)(a.w * b);
+
+ return result;
+ }
+
+ /** @hide
+ * Vector division
+ *
+ * @param a
+ */
+ public void div(Byte4 a) {
+ this.x /= a.x;
+ this.y /= a.y;
+ this.z /= a.z;
+ this.w /= a.w;
+ }
+
+ /** @hide
+ * Vector division
+ *
+ * @param a
+ * @param b
+ * @return
+ */
+ public static Byte4 div(Byte4 a, Byte4 b) {
+ Byte4 result = new Byte4();
+ result.x = (byte)(a.x / b.x);
+ result.y = (byte)(a.y / b.y);
+ result.z = (byte)(a.z / b.z);
+ result.w = (byte)(a.w / b.w);
+
+ return result;
+ }
+
+ /** @hide
+ * Vector division
+ *
+ * @param value
+ */
+ public void div(byte value) {
+ x /= value;
+ y /= value;
+ z /= value;
+ w /= value;
+ }
+
+ /** @hide
+ * Vector division
+ *
+ * @param a
+ * @param b
+ * @return
+ */
+ public static Byte4 div(Byte4 a, byte b) {
+ Byte4 result = new Byte4();
+ result.x = (byte)(a.x / b);
+ result.y = (byte)(a.y / b);
+ result.z = (byte)(a.z / b);
+ result.w = (byte)(a.w / b);
+
+ return result;
+ }
+
+ /** @hide
+ * get vector length
+ *
+ * @return
+ */
+ public byte length() {
+ return 4;
+ }
+
+ /** @hide
+ * set vector negate
+ */
+ public void negate() {
+ this.x = (byte)(-x);
+ this.y = (byte)(-y);
+ this.z = (byte)(-z);
+ this.w = (byte)(-w);
+ }
+
+ /** @hide
+ * Vector dot Product
+ *
+ * @param a
+ * @return
+ */
+ public byte dotProduct(Byte4 a) {
+ return (byte)((x * a.x) + (y * a.y) + (z * a.z) + (w * a.w));
+ }
+
+ /** @hide
+ * Vector dot Product
+ *
+ * @param a
+ * @param b
+ * @return
+ */
+ public static byte dotProduct(Byte4 a, Byte4 b) {
+ return (byte)((b.x * a.x) + (b.y * a.y) + (b.z * a.z) + (b.w * a.w));
+ }
+
+ /** @hide
+ * Vector add Multiple
+ *
+ * @param a
+ * @param factor
+ */
+ public void addMultiple(Byte4 a, byte factor) {
+ x += a.x * factor;
+ y += a.y * factor;
+ z += a.z * factor;
+ w += a.w * factor;
+ }
+
+ /** @hide
+ * set vector value by Byte4
+ *
+ * @param a
+ */
+ public void set(Byte4 a) {
+ this.x = a.x;
+ this.y = a.y;
+ this.z = a.z;
+ this.w = a.w;
+ }
+
+ /** @hide
+ * set the vector field values
+ *
+ * @param a
+ * @param b
+ * @param c
+ * @param d
+ */
+ public void setValues(byte a, byte b, byte c, byte d) {
+ this.x = a;
+ this.y = b;
+ this.z = c;
+ this.w = d;
+ }
+
+ /** @hide
+ * return the element sum of vector
+ *
+ * @return
+ */
+ public byte elementSum() {
+ return (byte)(x + y + z + w);
+ }
+
+ /** @hide
+ * get the vector field value by index
+ *
+ * @param i
+ * @return
+ */
+ public byte get(int i) {
+ switch (i) {
+ case 0:
+ return x;
+ case 1:
+ return y;
+ case 2:
+ return z;
+ case 3:
+ return w;
+ default:
+ throw new IndexOutOfBoundsException("Index: i");
+ }
+ }
+
+ /** @hide
+ * set the vector field value by index
+ *
+ * @param i
+ * @param value
+ */
+ public void setAt(int i, byte value) {
+ switch (i) {
+ case 0:
+ x = value;
+ return;
+ case 1:
+ y = value;
+ return;
+ case 2:
+ z = value;
+ return;
+ case 3:
+ w = value;
+ return;
+ default:
+ throw new IndexOutOfBoundsException("Index: i");
+ }
+ }
+
+ /** @hide
+ * add the vector field value by index
+ *
+ * @param i
+ * @param value
+ */
+ public void addAt(int i, byte value) {
+ switch (i) {
+ case 0:
+ x += value;
+ return;
+ case 1:
+ y += value;
+ return;
+ case 2:
+ z += value;
+ return;
+ case 3:
+ w += value;
+ return;
+ default:
+ throw new IndexOutOfBoundsException("Index: i");
+ }
+ }
+
+ /** @hide
+ * copy the vector to Char array
+ *
+ * @param data
+ * @param offset
+ */
+ public void copyTo(byte[] data, int offset) {
+ data[offset] = x;
+ data[offset + 1] = y;
+ data[offset + 2] = z;
+ data[offset + 3] = w;
+ }
}