Java Code Examples for java.awt.image.renderable.ParameterBlock.getIntParameter()

The following are Jave code examples for showing how to use getIntParameter() of the java.awt.image.renderable.ParameterBlock class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: rastertheque   File: HistogramRIF.java   Source Code and License Vote up 7 votes
/**
 * Creates a new instance of <code>HistogramOpImage</code>
 * in the rendered layer. Any image layout information in
 * <code>RenderingHints</code> is ignored.
 * This method satisfies the implementation of RIF.
 */
public RenderedImage create(ParameterBlock args,
                            RenderingHints hints) {
    RenderedImage src = args.getRenderedSource(0);

    int xStart = src.getMinX();	// default values
    int yStart = src.getMinY();

    int maxWidth = src.getWidth();
    int maxHeight = src.getHeight();

    ROI roi = (ROI)args.getObjectParameter(0);
    int xPeriod = args.getIntParameter(1);
    int yPeriod = args.getIntParameter(2);
    int[] numBins = (int[])args.getObjectParameter(3);
    double[] lowValue = (double[])args.getObjectParameter(4);
    double[] highValue = (double[])args.getObjectParameter(5);

    HistogramOpImage op = null;
    try {
        op = new HistogramOpImage(src,
                                  roi,
                                  xStart, yStart,
                                  xPeriod, yPeriod,
                                  numBins, lowValue, highValue);
    } catch (Exception e) {
        ImagingListener listener = ImageUtil.getImagingListener(hints);
        String message = JaiI18N.getString("HistogramRIF0");
        listener.errorOccurred(message, e, this, false);
    }

    return op;
}
 
Example 2
Project: rastertheque   File: MeanRIF.java   Source Code and License Vote up 6 votes
/**
 * Creates a new instance of <code>MeanOpImage</code>
 * in the rendered layer. Any image layout information in
 * <code>RenderingHints</code> is ignored.
 * This method satisfies the implementation of RIF.
 */
public RenderedImage create(ParameterBlock paramBlock,
                            RenderingHints renderHints) {
    RenderedImage src = paramBlock.getRenderedSource(0);

    int xStart = src.getMinX();		// default values
    int yStart = src.getMinY();

    int maxWidth = src.getWidth();
    int maxHeight = src.getHeight();

    return new MeanOpImage(src,
                           (ROI)paramBlock.getObjectParameter(0),
                           xStart, yStart,
                           paramBlock.getIntParameter(1),
                           paramBlock.getIntParameter(2));
}
 
Example 3
Project: rastertheque   File: ExtremaRIF.java   Source Code and License Vote up 6 votes
/**
 * Creates a new instance of <code>ExtremaOpImage</code>
 * in the rendered layer. Any image layout information in
 * <code>RenderingHints</code> is ignored.
 * This method satisfies the implementation of RIF.
 */
public RenderedImage create(ParameterBlock paramBlock,
                            RenderingHints hints) {
    RenderedImage src = paramBlock.getRenderedSource(0);

    int xStart = src.getMinX();		// default values
    int yStart = src.getMinY();

    int maxWidth = src.getWidth();
    int maxHeight = src.getHeight();

    return new ExtremaOpImage(src,
                              (ROI)paramBlock.getObjectParameter(0),
                              xStart, yStart,
                              paramBlock.getIntParameter(1),
                              paramBlock.getIntParameter(2),
                              ((Boolean)paramBlock.getObjectParameter(3)).booleanValue(),
                              paramBlock.getIntParameter(4));
}
 
Example 4
Project: rastertheque   File: PeriodicShiftCRIF.java   Source Code and License Vote up 6 votes
/**
 * Creates a new instance of <code>PeriodicShiftOpImage</code>
 * in the rendered layer. This method satisfies the
 * implementation of RIF.
 */
public RenderedImage create(ParameterBlock paramBlock,
                            RenderingHints renderHints) {
    // Get ImageLayout from renderHints if any.
    ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);
    
    
    // Get the source image.
    RenderedImage source = paramBlock.getRenderedSource(0);

    // Get the translation parameters.
    int shiftX = paramBlock.getIntParameter(0);
    int shiftY = paramBlock.getIntParameter(1);

    // Return the OpImage.
    return new PeriodicShiftOpImage(source, renderHints, layout, shiftX, shiftY);
}
 
Example 5
Project: rastertheque   File: PatternRIF.java   Source Code and License Vote up 5 votes
/**
 * Creates a new instance of PatternOpImage in the rendered layer.
 * This method satisfies the implementation of RIF.
 */
public RenderedImage create(ParameterBlock paramBlock,
                            RenderingHints renderHints) {
    // Get ImageLayout from renderHints if any.
    ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);
    
    int minX = 0;
    int minY = 0;

    if (layout != null) {
        if (layout.isValid(ImageLayout.MIN_X_MASK)) {
            minX = layout.getMinX(null);
        }
        if (layout.isValid(ImageLayout.MIN_Y_MASK)) {
            minY = layout.getMinY(null);
        }
    }

    RenderedImage source = (RenderedImage)paramBlock.getSource(0);
    Raster pattern = source.getData();
    ColorModel colorModel = source.getColorModel();
 
    // Get image width and height from the parameter block
    int width = paramBlock.getIntParameter(0);
    int height = paramBlock.getIntParameter(1);

    return new PatternOpImage(pattern, colorModel,
                              minX, minY, width, height);
}
 
Example 6
Project: rastertheque   File: BoxFilterRIF.java   Source Code and License Vote up 5 votes
/**
 * Create a new instance of SeparableConvolveOpImage in the rendered layer.
 * This method satisfies the implementation of RIF.
 *
 * @param paramBlock  The source image and the convolution kernel.
 */
public RenderedImage create(ParameterBlock paramBlock,
                            RenderingHints renderHints) {
    // Get ImageLayout from renderHints if any.
    ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);
    

    // Get BorderExtender from renderHints if any.
    BorderExtender extender = RIFUtil.getBorderExtenderHint(renderHints);

    // Get the operation parameters.
    int width = paramBlock.getIntParameter(0);
    int height = paramBlock.getIntParameter(1);
    int xOrigin = paramBlock.getIntParameter(2);
    int yOrigin = paramBlock.getIntParameter(3);

    // Allocate and initialize arrays.
    float[] dataH = new float[width];
    Arrays.fill(dataH, 1.0F/(float)width);
    float[] dataV = null;
    if(height == width) {
        dataV = dataH;
    } else {
        dataV = new float[height];
        Arrays.fill(dataV, 1.0F/(float)height);
    }

    // Construct a separable kernel.
    KernelJAI kernel = new KernelJAI(width, height, xOrigin, yOrigin,
                                     dataH, dataV);

    // Construct and return the OpImage.
    return new SeparableConvolveOpImage(paramBlock.getRenderedSource(0),
                                        extender,
                                        renderHints,
                                        layout,
                                        kernel);
}
 
Example 7
Project: rastertheque   File: FilteredSubsampleRIF.java   Source Code and License Vote up 5 votes
/**
    * <p> Creates a new instance of SubsampleOpImage in the rendered layer.
    * This method satisfies the implementation of RIF.
    *
    * @param paramBlock  The source image, the X and Y scale factors.
    * @param renderHints RenderingHints.
    */
   public RenderedImage create(ParameterBlock paramBlock,
                               RenderingHints renderHints) {
       RenderedImage source = paramBlock.getRenderedSource(0);

       BorderExtender extender = renderHints == null ? null :
           (BorderExtender)renderHints.get(JAI.KEY_BORDER_EXTENDER);
       ImageLayout layout = renderHints == null ? null :
           (ImageLayout)renderHints.get(JAI.KEY_IMAGE_LAYOUT);

       int scaleX = paramBlock.getIntParameter(0);
       int scaleY = paramBlock.getIntParameter(1);
       float [] qsFilter = (float [])paramBlock.getObjectParameter(2);
       Interpolation interp = (Interpolation)paramBlock.getObjectParameter(3);

       // check if binary and interpolation type allowed
SampleModel sm = source.getSampleModel();
       int dataType = sm.getDataType();

       // Determine the interpolation type, if not supported throw exception
boolean validInterp = (interp instanceof InterpolationNearest)  ||
                             (interp instanceof InterpolationBilinear) ||
                             (interp instanceof InterpolationBicubic)  ||
                             (interp instanceof InterpolationBicubic2);

       if (!validInterp)
           throw new IllegalArgumentException(
        JaiI18N.getString("FilteredSubsample3"));

       return new FilteredSubsampleOpImage(source, extender, (Map)renderHints, layout,
                                   scaleX, scaleY, qsFilter, interp);
   }
 
