javax.media.jai
Class AreaOpImage

java.lang.Object
  |
  +--javax.media.jai.PlanarImage
        |
        +--javax.media.jai.OpImage
              |
              +--javax.media.jai.AreaOpImage
All Implemented Interfaces:
ImageJAI, PropertyChangeEmitter, PropertySource, RenderedImage, WritablePropertySource

public abstract class AreaOpImage
extends OpImage

An abstract base class for image operators that require only a fixed rectangular source region around a source pixel in order to compute each destination pixel.

The source and the destination images will occupy the same region of the plane. A given destination pixel (x, y) may be computed from the neighborhood of source pixels beginning at (x - leftPadding, y - topPadding) and extending to (x + rightPadding, y + bottomPadding) inclusive.

Since this operator needs a region around the source pixel in order to compute the destination pixel, the border destination pixels cannot be computed without any source extension. The source extension can be specified by supplying a BorderExtender that will define the pixel values of the source outside the actual source area.

If no extension is specified, the destination samples that cannot be computed will be written in the destination as zero. If the source image begins at pixel (minX, minY) and has width w and height h, the result of performing an area operation will be an image beginning at minX, minY, and having a width of w and a height of h, with the area being computed and written starting at (minX + leftPadding, minY + topPadding) and having width Math.max(w - leftPadding - rightPadding, 0) and height Math.max(h - topPadding - bottomPadding, 0).

A RenderingHints for JAI.KEY_REPLACE_INDEX_COLOR_MODEL with the value of Boolean.TRUE will automatically be added to the given configuration and passed up to the superclass constructor so that area operations are performed on the pixel values instead of being performed on the indices into the color map for those operations whose source(s) have an IndexColorModel. This addition will only take place if a value for the JAI.KEY_REPLACE_INDEX_COLOR_MODEL has not already been provided by the user. Note that the configuration Map is cloned before the new hint is added to it. Regarding the value for the JAI.KEY_REPLACE_INDEX_COLOR_MODEL RenderingHints, the operator itself can be smart based on the parameters, i.e. while the default value for the JAI.KEY_REPLACE_INDEX_COLOR_MODEL is Boolean.TRUE for operations that extend this class, in some cases the operator could set the default.

See Also:
BorderExtender

Field Summary
protected  int bottomPadding
          The number of source pixels needed below the central pixel.
protected  BorderExtender extender
          The BorderExtender, may be null.
protected  int leftPadding
          The number of source pixels needed to the left of the central pixel.
protected  int rightPadding
          The number of source pixels needed to the right of the central pixel.
protected  int topPadding
          The number of source pixels needed above the central pixel.
 
Fields inherited from class javax.media.jai.OpImage
cache, cobbleSources, OP_COMPUTE_BOUND, OP_IO_BOUND, OP_NETWORK_BOUND, tileCacheMetric, tileRecycler
 
Fields inherited from class javax.media.jai.PlanarImage
colorModel, eventManager, height, minX, minY, properties, sampleModel, tileFactory, tileGridXOffset, tileGridYOffset, tileHeight, tileWidth, width
 
Constructor Summary
AreaOpImage(RenderedImage source, ImageLayout layout, Map configuration, boolean cobbleSources, BorderExtender extender, int leftPadding, int rightPadding, int topPadding, int bottomPadding)
          Constructs an AreaOpImage.
 
Method Summary
 Raster computeTile(int tileX, int tileY)
          Computes a tile.
 BorderExtender getBorderExtender()
          Retrieve the BorderExtender object associated with this class instance.
 int getBottomPadding()
          Returns the number of pixels needed below the central pixel.
 int getLeftPadding()
          Returns the number of pixels needed to the left of the central pixel.
 int getRightPadding()
          Returns the number of pixels needed to the right of the central pixel.
 int getTopPadding()
          Returns the number of pixels needed above the central pixel.
 Rectangle mapDestRect(Rectangle destRect, int sourceIndex)
          Returns a conservative estimate of the region of a specified source that is required in order to compute the pixels of a given destination rectangle.
 Rectangle mapSourceRect(Rectangle sourceRect, int sourceIndex)
          Returns a conservative estimate of the destination region that can potentially be affected by the pixels of a rectangle of a given source.
 
Methods inherited from class javax.media.jai.OpImage
addTileToCache, cancelTiles, computeRect, computeRect, computesUniqueTiles, createTile, dispose, getExpandedNumBands, getFormatTags, getOperationComputeType, getTile, getTileCache, getTileCacheMetric, getTileDependencies, getTileFromCache, getTileRecycler, getTiles, hasExtender, mapDestPoint, mapSourcePoint, prefetchTiles, queueTiles, recycleTile, setTileCache, vectorize, vectorize, vectorize
 
Methods inherited from class javax.media.jai.PlanarImage
addPropertyChangeListener, addPropertyChangeListener, addSink, addSink, addSource, addTileComputationListener, copyData, copyData, copyExtendedData, createColorModel, createSnapshot, createWritableRaster, finalize, getAsBufferedImage, getAsBufferedImage, getBounds, getColorModel, getData, getData, getDefaultColorModel, getExtendedData, getGraphics, getHeight, getImageID, getMaxTileX, getMaxTileY, getMaxX, getMaxY, getMinTileX, getMinTileY, getMinX, getMinY, getNumBands, getNumSources, getNumXTiles, getNumYTiles, getProperties, getProperty, getPropertyClass, getPropertyNames, getPropertyNames, getSampleModel, getSinks, getSource, getSourceImage, getSourceObject, getSources, getSplits, getTileComputationListeners, getTileFactory, getTileGridXOffset, getTileGridYOffset, getTileHeight, getTileIndices, getTileRect, getTiles, getTileWidth, getWidth, overlapsMultipleTiles, removeProperty, removePropertyChangeListener, removePropertyChangeListener, removeSink, removeSink, removeSinks, removeSource, removeSources, removeTileComputationListener, setImageLayout, setProperties, setProperty, setSource, setSources, tileXToX, tileXToX, tileYToY, tileYToY, toString, wrapRenderedImage, XToTileX, XToTileX, YToTileY, YToTileY
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

leftPadding

protected int leftPadding
The number of source pixels needed to the left of the central pixel.

rightPadding

protected int rightPadding
The number of source pixels needed to the right of the central pixel.

topPadding

protected int topPadding
The number of source pixels needed above the central pixel.

bottomPadding

protected int bottomPadding
The number of source pixels needed below the central pixel.

extender

protected BorderExtender extender
The BorderExtender, may be null.
Constructor Detail

AreaOpImage

public AreaOpImage(RenderedImage source,
                   ImageLayout layout,
                   Map configuration,
                   boolean cobbleSources,
                   BorderExtender extender,
                   int leftPadding,
                   int rightPadding,
                   int topPadding,
                   int bottomPadding)
Constructs an AreaOpImage. The layout variables are set in the standard way by the OpImage constructor.

Additional control over the image bounds, tile grid layout, SampleModel, and ColorModel may be obtained by specifying an ImageLayout parameter. If the image bounds are specified but do not overlap the source bounds then an IllegalArgumentException will be thrown. This parameter will be passed to the superclass constructor unchanged.

A RenderingHints for JAI.KEY_REPLACE_INDEX_COLOR_MODEL with the value of Boolean.TRUE will automatically be added to the given configuration and passed up to the superclass constructor so that area operations are performed on the pixel values instead of being performed on the indices into the color map for those operations whose source(s) have an IndexColorModel. This addition will only take place if a value for the JAI.KEY_REPLACE_INDEX_COLOR_MODEL has not already been provided by the user. Note that the configuration Map is cloned before the new hint is added to it.

Parameters:
source - A RenderedImage.
layout - An ImageLayout containing the source dimensions before padding, and optionally containing the tile grid layout, SampleModel, and ColorModel.
configuration - Configurable attributes of the image including configuration variables indexed by RenderingHints.Keys and image properties indexed by Strings or CaselessStringKeys. This is simply forwarded to the superclass constructor.
cobbleSources - A boolean indicating whether computeRect() expects contiguous sources.
extender - A BorderExtender, or null.
leftPadding - The desired left padding.
rightPadding - The desired right padding.
topPadding - The desired top padding.
bottomPadding - The desired bottom padding.
Throws:
IllegalArgumentException - if source is null.
IllegalArgumentException - if the user-specified bounds do intersect the source bounds.
Since:
JAI 1.1
Method Detail

getLeftPadding

public int getLeftPadding()
Returns the number of pixels needed to the left of the central pixel.
Returns:
The left padding factor.

getRightPadding

public int getRightPadding()
Returns the number of pixels needed to the right of the central pixel.
Returns:
The right padding factor.

getTopPadding

public int getTopPadding()
Returns the number of pixels needed above the central pixel.
Returns:
The top padding factor.

getBottomPadding

public int getBottomPadding()
Returns the number of pixels needed below the central pixel.
Returns:
The bottom padding factor.

getBorderExtender

public BorderExtender getBorderExtender()
Retrieve the BorderExtender object associated with this class instance. The object is returned by reference.
Returns:
The associated BorderExtender object or null.
Since:
JAI 1.1

mapSourceRect

public Rectangle mapSourceRect(Rectangle sourceRect,
                               int sourceIndex)
Returns a conservative estimate of the destination region that can potentially be affected by the pixels of a rectangle of a given source. The resulting Rectangle is not clipped to the destination image bounds.
Overrides:
mapSourceRect in class OpImage
Parameters:
sourceRect - the Rectangle in source coordinates.
sourceIndex - the index of the source image.
Returns:
a Rectangle indicating the potentially affected destination region, or null if the region is unknown.
Throws:
IllegalArgumentException - if sourceIndex is negative or greater than the index of the last source.
IllegalArgumentException - if sourceRect is null.

mapDestRect

public Rectangle mapDestRect(Rectangle destRect,
                             int sourceIndex)
Returns a conservative estimate of the region of a specified source that is required in order to compute the pixels of a given destination rectangle. The resulting Rectangle is not clipped to the source image bounds.
Overrides:
mapDestRect in class OpImage
Parameters:
destRect - the Rectangle in destination coordinates.
sourceIndex - the index of the source image.
Returns:
a Rectangle indicating the required source region.
Throws:
IllegalArgumentException - if sourceIndex is negative or greater than the index of the last source.
IllegalArgumentException - if destRect is null.

computeTile

public Raster computeTile(int tileX,
                          int tileY)
Computes a tile. If source cobbling was requested at construction time, the source tile boundaries are overlayed onto the destination, cobbling is performed for areas that intersect multiple source tiles, and computeRect(Raster[], WritableRaster, Rectangle) is called for each of the resulting regions. Otherwise, computeRect(PlanarImage[], WritableRaster, Rectangle) is called once to compute the entire active area of the tile.

The image bounds may be larger than the bounds of the source image. In this case, samples for which there are no no corresponding sources are set to zero.

Overrides:
computeTile in class OpImage
Parameters:
tileX - The X index of the tile.
tileY - The Y index of the tile.
Returns:
The tile as a Raster.