Search in sources :

Example 1 with CoreCommonImageMetadata

use of it.geosolutions.imageio.core.CoreCommonImageMetadata in project imageio-ext by geosolutions-it.

the class TIFFReadTest method readWithEmptyTiles.

@Test
public void readWithEmptyTiles() throws IOException {
    // This input image is a 1440x720 image. However, the right half of the image
    // is made of empty tiles filled with nodata
    final File file = TestData.file(this, "emptyTiles.tif");
    final TIFFImageReader reader = (TIFFImageReader) new TIFFImageReaderSpi().createReaderInstance();
    FileImageInputStream inputStream = new FileImageInputStream(file);
    try {
        reader.setInput(inputStream);
        ImageReadParam param = new ImageReadParam();
        // Setting up a region to fall in the half of the image containing empty tiles
        param.setSourceRegion(new Rectangle(360, 0, 720, 720));
        BufferedImage image = reader.read(0, param);
        Assert.assertEquals(720, image.getWidth());
        Assert.assertEquals(720, image.getHeight());
        IIOMetadata metadata = reader.getImageMetadata(0);
        Node rootNode = metadata.getAsTree(metadata.getNativeMetadataFormatName());
        double noDataValue = getNoDataValue(rootNode);
        // get it from the core common metadata too
        CoreCommonImageMetadata ccm = (CoreCommonImageMetadata) metadata;
        double[] noDataArray = ccm.getNoData();
        assertNotNull(noDataArray);
        assertEquals(noDataArray[0], noDataValue, 0d);
        assertEquals(noDataArray[1], noDataValue, 0d);
        // Check that the value is noData (the empty Tiles are filled with NoData)
        double val = image.getData().getSampleDouble(719, 0, 0);
        assertEquals(Double.toString(noDataValue), Double.toString(val));
        image.flush();
        image = null;
    } catch (Exception e) {
        // If an exception occurred the logger catch the exception and print
        // the message
        logger.log(Level.SEVERE, e.getMessage(), e);
    } finally {
        if (inputStream != null) {
            inputStream.flush();
            inputStream.close();
        }
        if (reader != null) {
            reader.dispose();
        }
    }
}
Also used : CoreCommonImageMetadata(it.geosolutions.imageio.core.CoreCommonImageMetadata) IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode) Node(org.w3c.dom.Node) MetadataNode(it.geosolutions.imageioimpl.plugins.tiff.TIFFStreamMetadata.MetadataNode) Rectangle(java.awt.Rectangle) TIFFImageReader(it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader) TIFFImageReaderSpi(it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReaderSpi) BufferedImage(java.awt.image.BufferedImage) IOException(java.io.IOException) FileImageInputStream(javax.imageio.stream.FileImageInputStream) IIOMetadata(javax.imageio.metadata.IIOMetadata) ImageReadParam(javax.imageio.ImageReadParam) File(java.io.File) Test(org.junit.Test)

Aggregations

CoreCommonImageMetadata (it.geosolutions.imageio.core.CoreCommonImageMetadata)1 TIFFImageReader (it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader)1 TIFFImageReaderSpi (it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReaderSpi)1 MetadataNode (it.geosolutions.imageioimpl.plugins.tiff.TIFFStreamMetadata.MetadataNode)1 Rectangle (java.awt.Rectangle)1 BufferedImage (java.awt.image.BufferedImage)1 File (java.io.File)1 IOException (java.io.IOException)1 ImageReadParam (javax.imageio.ImageReadParam)1 IIOMetadata (javax.imageio.metadata.IIOMetadata)1 IIOMetadataNode (javax.imageio.metadata.IIOMetadataNode)1 FileImageInputStream (javax.imageio.stream.FileImageInputStream)1 Test (org.junit.Test)1 Node (org.w3c.dom.Node)1