Example 8
Project: rastertheque   File: BorderRIF.java   Source Code and License Vote up 5 votes
/**
 * Creates a new instance of <code>BorderOpImage</code>
 * in the rendered layer.
 *
 * @param args   The source image and the border information
 * @param hints  Optionally contains destination image layout.
 */
public RenderedImage create(ParameterBlock args,
                            RenderingHints renderHints) {
    // Get ImageLayout from renderHints if any.
    ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);
    

    RenderedImage source = args.getRenderedSource(0);
    int leftPad = args.getIntParameter(0);
    int rightPad = args.getIntParameter(1);
    int topPad = args.getIntParameter(2);
    int bottomPad = args.getIntParameter(3);
    BorderExtender type =
        (BorderExtender)args.getObjectParameter(4);

    if (type ==
        BorderExtender.createInstance(BorderExtender.BORDER_WRAP)) {
        int minX = source.getMinX() - leftPad;
        int minY = source.getMinY() - topPad;
        int width = source.getWidth() + leftPad + rightPad;
        int height = source.getHeight() + topPad + bottomPad;

        return new PatternOpImage(source.getData(),
                                  source.getColorModel(),
                                  minX, minY,
                                  width, height);
    } else {
        return new BorderOpImage(source, renderHints, layout,
                                 leftPad, rightPad, topPad, bottomPad,
                                 type);
    }
}
 
Example 9
Project: rastertheque   File: ColorQuantizerRIF.java   Source Code and License Vote up 5 votes
/**
    * <p> Creates a new instance of ColorQuantizerOpImage in the
    * rendered layer.  This method satisfies the implementation of RIF.
    *
    * @param paramBlock  The source image, the color quantization algorithm
    *                    name, the maximum number of colors, the
    *                    parameter for training (the histogram size for
    *                    median-cut, the cycle for neuquant, and maximum tree
    *                    size for oct-tree), and the ROI.
    * @param renderHints RenderingHints.
    */
   public RenderedImage create(ParameterBlock paramBlock,
                               RenderingHints renderHints) {
       RenderedImage source = paramBlock.getRenderedSource(0);

       ImageLayout layout = renderHints == null ? null :
           (ImageLayout)renderHints.get(JAI.KEY_IMAGE_LAYOUT);

       ColorQuantizerType algorithm =
           (ColorQuantizerType)paramBlock.getObjectParameter(0);
       int maxColorNum = paramBlock.getIntParameter(1);
       int upperBound = paramBlock.getIntParameter(2);
       ROI roi= (ROI)paramBlock.getObjectParameter(3);
       int xPeriod = paramBlock.getIntParameter(4);
       int yPeriod = paramBlock.getIntParameter(5);

       // check if 3-band byte-type image
SampleModel sm = source.getSampleModel();
       if (sm.getNumBands() != 3  && sm.getDataType() == DataBuffer.TYPE_BYTE)
           throw new IllegalArgumentException("ColorQuantizerRIF0");

       if (algorithm.equals(ColorQuantizerDescriptor.NEUQUANT))
           return new NeuQuantOpImage(source, (Map)renderHints, layout,
                                       maxColorNum, upperBound, roi,
                                       xPeriod, yPeriod);

       if (algorithm.equals(ColorQuantizerDescriptor.OCTTREE))
           return new OctTreeOpImage(source, (Map)renderHints, layout,
                                       maxColorNum, upperBound, roi,
                                       xPeriod, yPeriod);
       else
           return new MedianCutOpImage(source, (Map)renderHints, layout,
                                       maxColorNum, upperBound, roi,
                                       xPeriod, yPeriod);

   }
 
