|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.media.jai.PlanarImage
javax.media.jai.OpImage
javax.media.jai.GeometricOpImage
it.geosolutions.jaiext.scale.ScaleOpImage
public abstract class ScaleOpImage
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.
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 |
---|
protected float scaleX
protected float scaleY
protected float transX
protected float transY
protected com.sun.media.jai.util.Rational scaleXRational
protected com.sun.media.jai.util.Rational scaleYRational
protected long scaleXRationalNum
protected long scaleXRationalDenom
protected long scaleYRationalNum
protected long scaleYRationalDenom
protected com.sun.media.jai.util.Rational invScaleXRational
protected com.sun.media.jai.util.Rational invScaleYRational
protected long invScaleXRationalNum
protected long invScaleXRationalDenom
protected long invScaleYRationalNum
protected long invScaleYRationalDenom
protected com.sun.media.jai.util.Rational transXRational
protected com.sun.media.jai.util.Rational transYRational
protected long transXRationalNum
protected long transXRationalDenom
protected long transYRationalNum
protected long transYRationalDenom
protected static float rationalTolerance
protected final javax.media.jai.ROI srcROI
protected final javax.media.jai.PlanarImage srcROIImage
protected final javax.media.jai.iterator.RandomIter roiIter
protected final boolean hasROI
protected final Rectangle roiBounds
protected boolean useRoiAccessor
protected long invScaleXInt
protected long invScaleXFrac
protected long invScaleYInt
protected long invScaleYFrac
protected javax.media.jai.Interpolation interpolator
protected boolean isBinary
protected int subsampleBits
protected int one
protected int interp_width
protected int interp_height
protected int interp_left
protected int interp_top
protected int shift
protected int shift2
protected int round2
protected int precisionBits
protected int round
protected int dataType
protected Range noData
protected boolean hasNoData
protected byte destinationNoDataByte
protected short destinationNoDataUShort
protected short destinationNoDataShort
protected int destinationNoDataInt
protected float destinationNoDataFloat
protected double destinationNoDataDouble
protected boolean isNegativeInf
protected boolean isPositiveInf
protected boolean isRangeNaN
protected boolean isNearestNew
protected boolean isBilinearNew
protected boolean isBicubicNew
protected boolean caseA
protected boolean caseB
protected boolean caseC
protected javax.media.jai.RenderedOp srcROIImgExt
protected javax.media.jai.RenderedOp extendedIMG
Constructor Detail |
---|
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)
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.
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.Key
s and
image properties indexed by String
s or CaselessStringKey
s. 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.
IllegalArgumentException
- if source
is null
.
IllegalArgumentException
- if combining the source bounds with the layout parameter results in negative output width or height.Method Detail |
---|
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)
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)
public Point2D mapDestPoint(Point2D destPt, int sourceIndex)
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.
mapDestPoint
in class javax.media.jai.GeometricOpImage
destPt
- the position in destination image coordinates to map to source image coordinates.sourceIndex
- the index of the source image.
Point2D
of the same class as destPt
.
IllegalArgumentException
- if destPt
is null
.
IndexOutOfBoundsException
- if sourceIndex
is non-zero.public Point2D mapSourcePoint(Point2D sourcePt, int sourceIndex)
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.
mapSourcePoint
in class javax.media.jai.GeometricOpImage
sourcePt
- the position in source image coordinates to map to destination image coordinates.sourceIndex
- the index of the source image.
Point2D
of the same class as sourcePt
.
IllegalArgumentException
- if sourcePt
is null
.
IndexOutOfBoundsException
- if sourceIndex
is non-zero.protected Rectangle forwardMapRect(Rectangle sourceRect, int sourceIndex)
Rectangle
of the specified source will be
mapped.
forwardMapRect
in class javax.media.jai.GeometricOpImage
sourceRect
- the Rectangle
in source coordinates.sourceIndex
- the index of the source image.
Rectangle
indicating the destination bounding box, or null
if the bounding box is unknown.
IllegalArgumentException
- if sourceIndex
is negative or greater than the index of the last source.
IllegalArgumentException
- if sourceRect
is null
.protected Rectangle backwardMapRect(Rectangle destRect, int sourceIndex)
Rectangle
of the destination will be
mapped.
backwardMapRect
in class javax.media.jai.GeometricOpImage
destRect
- the Rectangle
in destination coordinates.sourceIndex
- the index of the source image.
Rectangle
indicating the source bounding box, or null
if the bounding box is unknown.
IllegalArgumentException
- if sourceIndex
is negative or greater than the index of the last source.
IllegalArgumentException
- if destRect
is null
.public Raster computeTile(int tileX, int tileY)
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:
computeTile
in class javax.media.jai.GeometricOpImage
tileX
- The X index of the tile.tileY
- The Y index of the tile.
Raster
.public void dispose()
dispose
in class javax.media.jai.OpImage
protected abstract void computeRect(Raster[] sources, WritableRaster dest, Rectangle destRect, Raster[] rois)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |