Merge "Testing java compat lib for RS." into jb-mr1-dev

This commit is contained in:
Jason Sams
2012-08-16 11:23:40 -07:00
committed by Android (Google) Code Review
32 changed files with 2037 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
#
# Copyright (C) 2009 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.
#
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := tests
LOCAL_SRC_FILES := $(call all-java-files-under, src) \
$(call all-renderscript-files-under, src)
LOCAL_STATIC_JAVA_LIBRARIES := android.support.v8.renderscript
LOCAL_PACKAGE_NAME := ImageProcessing2
LOCAL_RENDERSCRIPT_FLAGS := -rs-package-name=android.support.v8.renderscript
LOCAL_REQUIRED_MODULES := librsjni
include $(BUILD_PACKAGE)
#include $(call all-makefiles-under, $(LOCAL_PATH))

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.rs.image2">
<uses-sdk android:minSdkVersion="11" />
<application android:label="IP GB"
android:hardwareAccelerated="true">
<activity android:name="ImageProcessingActivity2">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

Binary file not shown.

After

Width:  |  Height:  |  Size: 597 KiB

View File

@@ -0,0 +1,130 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2009 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.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/toplevel">
<SurfaceView
android:id="@+id/surface"
android:layout_width="1dip"
android:layout_height="1dip" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/display"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/benchmark"
android:onClick="benchmark"/>
<TextView
android:id="@+id/benchmarkText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="8pt"
android:text="@string/saturation"/>
</LinearLayout>
<Spinner
android:id="@+id/filterselection"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/slider1Text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="8pt"
android:layout_marginLeft="10sp"
android:layout_marginTop="15sp"
android:text="@string/saturation"/>
<SeekBar
android:id="@+id/slider1"
android:layout_marginLeft="10sp"
android:layout_marginRight="10sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/slider2Text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="8pt"
android:layout_marginLeft="10sp"
android:layout_marginTop="15sp"
android:text="@string/gamma"/>
<SeekBar
android:id="@+id/slider2"
android:layout_marginLeft="10sp"
android:layout_marginRight="10sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/slider3Text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10sp"
android:layout_marginTop="15sp"
android:textSize="8pt"
android:text="@string/out_white"/>
<SeekBar
android:id="@+id/slider3"
android:layout_marginLeft="10sp"
android:layout_marginRight="10sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/slider4Text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="8pt"
android:layout_marginLeft="10sp"
android:layout_marginTop="15sp"
android:text="@string/in_white"/>
<SeekBar
android:id="@+id/slider4"
android:layout_marginLeft="10sp"
android:layout_marginRight="10sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/slider5Text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="8pt"
android:layout_marginLeft="10sp"
android:layout_marginTop="15sp"
android:text="@string/in_white"/>
<SeekBar
android:id="@+id/slider5"
android:layout_marginLeft="10sp"
android:layout_marginRight="10sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</ScrollView>
</LinearLayout>

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp"
/>

View File

@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
* Copyright (C) 2008 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.
*/
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- General -->
<skip />
<!--slider label -->
<string name="blur_description">Blur Radius</string>
<string name="in_white">In White</string>
<string name="out_white">Out White</string>
<string name="in_black">In Black</string>
<string name="out_black">Out Black</string>
<string name="gamma">Gamma</string>
<string name="saturation">Saturation</string>
<string name="benchmark">Benchmark</string>
</resources>

View File

@@ -0,0 +1,101 @@
/*
* 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.
*/
package com.android.rs.image2;
import java.lang.Math;
import android.support.v8.renderscript.*;
import android.util.Log;
import android.widget.SeekBar;
import android.widget.TextView;
public class Blur25 extends TestBase {
private int MAX_RADIUS = 25;
private ScriptC_threshold mScript;
private ScriptC_vertical_blur mScriptVBlur;
private ScriptC_horizontal_blur mScriptHBlur;
private int mRadius = MAX_RADIUS;
private float mSaturation = 1.0f;
private Allocation mScratchPixelsAllocation1;
private Allocation mScratchPixelsAllocation2;
public boolean onBar1Setup(SeekBar b, TextView t) {
t.setText("Radius");
b.setProgress(100);
return true;
}
public boolean onBar2Setup(SeekBar b, TextView t) {
b.setProgress(50);
t.setText("Saturation");
return true;
}
public void onBar1Changed(int progress) {
float fRadius = progress / 100.0f;
fRadius *= (float)(MAX_RADIUS);
mRadius = (int)fRadius;
mScript.set_radius(mRadius);
}
public void onBar2Changed(int progress) {
mSaturation = (float)progress / 50.0f;
mScriptVBlur.invoke_setSaturation(mSaturation);
}
public void createTest(android.content.res.Resources res) {
int width = mInPixelsAllocation.getType().getX();
int height = mInPixelsAllocation.getType().getY();
Type.Builder tb = new Type.Builder(mRS, Element.F32_4(mRS));
tb.setX(width);
tb.setY(height);
mScratchPixelsAllocation1 = Allocation.createTyped(mRS, tb.create());
mScratchPixelsAllocation2 = Allocation.createTyped(mRS, tb.create());
mScriptVBlur = new ScriptC_vertical_blur(mRS, res, R.raw.vertical_blur);
mScriptHBlur = new ScriptC_horizontal_blur(mRS, res, R.raw.horizontal_blur);
mScript = new ScriptC_threshold(mRS, res, R.raw.threshold);
mScript.set_width(width);
mScript.set_height(height);
mScript.set_radius(mRadius);
mScriptVBlur.invoke_setSaturation(mSaturation);
mScript.bind_InPixel(mInPixelsAllocation);
mScript.bind_OutPixel(mOutPixelsAllocation);
mScript.bind_ScratchPixel1(mScratchPixelsAllocation1);
mScript.bind_ScratchPixel2(mScratchPixelsAllocation2);
mScript.set_vBlurScript(mScriptVBlur);
mScript.set_hBlurScript(mScriptHBlur);
}
public void runTest() {
mScript.invoke_filter();
}
public void setupBenchmark() {
mScript.set_radius(MAX_RADIUS);
}
public void exitBenchmark() {
mScript.set_radius(mRadius);
}
}