Example 10
Project: rastertheque   File: PeriodicShiftDescriptor.java   Source Code and License Vote up 5 votes
/**
    * Validates the input parameters.
    *
    * <p> In addition to the standard checks performed by the
    * superclass method, this method checks that "shiftX" and
    * "shiftY" are between 0 and the source image width and
    * height, respectively.
    */
   public boolean validateArguments(String modeName,
			     ParameterBlock args,
                                    StringBuffer msg) {
       if (!super.validateArguments(modeName, args, msg)) {
           return false;
       }

if (!modeName.equalsIgnoreCase("rendered"))
    return true;

       RenderedImage src = args.getRenderedSource(0);

       // Set non-static default values based on source
       if (args.getObjectParameter(0) == null) {
           args.set(new Integer(src.getWidth()/2), 0);
       }
       if (args.getObjectParameter(1) == null) {
           args.set(new Integer(src.getHeight()/2), 1);
       }

       int shiftX = args.getIntParameter(0);
       int shiftY = args.getIntParameter(1);
       if (shiftX < 0 || shiftX >= src.getWidth() || 
           shiftY < 0 || shiftY >= src.getHeight()) {
           msg.append(getName() + " " +
                      JaiI18N.getString("PeriodicShiftDescriptor3"));
           return false;
       }

       return true;
   }
 
Example 11
Project: rastertheque   File: MinFilterRIF.java   Source Code and License Vote up 4 votes
/**
 * Create a new instance of MinFilterOpImage in the rendered layer.
 * This method satisfies the implementation of RIF.
 *
 * @param paramBlock  The source image and the convolution kernel.
 */
public RenderedImage create(ParameterBlock paramBlock,
                            RenderingHints renderHints) {
    // Get ImageLayout from renderHints if any.
    ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);
    

    // Get BorderExtender from renderHints if any.
    BorderExtender extender = RIFUtil.getBorderExtenderHint(renderHints);

    MinFilterShape maskType =
        (MinFilterShape)paramBlock.getObjectParameter(0);
    int maskSize = paramBlock.getIntParameter(1);
    RenderedImage ri = paramBlock.getRenderedSource(0);
    
    if(maskType.equals(MinFilterDescriptor.MIN_MASK_SQUARE)) {
       return new MinFilterSquareOpImage(ri,
                                         extender,
                                         renderHints,
                                         layout,
                                         maskSize);
    } else if(maskType.equals(MinFilterDescriptor.MIN_MASK_PLUS)) {
       return new MinFilterPlusOpImage(ri,
                                       extender,
                                       renderHints,
                                       layout,
                                       maskSize);
    } else if(maskType.equals(MinFilterDescriptor.MIN_MASK_X)) {
       return new MinFilterXOpImage(ri,
                                    extender,
                                    renderHints,
                                    layout,
                                    maskSize);
    } else if(maskType.equals(MinFilterDescriptor.MIN_MASK_SQUARE_SEPARABLE)) {
       return new MinFilterSeparableOpImage(ri,
                                            extender,
                                            renderHints,
                                            layout,
                                            maskSize);
    }
    return null;
}
 
Example 12
Project: rastertheque   File: MedianFilterRIF.java   Source Code and License Vote up 4 votes
/**
 * Create a new instance of MedianFilterOpImage in the rendered layer.
 * This method satisfies the implementation of RIF.
 *
 * @param paramBlock  The source image and the convolution kernel.
 */
