R
Roland Richter
Dear all,
I work on an application which grabs/creates images in a native DLL
(written in C++, using Intel's IPP) and displays them in a Java
Swing GUI, using a class which displays a given BufferedImage.
This, of course, involves some conversions:
1) On the Java side: Call
((DataBufferByte)bufferedImage.getRaster().getDataBuffer()).getData()
to obtain a "pointer" to the byte array which backs the BufferedImage.
2) Pass that pointer to the JNI side and copy the contents of the native
image into that arry, something like
env->SetByteArrayRegion( (jbyteArray)target, 0, size, native_data );
I wonder whether copying in step 2) could be avoided.
java.nio is said to provide direct byte buffers for exactly this purpose.
However, I could not figure out the details, so I need some help.
Seems like there are two possibilites:
1) On the JNI side, create a ByteBuffer with NewDirectByteBuffer();
hopefully, this buffer is backed by an array (??!), so that one
can call the array() method on the Java side and use this byte[]
to create a BufferedImage.
2) Create a memory mapped file / MappedByteBuffer on the Java side;
get its address calling GetDirectBufferAddress() on the JNI side,
and use this memory area for the native images.
Both approaches seem error-prone to me; sure I'm missing something???
Any help is highly appreciated.
- Roland
I work on an application which grabs/creates images in a native DLL
(written in C++, using Intel's IPP) and displays them in a Java
Swing GUI, using a class which displays a given BufferedImage.
This, of course, involves some conversions:
1) On the Java side: Call
((DataBufferByte)bufferedImage.getRaster().getDataBuffer()).getData()
to obtain a "pointer" to the byte array which backs the BufferedImage.
2) Pass that pointer to the JNI side and copy the contents of the native
image into that arry, something like
env->SetByteArrayRegion( (jbyteArray)target, 0, size, native_data );
I wonder whether copying in step 2) could be avoided.
java.nio is said to provide direct byte buffers for exactly this purpose.
However, I could not figure out the details, so I need some help.
Seems like there are two possibilites:
1) On the JNI side, create a ByteBuffer with NewDirectByteBuffer();
hopefully, this buffer is backed by an array (??!), so that one
can call the array() method on the Java side and use this byte[]
to create a BufferedImage.
2) Create a memory mapped file / MappedByteBuffer on the Java side;
get its address calling GetDirectBufferAddress() on the JNI side,
and use this memory area for the native images.
Both approaches seem error-prone to me; sure I'm missing something???
Any help is highly appreciated.
- Roland