View File

@@ -0,0 +1,103 @@
/*
* 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.
*/
package com.android.rs.image2;
import android.support.v8.renderscript.*;
import android.widget.SeekBar;
import android.widget.TextView;
public class Fisheye extends TestBase {
private ScriptC_fisheye_full mScript_full = null;
private ScriptC_fisheye_relaxed mScript_relaxed = null;
private final boolean relaxed;
private float center_x = 0.5f;
private float center_y = 0.5f;
private float scale = 0.5f;
public Fisheye(boolean relaxed) {
this.relaxed = relaxed;
}
public boolean onBar1Setup(SeekBar b, TextView t) {
t.setText("Scale");
b.setMax(100);
b.setProgress(25);
return true;
}
public boolean onBar2Setup(SeekBar b, TextView t) {
t.setText("Shift center X");
b.setMax(100);
b.setProgress(50);
return true;
}
public boolean onBar3Setup(SeekBar b, TextView t) {
t.setText("Shift center Y");
b.setMax(100);
b.setProgress(50);
return true;
}
public void onBar1Changed(int progress) {
scale = progress / 50.0f;
do_init();
}
public void onBar2Changed(int progress) {
center_x = progress / 100.0f;
do_init();
}
public void onBar3Changed(int progress) {
center_y = progress / 100.0f;
do_init();
}
private void do_init() {
if (relaxed)
mScript_relaxed.invoke_init_filter(
mInPixelsAllocation.getType().getX(),
mInPixelsAllocation.getType().getY(), center_x, center_y,
scale);
else
mScript_full.invoke_init_filter(
mInPixelsAllocation.getType().getX(),
mInPixelsAllocation.getType().getY(), center_x, center_y,
scale);
}
public void createTest(android.content.res.Resources res) {
if (relaxed) {
mScript_relaxed = new ScriptC_fisheye_relaxed(mRS, res,
R.raw.fisheye_relaxed);
mScript_relaxed.set_in_alloc(mInPixelsAllocation);
mScript_relaxed.set_sampler(Sampler.CLAMP_LINEAR(mRS));
} else {
mScript_full = new ScriptC_fisheye_full(mRS, res,
R.raw.fisheye_full);
mScript_full.set_in_alloc(mInPixelsAllocation);
mScript_full.set_sampler(Sampler.CLAMP_LINEAR(mRS));
}
do_init();
}
public void runTest() {
if (relaxed)
mScript_relaxed.forEach_root(mOutPixelsAllocation);
else
mScript_full.forEach_root(mOutPixelsAllocation);
}
}

View File

@@ -0,0 +1,68 @@
/*
* 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.
*/
package com.android.rs.image2;
import java.lang.Math;
import android.support.v8.renderscript.*;
import android.util.Log;
import android.widget.SeekBar;
import android.widget.TextView;
public class Grain extends TestBase {
private ScriptC_grain mScript;
private Allocation mNoise;
private Allocation mNoise2;
public boolean onBar1Setup(SeekBar b, TextView t) {
t.setText("Strength");
b.setProgress(50);
return true;
}
public void onBar1Changed(int progress) {
float s = progress / 100.0f;
mScript.set_gNoiseStrength(s);
}
public void createTest(android.content.res.Resources res) {
int width = mInPixelsAllocation.getType().getX();
int height = mInPixelsAllocation.getType().getY();
Type.Builder tb = new Type.Builder(mRS, Element.U8(mRS));
tb.setX(width);
tb.setY(height);
mNoise = Allocation.createTyped(mRS, tb.create());
mNoise2 = Allocation.createTyped(mRS, tb.create());
mScript = new ScriptC_grain(mRS, res, R.raw.grain);
mScript.set_gWidth(width);
mScript.set_gHeight(height);
mScript.set_gNoiseStrength(0.5f);
mScript.set_gBlendSource(mNoise);
mScript.set_gNoise(mNoise2);
}
public void runTest() {
mScript.forEach_genRand(mNoise);
mScript.forEach_blend9(mNoise2);
mScript.forEach_root(mInPixelsAllocation, mOutPixelsAllocation);
}
}

View File

@@ -0,0 +1,35 @@
/*
* 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.
*/
package com.android.rs.image2;
import java.lang.Math;
import android.support.v8.renderscript.*;
import android.util.Log;
public class Greyscale extends TestBase {
private ScriptC_greyscale mScript;
public void createTest(android.content.res.Resources res) {
mScript = new ScriptC_greyscale(mRS, res, R.raw.greyscale);
}
public void runTest() {
mScript.forEach_root(mInPixelsAllocation, mOutPixelsAllocation);
}
}

View File

