|
|||||||||
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.OpImage | +--javax.media.jai.GeometricOpImage | +--javax.media.jai.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 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 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
Constructor Detail |
public ScaleOpImage(RenderedImage source, ImageLayout layout, Map configuration, boolean cobbleSources, BorderExtender extender, Interpolation interp, float scaleX, float scaleY, float transX, float transY)
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 |
public int getLeftPadding()
public int getRightPadding()
public int getTopPadding()
public int getBottomPadding()
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 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 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 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 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 GeometricOpImage
tileX
- The X index of the tile.tileY
- The Y index of the tile.Raster
.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |