Skip to content

Commit 35f3a22

Browse files
Jason SamsAndroid (Google) Code Review
authored andcommitted
Merge "Unhide intrinsics and document API." into jb-mr1-dev
2 parents 83835b1 + 80d8190 commit 35f3a22

File tree

8 files changed

+246
-67
lines changed

8 files changed

+246
-67
lines changed

api/current.txt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20043,6 +20043,49 @@ package android.renderscript {
2004320043
ctor protected ScriptC(android.renderscript.RenderScript, android.content.res.Resources, int);
2004420044
}
2004520045

20046+
public abstract class ScriptIntrinsic extends android.renderscript.Script {
20047+
}
20048+
20049+
public final class ScriptIntrinsicBlur extends android.renderscript.ScriptIntrinsic {
20050+
method public static android.renderscript.ScriptIntrinsicBlur create(android.renderscript.RenderScript, android.renderscript.Element);
20051+
method public void forEach(android.renderscript.Allocation);
20052+
method public void setInput(android.renderscript.Allocation);
20053+
method public void setRadius(float);
20054+
}
20055+
20056+
public final class ScriptIntrinsicColorMatrix extends android.renderscript.ScriptIntrinsic {
20057+
method public static android.renderscript.ScriptIntrinsicColorMatrix create(android.renderscript.RenderScript, android.renderscript.Element);
20058+
method public void forEach(android.renderscript.Allocation, android.renderscript.Allocation);
20059+
method public void setColorMatrix(android.renderscript.Matrix4f);
20060+
method public void setColorMatrix(android.renderscript.Matrix3f);
20061+
method public void setGreyscale();
20062+
method public void setRGBtoYUV();
20063+
method public void setYUVtoRGB();
20064+
}
20065+
20066+
public final class ScriptIntrinsicConvolve3x3 extends android.renderscript.ScriptIntrinsic {
20067+
method public static android.renderscript.ScriptIntrinsicConvolve3x3 create(android.renderscript.RenderScript, android.renderscript.Element);
20068+
method public void forEach(android.renderscript.Allocation);
20069+
method public void setCoefficients(float[]);
20070+
method public void setInput(android.renderscript.Allocation);
20071+
}
20072+
20073+
public final class ScriptIntrinsicConvolve5x5 extends android.renderscript.ScriptIntrinsic {
20074+
method public static android.renderscript.ScriptIntrinsicConvolve5x5 create(android.renderscript.RenderScript, android.renderscript.Element);
20075+
method public void forEach(android.renderscript.Allocation);
20076+
method public void setCoefficients(float[]);
20077+
method public void setInput(android.renderscript.Allocation);
20078+
}
20079+
20080+
public final class ScriptIntrinsicLUT extends android.renderscript.ScriptIntrinsic {
20081+
method public static android.renderscript.ScriptIntrinsicLUT create(android.renderscript.RenderScript, android.renderscript.Element);
20082+
method public void forEach(android.renderscript.Allocation, android.renderscript.Allocation);
20083+
method public void setAlpha(int, int);
20084+
method public void setBlue(int, int);
20085+
method public void setGreen(int, int);
20086+
method public void setRed(int, int);
20087+
}
20088+
2004620089
public class Short2 {
2004720090
ctor public Short2();
2004820091
ctor public Short2(short, short);

graphics/java/android/renderscript/ScriptIntrinsic.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2008 The Android Open Source Project
2+
* Copyright (C) 2012 The Android Open Source Project
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,9 +22,14 @@
2222

2323

2424
/**
25-
* @hide
25+
* Base class for all Intrinsic scripts. An intrinsic a script
26+
* which implements a pre-defined function. Intrinsics are
27+
* provided to provide effecient implemtations of common
28+
* operations.
29+
*
30+
* Not intended for direct use.
2631
**/
27-
public class ScriptIntrinsic extends Script {
32+
public abstract class ScriptIntrinsic extends Script {
2833
ScriptIntrinsic(int id, RenderScript rs) {
2934
super(id, rs);
3035
}

graphics/java/android/renderscript/ScriptIntrinsicBlur.java

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,43 +21,72 @@
2121
import android.util.Log;
2222

2323
/**
24-
* @hide
24+
* Intrinsic Gausian blur filter. Applies a gaussian blur of the
25+
* specified radius to all elements of an allocation.
26+
*
27+
*
2528
**/
26-
public class ScriptIntrinsicBlur extends ScriptIntrinsic {
27-
private float[] mValues = new float[9];
29+
public final class ScriptIntrinsicBlur extends ScriptIntrinsic {
30+
private final float[] mValues = new float[9];
2831
private Allocation mInput;
2932

30-
ScriptIntrinsicBlur(int id, RenderScript rs) {
33+
private ScriptIntrinsicBlur(int id, RenderScript rs) {
3134
super(id, rs);
3235
}
3336

3437
/**
35-
* Supported elements types are float, float4, uchar, uchar4
38+
* Create an intrinsic for applying a blur to an allocation. The
39+
* default radius is 5.0.
3640
*
41+
* Supported elements types are {@link Element#U8_4}
3742
*
38-
* @param rs
39-
* @param e
43+
* @param rs The Renderscript context
44+
* @param e Element type for inputs and outputs
4045
*
41-
* @return ScriptIntrinsicConvolve3x3
46+
* @return ScriptIntrinsicBlur
4247
*/
4348
public static ScriptIntrinsicBlur create(RenderScript rs, Element e) {
49+
if (e != Element.U8_4(rs)) {
50+
throw new RSIllegalArgumentException("Unsuported element type.");
51+
}
4452
int id = rs.nScriptIntrinsicCreate(5, e.getID(rs));
45-
return new ScriptIntrinsicBlur(id, rs);
46-
53+
ScriptIntrinsicBlur sib = new ScriptIntrinsicBlur(id, rs);
54+
sib.setRadius(5.f);
55+
return sib;
4756
}
4857

58+
/**
59+
* Set the input of the blur.
60+
* Must match the element type supplied during create.
61+
*
62+
* @param ain The input allocation
63+
*/
4964
public void setInput(Allocation ain) {
5065
mInput = ain;
5166
bindAllocation(ain, 1);
5267
}
5368

54-
public void setRadius(float v) {
55-
if (v < 0 || v > 25) {
69+
/**
70+
* Set the radius of the Blur.
71+
*
72+
* Supported range 0-25
73+
*
74+
* @param radius The radius of the blur
75+
*/
76+
public void setRadius(float radius) {
77+
if (radius < 0 || radius > 25) {
5678
throw new RSIllegalArgumentException("Radius out of range (0-25).");
5779
}
58-
setVar(0, v);
80+
setVar(0, radius);
5981
}
6082

83+
/**
84+
* Apply the filter to the input and save to the specified
85+
* allocation.
86+
*
87+
* @param aout Output allocation. Must match creation element
88+
* type.
89+
*/
6190
public void forEach(Allocation aout) {
6291
forEach(0, null, aout, null);
6392
}

graphics/java/android/renderscript/ScriptIntrinsicColorMatrix.java

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,38 @@
2020
import android.content.res.Resources;
2121
import android.util.Log;
2222

23-
import java.io.File;
24-
import java.io.IOException;
25-
import java.io.InputStream;
26-
import java.util.Map.Entry;
27-
import java.util.HashMap;
28-
29-
3023
/**
31-
* @hide
24+
* Intrinsic for applying a color matrix to allocations.
25+
*
26+
* This has the same effect as loading each element and
27+
* converting it to a {@link Element#F32_4}, multiplying the
28+
* result by the 4x4 color matrix as performed by
29+
* rsMatrixMultiply() and writing it to the output after
30+
* conversion back to {@link Element#U8_4}.
3231
**/
33-
public class ScriptIntrinsicColorMatrix extends ScriptIntrinsic {
34-
private Matrix4f mMatrix = new Matrix4f();
32+
public final class ScriptIntrinsicColorMatrix extends ScriptIntrinsic {
33+
private final Matrix4f mMatrix = new Matrix4f();
3534
private Allocation mInput;
3635

37-
ScriptIntrinsicColorMatrix(int id, RenderScript rs) {
36+
private ScriptIntrinsicColorMatrix(int id, RenderScript rs) {
3837
super(id, rs);
3938
}
4039

4140
/**
42-
* Supported elements types are uchar4
41+
* Create an intrinsic for applying a color matrix to an
42+
* allocation.
4343
*
44-
* @param rs
45-
* @param e
44+
* Supported elements types are {@link Element#U8_4}
45+
*
46+
* @param rs The Renderscript context
47+
* @param e Element type for intputs and outputs
4648
*
4749
* @return ScriptIntrinsicColorMatrix
4850
*/
4951
public static ScriptIntrinsicColorMatrix create(RenderScript rs, Element e) {
52+
if (e != Element.U8_4(rs)) {
53+
throw new RSIllegalArgumentException("Unsuported element type.");
54+
}
5055
int id = rs.nScriptIntrinsicCreate(2, e.getID(rs));
5156
return new ScriptIntrinsicColorMatrix(id, rs);
5257

@@ -59,7 +64,8 @@ private void setMatrix() {
5964
}
6065

6166
/**
62-
* Set the color matrix which will be applied to each cell of the image.
67+
* Set the color matrix which will be applied to each cell of
68+
* the image.
6369
*
6470
* @param m The 4x4 matrix to set.
6571
*/

graphics/java/android/renderscript/ScriptIntrinsicConvolve3x3.java

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,45 +20,70 @@
2020
import android.content.res.Resources;
2121
import android.util.Log;
2222

23-
import java.io.File;
24-
import java.io.IOException;
25-
import java.io.InputStream;
26-
import java.util.Map.Entry;
27-
import java.util.HashMap;
28-
29-
3023
/**
31-
* @hide
24+
* Intrinsic for applying a 3x3 convolve to an allocation.
25+
*
3226
**/
33-
public class ScriptIntrinsicConvolve3x3 extends ScriptIntrinsic {
34-
private float[] mValues = new float[9];
27+
public final class ScriptIntrinsicConvolve3x3 extends ScriptIntrinsic {
28+
private final float[] mValues = new float[9];
3529
private Allocation mInput;
3630

37-
ScriptIntrinsicConvolve3x3(int id, RenderScript rs) {
31+
private ScriptIntrinsicConvolve3x3(int id, RenderScript rs) {
3832
super(id, rs);
3933
}
4034

4135
/**
42-
* Supported elements types are float, float4, uchar, uchar4
36+
* Supported elements types are {@link Element#U8_4}
37+
*
38+
* The default coefficients are.
4339
*
40+
* <code>
41+
* <p> [ 0, 0, 0 ]
42+
* <p> [ 0, 1, 0 ]
43+
* <p> [ 0, 0, 0 ]
44+
* </code>
4445
*
45-
* @param rs
46-
* @param e
46+
* @param rs The Renderscript context
47+
* @param e Element type for intputs and outputs
4748
*
4849
* @return ScriptIntrinsicConvolve3x3
4950
*/
5051
public static ScriptIntrinsicConvolve3x3 create(RenderScript rs, Element e) {
52+
float f[] = { 0, 0, 0, 0, 1, 0, 0, 0, 0};
53+
if (e != Element.U8_4(rs)) {
54+
throw new RSIllegalArgumentException("Unsuported element type.");
55+
}
5156
int id = rs.nScriptIntrinsicCreate(1, e.getID(rs));
52-
return new ScriptIntrinsicConvolve3x3(id, rs);
57+
ScriptIntrinsicConvolve3x3 si = new ScriptIntrinsicConvolve3x3(id, rs);
58+
si.setCoefficients(f);
59+
return si;
5360

5461
}
5562

63+
/**
64+
* Set the input of the blur.
65+
* Must match the element type supplied during create.
66+
*
67+
* @param ain The input allocation.
68+
*/
5669
public void setInput(Allocation ain) {
5770
mInput = ain;
5871
bindAllocation(ain, 1);
5972
}
6073

61-
public void setColorMatrix(float v[]) {
74+
/**
75+
* Set the coefficients for the convolve.
76+
*
77+
* The convolve layout is
78+
* <code>
79+
* <p> [ 0, 1, 2 ]
80+
* <p> [ 3, 4, 5 ]
81+
* <p> [ 6, 7, 8 ]
82+
* </code>
83+
*
84+
* @param v The array of coefficients to set
85+
*/
86+
public void setCoefficients(float v[]) {
6287
FieldPacker fp = new FieldPacker(9*4);
6388
for (int ct=0; ct < mValues.length; ct++) {
6489
mValues[ct] = v[ct];
@@ -67,6 +92,13 @@ public void setColorMatrix(float v[]) {
6792
setVar(0, fp);
6893
}
6994

95+
/**
96+
* Apply the filter to the input and save to the specified
97+
* allocation.
98+
*
99+
* @param aout Output allocation. Must match creation element
100+
* type.
101+
*/
70102
public void forEach(Allocation aout) {
71103
forEach(0, null, aout, null);
72104
}

0 commit comments

Comments
 (0)