@@ -0,0 +1,87 @@
/*
* 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.
*/
package com.android.rs.image2;
import java.lang.Math;
import android.support.v8.renderscript.*;
import android.util.Log;
public class GroupTest extends TestBase {
private ScriptC_convolve3x3 mConvolve;
private ScriptC_colormatrix mMatrix;
private Allocation mScratchPixelsAllocation1;
private ScriptGroup mGroup;
private int mWidth;
private int mHeight;
private boolean mUseNative;
public GroupTest(boolean useNative) {
mUseNative = useNative;
}
public void createTest(android.content.res.Resources res) {
mWidth = mInPixelsAllocation.getType().getX();
mHeight = mInPixelsAllocation.getType().getY();
mConvolve = new ScriptC_convolve3x3(mRS, res, R.raw.convolve3x3);
mMatrix = new ScriptC_colormatrix(mRS, res, R.raw.colormatrix);
float f[] = new float[9];
f[0] = 0.f; f[1] = -1.f; f[2] = 0.f;
f[3] = -1.f; f[4] = 5.f; f[5] = -1.f;
f[6] = 0.f; f[7] = -1.f; f[8] = 0.f;
mConvolve.set_gCoeffs(f);
Matrix4f m = new Matrix4f();
m.set(1, 0, 0.2f);
m.set(1, 1, 0.9f);
m.set(1, 2, 0.2f);
mMatrix.invoke_setMatrix(m);
Type.Builder tb = new Type.Builder(mRS, Element.U8_4(mRS));
tb.setX(mWidth);
tb.setY(mHeight);
Type connect = tb.create();
if (mUseNative) {
ScriptGroup.Builder b = new ScriptGroup.Builder(mRS);
b.addConnection(connect, mConvolve, mMatrix, null);
mGroup = b.create();
} else {
mScratchPixelsAllocation1 = Allocation.createTyped(mRS, connect);
}
}
public void runTest() {
mConvolve.set_gIn(mInPixelsAllocation);
mConvolve.set_gWidth(mWidth);
mConvolve.set_gHeight(mHeight);
if (mUseNative) {
mGroup.setOutput(mMatrix, mOutPixelsAllocation);
mGroup.execute();
} else {
mConvolve.forEach_root(mScratchPixelsAllocation1);
mMatrix.forEach_root(mScratchPixelsAllocation1, mOutPixelsAllocation);
}
}
}

View File

@@ -0,0 +1,291 @@
/*
* 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.
*/
package com.android.rs.image2;
import android.app.Activity;
import android.os.Bundle;
import android.graphics.BitmapFactory;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.support.v8.renderscript.*;
import android.view.SurfaceView;
import android.view.SurfaceHolder;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.Spinner;
import android.widget.TextView;
import android.view.View;
import android.util.Log;
import java.lang.Math;
public class ImageProcessingActivity2 extends Activity
implements SeekBar.OnSeekBarChangeListener {
private final String TAG = "Img";
Bitmap mBitmapIn;
Bitmap mBitmapOut;
String mTestNames[];
private SeekBar mBar1;
private SeekBar mBar2;
private SeekBar mBar3;
private SeekBar mBar4;
private SeekBar mBar5;
private TextView mText1;
private TextView mText2;
private TextView mText3;
private TextView mText4;
private TextView mText5;
private float mSaturation = 1.0f;
private TextView mBenchmarkResult;
private Spinner mTestSpinner;
private SurfaceView mSurfaceView;
private ImageView mDisplayView;
private boolean mDoingBenchmark;
private TestBase mTest;
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (fromUser) {
if (seekBar == mBar1) {
mTest.onBar1Changed(progress);
} else if (seekBar == mBar2) {
mTest.onBar2Changed(progress);
} else if (seekBar == mBar3) {
mTest.onBar3Changed(progress);
} else if (seekBar == mBar4) {
mTest.onBar4Changed(progress);
} else if (seekBar == mBar5) {
mTest.onBar5Changed(progress);
}
mTest.runTest();
mTest.updateBitmap(mBitmapOut);
mDisplayView.invalidate();
}
}
public void onStartTrackingTouch(SeekBar seekBar) {
}
public void onStopTrackingTouch(SeekBar seekBar) {
}
void setupBars() {
mBar1.setVisibility(View.VISIBLE);
mText1.setVisibility(View.VISIBLE);
mTest.onBar1Setup(mBar1, mText1);
mBar2.setVisibility(View.VISIBLE);
mText2.setVisibility(View.VISIBLE);
mTest.onBar2Setup(mBar2, mText2);
mBar3.setVisibility(View.VISIBLE);
mText3.setVisibility(View.VISIBLE);
mTest.onBar3Setup(mBar3, mText3);
mBar4.setVisibility(View.VISIBLE);
mText4.setVisibility(View.VISIBLE);
mTest.onBar4Setup(mBar4, mText4);
mBar5.setVisibility(View.VISIBLE);
mText5.setVisibility(View.VISIBLE);
mTest.onBar5Setup(mBar5, mText5);
}
void changeTest(int testID) {
switch(testID) {
case 0:
mTest = new LevelsV4(false, false);
break;
case 1:
mTest = new LevelsV4(false, true);
break;
case 2:
mTest = new LevelsV4(true, false);
break;
case 3:
mTest = new LevelsV4(true, true);
break;
case 4:
mTest = new Blur25();
break;
case 5:
mTest = new Greyscale();
break;
case 6:
mTest = new Grain();
break;
case 7:
mTest = new Fisheye(false);
break;
case 8:
mTest = new Fisheye(true);
break;
case 9:
mTest = new Vignette(false);
break;
case 10:
mTest = new Vignette(true);
break;
case 11:
mTest = new GroupTest(false);
break;
case 12:
mTest = new GroupTest(true);
break;
}
mTest.createBaseTest(this, mBitmapIn);
setupBars();
mTest.runTest();
mTest.updateBitmap(mBitmapOut);
mDisplayView.invalidate();
mBenchmarkResult.setText("Result: not run");
}
void setupTests() {
mTestNames = new String[13];
mTestNames[0] = "Levels Vec3 Relaxed";
mTestNames[1] = "Levels Vec4 Relaxed";
mTestNames[2] = "Levels Vec3 Full";
mTestNames[3] = "Levels Vec4 Full";
mTestNames[4] = "Blur radius 25";
mTestNames[5] = "Greyscale";
mTestNames[6] = "Grain";
mTestNames[7] = "Fisheye Full";
mTestNames[8] = "Fisheye Relaxed";
mTestNames[9] = "Vignette Full";
mTestNames[10] = "Vignette Relaxed";
mTestNames[11] = "Group Test (emulated)";
mTestNames[12] = "Group Test (native)";
mTestSpinner.setAdapter(new ArrayAdapter<String>(
this, R.layout.spinner_layout, mTestNames));
}
private AdapterView.OnItemSelectedListener mTestSpinnerListener =
new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
changeTest(pos);
}
public void onNothingSelected(AdapterView parent) {
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mBitmapIn = loadBitmap(R.drawable.city);
mBitmapOut = loadBitmap(R.drawable.city);
mSurfaceView = (SurfaceView) findViewById(R.id.surface);
mDisplayView = (ImageView) findViewById(R.id.display);
mDisplayView.setImageBitmap(mBitmapOut);
mBar1 = (SeekBar) findViewById(R.id.slider1);
mBar2 = (SeekBar) findViewById(R.id.slider2);
mBar3 = (SeekBar) findViewById(R.id.slider3);
mBar4 = (SeekBar) findViewById(R.id.slider4);
mBar5 = (SeekBar) findViewById(R.id.slider5);
mBar1.setOnSeekBarChangeListener(this);
mBar2.setOnSeekBarChangeListener(this);
mBar3.setOnSeekBarChangeListener(this);
mBar4.setOnSeekBarChangeListener(this);
mBar5.setOnSeekBarChangeListener(this);
mText1 = (TextView) findViewById(R.id.slider1Text);
mText2 = (TextView) findViewById(R.id.slider2Text);
mText3 = (TextView) findViewById(R.id.slider3Text);
mText4 = (TextView) findViewById(R.id.slider4Text);
mText5 = (TextView) findViewById(R.id.slider5Text);
mTestSpinner = (Spinner) findViewById(R.id.filterselection);
mTestSpinner.setOnItemSelectedListener(mTestSpinnerListener);
mBenchmarkResult = (TextView) findViewById(R.id.benchmarkText);
mBenchmarkResult.setText("Result: not run");
setupTests();
changeTest(0);
}
private Bitmap loadBitmap(int resource) {
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
return copyBitmap(BitmapFactory.decodeResource(getResources(), resource, options));
}
private static Bitmap copyBitmap(Bitmap source) {
Bitmap b = Bitmap.createBitmap(source.getWidth(), source.getHeight(), source.getConfig());
Canvas c = new Canvas(b);
c.drawBitmap(source, 0, 0, null);
source.recycle();
return b;
}
// button hook
public void benchmark(View v) {
long t = getBenchmark();
//long javaTime = javaFilter();
//mBenchmarkResult.setText("RS: " + t + " ms Java: " + javaTime + " ms");
mBenchmarkResult.setText("Result: " + t + " ms");
}
// For benchmark test
public long getBenchmark() {
mDoingBenchmark = true;
mTest.setupBenchmark();
long result = 0;
Log.v(TAG, "Warming");
long t = java.lang.System.currentTimeMillis() + 2000;
do {
mTest.runTest();
mTest.finish();
} while (t > java.lang.System.currentTimeMillis());
Log.v(TAG, "Benchmarking");
t = java.lang.System.currentTimeMillis();
mTest.runTest();
mTest.finish();
t = java.lang.System.currentTimeMillis() - t;
Log.v(TAG, "getBenchmark: Renderscript frame time core ms " + t);
mTest.exitBenchmark();
mDoingBenchmark = false;
return t;
}
}

