PlanarImage scaleDown;
if (rescale != 1) {
float scaleX = (float) Math.floor(rescale * back.getWidth()) / (float) back.getWidth();
float scaleY = (float) Math.floor(rescale * back.getHeight()) / (float) back.getHeight();
ParameterBlock pb = new ParameterBlock();
pb.addSource(back);
pb.add(AffineTransform.getScaleInstance(scaleX, scaleY));
pb.add(interp);
RenderingHints layoutHints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT,
new ImageLayout(0, 0,
Math.max(JAIContext.TILE_WIDTH/divideByTwo, 8),
Math.max(JAIContext.TILE_HEIGHT/divideByTwo, 8),
null, null));
layoutHints.add(hints);
layoutHints.add(JAIContext.noCacheHint);
scaleDown = JAI.create("Affine", pb, layoutHints);
} else
scaleDown = back;
if (scaleDown.getColorModel().getNumComponents() == 3) {
ParameterBlock pb = new ParameterBlock();
pb.addSource(scaleDown);
pb.add(transform);
scaleDown = JAI.create("BandCombine", pb, JAIContext.noCacheHint); // Desaturate, single banded
}
scaleDown = JAI.create("Not", scaleDown, JAIContext.noCacheHint); // Invert
LookupTableJAI table = computeGammaTable(scaleDown.getSampleModel().getDataType());
ParameterBlock pb = new ParameterBlock();
pb.addSource(scaleDown);
pb.add(table);
// we cache this since convolution scans its input multiple times
gammaCurve = JAI.create("lookup", pb, null /*JAIContext.noCacheHint*/);
kernel = Functions.getGaussKernel(newRadius);
pb = new ParameterBlock();
pb.addSource(gammaCurve);
pb.add(kernel);
// RenderingHints convolveHints = new RenderingHints(hints);
// convolveHints.add(JAIContext.noCacheHint);
RenderedOp blur = JAI.create("LCSeparableConvolve", pb, hints); // Gaussian Blur
if (rescale != 1) {
pb = new ParameterBlock();
pb.addSource(blur);
pb.add(AffineTransform.getScaleInstance(back.getWidth() / (double) scaleDown.getWidth(),
back.getHeight() / (double) scaleDown.getHeight()));
pb.add(interp);
RenderingHints resultLayoutHints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT,
new ImageLayout(0, 0,
JAIContext.TILE_WIDTH,
JAIContext.TILE_HEIGHT,
null, null));