Skip to content

Commit 1e26a8b

Browse files
Jason SamsAndroid (Google) Code Review
authored andcommitted
Merge "LUT intrinsic and CrossProcess test. 5x5 convolve and test Gauss blur and test" into jb-mr1-dev
2 parents 99c0cb3 + 3a5b801 commit 1e26a8b

File tree

8 files changed

+556
-60
lines changed

8 files changed

+556
-60
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright (C) 2012 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package android.renderscript;
18+
19+
import android.content.Context;
20+
import android.content.res.Resources;
21+
import android.util.Log;
22+
23+
/**
24+
* @hide
25+
**/
26+
public class ScriptIntrinsicBlur extends ScriptIntrinsic {
27+
private float[] mValues = new float[9];
28+
private Allocation mInput;
29+
30+
ScriptIntrinsicBlur(int id, RenderScript rs) {
31+
super(id, rs);
32+
}
33+
34+
/**
35+
* Supported elements types are float, float4, uchar, uchar4
36+
*
37+
*
38+
* @param rs
39+
* @param e
40+
*
41+
* @return ScriptIntrinsicConvolve3x3
42+
*/
43+
public static ScriptIntrinsicBlur create(RenderScript rs, Element e) {
44+
int id = rs.nScriptIntrinsicCreate(5, e.getID(rs));
45+
return new ScriptIntrinsicBlur(id, rs);
46+
47+
}
48+
49+
public void setInput(Allocation ain) {
50+
mInput = ain;
51+
bindAllocation(ain, 1);
52+
}
53+
54+
public void setRadius(float v) {
55+
if (v < 0 || v > 25) {
56+
throw new RSIllegalArgumentException("Radius out of range (0-25).");
57+
}
58+
setVar(0, v);
59+
}
60+
61+
public void forEach(Allocation aout) {
62+
forEach(0, null, aout, null);
63+
}
64+
65+
}
66+
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright (C) 2012 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package android.renderscript;
18+
19+
import android.util.Log;
20+
21+
/**
22+
* @hide
23+
**/
24+
public class ScriptIntrinsicConvolve5x5 extends ScriptIntrinsic {
25+
private float[] mValues = new float[25];
26+
private Allocation mInput;
27+
28+
ScriptIntrinsicConvolve5x5(int id, RenderScript rs) {
29+
super(id, rs);
30+
}
31+
32+
/**
33+
* Supported elements types are float, float4, uchar, uchar4
34+
*
35+
*
36+
* @param rs
37+
* @param e
38+
*
39+
* @return ScriptIntrinsicConvolve5x5
40+
*/
41+
public static ScriptIntrinsicConvolve5x5 create(RenderScript rs, Element e) {
42+
int id = rs.nScriptIntrinsicCreate(4, e.getID(rs));
43+
return new ScriptIntrinsicConvolve5x5(id, rs);
44+
45+
}
46+
47+
public void setInput(Allocation ain) {
48+
mInput = ain;
49+
bindAllocation(ain, 1);
50+
}
51+
52+
public void setCoefficients(float v[]) {
53+
FieldPacker fp = new FieldPacker(25*4);
54+
for (int ct=0; ct < mValues.length; ct++) {
55+
mValues[ct] = v[ct];
56+
fp.addF32(mValues[ct]);
57+
}
58+
setVar(0, fp);
59+
}
60+
61+
public void forEach(Allocation aout) {
62+
forEach(0, null, aout, null);
63+
}
64+
65+
}
66+
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* Copyright (C) 2012 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package android.renderscript;
18+
19+
import android.content.Context;
20+
import android.content.res.Resources;
21+
import android.util.Log;
22+
23+
24+
/**
25+
* @hide
26+
**/
27+
public class ScriptIntrinsicLUT extends ScriptIntrinsic {
28+
private Matrix4f mMatrix = new Matrix4f();
29+
private Allocation mTables;
30+
private byte mCache[] = new byte[1024];
31+
private boolean mDirty = true;
32+
33+
ScriptIntrinsicLUT(int id, RenderScript rs) {
34+
super(id, rs);
35+
mTables = Allocation.createSized(rs, Element.U8(rs), 1024);
36+
for (int ct=0; ct < 256; ct++) {
37+
mCache[ct] = (byte)ct;
38+
mCache[ct + 256] = (byte)ct;
39+
mCache[ct + 512] = (byte)ct;
40+
mCache[ct + 768] = (byte)ct;
41+
}
42+
bindAllocation(mTables, 0);
43+
}
44+
45+
/**
46+
* Supported elements types are uchar4
47+
*
48+
* @param rs
49+
* @param e
50+
*
51+
* @return ScriptIntrinsicColorMatrix
52+
*/
53+
public static ScriptIntrinsicLUT create(RenderScript rs, Element e) {
54+
int id = rs.nScriptIntrinsicCreate(3, e.getID(rs));
55+
return new ScriptIntrinsicLUT(id, rs);
56+
57+
}
58+
59+
60+
private void validate(int index, int value) {
61+
if (index < 0 || index > 255) {
62+
throw new RSIllegalArgumentException("Index out of range (0-255).");
63+
}
64+
if (value < 0 || value > 255) {
65+
throw new RSIllegalArgumentException("Value out of range (0-255).");
66+
}
67+
}
68+
69+
public void setRed(int index, int value) {
70+
validate(index, value);
71+
mCache[index] = (byte)value;
72+
mDirty = true;
73+
}
74+
75+
public void setGreen(int index, int value) {
76+
validate(index, value);
77+
mCache[index+256] = (byte)value;
78+
mDirty = true;
79+
}
80+
81+
public void setBlue(int index, int value) {
82+
validate(index, value);
83+
mCache[index+512] = (byte)value;
84+
mDirty = true;
85+
}
86+
87+
public void setAlpha(int index, int value) {
88+
validate(index, value);
89+
mCache[index+768] = (byte)value;
90+
mDirty = true;
91+
}
92+
93+
94+
/**
95+
* Invoke the kernel and apply the matrix to each cell of ain and copy to
96+
* aout.
97+
*
98+
* @param ain Input allocation
99+
* @param aout Output allocation
100+
*/
101+
public void forEach(Allocation ain, Allocation aout) {
102+
if (mDirty) {
103+
mDirty = false;
104+
mTables.copyFromUnchecked(mCache);
105+
}
106+
forEach(0, ain, aout, null);
107+
}
108+
109+
}
110+

tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/Blur25.java

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@
2121
import android.renderscript.Allocation;
2222
import android.renderscript.Element;
2323
import android.renderscript.RenderScript;
24-
import android.renderscript.Script;
25-
import android.renderscript.ScriptC;
24+
import android.renderscript.ScriptIntrinsicBlur;
2625
import android.renderscript.Type;
2726
import android.util.Log;
2827
import android.widget.SeekBar;
2928
import android.widget.TextView;
3029

3130
public class Blur25 extends TestBase {
31+
private boolean mUseIntrinsic = false;
32+
private ScriptIntrinsicBlur mIntrinsic;
33+
3234
private int MAX_RADIUS = 25;
3335
private ScriptC_threshold mScript;
3436
private ScriptC_vertical_blur mScriptVBlur;
@@ -39,6 +41,10 @@ public class Blur25 extends TestBase {
3941
private Allocation mScratchPixelsAllocation2;
4042

4143

44+
public Blur25(boolean useIntrinsic) {
45+
mUseIntrinsic = useIntrinsic;
46+
}
47+
4248
public boolean onBar1Setup(SeekBar b, TextView t) {
4349
t.setText("Radius");
4450
b.setProgress(100);
@@ -67,40 +73,59 @@ public void createTest(android.content.res.Resources res) {
6773
int width = mInPixelsAllocation.getType().getX();
6874
int height = mInPixelsAllocation.getType().getY();
6975

70-
Type.Builder tb = new Type.Builder(mRS, Element.F32_4(mRS));
71-
tb.setX(width);
72-
tb.setY(height);
73-
mScratchPixelsAllocation1 = Allocation.createTyped(mRS, tb.create());
74-
mScratchPixelsAllocation2 = Allocation.createTyped(mRS, tb.create());
76+
if (mUseIntrinsic) {
77+
mIntrinsic = ScriptIntrinsicBlur.create(mRS, Element.U8_4(mRS));
78+
mIntrinsic.setRadius(25.f);
79+
mIntrinsic.setInput(mInPixelsAllocation);
80+
} else {
7581

76-
mScriptVBlur = new ScriptC_vertical_blur(mRS, res, R.raw.vertical_blur);
77-
mScriptHBlur = new ScriptC_horizontal_blur(mRS, res, R.raw.horizontal_blur);
82+
Type.Builder tb = new Type.Builder(mRS, Element.F32_4(mRS));
83+
tb.setX(width);
84+
tb.setY(height);
85+
mScratchPixelsAllocation1 = Allocation.createTyped(mRS, tb.create());
86+
mScratchPixelsAllocation2 = Allocation.createTyped(mRS, tb.create());
7887

79-
mScript = new ScriptC_threshold(mRS, res, R.raw.threshold);
80-
mScript.set_width(width);
81-
mScript.set_height(height);
82-
mScript.set_radius(mRadius);
88+
mScriptVBlur = new ScriptC_vertical_blur(mRS, res, R.raw.vertical_blur);
89+
mScriptHBlur = new ScriptC_horizontal_blur(mRS, res, R.raw.horizontal_blur);
8390

84-
mScriptVBlur.invoke_setSaturation(mSaturation);
91+
mScript = new ScriptC_threshold(mRS, res, R.raw.threshold);
92+
mScript.set_width(width);
93+
mScript.set_height(height);
94+
mScript.set_radius(mRadius);
95+
96+
mScriptVBlur.invoke_setSaturation(mSaturation);
8597

86-
mScript.bind_InPixel(mInPixelsAllocation);
87-
mScript.bind_OutPixel(mOutPixelsAllocation);
88-
mScript.bind_ScratchPixel1(mScratchPixelsAllocation1);
89-
mScript.bind_ScratchPixel2(mScratchPixelsAllocation2);
98+
mScript.bind_InPixel(mInPixelsAllocation);
99+
mScript.bind_OutPixel(mOutPixelsAllocation);
100+
mScript.bind_ScratchPixel1(mScratchPixelsAllocation1);
101+
mScript.bind_ScratchPixel2(mScratchPixelsAllocation2);
90102

91-
mScript.set_vBlurScript(mScriptVBlur);
92-
mScript.set_hBlurScript(mScriptHBlur);
103+
mScript.set_vBlurScript(mScriptVBlur);
104+
mScript.set_hBlurScript(mScriptHBlur);
105+
}
93106
}
94107

95108
public void runTest() {
96-
mScript.invoke_filter();
109+
if (mUseIntrinsic) {
110+
mIntrinsic.forEach(mOutPixelsAllocation);
111+
} else {
112+
mScript.invoke_filter();
113+
}
97114
}
98115

99116
public void setupBenchmark() {
100-
mScript.set_radius(MAX_RADIUS);
117+
if (mUseIntrinsic) {
118+
mIntrinsic.setRadius(MAX_RADIUS);
119+
} else {
120+
mScript.set_radius(MAX_RADIUS);
121+
}
101122
}
102123

103124
public void exitBenchmark() {
104-
mScript.set_radius(mRadius);
125+
if (mUseIntrinsic) {
126+
mIntrinsic.setRadius(mRadius);
127+
} else {
128+
mScript.set_radius(mRadius);
129+
}
105130
}
106131
}

0 commit comments

Comments
 (0)