it.geosolutions.jaiext.scale
Class ScaleDescriptor

java.lang.Object
  extended by javax.media.jai.OperationDescriptorImpl
      extended by it.geosolutions.jaiext.scale.ScaleDescriptor
All Implemented Interfaces:
Serializable, javax.media.jai.OperationDescriptor, javax.media.jai.RegistryElementDescriptor

public class ScaleDescriptor
extends javax.media.jai.OperationDescriptorImpl

An OperationDescriptor describing the "Scale" operation.

The "Scale" operation translates and resizes an image. For each pixel (x, y) of the destination, the source value at the fractional subpixel position ((x - xTrans)/xScale, (y - yTrans)/yScale) is constructed by means of an Interpolation object and written to the destination.

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 Border Extension is specified, the source will not be extended. The scaled image size is still calculated according to the formula specified above. However since there isn't 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 not be written.

Specifying a scale factor of greater than 1 increases the size of the image, specifying a scale factor between 0 and 1 (non-inclusive) decreases the size of an image. An IllegalArgumentException will be thrown if the specified scale factors are negative or equal to zero.

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 this operation automatically adds a value of Boolean.TRUE for the JAI.KEY_REPLACE_INDEX_COLOR_MODEL to the given configuration so that the operation is performed on the pixel values instead of being performed on the indices into the color map if the 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. The operation can be smart about the value of the JAI.KEY_REPLACE_INDEX_COLOR_MODEL RenderingHints, i.e. while the default value for the JAI.KEY_REPLACE_INDEX_COLOR_MODEL is Boolean.TRUE, in some cases the operator could set the default.

"Scale" defines a PropertyGenerator that performs an identical transformation on the "ROI" property of the source image, which can be retrieved by calling the getProperty method with "ROI" as the property name.

This new version of the "Scale" operation adds the ROI support and No Data support for every image type and even for Binary images. This extension becames possible with 3 new Interpolation extensions, each of them is an evolution of the classic interpolation method: InterpolationNearest, InterpolationBilinear, InterpolationBicubic. The No Data Range used must be defined inside the interpolator, at the interpolator creation time, while the ROI support is handled inside the ScaleGeneralOpImage.

Resource List
Name Value
GlobalName ScaleNoData
LocalName ScaleNoData
Vendor it.geosolutions.jaiext.roiaware
Description Resizes an image.
DocURL See this URL for the official description http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/ScaleDescriptor.html
Version 1.0
arg0Desc The X scale factor.
arg1Desc The Y scale factor.
arg2Desc The X translation.
arg3Desc The Y translation.
arg4Desc The interpolation method for resampling.

Parameter List
Name Class Type Default Value
xScale java.lang.Float 1.0F
yScale java.lang.Float 1.0F
xTrans java.lang.Float 0.0F
yTrans java.lang.Float 0.0F
interpolation javax.media.jai.Interpolation Null(An Interpolation Object must be defined)
ROI ROI null
useROIAccessorBoolean False

See Also:
Interpolation, BorderExtender, OperationDescriptor, Serialized Form

Field Summary
 
Fields inherited from class javax.media.jai.OperationDescriptorImpl
sourceNames, supportedModes
 
Fields inherited from interface javax.media.jai.OperationDescriptor
NO_PARAMETER_DEFAULT
 
Constructor Summary
ScaleDescriptor()
          Constructor.
 
Method Summary
static javax.media.jai.RenderedOp create(RenderedImage source0, Float xScale, Float yScale, Float xTrans, Float yTrans, javax.media.jai.Interpolation interpolation, javax.media.jai.ROI roi, Boolean useRoiAccessor, RenderingHints hints)
          Resizes an image.
static javax.media.jai.RenderableOp createRenderable(RenderableImage source0, Float xScale, Float yScale, Float xTrans, Float yTrans, javax.media.jai.Interpolation interpolation, javax.media.jai.ROI roi, RenderingHints hints)
          Resizes an image.
 Number getParamMinValue(int index)
          Returns the minimum legal value of a specified numeric parameter for this operation.
 javax.media.jai.PropertyGenerator[] getPropertyGenerators()
          Returns an array of PropertyGenerators implementing property inheritance for the "Scale" operation.
 boolean isRenderableSupported()
          Returns false since renderable operation is supported but never tested.
protected  boolean validateParameters(ParameterBlock args, StringBuffer msg)
          Validates the input parameters.
 
