it.geosolutions.jaiext.scale
Class ScaleOpImage

java.lang.Object
  extended by javax.media.jai.PlanarImage
      extended by javax.media.jai.OpImage
          extended by javax.media.jai.GeometricOpImage
              extended by it.geosolutions.jaiext.scale.ScaleOpImage
All Implemented Interfaces:
RenderedImage, javax.media.jai.ImageJAI, javax.media.jai.PropertyChangeEmitter, javax.media.jai.PropertySource, javax.media.jai.WritablePropertySource
Direct Known Subclasses:
ScaleBicubicOpImage, ScaleBilinearOpImage, ScaleGeneralOpImage, ScaleNearestOpImage, ScaleNearestOpImage2, ScaleNearestOpImage3

public abstract class ScaleOpImage
extends javax.media.jai.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  boolean caseA
          Boolean indicating if No Data and ROI are not used
protected  boolean caseB
          Boolean indicating if only the ROI is used
protected  boolean caseC
          Boolean indicating if only the No Data are used
protected  int dataType
          Image dataType
protected  byte destinationNoDataByte
          Destination value for No Data byte
protected  double destinationNoDataDouble
          Destination value for No Data double
protected  float destinationNoDataFloat
          Destination value for No Data float
protected  int destinationNoDataInt
          Destination value for No Data int
protected  short destinationNoDataShort
          Destination value for No Data short
protected  short destinationNoDataUShort
          Destination value for No Data ushort
protected  javax.media.jai.RenderedOp extendedIMG
          Extended source Image
protected  boolean hasNoData
          Boolean for checking if no data range is present
protected  boolean hasROI
          Boolean indicating if a ROI object is used
protected  int interp_height
          Interpolation kernel heigth
protected  int interp_left
          Interpolation kernel left padding
protected  int interp_top
          Interpolation kernel top padding
protected  int interp_width
          Interpolation kernel width
protected  javax.media.jai.Interpolation interpolator
          Interpolator provided to the Scale operator
protected  long invScaleXFrac
          Inverse scale fractional value X
protected  long invScaleXInt
          Inverse scale value X
protected  com.sun.media.jai.util.Rational invScaleXRational
           
protected  long invScaleXRationalDenom
           
protected  long invScaleXRationalNum
           
protected  long invScaleYFrac
          Inverse scale fractional value Y
protected  long invScaleYInt
          Inverse scale value Y
protected  com.sun.media.jai.util.Rational invScaleYRational
           
protected  long invScaleYRationalDenom
           
protected  long invScaleYRationalNum
           
protected  boolean isBicubicNew
          Boolean for checking if the interpolator is Bicubic
protected  boolean isBilinearNew
          Boolean for checking if the interpolator is Bilinear
protected  boolean isBinary
          Boolean for checking if the image is binary or not
protected  boolean isNearestNew
          Boolean for checking if the interpolator is Nearest
protected  boolean isNegativeInf
          Boolean for checking if the no data is negative infinity
protected  boolean isPositiveInf
          Boolean for checking if the no data is positive infinity
protected  boolean isRangeNaN
          Boolean for checking if the no data is NaN
protected  Range noData
          No Data Range
protected  int one
          Value used for calculating the fractional part of the y position
protected  int precisionBits
          Precision bits used for bicubic interpolation
protected static float rationalTolerance
           
protected  Rectangle roiBounds
          Rectangle containing ROI bounds
protected  javax.media.jai.iterator.RandomIter roiIter
          Random Iterator used iterating on the ROI data
protected  int round
          The value of 0.5 scaled by 2^precisionBits
protected  int round2
          The value of 0.5 scaled by 2^subsampleBits
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  int shift
          Value used for calculating the bilinear interpolation for integer dataTypes
protected  int shift2
          Value used for calculating the bilinear interpolation
protected  javax.media.jai.ROI srcROI
          Source ROI
protected  javax.media.jai.PlanarImage srcROIImage
          ROI image
protected  javax.media.jai.RenderedOp srcROIImgExt
          Extended ROI image
protected  int subsampleBits
          Subsample bits used for binary and bicubic interpolation
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
           
protected  boolean useRoiAccessor
          Value indicating if roi RasterAccessor should be used on computations
 
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, javax.media.jai.ImageLayout layout, Map configuration, boolean cobbleSources, javax.media.jai.BorderExtender extender, javax.media.jai.Interpolation interp, float scaleX, float scaleY, float transX, float transY, boolean useRoiAccessor)
          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.
protected abstract  void computeRect(Raster[] sources, WritableRaster dest, Rectangle destRect, Raster[] rois)
           
 Raster computeTile(int tileX, int tileY)
          Computes a tile.
 void dispose()
           
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.
 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.
protected  void preComputePositionsFloat(Rectangle destRect, int srcRectX, int srcRectY, int srcPixelStride, int srcScanlineStride, int[] xpos, int[] ypos, float[] xfracvalues, float[] yfracvalues, int roiScanlineStride, int[] yposRoi)
           
protected  void preComputePositionsInt(Rectangle destRect, int srcRectX, int srcRectY, int srcPixelStride, int srcScanlineStride, int[] xpos, int[] ypos, int[] xfracvalues, int[] yfracvalues, int roiScanlineStride, int[] yposRoi)
           
 
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, 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

srcROI

protected final javax.media.jai.ROI srcROI
Source ROI