View File

@@ -0,0 +1,161 @@
/*
* 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.
*/
package com.android.rs.image2;
import java.lang.Math;
import android.support.v8.renderscript.*;
import android.util.Log;
import android.widget.SeekBar;
import android.widget.TextView;
public class LevelsV4 extends TestBase {
private ScriptC_levels_relaxed mScriptR;
private ScriptC_levels_full mScriptF;
private float mInBlack = 0.0f;
private float mOutBlack = 0.0f;
private float mInWhite = 255.0f;
private float mOutWhite = 255.0f;
private float mSaturation = 1.0f;
Matrix3f satMatrix = new Matrix3f();
float mInWMinInB;
float mOutWMinOutB;
float mOverInWMinInB;
boolean mUseFull;
boolean mUseV4;
LevelsV4(boolean useFull, boolean useV4) {
mUseFull = useFull;
mUseV4 = useV4;
}
private void setLevels() {
mInWMinInB = mInWhite - mInBlack;
mOutWMinOutB = mOutWhite - mOutBlack;
mOverInWMinInB = 1.f / mInWMinInB;
mScriptR.set_inBlack(mInBlack);
mScriptR.set_outBlack(mOutBlack);
mScriptR.set_inWMinInB(mInWMinInB);
mScriptR.set_outWMinOutB(mOutWMinOutB);
mScriptR.set_overInWMinInB(mOverInWMinInB);
mScriptF.set_inBlack(mInBlack);
mScriptF.set_outBlack(mOutBlack);
mScriptF.set_inWMinInB(mInWMinInB);
mScriptF.set_outWMinOutB(mOutWMinOutB);
mScriptF.set_overInWMinInB(mOverInWMinInB);
}
private void setSaturation() {
float rWeight = 0.299f;
float gWeight = 0.587f;
float bWeight = 0.114f;
float oneMinusS = 1.0f - mSaturation;
satMatrix.set(0, 0, oneMinusS * rWeight + mSaturation);
satMatrix.set(0, 1, oneMinusS * rWeight);
satMatrix.set(0, 2, oneMinusS * rWeight);
satMatrix.set(1, 0, oneMinusS * gWeight);
satMatrix.set(1, 1, oneMinusS * gWeight + mSaturation);
satMatrix.set(1, 2, oneMinusS * gWeight);
satMatrix.set(2, 0, oneMinusS * bWeight);
satMatrix.set(2, 1, oneMinusS * bWeight);
satMatrix.set(2, 2, oneMinusS * bWeight + mSaturation);
mScriptR.set_colorMat(satMatrix);
mScriptF.set_colorMat(satMatrix);
}
public boolean onBar1Setup(SeekBar b, TextView t) {
b.setProgress(50);
t.setText("Saturation");
return true;
}
public boolean onBar2Setup(SeekBar b, TextView t) {
b.setMax(128);
b.setProgress(0);
t.setText("In Black");
return true;
}
public boolean onBar3Setup(SeekBar b, TextView t) {
b.setMax(128);
b.setProgress(0);
t.setText("Out Black");
return true;
}
public boolean onBar4Setup(SeekBar b, TextView t) {
b.setMax(128);
b.setProgress(128);
t.setText("Out White");
return true;
}
public boolean onBar5Setup(SeekBar b, TextView t) {
b.setMax(128);
b.setProgress(128);
t.setText("Out White");
return true;
}
public void onBar1Changed(int progress) {
mSaturation = (float)progress / 50.0f;
setSaturation();
}
public void onBar2Changed(int progress) {
mInBlack = (float)progress;
setLevels();
}
public void onBar3Changed(int progress) {
mOutBlack = (float)progress;
setLevels();
}
public void onBar4Changed(int progress) {
mInWhite = (float)progress + 127.0f;
setLevels();
}
public void onBar5Changed(int progress) {
mOutWhite = (float)progress + 127.0f;
setLevels();
}
public void createTest(android.content.res.Resources res) {
mScriptR = new ScriptC_levels_relaxed(mRS, res, R.raw.levels_relaxed);
mScriptF = new ScriptC_levels_full(mRS, res, R.raw.levels_full);
setSaturation();
setLevels();
}
public void runTest() {
if (mUseFull) {
if (mUseV4) {
mScriptF.forEach_root4(mInPixelsAllocation, mOutPixelsAllocation);
} else {
mScriptF.forEach_root(mInPixelsAllocation, mOutPixelsAllocation);
}
} else {
if (mUseV4) {
mScriptR.forEach_root4(mInPixelsAllocation, mOutPixelsAllocation);
} else {
mScriptR.forEach_root(mInPixelsAllocation, mOutPixelsAllocation);
}
}
}
}

