Visual Servoing Platform  version 3.4.0
VpImageUChar.cpp
1 #include <cstring>
2 #include <sstream>
3 #include <visp3/core/vpImage.h>
4 typedef unsigned char u_char;
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: VpImageUChar()
16 JNIEXPORT jlong JNICALL Java_org_visp_core_VpImageUChar_n_1VpImageUChar__
17 (JNIEnv *env, jclass, jstring type){
18  (void)env;
19  (void)type;
20  return (jlong) new vpImage<u_char>();
21 }
22 
23 // Java Method: VpImageUChar(int r, int c)
24 JNIEXPORT jlong JNICALL Java_org_visp_core_VpImageUChar_n_1VpImageUChar__II
25 (JNIEnv *env, jclass, jint r, jint c){
26  (void)env;
27  return (jlong) new vpImage<u_char>(r,c);
28 }
29 
30 // Java Method: VpImageUChar(int r, int c, byte val)
31 JNIEXPORT jlong JNICALL Java_org_visp_core_VpImageUChar_n_1VpImageUChar__IIB
32 (JNIEnv *env, jclass, jint r, jint c, jbyte value){
33  (void)env;
34  return (jlong) new vpImage<u_char>(r,c, (u_char) value);
35 }
36 
37 // Java Method: VpImageUChar(byte[] array, int height, int width, boolean copyData)
38 JNIEXPORT jlong JNICALL Java_org_visp_core_VpImageUChar_n_1VpImageUChar___3BIIZ
39 (JNIEnv *env, jclass, jbyteArray arr, jint h, jint w, jboolean copyData){
40  jbyte *array = env->GetByteArrayElements(arr, NULL);
41 
42  return (jlong) new vpImage<u_char>((u_char *const) array, (const unsigned int) h, (const unsigned int) w, copyData);
43 
44  // be memory friendly
45  env->ReleaseByteArrayElements(arr, array, 0);
46 }
47 
48 // Java Method: getCols()
49 JNIEXPORT jint JNICALL Java_org_visp_core_VpImageUChar_n_1cols
50 (JNIEnv *env, jclass, jlong address){
51  (void)env;
52  vpImage<u_char>* me = (vpImage<u_char>*) address; //TODO: check for NULL
53  return me->getCols();
54 }
55 
56 // Java Method: getRows()
57 JNIEXPORT jint JNICALL Java_org_visp_core_VpImageUChar_n_1rows
58 (JNIEnv *env, jclass, jlong address){
59  (void)env;
60  vpImage<u_char>* me = (vpImage<u_char>*) address; //TODO: check for NULL
61  return me->getRows();
62 }
63 
64 // Java Method: getPixel(int i, int j)
65 JNIEXPORT jint JNICALL Java_org_visp_core_VpImageUChar_n_1getPixel
66 (JNIEnv *env, jclass, jlong address, jint i, jint j){
67  (void)env;
68  vpImage<u_char>* me = (vpImage<u_char>*) address; //TODO: check for NULL
69  return (*me)(i,j);
70 }
71 
72 // Java Method: getPixels()
73 JNIEXPORT jbyteArray JNICALL Java_org_visp_core_VpImageUChar_n_1getPixels
74 (JNIEnv *env, jclass, jlong address){
75  vpImage<u_char>* me = (vpImage<u_char>*) address; //TODO: check for NULL
76  jbyteArray ret = env->NewByteArray(me->getNumberOfPixel());
77  env->SetByteArrayRegion (ret, 0, me->getNumberOfPixel(), (jbyte*) me->bitmap);
78  return ret;
79 }
80 
81 // Java Method: dump()
82 JNIEXPORT jstring JNICALL Java_org_visp_core_VpImageUChar_n_1dump
83 (JNIEnv *env, jclass, jlong address){
84  vpImage<u_char>* me = (vpImage<u_char>*) address; //TODO: check for NULL
85  std::stringstream ss;
86  ss << *me;
87  return env->NewStringUTF(ss.str().c_str());
88 }
89 
90 } // extern "C"
unsigned int getCols() const
Definition: vpImage.h:179
Type * bitmap
points toward the bitmap
Definition: vpImage.h:143
unsigned int getRows() const
Definition: vpImage.h:218
unsigned int getNumberOfPixel() const
Definition: vpImage.h:209
Definition of the vpImage class member functions.
Definition: vpImage.h:126