aboutsummaryrefslogtreecommitdiff
path: root/tests/ndkRsHelloCompute/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ndkRsHelloCompute/src/main')
-rw-r--r--tests/ndkRsHelloCompute/src/main/AndroidManifest.xml30
-rw-r--r--tests/ndkRsHelloCompute/src/main/java/com/example/android/rs/hellocomputendk/HelloComputeNDK.java59
-rw-r--r--tests/ndkRsHelloCompute/src/main/jni/helloComputeNDK.cpp59
-rw-r--r--tests/ndkRsHelloCompute/src/main/res/drawable/data.jpgbin0 -> 76367 bytes
-rw-r--r--tests/ndkRsHelloCompute/src/main/res/layout/main.xml31
-rw-r--r--tests/ndkRsHelloCompute/src/main/rs/mono.rs28
6 files changed, 207 insertions, 0 deletions
diff --git a/tests/ndkRsHelloCompute/src/main/AndroidManifest.xml b/tests/ndkRsHelloCompute/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..4db45e7
--- /dev/null
+++ b/tests/ndkRsHelloCompute/src/main/AndroidManifest.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2013 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.hellocomputendk">
+
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+ <uses-sdk android:minSdkVersion="14" />
+ <application android:label="HelloComputeNDK">
+ <activity android:name="HelloComputeNDK">
+ <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/ndkRsHelloCompute/src/main/java/com/example/android/rs/hellocomputendk/HelloComputeNDK.java b/tests/ndkRsHelloCompute/src/main/java/com/example/android/rs/hellocomputendk/HelloComputeNDK.java
new file mode 100644
index 0000000..aec6497
--- /dev/null
+++ b/tests/ndkRsHelloCompute/src/main/java/com/example/android/rs/hellocomputendk/HelloComputeNDK.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2013 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.hellocomputendk;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.graphics.BitmapFactory;
+import android.graphics.Bitmap;
+import android.widget.ImageView;
+
+public class HelloComputeNDK extends Activity {
+ private Bitmap mBitmapIn;
+ private Bitmap mBitmapOut;
+
+ static {
+ System.loadLibrary("hellocomputendk");
+ }
+
+ native void nativeMono(int X, int Y, Bitmap in, Bitmap out);
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.main);
+
+ mBitmapIn = loadBitmap(R.drawable.data);
+ mBitmapOut = Bitmap.createBitmap(mBitmapIn.getWidth(), mBitmapIn.getHeight(),
+ mBitmapIn.getConfig());
+
+ ImageView in = (ImageView) findViewById(R.id.displayin);
+ in.setImageBitmap(mBitmapIn);
+
+ ImageView out = (ImageView) findViewById(R.id.displayout);
+ out.setImageBitmap(mBitmapOut);
+
+ nativeMono(mBitmapIn.getWidth(), mBitmapIn.getHeight(), mBitmapIn, mBitmapOut);
+
+ }
+
+ private Bitmap loadBitmap(int resource) {
+ final BitmapFactory.Options options = new BitmapFactory.Options();
+ options.inPreferredConfig = Bitmap.Config.ARGB_8888;
+ return BitmapFactory.decodeResource(getResources(), resource, options);
+ }
+}
diff --git a/tests/ndkRsHelloCompute/src/main/jni/helloComputeNDK.cpp b/tests/ndkRsHelloCompute/src/main/jni/helloComputeNDK.cpp
new file mode 100644
index 0000000..6ed5589
--- /dev/null
+++ b/tests/ndkRsHelloCompute/src/main/jni/helloComputeNDK.cpp
@@ -0,0 +1,59 @@
+#include <jni.h>
+#include <android/log.h>
+#include <android/bitmap.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+
+#include <RenderScript.h>
+
+#include "ScriptC_mono.h"
+
+#define LOG_TAG "HelloComputeNDK"
+#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
+#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
+
+using namespace android::RSC;
+
+extern "C" JNIEXPORT void JNICALL
+Java_com_example_android_rs_hellocomputendk_HelloComputeNDK_nativeMono(JNIEnv * env,
+ jclass,
+ jint X,
+ jint Y,
+ jobject jbitmapIn,
+ jobject jbitmapOut
+ )
+{
+
+ void* inputPtr = NULL;
+ void* outputPtr = NULL;
+
+ AndroidBitmap_lockPixels(env, jbitmapIn, &inputPtr);
+ AndroidBitmap_lockPixels(env, jbitmapOut, &outputPtr);
+
+ sp<RS> rs = new RS();
+ rs->init();
+
+ sp<const Element> e = Element::RGBA_8888(rs);
+
+ sp<const Type> t = Type::create(rs, e, X, Y, 0);
+
+ sp<Allocation> inputAlloc = Allocation::createTyped(rs, t, RS_ALLOCATION_MIPMAP_NONE,
+ RS_ALLOCATION_USAGE_SHARED | RS_ALLOCATION_USAGE_SCRIPT,
+ inputPtr);
+ sp<Allocation> outputAlloc = Allocation::createTyped(rs, t, RS_ALLOCATION_MIPMAP_NONE,
+ RS_ALLOCATION_USAGE_SHARED | RS_ALLOCATION_USAGE_SCRIPT,
+ outputPtr);
+
+
+ inputAlloc->copy2DRangeFrom(0, 0, X, Y, inputPtr);
+ ScriptC_mono* sc = new ScriptC_mono(rs);
+ sc->forEach_root(inputAlloc, outputAlloc);
+ outputAlloc->copy2DRangeTo(0, 0, X, Y, outputPtr);
+
+
+ AndroidBitmap_unlockPixels(env, jbitmapIn);
+ AndroidBitmap_unlockPixels(env, jbitmapOut);
+
+}
diff --git a/tests/ndkRsHelloCompute/src/main/res/drawable/data.jpg b/tests/ndkRsHelloCompute/src/main/res/drawable/data.jpg
new file mode 100644
index 0000000..81a87b1
--- /dev/null
+++ b/tests/ndkRsHelloCompute/src/main/res/drawable/data.jpg
Binary files differ
diff --git a/tests/ndkRsHelloCompute/src/main/res/layout/main.xml b/tests/ndkRsHelloCompute/src/main/res/layout/main.xml
new file mode 100644
index 0000000..7b2c76a
--- /dev/null
+++ b/tests/ndkRsHelloCompute/src/main/res/layout/main.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2013 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/ndkRsHelloCompute/src/main/rs/mono.rs b/tests/ndkRsHelloCompute/src/main/rs/mono.rs
new file mode 100644
index 0000000..efa5c72
--- /dev/null
+++ b/tests/ndkRsHelloCompute/src/main/rs/mono.rs
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2013 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.hellocomputendk)
+
+const static float3 gMonoMult = {0.299f, 0.587f, 0.114f};
+
+void root(const uchar4 *v_in, uchar4 *v_out) {
+ float4 f4 = rsUnpackColor8888(*v_in);
+
+ float3 mono = dot(f4.rgb, gMonoMult);
+ *v_out = rsPackColorTo8888(mono);
+}
+