View File

@@ -0,0 +1,117 @@
/*
* 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.
*/
package com.android.rs.image2;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.graphics.BitmapFactory;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.support.v8.renderscript.*;
import android.view.SurfaceView;
import android.view.SurfaceHolder;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;
import android.view.View;
import android.util.Log;
import java.lang.Math;
public class TestBase {
protected final String TAG = "Img";
protected RenderScript mRS;
protected Allocation mInPixelsAllocation;
protected Allocation mOutPixelsAllocation;
// Override to use UI elements
public void onBar1Changed(int progress) {
}
public void onBar2Changed(int progress) {
}
public void onBar3Changed(int progress) {
}
public void onBar4Changed(int progress) {
}
public void onBar5Changed(int progress) {
}
// Override to use UI elements
// Unused bars will be hidden.
public boolean onBar1Setup(SeekBar b, TextView t) {
b.setVisibility(View.INVISIBLE);
t.setVisibility(View.INVISIBLE);
return false;
}
public boolean onBar2Setup(SeekBar b, TextView t) {
b.setVisibility(View.INVISIBLE);
t.setVisibility(View.INVISIBLE);
return false;
}
public boolean onBar3Setup(SeekBar b, TextView t) {
b.setVisibility(View.INVISIBLE);
t.setVisibility(View.INVISIBLE);
return false;
}
public boolean onBar4Setup(SeekBar b, TextView t) {
b.setVisibility(View.INVISIBLE);
t.setVisibility(View.INVISIBLE);
return false;
}
public boolean onBar5Setup(SeekBar b, TextView t) {
b.setVisibility(View.INVISIBLE);
t.setVisibility(View.INVISIBLE);
return false;
}
public final void createBaseTest(ImageProcessingActivity2 act, Bitmap b) {
mRS = RenderScript.create(act);
mInPixelsAllocation = Allocation.createFromBitmap(mRS, b,
Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);
mOutPixelsAllocation = Allocation.createFromBitmap(mRS, b,
Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);
createTest(act.getResources());
}
// Must override
public void createTest(android.content.res.Resources res) {
android.util.Log.e("img", "implement createTest");
}
// Must override
public void runTest() {
}
public void finish() {
mRS.finish();
}
public void updateBitmap(Bitmap b) {
mOutPixelsAllocation.copyTo(b);
}
// Override to configure specific benchmark config.
public void setupBenchmark() {
}
// Override to reset after benchmark.
public void exitBenchmark() {
}
}

View File

@@ -0,0 +1,121 @@
/*
* 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.
*/
package com.android.rs.image2;
import android.support.v8.renderscript.*;
import android.widget.SeekBar;
import android.widget.TextView;
public class Vignette extends TestBase {
private ScriptC_vignette_full mScript_full = null;
private ScriptC_vignette_relaxed mScript_relaxed = null;
private final boolean relaxed;
private float center_x = 0.5f;
private float center_y = 0.5f;
private float scale = 0.5f;
private float shade = 0.5f;
private float slope = 20.0f;
public Vignette(boolean relaxed) {
this.relaxed = relaxed;
}
public boolean onBar1Setup(SeekBar b, TextView t) {
t.setText("Scale");
b.setMax(100);
b.setProgress(25);
return true;
}
public boolean onBar2Setup(SeekBar b, TextView t) {
t.setText("Shade");
b.setMax(100);
b.setProgress(50);
return true;
}
public boolean onBar3Setup(SeekBar b, TextView t) {
t.setText("Slope");
b.setMax(100);
b.setProgress(20);
return true;
}
public boolean onBar4Setup(SeekBar b, TextView t) {
t.setText("Shift center X");
b.setMax(100);
b.setProgress(50);
return true;
}
public boolean onBar5Setup(SeekBar b, TextView t) {
t.setText("Shift center Y");
b.setMax(100);
b.setProgress(50);
return true;
}
public void onBar1Changed(int progress) {
scale = progress / 50.0f;
do_init();
}
public void onBar2Changed(int progress) {
shade = progress / 100.0f;
do_init();
}
public void onBar3Changed(int progress) {
slope = (float)progress;
do_init();
}
public void onBar4Changed(int progress) {
center_x = progress / 100.0f;
do_init();
}
public void onBar5Changed(int progress) {
center_y = progress / 100.0f;
do_init();
}
private void do_init() {
if (relaxed)
mScript_relaxed.invoke_init_vignette(
mInPixelsAllocation.getType().getX(),
mInPixelsAllocation.getType().getY(), center_x, center_y,
scale, shade, slope);
else
mScript_full.invoke_init_vignette(
mInPixelsAllocation.getType().getX(),
mInPixelsAllocation.getType().getY(), center_x, center_y,
scale, shade, slope);
}
public void createTest(android.content.res.Resources res) {
if (relaxed) {
mScript_relaxed = new ScriptC_vignette_relaxed(mRS, res,
R.raw.vignette_relaxed);
} 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);
else
mScript_full.forEach_root(mInPixelsAllocation, mOutPixelsAllocation);
}
}

