Example usage for java.awt.image RenderedImage getMinTileY

List of usage examples for java.awt.image RenderedImage getMinTileY

Introduction

In this page you can find the example usage for java.awt.image RenderedImage getMinTileY.

Prototype

int getMinTileY();

Source Link

Document

Returns the minimum tile index in the Y direction.

Usage

From source file:org.geoserver.wps.gs.raster.algebra.JiffleScriptProcessTest.java

/**
 * Private method for ensuring the validity of the output image.
 * //from w  ww.  j a v a  2 s.  com
 * @param outputImage RenderedImage extracted from the output coverage
 * @param inputCoverages Input Coverages used.
 * @param values
 */
private void checkExecution(RenderedImage outputImage, int[] values, GridCoverage2D... inputCoverages) {

    RenderedImage inputImage = inputCoverages[0].getRenderedImage();

    int numBands = outputImage.getSampleModel().getNumBands();

    int minTileX = outputImage.getMinTileX();
    int minTileY = outputImage.getMinTileY();
    int maxTileX = outputImage.getNumXTiles() + minTileX;
    int maxTileY = outputImage.getNumYTiles() + minTileY;

    int minX;
    int minY;
    int maxX;
    int maxY;

    Raster inputTile;
    Raster outputTile;

    int inputValue;
    int outputValue;
    // Cycle on each tile
    int valueOver0;

    for (int b = 0; b < numBands; b++) {

        valueOver0 = values[b];

        for (int xTile = minTileX; xTile < maxTileX; xTile++) {
            for (int yTile = minTileY; yTile < maxTileY; yTile++) {

                inputTile = inputImage.getTile(xTile, yTile);
                outputTile = outputImage.getTile(xTile, yTile);

                minX = inputTile.getMinX();
                minY = inputTile.getMinY();

                maxX = inputTile.getWidth() + minX;
                maxY = inputTile.getHeight() + minY;
                // Cycle on the x axis
                for (int x = minX; x < maxX; x++) {
                    // Cycle on the y axis
                    for (int y = minY; y < maxY; y++) {
                        inputValue = inputTile.getSample(x, y, b);
                        outputValue = outputTile.getSample(x, y, b);
                        // Check if the script operation is performed correctly
                        if (inputValue > 0) {
                            assertEquals(outputValue, valueOver0);
                        } else {
                            assertEquals(outputValue, LESS_THAN_ZERO_BAND_0);
                        }
                    }
                }
            }
        }
    }
}

From source file:org.geotools.gce.imagemosaic.ImageMosaicReaderTest.java

@Test
//    @Ignore// w w w .  j a  v  a 2 s . c o m
public void testRequestInHole() throws Exception {
    final AbstractGridFormat format = TestUtils.getFormat(rgbAURL);
    final ImageMosaicReader reader = TestUtils.getReader(rgbAURL, format);

    assertNotNull(reader);

    // ask to extract an area that is inside the coverage bbox, but in a hole (no data)
    final ParameterValue<GridGeometry2D> ggp = AbstractGridFormat.READ_GRIDGEOMETRY2D.createValue();
    Envelope2D env = new Envelope2D(reader.getCrs(), 500000, 3200000, 1000, 1000);
    GridGeometry2D gg = new GridGeometry2D(new GridEnvelope2D(0, 0, 100, 100), (Envelope) env);
    ggp.setValue(gg);

    // red background
    final ParameterValue<double[]> bgp = ImageMosaicFormat.BACKGROUND_VALUES.createValue();
    bgp.setValue(new double[] { 255, 0, 0, 255 });

    // read and check we actually got a coverage in the requested area
    GridCoverage2D coverage = reader.read(new GeneralParameterValue[] { ggp, bgp });
    assertNotNull(coverage);
    assertTrue(coverage.getEnvelope2D().intersects((Rectangle2D) env));

    // and that the color is the expected one given the background values provided
    RenderedImage ri = coverage.getRenderedImage();
    int[] pixel = new int[4];
    Raster tile = ri.getTile(ri.getMinTileX() + 1, ri.getMinTileY() + 1);
    tile.getPixel(tile.getMinX(), tile.getMinY(), pixel);
    assertEquals(255, pixel[0]);
    assertEquals(0, pixel[1]);
    assertEquals(0, pixel[2]);
    assertEquals(255, pixel[3]);
}

From source file:org.geotools.gce.imagemosaic.ImageMosaicReaderTest.java

@Test
//    @Ignore/*from  w w  w  . java 2  s .com*/
public void testRequestInOut() throws Exception {
    final AbstractGridFormat format = TestUtils.getFormat(rgbAURL);
    final ImageMosaicReader reader = TestUtils.getReader(rgbAURL, format);

    assertNotNull(reader);

    // ask to extract an area that is inside the coverage bbox, so that the area is partly
    // inside the raster, and partly outside
    final ParameterValue<GridGeometry2D> ggp = AbstractGridFormat.READ_GRIDGEOMETRY2D.createValue();
    Envelope2D env = new Envelope2D(reader.getCrs(), 64887, 2499342, 646897 - 64887, 3155705 - 2499342);
    GridGeometry2D gg = new GridGeometry2D(new GridEnvelope2D(0, 0, 100, 100), (Envelope) env);
    ggp.setValue(gg);

    // red background
    final ParameterValue<double[]> bgp = ImageMosaicFormat.BACKGROUND_VALUES.createValue();
    bgp.setValue(new double[] { 255, 0, 0, 255 });

    // read and check we actually got a coverage in the requested area
    GridCoverage2D coverage = reader.read(new GeneralParameterValue[] { ggp, bgp });
    assertNotNull(coverage);
    System.out.println(coverage.getEnvelope2D());
    System.out.println(env);
    assertTrue(coverage.getEnvelope2D().contains((Rectangle2D) env));

    // and that the color is the expected one given the background values provided
    RenderedImage ri = coverage.getRenderedImage();
    // ImageIO.write(ri, "PNG", new File("/tmp/mix.png"));
    System.out.println(ri.getNumXTiles());
    System.out.println(ri.getNumYTiles());
    int[] pixel = new int[4];
    Raster tile = ri.getTile(ri.getMinTileX() + ri.getNumXTiles() - 1,
            ri.getMinTileY() + ri.getNumYTiles() - 1);
    tile.getPixel(tile.getWidth() / 2, tile.getHeight() / 2, pixel);
    assertEquals(255, pixel[0]);
    assertEquals(0, pixel[1]);
    assertEquals(0, pixel[2]);
    assertEquals(255, pixel[3]);
}