diff options
author | Matthieu Delahaye <matthieu@multicorewareinc.com> | 2013-09-10 15:11:35 -0500 |
---|---|---|
committer | Matthieu Delahaye <matthieu@multicorewareinc.com> | 2013-10-23 16:02:03 -0500 |
commit | 6a5875cf96a6eebf4ef2e176176868ecbf17122f (patch) | |
tree | 009b6a091811feaab8e3e2b39e3c28e00887aca4 /graphics/java/android/renderscript/Int4.java | |
parent | a1b4d97b6920d3cd84fe19b07512a0de6996bb4c (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/Int4.java')
-rw-r--r-- | graphics/java/android/renderscript/Int4.java | 505 |
1 files changed, 487 insertions, 18 deletions
diff --git a/graphics/java/android/renderscript/Int4.java b/graphics/java/android/renderscript/Int4.java index eefb34924113..1c0e2e2621aa 100644 --- a/graphics/java/android/renderscript/Int4.java +++ b/graphics/java/android/renderscript/Int4.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,499 @@ package android.renderscript; -import java.lang.Math; -import android.util.Log; - - /** - * Class for exposing the native RenderScript int4 type back to the Android system. - * - **/ + * Vector version of the basic int type. + * Provides four int fields packed. + */ public class Int4 { + public int x; + public int y; + public int z; + public int w; + public Int4() { } - public Int4(int initX, int initY, int initZ, int initW) { - x = initX; - y = initY; - z = initZ; - w = initW; + /** @hide */ + public Int4(int i) { + this.x = this.y = this.z = this.w = i; } - public int x; - public int y; - public int z; - public int w; -} + public Int4(int x, int y, int z, int w) { + this.x = x; + this.y = y; + this.z = z; + this.w = w; + } + /** @hide */ + public Int4(Int4 source) { + this.x = source.x; + this.y = source.y; + this.z = source.z; + this.w = source.w; + } + + /** @hide + * Vector add + * + * @param a + */ + public void add(Int4 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 Int4 add(Int4 a, Int4 b) { + Int4 result = new Int4(); + result.x = a.x + b.x; + result.y = a.y + b.y; + result.z = a.z + b.z; + result.w = a.w + b.w; + + return result; + } + + /** @hide + * Vector add + * + * @param value + */ + public void add(int value) { + x += value; + y += value; + z += value; + w += value; + } + /** @hide + * Vector add + * + * @param a + * @param b + * @return + */ + public static Int4 add(Int4 a, int b) { + Int4 result = new Int4(); + result.x = a.x + b; + result.y = a.y + b; + result.z = a.z + b; + result.w = a.w + b; + + return result; + } + + /** @hide + * Vector subtraction + * + * @param a + */ + public void sub(Int4 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 Int4 sub(Int4 a, Int4 b) { + Int4 result = new Int4(); + result.x = a.x - b.x; + result.y = a.y - b.y; + result.z = a.z - b.z; + result.w = a.w - b.w; + + return result; + } + + /** @hide + * Vector subtraction + * + * @param value + */ + public void sub(int value) { + x -= value; + y -= value; + z -= value; + w -= value; + } + + /** @hide + * Vector subtraction + * + * @param a + * @param b + * @return + */ + public static Int4 sub(Int4 a, int b) { + Int4 result = new Int4(); + result.x = a.x - b; + result.y = a.y - b; + result.z = a.z - b; + result.w = a.w - b; + + return result; + } + + /** @hide + * Vector multiplication + * + * @param a + */ + public void mul(Int4 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 Int4 mul(Int4 a, Int4 b) { + Int4 result = new Int4(); + result.x = a.x * b.x; + result.y = a.y * b.y; + result.z = a.z * b.z; + result.w = a.w * b.w; + + return result; + } + + /** @hide + * Vector multiplication + * + * @param value + */ + public void mul(int value) { + x *= value; + y *= value; + z *= value; + w *= value; + } + + /** @hide + * Vector multiplication + * + * @param a + * @param b + * @return + */ + public static Int4 mul(Int4 a, int b) { + Int4 result = new Int4(); + result.x = a.x * b; + result.y = a.y * b; + result.z = a.z * b; + result.w = a.w * b; + + return result; + } + /** @hide + * Vector division + * + * @param a + */ + public void div(Int4 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 Int4 div(Int4 a, Int4 b) { + Int4 result = new Int4(); + result.x = a.x / b.x; + result.y = a.y / b.y; + result.z = a.z / b.z; + result.w = a.w / b.w; + + return result; + } + + /** @hide + * Vector division + * + * @param value + */ + public void div(int value) { + x /= value; + y /= value; + z /= value; + w /= value; + } + + /** @hide + * Vector division + * + * @param a + * @param b + * @return + */ + public static Int4 div(Int4 a, int b) { + Int4 result = new Int4(); + result.x = a.x / b; + result.y = a.y / b; + result.z = a.z / b; + result.w = a.w / b; + + return result; + } + + /** @hide + * Vector Modulo + * + * @param a + */ + public void mod(Int4 a) { + this.x %= a.x; + this.y %= a.y; + this.z %= a.z; + this.w %= a.w; + } + + /** @hide + * Vector Modulo + * + * @param a + * @param b + * @return + */ + public static Int4 mod(Int4 a, Int4 b) { + Int4 result = new Int4(); + result.x = a.x % b.x; + result.y = a.y % b.y; + result.z = a.z % b.z; + result.w = a.w % b.w; + + return result; + } + + /** @hide + * Vector Modulo + * + * @param value + */ + public void mod(int value) { + x %= value; + y %= value; + z %= value; + w %= value; + } + + /** @hide + * Vector Modulo + * + * @param a + * @param b + * @return + */ + public static Int4 mod(Int4 a, int b) { + Int4 result = new Int4(); + result.x = a.x % b; + result.y = a.y % b; + result.z = a.z % b; + result.w = a.w % b; + + return result; + } + + /** @hide + * get vector length + * + * @return + */ + public int length() { + return 4; + } + + /** @hide + * set vector negate + */ + public void negate() { + this.x = -x; + this.y = -y; + this.z = -z; + this.w = -w; + } + + /** @hide + * Vector dot Product + * + * @param a + * @return + */ + public int dotProduct(Int4 a) { + return (int)((x * a.x) + (y * a.y) + (z * a.z) + (w * a.w)); + } + + /** @hide + * Vector dot Product + * + * @param a + * @param b + * @return + */ + public static int dotProduct(Int4 a, Int4 b) { + return (int)((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(Int4 a, int factor) { + x += a.x * factor; + y += a.y * factor; + z += a.z * factor; + w += a.w * factor; + } + + /** @hide + * set vector value by Int4 + * + * @param a + */ + public void set(Int4 a) { + this.x = a.x; + this.y = a.y; + this.z = a.z; + this.w = a.w; + } + + /** @hide + * set the vector field value by Int + * + * @param a + * @param b + * @param c + * @param d + */ + public void setValues(int a, int b, int c, int d) { + this.x = a; + this.y = b; + this.z = c; + this.w = d; + } + + /** @hide + * return the element sum of vector + * + * @return + */ + public int elementSum() { + return (int)(x + y + z + w); + } + + /** @hide + * get the vector field value by index + * + * @param i + * @return + */ + public int get(int i) { + switch (i) { + case 0: + return (int)(x); + case 1: + return (int)(y); + case 2: + return (int)(z); + case 3: + return (int)(w); + default: + throw new IndexOutOfBoundsException("Index: i"); + } + } + + /** @hide + * set the vector field value by index + * + * @param i + * @param value + */ + public void setAt(int i, int 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, int 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 int array + * + * @param data + * @param offset + */ + public void copyTo(int[] data, int offset) { + data[offset] = (int)(x); + data[offset + 1] = (int)(y); + data[offset + 2] = (int)(z); + data[offset + 3] = (int)(w); + } +} |