blob: ebe564e04a896ad46b4dd614457407800fccd664 [file] [log] [blame]
DRCf8e00552011-02-04 11:06:36 +00001TurboJPEG/OSS JNI Wrapper
2=========================
3
4TurboJPEG/OSS can optionally be built with a Java Native Interface wrapper,
5which allows the TurboJPEG/OSS dynamic library to be loaded and used directly
DRCc5a41992011-02-08 06:54:36 +00006from Java applications. The Java front end for this is defined in several
7classes located under org/libjpegturbo/turbojpeg. The source code for these
8Java classes is licensed under a BSD-style license, so the files can be
DRCf8e00552011-02-04 11:06:36 +00009incorporated directly into both open source and proprietary projects without
10restriction.
11
DRC2413cb82011-02-08 02:11:37 +000012TJExample.java, which should also be located in the same directory as this
DRCf8e00552011-02-04 11:06:36 +000013README file, demonstrates how to use the TurboJPEG/OSS Java front end to
14compress and decompress JPEG images in memory.
15
DRCc5a41992011-02-08 06:54:36 +000016 javac TJExample.java
DRCf8e00552011-02-04 11:06:36 +000017
18builds .class files for both the front end and example code.
19
20
DRC7c998222011-03-10 07:25:41 +000021Performance Pitfalls
22--------------------
23
24The TurboJPEG Java front end defines several convenience methods which can
25allocate image buffers or instantiate classes to hold the result of compress,
26decompress, or transform operations. However, if you use these methods, then
27be mindful of the amount of new data you are creating on the heap. It may be
28necessary to manually invoke the garbage collector to prevent heap exhaustion
29or to prevent performance degradation. Background garbage collection can kill
30performance, particularly in a multi-threaded environment (Java pauses all
31threads when the GC runs.)
32
33The Java front end always gives you the option of pre-allocating your own
34source and destination buffers, which allows you to re-use these buffers for
35compressing/decompressing multiple images. If the image sequence you are
36compressing or decompressing consists of images of the same size, then
37pre-allocating the buffers is recommended.
38
39
DRCf8e00552011-02-04 11:06:36 +000040Note for OS X users
41-------------------
42
43/usr/lib, the directory under which libturbojpeg.dylib is installed on Mac
44systems, is not part of the normal Java library path. Thus, when running a
45Java application that uses TurboJPEG/OSS on Mac systems, you will need to pass
46an argument of -Djava.library.path=/usr/lib to java.
DRCed6526f2011-02-05 05:41:18 +000047
48
49Note for Solaris users
50----------------------
51
52/opt/libjpeg-turbo/lib, the directory under which libturbojpeg.so is installed
53on Solaris systems, is not part of the normal Java library path. Thus, when
54running a Java application that uses TurboJPEG/OSS on Solaris systems, you will
55need to pass an argument of -Djava.library.path=/opt/libjpeg-turbo/lib to java.
56If using a 64-bit data model, then instead pass an argument of
57-Djava.library.path=/opt/libjpeg-turbo/lib/amd64 to use the 64-bit version of
58libturbojpeg.so.
DRCf2214c22011-02-05 05:51:46 +000059
60
61Note for MinGW users
62--------------------
63
64When libjpeg-turbo is built with MinGW, the TurboJPEG/OSS dynamic library is
65named libturbojpeg.dll instead of turbojpeg.dll. This is in keeping with the
66convention of MinGW, and it also avoids a filename conflict when the GCC and
67Visual C++ versions of the libjpeg-turbo SDK are installed on the same system.
68However, the TurboJPEG/OSS JNI wrapper will not work on Windows unless the DLL
69is named turbojpeg.dll. You can work around this by renaming the DLL or by
DRC2413cb82011-02-08 02:11:37 +000070simply changing the LoadLibrary() calls in TurboJPEG.java so that they load
DRCf2214c22011-02-05 05:51:46 +000071"libturbojpeg" instead of "turbojpeg".