Skip to content

Commit

Permalink
Merge pull request #1564 from rolalaro/fix_java
Browse files Browse the repository at this point in the history
Fix java compilation
  • Loading branch information
fspindle authored Feb 5, 2025
2 parents c921a1b + 4c6465c commit 23098e8
Show file tree
Hide file tree
Showing 10 changed files with 298 additions and 267 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ if(NOT IOS)

# Alias variables to be consistent with previous detection method
set(PYTHON3_FOUND ${Python3_FOUND})
set(PYTHON_DEFAULT_AVAILABLE TRUE)
set(PYTHON3_EXECUTABLE ${Python3_EXECUTABLE})
set(PYTHON_DEFAULT_EXECUTABLE ${PYTHON3_EXECUTABLE})
set(PYTHON3INTERP_FOUND ${Python3_Interpreter_FOUND})
Expand Down
6 changes: 6 additions & 0 deletions modules/java/generator/hdr_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,9 @@ def parse(self, hname, wmode=True):
break

decl = None
if "BEGIN_VISP_NAMESPACE" in stmt:
stmt = stmt.replace("BEGIN_VISP_NAMESPACE", "")
stmt = stmt.strip()
if stack_top[self.PROCESS_FLAG]:
# even if stack_top[PUBLIC_SECTION] is False, we still try to process the statement,
# since it can start with "public:"
Expand All @@ -881,6 +884,9 @@ def parse(self, hname, wmode=True):
docstring = ""
if stmt_type == "namespace":
chunks = [block[1] for block in self.block_stack if block[0] == 'namespace'] + [name]
for i in range(len(chunks)):
if chunks[i] == "VISP_NAMESPACE_NAME":
chunks[i] = "visp"
self.namespaces.add('.'.join(chunks))
else:
stmt_type, name, parse_flag = "block", "", False
Expand Down
128 changes: 64 additions & 64 deletions modules/java/generator/src/cpp/VpContour.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,69 +14,69 @@ extern "C" {
// vpContour()
//

JNIEXPORT jlong JNICALL Java_org_visp_imgproc_VpContour_VpContour1(JNIEnv *, jclass);

JNIEXPORT jlong JNICALL Java_org_visp_imgproc_VpContour_VpContour1(JNIEnv *env, jclass)
{
(void)env;
vp::vpContour *_retval_ = new vp::vpContour();
return (jlong)_retval_;
}

//
// vpContour(vpContourType type)
//

JNIEXPORT jlong JNICALL Java_org_visp_imgproc_VpContour_VpContour2(JNIEnv *, jclass, jint);

JNIEXPORT jlong JNICALL Java_org_visp_imgproc_VpContour_VpContour2(JNIEnv *env, jclass, jint type)
{
(void)env;
if (type == 0)
return (jlong) new vp::vpContour(vp::CONTOUR_OUTER);
else
return (jlong) new vp::vpContour(vp::CONTOUR_HOLE);
}

//
// vpContour(vpContour contour)
//

JNIEXPORT jlong JNICALL Java_org_visp_imgproc_VpContour_VpContour3(JNIEnv *, jclass, jlong);

JNIEXPORT jlong JNICALL Java_org_visp_imgproc_VpContour_VpContour3(JNIEnv *env, jclass, jlong address)
{
(void)env;
vp::vpContour *other = (vp::vpContour *)address;
vp::vpContour *_retval_ = new vp::vpContour(*other);
return (jlong)_retval_;
}

//
// void setParent(vpContour *parent)
//

JNIEXPORT void JNICALL Java_org_visp_imgproc_VpContour_n_1setParent(JNIEnv *, jclass, jlong, jlong);

JNIEXPORT void JNICALL Java_org_visp_imgproc_VpContour_n_1setParent(JNIEnv *env, jclass, jlong address_self,
jlong address_parent)
{
(void)env;
vp::vpContour *self = (vp::vpContour *)address_self;
vp::vpContour *parent = (vp::vpContour *)address_parent;
self->setParent(parent);
}

//
// native support for java finalize()
// static void vpContour::delete( __int64 self )
//

JNIEXPORT void JNICALL Java_org_visp_imgproc_VpContour_delete(JNIEnv *, jclass, jlong);

JNIEXPORT void JNICALL Java_org_visp_imgproc_VpContour_delete(JNIEnv *, jclass, jlong self)
{
delete (vp::vpContour *)self;
}
JNIEXPORT jlong JNICALL Java_org_visp_imgproc_VpContour_VpContour1(JNIEnv *, jclass);

JNIEXPORT jlong JNICALL Java_org_visp_imgproc_VpContour_VpContour1(JNIEnv *env, jclass)
{
(void)env;
visp::vpContour *_retval_ = new visp::vpContour();
return (jlong)_retval_;
}

//
// vpContour(vpContourType type)
//

JNIEXPORT jlong JNICALL Java_org_visp_imgproc_VpContour_VpContour2(JNIEnv *, jclass, jint);

JNIEXPORT jlong JNICALL Java_org_visp_imgproc_VpContour_VpContour2(JNIEnv *env, jclass, jint type)
{
(void)env;
if (type == 0)
return (jlong) new visp::vpContour(visp::CONTOUR_OUTER);
else
return (jlong) new visp::vpContour(visp::CONTOUR_HOLE);
}

//
// vpContour(vpContour contour)
//

JNIEXPORT jlong JNICALL Java_org_visp_imgproc_VpContour_VpContour3(JNIEnv *, jclass, jlong);

JNIEXPORT jlong JNICALL Java_org_visp_imgproc_VpContour_VpContour3(JNIEnv *env, jclass, jlong address)
{
(void)env;
visp::vpContour *other = (visp::vpContour *)address;
visp::vpContour *_retval_ = new visp::vpContour(*other);
return (jlong)_retval_;
}

//
// void setParent(vpContour *parent)
//

JNIEXPORT void JNICALL Java_org_visp_imgproc_VpContour_n_1setParent(JNIEnv *, jclass, jlong, jlong);

JNIEXPORT void JNICALL Java_org_visp_imgproc_VpContour_n_1setParent(JNIEnv *env, jclass, jlong address_self,
jlong address_parent)
{
(void)env;
visp::vpContour *self = (visp::vpContour *)address_self;
visp::vpContour *parent = (visp::vpContour *)address_parent;
self->setParent(parent);
}

//
// native support for java finalize()
// static void vpContour::delete( __int64 self )
//

JNIEXPORT void JNICALL Java_org_visp_imgproc_VpContour_delete(JNIEnv *, jclass, jlong);

JNIEXPORT void JNICALL Java_org_visp_imgproc_VpContour_delete(JNIEnv *, jclass, jlong self)
{
delete (visp::vpContour *)self;
}

} // extern "C"
145 changes: 75 additions & 70 deletions modules/java/generator/src/cpp/VpImageRGBa.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <cstring>
#include <sstream>
#include <visp3/core/vpConfig.h>
#include <visp3/core/vpImage.h>
#include <visp3/core/vpRGBa.h>