srcROIImage

protected final javax.media.jai.PlanarImage srcROIImage
ROI image


roiIter

protected final javax.media.jai.iterator.RandomIter roiIter
Random Iterator used iterating on the ROI data


hasROI

protected final boolean hasROI
Boolean indicating if a ROI object is used


roiBounds

protected final Rectangle roiBounds
Rectangle containing ROI bounds


useRoiAccessor

protected boolean useRoiAccessor
Value indicating if roi RasterAccessor should be used on computations


invScaleXInt

protected long invScaleXInt
Inverse scale value X


invScaleXFrac

protected long invScaleXFrac
Inverse scale fractional value X


invScaleYInt

protected long invScaleYInt
Inverse scale value Y


invScaleYFrac

protected long invScaleYFrac
Inverse scale fractional value Y


interpolator

protected javax.media.jai.Interpolation interpolator
Interpolator provided to the Scale operator


isBinary

protected boolean isBinary
Boolean for checking if the image is binary or not


subsampleBits

protected int subsampleBits
Subsample bits used for binary and bicubic interpolation


one

protected int one
Value used for calculating the fractional part of the y position


interp_width

protected int interp_width
Interpolation kernel width


interp_height

protected int interp_height
Interpolation kernel heigth


interp_left

protected int interp_left
Interpolation kernel left padding


interp_top

protected int interp_top
Interpolation kernel top padding


shift

protected int shift
Value used for calculating the bilinear interpolation for integer dataTypes


shift2

protected int shift2
Value used for calculating the bilinear interpolation


round2

protected int round2
The value of 0.5 scaled by 2^subsampleBits


precisionBits

protected int precisionBits
Precision bits used for bicubic interpolation


round

protected int round
The value of 0.5 scaled by 2^precisionBits


dataType

protected int dataType
Image dataType


noData

protected Range noData
No Data Range


hasNoData

protected boolean hasNoData
Boolean for checking if no data range is present


destinationNoDataByte

protected byte destinationNoDataByte
Destination value for No Data byte


destinationNoDataUShort

protected short destinationNoDataUShort
Destination value for No Data ushort


destinationNoDataShort

protected short destinationNoDataShort
Destination value for No Data short


destinationNoDataInt

protected int destinationNoDataInt
Destination value for No Data int


destinationNoDataFloat

protected float destinationNoDataFloat
Destination value for No Data float


destinationNoDataDouble

protected double destinationNoDataDouble
Destination value for No Data double


isNegativeInf

protected boolean isNegativeInf
Boolean for checking if the no data is negative infinity


isPositiveInf

protected boolean isPositiveInf
Boolean for checking if the no data is positive infinity


isRangeNaN

protected boolean isRangeNaN
Boolean for checking if the no data is NaN


isNearestNew

protected boolean isNearestNew
Boolean for checking if the interpolator is Nearest


isBilinearNew

protected boolean isBilinearNew
Boolean for checking if the interpolator is Bilinear


isBicubicNew

protected boolean isBicubicNew
Boolean for checking if the interpolator is Bicubic


caseA

protected boolean caseA
Boolean indicating if No Data and ROI are not used


caseB

protected boolean caseB
Boolean indicating if only the ROI is used


caseC

protected boolean caseC
Boolean indicating if only the No Data are used


srcROIImgExt

protected javax.media.jai.RenderedOp srcROIImgExt
Extended ROI image


extendedIMG

protected javax.media.jai.RenderedOp extendedIMG
Extended source Image

Constructor Detail

ScaleOpImage

public ScaleOpImage(RenderedImage source,
                    javax.media.jai.ImageLayout layout,
                    Map configuration,
                    boolean cobbleSources,
                    javax.media.jai.BorderExtender extender,
                    javax.media.jai.Interpolation interp,
                    float scaleX,
                    float scaleY,
                    float transX,
                    float transY,
                    boolean useRoiAccessor)
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

preComputePositionsInt

protected final void preComputePositionsInt(Rectangle destRect,
                                            int srcRectX,
                                            int srcRectY,
                                            int srcPixelStride,
                                            int srcScanlineStride,
                                            int[] xpos,
                                            int[] ypos,
                                            int[] xfracvalues,
                                            int[] yfracvalues,
                                            int roiScanlineStride,
                                            int[] yposRoi)

preComputePositionsFloat

protected final void preComputePositionsFloat(Rectangle destRect,
                                              int srcRectX,
                                              int srcRectY,
                                              int srcPixelStride,
                                              int srcScanlineStride,
                                              int[] xpos,
                                              int[] ypos,
                                              float[] xfracvalues,
                                              float[] yfracvalues,
                                              int roiScanlineStride,
                                              int[] yposRoi)

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 javax.media.jai.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 javax.media.jai.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.

Specified by:
forwardMapRect in class javax.media.jai.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.

Specified by:
backwardMapRect in class javax.media.jai.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 javax.media.jai.GeometricOpImage
Parameters:
tileX - The X index of the tile.
tileY - The Y index of the tile.
Returns:
The tile as a Raster.

dispose

public void dispose()
Overrides:
dispose in class javax.media.jai.OpImage

computeRect

protected abstract void computeRect(Raster[] sources,
                                    WritableRaster dest,
                                    Rectangle destRect,
                                    Raster[] rois)


Copyright © 2006–2015 GeoSolutions. All rights reserved.