Skip to content

Commit 5254181

Browse files
author
Jason Sams
committed
Refactor ImageProcessing benchmark and stabilize results.
Change-Id: I3d43bf855515a3ab707089e97cc310b561683f5f
1 parent 0734102 commit 5254181

File tree

13 files changed

+742
-254
lines changed

13 files changed

+742
-254
lines changed

tests/RenderScriptTests/ImageProcessing/res/layout/main.xml

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -50,100 +50,76 @@
5050
android:textSize="8pt"
5151
android:text="@string/saturation"/>
5252
</LinearLayout>
53+
<Spinner
54+
android:id="@+id/filterselection"
55+
android:layout_width="fill_parent"
56+
android:layout_height="wrap_content"/>
5357
<TextView
54-
android:id="@+id/inSaturationText"
58+
android:id="@+id/slider1Text"
5559
android:layout_width="match_parent"
5660
android:layout_height="wrap_content"
5761
android:textSize="8pt"
5862
android:layout_marginLeft="10sp"
5963
android:layout_marginTop="15sp"
6064
android:text="@string/saturation"/>
6165
<SeekBar
62-
android:id="@+id/inSaturation"
66+
android:id="@+id/slider1"
6367
android:layout_marginLeft="10sp"
6468
android:layout_marginRight="10sp"
6569
android:layout_width="match_parent"
6670
android:layout_height="wrap_content"/>
6771
<TextView
68-
android:id="@+id/inGammaText"
72+
android:id="@+id/slider2Text"
6973
android:layout_width="match_parent"
7074
android:layout_height="wrap_content"
7175
android:textSize="8pt"
7276
android:layout_marginLeft="10sp"
7377
android:layout_marginTop="15sp"
7478
android:text="@string/gamma"/>
7579
<SeekBar
76-
android:id="@+id/inGamma"
80+
android:id="@+id/slider2"
7781
android:layout_marginLeft="10sp"
7882
android:layout_marginRight="10sp"
7983
android:layout_width="match_parent"
8084
android:layout_height="wrap_content"/>
8185
<TextView
82-
android:id="@+id/outWhiteText"
86+
android:id="@+id/slider3Text"
8387
android:layout_width="match_parent"
8488
android:layout_height="wrap_content"
8589
android:layout_marginLeft="10sp"
8690
android:layout_marginTop="15sp"
8791
android:textSize="8pt"
8892
android:text="@string/out_white"/>
8993
<SeekBar
90-
android:id="@+id/outWhite"
94+
android:id="@+id/slider3"
9195
android:layout_marginLeft="10sp"
9296
android:layout_marginRight="10sp"
9397
android:layout_width="match_parent"
9498
android:layout_height="wrap_content"/>
9599
<TextView
96-
android:id="@+id/inWhiteText"
100+
android:id="@+id/slider4Text"
97101
android:layout_width="match_parent"
98102
android:layout_height="wrap_content"
99103
android:textSize="8pt"
100104
android:layout_marginLeft="10sp"
101105
android:layout_marginTop="15sp"
102106
android:text="@string/in_white"/>
103107
<SeekBar
104-
android:id="@+id/inWhite"
105-
android:layout_marginLeft="10sp"
106-
android:layout_marginRight="10sp"
107-
android:layout_width="match_parent"
108-
android:layout_height="wrap_content"/>
109-
<TextView
110-
android:id="@+id/outBlackText"
111-
android:layout_width="match_parent"
112-
android:layout_height="wrap_content"
113-
android:textSize="8pt"
114-
android:layout_marginLeft="10sp"
115-
android:layout_marginTop="15sp"
116-
android:text="@string/out_black"/>
117-
<SeekBar
118-
android:id="@+id/outBlack"
108+
android:id="@+id/slider4"
119109
android:layout_marginLeft="10sp"
120110
android:layout_marginRight="10sp"
121111
android:layout_width="match_parent"
122112
android:layout_height="wrap_content"/>
123113
<TextView
124-
android:id="@+id/inBlackText"
114+
android:id="@+id/slider5Text"
125115
android:layout_width="match_parent"
126116
android:layout_height="wrap_content"
127117
android:textSize="8pt"
128118
android:layout_marginLeft="10sp"
129119
android:layout_marginTop="15sp"
130-
android:text="@string/in_black"/>
131-
<SeekBar
132-
android:id="@+id/inBlack"
133-
android:layout_marginLeft="10sp"
134-
android:layout_marginRight="10sp"
135-
android:layout_width="match_parent"
136-
android:layout_height="wrap_content"/>
137-
<TextView
138-
android:id="@+id/blurText"
139-
android:layout_width="match_parent"
140-
android:layout_height="wrap_content"
141-
android:textSize="8pt"
142-
android:layout_marginLeft="10sp"
143-
android:layout_marginTop="15sp"
144-
android:text="@string/blur_description"/>
120+
android:text="@string/in_white"/>
145121
<SeekBar
146-
android:id="@+id/radius"
122+
android:id="@+id/slider5"
147123
android:layout_marginLeft="10sp"
148124
android:layout_marginRight="10sp"
149125
android:layout_width="match_parent"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<!-- Copyright (C) 2012 The Android Open Source Project
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
18+
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
19+
android:layout_width="fill_parent"
20+
android:layout_height="fill_parent"
21+
android:padding="10dp"
22+
android:textSize="16sp"
23+
/>
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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 com.android.rs.image;
18+
19+
import java.lang.Math;
20+
21+
import android.renderscript.Allocation;
22+
import android.renderscript.Element;
23+
import android.renderscript.RenderScript;
24+
import android.renderscript.Script;
25+
import android.renderscript.ScriptC;
26+
import android.renderscript.Type;
27+
import android.util.Log;
28+
import android.widget.SeekBar;
29+
import android.widget.TextView;
30+
31+
public class Blur25 extends TestBase {
32+
private int MAX_RADIUS = 25;
33+
private ScriptC_threshold mScript;
34+
private ScriptC_vertical_blur mScriptVBlur;
35+
private ScriptC_horizontal_blur mScriptHBlur;
36+
private int mRadius = MAX_RADIUS;
37+
private float mSaturation = 1.0f;
38+
private Allocation mScratchPixelsAllocation1;
39+
private Allocation mScratchPixelsAllocation2;
40+
41+
42+
public boolean onBar1Setup(SeekBar b, TextView t) {
43+
t.setText("Radius");
44+
b.setProgress(100);
45+
return true;
46+
}
47+
public boolean onBar2Setup(SeekBar b, TextView t) {
48+
b.setProgress(50);
49+
t.setText("Saturation");
50+
return true;
51+
}
52+
53+
54+
public void onBar1Changed(int progress) {
55+
float fRadius = progress / 100.0f;
56+
fRadius *= (float)(MAX_RADIUS);
57+
mRadius = (int)fRadius;
58+
mScript.set_radius(mRadius);
59+
}
60+
public void onBar2Changed(int progress) {
61+
mSaturation = (float)progress / 50.0f;
62+
mScriptVBlur.invoke_setSaturation(mSaturation);
63+
}
64+
65+
66+
public void createTest(android.content.res.Resources res) {
67+
int width = mInPixelsAllocation.getType().getX();
68+
int height = mInPixelsAllocation.getType().getY();
69+
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());
75+
76+
mScriptVBlur = new ScriptC_vertical_blur(mRS, res, R.raw.vertical_blur);
77+
mScriptHBlur = new ScriptC_horizontal_blur(mRS, res, R.raw.horizontal_blur);
78+
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);
83+
84+
mScriptVBlur.invoke_setSaturation(mSaturation);
85+
86+
mScript.bind_InPixel(mInPixelsAllocation);
87+
mScript.bind_OutPixel(mOutPixelsAllocation);
88+
mScript.bind_ScratchPixel1(mScratchPixelsAllocation1);
89+
mScript.bind_ScratchPixel2(mScratchPixelsAllocation2);
90+
91+
mScript.set_vBlurScript(mScriptVBlur);
92+
mScript.set_hBlurScript(mScriptHBlur);
93+
}
94+
95+
public void runTest() {
96+
mScript.invoke_filter();
97+
}
98+
99+
public void setupBenchmark() {
100+
mScript.set_radius(MAX_RADIUS);
101+
}
102+
103+
public void exitBenchmark() {
104+
mScript.set_radius(mRadius);
105+
}
106+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 com.android.rs.image;
18+
19+
import java.lang.Math;
20+
21+
import android.renderscript.Allocation;
22+
import android.renderscript.Element;
23+
import android.renderscript.RenderScript;
24+
import android.renderscript.Script;
25+
import android.renderscript.ScriptC;
26+
import android.renderscript.Type;
27+
import android.util.Log;
28+
29+
public class Greyscale extends TestBase {
30+
private ScriptC_greyscale mScript;
31+
32+
public void createTest(android.content.res.Resources res) {
33+
mScript = new ScriptC_greyscale(mRS, res, R.raw.greyscale);
34+
}
35+
36+
public void runTest() {
37+
mScript.forEach_root(mInPixelsAllocation, mOutPixelsAllocation);
38+
}
39+
40+
}

0 commit comments

Comments
 (0)