use of org.apache.sis.image.WritablePixelIterator in project sis by apache.
the class CoverageCanvasApp method createImage.
/**
* Creates a dummy image for testing purpose. Some tiles will
* have artificial errors in order to see the error controls.
*/
private static GridCoverage2D createImage() {
final Random random = new Random();
final int width = TILE_WIDTH * 4;
final int height = TILE_HEIGHT * 2;
final TiledImageMock image = new TiledImageMock(DataBuffer.TYPE_BYTE, 1, // minX
random.nextInt(50) - 25, // minY
random.nextInt(50) - 25, width, height, TILE_WIDTH, TILE_HEIGHT, // minTileX
random.nextInt(10) - 5, // minTileY
random.nextInt(10) - 5, false);
image.validate();
final double sc = 500d / Math.max(width, height);
final WritablePixelIterator it = WritablePixelIterator.create(image);
while (it.next()) {
final Point p = it.getPosition();
final double d = Math.hypot(p.x - width / 2, p.y - height / 2);
int value = 0;
if ((Math.round(d) & 16) == 0) {
value = Math.max(0, 255 - (int) (d * sc));
}
it.setSample(0, value);
}
image.failRandomly(random, false);
return new GridCoverage2D(new GridGeometry(null, PixelInCell.CELL_CORNER, MathTransforms.identity(2), CommonCRS.Engineering.DISPLAY.crs()), null, image);
}
Aggregations