?? programming in java advanced imaging3.htm
字號(hào):
<CODE>double</CODE>, or an <CODE>Object</CODE>. The
<CODE>setOperationName</CODE> method can be used to change the operation name.
The <CODE>setParameterBlock</CODE> method can be used to change the nodes's
<CODE>ParameterBlock</CODE>.
<P><A name=57755>
<H4>3.3.3.2 <IMG
src="Programming in Java Advanced Imaging3.files/space.gif">Editing Renderable
Graphs</H4></A>Since Renderable graphs are not evaluated until there is a
specific request for a rendering, the nodes may be edited at any time. The
main concern with editing Renderable graphs is the introduction of cycles,
which must be avoided.
<P>The <CODE>RenderableOp</CODE> class provides several methods for
reconfiguring a Renderable node. The <CODE>setParameter</CODE> methods can be
used to set the node's parameters to a <CODE>byte</CODE>, <CODE>char</CODE>,
<CODE>short</CODE>, <CODE>int</CODE>, <CODE>long</CODE>, <CODE>float</CODE>,
<CODE>double</CODE>, or an <CODE>Object</CODE>. The
<CODE>setParameterBlock</CODE> method can be used to change the nodes's
<CODE>ParameterBlock</CODE>. The <CODE>setProperty</CODE> method can be used
to change a node's local property. The <CODE>setSource</CODE> method can be
used to set one of the node's sources to an <CODE>Object</CODE>.
<P><A name=56364>
<H2>3.4 <IMG
src="Programming in Java Advanced Imaging3.files/space.gif">Remote
Execution</H2></A>Up to this point, we have been talking about standalone
image processing. JAI also provides for client-server image processing through
what is called the <EM>Remote Execution</EM> model.
<P>Remote execution is based on Java RMI (remote method invocation). Java RMI
allows Java code on a client to invoke method calls on objects that reside on
another computer without having to move those objects to the client. The
advantages of remote execution become obvious if you think of several clients
wanting to access the same objects on a server. To learn more about remote
method invocation, refer to one of the books on Java described in <A
href="http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Preface.doc.html#47778">"Related
Documentation" on page xv</A>.
<P>To do remote method invocation in JAI, a <CODE>RemoteImage</CODE> is set up
on the server and a <CODE>RenderedImage</CODE> chain is set up on the client.
For more information, see <A
href="http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Client-server.doc.html#47285">Chapter
12, "Client-Server Imaging</A>."
<P><A name=52603>
<H2>3.5 <IMG src="Programming in Java Advanced Imaging3.files/space.gif">Basic
JAI API Classes</H2></A>JAI consists of several classes grouped into five
packages:
<P>
<UL>
<LI><CODE>javax.media.jai</CODE> - contains the "core" JAI interfaces and
classes
<P></P></LI></UL>
<UL>
<LI><CODE>javax.media.jai.iterator</CODE> - contains special iterator
interfaces and classes, which are useful for writing extension operations
<P></P></LI></UL>
<UL>
<LI><CODE>javax.media.jai.operator</CODE> - contains classes that describe
all of the image operators
<P></P></LI></UL>
<UL>
<LI><CODE>javax.media.jai.widget</CODE> - contains interfaces and classes
for creating simple image canvases and scrolling windows for image display
<P></P></LI></UL>Now, let's take a look at the most common classes in the JAI
class hierarchy.
<P><A name=52605>
<H3>3.5.1 <IMG src="Programming in Java Advanced Imaging3.files/space.gif">The
JAI Class</H3></A>The <CODE>JAI</CODE> class cannot be instantiated; it is
simply a placeholder for static methods that provide a simple syntax for
creating Renderable and Rendered graphs. The majority of the methods in this
class are used to create a <CODE>RenderedImage</CODE>, taking an operation
name, a <CODE>ParameterBlock</CODE>, and <CODE>RenderingHints</CODE> as
arguments. There is one method to create a <CODE>RenderableImage</CODE>,
taking an operation name, a <CODE>ParameterBlock</CODE>, and
<CODE>RenderingHints</CODE> as arguments.
<P>There are several variations of the <CODE>create</CODE> method, all of
which take sources and parameters directly and construct a
<CODE>ParameterBlock</CODE> automatically.
<P><A name=52611>
<H3>3.5.2 <IMG src="Programming in Java Advanced Imaging3.files/space.gif">The
PlanarImage Class</H3></A>The <CODE>PlanarImage</CODE> class is the main class
for describing two-dimensional images in JAI. <CODE>PlanarImage</CODE>
implements the <CODE>RenderedImage</CODE> interface from the Java 2D API.
<CODE>TiledImage</CODE> and <CODE>OpImage</CODE>, described later, are
subclasses of <CODE>PlanarImage</CODE>.<CODE></CODE>
<P>The <CODE>RenderedImage</CODE> interface describes a tiled, read-only image
with a pixel layout described by a <CODE>SampleModel</CODE> and a
<CODE>DataBuffer</CODE>. Each tile is a rectangle of identical dimensions,
laid out on a regular grid pattern. All tiles share a common
<CODE>SampleModel</CODE>.
<P>In addition to the capabilities offered by <CODE>RenderedImage</CODE>,
<CODE>PlanarImage</CODE> maintains source and sink connections between the
nodes of rendered graphs. Since graph nodes are connected bidirectionally, the
garbage collector requires assistance to detect when a portion of a graph is
no longer referenced from user code and may be discarded.
<CODE>PlanarImage</CODE> takes care of this by using the <EM>Weak References
API</EM> of Java 2.
<P>Any <CODE>RenderedImage</CODE>s from outside the API are "wrapped" to
produce an instance of <CODE>PlanarImage</CODE>. This allows the API to make
use of the extra functionality of <CODE>PlanarImage</CODE> for all images.
<P><A name=52625>
<H3>3.5.3 <IMG src="Programming in Java Advanced Imaging3.files/space.gif">The
CollectionImage Class</H3></A><CODE>CollectionImage</CODE> is the abstract
superclass for four classes representing collections of
<CODE>PlanarImage</CODE>s:
<P>
<UL>
<LI><CODE>ImageStack</CODE> - represents a set of two-dimensional images
lying in a common three-dimensional space, such as CT scans or seismic
volumes. The images need not lie parallel to one another.
<P></P></LI></UL>
<UL>
<LI><CODE>ImageSequence</CODE> - represents a sequence of images with
associated time stamps and camera positions. This class can be used to
represent video or time-lapse photography.
<P></P></LI></UL>
<UL>
<LI><CODE>ImagePyramid</CODE> - represents a series of images of
progressively lesser resolution, each derived from the last by means of an
imaging operator.
<P></P></LI></UL>
<UL>
<LI><CODE>ImageMIPMap</CODE> - represents a stack of images with a fixed
operational relationship between adjacent slices.
<P></P></LI></UL><A name=52640>
<H3>3.5.4 <IMG src="Programming in Java Advanced Imaging3.files/space.gif">The
TiledImage Class</H3></A>The <CODE>TiledImage</CODE> class represents images
containing multiple tiles arranged into a grid. The tiles form a regular grid,
which may occupy any rectangular region of the plane.
<P><CODE>TiledImage</CODE> implements the <CODE>WritableRenderedImage</CODE>
interface from the Java 2D API, as well as extending <CODE>PlanarImage</CODE>.
A <CODE>TiledImage</CODE> allows its tiles to be checked out for writing,
after which their pixel data may be accessed directly. <CODE>TiledImage</CODE>
also has a <CODE>createGraphics</CODE> method that allows its contents to be
altered using Java 2D API drawing calls.
<P>A <CODE>TiledImage</CODE> contains a tile grid that is initially empty. As
each tile is requested, it is initialized with data from a
<CODE>PlanarImage</CODE> source. Once a tile has been initialized, its
contents can be altered. The source image may also be changed for all or part
of the <CODE>TiledImage</CODE> using its <CODE>set</CODE> methods. In
particular, an arbitrary region of interest (ROI) may be filled with data
copied from a <CODE>PlanarImage</CODE> source.
<P>The <CODE>TiledImage</CODE> class includes a method that allows you to
paint a <CODE>Graphics2D</CODE> onto the <CODE>TiledImage</CODE>. This is
useful for adding text, lines, and other simple graphics objects to an image
for annotating the image. For more on the TiledImage class, see <A
href="http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Acquisition.doc.html#52363">Section
4.2.2, "Tiled Image</A>."
<P><A name=52693>
<H3>3.5.5 <IMG src="Programming in Java Advanced Imaging3.files/space.gif">The
OpImage Class</H3></A>The OpImage class is the parent class for all imaging
operations, such as:
<P>
<UL>
<LI><CODE>AreaOpImage</CODE> - for image operators that require only a fixed
rectangular source region around a source pixel to compute each destination
pixel
<P></P></LI></UL>
<UL>
<LI><CODE>PointOpImage</CODE> - for image operators that require only a
single source pixel to compute each destination pixel
<P></P></LI></UL>
<UL>
<LI><CODE>SourcelessOpImage</CODE> - for image operators that have no image
sources
<P></P></LI></UL>
<UL>
<LI><CODE>StatisticsOpImage</CODE> - for image operators that compute
statistics on a given region of an image, and with a given sampling rate
<P></P></LI></UL>
<UL>
<LI><CODE>UntiledOpimage</CODE> - for single-source operations in which the
values of all pixels in the source image contribute to the value of each
pixel in the destination image
<P></P></LI></UL>
<UL>
<LI><CODE>WarpOpImage</CODE> - for image operators that perform an image
warp
<P></P></LI></UL>
<UL>
<LI><CODE>ScaleOpImage</CODE> - for extension operators that perform image
scaling requiring rectilinear backwards mapping and padding by the
resampling filter dimensions<CODE></CODE>
<P></P></LI></UL>The <CODE>OpImage</CODE> is able to determine what source
areas are sufficient for the computation of a given area of the destination by
means of a user-supplied <CODE>mapDestRect</CODE> method. For most operations,
this method as well as a suitable implementation of <CODE>getTile</CODE> is
supplied by a standard subclass of <CODE>OpImage</CODE>, such as
<CODE>PointOpImage</CODE> or <CODE>AreaOpImage</CODE>.
<P>An <CODE>OpImage</CODE> is effectively a <CODE>PlanarImage</CODE> that is
defined computationally. In <CODE>PlanarImage</CODE>, the <CODE>getTile</CODE>
method of <CODE>RenderedImage</CODE> is left abstract, and
<CODE>OpImage</CODE> subclasses override it to perform their operation. Since
it may be awkward to produce a tile of output at a time, due to the fact that
source tile boundaries may need to be crossed, the <CODE>OpImage</CODE> class
defines a <CODE>getTile</CODE> method to cobble (copy) source data as needed
and to call a user-supplied <CODE>computeRect</CODE> method. This method then
receives contiguous source <CODE>Rasters</CODE> that are guaranteed to contain
sufficient data to produce the desired results. By calling
<CODE>computeRect</CODE> on subareas of the desired tile, <CODE>OpImage</CODE>
is able to minimize the amount of data that must be cobbled.
<P>A second version of the <CODE>computeRect</CODE> method that is called with
uncobbled sources is available to extenders. This interface is useful for
operations that are implemented using <EM>iterators</EM> (see <A
href="http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Extension.doc.html#51261">Section
14.4, "Iterators</A>"), which abstract away the notion of tile boundaries.
<P><A name=52811>
<H3>3.5.6 <IMG src="Programming in Java Advanced Imaging3.files/space.gif">The
RenderableOp Class</H3></A>The <CODE>RenderableOp</CODE> class provides a
lightweight representation of an operation in the Renderable space (see <A
href="http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Programming-environ.doc.html#55932">Section
3.3.2, "Renderable Graphs</A>"). <CODE>RenderableOp</CODE>s are typically
created using the <CODE>createRenderable</CODE> method of the <CODE>JAI</CODE>
class, and may be edited at will. <CODE>RenderableOp</CODE> implements the
<CODE>RenderableImage</CODE> interface, and so may be queried for its
rendering-independent dimensions.
<P>When a <CODE>RenderableOp</CODE> is to be rendered, it makes use of the
<CODE>OperationRegistry</CODE> (described in <A
href="http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Extension.doc.html#47227">Chapter
14</A>) to locate an appropriate <CODE>ContextualRenderedImageFactory</CODE>
object to perform the conversion from the Renderable space into a
<CODE>RenderedImage</CODE>.
<P><A name=52834>
<H3>3.5.7 <IMG src="Programming in Java Advanced Imaging3.files/space.gif">The
RenderedOp Class</H3></A>The <CODE>RenderedOp</CODE> is a lightweight object
similar to <CODE>RenderableOp</CODE> that stores an operation name,
<CODE>ParameterBlock</CODE>, and <CODE>RenderingHints</CODE>, and can be
joined into a Rendered graph (see <A
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -