summaryrefslogtreecommitdiffstats
path: root/tests/RenderScriptTests
diff options
context:
space:
mode:
Diffstat (limited to 'tests/RenderScriptTests')
-rw-r--r--tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/Blur25G.java97
-rw-r--r--tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java63
-rw-r--r--tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/TestBase.java21
-rw-r--r--tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/greyscale.fs8
-rw-r--r--tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/msg.rs23
-rw-r--r--tests/RenderScriptTests/ImageProcessing2/src/com/android/rs/image/convolve3x3.rs4
-rw-r--r--tests/RenderScriptTests/ImageProcessing2/src/com/android/rs/image/convolve5x5.rs1
-rw-r--r--tests/RenderScriptTests/ImageProcessing2/src/com/android/rs/image/mandelbrot.rs2
-rw-r--r--tests/RenderScriptTests/ImageProcessing_jb/Android.mk29
-rw-r--r--tests/RenderScriptTests/ImageProcessing_jb/AndroidManifest.xml16
-rw-r--r--tests/RenderScriptTests/ImageProcessing_jb/res/drawable-nodpi/img1600x1067.jpgbin0 -> 1062402 bytes
-rw-r--r--tests/RenderScriptTests/ImageProcessing_jb/res/drawable-nodpi/img1600x1067b.jpgbin0 -> 1205161 bytes
-rw-r--r--tests/RenderScriptTests/ImageProcessing_jb/res/layout/main.xml139
-rw-r--r--tests/RenderScriptTests/ImageProcessing_jb/res/layout/spinner_layout.xml23
-rw-r--r--tests/RenderScriptTests/ImageProcessing_jb/res/values/strings.xml34
-rw-r--r--tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/Blur25.java90
-rw-r--r--tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/ColorMatrix.java52
-rw-r--r--tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/Convolve3x3.java59
-rw-r--r--tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/Convolve5x5.java73
-rw-r--r--tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/Copy.java40
-rw-r--r--tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/Grain.java94
-rw-r--r--tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/Greyscale.java40
-rw-r--r--tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/ImageProcessingActivityJB.java386
-rw-r--r--tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/LevelsV4.java167
-rw-r--r--tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/Mandelbrot.java98
-rw-r--r--tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/TestBase.java161
-rw-r--r--tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/Vignette.java125
-rw-r--r--tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/colormatrix.rs38
-rw-r--r--tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/convolve3x3.rs71
-rw-r--r--tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/convolve5x5.rs78
-rw-r--r--tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/copy.rs24
-rw-r--r--tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/grain.rs101
-rw-r--r--tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/greyscale.rs30
-rw-r--r--tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/levels.rsh44
-rw-r--r--tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/levels_full.rs21
-rw-r--r--tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/levels_relaxed.rs22
-rw-r--r--tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/mandelbrot.rs56
-rw-r--r--tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/msg.rs23
-rw-r--r--tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/threshold.rs106
-rw-r--r--tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/vignette.rsh59
-rw-r--r--tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/vignette_full.rs21
-rw-r--r--tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/vignette_relaxed.rs22
-rw-r--r--tests/RenderScriptTests/LatencyBenchmark/Android.mk27
-rw-r--r--tests/RenderScriptTests/LatencyBenchmark/AndroidManifest.xml30
-rw-r--r--tests/RenderScriptTests/LatencyBenchmark/res/layout/main.xml31
-rw-r--r--tests/RenderScriptTests/LatencyBenchmark/src/com/example/android/rs/computebench/Benchmark.java63
-rw-r--r--tests/RenderScriptTests/LatencyBenchmark/src/com/example/android/rs/computebench/LatencyBench.java37
-rw-r--r--tests/RenderScriptTests/LatencyBenchmark/src/com/example/android/rs/computebench/compute_benchmark.rs29
48 files changed, 2760 insertions, 18 deletions
diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/Blur25G.java b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/Blur25G.java
new file mode 100644
index 0000000..ac0dad1
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/Blur25G.java
@@ -0,0 +1,97 @@
+/*
+ * 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.image;
+
+import java.lang.Math;
+
+import android.graphics.Bitmap;
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.RenderScript;
+import android.renderscript.ScriptIntrinsicBlur;
+import android.renderscript.Type;
+import android.util.Log;
+import android.widget.SeekBar;
+import android.widget.TextView;
+
+public class Blur25G extends TestBase {
+ private final int MAX_RADIUS = 25;
+ private float mRadius = MAX_RADIUS;
+
+ private ScriptIntrinsicBlur mIntrinsic;
+
+ private ScriptC_greyscale mScript;
+ private Allocation mScratchPixelsAllocation1;
+ private Allocation mScratchPixelsAllocation2;
+
+
+ public Blur25G() {
+ }
+
+ public boolean onBar1Setup(SeekBar b, TextView t) {
+ t.setText("Radius");
+ b.setProgress(100);
+ return true;
+ }
+
+
+ public void onBar1Changed(int progress) {
+ mRadius = ((float)progress) / 100.0f * MAX_RADIUS;
+ if (mRadius <= 0.10f) {
+ mRadius = 0.10f;
+ }
+ mIntrinsic.setRadius(mRadius);
+ }
+
+
+ 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);
+ mScratchPixelsAllocation1 = Allocation.createTyped(mRS, tb.create());
+ mScratchPixelsAllocation2 = Allocation.createTyped(mRS, tb.create());
+
+ mScript = new ScriptC_greyscale(mRS);
+ mScript.forEach_toU8(mInPixelsAllocation, mScratchPixelsAllocation1);
+
+ mIntrinsic = ScriptIntrinsicBlur.create(mRS, Element.U8(mRS));
+ mIntrinsic.setRadius(MAX_RADIUS);
+ mIntrinsic.setInput(mScratchPixelsAllocation1);
+ }
+
+ public void runTest() {
+ mIntrinsic.forEach(mScratchPixelsAllocation2);
+ }
+
+ public void setupBenchmark() {
+ mIntrinsic.setRadius(MAX_RADIUS);
+ }
+
+ public void exitBenchmark() {
+ mIntrinsic.setRadius(mRadius);
+ }
+
+ public void updateBitmap(Bitmap b) {
+ mScript.forEach_toU8_4(mScratchPixelsAllocation2, mOutPixelsAllocation);
+ mOutPixelsAllocation.copyTo(b);
+ }
+
+}
+
diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java
index db0ef78..90fa74f 100644
--- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java
+++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java
@@ -18,6 +18,8 @@ package com.android.rs.image;
import android.app.Activity;
import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
import android.graphics.BitmapFactory;
import android.graphics.Bitmap;
import android.graphics.Canvas;
@@ -82,11 +84,37 @@ public class ImageProcessingActivity extends Activity
private boolean mDoingBenchmark;
private TestBase mTest;
+ private int mRunCount;
public void updateDisplay() {
+ mHandler.sendMessage(Message.obtain());
+ }
+
+ private Handler mHandler = new Handler() {
+ // Allow the filter to complete without blocking the UI
+ // thread. When the message arrives that the op is complete
+ // we will either mark completion or start a new filter if
+ // more work is ready. Either way, display the result.
+ @Override
+ public void handleMessage(Message msg) {
mTest.updateBitmap(mBitmapOut);
mDisplayView.invalidate();
- }
+
+ boolean doTest = false;
+ synchronized(this) {
+ if (mRunCount > 0) {
+ mRunCount--;
+ if (mRunCount > 0) {
+ doTest = true;
+ }
+ }
+ }
+ if (doTest) {
+ mTest.runTestSendMessage();
+ }
+ }
+
+ };
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (fromUser) {
@@ -103,8 +131,18 @@ public class ImageProcessingActivity extends Activity
mTest.onBar5Changed(progress);
}
- mTest.runTest();
- updateDisplay();
+ boolean doTest = false;
+ synchronized(this) {
+ if (mRunCount == 0) {
+ doTest = true;
+ mRunCount = 1;
+ } else {
+ mRunCount = 2;
+ }
+ }
+ if (doTest) {
+ mTest.runTestSendMessage();
+ }
}
}
@@ -232,6 +270,9 @@ public class ImageProcessingActivity extends Activity
case 28:
mTest = new Blend();
break;
+ case 29:
+ mTest = new Blur25G();
+ break;
}
mTest.createBaseTest(this, mBitmapIn, mBitmapIn2);
@@ -243,7 +284,7 @@ public class ImageProcessingActivity extends Activity
}
void setupTests() {
- mTestNames = new String[29];
+ mTestNames = new String[30];
mTestNames[0] = "Levels Vec3 Relaxed";
mTestNames[1] = "Levels Vec4 Relaxed";
mTestNames[2] = "Levels Vec3 Full";
@@ -273,6 +314,7 @@ public class ImageProcessingActivity extends Activity
mTestNames[26] = "Intrinsics Convolve 5x5";
mTestNames[27] = "Mandelbrot";
mTestNames[28] = "Intrinsics Blend";
+ mTestNames[29] = "Intrinsics Blur 25 uchar";
mTestSpinner.setAdapter(new ArrayAdapter<String>(
this, R.layout.spinner_layout, mTestNames));
@@ -296,7 +338,8 @@ public class ImageProcessingActivity extends Activity
mBitmapIn = loadBitmap(R.drawable.img1600x1067);
mBitmapIn2 = loadBitmap(R.drawable.img1600x1067b);
- mBitmapOut = loadBitmap(R.drawable.img1600x1067);
+ mBitmapOut = Bitmap.createBitmap(mBitmapIn.getWidth(), mBitmapIn.getHeight(),
+ mBitmapIn.getConfig());
mSurfaceView = (SurfaceView) findViewById(R.id.surface);
@@ -337,15 +380,7 @@ public class ImageProcessingActivity extends Activity
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;
+ return BitmapFactory.decodeResource(getResources(), resource, options);
}
// button hook
diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/TestBase.java b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/TestBase.java
index bb3f2f3..d4c4898 100644
--- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/TestBase.java
+++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/TestBase.java
@@ -45,9 +45,22 @@ public class TestBase {
protected Allocation mInPixelsAllocation;
protected Allocation mInPixelsAllocation2;
protected Allocation mOutPixelsAllocation;
+ protected ScriptC_msg mMessageScript;
protected ImageProcessingActivity act;
+ private class MessageProcessor extends RenderScript.RSMessageHandler {
+ ImageProcessingActivity mAct;
+
+ MessageProcessor(ImageProcessingActivity act) {
+ mAct = act;
+ }
+
+ public void run() {
+ mAct.updateDisplay();
+ }
+ }
+
// Override to use UI elements
public void onBar1Changed(int progress) {
}
@@ -96,6 +109,8 @@ public class TestBase {
public final void createBaseTest(ImageProcessingActivity ipact, Bitmap b, Bitmap b2) {
act = ipact;
mRS = RenderScript.create(act);
+ mRS.setMessageHandler(new MessageProcessor(act));
+ mMessageScript = new ScriptC_msg(mRS);
mInPixelsAllocation = Allocation.createFromBitmap(mRS, b,
Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);
@@ -110,13 +125,17 @@ public class TestBase {
// Must override
public void createTest(android.content.res.Resources res) {
- android.util.Log.e("img", "implement createTest");
}
// Must override
public void runTest() {
}
+ final public void runTestSendMessage() {
+ runTest();
+ mMessageScript.invoke_sendMsg();
+ }
+
public void finish() {
mRS.finish();
}
diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/greyscale.fs b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/greyscale.fs
index 90ba058..d419459 100644
--- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/greyscale.fs
+++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/greyscale.fs
@@ -27,4 +27,12 @@ uchar4 __attribute__((kernel)) root(uchar4 v_in) {
return rsPackColorTo8888(mono);
}
+uchar __attribute__((kernel)) toU8(uchar4 v_in) {
+ float4 f4 = convert_float4(v_in);
+ return (uchar)dot(f4.rgb, gMonoMult);
+}
+
+uchar4 __attribute__((kernel)) toU8_4(uchar v_in) {
+ return (uchar4)v_in;
+}
diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/msg.rs b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/msg.rs
new file mode 100644
index 0000000..1a19ffc
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/msg.rs
@@ -0,0 +1,23 @@
+/*
+ * 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)
+
+void sendMsg() {
+ rsSendToClientBlocking(0);
+}
+
diff --git a/tests/RenderScriptTests/ImageProcessing2/src/com/android/rs/image/convolve3x3.rs b/tests/RenderScriptTests/ImageProcessing2/src/com/android/rs/image/convolve3x3.rs
index b55190c..13f9032 100644
--- a/tests/RenderScriptTests/ImageProcessing2/src/com/android/rs/image/convolve3x3.rs
+++ b/tests/RenderScriptTests/ImageProcessing2/src/com/android/rs/image/convolve3x3.rs
@@ -25,9 +25,9 @@ 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 x1 = min((int32_t)x+1, gWidth-1);
uint32_t x2 = max((int32_t)x-1, 0);
- uint32_t y1 = min((int32_t)y+1, gHeight);
+ uint32_t y1 = min((int32_t)y+1, gHeight-1);
uint32_t y2 = max((int32_t)y-1, 0);
float4 p00 = convert_float4(((uchar4 *)rsGetElementAt(gIn, x1, y1))[0]);
diff --git a/tests/RenderScriptTests/ImageProcessing2/src/com/android/rs/image/convolve5x5.rs b/tests/RenderScriptTests/ImageProcessing2/src/com/android/rs/image/convolve5x5.rs
index b110b88..b1ad241 100644
--- a/tests/RenderScriptTests/ImageProcessing2/src/com/android/rs/image/convolve5x5.rs
+++ b/tests/RenderScriptTests/ImageProcessing2/src/com/android/rs/image/convolve5x5.rs
@@ -68,6 +68,7 @@ void root(uchar4 *out, uint32_t x, uint32_t y) {
+ convert_float4(rsGetElementAt_uchar4(gIn, x4, y4)) * gCoeffs[24];
p0 = clamp(p0 + p1 + p2 + p3 + p4, 0.f, 255.f);
+ p0.a = 255.f;
*out = convert_uchar4(p0);
}
diff --git a/tests/RenderScriptTests/ImageProcessing2/src/com/android/rs/image/mandelbrot.rs b/tests/RenderScriptTests/ImageProcessing2/src/com/android/rs/image/mandelbrot.rs
index 55e5304..5b3912d 100644
--- a/tests/RenderScriptTests/ImageProcessing2/src/com/android/rs/image/mandelbrot.rs
+++ b/tests/RenderScriptTests/ImageProcessing2/src/com/android/rs/image/mandelbrot.rs
@@ -43,7 +43,7 @@ void root(uchar4 *v_out, uint32_t x, uint32_t y) {
// write a non-transparent black pixel
*v_out = (uchar4){0, 0, 0, 0xff};
} else {
- float mi3 = gMaxIteration / 3.;
+ float mi3 = gMaxIteration / 3.f;
if (iter <= (gMaxIteration / 3))
*v_out = (uchar4){0xff * (iter / mi3), 0, 0, 0xff};
else if (iter <= (((gMaxIteration / 3) * 2)))
diff --git a/tests/RenderScriptTests/ImageProcessing_jb/Android.mk b/tests/RenderScriptTests/ImageProcessing_jb/Android.mk
new file mode 100644
index 0000000..6cdd1c0
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing_jb/Android.mk
@@ -0,0 +1,29 @@
+#
+# 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.renderscript
+
+LOCAL_PACKAGE_NAME := ImageProcessingJB
+LOCAL_SDK_VERSION := 16
+
+include $(BUILD_PACKAGE)
diff --git a/tests/RenderScriptTests/ImageProcessing_jb/AndroidManifest.xml b/tests/RenderScriptTests/ImageProcessing_jb/AndroidManifest.xml
new file mode 100644
index 0000000..b3fcfc4
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing_jb/AndroidManifest.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.rs.imagejb">
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+ <uses-sdk android:minSdkVersion="11" />
+ <application android:label="Image Processing JB"
+ android:hardwareAccelerated="true">
+ <activity android:name="ImageProcessingActivityJB">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+</manifest>
diff --git a/tests/RenderScriptTests/ImageProcessing_jb/res/drawable-nodpi/img1600x1067.jpg b/tests/RenderScriptTests/ImageProcessing_jb/res/drawable-nodpi/img1600x1067.jpg
new file mode 100644
index 0000000..05d3ee2
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing_jb/res/drawable-nodpi/img1600x1067.jpg
Binary files differ
diff --git a/tests/RenderScriptTests/ImageProcessing_jb/res/drawable-nodpi/img1600x1067b.jpg b/tests/RenderScriptTests/ImageProcessing_jb/res/drawable-nodpi/img1600x1067b.jpg
new file mode 100644
index 0000000..aed0781
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing_jb/res/drawable-nodpi/img1600x1067b.jpg
Binary files differ
diff --git a/tests/RenderScriptTests/ImageProcessing_jb/res/layout/main.xml b/tests/RenderScriptTests/ImageProcessing_jb/res/layout/main.xml
new file mode 100644
index 0000000..f0a2b92
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing_jb/res/layout/main.xml
@@ -0,0 +1,139 @@
+<?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"/>
+ <Spinner
+ android:id="@+id/spinner1"
+ 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"/>
+ <Button
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/benchmark_all"
+ android:onClick="benchmark_all"/>
+ </LinearLayout>
+ </ScrollView>
+</LinearLayout>
+
diff --git a/tests/RenderScriptTests/ImageProcessing_jb/res/layout/spinner_layout.xml b/tests/RenderScriptTests/ImageProcessing_jb/res/layout/spinner_layout.xml
new file mode 100644
index 0000000..8196bbf
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing_jb/res/layout/spinner_layout.xml
@@ -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"
+/>
diff --git a/tests/RenderScriptTests/ImageProcessing_jb/res/values/strings.xml b/tests/RenderScriptTests/ImageProcessing_jb/res/values/strings.xml
new file mode 100644
index 0000000..a7dd165
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing_jb/res/values/strings.xml
@@ -0,0 +1,34 @@
+<?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>
+ <string name="benchmark_all">Benchmark All</string>
+
+</resources>
diff --git a/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/Blur25.java b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/Blur25.java
new file mode 100644
index 0000000..d7e918b
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/Blur25.java
@@ -0,0 +1,90 @@
+/*
+ * 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.imagejb;
+
+import java.lang.Math;
+
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.RenderScript;
+import android.renderscript.Type;
+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 float mRadius = MAX_RADIUS;
+ private float mSaturation = 1.0f;
+ private Allocation mScratchPixelsAllocation1;
+ private Allocation mScratchPixelsAllocation2;
+
+
+ public Blur25() {
+ }
+
+ public boolean onBar1Setup(SeekBar b, TextView t) {
+ t.setText("Radius");
+ b.setProgress(100);
+ return true;
+ }
+
+
+ public void onBar1Changed(int progress) {
+ mRadius = ((float)progress) / 100.0f * MAX_RADIUS;
+ if (mRadius <= 0.10f) {
+ mRadius = 0.10f;
+ }
+ mScript.invoke_setRadius((int)mRadius);
+ }
+
+
+ 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());
+
+ mScript = new ScriptC_threshold(mRS, res, R.raw.threshold);
+ mScript.set_width(width);
+ mScript.set_height(height);
+ mScript.invoke_setRadius(MAX_RADIUS);
+
+ mScript.set_InPixel(mInPixelsAllocation);
+ mScript.set_ScratchPixel1(mScratchPixelsAllocation1);
+ mScript.set_ScratchPixel2(mScratchPixelsAllocation2);
+ }
+
+ public void runTest() {
+ mScript.forEach_copyIn(mInPixelsAllocation, mScratchPixelsAllocation1);
+ mScript.forEach_horz(mScratchPixelsAllocation2);
+ mScript.forEach_vert(mOutPixelsAllocation);
+ }
+
+ public void setupBenchmark() {
+ mScript.invoke_setRadius(MAX_RADIUS);
+ }
+
+ public void exitBenchmark() {
+ mScript.invoke_setRadius((int)mRadius);
+ }
+}
diff --git a/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/ColorMatrix.java b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/ColorMatrix.java
new file mode 100644
index 0000000..62ca694
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/ColorMatrix.java
@@ -0,0 +1,52 @@
+/*
+ * 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.imagejb;
+
+import java.lang.Math;
+
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.Matrix4f;
+import android.renderscript.RenderScript;
+import android.renderscript.Script;
+import android.renderscript.ScriptC;
+import android.renderscript.Type;
+import android.util.Log;
+
+public class ColorMatrix extends TestBase {
+ private ScriptC_colormatrix mScript;
+ private boolean mUseGrey;
+
+ public ColorMatrix(boolean useGrey) {
+ mUseGrey = useGrey;
+ }
+
+ public void createTest(android.content.res.Resources res) {
+ Matrix4f m = new Matrix4f();
+ m.set(1, 0, 0.2f);
+ m.set(1, 1, 0.9f);
+ m.set(1, 2, 0.2f);
+
+ mScript = new ScriptC_colormatrix(mRS, res, R.raw.colormatrix);
+ mScript.invoke_setMatrix(m);
+ }
+
+ public void runTest() {
+ mScript.forEach_root(mInPixelsAllocation, mOutPixelsAllocation);
+ }
+
+}
diff --git a/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/Convolve3x3.java b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/Convolve3x3.java
new file mode 100644
index 0000000..6673032
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/Convolve3x3.java
@@ -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.
+ */
+
+package com.android.rs.imagejb;
+
+import java.lang.Math;
+
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.Matrix4f;
+import android.renderscript.RenderScript;
+import android.renderscript.Script;
+import android.renderscript.ScriptC;
+import android.renderscript.Type;
+import android.util.Log;
+
+public class Convolve3x3 extends TestBase {
+ private ScriptC_convolve3x3 mScript;
+
+ private int mWidth;
+ private int mHeight;
+
+ public Convolve3x3() {
+ }
+
+ public void createTest(android.content.res.Resources res) {
+ mWidth = mInPixelsAllocation.getType().getX();
+ mHeight = mInPixelsAllocation.getType().getY();
+
+ 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;
+
+ mScript = new ScriptC_convolve3x3(mRS, res, R.raw.convolve3x3);
+ mScript.set_gCoeffs(f);
+ mScript.set_gIn(mInPixelsAllocation);
+ mScript.set_gWidth(mWidth);
+ mScript.set_gHeight(mHeight);
+ }
+
+ public void runTest() {
+ mScript.forEach_root(mOutPixelsAllocation);
+ }
+
+}
diff --git a/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/Convolve5x5.java b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/Convolve5x5.java
new file mode 100644
index 0000000..895d459
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/Convolve5x5.java
@@ -0,0 +1,73 @@
+/*
+ * 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.imagejb;
+
+import java.lang.Math;
+
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.Matrix4f;
+import android.renderscript.RenderScript;
+import android.renderscript.Script;
+import android.renderscript.ScriptC;
+import android.renderscript.Type;
+import android.util.Log;
+
+public class Convolve5x5 extends TestBase {
+ private ScriptC_convolve5x5 mScript;
+
+ private int mWidth;
+ private int mHeight;
+
+ public Convolve5x5() {
+ }
+
+ public void createTest(android.content.res.Resources res) {
+ mWidth = mInPixelsAllocation.getType().getX();
+ mHeight = mInPixelsAllocation.getType().getY();
+
+ float f[] = new float[25];
+ //f[0] = 0.012f; f[1] = 0.025f; f[2] = 0.031f; f[3] = 0.025f; f[4] = 0.012f;
+ //f[5] = 0.025f; f[6] = 0.057f; f[7] = 0.075f; f[8] = 0.057f; f[9] = 0.025f;
+ //f[10]= 0.031f; f[11]= 0.075f; f[12]= 0.095f; f[13]= 0.075f; f[14]= 0.031f;
+ //f[15]= 0.025f; f[16]= 0.057f; f[17]= 0.075f; f[18]= 0.057f; f[19]= 0.025f;
+ //f[20]= 0.012f; f[21]= 0.025f; f[22]= 0.031f; f[23]= 0.025f; f[24]= 0.012f;
+
+ //f[0] = 1.f; f[1] = 2.f; f[2] = 0.f; f[3] = -2.f; f[4] = -1.f;
+ //f[5] = 4.f; f[6] = 8.f; f[7] = 0.f; f[8] = -8.f; f[9] = -4.f;
+ //f[10]= 6.f; f[11]=12.f; f[12]= 0.f; f[13]=-12.f; f[14]= -6.f;
+ //f[15]= 4.f; f[16]= 8.f; f[17]= 0.f; f[18]= -8.f; f[19]= -4.f;
+ //f[20]= 1.f; f[21]= 2.f; f[22]= 0.f; f[23]= -2.f; f[24]= -1.f;
+
+ f[0] = -1.f; f[1] = -3.f; f[2] = -4.f; f[3] = -3.f; f[4] = -1.f;
+ f[5] = -3.f; f[6] = 0.f; f[7] = 6.f; f[8] = 0.f; f[9] = -3.f;
+ f[10]= -4.f; f[11]= 6.f; f[12]= 20.f; f[13]= 6.f; f[14]= -4.f;
+ f[15]= -3.f; f[16]= 0.f; f[17]= 6.f; f[18]= 0.f; f[19]= -3.f;
+ f[20]= -1.f; f[21]= -3.f; f[22]= -4.f; f[23]= -3.f; f[24]= -1.f;
+
+ mScript = new ScriptC_convolve5x5(mRS, res, R.raw.convolve5x5);
+ mScript.set_gCoeffs(f);
+ mScript.set_gIn(mInPixelsAllocation);
+ mScript.set_gWidth(mWidth);
+ mScript.set_gHeight(mHeight);
+ }
+
+ public void runTest() {
+ mScript.forEach_root(mOutPixelsAllocation);
+ }
+
+}
diff --git a/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/Copy.java b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/Copy.java
new file mode 100644
index 0000000..1bdee4b
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/Copy.java
@@ -0,0 +1,40 @@
+/*
+ * 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.imagejb;
+
+import java.lang.Math;
+
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.RenderScript;
+import android.renderscript.Script;
+import android.renderscript.ScriptC;
+import android.renderscript.Type;
+import android.util.Log;
+
+public class Copy extends TestBase {
+ private ScriptC_copy mScript;
+
+ public void createTest(android.content.res.Resources res) {
+ mScript = new ScriptC_copy(mRS, res, R.raw.copy);
+ }
+
+ public void runTest() {
+ mScript.forEach_root(mInPixelsAllocation, mOutPixelsAllocation);
+ }
+
+}
diff --git a/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/Grain.java b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/Grain.java
new file mode 100644
index 0000000..5cd19a2
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/Grain.java
@@ -0,0 +1,94 @@
+/*
+ * 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.imagejb;
+
+import java.lang.Math;
+
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.RenderScript;
+import android.renderscript.Script;
+import android.renderscript.ScriptC;
+import android.renderscript.Type;
+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);
+ }
+
+ private int findHighBit(int v) {
+ int bit = 0;
+ while (v > 1) {
+ bit++;
+ v >>= 1;
+ }
+ return bit;
+ }
+
+
+ public void createTest(android.content.res.Resources res) {
+ int width = mInPixelsAllocation.getType().getX();
+ int height = mInPixelsAllocation.getType().getY();
+
+ int noiseW = findHighBit(width);
+ int noiseH = findHighBit(height);
+ if (noiseW > 9) {
+ noiseW = 9;
+ }
+ if (noiseH > 9) {
+ noiseH = 9;
+ }
+ noiseW = 1 << noiseW;
+ noiseH = 1 << noiseH;
+
+ Type.Builder tb = new Type.Builder(mRS, Element.U8(mRS));
+ tb.setX(noiseW);
+ tb.setY(noiseH);
+ mNoise = Allocation.createTyped(mRS, tb.create());
+ mNoise2 = Allocation.createTyped(mRS, tb.create());
+
+ mScript = new ScriptC_grain(mRS, res, R.raw.grain);
+ mScript.set_gWMask(noiseW - 1);
+ mScript.set_gHMask(noiseH - 1);
+ 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);
+ }
+
+}
+
diff --git a/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/Greyscale.java b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/Greyscale.java
new file mode 100644
index 0000000..f1952e7
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/Greyscale.java
@@ -0,0 +1,40 @@
+/*
+ * 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.imagejb;
+
+import java.lang.Math;
+
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.RenderScript;
+import android.renderscript.Script;
+import android.renderscript.ScriptC;
+import android.renderscript.Type;
+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);
+ }
+
+}
diff --git a/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/ImageProcessingActivityJB.java b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/ImageProcessingActivityJB.java
new file mode 100644
index 0000000..b3b06d4
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/ImageProcessingActivityJB.java
@@ -0,0 +1,386 @@
+/*
+ * 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.imagejb;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.graphics.BitmapFactory;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.renderscript.ScriptC;
+import android.renderscript.RenderScript;
+import android.renderscript.Type;
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.Script;
+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;
+
+import android.os.Environment;
+import android.app.Instrumentation;
+import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+
+public class ImageProcessingActivityJB extends Activity
+ implements SeekBar.OnSeekBarChangeListener {
+ private final String TAG = "Img";
+ private final String RESULT_FILE = "image_processing_result.csv";
+
+ Bitmap mBitmapIn;
+ Bitmap mBitmapIn2;
+ Bitmap mBitmapOut;
+ String mTestNames[];
+
+ private Spinner mSpinner;
+ 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;
+ private int mRunCount;
+
+ public void updateDisplay() {
+ mHandler.sendMessage(Message.obtain());
+ }
+
+ private Handler mHandler = new Handler() {
+ @Override
+ public void handleMessage(Message msg) {
+ mTest.updateBitmap(mBitmapOut);
+ mDisplayView.invalidate();
+
+ android.util.Log.v("Img", "mRunCount hdl " + mRunCount);
+ boolean doTest = false;
+ synchronized(this) {
+ if (mRunCount > 0) {
+ mRunCount--;
+ if (mRunCount > 0) {
+ doTest = true;
+ }
+ }
+ }
+ if (doTest) {
+ mTest.runTestSendMessage();
+ }
+ }
+
+ };
+
+ 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);
+ }
+
+ boolean doTest = false;
+ synchronized(this) {
+ if (mRunCount == 0) {
+ doTest = true;
+ mRunCount = 1;
+ } else {
+ mRunCount = 2;
+ }
+ }
+ if (doTest) {
+ mTest.runTestSendMessage();
+ }
+ }
+ }
+
+ public void onStartTrackingTouch(SeekBar seekBar) {
+ }
+
+ public void onStopTrackingTouch(SeekBar seekBar) {
+ }
+
+ void setupBars() {
+ mSpinner.setVisibility(View.VISIBLE);
+ mTest.onSpinner1Setup(mSpinner);
+
+ 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) {
+ if (mTest != null) {
+ mTest.destroy();
+ }
+ 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 Vignette(false);
+ break;
+ case 8:
+ mTest = new Vignette(true);
+ break;
+ case 9:
+ mTest = new Convolve3x3();
+ break;
+ case 10:
+ mTest = new ColorMatrix(false);
+ break;
+ case 11:
+ mTest = new Copy();
+ break;
+ case 12:
+ mTest = new Convolve5x5();
+ break;
+ case 13:
+ mTest = new Mandelbrot();
+ break;
+ }
+
+ mTest.createBaseTest(this, mBitmapIn, mBitmapIn2);
+ setupBars();
+
+ mTest.runTest();
+ updateDisplay();
+ mBenchmarkResult.setText("Result: not run");
+ }
+
+ void setupTests() {
+ mTestNames = new String[14];
+ 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] = "Vignette Full";
+ mTestNames[8] = "Vignette Relaxed";
+ mTestNames[9] = "Convolve 3x3";
+ mTestNames[10] = "ColorMatrix";
+ mTestNames[11] = "Copy";
+ mTestNames[12] = "Convolve 5x5";
+ mTestNames[13] = "Mandelbrot";
+
+ 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.img1600x1067);
+ mBitmapIn2 = loadBitmap(R.drawable.img1600x1067b);
+ mBitmapOut = Bitmap.createBitmap(mBitmapIn.getWidth(), mBitmapIn.getHeight(),
+ mBitmapIn.getConfig());
+
+ mSurfaceView = (SurfaceView) findViewById(R.id.surface);
+
+ mDisplayView = (ImageView) findViewById(R.id.display);
+ mDisplayView.setImageBitmap(mBitmapOut);
+
+ mSpinner = (Spinner) findViewById(R.id.spinner1);
+
+ 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 BitmapFactory.decodeResource(getResources(), resource, options);
+ }
+
+ // button hook
+ public void benchmark(View v) {
+ float t = getBenchmark();
+ //long javaTime = javaFilter();
+ //mBenchmarkResult.setText("RS: " + t + " ms Java: " + javaTime + " ms");
+ mBenchmarkResult.setText("Result: " + t + " ms");
+ Log.v(TAG, "getBenchmark: Renderscript frame time core ms " + t);
+ }
+
+ public void benchmark_all(View v) {
+ // write result into a file
+ File externalStorage = Environment.getExternalStorageDirectory();
+ if (!externalStorage.canWrite()) {
+ Log.v(TAG, "sdcard is not writable");
+ return;
+ }
+ File resultFile = new File(externalStorage, RESULT_FILE);
+ resultFile.setWritable(true, false);
+ try {
+ BufferedWriter rsWriter = new BufferedWriter(new FileWriter(resultFile));
+ Log.v(TAG, "Saved results in: " + resultFile.getAbsolutePath());
+ for (int i = 0; i < mTestNames.length; i++ ) {
+ changeTest(i);
+ float t = getBenchmark();
+ String s = new String("" + mTestNames[i] + ", " + t);
+ rsWriter.write(s + "\n");
+ Log.v(TAG, "Test " + s + "ms\n");
+ }
+ rsWriter.close();
+ } catch (IOException e) {
+ Log.v(TAG, "Unable to write result file " + e.getMessage());
+ }
+ changeTest(0);
+ }
+
+ // For benchmark test
+ public float getBenchmark() {
+ mDoingBenchmark = true;
+
+ mTest.setupBenchmark();
+ long result = 0;
+
+ //Log.v(TAG, "Warming");
+ long t = java.lang.System.currentTimeMillis() + 250;
+ do {
+ mTest.runTest();
+ mTest.finish();
+ } while (t > java.lang.System.currentTimeMillis());
+
+
+ //Log.v(TAG, "Benchmarking");
+ int ct = 0;
+ t = java.lang.System.currentTimeMillis();
+ do {
+ mTest.runTest();
+ mTest.finish();
+ ct++;
+ } while ((t+1000) > java.lang.System.currentTimeMillis());
+ t = java.lang.System.currentTimeMillis() - t;
+ float ft = (float)t;
+ ft /= ct;
+
+ mTest.exitBenchmark();
+ mDoingBenchmark = false;
+
+ return ft;
+ }
+}
diff --git a/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/LevelsV4.java b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/LevelsV4.java
new file mode 100644
index 0000000..741e480
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/LevelsV4.java
@@ -0,0 +1,167 @@
+/*
+ * 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.imagejb;
+
+import java.lang.Math;
+
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.RenderScript;
+import android.renderscript.Matrix3f;
+import android.renderscript.Script;
+import android.renderscript.ScriptC;
+import android.renderscript.Type;
+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);
+ }
+ }
+ }
+
+}
+
diff --git a/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/Mandelbrot.java b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/Mandelbrot.java
new file mode 100644
index 0000000..ca34848
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/Mandelbrot.java
@@ -0,0 +1,98 @@
+/*
+ * 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.imagejb;
+
+import java.lang.Math;
+
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.RenderScript;
+import android.renderscript.Script;
+import android.renderscript.ScriptC;
+import android.renderscript.Type;
+import android.util.Log;
+import android.widget.SeekBar;
+import android.widget.TextView;
+
+public class Mandelbrot extends TestBase {
+ private ScriptC_mandelbrot mScript;
+
+ public boolean onBar1Setup(SeekBar b, TextView t) {
+ t.setText("Iterations");
+ b.setProgress(0);
+ return true;
+ }
+
+ public void onBar1Changed(int progress) {
+ int iters = progress * 3 + 50;
+ mScript.set_gMaxIteration(iters);
+ }
+
+ public boolean onBar2Setup(SeekBar b, TextView t) {
+ t.setText("Lower Bound: X");
+ b.setProgress(0);
+ return true;
+ }
+
+ public void onBar2Changed(int progress) {
+ float scaleFactor = mScript.get_scaleFactor();
+ // allow viewport to be moved by 2x scale factor
+ float lowerBoundX = -2.f + ((progress / scaleFactor) / 50.f);
+ mScript.set_lowerBoundX(lowerBoundX);
+ }
+
+ public boolean onBar3Setup(SeekBar b, TextView t) {
+ t.setText("Lower Bound: Y");
+ b.setProgress(0);
+ return true;
+ }
+
+ public void onBar3Changed(int progress) {
+ float scaleFactor = mScript.get_scaleFactor();
+ // allow viewport to be moved by 2x scale factor
+ float lowerBoundY = -2.f + ((progress / scaleFactor) / 50.f);
+ mScript.set_lowerBoundY(lowerBoundY);
+ }
+
+ public boolean onBar4Setup(SeekBar b, TextView t) {
+ t.setText("Scale Factor");
+ b.setProgress(0);
+ return true;
+ }
+
+ public void onBar4Changed(int progress) {
+ float scaleFactor = 4.f - (3.96f * (progress / 100.f));
+ mScript.set_scaleFactor(scaleFactor);
+ }
+
+ public void createTest(android.content.res.Resources res) {
+ int width = mOutPixelsAllocation.getType().getX();
+ int height = mOutPixelsAllocation.getType().getY();
+
+ mScript = new ScriptC_mandelbrot(mRS, res, R.raw.mandelbrot);
+ mScript.set_gDimX(width);
+ mScript.set_gDimY(height);
+ mScript.set_gMaxIteration(50);
+ }
+
+ public void runTest() {
+ mScript.forEach_root(mOutPixelsAllocation);
+ mRS.finish();
+ }
+
+}
+
diff --git a/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/TestBase.java b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/TestBase.java
new file mode 100644
index 0000000..ed22578
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/TestBase.java
@@ -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.imagejb;
+
+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.renderscript.ScriptC;
+import android.renderscript.RenderScript;
+import android.renderscript.Type;
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.Script;
+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;
+import android.widget.Spinner;
+
+public class TestBase {
+ protected final String TAG = "Img";
+
+ protected RenderScript mRS;
+ protected Allocation mInPixelsAllocation;
+ protected Allocation mInPixelsAllocation2;
+ protected Allocation mOutPixelsAllocation;
+ protected ScriptC_msg mMessageScript;
+
+ protected ImageProcessingActivityJB act;
+
+ private class MessageProcessor extends RenderScript.RSMessageHandler {
+ ImageProcessingActivityJB mAct;
+
+ MessageProcessor(ImageProcessingActivityJB act) {
+ mAct = act;
+ }
+
+ public void run() {
+ mAct.updateDisplay();
+ }
+ }
+
+ // 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 boolean onSpinner1Setup(Spinner s) {
+ s.setVisibility(View.INVISIBLE);
+ return false;
+ }
+
+ public final void createBaseTest(ImageProcessingActivityJB ipact, Bitmap b, Bitmap b2) {
+ act = ipact;
+ mRS = RenderScript.create(act);
+ mRS.setMessageHandler(new MessageProcessor(act));
+ mMessageScript = new ScriptC_msg(mRS);
+ mInPixelsAllocation = Allocation.createFromBitmap(mRS, b,
+ Allocation.MipmapControl.MIPMAP_NONE,
+ Allocation.USAGE_SCRIPT);
+ mInPixelsAllocation2 = Allocation.createFromBitmap(mRS, b2,
+ 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() {
+ }
+
+ final public void runTestSendMessage() {
+ android.util.Log.v("Img", "run");
+ runTest();
+ mMessageScript.invoke_sendMsg();
+ }
+
+ public void finish() {
+ mRS.finish();
+ }
+
+ public void destroy() {
+ mRS.destroy();
+ mRS = null;
+ }
+
+ 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() {
+ }
+}
diff --git a/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/Vignette.java b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/Vignette.java
new file mode 100644
index 0000000..487cd63
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/Vignette.java
@@ -0,0 +1,125 @@
+/*
+ * 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.imagejb;
+
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.Sampler;
+import android.renderscript.Type;
+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);
+ }
+
+}
+
diff --git a/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/colormatrix.rs b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/colormatrix.rs
new file mode 100644
index 0000000..772cb83
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/colormatrix.rs
@@ -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.imagejb)
+#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);
+}
+
diff --git a/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/convolve3x3.rs b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/convolve3x3.rs
new file mode 100644
index 0000000..f12f6ce
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/convolve3x3.rs
@@ -0,0 +1,71 @@
+/*
+ * 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.imagejb)
+#pragma rs_fp_relaxed
+
+int32_t gWidth;
+int32_t gHeight;
+rs_allocation gIn;
+
+float gCoeffs[9];
+
+static inline uchar4 GetElementAt_uchar4(rs_allocation a, uint32_t x, uint32_t y) {
+ return ((uchar4 *)rsGetElementAt(a, x, y))[0];
+}
+
+void root(uchar4 *out, uint32_t x, uint32_t y) {
+ uint32_t x1 = min((int32_t)x+1, gWidth-1);
+ uint32_t x2 = max((int32_t)x-1, 0);
+ uint32_t y1 = min((int32_t)y+1, gHeight-1);
+ uint32_t y2 = max((int32_t)y-1, 0);
+
+ float4 p00 = convert_float4(GetElementAt_uchar4(gIn, x1, y1));
+ float4 p01 = convert_float4(GetElementAt_uchar4(gIn, x, y1));
+ float4 p02 = convert_float4(GetElementAt_uchar4(gIn, x2, y1));
+ float4 p10 = convert_float4(GetElementAt_uchar4(gIn, x1, y));
+ float4 p11 = convert_float4(GetElementAt_uchar4(gIn, x, y));
+ float4 p12 = convert_float4(GetElementAt_uchar4(gIn, x2, y));
+ float4 p20 = convert_float4(GetElementAt_uchar4(gIn, x1, y2));
+ float4 p21 = convert_float4(GetElementAt_uchar4(gIn, x, y2));
+ float4 p22 = convert_float4(GetElementAt_uchar4(gIn, x2, y2));
+ 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);
+}
+
+
diff --git a/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/convolve5x5.rs b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/convolve5x5.rs
new file mode 100644
index 0000000..6e23d79
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/convolve5x5.rs
@@ -0,0 +1,78 @@
+/*
+ * 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.imagejb)
+#pragma rs_fp_relaxed
+
+int32_t gWidth;
+int32_t gHeight;
+rs_allocation gIn;
+
+float gCoeffs[25];
+
+static inline uchar4 GetElementAt_uchar4(rs_allocation a, uint32_t x, uint32_t y) {
+ return ((uchar4 *)rsGetElementAt(a, x, y))[0];
+}
+
+void root(uchar4 *out, uint32_t x, uint32_t y) {
+ uint32_t x0 = max((int32_t)x-2, 0);
+ uint32_t x1 = max((int32_t)x-1, 0);
+ uint32_t x2 = x;
+ uint32_t x3 = min((int32_t)x+1, gWidth-1);
+ uint32_t x4 = min((int32_t)x+2, gWidth-1);
+
+ uint32_t y0 = max((int32_t)y-2, 0);
+ uint32_t y1 = max((int32_t)y-1, 0);
+ uint32_t y2 = y;
+ uint32_t y3 = min((int32_t)y+1, gHeight-1);
+ uint32_t y4 = min((int32_t)y+2, gHeight-1);
+
+ float4 p0 = convert_float4(GetElementAt_uchar4(gIn, x0, y0)) * gCoeffs[0]
+ + convert_float4(GetElementAt_uchar4(gIn, x1, y0)) * gCoeffs[1]
+ + convert_float4(GetElementAt_uchar4(gIn, x2, y0)) * gCoeffs[2]
+ + convert_float4(GetElementAt_uchar4(gIn, x3, y0)) * gCoeffs[3]
+ + convert_float4(GetElementAt_uchar4(gIn, x4, y0)) * gCoeffs[4];
+
+ float4 p1 = convert_float4(GetElementAt_uchar4(gIn, x0, y1)) * gCoeffs[5]
+ + convert_float4(GetElementAt_uchar4(gIn, x1, y1)) * gCoeffs[6]
+ + convert_float4(GetElementAt_uchar4(gIn, x2, y1)) * gCoeffs[7]
+ + convert_float4(GetElementAt_uchar4(gIn, x3, y1)) * gCoeffs[8]
+ + convert_float4(GetElementAt_uchar4(gIn, x4, y1)) * gCoeffs[9];
+
+ float4 p2 = convert_float4(GetElementAt_uchar4(gIn, x0, y2)) * gCoeffs[10]
+ + convert_float4(GetElementAt_uchar4(gIn, x1, y2)) * gCoeffs[11]
+ + convert_float4(GetElementAt_uchar4(gIn, x2, y2)) * gCoeffs[12]
+ + convert_float4(GetElementAt_uchar4(gIn, x3, y2)) * gCoeffs[13]
+ + convert_float4(GetElementAt_uchar4(gIn, x4, y2)) * gCoeffs[14];
+
+ float4 p3 = convert_float4(GetElementAt_uchar4(gIn, x0, y3)) * gCoeffs[15]
+ + convert_float4(GetElementAt_uchar4(gIn, x1, y3)) * gCoeffs[16]
+ + convert_float4(GetElementAt_uchar4(gIn, x2, y3)) * gCoeffs[17]
+ + convert_float4(GetElementAt_uchar4(gIn, x3, y3)) * gCoeffs[18]
+ + convert_float4(GetElementAt_uchar4(gIn, x4, y3)) * gCoeffs[19];
+
+ float4 p4 = convert_float4(GetElementAt_uchar4(gIn, x0, y4)) * gCoeffs[20]
+ + convert_float4(GetElementAt_uchar4(gIn, x1, y4)) * gCoeffs[21]
+ + convert_float4(GetElementAt_uchar4(gIn, x2, y4)) * gCoeffs[22]
+ + convert_float4(GetElementAt_uchar4(gIn, x3, y4)) * gCoeffs[23]
+ + convert_float4(GetElementAt_uchar4(gIn, x4, y4)) * gCoeffs[24];
+
+ p0 = clamp(p0 + p1 + p2 + p3 + p4, 0.f, 255.f);
+ *out = convert_uchar4(p0);
+}
+
+
diff --git a/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/copy.rs b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/copy.rs
new file mode 100644
index 0000000..17f7cff
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/copy.rs
@@ -0,0 +1,24 @@
+/*
+ * 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.imagejb)
+
+void root(const uchar4 *in, uchar4 *out) {
+ *out = *in;
+}
+
+
diff --git a/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/grain.rs b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/grain.rs
new file mode 100644
index 0000000..885ef49
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/grain.rs
@@ -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.
+ */
+
+#pragma version(1)
+#pragma rs java_package_name(com.android.rs.imagejb)
+#pragma rs_fp_relaxed
+
+void genRand(uchar *out) {
+ *out = (uchar)rsRand(0xff);
+}
+
+static inline uchar GetElementAt_uchar(rs_allocation a, uint32_t x, uint32_t y) {
+ return ((uchar *)rsGetElementAt(a, x, y))[0];
+}
+
+static inline float4 GetElementAt_float4(rs_allocation a, uint32_t x, uint32_t y) {
+ return ((float4 *)rsGetElementAt(a, x, y))[0];
+}
+
+/*
+ * 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 gWMask;
+int32_t gHMask;
+
+rs_allocation gBlendSource;
+void blend9(uchar *out, uint32_t x, uint32_t y) {
+ uint32_t x1 = (x-1) & gWMask;
+ uint32_t x2 = (x+1) & gWMask;
+ uint32_t y1 = (y-1) & gHMask;
+ uint32_t y2 = (y+1) & gHMask;
+
+ uint p00 = 56 * GetElementAt_uchar(gBlendSource, x1, y1);
+ uint p01 = 114 * GetElementAt_uchar(gBlendSource, x, y1);
+ uint p02 = 56 * GetElementAt_uchar(gBlendSource, x2, y1);
+ uint p10 = 114 * GetElementAt_uchar(gBlendSource, x1, y);
+ uint p11 = 230 * GetElementAt_uchar(gBlendSource, x, y);
+ uint p12 = 114 * GetElementAt_uchar(gBlendSource, x2, y);
+ uint p20 = 56 * GetElementAt_uchar(gBlendSource, x1, y2);
+ uint p21 = 114 * GetElementAt_uchar(gBlendSource, x, y2);
+ uint p22 = 56 * GetElementAt_uchar(gBlendSource, x2, y2);
+
+ p00 += p01;
+ p02 += p10;
+ p11 += p12;
+ p20 += p21;
+
+ p22 += p00;
+ p02 += p11;
+
+ p20 += p22;
+ p20 += p02;
+
+ p20 = min(p20 >> 10, (uint)255);
+ *out = (uchar)p20;
+}
+
+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) GetElementAt_uchar(gNoise, x & gWMask, y & gHMask);
+
+ 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;
+}
diff --git a/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/greyscale.rs b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/greyscale.rs
new file mode 100644
index 0000000..b3a7ef0
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/greyscale.rs
@@ -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.imagejb)
+#pragma rs_fp_relaxed
+
+const static float3 gMonoMult = {0.299f, 0.587f, 0.114f};
+
+void root(const uchar4 *v_in, uchar4 *out) {
+ float4 f4 = rsUnpackColor8888(*v_in);
+
+ float3 mono = dot(f4.rgb, gMonoMult);
+ *out = rsPackColorTo8888(mono);
+}
+
+
diff --git a/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/levels.rsh b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/levels.rsh
new file mode 100644
index 0000000..a3a2775
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/levels.rsh
@@ -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).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);
+ 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 = convert_uchar4(pixel);
+}
+
diff --git a/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/levels_full.rs b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/levels_full.rs
new file mode 100644
index 0000000..dead169
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/levels_full.rs
@@ -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.imagejb)
+
+#include "levels.rsh"
+
diff --git a/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/levels_relaxed.rs b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/levels_relaxed.rs
new file mode 100644
index 0000000..b2564ef
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/levels_relaxed.rs
@@ -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.imagejb)
+#pragma rs_fp_relaxed
+
+#include "levels.rsh"
+
diff --git a/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/mandelbrot.rs b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/mandelbrot.rs
new file mode 100644
index 0000000..7cd8488
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/mandelbrot.rs
@@ -0,0 +1,56 @@
+// Copyright (C) 2011 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.imagejb)
+
+uint32_t gMaxIteration = 500;
+uint32_t gDimX = 1024;
+uint32_t gDimY = 1024;
+
+float lowerBoundX = -2.f;
+float lowerBoundY = -2.f;
+float scaleFactor = 4.f;
+
+void root(uchar4 *out, uint32_t x, uint32_t y) {
+ float2 p;
+ p.x = lowerBoundX + ((float)x / gDimX) * scaleFactor;
+ p.y = lowerBoundY + ((float)y / gDimY) * scaleFactor;
+
+ float2 t = 0;
+ float2 t2 = t * t;
+ int iter = 0;
+ while((t2.x + t2.y < 4.f) && (iter < gMaxIteration)) {
+ float xtemp = t2.x - t2.y + p.x;
+ t.y = 2 * t.x * t.y + p.y;
+ t.x = xtemp;
+ iter++;
+ t2 = t * t;
+ }
+
+ if(iter >= gMaxIteration) {
+ // write a non-transparent black pixel
+ *out = (uchar4){0, 0, 0, 0xff};
+ } else {
+ float mi3 = gMaxIteration / 3.f;
+ if (iter <= (gMaxIteration / 3))
+ *out = (uchar4){0xff * (iter / mi3), 0, 0, 0xff};
+ else if (iter <= (((gMaxIteration / 3) * 2)))
+ *out = (uchar4){0xff - (0xff * ((iter - mi3) / mi3)),
+ (0xff * ((iter - mi3) / mi3)), 0, 0xff};
+ else
+ *out = (uchar4){0, 0xff - (0xff * ((iter - (mi3 * 2)) / mi3)),
+ (0xff * ((iter - (mi3 * 2)) / mi3)), 0xff};
+ }
+}
diff --git a/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/msg.rs b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/msg.rs
new file mode 100644
index 0000000..645eb98
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/msg.rs
@@ -0,0 +1,23 @@
+/*
+ * 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.imagejb)
+
+void sendMsg() {
+ rsSendToClientBlocking(0);
+}
+
diff --git a/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/threshold.rs b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/threshold.rs
new file mode 100644
index 0000000..d18117a
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/threshold.rs
@@ -0,0 +1,106 @@
+#pragma version(1)
+#pragma rs java_package_name(com.android.rs.imagejb)
+#pragma rs_fp_relaxed
+
+
+int height;
+int width;
+static int radius;
+
+rs_allocation InPixel;
+rs_allocation ScratchPixel1;
+rs_allocation ScratchPixel2;
+
+const int MAX_RADIUS = 25;
+
+// Store our coefficients here
+static float gaussian[MAX_RADIUS * 2 + 1];
+
+void setRadius(int rad) {
+ radius = rad;
+ // 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;
+ for (int 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 (int r = -radius; r <= radius; r ++) {
+ floatR = (float)r;
+ gaussian[r + radius] *= normalizeFactor;
+ }
+}
+
+void copyIn(const uchar4 *in, float4 *out) {
+ *out = convert_float4(*in);
+}
+
+static inline float4 GetElementAt_float4(rs_allocation a, uint32_t x, uint32_t y) {
+ return ((float4 *)rsGetElementAt(a, x, y))[0];
+}
+
+void vert(uchar4 *out, uint32_t x, uint32_t y) {
+ float3 blurredPixel = 0;
+ int gi = 0;
+ if ((y > radius) && (y < (height - radius))) {
+ for (int r = -radius; r <= radius; r ++) {
+ float4 i = GetElementAt_float4(ScratchPixel2, x, y + r);
+ blurredPixel += i.xyz * gaussian[gi++];
+ }
+ } else {
+ for (int r = -radius; r <= radius; r ++) {
+ int validH = rsClamp((int)y + r, (int)0, (int)(height - 1));
+ float4 i = GetElementAt_float4(ScratchPixel2, x, validH);
+ blurredPixel += i.xyz * gaussian[gi++];
+ }
+ }
+
+ out->xyz = convert_uchar3(clamp(blurredPixel, 0.f, 255.f));
+ out->w = 0xff;
+}
+
+void horz(float4 *out, uint32_t x, uint32_t y) {
+ float4 blurredPixel = 0;
+ int gi = 0;
+ if ((x > radius) && (x < (width - radius))) {
+ for (int r = -radius; r <= radius; r ++) {
+ float4 i = GetElementAt_float4(ScratchPixel1, x + r, y);
+ blurredPixel += i * gaussian[gi++];
+ }
+ } else {
+ for (int r = -radius; r <= radius; r ++) {
+ // Stepping left and right away from the pixel
+ int validX = rsClamp((int)x + r, (int)0, (int)(width - 1));
+ float4 i = GetElementAt_float4(ScratchPixel1, validX, y);
+ blurredPixel += i * gaussian[gi++];
+ }
+ }
+
+ *out = blurredPixel;
+}
+
diff --git a/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/vignette.rsh b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/vignette.rsh
new file mode 100644
index 0000000..3fef0c3
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/vignette.rsh
@@ -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.5f * 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.7f*sqrt(desired_scale) - 1.3f;
+ 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.0f + sloped_neg_range * exp(sloped_dist_ratio) );
+ float4 fout;
+ fout.rgb = fin.rgb * lumen;
+ fout.w = fin.w;
+ *out = convert_uchar4(fout);
+}
+
diff --git a/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/vignette_full.rs b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/vignette_full.rs
new file mode 100644
index 0000000..c5b08a9
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/vignette_full.rs
@@ -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.imagejb)
+
+#include "vignette.rsh"
+
diff --git a/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/vignette_relaxed.rs b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/vignette_relaxed.rs
new file mode 100644
index 0000000..339b747
--- /dev/null
+++ b/tests/RenderScriptTests/ImageProcessing_jb/src/com/android/rs/image/vignette_relaxed.rs
@@ -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.imagejb)
+#pragma rs_fp_relaxed
+
+#include "vignette.rsh"
+
diff --git a/tests/RenderScriptTests/LatencyBenchmark/Android.mk b/tests/RenderScriptTests/LatencyBenchmark/Android.mk
new file mode 100644
index 0000000..ef2164d
--- /dev/null
+++ b/tests/RenderScriptTests/LatencyBenchmark/Android.mk
@@ -0,0 +1,27 @@
+#
+# 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.
+#
+
+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_PACKAGE_NAME := RsLatencyBenchmark
+
+include $(BUILD_PACKAGE)
diff --git a/tests/RenderScriptTests/LatencyBenchmark/AndroidManifest.xml b/tests/RenderScriptTests/LatencyBenchmark/AndroidManifest.xml
new file mode 100644
index 0000000..923bb88
--- /dev/null
+++ b/tests/RenderScriptTests/LatencyBenchmark/AndroidManifest.xml
@@ -0,0 +1,30 @@
+<?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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.rs.latencybench">
+
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+ <uses-sdk android:minSdkVersion="17" />
+ <application android:label="_RS_Latency_Bench">
+ <activity android:name="LatencyBench">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+</manifest>
diff --git a/tests/RenderScriptTests/LatencyBenchmark/res/layout/main.xml b/tests/RenderScriptTests/LatencyBenchmark/res/layout/main.xml
new file mode 100644
index 0000000..9e9dab8
--- /dev/null
+++ b/tests/RenderScriptTests/LatencyBenchmark/res/layout/main.xml
@@ -0,0 +1,31 @@
+<?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.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <ImageView
+ android:id="@+id/displayin"
+ android:layout_width="320dip"
+ android:layout_height="266dip" />
+
+ <ImageView
+ android:id="@+id/displayout"
+ android:layout_width="320dip"
+ android:layout_height="266dip" />
+
+</LinearLayout>
diff --git a/tests/RenderScriptTests/LatencyBenchmark/src/com/example/android/rs/computebench/Benchmark.java b/tests/RenderScriptTests/LatencyBenchmark/src/com/example/android/rs/computebench/Benchmark.java
new file mode 100644
index 0000000..ee14fb9
--- /dev/null
+++ b/tests/RenderScriptTests/LatencyBenchmark/src/com/example/android/rs/computebench/Benchmark.java
@@ -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.
+ */
+
+package com.example.android.rs.latencybench;
+import android.content.Context;
+import android.content.res.Resources;
+import android.renderscript.*;
+
+public class Benchmark implements Runnable {
+ private final RenderScript mRS;
+ private ScriptC_compute_benchmark mScript;
+ private Allocation ain;
+ private Allocation aout;
+
+ public Benchmark(RenderScript rs, Resources res) {
+ mRS = rs;
+ mScript = new ScriptC_compute_benchmark(mRS, res, R.raw.compute_benchmark);
+ ain = Allocation.createSized(rs, Element.U32(mRS), 10000);
+ aout = Allocation.createSized(rs, Element.U32(mRS), 10000);
+ }
+
+ public void run() {
+ int[] temp;
+ temp = new int[1];
+
+ long t = java.lang.System.currentTimeMillis();
+
+ for (int i = 0; i < 1000000; i++)
+ mScript.forEach_root(ain, aout);
+ aout.copy1DRangeFrom(0, 1, temp);
+
+ t = java.lang.System.currentTimeMillis() - t;
+ android.util.Log.v("LatencyBench", "Iterated Java forEach took " + t + " ms");
+
+ mScript.set_empty_kern(mScript);
+ mScript.set_in(ain);
+ mScript.set_out(aout);
+
+ t = java.lang.System.currentTimeMillis();
+ mScript.invoke_emptyKernelLauncher();
+ aout.copy1DRangeFrom(0, 1, temp);
+
+ t = java.lang.System.currentTimeMillis() - t;
+ android.util.Log.v("LatencyBench", "Invoked forEach took " + t + " ms");
+
+
+
+ }
+
+}
diff --git a/tests/RenderScriptTests/LatencyBenchmark/src/com/example/android/rs/computebench/LatencyBench.java b/tests/RenderScriptTests/LatencyBenchmark/src/com/example/android/rs/computebench/LatencyBench.java
new file mode 100644
index 0000000..fdce9a7
--- /dev/null
+++ b/tests/RenderScriptTests/LatencyBenchmark/src/com/example/android/rs/computebench/LatencyBench.java
@@ -0,0 +1,37 @@
+/*
+ * 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.example.android.rs.latencybench;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.renderscript.RenderScript;
+
+public class LatencyBench extends Activity {
+ private RenderScript mRS;
+ private Benchmark mBenchmark;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.main);
+
+ mRS = RenderScript.create(this);
+
+ mBenchmark = new Benchmark(mRS, getResources());
+ mBenchmark.run();
+ }
+}
diff --git a/tests/RenderScriptTests/LatencyBenchmark/src/com/example/android/rs/computebench/compute_benchmark.rs b/tests/RenderScriptTests/LatencyBenchmark/src/com/example/android/rs/computebench/compute_benchmark.rs
new file mode 100644
index 0000000..c6d1ea9
--- /dev/null
+++ b/tests/RenderScriptTests/LatencyBenchmark/src/com/example/android/rs/computebench/compute_benchmark.rs
@@ -0,0 +1,29 @@
+// 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.example.android.rs.latencybench)
+
+rs_script empty_kern;
+rs_allocation in, out;
+int iters = 1000000;
+
+void root(const uint32_t *ain, uint32_t *aout) {
+
+}
+
+void emptyKernelLauncher() {
+ for (int i = 0; i < iters; i++)
+ rsForEach(empty_kern, in, out);
+}