public RenderedImage create(ParameterBlock paramBlock,
                            RenderingHints renderHints) {
    // Get ImageLayout from renderHints if any.
    ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);
    

    // Get BorderExtender from renderHints if any.
    BorderExtender extender = RIFUtil.getBorderExtenderHint(renderHints);

    MedianFilterShape maskType =
        (MedianFilterShape)paramBlock.getObjectParameter(0);
    int maskSize = paramBlock.getIntParameter(1);
    RenderedImage ri = paramBlock.getRenderedSource(0);
    
    if(maskType.equals(MedianFilterDescriptor.MEDIAN_MASK_SQUARE)) {
       return new MedianFilterSquareOpImage(ri,
                                         extender,
                                         renderHints,
                                         layout,
                                         maskSize);
    } else if(maskType.equals(MedianFilterDescriptor.MEDIAN_MASK_PLUS)) {
       return new MedianFilterPlusOpImage(ri,
                                       extender,
                                       renderHints,
                                       layout,
                                       maskSize);
    } else if(maskType.equals(MedianFilterDescriptor.MEDIAN_MASK_X)) {
       return new MedianFilterXOpImage(ri,
                                    extender,
                                    renderHints,
                                    layout,
                                    maskSize);
    } else if(maskType.equals(MedianFilterDescriptor.MEDIAN_MASK_SQUARE_SEPARABLE)) {
       return new MedianFilterSeparableOpImage(ri,
                                            extender,
                                            renderHints,
                                            layout,
                                            maskSize);
    }
    return null;
}
 
Example 13
Project: rastertheque   File: RenderableCRIF.java   Source Code and License Vote up 4 votes
/**
 * Creates a RenderableImage pyramid from the source and parameters.
 * If the down sampler operation chain does not decrease both the
 * width and height at a given level an IllegalArgumentException will
 * be thrown.
 *
 * @param paramBlock The ParameterBlock containing a single RenderedImage
 * source and parameters sufficient to create an image pyramid.
 */
private RenderableImage createRenderable(ParameterBlock paramBlock) {
    // Create the Hashtable "just in time".
    if(mresTable == null) {
        mresTable = new Hashtable();
    }

    // Check for a SoftReference hashed on a ParameterBlock-derived key.
    Object key = getKey(paramBlock);
    SoftReference ref = (SoftReference)mresTable.get(key);

    // Retrieve the image from the SoftReference if possible.
    RenderableImage mres = null;
    if(ref != null && (mres = (RenderableImage)ref.get()) == null) {
        // null referent: remove the ParameterBlock key from the Hashtable.
        mresTable.remove(key);
    }

    // Derive the image if necessary.
    if(mres == null) {
        // Retrieve the source and parameters.
        RenderedImage source = paramBlock.getRenderedSource(0);
        RenderedOp downSampler =
            (RenderedOp)paramBlock.getObjectParameter(0);
        int maxLowResDim = paramBlock.getIntParameter(1);
        float minX = paramBlock.getFloatParameter(2);
        float minY = paramBlock.getFloatParameter(3);
        float height = paramBlock.getFloatParameter(4);

        // Create an image pyramid.
        ImageMIPMap pyramid = new ImageMIPMap(source, downSampler);

        // Create a Vector of RenderedImages from the pyramid.
        Vector sourceVector = new Vector();
        RenderedImage currentImage = pyramid.getCurrentImage();
        sourceVector.add(currentImage);
        while(currentImage.getWidth() > maxLowResDim ||
              currentImage.getHeight() > maxLowResDim) {
            RenderedImage nextImage = pyramid.getDownImage();
            if(nextImage.getWidth() >= currentImage.getWidth() ||
               nextImage.getHeight() >= currentImage.getHeight()) {
                throw new IllegalArgumentException(JaiI18N.getString("RenderableCRIF0"));
            }
            sourceVector.add(nextImage);
            currentImage = nextImage;
        }

        // Create a RenderableImage
        mres = new MultiResolutionRenderableImage(sourceVector,
                                                  minX, minY, height);

        // Store a SoftReference to the RenderableImage in the Hashtable.
        mresTable.put(key, new SoftReference(mres));
    }

    return mres;
}
 
Example 14
Project: rastertheque   File: MaxFilterRIF.java   Source Code and License Vote up 4 votes
/**
 * Create a new instance of MaxFilterOpImage in the rendered layer.
 * This method satisfies the implementation of RIF.
 *
 * @param paramBlock  The source image and the convolution kernel.
 */