View File

@@ -0,0 +1,38 @@
/*
* 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.image2)
#pragma rs_fp_relaxed
static rs_matrix4x4 Mat;
void init() {
rsMatrixLoadIdentity(&Mat);
}
void setMatrix(rs_matrix4x4 m) {
Mat = m;
}
void root(const uchar4 *in, uchar4 *out) {
float4 f = convert_float4(*in);
f = rsMatrixMultiply(&Mat, f);
f = clamp(f, 0.f, 255.f);
*out = convert_uchar4(f);
}

View File

@@ -0,0 +1,67 @@
/*
* 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.image2)
#pragma rs_fp_relaxed
int32_t gWidth;
int32_t gHeight;
rs_allocation gIn;
float gCoeffs[9];
void root(uchar4 *out, uint32_t x, uint32_t y) {
uint32_t x1 = min((int32_t)x+1, gWidth);
uint32_t x2 = max((int32_t)x-1, 0);
uint32_t y1 = min((int32_t)y+1, gHeight);
uint32_t y2 = max((int32_t)y-1, 0);
float4 p00 = convert_float4(((uchar4 *)rsGetElementAt(gIn, x1, y1))[0]);
float4 p01 = convert_float4(((uchar4 *)rsGetElementAt(gIn, x, y1))[0]);
float4 p02 = convert_float4(((uchar4 *)rsGetElementAt(gIn, x2, y1))[0]);
float4 p10 = convert_float4(((uchar4 *)rsGetElementAt(gIn, x1, y))[0]);
float4 p11 = convert_float4(((uchar4 *)rsGetElementAt(gIn, x, y))[0]);
float4 p12 = convert_float4(((uchar4 *)rsGetElementAt(gIn, x2, y))[0]);
float4 p20 = convert_float4(((uchar4 *)rsGetElementAt(gIn, x1, y2))[0]);
float4 p21 = convert_float4(((uchar4 *)rsGetElementAt(gIn, x, y2))[0]);
float4 p22 = convert_float4(((uchar4 *)rsGetElementAt(gIn, x2, y2))[0]);
p00 *= gCoeffs[0];
p01 *= gCoeffs[1];
p02 *= gCoeffs[2];
p10 *= gCoeffs[3];
p11 *= gCoeffs[4];
p12 *= gCoeffs[5];
p20 *= gCoeffs[6];
p21 *= gCoeffs[7];
p22 *= gCoeffs[8];
p00 += p01;
p02 += p10;
p11 += p12;
p20 += p21;
p22 += p00;
p02 += p11;
p20 += p22;
p20 += p02;
p20 = clamp(p20, 0.f, 255.f);
*out = convert_uchar4(p20);
}

View File

@@ -0,0 +1,63 @@
/*
* 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.
*/
rs_allocation in_alloc;
rs_sampler sampler;
static float2 center, dimensions;
static float2 scale;
static float alpha;
static float radius2;
static float factor;
void init_filter(uint32_t dim_x, uint32_t dim_y, float focus_x, float focus_y, float k) {
center.x = focus_x;
center.y = focus_y;
dimensions.x = (float)dim_x;
dimensions.y = (float)dim_y;
alpha = k * 2.0 + 0.75;
float bound2 = 0.25;
if (dim_x > dim_y) {
scale.x = 1.0;
scale.y = dimensions.y / dimensions.x;
bound2 *= (scale.y*scale.y + 1);
} else {
scale.x = dimensions.x / dimensions.y;
scale.y = 1.0;
bound2 *= (scale.x*scale.x + 1);
}
const float bound = sqrt(bound2);
const float radius = 1.15 * bound;
radius2 = radius*radius;
const float max_radian = 0.5f * M_PI - atan(alpha / bound * sqrt(radius2 - bound2));
factor = bound / max_radian;
}
void root(uchar4 *out, uint32_t x, uint32_t y) {
// Convert x and y to floating point coordinates with center as origin
float2 coord;
coord.x = (float)x / dimensions.x;
coord.y = (float)y / dimensions.y;
coord -= center;
const float dist = length(scale * coord);
const float radian = M_PI_2 - atan((alpha * sqrt(radius2 - dist * dist)) / dist);
const float scalar = radian * factor / dist;
const float2 new_coord = coord * scalar + center;
const float4 fout = rsSample(in_alloc, sampler, new_coord);
*out = rsPackColorTo8888(fout);
}

View File

@@ -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.image2)
#include "fisheye.rsh"

View File

@@ -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.image2)
#pragma rs_fp_relaxed
#include "fisheye.rsh"

View File

