Search in sources :

Example 1 with WritablePixelIterator

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);
}
Also used : GridGeometry(org.apache.sis.coverage.grid.GridGeometry) GridCoverage2D(org.apache.sis.coverage.grid.GridCoverage2D) Random(java.util.Random) WritablePixelIterator(org.apache.sis.image.WritablePixelIterator) TiledImageMock(org.apache.sis.image.TiledImageMock) Point(java.awt.Point) Point(java.awt.Point)

Aggregations

Point (java.awt.Point)1 Random (java.util.Random)1 GridCoverage2D (org.apache.sis.coverage.grid.GridCoverage2D)1 GridGeometry (org.apache.sis.coverage.grid.GridGeometry)1 TiledImageMock (org.apache.sis.image.TiledImageMock)1 WritablePixelIterator (org.apache.sis.image.WritablePixelIterator)1