Menu

Home

StephenG
There is a newer version of this page. You can find it here.

JLibJPEG is a small Java class interfacing to C code using JNI. Ut is designed to load large JPEGs as quickly as possible.

JPEG images are a major, perhaps the major, image file type used in applications. Java's standard methods for loadig a JPEG to a BufferedImage are very slow. This is particularl;y frsutrating if you want to develop applications that view the large image files from modern cameras. JLibJPEG tries to address this by providing an explicit call to load JPEGs.

JLibJPEG should work with both RGB and B&W images - it has been tested with both.

Performance tests on the developer's system using an AMD A8 APU indicate a speedup of up to a factor of ten over ImageIO for a 16Mp JPEG straight from a digital camera. The smaller the image, the less the gain. In practical terms this made the difference between a photo viewer application that could flip between images ona key stroke and one that had serious lag when images were switched.

Using JLibJPEG

Using JLIbJPEG is very simple - it's just one call to a static method. For example ;

BufferedImage bi = JLibJPEG.loadImage( "location/name.jpg" ) ;

The loadImage() method returns null if the load operation fails for any reason. No exceptions should be thrown.

Building JLibJPEG

To build JLibJPEG you first need to compile the Java file and then use that to build the C include file with javah. Finally you compile the C file with the native code. THis is an example from teh developer's own system :

javac JLibJPEG.java

javah -jni JLibJPEG

jar cf JLibJPEG.jar *.class

gcc -g -shared -fPIC -I/usr/lib/jvm/java-7-openjdk-amd64/include -o libJLibJPEG.so JLibJPEG.c -ljpeg

The resulting JAR and shared library files need to be on your application's classpath to use them, of course.

A test file is also available

Project Members:


MongoDB Logo MongoDB