The pseudo code for the rescaling operation is as follows:
for each pixel from Source object {
for each band/component of the pixel {
dstElement = (srcElement*scaleFactor) + offset
}
}
For Rasters, rescaling operates on bands. The number of sets of scaling constants may be one, in which case the same constants are applied to all bands, or it must equal the number of Source Raster bands.
For BufferedImages, rescaling operates on color and alpha components. The number of sets of scaling constants may be one, in which case the same constants are applied to all color (but not alpha) components. Otherwise, the number of sets of scaling constants may equal the number of Source color components, in which case no rescaling of the alpha component (if present) is performed. If neither of these cases apply, the number of sets of scaling constants must equal the number of Source color components plus alpha components, in which case all color and alpha components are rescaled.
BufferedImage sources with premultiplied alpha data are treated in the same manner as non-premultiplied images for purposes of rescaling. That is, the rescaling is done per band on the raw data of the BufferedImage source without regard to whether the data is premultiplied. If a color conversion is required to the destination ColorModel, the premultiplied state of both source and destination will be taken into account for this step.
Images with an IndexColorModel cannot be rescaled.
If a RenderingHints object is specified in the constructor, the color rendering hint and the dithering hint may be used when color conversion is required.
Note that in-place operation is allowed (i.e. the source and destination can be the same object).
java.awt.RenderingHints#KEY_COLOR_RENDERING , java.awt.RenderingHints#KEY_DITHERING
| Modifier and Type | Field and Description |
|---|---|
| private int | |
| pack-priv RenderingHints | |
| pack-priv int | |
| pack-priv float[] | |
| pack-priv float[] | |
| private int |
| Access | Constructor and Description |
|---|---|
| public | RescaleOp(float[]
the specified scale factors scaleFactors, float[] the specified offsets offsets, RenderingHints the specified hints)RenderingHints, or
nullConstructs a new RescaleOp with the desired scale factors and offsets. |
| public | RescaleOp(float
the specified scale factor scaleFactor, float the specified offset offset, RenderingHints the specified hints)RenderingHints, or
nullConstructs a new RescaleOp with the desired scale factor and offset. |
| Modifier and Type | Method and Description |
|---|---|
| private boolean | |
| private ByteLookupTable | createByteLut(float[] scale, float[] off, int nBands, int
Number of elements the table is to have.
This will generally be 256 for byte and
65536 for short. nElems)Creates a ByteLookupTable to implement the rescale. |
| public BufferedImage | Returns: the zeroed-destination image.Source image for the filter operation. src, ColorModel ColorModel of the destination. If null, the
ColorModel of the source will be used. destCM)Implements java. Creates a zeroed destination image with the correct size and number of bands. |
| public WritableRaster | Returns: the zeroed-destinationRaster.the source src)RasterImplements java. Creates a zeroed-destination |
| private ShortLookupTable | createShortLut(float[] scale, float[] off, int nBands, int
Number of elements the table is to have.
This will generally be 256 for byte and
65536 for short. nElems)Creates a ShortLookupTable to implement the rescale. |
| public final BufferedImage | Returns: the filteredBufferedImage.the src, BufferedImage BufferedImage to be filteredthe destination for the filtering operation
or dst)nullImplements java. Rescales the source BufferedImage. |
| public final WritableRaster | Returns: the filteredWritableRaster.the src, WritableRaster Raster to be filteredthe destination for the filtering operation
or dst)nullImplements java. Rescales the pixel data in the source Raster. |
| private WritableRaster | |
| public final Rectangle2D | getBounds2D(BufferedImage src)
Implements java. Returns the bounding box of the rescaled destination image. |
| public final Rectangle2D | Returns: the bounds of the specifiedRaster.the rescaled destination src)RasterImplements java. Returns the bounding box of the rescaled destination Raster. |
| public final int | Returns: the number of scaling factors and offsets of thisRescaleOp.Returns the number of scaling factors and offsets used in this RescaleOp. |
| public final float[] | Returns: the offsets of thisRescaleOp.the array to contain the offsets of
this offsets)RescaleOpReturns the offsets in the given array. |
| public final Point2D | Returns: the location of the destination point.a point in the source image srcPt, Point2D the destination point or dstPt)nullImplements java. Returns the location of the destination point given a point in the source. |
| public final RenderingHints | Returns: the rendering hints of thisRescaleOp.Implements java. Returns the rendering hints for this op. |
| public final float[] | Returns: the scale factors of thisRescaleOp.the array to contain the scale factors of
this scaleFactors)RescaleOpReturns the scale factors in the given array. |
| dstNbits | back to summary |
|---|---|
| private int dstNbits | |
| hints | back to summary |
|---|---|
| pack-priv RenderingHints hints | |
| length | back to summary |
|---|---|
| pack-priv int length | |
| offsets | back to summary |
|---|---|
| pack-priv float[] offsets | |
| scaleFactors | back to summary |
|---|---|
| pack-priv float[] scaleFactors | |
| srcNbits | back to summary |
|---|---|
| private int srcNbits | |
| RescaleOp | back to summary |
|---|---|
| public RescaleOp(float[] scaleFactors, float[] offsets, RenderingHints hints) Constructs a new RescaleOp with the desired scale factors and offsets. The length of the scaleFactor and offset arrays must meet the restrictions stated in the class comments above. The RenderingHints argument may be null.
| |
| RescaleOp | back to summary |
|---|---|
| public RescaleOp(float scaleFactor, float offset, RenderingHints hints) Constructs a new RescaleOp with the desired scale factor and offset. The scaleFactor and offset will be applied to all bands in a source Raster and to all color (but not alpha) components in a BufferedImage. The RenderingHints argument may be null.
| |
| canUseLookup | back to summary |
|---|---|
| private boolean canUseLookup(Raster src, Raster dst) Determines if the rescale can be performed as a lookup. The dst must be a byte or short type. The src must be less than 16 bits. All source band sizes must be the same and all dst band sizes must be the same. | |
| createByteLut | back to summary |
|---|---|
| private ByteLookupTable createByteLut(float[] scale, float[] off, int nBands, int nElems) Creates a ByteLookupTable to implement the rescale. The table may have either a SHORT or BYTE input.
| |
| createCompatibleDestImage | back to summary |
|---|---|
| public BufferedImage createCompatibleDestImage(BufferedImage src, ColorModel destCM) Implements java. Creates a zeroed destination image with the correct size and number of bands.
| |
| createCompatibleDestRaster | back to summary |
|---|---|
| public WritableRaster createCompatibleDestRaster(Raster src) Implements java. Creates a zeroed-destination
| |
| createShortLut | back to summary |
|---|---|
| private ShortLookupTable createShortLut(float[] scale, float[] off, int nBands, int nElems) Creates a ShortLookupTable to implement the rescale. The table may have either a SHORT or BYTE input.
| |
| filter | back to summary |
|---|---|
| public final BufferedImage filter(BufferedImage src, BufferedImage dst) Implements java. Rescales the source BufferedImage. If the color model in the source image is not the same as that in the destination image, the pixels will be converted in the destination. If the destination image is null, a BufferedImage will be created with the source ColorModel. An IllegalArgumentException may be thrown if the number of scaling factors/offsets in this object does not meet the restrictions stated in the class comments above, or if the source image has an IndexColorModel.
| |
| filter | back to summary |
|---|---|
| public final WritableRaster filter(Raster src, WritableRaster dst) Implements java. Rescales the pixel data in the source Raster. If the destination Raster is null, a new Raster will be created. The source and destination must have the same number of bands. Otherwise, an IllegalArgumentException is thrown. Note that the number of scaling factors/offsets in this object must meet the restrictions stated in the class comments above. Otherwise, an IllegalArgumentException is thrown.
| |
| filterRasterImpl | back to summary |
|---|---|
| private WritableRaster filterRasterImpl(Raster src, WritableRaster dst, int scaleConst, boolean sCheck) | |
| getBounds2D | back to summary |
|---|---|
| public final Rectangle2D getBounds2D(BufferedImage src) Implements java. Returns the bounding box of the rescaled destination image. Since this is not a geometric operation, the bounding box does not change. | |
| getBounds2D | back to summary |
|---|---|
| public final Rectangle2D getBounds2D(Raster src) Implements java. Returns the bounding box of the rescaled destination Raster. Since this is not a geometric operation, the bounding box does not change.
| |
| getNumFactors | back to summary |
|---|---|
| public final int getNumFactors() Returns the number of scaling factors and offsets used in this RescaleOp.
| |
| getOffsets | back to summary |
|---|---|
| public final float[] getOffsets(float[] offsets) Returns the offsets in the given array. The array is also returned for convenience. If offsets is null, a new array will be allocated.
| |
| getPoint2D | back to summary |
|---|---|
| public final Point2D getPoint2D(Point2D srcPt, Point2D dstPt) Implements java. Returns the location of the destination point given a point in the source. If dstPt is non-null, it will be used to hold the return value. Since this is not a geometric operation, the srcPt will equal the dstPt. | |
| getRenderingHints | back to summary |
|---|---|
| public final RenderingHints getRenderingHints() Implements java. Returns the rendering hints for this op.
| |
| getScaleFactors | back to summary |
|---|---|
| public final float[] getScaleFactors(float[] scaleFactors) Returns the scale factors in the given array. The array is also returned for convenience. If scaleFactors is null, a new array will be allocated.
| |