Search in sources :

Example 1 with GeoTiffImageWriterSpi

use of it.geosolutions.imageio.plugins.geotiff.GeoTiffImageWriterSpi in project imageio-ext by geosolutions-it.

the class GeoTiffVrtTest method write.

/**
 * Test Writing capabilities.
 *
 * @throws FileNotFoundException
 * @throws IOException
 */
@Test
public void write() throws IOException, FileNotFoundException {
    if (!isGDALAvailable) {
        return;
    }
    final File outputFile = TestData.temp(this, "writetest.tif", false);
    outputFile.deleteOnExit();
    final File inputFile = TestData.file(this, "utmByte.tif.vrt");
    ImageReadParam rparam = new ImageReadParam();
    rparam.setSourceRegion(new Rectangle(1, 1, 300, 500));
    rparam.setSourceSubsampling(1, 2, 0, 0);
    ImageReader reader = new VRTImageReaderSpi().createReaderInstance();
    reader.setInput(inputFile);
    final IIOMetadata metadata = reader.getImageMetadata(0);
    final ParameterBlockJAI pbjImageRead = new ParameterBlockJAI("ImageRead");
    pbjImageRead.setParameter("Input", inputFile);
    pbjImageRead.setParameter("reader", reader);
    pbjImageRead.setParameter("readParam", rparam);
    final ImageLayout l = new ImageLayout();
    l.setTileGridXOffset(0).setTileGridYOffset(0).setTileHeight(256).setTileWidth(256);
    RenderedOp image = JAI.create("ImageRead", pbjImageRead, new RenderingHints(JAI.KEY_IMAGE_LAYOUT, l));
    if (TestData.isInteractiveTest())
        Viewer.visualizeAllInformation(image, "geotiff");
    // ////////////////////////////////////////////////////////////////
    // preparing to write
    // ////////////////////////////////////////////////////////////////
    final ParameterBlockJAI pbjImageWrite = new ParameterBlockJAI("ImageWrite");
    ImageWriter writer = new GeoTiffImageWriterSpi().createWriterInstance();
    pbjImageWrite.setParameter("Output", outputFile);
    pbjImageWrite.setParameter("writer", writer);
    pbjImageWrite.setParameter("ImageMetadata", metadata);
    pbjImageWrite.setParameter("Transcode", false);
    ImageWriteParam param = new ImageWriteParam(Locale.getDefault());
    param.setSourceRegion(new Rectangle(10, 10, 100, 100));
    param.setSourceSubsampling(2, 1, 0, 0);
    pbjImageWrite.setParameter("writeParam", param);
    pbjImageWrite.addSource(image);
    final RenderedOp op = JAI.create("ImageWrite", pbjImageWrite);
    final ImageWriter writer2 = (ImageWriter) op.getProperty(ImageWriteDescriptor.PROPERTY_NAME_IMAGE_WRITER);
    writer2.dispose();
    // ////////////////////////////////////////////////////////////////
    // preparing to read again
    // ////////////////////////////////////////////////////////////////
    final ParameterBlockJAI pbjImageReRead = new ParameterBlockJAI("ImageRead");
    pbjImageReRead.setParameter("Input", outputFile);
    pbjImageReRead.setParameter("Reader", new GeoTiffImageReaderSpi().createReaderInstance());
    final RenderedOp image2 = JAI.create("ImageRead", pbjImageReRead);
    if (TestData.isInteractiveTest())
        Viewer.visualizeAllInformation(image2, "geotif2");
    else
        Assert.assertNotNull(image2.getTiles());
}
Also used : ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) ImageWriter(javax.imageio.ImageWriter) ImageWriteParam(javax.imageio.ImageWriteParam) GeoTiffImageReaderSpi(it.geosolutions.imageio.plugins.geotiff.GeoTiffImageReaderSpi) IIOMetadata(javax.imageio.metadata.IIOMetadata) ImageReadParam(javax.imageio.ImageReadParam) RenderedOp(javax.media.jai.RenderedOp) GeoTiffImageWriterSpi(it.geosolutions.imageio.plugins.geotiff.GeoTiffImageWriterSpi) ImageReader(javax.imageio.ImageReader) File(java.io.File) ImageLayout(javax.media.jai.ImageLayout) AbstractGDALTest(it.geosolutions.imageio.gdalframework.AbstractGDALTest) Test(org.junit.Test)

Example 2 with GeoTiffImageWriterSpi

use of it.geosolutions.imageio.plugins.geotiff.GeoTiffImageWriterSpi in project imageio-ext by geosolutions-it.

