Skip to content

Commit 5590027

Browse files
stephenhinesAndroid (Google) Code Review
authored andcommitted
Merge "Add vignette filter to Image Processing test" into jb-mr1-dev
2 parents d395ea1 + bb0dbf7 commit 5590027

File tree

5 files changed

+238
-1
lines changed

5 files changed

+238
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ void changeTest(int testID) {
149149
case 8:
150150
mTest = new Fisheye(true);
151151
break;
152+
case 9:
153+
mTest = new Vignette(false);
154+
break;
155+
case 10:
156+
mTest = new Vignette(true);
157+
break;
152158
}
153159

154160
mTest.createBaseTest(this, mBitmapIn);
@@ -161,7 +167,7 @@ void changeTest(int testID) {
161167
}
162168

163169
void setupTests() {
164-
mTestNames = new String[9];
170+
mTestNames = new String[11];
165171
mTestNames[0] = "Levels Vec3 Relaxed";
166172
mTestNames[1] = "Levels Vec4 Relaxed";
167173
mTestNames[2] = "Levels Vec3 Full";
@@ -171,6 +177,8 @@ void setupTests() {
171177
mTestNames[6] = "Grain";
172178
mTestNames[7] = "Fisheye Full";
173179
mTestNames[8] = "Fisheye Relaxed";
180+
mTestNames[9] = "Vignette Full";
181+
mTestNames[10] = "Vignette Relaxed";
174182
mTestSpinner.setAdapter(new ArrayAdapter<String>(
175183
this, R.layout.spinner_layout, mTestNames));
176184
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
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 android.renderscript.Allocation;
20+
import android.renderscript.Element;
21+
import android.renderscript.Sampler;
22+
import android.renderscript.Type;
23+
import android.widget.SeekBar;
24+
import android.widget.TextView;
25+
26+
public class Vignette extends TestBase {
27+
private ScriptC_vignette_full mScript_full = null;
28+
private ScriptC_vignette_relaxed mScript_relaxed = null;
29+
private final boolean relaxed;
30+
private float center_x = 0.5f;
31+
private float center_y = 0.5f;
32+
private float scale = 0.5f;
33+
private float shade = 0.5f;
34+
private float slope = 20.0f;
35+
36+
public Vignette(boolean relaxed) {
37+
this.relaxed = relaxed;
38+
}
39+
40+
public boolean onBar1Setup(SeekBar b, TextView t) {
41+
t.setText("Scale");
42+
b.setMax(100);
43+
b.setProgress(25);
44+
return true;
45+
}
46+
public boolean onBar2Setup(SeekBar b, TextView t) {
47+
t.setText("Shade");
48+
b.setMax(100);
49+
b.setProgress(50);
50+
return true;
51+
}
52+
public boolean onBar3Setup(SeekBar b, TextView t) {
53+
t.setText("Slope");
54+
b.setMax(100);
55+
b.setProgress(20);
56+
return true;
57+
}
58+
public boolean onBar4Setup(SeekBar b, TextView t) {
59+
t.setText("Shift center X");
60+
b.setMax(100);
61+
b.setProgress(50);
62+
return true;
63+
}
64+
public boolean onBar5Setup(SeekBar b, TextView t) {
65+
t.setText("Shift center Y");
66+
b.setMax(100);
67+
b.setProgress(50);
68+
return true;
69+
}
70+
71+
public void onBar1Changed(int progress) {
72+
scale = progress / 50.0f;
73+
do_init();
74+
}
75+
public void onBar2Changed(int progress) {
76+
shade = progress / 100.0f;
77+
do_init();
78+
}
79+
public void onBar3Changed(int progress) {
80+
slope = (float)progress;
81+
do_init();
82+
}
83+
public void onBar4Changed(int progress) {
84+
center_x = progress / 100.0f;
85+
do_init();
86+
}
87+
public void onBar5Changed(int progress) {
88+
center_y = progress / 100.0f;
89+
do_init();
90+
}
91+
92+
private void do_init() {
93+
if (relaxed)
94+
mScript_relaxed.invoke_init_vignette(
95+
mInPixelsAllocation.getType().getX(),
96+
mInPixelsAllocation.getType().getY(), center_x, center_y,
97+
scale, shade, slope);
98+
else
99+
mScript_full.invoke_init_vignette(
100+
mInPixelsAllocation.getType().getX(),
101+
mInPixelsAllocation.getType().getY(), center_x, center_y,
102+
scale, shade, slope);
103+
}
104+
105+
public void createTest(android.content.res.Resources res) {
106+
if (relaxed) {
107+
mScript_relaxed = new ScriptC_vignette_relaxed(mRS, res,
108+
R.raw.vignette_relaxed);
109+
} else {
110+
mScript_full = new ScriptC_vignette_full(mRS, res,
111+
R.raw.vignette_full);
112+
}
113+
do_init();
114+
}
115+
116+
public void runTest() {
117+
if (relaxed)
118+
mScript_relaxed.forEach_root(mInPixelsAllocation, mOutPixelsAllocation);
119+
else
120+
mScript_full.forEach_root(mInPixelsAllocation, mOutPixelsAllocation);
121+
}
122+
123+
}
124+
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
static float2 scale;
18+
static float2 center, dimensions;
19+
static float range, inv_max_dist, shade, slope;
20+
21+
void init_vignette(uint32_t dim_x, uint32_t dim_y, float center_x, float center_y,
22+
float desired_scale, float desired_shade, float desired_slope) {
23+
24+
center.x = center_x;
25+
center.y = center_y;
26+
dimensions.x = (float)dim_x;
27+
dimensions.y = (float)dim_y;
28+
29+
float max_dist = 0.5;
30+
if (dim_x > dim_y) {
31+
scale.x = 1.0;
32+
scale.y = dimensions.y / dimensions.x;
33+
max_dist *= sqrt(scale.y*scale.y + 1);
34+
} else {
35+
scale.x = dimensions.x / dimensions.y;
36+
scale.y = 1.0;
37+
max_dist *= sqrt(scale.x*scale.x + 1);
38+
}
39+
inv_max_dist = 1.0/max_dist;
40+
// Range needs to be between 1.3 to 0.6. When scale is zero then range is
41+
// 1.3 which means no vignette at all because the luminousity difference is
42+
// less than 1/256. Expect input scale to be between 0.0 and 1.0.
43+
range = 1.3 - 0.7*sqrt(desired_scale);
44+
shade = desired_shade;
45+
slope = desired_slope;
46+
}
47+
48+
void root(const uchar4 *in, uchar4 *out, uint32_t x, uint32_t y) {
49+
// Convert x and y to floating point coordinates with center as origin
50+
const float4 fin = rsUnpackColor8888(*in);
51+
float2 coord;
52+
coord.x = (float)x / dimensions.x;
53+
coord.y = (float)y / dimensions.y;
54+
coord -= center;
55+
const float dist = length(scale * coord);
56+
const float lumen = shade / (1.0 + exp((dist * inv_max_dist - range) * slope)) + (1.0 - shade);
57+
float4 fout;
58+
fout.rgb = fin.rgb * lumen;
59+
fout.w = fin.w;
60+
*out = rsPackColorTo8888(fout);
61+
}
62+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
#pragma version(1)
18+
#pragma rs java_package_name(com.android.rs.image)
19+
20+
#include "vignette.rsh"
21+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
#pragma version(1)
18+
#pragma rs java_package_name(com.android.rs.image)
19+
#pragma rs_fp_relaxed
20+
21+
#include "vignette.rsh"
22+

0 commit comments

Comments
 (0)