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.
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!
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.
Why use JDeli?
JDeli offers a range of advantages over ImageIO and alternatives, including:
- prevents heap related JVM crashes
- implements unsupported image formats
- reduce output file size
- improve read/write performance
- supports threading
- superior image scaling algorithms
Did you know...
IDRsolutions offers a whole range of online file converters to convert PDF and Microsoft Excel, Word and Office Documents to HTML5, SVG or image formats?
It is free to use for single file conversions and also includes Developer links if you want to use our commercial software for bulk conversions. Find out more on this page