@@ -0,0 +1,92 @@
/*
* 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.image2)
#pragma rs_fp_relaxed
void genRand(uchar *out) {
*out = (uchar)rsRand(0xff);
}
/*
* Convolution matrix of distance 2 with fixed point of 'kShiftBits' bits
* shifted. Thus the sum of this matrix should be 'kShiftValue'. Entries of
* small values are not calculated to gain efficiency.
* The order ot pixels represented in this matrix is:
* 1 2 3
* 4 0 5
* 6 7 8
* and the matrix should be: {230, 56, 114, 56, 114, 114, 56, 114, 56}.
* However, since most of the valus are identical, we only use the first three
* entries and the entries corresponding to the pixels is:
* 1 2 1
* 2 0 2
* 1 2 1
*/
int32_t gWidth;
int32_t gHeight;
rs_allocation gBlendSource;
void blend9(uchar *out, uint32_t x, uint32_t y) {
uint32_t x1 = min(x+1, (uint32_t)gWidth);
uint32_t x2 = max(x-1, (uint32_t)0);
uint32_t y1 = min(y+1, (uint32_t)gHeight);
uint32_t y2 = max(y-1, (uint32_t)0);
uint p00 = 56 * ((uchar *)rsGetElementAt(gBlendSource, x1, y1))[0];
uint p01 = 114 * ((uchar *)rsGetElementAt(gBlendSource, x, y1))[0];
uint p02 = 56 * ((uchar *)rsGetElementAt(gBlendSource, x2, y1))[0];
uint p10 = 114 * ((uchar *)rsGetElementAt(gBlendSource, x1, y))[0];
uint p11 = 230 * ((uchar *)rsGetElementAt(gBlendSource, x, y))[0];
uint p12 = 114 * ((uchar *)rsGetElementAt(gBlendSource, x2, y))[0];
uint p20 = 56 * ((uchar *)rsGetElementAt(gBlendSource, x1, y2))[0];
uint p21 = 114 * ((uchar *)rsGetElementAt(gBlendSource, x, y2))[0];
uint p22 = 56 * ((uchar *)rsGetElementAt(gBlendSource, x2, y2))[0];
p00 += p01;
p02 += p10;
p11 += p12;
p20 += p21;
p22 += p00;
p02 += p11;
p20 += p22;
p20 += p02;
*out = (uchar)(p20 >> 10);
}
float gNoiseStrength;
rs_allocation gNoise;
void root(const uchar4 *in, uchar4 *out, uint32_t x, uint32_t y) {
float4 ip = convert_float4(*in);
float pnoise = (float) ((uchar *)rsGetElementAt(gNoise, x, y))[0];
float energy_level = ip.r + ip.g + ip.b;
float energy_mask = (28.f - sqrt(energy_level)) * 0.03571f;
pnoise = (pnoise - 128.f) * energy_mask;
ip += pnoise * gNoiseStrength;
ip = clamp(ip, 0.f, 255.f);
uchar4 p = convert_uchar4(ip);
p.a = 0xff;
*out = p;
}

View File

@@ -0,0 +1,30 @@
/*
* 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.image2)
#pragma rs_fp_relaxed
const static float3 gMonoMult = {0.299f, 0.587f, 0.114f};
void root(const uchar4 *v_in, uchar4 *v_out) {
float4 f4 = rsUnpackColor8888(*v_in);
float3 mono = dot(f4.rgb, gMonoMult);
*v_out = rsPackColorTo8888(mono);
}

View File

@@ -0,0 +1,28 @@
#pragma version(1)
#pragma rs_fp_relaxed
#include "ip.rsh"
void root(float4 *out, const void *usrData, uint32_t x, uint32_t y) {
const FilterStruct *fs = (const FilterStruct *)usrData;
float3 blurredPixel = 0;
const float *gPtr = fs->gaussian;
if ((x > fs->radius) && (x < (fs->width - fs->radius))) {
for (int r = -fs->radius; r <= fs->radius; r ++) {
const float4 *i = (const float4 *)rsGetElementAt(fs->ain, x + r, y);
blurredPixel += i->xyz * gPtr[0];
gPtr++;
}
} else {
for (int r = -fs->radius; r <= fs->radius; r ++) {
// Stepping left and right away from the pixel
int validX = rsClamp((int)x + r, (int)0, (int)(fs->width - 1));
const float4 *i = (const float4 *)rsGetElementAt(fs->ain, validX, y);
blurredPixel += i->xyz * gPtr[0];
gPtr++;
}
}
out->xyz = blurredPixel;
}

View File

@@ -0,0 +1,15 @@
#pragma rs java_package_name(com.android.rs.image2)
#define MAX_RADIUS 25
typedef struct FilterStruct_s {
rs_allocation ain;
float *gaussian; //[MAX_RADIUS * 2 + 1];
int height;
int width;
int radius;
} FilterStruct;

View File

@@ -0,0 +1,44 @@
/*
* 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.
*/
float inBlack;
float outBlack;
float inWMinInB;
float outWMinOutB;
float overInWMinInB;
rs_matrix3x3 colorMat;
void root(const uchar4 *in, uchar4 *out, uint32_t x, uint32_t y) {
float3 pixel = convert_float4(in[0]).rgb;
pixel = rsMatrixMultiply(&colorMat, pixel);
pixel = clamp(pixel, 0.f, 255.f);
pixel = (pixel - inBlack) * overInWMinInB;
pixel = pixel * outWMinOutB + outBlack;
pixel = clamp(pixel, 0.f, 255.f);
out->xyz = convert_uchar3(pixel);
out->w = 0xff;
}
void root4(const uchar4 *in, uchar4 *out, uint32_t x, uint32_t y) {
float4 pixel = convert_float4(in[0]);
pixel.rgb = rsMatrixMultiply(&colorMat, pixel.rgb);
pixel = clamp(pixel, 0.f, 255.f);
pixel = (pixel - inBlack) * overInWMinInB;
pixel = pixel * outWMinOutB + outBlack;
pixel = clamp(pixel, 0.f, 255.f);
out->xyzw = convert_uchar4(pixel);
}

View File

@@ -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.image2)
#include "levels.rsh"

View File

@@ -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.image2)
#pragma rs_fp_relaxed
#include "levels.rsh"

View File

