Exemplo n.º 1
0
 public static RenderedImage getImageOp(RenderedImage image, String opName) {
   if (image instanceof RenderedOp) {
     RenderedOp op = (RenderedOp) image;
     if (op.getOperationName().equalsIgnoreCase(opName)) {
       return image;
     }
     while (op.getNumSources() > 0) {
       try {
         PlanarImage img = op.getSourceImage(0);
         if (image instanceof RenderedOp) {
           RenderedOp op2 = (RenderedOp) img;
           if (op2.getOperationName().equalsIgnoreCase(opName)) {
             return img;
           }
         }
       } catch (Exception ex) {
         return null;
       }
     }
   }
   return null;
 }
Exemplo n.º 2
0
  @Test
  public void testOptimizedWarp() throws Exception {
    // do it again, make sure the image does not turn black since
    GridCoverage2D ushortCoverage = EXAMPLES.get(5);
    GridCoverage2D coverage =
        project(ushortCoverage, CRS.parseWKT(GOOGLE_MERCATOR_WKT), null, "nearest", null, true);
    RenderedImage ri = coverage.getRenderedImage();

    ImageWorker.WARP_REDUCTION_ENABLED = false;
    AffineTransform at = new AffineTransform(0.4, 0, 0, 0.5, -200, -200);
    RenderedOp fullChain =
        (RenderedOp)
            new ImageWorker(ri)
                .affine(
                    at, Interpolation.getInstance(Interpolation.INTERP_NEAREST), new double[] {0})
                .getRenderedImage();
    assertEquals("Scale", fullChain.getOperationName());
    fullChain.getTiles();

    ImageWorker.WARP_REDUCTION_ENABLED = true;
    RenderedOp reduced =
        (RenderedOp)
            new ImageWorker(ri)
                .affine(
                    at, Interpolation.getInstance(Interpolation.INTERP_NEAREST), new double[] {0})
                .getRenderedImage();
    // force computation, to make sure it does not throw exceptions
    reduced.getTiles();
    // check the chain has been reduced
    assertEquals("Warp", reduced.getOperationName());
    assertEquals(1, reduced.getSources().size());
    assertSame(ushortCoverage.getRenderedImage(), reduced.getSourceImage(0));

    // check the bounds of the output image has not changed
    assertEquals(fullChain.getBounds(), reduced.getBounds());
  }