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 Warp object.
Warp warp = (Warp)pb.getObjectParameter(0);
// Setting constant image to be warped as a ROI
Rectangle dstBounds = op.getBounds();
// Setting layout of the constant image
ImageLayout2 layout = new ImageLayout2();
int minx = (int) srcBounds.getMinX();
int miny = (int) srcBounds.getMinY();
int w = (int) srcBounds.getWidth();
int h = (int) srcBounds.getHeight();
layout.setMinX(minx);
layout.setMinY(miny);
layout.setWidth(w);
layout.setHeight(h);
RenderingHints hints = op.getRenderingHints();
hints.add(new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout));
final PlanarImage constantImage = ConstantDescriptor.create(new Float(w), new Float(h), new Byte[]{(byte)255}, hints);
PlanarImage roiImage = null;
// Make sure to specify tileCache, tileScheduler, tileRecyclier, by cloning hints.
RenderingHints warpingHints = op.getRenderingHints();
warpingHints.remove(JAI.KEY_IMAGE_LAYOUT);
// Creating warped roi by the same way (Warp, Interpolation, source ROI) we warped the
// input image.
final ParameterBlock paramBlk = new ParameterBlock();
paramBlk.addSource(constantImage);
paramBlk.add(warp);
paramBlk.add(interp);
paramBlk.add(null);
paramBlk.add(srcROI);
// force in the image layout, this way we get exactly the same
// as the affine we're eliminating
Hints localHints = new Hints(op.getRenderingHints());
localHints.remove(JAI.KEY_IMAGE_LAYOUT);
ImageLayout il = new ImageLayout();
il.setMinX(dstBounds.x);
il.setMinY(dstBounds.y);
il.setWidth(dstBounds.width);
il.setHeight(dstBounds.height);
localHints.put(JAI.KEY_IMAGE_LAYOUT, il);
roiImage = JAI.create("Warp", paramBlk, localHints);
ROI dstROI = new ROI(roiImage, 1);
// 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;
}