@@ -0,0 +1,93 @@
#pragma version(1)
#include "ip.rsh"
int height;
int width;
int radius;
uchar4 * InPixel;
uchar4 * OutPixel;
float4 * ScratchPixel1;
float4 * ScratchPixel2;
rs_script vBlurScript;
rs_script hBlurScript;
const int CMD_FINISHED = 1;
// Store our coefficients here
static float gaussian[MAX_RADIUS * 2 + 1];
static void computeGaussianWeights() {
// Compute gaussian weights for the blur
// e is the euler's number
float e = 2.718281828459045f;
float pi = 3.1415926535897932f;
// g(x) = ( 1 / sqrt( 2 * pi ) * sigma) * e ^ ( -x^2 / 2 * sigma^2 )
// x is of the form [-radius .. 0 .. radius]
// and sigma varies with radius.
// Based on some experimental radius values and sigma's
// we approximately fit sigma = f(radius) as
// sigma = radius * 0.4 + 0.6
// The larger the radius gets, the more our gaussian blur
// will resemble a box blur since with large sigma
// the gaussian curve begins to lose its shape
float sigma = 0.4f * (float)radius + 0.6f;
// Now compute the coefficints
// We will store some redundant values to save some math during
// the blur calculations
// precompute some values
float coeff1 = 1.0f / (sqrt( 2.0f * pi ) * sigma);
float coeff2 = - 1.0f / (2.0f * sigma * sigma);
float normalizeFactor = 0.0f;
float floatR = 0.0f;
int r;
for (r = -radius; r <= radius; r ++) {
floatR = (float)r;
gaussian[r + radius] = coeff1 * pow(e, floatR * floatR * coeff2);
normalizeFactor += gaussian[r + radius];
}
//Now we need to normalize the weights because all our coefficients need to add up to one
normalizeFactor = 1.0f / normalizeFactor;
for (r = -radius; r <= radius; r ++) {
floatR = (float)r;
gaussian[r + radius] *= normalizeFactor;
}
}
static void copyInput() {
rs_allocation ain;
ain = rsGetAllocation(InPixel);
uint32_t dimx = rsAllocationGetDimX(ain);
uint32_t dimy = rsAllocationGetDimY(ain);
for (uint32_t y = 0; y < dimy; y++) {
for (uint32_t x = 0; x < dimx; x++) {
ScratchPixel1[x + y * dimx] = convert_float4(InPixel[x + y * dimx]);
}
}
}
void filter() {
copyInput();
computeGaussianWeights();
FilterStruct fs;
fs.gaussian = gaussian;
fs.width = width;
fs.height = height;
fs.radius = radius;
fs.ain = rsGetAllocation(ScratchPixel1);
rsForEach(hBlurScript, fs.ain, rsGetAllocation(ScratchPixel2), &fs, sizeof(fs));
fs.ain = rsGetAllocation(ScratchPixel2);
rsForEach(vBlurScript, fs.ain, rsGetAllocation(OutPixel), &fs, sizeof(fs));
//rsSendToClientBlocking(CMD_FINISHED);
}

View File

@@ -0,0 +1,59 @@
#pragma version(1)
#pragma rs_fp_relaxed
#include "ip.rsh"
static float saturation;
static rs_matrix3x3 colorMat;
void setSaturation(float sat) {
saturation = sat;
// Saturation
// Linear weights
//float rWeight = 0.3086f;
//float gWeight = 0.6094f;
//float bWeight = 0.0820f;
// Gamma 2.2 weights (we haven't converted our image to linear space yet for perf reasons)
float rWeight = 0.299f;
float gWeight = 0.587f;
float bWeight = 0.114f;
float oneMinusS = 1.0f - saturation;
rsMatrixSet(&colorMat, 0, 0, oneMinusS * rWeight + saturation);
rsMatrixSet(&colorMat, 0, 1, oneMinusS * rWeight);
rsMatrixSet(&colorMat, 0, 2, oneMinusS * rWeight);
rsMatrixSet(&colorMat, 1, 0, oneMinusS * gWeight);
rsMatrixSet(&colorMat, 1, 1, oneMinusS * gWeight + saturation);
rsMatrixSet(&colorMat, 1, 2, oneMinusS * gWeight);
rsMatrixSet(&colorMat, 2, 0, oneMinusS * bWeight);
rsMatrixSet(&colorMat, 2, 1, oneMinusS * bWeight);
rsMatrixSet(&colorMat, 2, 2, oneMinusS * bWeight + saturation);
}
void root(uchar4 *out, const void *usrData, uint32_t x, uint32_t y) {
const FilterStruct *fs = (const FilterStruct *)usrData;
float3 blurredPixel = 0;
const float *gPtr = fs->gaussian;
if ((y > fs->radius) && (y < (fs->height - fs->radius))) {
for (int r = -fs->radius; r <= fs->radius; r ++) {
const float4 *i = (const float4 *)rsGetElementAt(fs->ain, x, y + r);
blurredPixel += i->xyz * gPtr[0];
gPtr++;
}
} else {
for (int r = -fs->radius; r <= fs->radius; r ++) {
int validH = rsClamp((int)y + r, (int)0, (int)(fs->height - 1));
const float4 *i = (const float4 *)rsGetElementAt(fs->ain, x, validH);
blurredPixel += i->xyz * gPtr[0];
gPtr++;
}
}
float3 temp = rsMatrixMultiply(&colorMat, blurredPixel);
temp = clamp(temp, 0.f, 255.f);
out->xyz = convert_uchar3(temp);
out->w = 0xff;
}

View File

@@ -0,0 +1,59 @@
/*
* 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 = length(axis_scale * coord) * sloped_inv_max_dist;
const float lumen = opp_shade + shade / ( 1.0 + sloped_neg_range * exp(sloped_dist_ratio) );
float4 fout;
fout.rgb = fin.rgb * lumen;
fout.w = fin.w;
*out = convert_uchar4(fout);
}

View File

@@ -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.image2)
#include "vignette.rsh"

View File

@@ -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.image2)
#pragma rs_fp_relaxed
#include "vignette.rsh"