src.setSample(2, 1, 1, 25);
src.setSample(4, 4, 1, 110);
// Basic checks on output
BandCombineOp op = new BandCombineOp(matrix, null);
WritableRaster dst2 = op.createCompatibleDestRaster(src);
WritableRaster dst = op.filter(src, dst2);
harness.check(dst, dst2);
harness.check(dst.getNumBands(), 2);
// A null dst2 should also work
dst2 = null;
dst = op.filter(src, dst2);
harness.check(dst instanceof WritableRaster);
harness.check(dst2, null);
// Check first band
int[] pixels = dst.getSamples(0, 0, 5, 5, 0, (int[])null);
int[] expected = new int[25];
Arrays.fill(expected, 0);
expected[7] = 475;
expected[24] = 940;
harness.check(Arrays.equals(expected, pixels));
// Check second band
pixels = dst.getSamples(0, 0, 5, 5, 1, pixels);
expected[7] = 900;
expected[24] = 1085;
harness.check(Arrays.equals(expected, pixels));
// Check the implied 1 at the end of the band samples, which happens if
// there is one more column in the matrix than there are bands
// And throw in a check with negative numbers too... why not =)
matrix = new float[][] {{2, -7, 5},
{5, 6, -3}};
op = new BandCombineOp(matrix, null);
dst = op.filter(src, dst);
// First band
pixels = dst.getSamples(0, 0, 5, 5, 0, (int[])null);
Arrays.fill(expected, 5);
expected[7] = 130;
expected[24] = -595;
harness.check(Arrays.equals(expected, pixels));
// Second band
pixels = dst.getSamples(0, 0, 5, 5, 1, (int[])null);
Arrays.fill(expected, -3);
expected[7] = 897;
expected[24] = 1082;
harness.check(Arrays.equals(expected, pixels));
// Check for overflow (this should fail silently and not throw an exception)
matrix = new float[][] {{2000000000, 2000000000},
{2000000000, 2000000000}};
try
{
op = new BandCombineOp(matrix, null);
dst = op.filter(src, dst);
harness.check(true);
}
catch (Exception e)
{
harness.check(false);
}
// Check for exceptions
try
{
expected[25] = 100;
harness.check(false);
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// accessing invalid band number
try
{
pixels = dst.getSamples(0, 0, 5, 5, 2, pixels);
harness.check(false);
}
catch (ArrayIndexOutOfBoundsException e)
{
harness.check(true);
}
// dst has wrong number of bands
dst = Raster.createBandedRaster(DataBuffer.TYPE_INT, 5, 5, 6, new Point(0,0));
try
{
dst = op.filter(src, dst);
harness.check(false);
}
catch (IllegalArgumentException e)
{
harness.check(true);
}
// dst has wrong data type
dst = Raster.createBandedRaster(DataBuffer.TYPE_BYTE, 5, 5, 1, new Point(0,0));
try
{
dst = op.filter(src, dst);
harness.check(false);
}
catch (IllegalArgumentException e)
{
harness.check(true);