Expand All @@ -11,86 +12,90 @@ extern "C" {
#endif
#include <jni.h>

#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif

// Java Method: VpImageRGBa()
JNIEXPORT jlong JNICALL Java_org_visp_core_VpImageRGBa_n_1VpImageRGBa__(JNIEnv *env, jclass, jstring type)
{
(void)env;
(void)type;
return (jlong) new vpImage<vpRGBa>();
}
JNIEXPORT jlong JNICALL Java_org_visp_core_VpImageRGBa_n_1VpImageRGBa__(JNIEnv *env, jclass, jstring type)
{
(void)env;
(void)type;
return (jlong) new vpImage<vpRGBa>();
}

// Java Method: VpImageRGBa(int r, int c)
JNIEXPORT jlong JNICALL Java_org_visp_core_VpImageRGBa_n_1VpImageRGBa__II(JNIEnv *env, jclass, jint r, jint c)
{
(void)env;
return (jlong) new vpImage<vpRGBa>(r, c);
}
// Java Method: VpImageRGBa(int r, int c)
JNIEXPORT jlong JNICALL Java_org_visp_core_VpImageRGBa_n_1VpImageRGBa__II(JNIEnv *env, jclass, jint r, jint c)
{
(void)env;
return (jlong) new vpImage<vpRGBa>(r, c);
}

// Java Method: VpImageRGBa(int r, int c, byte val)
JNIEXPORT jlong JNICALL Java_org_visp_core_VpImageRGBa_n_1VpImageRGBa__IICCCC(JNIEnv *env, jclass, jint r, jint c,
jchar R, jchar G, jchar B, jchar A)
{
(void)env;
vpRGBa val(R, G, B, A);
return (jlong) new vpImage<vpRGBa>(r, c, val);
}
// Java Method: VpImageRGBa(int r, int c, byte val)
JNIEXPORT jlong JNICALL Java_org_visp_core_VpImageRGBa_n_1VpImageRGBa__IICCCC(JNIEnv *env, jclass, jint r, jint c,
jchar R, jchar G, jchar B, jchar A)
{
(void)env;
vpRGBa val(R, G, B, A);
return (jlong) new vpImage<vpRGBa>(r, c, val);
}

// Java Method: VpImageRGBa(byte[] array, int height, int width, boolean copyData)
JNIEXPORT jlong JNICALL Java_org_visp_core_VpImageRGBa_n_1VpImageRGBa___3BIIZ(JNIEnv *env, jclass, jbyteArray arr,
jint h, jint w, jboolean copyData)
{
jbyte *array = env->GetByteArrayElements(arr, nullptr);
// Java Method: VpImageRGBa(byte[] array, int height, int width, boolean copyData)
JNIEXPORT jlong JNICALL Java_org_visp_core_VpImageRGBa_n_1VpImageRGBa___3BIIZ(JNIEnv *env, jclass, jbyteArray arr,
jint h, jint w, jboolean copyData)
{
jbyte *array = env->GetByteArrayElements(arr, nullptr);

return (jlong) new vpImage<vpRGBa>((vpRGBa *const)array, (const unsigned int)h, (const unsigned int)w, copyData);
return (jlong) new vpImage<vpRGBa>((vpRGBa *const)array, (const unsigned int)h, (const unsigned int)w, copyData);

// be memory friendly
env->ReleaseByteArrayElements(arr, array, 0);
}
// be memory friendly
env->ReleaseByteArrayElements(arr, array, 0);
}

// Java Method: getCols()
JNIEXPORT jint JNICALL Java_org_visp_core_VpImageRGBa_n_1cols(JNIEnv *env, jclass, jlong address)
{
(void)env;
vpImage<vpRGBa> *me = (vpImage<vpRGBa> *)address; // TODO: check for nullptr
return me->getCols();
}
// Java Method: getCols()
JNIEXPORT jint JNICALL Java_org_visp_core_VpImageRGBa_n_1cols(JNIEnv *env, jclass, jlong address)
{
(void)env;
vpImage<vpRGBa> *me = (vpImage<vpRGBa> *)address; // TODO: check for nullptr
return me->getCols();
}

// Java Method: getRows()
JNIEXPORT jint JNICALL Java_org_visp_core_VpImageRGBa_n_1rows(JNIEnv *env, jclass, jlong address)
{
(void)env;
vpImage<vpRGBa> *me = (vpImage<vpRGBa> *)address; // TODO: check for nullptr
return me->getRows();
}
// Java Method: getRows()
JNIEXPORT jint JNICALL Java_org_visp_core_VpImageRGBa_n_1rows(JNIEnv *env, jclass, jlong address)
{
(void)env;
vpImage<vpRGBa> *me = (vpImage<vpRGBa> *)address; // TODO: check for nullptr
return me->getRows();
}

// Java Method: getPixel(int i, int j)
JNIEXPORT jbyteArray JNICALL Java_org_visp_core_VpImageRGBa_n_1getPixel(JNIEnv *env, jclass, jlong address, jint i,
jint j)
{
vpImage<vpRGBa> *me = (vpImage<vpRGBa> *)address; // TODO: check for nullptr
vpRGBa val = (*me)(i, j);
jbyteArray ret = env->NewByteArray(4);
unsigned char temp[] = {val.R, val.G, val.B, val.A};
env->SetByteArrayRegion(ret, 0, 4, (jbyte *)temp);
return ret;
}
// Java Method: getPixel(int i, int j)
JNIEXPORT jbyteArray JNICALL Java_org_visp_core_VpImageRGBa_n_1getPixel(JNIEnv *env, jclass, jlong address, jint i,
jint j)
{
vpImage<vpRGBa> *me = (vpImage<vpRGBa> *)address; // TODO: check for nullptr
vpRGBa val = (*me)(i, j);
jbyteArray ret = env->NewByteArray(4);
unsigned char temp[] = { val.R, val.G, val.B, val.A };
env->SetByteArrayRegion(ret, 0, 4, (jbyte *)temp);
return ret;
}

// Java Method: getPixels()
JNIEXPORT jbyteArray JNICALL Java_org_visp_core_VpImageRGBa_n_1getPixels(JNIEnv *env, jclass, jlong address)
{
vpImage<vpRGBa> *me = (vpImage<vpRGBa> *)address; // TODO: check for nullptr
jbyteArray ret = env->NewByteArray(me->getNumberOfPixel() * 4);
env->SetByteArrayRegion(ret, 0, me->getNumberOfPixel() * 4, (jbyte *)me->bitmap);
return ret;
}
// Java Method: getPixels()
JNIEXPORT jbyteArray JNICALL Java_org_visp_core_VpImageRGBa_n_1getPixels(JNIEnv *env, jclass, jlong address)
{
vpImage<vpRGBa> *me = (vpImage<vpRGBa> *)address; // TODO: check for nullptr
jbyteArray ret = env->NewByteArray(me->getNumberOfPixel() * 4);
env->SetByteArrayRegion(ret, 0, me->getNumberOfPixel() * 4, (jbyte *)me->bitmap);
return ret;
}

// Java Method: dump()
JNIEXPORT jstring JNICALL Java_org_visp_core_VpImageRGBa_n_1dump(JNIEnv *env, jclass, jlong address)
{
vpImage<vpRGBa> *me = (vpImage<vpRGBa> *)address; // TODO: check for nullptr
std::stringstream ss;
ss << *me;
return env->NewStringUTF(ss.str().c_str());
}
// Java Method: dump()
JNIEXPORT jstring JNICALL Java_org_visp_core_VpImageRGBa_n_1dump(JNIEnv *env, jclass, jlong address)
{
vpImage<vpRGBa> *me = (vpImage<vpRGBa> *)address; // TODO: check for nullptr
std::stringstream ss;
ss << *me;
return env->NewStringUTF(ss.str().c_str());
}

} // extern "C"
Loading

0 comments on commit 23098e8

Please sign in to comment.