Skip to content

Commit 0e64d89

Browse files
author
Tim Murray
committed
Add Mandelbrot test to ImageProcessing.
Change-Id: I1d5478d58609394111410fbfd9f48b5018f385b1
1 parent 61d3704 commit 0e64d89

File tree

3 files changed

+160
-1
lines changed

3 files changed

+160
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ void changeTest(int testID) {
203203
case 26:
204204
mTest = new Convolve5x5(true);
205205
break;
206+
case 27:
207+
mTest = new Mandelbrot();
208+
break;
206209
}
207210

208211
mTest.createBaseTest(this, mBitmapIn);
@@ -215,7 +218,7 @@ void changeTest(int testID) {
215218
}
216219

217220
void setupTests() {
218-
mTestNames = new String[27];
221+
mTestNames = new String[28];
219222
mTestNames[0] = "Levels Vec3 Relaxed";
220223
mTestNames[1] = "Levels Vec4 Relaxed";
221224
mTestNames[2] = "Levels Vec3 Full";
@@ -243,6 +246,8 @@ void setupTests() {
243246
mTestNames[24] = "CrossProcess (using LUT)";
244247
mTestNames[25] = "Convolve 5x5";
245248
mTestNames[26] = "Intrinsics Convolve 5x5";
249+
mTestNames[27] = "Mandelbrot";
250+
246251
mTestSpinner.setAdapter(new ArrayAdapter<String>(
247252
this, R.layout.spinner_layout, mTestNames));
248253
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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 Mandelbrot extends TestBase {
32+
private ScriptC_mandelbrot mScript;
33+
34+
public boolean onBar1Setup(SeekBar b, TextView t) {
35+
t.setText("Iterations");
36+
b.setProgress(0);
37+
return true;
38+
}
39+
40+
public void onBar1Changed(int progress) {
41+
int iters = progress * 3 + 50;
42+
mScript.set_gMaxIteration(iters);
43+
}
44+
45+
public boolean onBar2Setup(SeekBar b, TextView t) {
46+
t.setText("Lower Bound: X");
47+
b.setProgress(0);
48+
return true;
49+
}
50+
51+
public void onBar2Changed(int progress) {
52+
float scaleFactor = mScript.get_scaleFactor();
53+
// allow viewport to be moved by 2x scale factor
54+
float lowerBoundX = -2.f + ((progress / scaleFactor) / 50.f);
55+
mScript.set_lowerBoundX(lowerBoundX);
56+
}
57+
58+
public boolean onBar3Setup(SeekBar b, TextView t) {
59+
t.setText("Lower Bound: Y");
60+
b.setProgress(0);
61+
return true;
62+
}
63+
64+
public void onBar3Changed(int progress) {
65+
float scaleFactor = mScript.get_scaleFactor();
66+
// allow viewport to be moved by 2x scale factor
67+
float lowerBoundY = -2.f + ((progress / scaleFactor) / 50.f);
68+
mScript.set_lowerBoundY(lowerBoundY);
69+
}
70+
71+
public boolean onBar4Setup(SeekBar b, TextView t) {
72+
t.setText("Scale Factor");
73+
b.setProgress(0);
74+
return true;
75+
}
76+
77+
public void onBar4Changed(int progress) {
78+
float scaleFactor = 4.f - (3.96f * (progress / 100.f));
79+
mScript.set_scaleFactor(scaleFactor);
80+
}
81+
82+
public void createTest(android.content.res.Resources res) {
83+
int width = mOutPixelsAllocation.getType().getX();
84+
int height = mOutPixelsAllocation.getType().getY();
85+
86+
mScript = new ScriptC_mandelbrot(mRS, res, R.raw.mandelbrot);
87+
mScript.set_gDimX(width);
88+
mScript.set_gDimY(height);
89+
mScript.set_gMaxIteration(50);
90+
}
91+
92+
public void runTest() {
93+
mScript.forEach_root(mOutPixelsAllocation);
94+
mRS.finish();
95+
}
96+
97+
}
98+
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright (C) 2011 The Android Open Source Project
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#pragma version(1)
16+
#pragma rs java_package_name(com.android.rs.image)
17+
18+
uint32_t gMaxIteration = 500;
19+
uint32_t gDimX = 1024;
20+
uint32_t gDimY = 1024;
21+
22+
float lowerBoundX = -2.f;
23+
float lowerBoundY = -2.f;
24+
float scaleFactor = 4.f;
25+
26+
void root(uchar4 *v_out, uint32_t x, uint32_t y) {
27+
float2 p;
28+
p.x = lowerBoundX + ((float)x / gDimX) * scaleFactor;
29+
p.y = lowerBoundY + ((float)y / gDimY) * scaleFactor;
30+
31+
float2 t = 0;
32+
float2 t2 = t * t;
33+
int iter = 0;
34+
while((t2.x + t2.y < 4.f) && (iter < gMaxIteration)) {
35+
float xtemp = t2.x - t2.y + p.x;
36+
t.y = 2 * t.x * t.y + p.y;
37+
t.x = xtemp;
38+
iter++;
39+
t2 = t * t;
40+
}
41+
42+
if(iter >= gMaxIteration) {
43+
// write a non-transparent black pixel
44+
*v_out = (uchar4){0, 0, 0, 0xff};
45+
} else {
46+
float mi3 = gMaxIteration / 3.;
47+
if (iter <= (gMaxIteration / 3))
48+
*v_out = (uchar4){0xff * (iter / mi3), 0, 0, 0xff};
49+
else if (iter <= (((gMaxIteration / 3) * 2)))
50+
*v_out = (uchar4){0xff - (0xff * ((iter - mi3) / mi3)),
51+
(0xff * ((iter - mi3) / mi3)), 0, 0xff};
52+
else
53+
*v_out = (uchar4){0, 0xff - (0xff * ((iter - (mi3 * 2)) / mi3)),
54+
(0xff * ((iter - (mi3 * 2)) / mi3)), 0xff};
55+
}
56+
}

0 commit comments

Comments
 (0)