public RenderedImage create(ParameterBlock paramBlock,
                            RenderingHints renderHints) {
    // Get ImageLayout from renderHints if any.
    ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);
    

    // Get BorderExtender from renderHints if any.
    BorderExtender extender = RIFUtil.getBorderExtenderHint(renderHints);

    MaxFilterShape maskType =
        (MaxFilterShape)paramBlock.getObjectParameter(0);
    int maskSize = paramBlock.getIntParameter(1);
    RenderedImage ri = paramBlock.getRenderedSource(0);
    
    if(maskType.equals(MaxFilterDescriptor.MAX_MASK_SQUARE)) {
       return new MaxFilterSquareOpImage(ri,
                                         extender,
                                         renderHints,
                                         layout,
                                         maskSize);
    } else if(maskType.equals(MaxFilterDescriptor.MAX_MASK_PLUS)) {
       return new MaxFilterPlusOpImage(ri,
                                       extender,
                                       renderHints,
                                       layout,
                                       maskSize);
    } else if(maskType.equals(MaxFilterDescriptor.MAX_MASK_X)) {
       return new MaxFilterXOpImage(ri,
                                    extender,
                                    renderHints,
                                    layout,
                                    maskSize);
    } else if(maskType.equals(MaxFilterDescriptor.MAX_MASK_SQUARE_SEPARABLE)) {
       return new MaxFilterSeparableOpImage(ri,
                                            extender,
                                            renderHints,
                                            layout,
                                            maskSize);
    }
    return null;
}
 
Example 15
Project: rastertheque   File: ImageFunctionRIF.java   Source Code and License Vote up 4 votes
/**
 * Creates a new instance of ImageFunctionOpImage in the rendered layer.
 * This method satisfies the implementation of RIF.
 *
 * @param paramBlock  The source image, the X and Y scale factor,
 *                    and the interpolation method for resampling.
 */
public RenderedImage create(ParameterBlock paramBlock,
                            RenderingHints renderHints) {
    // Get ImageLayout from renderHints if any.
    ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);
    

    ImageFunction function =
        (ImageFunction)paramBlock.getObjectParameter(0);

    // Ascertain that a supplied SampleModel has the requisite
    // number of bands vis-a-vis the ImageFunction.
    int numBandsRequired = function.isComplex() ?
        function.getNumElements() * 2 : function.getNumElements();
    if(layout != null &&
       layout.isValid(ImageLayout.SAMPLE_MODEL_MASK) &&
       layout.getSampleModel(null).getNumBands() != numBandsRequired ) {
        throw new RuntimeException(JaiI18N.getString("ImageFunctionRIF0"));
    }

    int minX = 0;
    int minY = 0;
    if (layout != null) {
        if (layout.isValid(ImageLayout.MIN_X_MASK)) {
            minX = layout.getMinX(null);
        }
        if (layout.isValid(ImageLayout.MIN_Y_MASK)) {
            minY = layout.getMinX(null);
        }
    }

    int width = paramBlock.getIntParameter(1);
    int height = paramBlock.getIntParameter(2);
    float xScale = paramBlock.getFloatParameter(3);
    float yScale = paramBlock.getFloatParameter(4);
    float xTrans = paramBlock.getFloatParameter(5);
    float yTrans = paramBlock.getFloatParameter(6);

    return new ImageFunctionOpImage(function,
                                    minX, minY,
                                    width, height,
                                    xScale, yScale,
                                    xTrans, yTrans,
                                    renderHints, layout);
}
 
