1 #include <cstring>
2 #include <sstream>
3 #include <visp3/core/vpImage.h>
4 #include <visp3/core/vpRGBa.h>
5
6 extern "C" {
7
8 #if !defined(__ppc__)
9 // to suppress warning from jni.h on OS X
10 # define TARGET_RT_MAC_CFM 0
11 #endif
12 #include <jni.h>
13
14
15 // Java Method: VpImageRGBa()
Java_org_visp_core_VpImageRGBa_n_1VpImageRGBa__(JNIEnv * env,jclass,jstring type)16 JNIEXPORT jlong JNICALL Java_org_visp_core_VpImageRGBa_n_1VpImageRGBa__
17 (JNIEnv *env, jclass, jstring type){
18 (void)env;
19 (void)type;
20 return (jlong) new vpImage<vpRGBa>();
21 }
22
23 // Java Method: VpImageRGBa(int r, int c)
Java_org_visp_core_VpImageRGBa_n_1VpImageRGBa__II(JNIEnv * env,jclass,jint r,jint c)24 JNIEXPORT jlong JNICALL Java_org_visp_core_VpImageRGBa_n_1VpImageRGBa__II
25 (JNIEnv *env, jclass, jint r, jint c){
26 (void)env;
27 return (jlong) new vpImage<vpRGBa>(r,c);
28 }
29
30 // Java Method: VpImageRGBa(int r, int c, byte val)
Java_org_visp_core_VpImageRGBa_n_1VpImageRGBa__IICCCC(JNIEnv * env,jclass,jint r,jint c,jchar R,jchar G,jchar B,jchar A)31 JNIEXPORT jlong JNICALL Java_org_visp_core_VpImageRGBa_n_1VpImageRGBa__IICCCC
32 (JNIEnv *env, jclass, jint r, jint c, jchar R, jchar G, jchar B, jchar A){
33 (void)env;
34 vpRGBa val(R,G,B,A);
35 return (jlong) new vpImage<vpRGBa>(r,c,val);
36 }
37
38 // Java Method: VpImageRGBa(byte[] array, int height, int width, boolean copyData)
Java_org_visp_core_VpImageRGBa_n_1VpImageRGBa___3BIIZ(JNIEnv * env,jclass,jbyteArray arr,jint h,jint w,jboolean copyData)39 JNIEXPORT jlong JNICALL Java_org_visp_core_VpImageRGBa_n_1VpImageRGBa___3BIIZ
40 (JNIEnv *env, jclass, jbyteArray arr, jint h, jint w, jboolean copyData){
41 jbyte *array = env->GetByteArrayElements(arr, NULL);
42
43 return (jlong) new vpImage<vpRGBa>((vpRGBa *const) array, (const unsigned int) h, (const unsigned int) w, copyData);
44
45 // be memory friendly
46 env->ReleaseByteArrayElements(arr, array, 0);
47 }
48
49 // Java Method: getCols()
Java_org_visp_core_VpImageRGBa_n_1cols(JNIEnv * env,jclass,jlong address)50 JNIEXPORT jint JNICALL Java_org_visp_core_VpImageRGBa_n_1cols
51 (JNIEnv *env, jclass, jlong address){
52 (void)env;
53 vpImage<vpRGBa>* me = (vpImage<vpRGBa>*) address; //TODO: check for NULL
54 return me->getCols();
55 }
56
57 // Java Method: getRows()
Java_org_visp_core_VpImageRGBa_n_1rows(JNIEnv * env,jclass,jlong address)58 JNIEXPORT jint JNICALL Java_org_visp_core_VpImageRGBa_n_1rows
59 (JNIEnv *env, jclass, jlong address){
60 (void)env;
61 vpImage<vpRGBa>* me = (vpImage<vpRGBa>*) address; //TODO: check for NULL
62 return me->getRows();
63 }
64
65 // Java Method: getPixel(int i, int j)
Java_org_visp_core_VpImageRGBa_n_1getPixel(JNIEnv * env,jclass,jlong address,jint i,jint j)66 JNIEXPORT jbyteArray JNICALL Java_org_visp_core_VpImageRGBa_n_1getPixel
67 (JNIEnv *env, jclass, jlong address, jint i, jint j){
68 vpImage<vpRGBa>* me = (vpImage<vpRGBa>*) address; //TODO: check for NULL
69 vpRGBa val = (*me)(i,j);
70 jbyteArray ret = env->NewByteArray(4);
71 unsigned char temp[] = {val.R,val.G,val.B,val.A};
72 env->SetByteArrayRegion (ret, 0, 4, (jbyte*) temp);
73 return ret;
74 }
75
76 // Java Method: getPixels()
Java_org_visp_core_VpImageRGBa_n_1getPixels(JNIEnv * env,jclass,jlong address)77 JNIEXPORT jbyteArray JNICALL Java_org_visp_core_VpImageRGBa_n_1getPixels
78 (JNIEnv *env, jclass, jlong address){
79 vpImage<vpRGBa>* me = (vpImage<vpRGBa>*) address; //TODO: check for NULL
80 jbyteArray ret = env->NewByteArray(me->getNumberOfPixel()*4);
81 env->SetByteArrayRegion (ret, 0, me->getNumberOfPixel()*4, (jbyte*) me->bitmap);
82 return ret;
83 }
84
85 // Java Method: dump()
Java_org_visp_core_VpImageRGBa_n_1dump(JNIEnv * env,jclass,jlong address)86 JNIEXPORT jstring JNICALL Java_org_visp_core_VpImageRGBa_n_1dump
87 (JNIEnv *env, jclass, jlong address){
88 vpImage<vpRGBa>* me = (vpImage<vpRGBa>*) address; //TODO: check for NULL
89 std::stringstream ss;
90 ss << *me;
91 return env->NewStringUTF(ss.str().c_str());
92 }
93
94 } // extern "C"
95