summaryrefslogtreecommitdiff
path: root/graphics/java/android/renderscript/ScriptIntrinsicConvolve3x3.java
diff options
context:
space:
mode:
authorJason Sams <jsams@google.com>2012-09-13 17:00:48 -0700
committerJason Sams <jsams@google.com>2012-09-13 17:00:48 -0700
commit80d819033d4687507907f787d47379b7b37eae19 (patch)
tree8a6533a8e512adeb453644ad98f918a6e919a372 /graphics/java/android/renderscript/ScriptIntrinsicConvolve3x3.java
parent83cdb021eb9a8cfe26cd565febadb1a70380f3a9 (diff)
Unhide intrinsics and document API.
Change-Id: I0233245c68f9a08780213062e62cfea6cf909c13
Diffstat (limited to 'graphics/java/android/renderscript/ScriptIntrinsicConvolve3x3.java')
-rw-r--r--graphics/java/android/renderscript/ScriptIntrinsicConvolve3x3.java64
1 files changed, 48 insertions, 16 deletions
diff --git a/graphics/java/android/renderscript/ScriptIntrinsicConvolve3x3.java b/graphics/java/android/renderscript/ScriptIntrinsicConvolve3x3.java
index c7465a7d522a..fb2948da9f19 100644
--- a/graphics/java/android/renderscript/ScriptIntrinsicConvolve3x3.java
+++ b/graphics/java/android/renderscript/ScriptIntrinsicConvolve3x3.java
@@ -20,45 +20,70 @@ import android.content.Context;
import android.content.res.Resources;
import android.util.Log;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Map.Entry;
-import java.util.HashMap;
-
-
/**
- * @hide
+ * Intrinsic for applying a 3x3 convolve to an allocation.
+ *
**/
-public class ScriptIntrinsicConvolve3x3 extends ScriptIntrinsic {
- private float[] mValues = new float[9];
+public final class ScriptIntrinsicConvolve3x3 extends ScriptIntrinsic {
+ private final float[] mValues = new float[9];
private Allocation mInput;
- ScriptIntrinsicConvolve3x3(int id, RenderScript rs) {
+ private ScriptIntrinsicConvolve3x3(int id, RenderScript rs) {
super(id, rs);
}
/**
- * Supported elements types are float, float4, uchar, uchar4
+ * Supported elements types are {@link Element#U8_4}
+ *
+ * The default coefficients are.
*
+ * <code>
+ * <p> [ 0, 0, 0 ]
+ * <p> [ 0, 1, 0 ]
+ * <p> [ 0, 0, 0 ]
+ * </code>
*
- * @param rs
- * @param e
+ * @param rs The Renderscript context
+ * @param e Element type for intputs and outputs
*
* @return ScriptIntrinsicConvolve3x3
*/
public static ScriptIntrinsicConvolve3x3 create(RenderScript rs, Element e) {
+ float f[] = { 0, 0, 0, 0, 1, 0, 0, 0, 0};
+ if (e != Element.U8_4(rs)) {
+ throw new RSIllegalArgumentException("Unsuported element type.");
+ }
int id = rs.nScriptIntrinsicCreate(1, e.getID(rs));
- return new ScriptIntrinsicConvolve3x3(id, rs);
+ ScriptIntrinsicConvolve3x3 si = new ScriptIntrinsicConvolve3x3(id, rs);
+ si.setCoefficients(f);
+ return si;
}
+ /**
+ * Set the input of the blur.
+ * Must match the element type supplied during create.
+ *
+ * @param ain The input allocation.
+ */
public void setInput(Allocation ain) {
mInput = ain;
bindAllocation(ain, 1);
}
- public void setColorMatrix(float v[]) {
+ /**
+ * Set the coefficients for the convolve.
+ *
+ * The convolve layout is
+ * <code>
+ * <p> [ 0, 1, 2 ]
+ * <p> [ 3, 4, 5 ]
+ * <p> [ 6, 7, 8 ]
+ * </code>
+ *
+ * @param v The array of coefficients to set
+ */
+ public void setCoefficients(float v[]) {
FieldPacker fp = new FieldPacker(9*4);
for (int ct=0; ct < mValues.length; ct++) {
mValues[ct] = v[ct];
@@ -67,6 +92,13 @@ public class ScriptIntrinsicConvolve3x3 extends ScriptIntrinsic {
setVar(0, fp);
}
+ /**
+ * Apply the filter to the input and save to the specified
+ * allocation.
+ *
+ * @param aout Output allocation. Must match creation element
+ * type.
+ */
public void forEach(Allocation aout) {
forEach(0, null, aout, null);
}