Example 16
Project: rastertheque   File: FilteredSubsampleDescriptor.java   Source Code and License Vote up 4 votes
/**
    * Returns the specified property.
    *
    * @param name  Property name.
    * @param opNode Operation node.
    */
   public Object getProperty(String name,
                             Object opNode) {
       validate(name, opNode);

       if(opNode instanceof RenderedOp &&
          name.equalsIgnoreCase("roi")) {
           RenderedOp op = (RenderedOp)opNode;

    ParameterBlock pb = op.getParameterBlock();

    // Retrieve the rendered source image and its ROI.
    RenderedImage src = pb.getRenderedSource(0);
    Object property = src.getProperty("ROI");
    if (property == null ||
	property.equals(java.awt.Image.UndefinedProperty) ||
	!(property instanceof ROI)) {
	return null;
    }
    ROI srcROI = (ROI)property;

    // Determine the effective source bounds.
    Rectangle srcBounds = null;
    PlanarImage dst = op.getRendering();
    if(dst instanceof WarpOpImage && !((OpImage)dst).hasExtender(0)) {
	WarpOpImage warpIm = (WarpOpImage)dst;
	srcBounds =
	    new Rectangle(src.getMinX() + warpIm.getLeftPadding(),
			  src.getMinY() + warpIm.getTopPadding(),
			  src.getWidth() - warpIm.getWidth() + 1,
			  src.getHeight() - warpIm.getHeight() + 1);
    } else {
	srcBounds = new Rectangle(src.getMinX(),
				  src.getMinY(),
				  src.getWidth(),
				  src.getHeight());
    }

    // If necessary, clip the ROI to the effective source bounds.
    if(!srcBounds.contains(srcROI.getBounds())) {
	srcROI = srcROI.intersect(new ROIShape(srcBounds));
    }

    // Retrieve the scale factors
    float sx = 1.0F/pb.getIntParameter(1);
    float sy = 1.0F/pb.getIntParameter(2);

    // Create an equivalent transform.
    AffineTransform transform =
	new AffineTransform(sx, 0.0, 0.0, sy, 0, 0);

    // Create the scaled ROI.
    ROI dstROI = srcROI.transform(transform);

    // Retrieve the destination bounds.
    Rectangle dstBounds = op.getBounds();

    // If necessary, clip the warped ROI to the destination bounds.
    if(!dstBounds.contains(dstROI.getBounds())) {
	dstROI = dstROI.intersect(new ROIShape(dstBounds));
    }

    // Return the warped and possibly clipped ROI.
    return dstROI;
} else {
    return null;
}
   }
 
Example 17
Project: rastertheque   File: FilteredSubsampleDescriptor.java   Source Code and License Vote up 4 votes
/**
    * Validates the input parameters.
    *
    * <p> In addition to the standard checks performed by the
    * superclass method, this method checks that "scaleX" and "scaleY"
    * are both greater than 0 and that the interpolation type
    * is one of 4 standard types: <br>
    * <p> <code>
    *    javax.media.jai.InterpolationNearest <br>
    *    javax.media.jai.InterpolationBilinear <br>
    *    javax.media.jai.InterpolationBicubic <br>
    *    javax.media.jai.InterpolationBicubic2
    * </code>
    */
   protected boolean validateParameters(String modeName,
				 ParameterBlock args,
                                        StringBuffer msg) {
if (!super.validateParameters(modeName, args, msg))
    return false;

       int scaleX = args.getIntParameter(0);
       int scaleY = args.getIntParameter(1);
       if (scaleX < 1 || scaleY < 1) {
           msg.append(getName() + " " +
                      JaiI18N.getString("FilteredSubsampleDescriptor1"));
           return false;
       }

float[] filter = (float[])args.getObjectParameter(2);

// if this parameter is null, generate the kernel based on the
// procedure described above.
if (filter == null) {
    int m = scaleX > scaleY ? scaleX: scaleY;
    if ((m & 1) == 0)
	m++;

    double sigma = (m - 1) / 6.0;

    // when m is 1, sigma is 0; will generate NaN.  Give any number
    // to sigma will generate the correct kernel {1.0}
    if (m == 1)
	sigma = 1.0;

    filter = new float[m/2 + 1];
    float sum = 0;

    for (int i = 0; i < filter.length; i++) {
	filter[i] = (float)gaussian((double)i, sigma);
	if (i == 0)
	    sum += filter[i];
	else
	    sum += filter[i] * 2;
    }

    for (int i = 0; i < filter.length; i++) {
	filter[i] /= sum;
    }

    args.set(filter, 2);
}

       Interpolation interp = (Interpolation)args.getObjectParameter(3);

       // Determine the interpolation type, if not supported throw exception
       if (!((interp instanceof InterpolationNearest)  ||
           (interp instanceof InterpolationBilinear) ||
           (interp instanceof InterpolationBicubic)  ||
           (interp instanceof InterpolationBicubic2))) {
          msg.append(getName() + " " +
                      JaiI18N.getString("FilteredSubsampleDescriptor2"));
          return false;
       }
       return true;

   }