Visual Servoing Platform version 3.5.0
VpImageRGBa.cpp
1#include <cstring>
2#include <sstream>
3#include <visp3/core/vpImage.h>
4#include <visp3/core/vpRGBa.h>
5
6extern "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()
16JNIEXPORT 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)
24JNIEXPORT 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)
31JNIEXPORT 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)
39JNIEXPORT 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()
50JNIEXPORT 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()
58JNIEXPORT 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)
66JNIEXPORT 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()
77JNIEXPORT 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()
86JNIEXPORT 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"
unsigned int getNumberOfPixel() const
Definition: vpImage.h:209
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
Definition: vpRGBa.h:67
unsigned char B
Blue component.
Definition: vpRGBa.h:150
unsigned char R
Red component.
Definition: vpRGBa.h:148
unsigned char G
Green component.
Definition: vpRGBa.h:149
unsigned char A
Additionnal component.
Definition: vpRGBa.h:151