private void extendAsShort(WritableRaster raster, PlanarImage sourceImage) { Rectangle bounds = sourceImage.getBounds(); Rectangle samplingBounds = new Rectangle(0, 0, 2 * maxDistance + 1, 2 * maxDistance + 1); RandomIter srcIter = RandomIterFactory.create(sourceImage, bounds); int[] pixel = new int[raster.getNumBands()]; for (int y = raster.getMinY(), ny = 0; ny < raster.getHeight(); y++, ny++) { for (int x = raster.getMinX(), nx = 0; nx < raster.getWidth(); x++, nx++) { if (!bounds.contains(x, y)) { samplingBounds.setLocation(x - maxDistance, y - maxDistance); Rectangle sourceSamplingBounds = samplingBounds.intersection(bounds); int sx = rand.nextInt(sourceSamplingBounds.width) + sourceSamplingBounds.x; int sy = rand.nextInt(sourceSamplingBounds.height) + sourceSamplingBounds.y; srcIter.getPixel(sx, sy, pixel); for (int b = 0; b < raster.getNumBands(); b++) { raster.setSample(x, y, b, clamp(pixel[b], Short.MIN_VALUE, Short.MAX_VALUE)); } } } } }