summaryrefslogtreecommitdiff
path: root/graphics/java/android/renderscript/Float4.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/Float4.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/Float4.java')
-rw-r--r--graphics/java/android/renderscript/Float4.java441
1 files changed, 423 insertions, 18 deletions
diff --git a/graphics/java/android/renderscript/Float4.java b/graphics/java/android/renderscript/Float4.java
index 7ddf6aa96d9b..6541b2ec7264 100644
--- a/graphics/java/android/renderscript/Float4.java
+++ b/graphics/java/android/renderscript/Float4.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 The Android Open Source Project
+ * Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,30 +16,435 @@
package android.renderscript;
-import java.lang.Math;
-import android.util.Log;
-
-
/**
- * Class for exposing the native RenderScript float2 type back to the Android system.
- *
- **/
+ * Vector version of the basic float type.
+ * Provides four float fields packed.
+ */
public class Float4 {
+ public float x;
+ public float y;
+ public float z;
+ public float w;
+
public Float4() {
}
+ /** @hide */
+ public Float4(Float4 data) {
+ this.x = data.x;
+ this.y = data.y;
+ this.z = data.z;
+ this.w = data.w;
+ }
- public Float4(float initX, float initY, float initZ, float initW) {
- x = initX;
- y = initY;
- z = initZ;
- w = initW;
+ public Float4(float x, float y, float z, float w) {
+ this.x = x;
+ this.y = y;
+ this.z = z;
+ this.w = w;
}
- public float x;
- public float y;
- public float z;
- public float w;
-}
+ /** @hide
+ * Vector add
+ *
+ * @param a
+ * @param b
+ * @return
+ */
+ public static Float4 add(Float4 a, Float4 b) {
+ Float4 res = new Float4();
+ res.x = a.x + b.x;
+ res.y = a.y + b.y;
+ res.z = a.z + b.z;
+ res.w = a.w + b.w;
+
+ return res;
+ }
+
+ /** @hide
+ * Vector add
+ *
+ * @param value
+ */
+ public void add(Float4 value) {
+ x += value.x;
+ y += value.y;
+ z += value.z;
+ w += value.w;
+ }
+
+ /** @hide
+ * Vector add
+ *
+ * @param value
+ */
+ public void add(float value) {
+ x += value;
+ y += value;
+ z += value;
+ w += value;
+ }
+
+ /** @hide
+ * Vector add
+ *
+ * @param a
+ * @param b
+ * @return
+ */
+ public static Float4 add(Float4 a, float b) {
+ Float4 res = new Float4();
+ res.x = a.x + b;
+ res.y = a.y + b;
+ res.z = a.z + b;
+ res.w = a.w + b;
+
+ return res;
+ }
+
+ /** @hide
+ * Vector subtraction
+ *
+ * @param value
+ */
+ public void sub(Float4 value) {
+ x -= value.x;
+ y -= value.y;
+ z -= value.z;
+ w -= value.w;
+ }
+
+ /** @hide
+ * Vector subtraction
+ *
+ * @param value
+ */
+ public void sub(float value) {
+ x -= value;
+ y -= value;
+ z -= value;
+ w -= value;
+ }
+
+ /** @hide
+ * Vector subtraction
+ *
+ * @param a
+ * @param b
+ * @return
+ */
+ public static Float4 sub(Float4 a, float b) {
+ Float4 res = new Float4();
+ res.x = a.x - b;
+ res.y = a.y - b;
+ res.z = a.z - b;
+ res.w = a.w - b;
+
+ return res;
+ }
+
+ /** @hide
+ * Vector subtraction
+ *
+ * @param a
+ * @param b
+ * @return
+ */
+ public static Float4 sub(Float4 a, Float4 b) {
+ Float4 res = new Float4();
+ res.x = a.x - b.x;
+ res.y = a.y - b.y;
+ res.z = a.z - b.z;
+ res.w = a.w - b.w;
+
+ return res;
+ }
+
+ /** @hide
+ * Vector multiplication
+ *
+ * @param value
+ */
+ public void mul(Float4 value) {
+ x *= value.x;
+ y *= value.y;
+ z *= value.z;
+ w *= value.w;
+ }
+
+ /** @hide
+ * Vector multiplication
+ *
+ * @param value
+ */
+ public void mul(float value) {
+ x *= value;
+ y *= value;
+ z *= value;
+ w *= value;
+ }
+ /** @hide
+ * Vector multiplication
+ *
+ * @param a
+ * @param b
+ * @return
+ */
+ public static Float4 mul(Float4 a, Float4 b) {
+ Float4 res = new Float4();
+ res.x = a.x * b.x;
+ res.y = a.y * b.y;
+ res.z = a.z * b.z;
+ res.w = a.w * b.w;
+ return res;
+ }
+
+ /** @hide
+ * Vector multiplication
+ *
+ * @param a
+ * @param b
+ * @return
+ */
+ public static Float4 mul(Float4 a, float b) {
+ Float4 res = new Float4();
+ res.x = a.x * b;
+ res.y = a.y * b;
+ res.z = a.z * b;
+ res.w = a.w * b;
+
+ return res;
+ }
+
+ /** @hide
+ * Vector division
+ *
+ * @param value
+ */
+ public void div(Float4 value) {
+ x /= value.x;
+ y /= value.y;
+ z /= value.z;
+ w /= value.w;
+ }
+
+ /** @hide
+ * Vector division
+ *
+ * @param value
+ */
+ public void div(float value) {
+ x /= value;
+ y /= value;
+ z /= value;
+ w /= value;
+ }
+
+ /** @hide
+ * Vector division
+ *
+ * @param a
+ * @param b
+ * @return
+ */
+ public static Float4 div(Float4 a, float b) {
+ Float4 res = new Float4();
+ res.x = a.x / b;
+ res.y = a.y / b;
+ res.z = a.z / b;
+ res.w = a.w / b;
+
+ return res;
+ }
+
+ /** @hide
+ * Vector division
+ *
+ * @param a
+ * @param b
+ * @return
+ */
+ public static Float4 div(Float4 a, Float4 b) {
+ Float4 res = new Float4();
+ res.x = a.x / b.x;
+ res.y = a.y / b.y;
+ res.z = a.z / b.z;
+ res.w = a.w / b.w;
+
+ return res;
+ }
+
+ /** @hide
+ * Vector dot Product
+ *
+ * @param a
+ * @return
+ */
+ public float dotProduct(Float4 a) {
+ return (x * a.x) + (y * a.y) + (z * a.z) + (w * a.w);
+ }
+
+ /** @hide
+ * Vector dot Product
+ *
+ * @param a
+ * @param b
+ * @return
+ */
+ public static float dotProduct(Float4 a, Float4 b) {
+ return (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(Float4 a, float factor) {
+ x += a.x * factor;
+ y += a.y * factor;
+ z += a.z * factor;
+ w += a.w * factor;
+ }
+
+ /** @hide
+ * set vector value by float4
+ *
+ * @param a
+ */
+ public void set(Float4 a) {
+ this.x = a.x;
+ this.y = a.y;
+ this.z = a.z;
+ this.w = a.w;
+ }
+
+ /** @hide
+ * set vector negate
+ */
+ public void negate() {
+ x = -x;
+ y = -y;
+ z = -z;
+ w = -w;
+ }
+ /** @hide
+ * get vector length
+ *
+ * @return
+ */
+ public int length() {
+ return 4;
+ }
+
+ /** @hide
+ * return the element sum of vector
+ *
+ * @return
+ */
+ public float elementSum() {
+ return x + y + z + w;
+ }
+
+ /** @hide
+ * get the vector field value by index
+ *
+ * @param i
+ * @return
+ */
+ public float 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, float 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, float 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
+ * set the vector field value
+ *
+ * @param x
+ * @param y
+ * @param z
+ * @param w
+ */
+ public void setValues(float x, float y, float z, float w) {
+ this.x = x;
+ this.y = y;
+ this.z = z;
+ this.w = w;
+ }
+
+ /** @hide
+ * copy the vector to float array
+ *
+ * @param data
+ * @param offset
+ */
+ public void copyTo(float[] data, int offset) {
+ data[offset] = x;
+ data[offset + 1] = y;
+ data[offset + 2] = z;
+ data[offset + 3] = w;
+ }
+}