// Create an image to work on
BufferedImage img = new BufferedImage(20, 20, BufferedImage.TYPE_USHORT_GRAY);
WritableRaster r = img.getRaster();
r.setSample(1, 1, 0, 150);
RescaleOp op = new RescaleOp(1, 1, null);
// Src and dst rasters can be the same
try
{
op.filter(r, r);
harness.check(true);
}
catch (IllegalArgumentException e)
{
harness.check(false);
}
// Src and dst are different sizes (not allowed, unlike some other Ops)
BufferedImage dst = new BufferedImage(30, 40, BufferedImage.TYPE_INT_RGB);
try
{
op.filter(r, dst.getRaster());
harness.check(false);
}
catch (IllegalArgumentException e)
{
harness.check(true);
}
// Null destination check
WritableRaster dstRast = op.filter(r, null);
harness.check(dstRast.getHeight(), r.getHeight());
harness.check(dstRast.getWidth(), r.getWidth());
harness.check(dstRast.getMinX(), r.getMinX());
harness.check(dstRast.getMinY(), r.getMinY());
harness.check(dstRast.getNumBands(), r.getNumBands());
harness.check(dstRast.getNumDataElements(), r.getNumDataElements());
harness.check(dstRast.getTransferType(), r.getTransferType());
harness.check(dstRast.getBounds(), r.getBounds());
harness.check(dstRast.getDataBuffer().getClass(), r.getDataBuffer().getClass());
// Test positive & negative clipping behaviour
img.getRaster().setSample(1, 1, 0, 1500);
op = new RescaleOp(100, 0, null);
dstRast = op.filter(r, null);
double maxValue = Math.pow(2, r.getSampleModel().getSampleSize(0)) - 1;
harness.check(dstRast.getSample(1, 1, 0), maxValue);
op = new RescaleOp(1, -2000, null);
dstRast = op.filter(r, null);
harness.check(dstRast.getSample(1, 1, 0), 0);
}