suda Senior Java EE Develope specialises in Pdf forms , Fonts, application servers and Image manipulation, meditates in spare time.

Fixing bugs in the Java JPEG2000 library – getting the source code to run

1 min read

In 2 previous blog posts, my colleague Daniel wrote about finding a memory leak in the Java JPEG2000 library and the source code change. I have been looking at another bug  so I thought a series of articles on the subject would be of interest.

To use JPEG2000 images in Java, you need to use some additional libraries. These seem to have been abandoned by Oracle but luckily you can still get the source code to debug. This article is about how to get the source code and set it up to run in an IDE (I have used Eclipse as an example);.

Downloading the source

The first step is to get the Java code.

You can download the source code from Oracle with this command

svn co https://svn.java.net/svn/jai-imageio-core~svn

Don’t forget to include Daniel’s patch for the memory leak which you can get here.

Set the source as your src

The SVN repositry actually contains not only the source code bu also jars needed to run the code and build tools. The source code for the actual JPEG2000 plugin is hidden in trunk/src/share/classes – we added a link to this so we could preserve the SVN structure and still have the correct package locations. You will also need the 2 JAI jars (jai_core.jar and jai_codec.jar) and trunk/src/share/jc4libjai/clibwrapper_jiio.jar to compile the source.

Hacking the source to run

To get the code to run, I found that I had to hack the PackageUtil class. Once you have downloaded and configured the project, hack the vendor code  in the package com.sun.media.imageioimpl.common.PackageUtil.java by setting version and vendor details as you can see in this screenshot.

Java code to edit

The actual JPEG2000 code is mainly found in jpeg2000 library plug-ins can be found in the package called com.sun.media.imageioimpl.plugins.jpeg2000; I will be looking at this in more detail in later articles…

Now you are ready to start hacking the code!

Update
In the end we gave up with trying to patch ImageIO and JAI and wrote our own ImageIO replacement from scratch. Lots of other developers seemed to have the problems so we made this commercially available as the JDeli Image library. You can find out more on the JDeli page.

IDRsolutions develop a Java PDF Viewer and SDK, an Adobe forms to HTML5 forms converter, a PDF to HTML5 converter and a Java ImageIO replacement. On the blog our team post anything interesting they learn about.

suda Senior Java EE Develope specialises in Pdf forms , Fonts, application servers and Image manipulation, meditates in spare time.

How to choose JPG versus JPEG2000 for image files

Since we started to support both JPG and JPG2000 as image file outputs in our software, we have found that this is a very...
Mark Stephens
1 min read

What’s new in Java13?

Nirali
1 min read

Leave a Reply

Your email address will not be published. Required fields are marked *

IDRsolutions Ltd 2019. All rights reserved.