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();
}
}
}
Aggregations