RenderedOp clippedImage = image;
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("OriginalImage:" + ImageInformation.asString(image));
}
ClipXY clipper = null;
// should try to crop the image.
if (params.containsName(ParameterNames.CLIP_AREA)) {
clipper = (ClipXY) params.getObject(ParameterNames.CLIP_AREA);
}
if (clipper != null) {
// should try to crop the image.
// adjust clipper for selected frame. It has to be cloned to preserve
// initial clip area for further processing
ClipXY frameClipper = (ClipXY) clipper.clone();
frameClipper.adjustTo(image.getMinX(), image.getWidth(), image.getMinY(), image.getHeight());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("ClipInfo: " + clipper.toString());
LOGGER.debug("FrameClipInfo: " + frameClipper.toString());
}
ParameterBlock cropParams = new ParameterBlock();
cropParams.addSource(clippedImage);
cropParams.add((float) frameClipper.getX().getClipOffset());
cropParams.add((float) frameClipper.getY().getClipOffset());
cropParams.add((float) frameClipper.getX().getClipSize());
cropParams.add((float) frameClipper.getY().getClipSize());
try {
clippedImage = JAI.create("crop", cropParams);
} catch (Exception e) {
LOGGER.error("jai-operation-failure", "crop");