Methods inherited from class javax.media.jai.OperationDescriptorImpl
arePropertiesSupported, getDefaultSourceClass, getDestClass, getDestClass, getInvalidRegion, getName, getNumParameters, getNumSources, getParamClasses, getParamDefaults, getParamDefaultValue, getParameterListDescriptor, getParamMaxValue, getParamNames, getPropertyGenerators, getRenderableDestClass, getRenderableSourceClasses, getResourceBundle, getResources, getSourceClasses, getSourceClasses, getSourceNames, getSupportedModes, isImmediate, isModeSupported, isRenderedSupported, makeDefaultSourceClassList, validateArguments, validateArguments, validateParameters, validateRenderableArguments, validateRenderableSources, validateSources, validateSources
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScaleDescriptor

public ScaleDescriptor()
Constructor.

Method Detail

isRenderableSupported

public boolean isRenderableSupported()
Returns false since renderable operation is supported but never tested.

Specified by:
isRenderableSupported in interface javax.media.jai.OperationDescriptor
Overrides:
isRenderableSupported in class javax.media.jai.OperationDescriptorImpl

getPropertyGenerators

public javax.media.jai.PropertyGenerator[] getPropertyGenerators()
Returns an array of PropertyGenerators implementing property inheritance for the "Scale" operation.

Specified by:
getPropertyGenerators in interface javax.media.jai.OperationDescriptor
Overrides:
getPropertyGenerators in class javax.media.jai.OperationDescriptorImpl
Returns:
An array of property generators.

validateParameters

protected boolean validateParameters(ParameterBlock args,
                                     StringBuffer msg)
Validates the input parameters.

In addition to the standard checks performed by the superclass method, this method checks that "xScale" and "yScale" are both greater than 0.

Overrides:
validateParameters in class javax.media.jai.OperationDescriptorImpl

getParamMinValue

public Number getParamMinValue(int index)
Returns the minimum legal value of a specified numeric parameter for this operation.

For the minimum value of "xScale" and "yScale", this method returns 0. However, the scale factors must be a positive floating number and can not be 0.

Specified by:
getParamMinValue in interface javax.media.jai.OperationDescriptor
Overrides:
getParamMinValue in class javax.media.jai.OperationDescriptorImpl

create

public static javax.media.jai.RenderedOp create(RenderedImage source0,
                                                Float xScale,
                                                Float yScale,
                                                Float xTrans,
                                                Float yTrans,
                                                javax.media.jai.Interpolation interpolation,
                                                javax.media.jai.ROI roi,
                                                Boolean useRoiAccessor,
                                                RenderingHints hints)
Resizes an image.

Creates a ParameterBlockJAI from all supplied arguments except hints and invokes JAI.create(String,ParameterBlock,RenderingHints).

Parameters:
source0 - RenderedImage source 0.
xScale - The X scale factor. May be null.
yScale - The Y scale factor. May be null.
xTrans - The X translation. May be null.
yTrans - The Y translation. May be null.
interpolation - The interpolation method for resampling. May be null.
hints - The RenderingHints to use. May be null.
Returns:
The RenderedOp destination.
Throws:
IllegalArgumentException - if source0 is null.
See Also:
JAI, ParameterBlockJAI, RenderedOp

createRenderable

public static javax.media.jai.RenderableOp createRenderable(RenderableImage source0,
                                                            Float xScale,
                                                            Float yScale,
                                                            Float xTrans,
                                                            Float yTrans,
                                                            javax.media.jai.Interpolation interpolation,
                                                            javax.media.jai.ROI roi,
                                                            RenderingHints hints)
Resizes an image.

Creates a ParameterBlockJAI from all supplied arguments except hints and invokes JAI.createRenderable(String,ParameterBlock,RenderingHints).

Parameters:
source0 - RenderableImage source 0.
xScale - The X scale factor. May be null.
yScale - The Y scale factor. May be null.
xTrans - The X translation. May be null.
yTrans - The Y translation. May be null.
interpolation - The interpolation method for resampling. May be null.
hints - The RenderingHints to use. May be null.
Returns:
The RenderableOp destination.
Throws:
IllegalArgumentException - if source0 is null.
See Also:
JAI, ParameterBlockJAI, RenderableOp


Copyright © 2006–2014 GeoSolutions. All rights reserved.