/**
   * Extract the ImageLayout from the provided reader for the first available image.
   *
   * @param reader an istance of {@link ImageReader}
   * @throws IOException in case an error occurs
   */
  protected void setLayout(ImageReader reader) throws IOException {

    Utilities.ensureNonNull("reader", reader);
    // save ImageLayout
    ImageLayout2 layout = new ImageLayout2();
    ImageTypeSpecifier its = reader.getImageTypes(0).next();
    layout.setColorModel(its.getColorModel()).setSampleModel(its.getSampleModel());
    layout.setMinX(0).setMinY(0).setWidth(reader.getWidth(0)).setHeight(reader.getHeight(0));
    layout
        .setTileGridXOffset(0)
        .setTileGridYOffset(0)
        .setTileWidth(reader.getTileWidth(0))
        .setTileHeight(reader.getTileHeight(0));
    setlayout(layout);
  }
  @Test
  //    @Ignore
  public void nearestExternal() throws Exception {

    final OverviewsEmbedder oe = new OverviewsEmbedder();
    oe.setDownsampleStep(2);
    oe.setNumSteps(5);
    oe.setScaleAlgorithm(OverviewsEmbedder.SubsampleAlgorithm.Nearest.toString());
    // use default
    oe.setTileCache(JAI.getDefaultInstance().getTileCache());
    oe.setTileWidth(256);
    oe.setTileHeight(256);
    oe.setExternalOverviews(true);
    oe.setSourcePath(TestData.file(this, "DEM_.tiff").getAbsolutePath());
    oe.addProcessingEventListener(
        new ProcessingEventListener() {

          @Override
          public void getNotification(ProcessingEvent event) {
            LOGGER.info(event.toString());
          }

          @Override
          public void exceptionOccurred(ExceptionEvent event) {
            LOGGER.warning(event.toString());
          }
        });
    oe.run();

    // now red it back and check that things are coherent
    final ImageReader reader = new TIFFImageReaderSpi().createReaderInstance();
    reader.setInput(
        ImageIO.createImageInputStream(org.geotools.test.TestData.file(this, "DEM_.tiff")));
    assertTrue(reader.getNumImages(true) == 1);
    reader.reset();

    assertTrue(org.geotools.test.TestData.file(this, "DEM_.tif.ovr").exists());
    reader.setInput(
        ImageIO.createImageInputStream(org.geotools.test.TestData.file(this, "DEM_.tif.ovr")));
    assertTrue(reader.getNumImages(true) == 5);
    assertTrue(reader.isImageTiled(0));
    assertEquals(256, reader.getTileHeight(0));
    assertEquals(256, reader.getTileWidth(0));
    reader.dispose();
  }