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 java.awt.Image.UndefinedProperty;
}
ROI srcROI = (ROI)property;
// Retrieve the Interpolation object.
Interpolation interp = (Interpolation)pb.getObjectParameter(3);
// Determine the effective source bounds.
Rectangle srcBounds = null;
PlanarImage dst = op.getRendering();
if (dst instanceof GeometricOpImage &&
((GeometricOpImage)dst).getBorderExtender() == null) {
srcBounds =
new Rectangle(src.getMinX() + interp.getLeftPadding(),
src.getMinY() + interp.getTopPadding(),
src.getWidth() - interp.getWidth() + 1,
src.getHeight() - interp.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 translation and rotation angle.
double xorig = (double)pb.getFloatParameter(0);
double yorig = (double)pb.getFloatParameter(1);
double angle = (double)pb.getFloatParameter(2);
// Create an transform representing the rotation.
AffineTransform transform =
AffineTransform.getRotateInstance(angle, xorig, yorig);
// Create the rotated/translated ROI.
ROI dstROI = srcROI.transform(transform);
// Retrieve the destination bounds.
Rectangle dstBounds = op.getBounds();
// If necessary, clip the rotated ROI to the destination bounds.
if(!dstBounds.contains(dstROI.getBounds())) {
dstROI = dstROI.intersect(new ROIShape(dstBounds));
}