Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
VpImageUChar.cpp
1#include <cstring>
2#include <sstream>
3#include <visp3/core/vpConfig.h>
4#include <visp3/core/vpImage.h>
5typedef unsigned char u_char;
6
7extern "C" {
8
9#if !defined(__ppc__)
10// to suppress warning from jni.h on OS X
11#define TARGET_RT_MAC_CFM 0
12#endif
13#include <jni.h>
14
15#ifdef ENABLE_VISP_NAMESPACE
16 using namespace VISP_NAMESPACE_NAME;
17#endif
18
19#if defined(__clang__)
20// Mute warning : identifier 'Java_org_visp_core_VpImageUChar_n_1VpImageUChar__II' is reserved because it contains '__' [-Wreserved-identifier]
21# pragma clang diagnostic push
22# pragma clang diagnostic ignored "-Wreserved-identifier"
23#endif
24
25 // Java Method: VpImageUChar()
26 JNIEXPORT jlong JNICALL Java_org_visp_core_VpImageUChar_n_1VpImageUChar__(JNIEnv *env, jclass, jstring type)
27 {
28 (void)env;
29 (void)type;
30 return (jlong) new vpImage<u_char>();
31 }
32
33 // Java Method: VpImageUChar(int r, int c)
34 JNIEXPORT jlong JNICALL Java_org_visp_core_VpImageUChar_n_1VpImageUChar__II(JNIEnv *env, jclass, jint r, jint c)
35 {
36 (void)env;
37 return (jlong) new vpImage<u_char>(r, c);
38 }
39
40 // Java Method: VpImageUChar(int r, int c, byte val)
41 JNIEXPORT jlong JNICALL Java_org_visp_core_VpImageUChar_n_1VpImageUChar__IIB(JNIEnv *env, jclass, jint r, jint c,
42 jbyte value)
43 {
44 (void)env;
45 return (jlong) new vpImage<u_char>(r, c, (u_char)value);
46 }
47
48 // Java Method: VpImageUChar(byte[] array, int height, int width, boolean copyData)
49 JNIEXPORT jlong JNICALL Java_org_visp_core_VpImageUChar_n_1VpImageUChar___3BIIZ(JNIEnv *env, jclass, jbyteArray arr,
50 jint h, jint w, jboolean copyData)
51 {
52 jbyte *array = env->GetByteArrayElements(arr, nullptr);
53
54 return (jlong) new vpImage<u_char>((u_char *)array, static_cast<unsigned int>(h), static_cast<unsigned int>(w), copyData);
55
56 // be memory friendly
57 env->ReleaseByteArrayElements(arr, array, 0);
58 }
59
60 // Java Method: getCols()
61 JNIEXPORT jint JNICALL Java_org_visp_core_VpImageUChar_n_1cols(JNIEnv *env, jclass, jlong address)
62 {
63 (void)env;
64 vpImage<u_char> *me = (vpImage<u_char> *)address; // TODO: check for nullptr
65 return me->getCols();
66 }
67
68 // Java Method: getRows()
69 JNIEXPORT jint JNICALL Java_org_visp_core_VpImageUChar_n_1rows(JNIEnv *env, jclass, jlong address)
70 {
71 (void)env;
72 vpImage<u_char> *me = (vpImage<u_char> *)address; // TODO: check for nullptr
73 return me->getRows();
74 }
75
76 // Java Method: getPixel(int i, int j)
77 JNIEXPORT jint JNICALL Java_org_visp_core_VpImageUChar_n_1getPixel(JNIEnv *env, jclass, jlong address, jint i, jint j)
78 {
79 (void)env;
80 vpImage<u_char> *me = (vpImage<u_char> *)address; // TODO: check for nullptr
81 return (*me)(i, j);
82 }
83
84 // Java Method: getPixels()
85 JNIEXPORT jbyteArray JNICALL Java_org_visp_core_VpImageUChar_n_1getPixels(JNIEnv *env, jclass, jlong address)
86 {
87 vpImage<u_char> *me = (vpImage<u_char> *)address; // TODO: check for nullptr
88 jbyteArray ret = env->NewByteArray(me->getNumberOfPixel());
89 env->SetByteArrayRegion(ret, 0, me->getNumberOfPixel(), (jbyte *)me->bitmap);
90 return ret;
91 }
92
93 // Java Method: dump()
94 JNIEXPORT jstring JNICALL Java_org_visp_core_VpImageUChar_n_1dump(JNIEnv *env, jclass, jlong address)
95 {
96 vpImage<u_char> *me = (vpImage<u_char> *)address; // TODO: check for nullptr
97 std::stringstream ss;
98 ss << *me;
99 return env->NewStringUTF(ss.str().c_str());
100 }
101
102#if defined(__clang__)
103# pragma clang diagnostic pop
104#endif
105
106} // extern "C"
Definition of the vpImage class member functions.
Definition vpImage.h:131
unsigned int getNumberOfPixel() const
Definition vpImage.h:203
unsigned int getCols() const
Definition vpImage.h:171
Type * bitmap
points toward the bitmap
Definition vpImage.h:135
unsigned int getRows() const
Definition vpImage.h:212