Ejemplo n.º 1
0
 @Test
 public void testTranslatedImage() throws Exception {
   BufferedImage bi = new BufferedImage(256, 256, BufferedImage.TYPE_BYTE_GRAY);
   TiledImage image =
       new TiledImage(
           0,
           0,
           256,
           256,
           1,
           1,
           bi.getSampleModel().createCompatibleSampleModel(256, 256),
           bi.getColorModel());
   Graphics g = image.createGraphics();
   g.setColor(Color.WHITE);
   g.fillRect(0, 0, 20, 20);
   g.setColor(new Color(20, 20, 20)); // A dark gray
   g.fillRect(20, 20, 20, 20);
   g.setColor(new Color(200, 200, 200)); // A light gray
   g.fillRect(0, 20, 20, 20);
   g.dispose();
   RenderedImage indexed = quantize(image);
   assertTrue(indexed.getColorModel() instanceof IndexColorModel);
   IndexColorModel icm = (IndexColorModel) indexed.getColorModel();
   assertEquals(4, icm.getMapSize()); // Black background, white fill,
   // light gray fill, dark gray fill =
   // 4 colors
 }
Ejemplo n.º 2
0
  /** Tests that flipping axis on a coverage whose origin is not (0,0) works as expected */
  @Test
  public void testFlipTranslated() throws Exception {
    // build a translated image
    SampleModel sm =
        RasterFactory.createPixelInterleavedSampleModel(DataBuffer.TYPE_BYTE, 256, 256, 3);
    ColorModel cm = PlanarImage.createColorModel(sm);
    TiledImage ti = new TiledImage(-10, -10, 5, 5, 0, 0, sm, cm);
    Graphics2D g = ti.createGraphics();
    g.setColor(Color.GREEN);
    g.fillRect(-10, -10, 5, 5);
    g.dispose();

    // build a coverage around it
    CoordinateReferenceSystem wgs84LatLon = CRS.decode("EPSG:4326");
    final GridCoverageFactory factory = CoverageFactoryFinder.getGridCoverageFactory(null);
    GridCoverage2D coverage =
        factory.create("translated", ti, new Envelope2D(wgs84LatLon, 3, 5, 6, 8));

    // verify we're good
    int[] pixel = new int[3];
    coverage.evaluate((DirectPosition) new DirectPosition2D(4, 6), pixel);
    assertEquals(0, pixel[0]);
    assertEquals(255, pixel[1]);
    assertEquals(0, pixel[2]);

    // now reproject flipping the axis
    CoordinateReferenceSystem wgs84LonLat = CRS.decode("EPSG:4326", true);
    GridGeometry gg =
        new GridGeometry2D(
            new GridEnvelope2D(-10, -10, 5, 5), (Envelope) new Envelope2D(wgs84LonLat, 5, 3, 8, 6));
    GridCoverage2D flipped =
        (GridCoverage2D)
            Operations.DEFAULT.resample(
                coverage, wgs84LonLat, gg, Interpolation.getInstance(Interpolation.INTERP_NEAREST));

    // before the fix the pixel would have been black
    flipped.evaluate((DirectPosition) new DirectPosition2D(6, 4), pixel);
    assertEquals(0, pixel[0]);
    assertEquals(255, pixel[1]);
    assertEquals(0, pixel[2]);
  }