iron261 / openjpeg

Automatically exported from code.google.com/p/openjpeg
Other
0 stars 0 forks source link

JNI Problems #404

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Download trunk
2. Run cmake with -DBUILD_JAVA:bool=on
3. Run make

What is the expected output? What do you see instead?
I expect it to build without errors.

Due to changes in the core code, not reflected in the JNI bindings, the jar 
fails to build.

What version of the product are you using? On what operating system?
Tested on Windows 7 and Redhat Linux

Please provide any additional information below.
I believe this patch will also close issue 199.
Due to problems with git diff, the patch has to be applied in 2 files. One with 
the changes and deletions to the trunk, the other with the newly added files. 
Though, these newly added files and mainly renames of original files with 
modifications.

Feel free to contact me if you need any more information

Original issue reported on code.google.com by belko...@students.rowan.edu on 22 Sep 2014 at 12:17

Attachments:

GoogleCodeExporter commented 9 years ago
Issue 404 - JNI not found

Original comment by belko...@students.rowan.edu on 22 Sep 2014 at 12:18

GoogleCodeExporter commented 9 years ago
These patches do not work.

-------------------------------------------------------------
cmake -DCMAKE_BUILD_TYPE:string="Release" -DBUILD_VIEWER:bool=off 
-DBUILD_JAVA:bool=on -DBUILD_JPIP_SERVER:bool=off -DBUILD_SHARED_LIBS:bool=on 
-DBUILD_MJ2:bool=on -DBUILD_JP3D:bool=off -DBUILD_JPWL:bool=off 
-DBUILD_JPIP:bool=off -DCMAKE_INSTALL_PREFIX=/usr/local/JAVA_TEST ..

/home/szukw000/OPENJPEG/TRUNK/openjpeg-2.x-trunk-r2885-1/src/bin/jp2/convert.h:6
2:5: error: unknown type name 'OPJ_BOOL'
     OPJ_BOOL rawSigned;
     ^
make[2]: *** 
[wrapping/java/openjp2/CMakeFiles/openjpegjni.dir/JavaOpenJPEGDecoder.c.o] 
Error 1
make[1]: *** [wrapping/java/openjp2/CMakeFiles/openjpegjni.dir/all] Error 2
make: *** [all] Error 2
-------------------------------------------------------------

The 'openjp2' library does not know 'opj_stream_create_file_stream_v4()'.

This is a function invented by Aaron Boxer for his

 openjpeg-java_imageio resp. RadStackJava

archives. I suppose these patches are 'copies' of the respective
'wrapping/java/openjp2' files of these archives:
-------------------------------------------------------------
                                    decodeInfo.stream = opj_stream_create_file_stream_v4(p_file_info,OPJ_J2K_STREAM_CHUNK_SIZE,1);
./wrapping/java/openjp2/OpenJPEGJavaDecoder.c
        return opj_stream_create_file_stream_v4(p_file_info, p_size, p_is_read_stream);
opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream_v4 (
./src/lib/openjp2/openjpeg.c

OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream_v4 
(opj_file_info_t* p_file_info,
./src/lib/openjp2/openjpeg.h
-------------------------------------------------------------

And the 'wrapping/java/openjp2/CMakeLists.txt' file contains:
-------------------------------------------------------------
# FIXME (need to use old API):
if(BUILD_MJ2)
  target_link_libraries(openjpegjni openmj2)
endif()
-------------------------------------------------------------

But 'src/lib/openjp2/openjpeg.h' does know OPJ_BOOL, OPJ_OFF_T,
OPJ_SIZE_T, OPJ_CODEC_J2K, etc.

Only 'src/lib/openmj2/openjpeg.h' does know them.

winfried

Original comment by szukw...@arcor.de on 22 Sep 2014 at 10:14

GoogleCodeExporter commented 9 years ago
Sorry, paste error. Correction:

Only 'src/lib/openjp2/openjpeg.h' does know OPJ_BOOL, OPJ_OFF_T,
OPJ_SIZE_T, OPJ_CODEC_J2K, etc.

But 'src/lib/openmj2/openjpeg.h' does NOT know them.

winfried

Original comment by szukw...@arcor.de on 23 Sep 2014 at 9:31

GoogleCodeExporter commented 9 years ago
Hello Winfried,

I went back and looked at the trunk and had the same errors.

The MJ2 is broken there, not by something in this patch.
The "Fix Me" in the 'wrapping/java/openjp2/CMakeLists.txt' is also in the trunk.

Pat

Original comment by belko...@students.rowan.edu on 24 Sep 2014 at 12:56

GoogleCodeExporter commented 9 years ago
The MJ2 library is not broken. The patch is 'broken'.

In the following lines JAVA means 'src/lib/openjp2' from

 https://github.com/CodecCentral/openjpeg/tree/java_imageio

 openjpeg-java_imageio.zip

Please show me the file where the following is found
either in

'openjpeg-2.x-trunk-r2885/src/lib/openjp2'

or

'openjpeg-2.x-trunk-r2885/src/lib/openmj2':

JAVA/openjpeg.h:
=========================

typedef struct opj_buffer_info
{
    OPJ_BYTE *buf;
    OPJ_BYTE *cur;
    OPJ_SIZE_T len;
} opj_buffer_info_t;

OPJ_API opj_stream_t* OPJ_CALLCONV
opj_stream_create_buffer_stream(opj_buffer_info_t* p_source_buffer,
    OPJ_BOOL p_is_read_stream);

typedef struct opj_segmented_file_info
{
    char infile[OPJ_PATH_LEN];
    FILE* p_file;
    OPJ_SIZE_T dataLength;
    OPJ_SIZE_T dataRead;
    int numSegmentsMinusOne;
    OPJ_OFF_T* p_segmentPositionsList;
    OPJ_SIZE_T* p_segmentLengths;
    OPJ_OFF_T curPos;
    int curSegment;
} opj_file_info_t;

OPJ_API opj_stream_t* OPJ_CALLCONV
opj_stream_create_default_file_stream_v4 (opj_file_info_t* p_file_info,
    OPJ_BOOL p_is_read_stream);

OPJ_API opj_stream_t* OPJ_CALLCONV
opj_stream_create_file_stream_v4 (opj_file_info_t* p_file_info,
    OPJ_SIZE_T p_buffer_size,
    OPJ_BOOL p_is_read_stream);

OPJ_API opj_stream_t* OPJ_CALLCONV
opj_stream_create_segmented_file_stream(opj_file_info_t* p_source_file,
    OPJ_BOOL p_is_read_stream);

JAVA/openjpeg.c:
=========================

static void
opj_increment_segment(opj_file_info_t * p_file_info);

static OPJ_SIZE_T
opj_read_from_segmented_file (void * p_buffer,
    OPJ_SIZE_T p_nb_bytes, opj_file_info_t * p_file_info);

static OPJ_SIZE_T
opj_get_data_length_from_segmented_file (opj_file_info_t * p_file_info);

static OPJ_BOOL
opj_init_segmented_file_info (opj_file_info_t * p_file_info);

static OPJ_OFF_T
opj_skip_from_segmented_file (OPJ_OFF_T p_nb_bytes,
    opj_file_info_t * p_file_info);

static OPJ_BOOL
opj_seek_from_segmented_file (OPJ_OFF_T p_nb_bytes,
    opj_file_info_t* p_file_info);

static OPJ_SIZE_T
opj_read_from_file (void * p_buffer, OPJ_SIZE_T p_nb_bytes,
    opj_file_info_t* p_file_info);
    ^^^^^^^^^^^^^^^^^
static OPJ_SIZE_T
opj_get_data_length_from_file (opj_file_info_t * p_file_info);
                               ^^^^^^^^^^^^^^^^^
static OPJ_SIZE_T
opj_write_from_file (void * p_buffer, OPJ_SIZE_T p_nb_bytes,
    opj_file_info_t * p_file_info);
    ^^^^^^^^^^^^^^^^^
static OPJ_OFF_T
opj_skip_from_file (OPJ_OFF_T p_nb_bytes,
    opj_file_info_t * p_user_data);
    ^^^^^^^^^^^^^^^^^
static OPJ_BOOL
opj_seek_from_file (OPJ_OFF_T p_nb_bytes,
    opj_file_info_t * p_user_data);
    ^^^^^^^^^^^^^^^^^

>The "Fix Me" in the 'wrapping/java/openjp2/CMakeLists.txt' is also in the 
trunk.

Yes. Because using the MJ2 library was necessary to use the code in
'wrapping/java/openjp2/': this code is openjpeg-v1 code; and the MJ2
code too is openjpeg-v1 code.

winfried

Original comment by szukw...@arcor.de on 25 Sep 2014 at 10:46

GoogleCodeExporter commented 9 years ago
Pat,

I have written a very simple adaption of

 'wrapper/java/openjp2'

for 'openjpeg-2.x-trunk-r2887'.

Simple means: all openjpeg-v1 code is replaced with code
from openjpeg-v2.

The code needs polish.

It compiles on LINUX. Can you test it?

Do you need the

  create_index_into_byte_array()

function?

Please read the comment above the definition.

winfried

Original comment by szukw...@arcor.de on 29 Sep 2014 at 5:21

Attachments:

GoogleCodeExporter commented 9 years ago
Winfried,

Thanks for providing a more updated version of the wrapper code that uses the 
jp2 library. I got your code to compile, but I was unable to create the 
openjpegjni library. That's alright though, I was able to build it shortly 
after with some edits to the CMake file found in the wrapping/java/openjp2 
directory.

Soon I will be releasing another version of the patch. I will provide the 
option of using a byte stream for the decoder. Note: I made some changes to 
your OpenJPEGJavaDecoder class to make the byte stream option work. I am not 
sure if I will make any edits to the encoder code though.

Original comment by emd5...@psu.edu on 2 Oct 2014 at 1:31

GoogleCodeExporter commented 9 years ago
Here is 'wrapping-trunk-r2887.tgz', the

 'wrapping/java/openjp2'

directory for 'openjpeg-2.x-trunk-r2882'.

In openjpeg-v1, JavaOpenJPEGDecoder.c:
===============================================
'-i' is an option and used.
'-o' is an option and used.
'-O' is an option and used.
 '-ImgDir' is an option and used in load_images() that is unused.
 '-OutFor' is an option REQUIRED only together with '-ImgDir'.

In openjpeg-v1, JavaOpenJPEG.c: // i.e. JavaOpenJPEGEncoder.c
===============================================
'-i' is no option.
'-o' is an option and used.
 '-ImgDir' is an option that is unused.
 '-OutFor' is an option REQUIRED only together with '-ImgDir'.
'-x' is an option and used.

So in openjpeg-v2, JavaOpenJPEGDecoder.c:
===============================================
'-ImgDir' and '-OutFor' HAVE BEEN REMOVED.

And in openjpeg-v2, JavaOpenJPEGEncoder.c:
===============================================
'-ImgDir' and '-OutFor' HAVE BEEN REMOVED.

DO NOT FORGET: the top 'CMakeLists.txt' needs inclusion of
the following code (in line 191 of trunk-r2882):

if(UNIX)
 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
endif(UNIX)

Necessary for BUILD_THIRDPARTY (static libraries) and
BUILD_JAVA (dynamic library).

Systems used: LINUX 64-Bit and Win7 64-Bit, JAVA-8u20.
              LINUX with 'gcc-4.8', Win7 with 'cl'.

winfried

Original comment by szukw...@arcor.de on 3 Oct 2014 at 12:48

Attachments:

GoogleCodeExporter commented 9 years ago
Winfried,

The wrapping-trunk-r2887 version you just provided, will this be the official 
patch of this issue or will you be continuing to add more?

Original comment by emd5...@psu.edu on 3 Oct 2014 at 12:33

GoogleCodeExporter commented 9 years ago
Winfried,

I provided an update to your recent wrapping-trunk-r2887 version. I added the 
option to use a byte stream (using the byte stream functions that Aaron Boxer 
was using but still staying with the openjp2 libraries) to decode an image. I 
provided a 'changesanddeletions' diff (Comparing your recent r2887 submission 
to mine submission).

To use the byte stream option for the OpenJPEGJavaDecoder, just call the 
OpenJPEGJavaDecoder's setCompressedStream function and set the byte array of 
that j2k image file and then call the decodeJ2KtoImage() function. It won't 
export to anything (as intended), but it will return an array of J2K info to 
the image8, image16, image24 variables and you can create a BufferedImage from 
that.

I only modified a few lines of code in the JavaOpenJPEGDecoder.c/h and 
JavaOpenJPEGEncoder.c/h files and the OpenJPEGJavaDecoder.java file to allow 
the byte stream functions to work. I was using Windows 7/MinGW to compile 
OpenJPEG. If there's any problems, let me know. You might need to change the C 
JNI functions calls back to their original names (I had an UnsatifiedLinkError 
from Java because I had to add an underscore in front of the JNI C functions. I 
don't know if there is a workaround this for Windows systems).

-Eric

Original comment by emd5...@psu.edu on 9 Oct 2014 at 6:37

Attachments:

GoogleCodeExporter commented 9 years ago
I am chopped off: my (provider) modem is broken. So only two short notes.

The wrapping directory is part of the offical library. But

   opj_stream_create_buffer_stream()

is not found in the official library. It is only part of Aaron Boxers
archive (Cnf. comment #5).

Using a buffer stream you have to create a local function in your application.
E.g.:

static opj_stream_t* stream_create_buffer_stream(opj_buffer_info_t* buf_info,
    OPJ_UINT32 p_size, OPJ_BOOL p_is_read_stream)
{
    opj_stream_t* l_stream;

    l_stream = opj_stream_create(p_size, p_is_read_stream);

    if(! l_stream) return NULL;

    opj_stream_set_user_data(l_stream, buf_info);

    opj_stream_set_user_data_length(l_stream, buf_info->len);

    opj_stream_set_read_function(l_stream,
     (opj_stream_read_fn) read_from_buffer);

    opj_stream_set_write_function(l_stream,
     (opj_stream_write_fn) write_from_buffer);

    opj_stream_set_skip_function(l_stream,
     (opj_stream_skip_fn) skip_from_buffer);

    opj_stream_set_seek_function(l_stream,
     (opj_stream_seek_fn) seek_from_buffer);

    return l_stream;
}

Now you can read_from_buffer etc.

This does not look correct:

+       /*
+
+        /* Allocate JAVA memory:
+        */

winfried

Original comment by szukw...@arcor.de on 9 Oct 2014 at 9:18

GoogleCodeExporter commented 9 years ago
Thanks for looking into my patch submission. For the patch approval process, is 
it alright if I used those functions* that weren't in the  official libraries 
for the byte stream implementation? I also corrected the comments in the code. 
I will post another diff and zip file of the corrections in the near future.

Let me know if there's anything else I should do to get this issue resolved. 

Thanks,

Eric

*:
opj_stream_t* OPJ_CALLCONV opj_stream_create_buffer_stream(opj_buffer_info_t* 
p_source_buffer, OPJ_BOOL p_is_read_stream);

static OPJ_SIZE_T opj_read_from_buffer(void * p_buffer,
    OPJ_SIZE_T p_nb_bytes, opj_buffer_info_t* p_source_buffer);

static OPJ_SIZE_T opj_write_from_buffer(void * p_buffer,
    OPJ_SIZE_T p_nb_bytes, opj_buffer_info_t* p_source_buffer);

static OPJ_SIZE_T opj_skip_from_buffer(OPJ_SIZE_T p_nb_bytes,
    opj_buffer_info_t * p_source_buffer);

static OPJ_BOOL opj_seek_from_buffer(OPJ_SIZE_T p_nb_bytes,
    opj_buffer_info_t * p_source_buffer);

Original comment by emd5...@psu.edu on 10 Oct 2014 at 12:48

GoogleCodeExporter commented 9 years ago
I thought I might add to make things clearer, is it alright to leave those 
mentioned functions inside the JavaOpenJPEGDecoder.c/h files for the byte 
stream? I also added the opj_buffer_info struct in the JavaOpenJPEGDecoder.h 
file that was used in Aaron Boxer.

Original comment by emd5...@psu.edu on 10 Oct 2014 at 4:00

GoogleCodeExporter commented 9 years ago
Here's an update to the byte stream implementation. There wasn't a lot of 
changes to the code behavior for the byte stream (if any). All functions Aaron 
Boxer used for the byte stream are fully implemented into the 
JavaOpenJPEGDecoder.h/c files. Cleaned up some of the comments. Feel free to 
let me know if there's anything else I can do.

Original comment by emd5...@psu.edu on 13 Oct 2014 at 7:27

Attachments:

GoogleCodeExporter commented 9 years ago
I was just checking in to see if there was an update for the patch. winfried 
and I have done some patch updates to get this issue fixed, but I was hoping if 
anyone could check in and give me an update on the patch progress.

Thanks,

Eric

Original comment by emd5...@psu.edu on 22 Oct 2014 at 1:47

GoogleCodeExporter commented 9 years ago

Original comment by antonin on 22 Oct 2014 at 11:04

GoogleCodeExporter commented 9 years ago
Thanks antonin for the update. I hope our patches makes this an easy 
implementation for the trunk's wrapping code. My most recent patch (#14) just 
adds onto winfried's patch with a simple compressed byte stream option for the 
JNI JavaDecoder. 

Eric

Original comment by emd5...@psu.edu on 27 Oct 2014 at 6:15

GoogleCodeExporter commented 9 years ago
Hello,

Just checking back to see if there was any patch updates for this issue. 

I was hoping to know how long it might take to get this issue verified. I know 
it's just the JNI bindings. 

Thanks,

-Eric

Original comment by emd5...@psu.edu on 12 Nov 2014 at 9:44

GoogleCodeExporter commented 9 years ago
I've reformatted the syntax so it would match up with what was in the trunk so 
the .patch can make it easier to see what I've changed. I'v changed 
JavaOpenJPEGDecoder.c the most, so it might be harder to see what I've changed. 
Also, I have made a github mirror of OpenJPEG 
(https://github.com/emd5174/openjpeg/tree/jni). If you wish to do a comparison 
of the most recent changes, https://github.com/emd5174/openjpeg/tree/jni). 

-Eric

Original comment by emd5...@psu.edu on 6 Jan 2015 at 3:04

Attachments:

GoogleCodeExporter commented 9 years ago
I've updated the github project, so the issue404.patch is now obsolete. To get 
the current up to date patch https://github.com/emd5174/openjpeg/compare/jni 
(select the files changed tab).  

The only files that were changed from the master branch of OpenJPEG were 
/wrapping/java/openjp2/CMakeLists.txt and 
/wrapping/java/openjp2/JavaOpenJPEGDecoder.c
and the 
/wrapping/java/openjp2/java-sources/org/openJpeg/OpenJPEGJavaDecoder.java class 
(There are other files in that diff, but I added those extra files for my own 
uses. OpenJPEG will not need them). 

Original comment by emd5...@psu.edu on 25 Feb 2015 at 5:56

GoogleCodeExporter commented 9 years ago
Also include /wrapping/java/openjp2/java_helpers.h in that diff.

Original comment by emd5...@psu.edu on 25 Feb 2015 at 6:07