the class GeoTiffVrtTest method palette.

/**
 * Test Read on a Paletted Image
 *
 * @throws FileNotFoundException
 * @throws IOException
 */
@Test
public void palette() throws FileNotFoundException, IOException {
    if (!isGDALAvailable) {
        return;
    }
    final File outputFile = TestData.temp(this, "writetest.tif", false);
    outputFile.deleteOnExit();
    final File inputFile = TestData.file(this, "paletted.tif.vrt");
    ImageReader reader = new VRTImageReaderSpi().createReaderInstance();
    reader.setInput(inputFile);
    final IIOMetadata metadata = reader.getImageMetadata(0);
    final ParameterBlockJAI pbjImageRead = new ParameterBlockJAI("ImageRead");
    pbjImageRead.setParameter("Input", inputFile);
    pbjImageRead.setParameter("reader", reader);
    final ImageLayout l = new ImageLayout();
    l.setTileGridXOffset(0).setTileGridYOffset(0).setTileHeight(256).setTileWidth(256);
    RenderedOp image = JAI.create("ImageRead", pbjImageRead, new RenderingHints(JAI.KEY_IMAGE_LAYOUT, l));
    if (TestData.isInteractiveTest())
        Viewer.visualizeAllInformation(image, "Paletted image read");
    // ////////////////////////////////////////////////////////////////
    // preparing to write
    // ////////////////////////////////////////////////////////////////
    final ParameterBlockJAI pbjImageWrite = new ParameterBlockJAI("ImageWrite");
    ImageWriter writer = new GeoTiffImageWriterSpi().createWriterInstance();
    pbjImageWrite.setParameter("Output", outputFile);
    pbjImageWrite.setParameter("writer", writer);
    pbjImageWrite.setParameter("ImageMetadata", metadata);
    pbjImageWrite.setParameter("Transcode", false);
    pbjImageWrite.addSource(image);
    final RenderedOp op = JAI.create("ImageWrite", pbjImageWrite);
    final ImageWriter writer2 = (ImageWriter) op.getProperty(ImageWriteDescriptor.PROPERTY_NAME_IMAGE_WRITER);
    writer2.dispose();
    // ////////////////////////////////////////////////////////////////
    // preparing to read again
    // ////////////////////////////////////////////////////////////////
    final ParameterBlockJAI pbjImageReRead = new ParameterBlockJAI("ImageRead");
    pbjImageReRead.setParameter("Input", outputFile);
    pbjImageReRead.setParameter("Reader", new GeoTiffImageReaderSpi().createReaderInstance());
    final RenderedOp image2 = JAI.create("ImageRead", pbjImageReRead);
    if (TestData.isInteractiveTest())
        Viewer.visualizeAllInformation(image2, "Paletted image read back after writing");
    else
        Assert.assertNotNull(image2.getTiles());
    ImageIOUtilities.disposeImage(image2);
    ImageIOUtilities.disposeImage(image);
}
Also used : IIOMetadata(javax.imageio.metadata.IIOMetadata) RenderedOp(javax.media.jai.RenderedOp) ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) ImageWriter(javax.imageio.ImageWriter) GeoTiffImageWriterSpi(it.geosolutions.imageio.plugins.geotiff.GeoTiffImageWriterSpi) ImageReader(javax.imageio.ImageReader) GeoTiffImageReaderSpi(it.geosolutions.imageio.plugins.geotiff.GeoTiffImageReaderSpi) File(java.io.File) ImageLayout(javax.media.jai.ImageLayout) AbstractGDALTest(it.geosolutions.imageio.gdalframework.AbstractGDALTest) Test(org.junit.Test)

Aggregations

AbstractGDALTest (it.geosolutions.imageio.gdalframework.AbstractGDALTest)2 GeoTiffImageReaderSpi (it.geosolutions.imageio.plugins.geotiff.GeoTiffImageReaderSpi)2 GeoTiffImageWriterSpi (it.geosolutions.imageio.plugins.geotiff.GeoTiffImageWriterSpi)2 File (java.io.File)2 ImageReader (javax.imageio.ImageReader)2 ImageWriter (javax.imageio.ImageWriter)2 IIOMetadata (javax.imageio.metadata.IIOMetadata)2 ImageLayout (javax.media.jai.ImageLayout)2 ParameterBlockJAI (javax.media.jai.ParameterBlockJAI)2 RenderedOp (javax.media.jai.RenderedOp)2 Test (org.junit.Test)2 ImageReadParam (javax.imageio.ImageReadParam)1 ImageWriteParam (javax.imageio.ImageWriteParam)1