shun-iwasawa 82a8f5
TurboJPEG Java Wrapper
shun-iwasawa 82a8f5
======================
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
The TurboJPEG shared library can optionally be built with a Java Native
shun-iwasawa 82a8f5
Interface wrapper, which allows the library to be loaded and used directly from
shun-iwasawa 82a8f5
Java applications.  The Java front end for this is defined in several classes
shun-iwasawa 82a8f5
located under org/libjpegturbo/turbojpeg.  The source code for these Java
shun-iwasawa 82a8f5
classes is licensed under a BSD-style license, so the files can be incorporated
shun-iwasawa 82a8f5
directly into both open source and proprietary projects without restriction.  A
shun-iwasawa 82a8f5
Java archive (JAR) file containing these classes is also shipped with the
shun-iwasawa 82a8f5
"official" distribution packages of libjpeg-turbo.
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
TJExample.java, which should also be located in the same directory as this
shun-iwasawa 82a8f5
README file, demonstrates how to use the TurboJPEG Java API to compress and
shun-iwasawa 82a8f5
decompress JPEG images in memory.
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
Performance Pitfalls
shun-iwasawa 82a8f5
--------------------
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
The TurboJPEG Java API defines several convenience methods that can allocate
shun-iwasawa 82a8f5
image buffers or instantiate classes to hold the result of compress,
shun-iwasawa 82a8f5
decompress, or transform operations.  However, if you use these methods, then
shun-iwasawa 82a8f5
be mindful of the amount of new data you are creating on the heap.  It may be
shun-iwasawa 82a8f5
necessary to manually invoke the garbage collector to prevent heap exhaustion
shun-iwasawa 82a8f5
or to prevent performance degradation.  Background garbage collection can kill
shun-iwasawa 82a8f5
performance, particularly in a multi-threaded environment (Java pauses all
shun-iwasawa 82a8f5
threads when the GC runs.)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
The TurboJPEG Java API always gives you the option of pre-allocating your own
shun-iwasawa 82a8f5
source and destination buffers, which allows you to re-use those buffers for
shun-iwasawa 82a8f5
compressing/decompressing multiple images.  If the image sequence you are
shun-iwasawa 82a8f5
compressing or decompressing consists of images of the same size, then
shun-iwasawa 82a8f5
pre-allocating the buffers is recommended.
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
Installation Directory
shun-iwasawa 82a8f5
----------------------
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
The TurboJPEG Java Wrapper will look for the TurboJPEG JNI library
shun-iwasawa 82a8f5
(libturbojpeg.so, libturbojpeg.jnilib, or turbojpeg.dll) in the system library
shun-iwasawa 82a8f5
paths or in any paths specified in LD_LIBRARY_PATH (Un*x), DYLD_LIBRARY_PATH
shun-iwasawa 82a8f5
(Mac), or PATH (Windows.)  Failing this, on Un*x and Mac systems, the wrapper
shun-iwasawa 82a8f5
will look for the JNI library under the library directory configured when
shun-iwasawa 82a8f5
libjpeg-turbo was built.  If that library directory is
shun-iwasawa 82a8f5
/opt/libjpeg-turbo/lib32, then /opt/libjpeg-turbo/lib64 is also searched, and
shun-iwasawa 82a8f5
vice versa.
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
If you installed the JNI library into another directory, then you will need
shun-iwasawa 82a8f5
to pass an argument of -Djava.library.path={path_to_JNI_library} to java, or
shun-iwasawa 82a8f5
manipulate LD_LIBRARY_PATH, DYLD_LIBRARY_PATH, or PATH to include the directory
shun-iwasawa 82a8f5
containing the JNI library.