am 5aede2a5: Merge "Add approximate version of Vignette filter to Image Processing test" into jb-mr1-dev
* commit '5aede2a5f8a0b81435baca42c74fa253849ea4f4': Add approximate version of Vignette filter to Image Processing test
This commit is contained in:
@@ -150,10 +150,16 @@ public class ImageProcessingActivity extends Activity
|
||||
mTest = new Fisheye(true);
|
||||
break;
|
||||
case 9:
|
||||
mTest = new Vignette(false);
|
||||
mTest = new Vignette(false, false);
|
||||
break;
|
||||
case 10:
|
||||
mTest = new Vignette(true);
|
||||
mTest = new Vignette(false, true);
|
||||
break;
|
||||
case 11:
|
||||
mTest = new Vignette(true, false);
|
||||
break;
|
||||
case 12:
|
||||
mTest = new Vignette(true, true);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -167,7 +173,7 @@ public class ImageProcessingActivity extends Activity
|
||||
}
|
||||
|
||||
void setupTests() {
|
||||
mTestNames = new String[11];
|
||||
mTestNames = new String[13];
|
||||
mTestNames[0] = "Levels Vec3 Relaxed";
|
||||
mTestNames[1] = "Levels Vec4 Relaxed";
|
||||
mTestNames[2] = "Levels Vec3 Full";
|
||||
@@ -179,6 +185,8 @@ public class ImageProcessingActivity extends Activity
|
||||
mTestNames[8] = "Fisheye Relaxed";
|
||||
mTestNames[9] = "Vignette Full";
|
||||
mTestNames[10] = "Vignette Relaxed";
|
||||
mTestNames[11] = "Vignette Approximate Full";
|
||||
mTestNames[12] = "Vignette Approximate Relaxed";
|
||||
mTestSpinner.setAdapter(new ArrayAdapter<String>(
|
||||
this, R.layout.spinner_layout, mTestNames));
|
||||
}
|
||||
|
||||
@@ -26,6 +26,9 @@ import android.widget.TextView;
|
||||
public class Vignette extends TestBase {
|
||||
private ScriptC_vignette_full mScript_full = null;
|
||||
private ScriptC_vignette_relaxed mScript_relaxed = null;
|
||||
private ScriptC_vignette_approx_full mScript_approx_full = null;
|
||||
private ScriptC_vignette_approx_relaxed mScript_approx_relaxed = null;
|
||||
private final boolean approx;
|
||||
private final boolean relaxed;
|
||||
private float center_x = 0.5f;
|
||||
private float center_y = 0.5f;
|
||||
@@ -33,7 +36,8 @@ public class Vignette extends TestBase {
|
||||
private float shade = 0.5f;
|
||||
private float slope = 20.0f;
|
||||
|
||||
public Vignette(boolean relaxed) {
|
||||
public Vignette(boolean approx, boolean relaxed) {
|
||||
this.approx = approx;
|
||||
this.relaxed = relaxed;
|
||||
}
|
||||
|
||||
@@ -90,7 +94,18 @@ public class Vignette extends TestBase {
|
||||
}
|
||||
|
||||
private void do_init() {
|
||||
if (relaxed)
|
||||
if (approx) {
|
||||
if (relaxed)
|
||||
mScript_approx_relaxed.invoke_init_vignette(
|
||||
mInPixelsAllocation.getType().getX(),
|
||||
mInPixelsAllocation.getType().getY(), center_x,
|
||||
center_y, scale, shade, slope);
|
||||
else
|
||||
mScript_approx_full.invoke_init_vignette(
|
||||
mInPixelsAllocation.getType().getX(),
|
||||
mInPixelsAllocation.getType().getY(), center_x,
|
||||
center_y, scale, shade, slope);
|
||||
} else if (relaxed)
|
||||
mScript_relaxed.invoke_init_vignette(
|
||||
mInPixelsAllocation.getType().getX(),
|
||||
mInPixelsAllocation.getType().getY(), center_x, center_y,
|
||||
@@ -103,21 +118,36 @@ public class Vignette extends TestBase {
|
||||
}
|
||||
|
||||
public void createTest(android.content.res.Resources res) {
|
||||
if (relaxed) {
|
||||
if (approx) {
|
||||
if (relaxed)
|
||||
mScript_approx_relaxed = new ScriptC_vignette_approx_relaxed(
|
||||
mRS, res, R.raw.vignette_approx_relaxed);
|
||||
else
|
||||
mScript_approx_full = new ScriptC_vignette_approx_full(
|
||||
mRS, res, R.raw.vignette_approx_full);
|
||||
} else if (relaxed)
|
||||
mScript_relaxed = new ScriptC_vignette_relaxed(mRS, res,
|
||||
R.raw.vignette_relaxed);
|
||||
} else {
|
||||
else
|
||||
mScript_full = new ScriptC_vignette_full(mRS, res,
|
||||
R.raw.vignette_full);
|
||||
}
|
||||
do_init();
|
||||
}
|
||||
|
||||
public void runTest() {
|
||||
if (relaxed)
|
||||
mScript_relaxed.forEach_root(mInPixelsAllocation, mOutPixelsAllocation);
|
||||
if (approx) {
|
||||
if (relaxed)
|
||||
mScript_approx_relaxed.forEach_root(mInPixelsAllocation,
|
||||
mOutPixelsAllocation);
|
||||
else
|
||||
mScript_approx_full.forEach_root(mInPixelsAllocation,
|
||||
mOutPixelsAllocation);
|
||||
} else if (relaxed)
|
||||
mScript_relaxed.forEach_root(mInPixelsAllocation,
|
||||
mOutPixelsAllocation);
|
||||
else
|
||||
mScript_full.forEach_root(mInPixelsAllocation, mOutPixelsAllocation);
|
||||
mScript_full.forEach_root(mInPixelsAllocation,
|
||||
mOutPixelsAllocation);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) 2012 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
static float2 neg_center, axis_scale, inv_dimensions;
|
||||
static float sloped_neg_range, sloped_inv_max_dist, shade, opp_shade;
|
||||
|
||||
void init_vignette(uint32_t dim_x, uint32_t dim_y, float center_x, float center_y,
|
||||
float desired_scale, float desired_shade, float desired_slope) {
|
||||
|
||||
neg_center.x = -center_x;
|
||||
neg_center.y = -center_y;
|
||||
inv_dimensions.x = 1.f / (float)dim_x;
|
||||
inv_dimensions.y = 1.f / (float)dim_y;
|
||||
|
||||
axis_scale = (float2)1.f;
|
||||
if (dim_x > dim_y)
|
||||
axis_scale.y = (float)dim_y / (float)dim_x;
|
||||
else
|
||||
axis_scale.x = (float)dim_x / (float)dim_y;
|
||||
|
||||
const float max_dist = 0.5 * length(axis_scale);
|
||||
sloped_inv_max_dist = desired_slope * 1.f/max_dist;
|
||||
|
||||
// Range needs to be between 1.3 to 0.6. When scale is zero then range is
|
||||
// 1.3 which means no vignette at all because the luminousity difference is
|
||||
// less than 1/256. Expect input scale to be between 0.0 and 1.0.
|
||||
const float neg_range = 0.7*sqrt(desired_scale) - 1.3;
|
||||
sloped_neg_range = exp(neg_range * desired_slope);
|
||||
|
||||
shade = desired_shade;
|
||||
opp_shade = 1.f - desired_shade;
|
||||
}
|
||||
|
||||
void root(const uchar4 *in, uchar4 *out, uint32_t x, uint32_t y) {
|
||||
// Convert x and y to floating point coordinates with center as origin
|
||||
const float4 fin = convert_float4(*in);
|
||||
const float2 inCoord = {(float)x, (float)y};
|
||||
const float2 coord = mad(inCoord, inv_dimensions, neg_center);
|
||||
const float sloped_dist_ratio = approx_length(axis_scale * coord) * sloped_inv_max_dist;
|
||||
// TODO: add approx_exp once implemented
|
||||
const float lumen = opp_shade + shade * approx_recip(1.f + sloped_neg_range * exp(sloped_dist_ratio));
|
||||
float4 fout;
|
||||
fout.rgb = fin.rgb * lumen;
|
||||
fout.w = fin.w;
|
||||
*out = convert_uchar4(fout);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (C) 2012 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#pragma version(1)
|
||||
#pragma rs java_package_name(com.android.rs.image)
|
||||
|
||||
#include "vignette_approx.rsh"
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (C) 2012 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#pragma version(1)
|
||||
#pragma rs java_package_name(com.android.rs.image)
|
||||
#pragma rs_fp_relaxed
|
||||
|
||||
#include "vignette_approx.rsh"
|
||||
|
||||
Reference in New Issue
Block a user