|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--javax.media.jai.PlanarImage | +--javax.media.jai.TiledImage
A concrete implementation of WritableRenderedImage
.
TiledImage
is the main class for writable images
in JAI. TiledImage
provides a straightforward
implementation of the WritableRenderedImage
interface,
taking advantage of that interface's ability to describe images
with multiple tiles. The tiles of a
WritableRenderedImage
must share a
SampleModel
, which determines their width, height, and
pixel format. The tiles form a regular grid, which may occupy any
rectangular region of the plane. Tile pixels the locations of which
lie outside the stated image bounds have undefined values.
The contents of a TiledImage
are defined by a
single RenderedImage
source provided by means of one of
the set()
methods or to a constructor which accepts a
RenderedImage
. The set()
methods provide
a way to selectively overwrite a portion of a TiledImage
,
possibly using a region of interest (ROI).
TiledImage
also supports direct manipulation of
pixels by means of the getWritableTile()
method. This
method returns a WritableRaster
that can be modified directly.
Such changes become visible to readers according to the regular
thread synchronization rules of the Java virtual machine; JAI makes
no additional guarantees. When a writer is finished modifying a
tile, it should call releaseWritableTile()
. A
shortcut is to call setData()
, which copies a rectangular
region or an area specified by a ROI
from a supplied
Raster
directly into the TiledImage
.
A final way to modify the contents of a TiledImage
is through calls to the object returned by createGraphics()
.
This returns a Graphics2D
object that can be used to draw
line art, text, and images in the usual Abstract Window Toolkit (AWT)
manner.
A TiledImage
does not attempt to maintain
synchronous state on its own. That task is left to
SnapshotImage
. If a synchronous (unchangeable) view
of a TiledImage
is desired, its
createSnapshot()
method must be used. Otherwise,
changes due to calls to set() or direct writing of tiles by objects
that call getWritableTile()
will be visible.
TiledImage
does not actually cause its tiles to be
copied from the specified source until their contents are demanded.
Once a tile has been computed, its contents may be discarded if it can
be determined that it can be recomputed identically from the source.
The lockTile()
method forces a tile to be computed and
maintained for the lifetime of the TiledImage
.
SnapshotImage
,
RenderedImage
,
WritableRenderedImage
Field Summary | |
protected int |
minTileX
The index of the leftmost column of tiles. |
protected int |
minTileY
The index of the uppermost row of tiles. |
protected Vector |
tileObservers
The current set of TileObservers. |
protected WritableRaster[][] |
tiles
The tile array. |
protected int |
tilesX
The number of tiles in the X direction. |
protected int |
tilesY
The number of tiles in the Y direction. |
protected int[][] |
writers
The number of writers of each tile; -1 indicates a locked tile. |
Fields inherited from class javax.media.jai.PlanarImage |
colorModel, eventManager, height, minX, minY, properties, sampleModel, tileFactory, tileGridXOffset, tileGridYOffset, tileHeight, tileWidth, width |
Constructor Summary | |
TiledImage(int minX,
int minY,
int width,
int height,
int tileGridXOffset,
int tileGridYOffset,
SampleModel tileSampleModel,
ColorModel colorModel)
Constructs a TiledImage with a given layout,
SampleModel , and ColorModel . |
|
TiledImage(Point origin,
SampleModel sampleModel,
int tileWidth,
int tileHeight)
Deprecated. as of JAI 1.1. |
|
TiledImage(RenderedImage source,
boolean areBuffersShared)
Constructs a TiledImage equivalent to a given
RenderedImage . |
|
TiledImage(RenderedImage source,
int tileWidth,
int tileHeight)
Constructs a TiledImage equivalent to a given
RenderedImage but with specific tile dimensions. |
|
TiledImage(SampleModel sampleModel,
int tileWidth,
int tileHeight)
Deprecated. as of JAI 1.1. |
Method Summary | |
void |
addTileObserver(TileObserver observer)
Informs this TiledImage that another object is
interested in being notified whenever any tile becomes writable
or ceases to be writable. |
void |
clearTiles()
Sets the tiles array to null so that
the image may be used again. |
static TiledImage |
createBanded(int minX,
int minY,
int width,
int height,
int dataType,
int tileWidth,
int tileHeight,
int[] bankIndices,
int[] bandOffsets)
Deprecated. as of JAI 1.1. |
Graphics2D |
createGraphics()
Creates a Graphics2D object that can be used to
paint text and graphics onto the TiledImage . |
static TiledImage |
createInterleaved(int minX,
int minY,
int width,
int height,
int numBands,
int dataType,
int tileWidth,
int tileHeight,
int[] bandOffsets)
Deprecated. as of JAI 1.1. |
Graphics |
getGraphics()
Deprecated. as of JAI 1.1. |
int |
getSample(int x,
int y,
int b)
Returns the value of a given sample of a pixel as an int . |
double |
getSampleDouble(int x,
int y,
int b)
Returns the value of a given sample of a pixel as a double . |
float |
getSampleFloat(int x,
int y,
int b)
Returns the value of a given sample of a pixel as a float . |
TiledImage |
getSubImage(int[] bandSelect)
Deprecated. as of JAI 1.1. |
TiledImage |
getSubImage(int[] bandSelect,
ColorModel cm)
Returns a TiledImage that shares the tile
Raster s of this image. |
TiledImage |
getSubImage(int x,
int y,
int w,
int h)
Returns a TiledImage that shares the tile
Raster s of this image. |
TiledImage |
getSubImage(int x,
int y,
int w,
int h,
int[] bandSelect)
Deprecated. as of JAI 1.1. |
TiledImage |
getSubImage(int x,
int y,
int w,
int h,
int[] bandSelect,
ColorModel cm)
Returns a TiledImage that shares the tile
Raster s of this image. |
Raster |
getTile(int tileX,
int tileY)
Retrieves a particular tile from the image for reading only. |
WritableRaster |
getWritableTile(int tileX,
int tileY)
Retrieves a particular tile from the image for reading and writing. |
Point[] |
getWritableTileIndices()
Returns a list of tiles that are currently held by one or more writers or null of no tiles are so held. |
boolean |
hasTileWriters()
Returns true if any tile is being held by a
writer, false otherwise. |
protected boolean |
isTileLocked(int tileX,
int tileY)
Returns true if a tile is locked. |
boolean |
isTileWritable(int tileX,
int tileY)
Returns true if a tile has writers. |
protected boolean |
lockTile(int tileX,
int tileY)
Forces a tile to be computed, and its contents stored indefinitely. |
void |
propertyChange(PropertyChangeEvent evt)
Implementation of PropertyChangeListener . |
void |
releaseWritableTile(int tileX,
int tileY)
Indicates that a writer is done updating a tile. |
void |
removeTileObserver(TileObserver observer)
Informs this TiledImage that a particular TileObserver no
longer wishes to receive updates on tile writability status. |
void |
set(RenderedImage im)
Overlays a given RenderedImage on top of the
current contents of the TiledImage . |
void |
set(RenderedImage im,
ROI roi)
Overlays a given RenderedImage on top of the
current contents of the TiledImage and its
intersection with the supplied ROI. |
void |
setData(Raster r)
Sets a region of a TiledImage to be a copy of a
supplied Raster . |
void |
setData(Raster r,
ROI roi)
Sets a region of a TiledImage to be a copy of a
supplied Raster . |
void |
setSample(int x,
int y,
int b,
double s)
Sets a sample of a pixel to a given double value. |
void |
setSample(int x,
int y,
int b,
float s)
Sets a sample of a pixel to a given float value. |
void |
setSample(int x,
int y,
int b,
int s)
Sets a sample of a pixel to a given int value. |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.awt.image.RenderedImage |
copyData, getColorModel, getData, getData, getHeight, getMinTileX, getMinTileY, getMinX, getMinY, getNumXTiles, getNumYTiles, getProperty, getPropertyNames, getSampleModel, getSources, getTileGridXOffset, getTileGridYOffset, getTileHeight, getTileWidth, getWidth |
Field Detail |
protected int tilesX
protected int tilesY
protected int minTileX
protected int minTileY
protected WritableRaster[][] tiles
protected int[][] writers
protected Vector tileObservers
Constructor Detail |
public TiledImage(int minX, int minY, int width, int height, int tileGridXOffset, int tileGridYOffset, SampleModel tileSampleModel, ColorModel colorModel)
TiledImage
with a given layout,
SampleModel
, and ColorModel
. The
width and height of the image tiles will be respectively equal
to the width and height of the SampleModel
. The
tileFactory
instance variable will be set to the
value of the JAI.KEY_TILE_FACTORY
hint set on
the default instance of JAI
.minX
- The X coordinate of the upper-left pixelminY
- The Y coordinate of the upper-left pixel.width
- The width of the image.height
- The height of the image.tileGridXOffset
- The X coordinate of the upper-left
pixel of tile (0, 0).tileGridYOffset
- The Y coordinate of the upper-left
pixel of tile (0, 0).tileSampleModel
- A SampleModel
with which to be
compatible.colorModel
- A ColorModel
to associate with the
image.public TiledImage(Point origin, SampleModel sampleModel, int tileWidth, int tileHeight)
TiledImage
with a
SampleModel
that is compatible with a given
SampleModel
, and given tile dimensions. The width
and height are taken from the SampleModel
, and the
image begins at a specified point. The ColorModel
will be derived from the SampleModel
using the
createColorModel
method of PlanarImage
.
Note that this implies that the ColorModel
could be
null
.origin
- A Point
indicating the image's upper
left corner.sampleModel
- A SampleModel
with which to be
compatible.tileWidth
- The desired tile width.tileHeight
- The desired tile height.public TiledImage(SampleModel sampleModel, int tileWidth, int tileHeight)
TiledImage
starting at the global
coordinate origin. The ColorModel
will be derived from the SampleModel
using the
createColorModel
method of PlanarImage
.
Note that this implies that the ColorModel
could be
null
.sampleModel
- A SampleModel
with which to be
compatible.tileWidth
- The desired tile width.tileHeight
- The desired tile height.public TiledImage(RenderedImage source, int tileWidth, int tileHeight)
TiledImage
equivalent to a given
RenderedImage
but with specific tile dimensions.
Actual copying of the pixel data from the RenderedImage
will be deferred until the first time they are requested from the
TiledImage
.source
- The source RenderedImage
.tileWidth
- The desired tile width.tileHeight
- The desired tile height.public TiledImage(RenderedImage source, boolean areBuffersShared)
TiledImage
equivalent to a given
RenderedImage
. Actual copying of the pixel data from
the RenderedImage
will be deferred until the first time
they are requested from the TiledImage
. The tiles of
the TiledImage
may optionally share
DataBuffer
s with the tiles of the source image but it
should be realized in this case that data written into the
TiledImage
will be visible in the source image.source
- The source RenderedImage
.areBuffersShared
- Whether the tile DataBuffer
s
of the source are re-used in the tiles of
this image. If false
new
WritableRaster
s will be
created.Method Detail |
public static TiledImage createInterleaved(int minX, int minY, int width, int height, int numBands, int dataType, int tileWidth, int tileHeight, int[] bandOffsets)
TiledImage
making use of an
interleaved SampleModel
with a given layout,
number of bands, and data type. The ColorModel
will be derived from the SampleModel
using the
createColorModel
method of PlanarImage
.
Note that this implies that the ColorModel
could be
null
.minX
- The X coordinate of the upper-left pixelminY
- The Y coordinate of the upper-left pixel.width
- The width of the image.height
- The height of the image.numBands
- The number of bands in the image.dataType
- The data type, from among the constants
DataBuffer.TYPE_*
.tileWidth
- The tile width.tileHeight
- The tile height.bandOffsets
- An array of non-duplicated integers between 0 and
numBands - 1
of length numBands
indicating the relative offset of each band.public static TiledImage createBanded(int minX, int minY, int width, int height, int dataType, int tileWidth, int tileHeight, int[] bankIndices, int[] bandOffsets)
TiledImage
making use of an
banded SampleModel
with a given layout,
number of bands, and data type. The ColorModel
will be derived from the SampleModel
using the
createColorModel
method of PlanarImage
.
Note that this implies that the ColorModel
could be
null
.minX
- The X coordinate of the upper-left pixelminY
- The Y coordinate of the upper-left pixel.width
- The width of the image.height
- The height of the image.dataType
- The data type, from among the constants
DataBuffer.TYPE_*
.tileWidth
- The tile width.tileHeight
- The tile height.bankIndices
- An array of int
s indicating the
index of the bank to use for each band. Bank indices
may be duplicated.bandOffsets
- An array of integers indicating the starting
offset of each band within its bank. Bands stored in
the same bank must have sufficiently different offsets
so as not to overlap.public void set(RenderedImage im)
RenderedImage
on top of the
current contents of the TiledImage
. The source
image must have a SampleModel
compatible with that
of this image. If the source image does not overlap this image
then invoking this method will have no effect.
The source image is added as a fallback PropertySource
for the TiledImage
: if a given property is not set directly
on the TiledImage
an attempt will be made to obtain its
value from the source image.
im
- A RenderedImage
source to overlay.IllegalArgumentException
- if im
is
null
.public void set(RenderedImage im, ROI roi)
RenderedImage
on top of the
current contents of the TiledImage
and its
intersection with the supplied ROI. The source
image must have a SampleModel
compatible with that
of this image. If the source image and the region of interest
do not both overlap this image then invoking this method will
have no effect.
The source image is added as a fallback PropertySource
for the TiledImage
: if a given property is not set directly
on the TiledImage
an attempt will be made to obtain its
value from the source image.
im
- A RenderedImage
source to overlay.roi
- The region of interest.IllegalArgumentException
- either parameter is
null
.public Graphics getGraphics()
Graphics
object that can be used to
paint text and graphics onto the TiledImage
.
The TiledImage
must be of integral data type
or an UnsupportedOperationException
will be thrown.getGraphics
in class PlanarImage
public Graphics2D createGraphics()
Graphics2D
object that can be used to
paint text and graphics onto the TiledImage
.
The TiledImage
must be of integral data type
or an UnsupportedOperationException
will be thrown.public TiledImage getSubImage(int x, int y, int w, int h, int[] bandSelect, ColorModel cm)
TiledImage
that shares the tile
Raster
s of this image. The returned image
occupies a sub-area of the parent image, and possesses a
possibly permuted subset of the parent's bands. The two images
share a common coordinate system.
The image bounds are clipped against the bounds of the parent image.
If the specified ColorModel
is null
then the ColorModel
of the sub-image will be set to
null
unless bandSelect
is either
null
or equal in length to the number of bands in the
image in which cases the sub-image ColorModel
will be
set to that of the current image.
x
- the minimum X coordinate of the subimage.y
- the minimum Y coordinate of the subimage.w
- the width of the subimage.h
- the height of the subimage.bandSelect
- an array of band indices; if null,
all bands are selected.cm
- the ColorModel
of the sub-image.null
if either
the specified rectangular area or its intersection with
the current image is empty.public TiledImage getSubImage(int x, int y, int w, int h, int[] bandSelect)
TiledImage
that shares the tile
Raster
s of this image. The returned image
occupies a sub-area of the parent image, and possesses a
possibly permuted subset of the parent's bands. The two images
share a common coordinate system. The ColorModel
will be derived from the sub-image SampleModel
using the
createColorModel
method of PlanarImage
.
Note that this implies that the ColorModel
could be
null
.
The image bounds are clipped against the bounds of the parent image.
x
- the minimum X coordinate of the subimage.y
- the minimum Y coordinate of the subimage.w
- the width of the subimage.h
- the height of the subimage.bandSelect
- an array of band indices; if null,
all bands are selected.null
if either
the specified rectangular area or its intersection with
the current image is empty.public TiledImage getSubImage(int x, int y, int w, int h)
TiledImage
that shares the tile
Raster
s of this image. The returned image
occupies a subarea of the parent image. The two images share a
common coordinate system.
The image bounds are clipped against the bounds of the parent image.
x
- the minimum X coordinate of the subimage.y
- the minimum Y coordinate of the subimage.w
- the width of the subimage.h
- the height of the subimage.public TiledImage getSubImage(int[] bandSelect, ColorModel cm)
TiledImage
that shares the tile
Raster
s of this image.
If the specified ColorModel
is null
then the ColorModel
of the sub-image will be set to
null
unless bandSelect
is equal in length
to the number of bands in the image in which cases the sub-image
ColorModel
will be set to that of the current image.
bandSelect
- an array of band indices.cm
- the ColorModel
of the sub-image.IllegalArgumentException
- is bandSelect
is null
.public TiledImage getSubImage(int[] bandSelect)
TiledImage
that shares the tile
Raster
s of this image. The returned image
occupies the same area as the parent image, and possesses a
possibly permuted subset of the parent's bands. The
ColorModel
will be derived from the sub-image
SampleModel
using the createColorModel
method of PlanarImage
. Note that this implies that
the ColorModel
could be null
.bandSelect
- an array of band indices.public Raster getTile(int tileX, int tileY)
getTile
in interface RenderedImage
getTile
in class PlanarImage
tileX
- the X index of the tile.tileY
- the Y index of the tile.public WritableRaster getWritableTile(int tileX, int tileY)
getWritableTile
in interface WritableRenderedImage
tileX
- the X index of the tile.tileY
- the Y index of the tile.public void releaseWritableTile(int tileX, int tileY)
releaseWritableTile
in interface WritableRenderedImage
tileX
- the X index of the tile.tileY
- the Y index of the tile.protected boolean lockTile(int tileX, int tileY)
tileX
- the X index of the tile.tileY
- the Y index of the tile.protected boolean isTileLocked(int tileX, int tileY)
true
if a tile is locked.tileX
- the X index of the tile.tileY
- the Y index of the tile.public void setData(Raster r)
TiledImage
to be a copy of a
supplied Raster
. The Raster
's
coordinate system is used to position it within the image.
The computation of all overlapping tiles will be forced prior
to modification of the data of the affected area.setData
in interface WritableRenderedImage
r
- a Raster
containing pixels to be copied
into the TiledImage
.public void setData(Raster r, ROI roi)
TiledImage
to be a copy of a
supplied Raster
. The Raster
's
coordinate system is used to position it within the image.
The computation of all overlapping tiles will be forced prior
to modification of the data of the affected area.r
- a Raster
containing pixels to be copied
into the TiledImage
.roi
- The region of interest.public void addTileObserver(TileObserver observer)
TiledImage
that another object is
interested in being notified whenever any tile becomes writable
or ceases to be writable. A tile becomes writable when it is
not currently writable and getWritableTile()
is
called. A tile ceases to be writable when
releaseTile()
is called and the number of calls to
getWritableTile()
and
releaseWritableTile()
are identical.
It is the responsibility of the TiledImage
to
inform all registered TileObserver
objects of such
changes in tile writability before the writer has a chance to
make any modifications.
addTileObserver
in interface WritableRenderedImage
observer
- An object implementing the
TileObserver
interface.public void removeTileObserver(TileObserver observer)
TiledImage
that a particular TileObserver no
longer wishes to receive updates on tile writability status.
The result of attempting to remove a listener that is not
registered is undefined.removeTileObserver
in interface WritableRenderedImage
observer
- An object implementing the
TileObserver
interface.public Point[] getWritableTileIndices()
null
of no tiles are so held.getWritableTileIndices
in interface WritableRenderedImage
Point
s representing tile indices
or null
.public boolean hasTileWriters()
true
if any tile is being held by a
writer, false
otherwise. This provides a quick
way to check whether it is necessary to make copies of tiles --
if there are no writers, it is safe to use the tiles directly,
while registering to learn of future writers.hasTileWriters
in interface WritableRenderedImage
public boolean isTileWritable(int tileX, int tileY)
true
if a tile has writers.isTileWritable
in interface WritableRenderedImage
tileX
- the X index of the tile.tileY
- the Y index of the tile.public void clearTiles()
tiles
array to null
so that
the image may be used again.IllegalStateException
- if hasTileWriters()
returns true
.public void setSample(int x, int y, int b, int s)
int
value.x
- The X coordinate of the pixel.y
- The Y coordinate of the pixel.b
- The band of the sample within the pixel.s
- The value to which to set the sample.public int getSample(int x, int y, int b)
int
.x
- The X coordinate of the pixel.y
- The Y coordinate of the pixel.b
- The band of the sample within the pixel.public void setSample(int x, int y, int b, float s)
float
value.x
- The X coordinate of the pixel.y
- The Y coordinate of the pixel.b
- The band of the sample within the pixel.s
- The value to which to set the sample.public float getSampleFloat(int x, int y, int b)
float
.x
- The X coordinate of the pixel.y
- The Y coordinate of the pixel.b
- The band of the sample within the pixel.public void setSample(int x, int y, int b, double s)
double
value.x
- The X coordinate of the pixel.y
- The Y coordinate of the pixel.b
- The band of the sample within the pixel.s
- The value to which to set the sample.public double getSampleDouble(int x, int y, int b)
double
.x
- The X coordinate of the pixel.y
- The Y coordinate of the pixel.b
- The band of the sample within the pixel.public void propertyChange(PropertyChangeEvent evt)
PropertyChangeListener
.
When invoked with an event emitted by the source image specified
for this TiledImage
and the event is either a
PropertyChangeEventJAI
named "InvalidRegion"
(case-insensitive) or a RenderingChangeEvent
, then
all tiles which overlap the intersection of the invalid region and the
region of interest specified for this image (if any) will
be cleared. If the event is a RenderingChangeEvent
then
the invalid region will be obtained from the getInvalidRegion
method of the event object; if a PropertyChangeEventJAI
it will be obtained from the getNewValue()
method.
In either case, a new PropertyChangeEventJAI
will be
fired to all registered listeners of the property name
"InvalidRegion" and to all known sinks which are
PropertyChangeListener
s. Its old and new values will
contain the previous and current invalid regions. This may be used to
determine which tiles must be re-requested. The
TiledImage
itself will not re-request the data.
propertyChange
in interface PropertyChangeListener
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |