javax.media.jai
Class ScaleOpImage

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

public abstract class ScaleOpImage
extends GeometricOpImage

A class extending WarpOpImage for use by further extension classes that perform image scaling. Image scaling operations require rectilinear backwards mapping and padding by the resampling filter dimensions.

When applying scale factors of scaleX, scaleY to a source image with the upper left pixel at (srcMinX, srcMinY) and width of srcWidth and height of srcHeight, the resulting image is defined to have the following bounds: dstMinX = ceil(A), where A = srcMinX * scaleX - 0.5 + transX, dstMinY = ceil(B), where B = srcMinY * scaleY - 0.5 + transY, dstMaxX = ceil(C), where C = (srcMaxX + 1) * scaleX - 1.5 + transX and srcMaxX = srcMinX + srcWidth - 1 dstMaxY = ceil(D), where D = (srcMaxY + 1) * scaleY - 1.5 + transY and srcMaxY = srcMinY + srcHeight - 1 dstWidth = dstMaxX - dstMinX + 1 dstHeight = dstMaxY - dstMinY + 1

In the case where source's upper left pixel is located is (0, 0), the formulae simplify to dstMinX = 0 dstMinY = 0 dstWidth = ceil (srcWidth * scaleX - 0.5 + transX) dstHeight = ceil (srcHeight * scaleY - 0.5 + transY)

In the case where the source's upper left pixel is located at (0, 0) and the scaling factors are integers, the formulae further simplify to dstMinX = 0 dstMinY = 0 dstWidth = ceil (srcWidth * scaleX + transX) dstWidth = ceil (srcHeight * scaleY + transY)

When interpolations which require padding the source such as Bilinear or Bicubic interpolation are specified, the source needs to be extended such that it has the extra pixels needed to compute all the destination pixels. This extension is performed via the BorderExtender class. The type of border extension can be specified as a RenderingHint to the JAI.create method.

If no BorderExtender is specified, the source will not be extended. The scaled image size is still calculated according to the formula specified above. However since there is not enough source to compute all the destination pixels, only that subset of the destination image's pixels which can be computed, will be written in the destination. The rest of the destination will be set to zeros.

It may be noted that the minX, minY, width and height hints as specified through the JAI.KEY_IMAGE_LAYOUT hint in the RenderingHints object are not honored, as this operator calculates the destination image bounds itself. The other ImageLayout hints, like tileWidth and tileHeight, however are honored. It should be noted that the superclass GeometricOpImage automatically adds a value of Boolean.TRUE for the JAI.KEY_REPLACE_INDEX_COLOR_MODEL to the given configuration and passes it up to its superclass constructor so that geometric 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 take place only 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:
WarpOpImage, OpImage

Field Summary
protected  com.sun.media.jai.util.Rational invScaleXRational
           
protected  long invScaleXRationalDenom
           
protected  long invScaleXRationalNum
           
protected  com.sun.media.jai.util.Rational invScaleYRational
           
protected  long invScaleYRationalDenom
           
protected  long invScaleYRationalNum
           
protected static float rationalTolerance
           
protected  float scaleX
          The horizontal scale factor.
protected  com.sun.media.jai.util.Rational scaleXRational
          Rational representations
protected  long scaleXRationalDenom
           
protected  long scaleXRationalNum
           
protected  float scaleY
          The vertical scale factor.
protected  com.sun.media.jai.util.Rational scaleYRational
          Rational representations
protected  long scaleYRationalDenom
           
protected  long scaleYRationalNum
           
protected  float transX
          Thee horizontal translation factor
protected  com.sun.media.jai.util.Rational transXRational
           
protected  long transXRationalDenom
           
protected  long transXRationalNum
           
protected  float transY
          The vertical translation factor
protected  com.sun.media.jai.util.Rational transYRational
           
protected  long transYRationalDenom
           
protected  long transYRationalNum
           
 
Fields inherited from class javax.media.jai.GeometricOpImage
backgroundValues, computableBounds, extender, intBackgroundValues, interp, setBackground
 
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
ScaleOpImage(RenderedImage source, ImageLayout layout, Map configuration, boolean cobbleSources, BorderExtender extender, Interpolation interp, float scaleX, float scaleY, float transX, float transY)
          Constructs a ScaleOpImage from a RenderedImage source, an optional BorderExtender, x and y scale and translation factors, and an Interpolation object.
 
Method Summary
protected  Rectangle backwardMapRect(Rectangle destRect, int sourceIndex)
          Returns the minimum bounding box of the region of the specified source to which a particular Rectangle of the destination will be mapped.
 Raster computeTile(int tileX, int tileY)
          Computes a tile.
protected  Rectangle forwardMapRect(Rectangle sourceRect, int sourceIndex)
          Returns the minimum bounding box of the region of the destination to which a particular Rectangle of the specified source will be mapped.
 int getBottomPadding()
          Deprecated. as of JAI 1.1.
 int getLeftPadding()
          Deprecated. as of JAI 1.1.
 int getRightPadding()
          Deprecated. as of JAI 1.1.
 int getTopPadding()
          Deprecated. as of JAI 1.1.
 Point2D mapDestPoint(Point2D destPt, int sourceIndex)
          Computes the position in the specified source that best matches the supplied destination image position.
 Point2D mapSourcePoint(Point2D sourcePt, int sourceIndex)
          Computes the position in the destination that best matches the supplied source image position.
 
Methods inherited from class javax.media.jai.GeometricOpImage
getBorderExtender, getInterpolation, mapDestRect, mapSourceRect
 
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, 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

scaleX

protected float scaleX
The horizontal scale factor.

scaleY

protected float scaleY
The vertical scale factor.

transX

protected float transX
Thee horizontal translation factor

transY

protected float transY
The vertical translation factor

scaleXRational

protected com.sun.media.jai.util.Rational scaleXRational
Rational representations

scaleYRational

protected com.sun.media.jai.util.Rational scaleYRational
Rational representations

scaleXRationalNum

protected long scaleXRationalNum

scaleXRationalDenom

protected long scaleXRationalDenom

scaleYRationalNum

protected long scaleYRationalNum

scaleYRationalDenom

protected long scaleYRationalDenom

invScaleXRational

protected com.sun.media.jai.util.Rational invScaleXRational

invScaleYRational

protected com.sun.media.jai.util.Rational invScaleYRational

invScaleXRationalNum

protected long invScaleXRationalNum

invScaleXRationalDenom

protected long invScaleXRationalDenom

invScaleYRationalNum

protected long invScaleYRationalNum

invScaleYRationalDenom

protected long invScaleYRationalDenom

transXRational

protected com.sun.media.jai.util.Rational transXRational

transYRational

protected com.sun.media.jai.util.Rational transYRational

transXRationalNum

protected long transXRationalNum

transXRationalDenom

protected long transXRationalDenom

transYRationalNum

protected long transYRationalNum

transYRationalDenom

protected long transYRationalDenom

rationalTolerance

protected static float rationalTolerance
Constructor Detail

ScaleOpImage

public ScaleOpImage(RenderedImage source,
                    ImageLayout layout,
                    Map configuration,
                    boolean cobbleSources,
                    BorderExtender extender,
                    Interpolation interp,
                    float scaleX,
                    float scaleY,
                    float transX,
                    float transY)
Constructs a ScaleOpImage from a RenderedImage source, an optional BorderExtender, x and y scale and translation factors, and an Interpolation object. The image dimensions are determined by forward-mapping the source bounds, and are passed to the superclass constructor by means of the layout parameter. Other fields of the layout are passed through unchanged. If layout is null, a new ImageLayout will be constructor to hold the bounds information. Note that the scale factors are represented internally as Rational numbers in order to workaround inexact device specific representation of floating point numbers. For instance the floating point number 1.2 is internally represented as 1.200001, which can throw the calculations off during a forward/backward map.

The Rational approximation is valid upto the sixth decimal place.

