1 #include <jni.h>
2 #include <android/log.h>
3 #include <android/bitmap.h>
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <math.h>
8
9 #include <RenderScript.h>
10
11 #include "ScriptC_mono.h"
12
13 #define LOG_TAG "HelloComputeNDK"
14 #define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
15 #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
16
17 using namespace android::RSC;
18
19 extern "C" JNIEXPORT void JNICALL
Java_com_example_android_rs_hellocomputendk_HelloComputeNDK_nativeMono(JNIEnv * env,jclass,jint X,jint Y,jobject jbitmapIn,jobject jbitmapOut)20 Java_com_example_android_rs_hellocomputendk_HelloComputeNDK_nativeMono(JNIEnv * env,
21 jclass,
22 jint X,
23 jint Y,
24 jobject jbitmapIn,
25 jobject jbitmapOut
26 )
27 {
28
29 void* inputPtr = NULL;
30 void* outputPtr = NULL;
31
32 AndroidBitmap_lockPixels(env, jbitmapIn, &inputPtr);
33 AndroidBitmap_lockPixels(env, jbitmapOut, &outputPtr);
34
35 sp<RS> rs = new RS();
36 rs->init();
37
38 sp<const Element> e = Element::RGBA_8888(rs);
39
40 sp<const Type> t = Type::create(rs, e, X, Y, 0);
41
42 sp<Allocation> inputAlloc = Allocation::createTyped(rs, t, RS_ALLOCATION_MIPMAP_NONE,
43 RS_ALLOCATION_USAGE_SHARED | RS_ALLOCATION_USAGE_SCRIPT,
44 inputPtr);
45 sp<Allocation> outputAlloc = Allocation::createTyped(rs, t, RS_ALLOCATION_MIPMAP_NONE,
46 RS_ALLOCATION_USAGE_SHARED | RS_ALLOCATION_USAGE_SCRIPT,
47 outputPtr);
48
49
50 inputAlloc->copy2DRangeFrom(0, 0, X, Y, inputPtr);
51 ScriptC_mono* sc = new ScriptC_mono(rs);
52 sc->forEach_root(inputAlloc, outputAlloc);
53 outputAlloc->copy2DRangeTo(0, 0, X, Y, outputPtr);
54
55
56 AndroidBitmap_unlockPixels(env, jbitmapIn);
57 AndroidBitmap_unlockPixels(env, jbitmapOut);
58
59 }
60