The JavaTM Advanced Imaging (JAI) tutorial provides an overview of JAI features, source code, and demos in the form of an
interactive book. Examples show key JAI functionality and coding style to incorporate advanced imaging features into programs or applets, including:
- Convolution filtering
- Basic image arithmetic operators
- Look up table operations (brightness and contrast)
- Pan and zoom
- Image compositing
The tutorial was written using the JavaTM Foundation Classes and Project Swing components. To view this tutorial or to develop applets using JAI, you must download and install the JavaTM Plug-In and the JAI package. This tutorial is also available in application form on the JAI web site.
Tutorial Set Up
To view JAI tutorial applets in your browser:
- Download and install the latest version of JavaTM Plug-In.
- Download and install the latest version of JAI. The JAI installation puts the files into the JDKTM on the system. To use JAI with applets in browsers, copy the appropriate JAR files to the virtual machine used by the browser.
For Solaris
The next steps assume that Netscape has been installed in the following path:
/opt/NSCPcom/
- Set the following environment variables (in csh):
% setenv THREADS_FLAG native
% setenv NPX_PLUGIN_PATH /opt/NSCPcom/plugins
% setenv NPX_JRE_PATH /opt/NSCPcom/j2pi
- Copy the JAI files to the
plugin
directory:
$PLUGIN
is the location Netscape has been installed.
$ARCH
is the architecture(sparc/i386).
$JAVAHOME
is the location of the JDK.
// Type each %cp command on one line
%cp $JAVAHOME/jre/lib/ext/jai_core.jar $PLUGIN
/j2pi/lib/
%cp $JAVAHOME/jre/lib/ext/jai_codec.jar
$PLUGIN/j2pi/lib/
%cp $JAVAHOME/jre/lib/ext/mlibwrapper_jai.jar
$PLUGIN/j2pi/lib/
%cp $JAVAHOME/jre/lib/ext/registryFile.jai
$PLUGIN/j2pi/lib/
%cp $JAVAHOME/jre/lib/$ARCH/libmlib_java_jai.so
$PLUGIN/j2pi/lib/$ARCH/
- If
$ARCH
is sparc, do the following:
// Type the following on one line
%cp $JAVAHOME/jre/lib/$ARCH
/libmlib_java_jai_vis.so
$PLUGIN/j2pi/lib/$ARCH/
For Windows
Copy the JAI files to the JRE in the JavaSoft
directory.
C:\Program Files\JavaSoft\JRE\
Copying the files can be done either from the command line or from Windows Explorer.
- From the command line:
%JAVAHOME%
is the location of the JDK.
%JRE%
is the location of the Java Runtime Environment.
()
// Type each of the commands on one line
C:\>copy %JAVAHOME%\jre\lib\ext
\jai_core.jar %JRE%\lib\ext
C:\>copy %JAVAHOME%\jre\lib\ext
\jai_codec.jar %JRE%\lib\ext
C:\>copy %JAVAHOME%\jre\lib\ext
\mlibwrapper_jai.jar %JRE%\lib\ext
C:\>copy %JAVAHOME%\jre\lib\ext
\registryFile.jai %JRE%\lib\ext
C:\>copy %JAVAHOME%\jre\bin\
mlib_image_jai.dll %JRE%\bin\
C:\>copy %JAVAHOME%\jre\bin
\mlib_java_jai.dll %JRE%\bin\
- From Windows Explorer:
Copy and paste the files from
\lib\ext
to:
C:\Program Files\JavaSoft\JRE\
In addition, copy and paste the files in
\bin\
to:
C:\Program Files\JavaSoft\JRE\
These steps ensure that the JAI files are picked up by the plugin at runtime.
Applet Permissions
For JAI applets to use native acceleration on the Sparc and Windows platforms, appropriate security permissions must be given.
Edit the java.policy file to set permissions. The location of java.policy depends on your operating system.
- Solaris:
/opt/NSCPcom/j2pi/lib/security/java.policy
- Windows:
C:\Program Files\JavaSoft\Jre\1.x\lib\security\java.policy
Edit java.policy so it contains only the following:
grant
{
permission java.security.AllPermission;
};
Warning: Setting these security permissions grants ALL applets complete privileges on your system, which may expose your system to danger from rogue applets.
Note: In case an OutOfMemoryException
is encountered while running some of the demos
in the tutorial, try changing the amount of memory available to the JavaTM Virtual
Machine1 by adding the following "Java Run Time Parameters" in the Java Plug In
Control Panel:
-ms16m -mx64m
The Java Plug In Control Panel is located in the Control Panel on Windows
machine and in the Java Plug In directory on Solaris machines (typically
/opt/NSCPcom/j2pi
)
Reader Survey
Tell us what you think of this tutorial.
_______
1 As used on this web site, the terms "Java
Virtual Machine" or "JVM" mean a virtual machine for the Java
platform.