Parameters:
layout - an ImageLayout optionally containing the tile grid layout, SampleModel, and ColorModel, or null.
source - a RenderedImage.
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.
interp - an Interpolation object to use for resampling.
scaleX - scale factor along x axis.
scaleY - scale factor along y axis.
transX - translation factor along x axis.
transY - translation factor along y axis.
Throws:
IllegalArgumentException - if source is null.
IllegalArgumentException - if combining the source bounds with the layout parameter results in negative output width or height.
Since:
JAI 1.1
Method Detail

getLeftPadding

public int getLeftPadding()
Deprecated. as of JAI 1.1.

Returns the number of samples required to the left of the center.
Returns:
The left padding factor.

getRightPadding

public int getRightPadding()
Deprecated. as of JAI 1.1.

Returns the number of samples required to the right of the center.
Returns:
The right padding factor.

getTopPadding

public int getTopPadding()
Deprecated. as of JAI 1.1.

Returns the number of samples required above the center.
Returns:
The top padding factor.

getBottomPadding

public int getBottomPadding()
Deprecated. as of JAI 1.1.

Returns the number of samples required below the center.
Returns:
The bottom padding factor.

mapDestPoint

public Point2D mapDestPoint(Point2D destPt,
                            int sourceIndex)
Computes the position in the specified source that best matches the supplied destination image position.

The implementation in this class returns the value of pt in the following code snippet:

 Point2D pt = (Point2D)destPt.clone();
 pt.setLocation((destPt.getX() - transX + 0.5)/scaleX - 0.5,
                (destPt.getY() - transY + 0.5)/scaleY - 0.5);
 
Subclasses requiring different behavior should override this method.

Overrides:
mapDestPoint in class GeometricOpImage
Parameters:
destPt - the position in destination image coordinates to map to source image coordinates.
sourceIndex - the index of the source image.
Returns:
a Point2D of the same class as destPt.
Throws:
IllegalArgumentException - if destPt is null.
IndexOutOfBoundsException - if sourceIndex is non-zero.
Since:
JAI 1.1.2

mapSourcePoint

public Point2D mapSourcePoint(Point2D sourcePt,
                              int sourceIndex)
Computes the position in the destination that best matches the supplied source image position.

The implementation in this class returns the value of pt in the following code snippet:

 Point2D pt = (Point2D)sourcePt.clone();
 pt.setLocation(scaleX*(sourcePt.getX() + 0.5) + transX - 0.5,
                scaleY*(sourcePt.getY() + 0.5) + transY - 0.5);
 
Subclasses requiring different behavior should override this method.

Overrides:
mapSourcePoint in class GeometricOpImage
Parameters:
sourcePt - the position in source image coordinates to map to destination image coordinates.
sourceIndex - the index of the source image.
Returns:
a Point2D of the same class as sourcePt.
Throws:
IllegalArgumentException - if sourcePt is null.
IndexOutOfBoundsException - if sourceIndex is non-zero.
Since:
JAI 1.1.2

forwardMapRect

protected Rectangle forwardMapRect(Rectangle sourceRect,
                                   int sourceIndex)
Returns the minimum bounding box of the region of the destination to which a particular Rectangle of the specified source will be mapped.
Overrides:
forwardMapRect in class GeometricOpImage
Parameters:
sourceRect - the Rectangle in source coordinates.
sourceIndex - the index of the source image.
Returns:
a Rectangle indicating the destination bounding box, or null if the bounding box is unknown.
Throws:
IllegalArgumentException - if sourceIndex is negative or greater than the index of the last source.
IllegalArgumentException - if sourceRect is null.
Since:
JAI 1.1

backwardMapRect

protected Rectangle backwardMapRect(Rectangle destRect,
                                    int sourceIndex)
Returns the minimum bounding box of the region of the specified source to which a particular Rectangle of the destination will be mapped.
Overrides:
backwardMapRect in class GeometricOpImage
Parameters:
destRect - the Rectangle in destination coordinates.
sourceIndex - the index of the source image.
Returns:
a Rectangle indicating the source bounding box, or null if the bounding box is unknown.
Throws:
IllegalArgumentException - if sourceIndex is negative or greater than the index of the last source.
IllegalArgumentException - if destRect is null.
Since:
JAI 1.1

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 corresponding sources are set to zero.

The following steps are performed in order to compute the tile:

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