use of it.geosolutions.imageioimpl.plugins.tiff.TIFFStreamMetadata.MetadataNode in project imageio-ext by geosolutions-it.
the class TiffDatasetLayoutImpl method parseLayout.
/**
* Creates a new {@link DatasetLayout} instance created from parsing input reader Stream Metadata.
*
* @param metadata {@link IIOMetadata} object to parse
*
* @return a {@link DatasetLayout} instance parsed from input StreamMetadata
*/
public static DatasetLayout parseLayout(IIOMetadata metadata) throws IOException {
// Init the layout to null
TiffDatasetLayoutImpl layout = null;
// Getting input parameters
Node tree = metadata.getAsTree("com_sun_media_imageio_plugins_tiff_stream_1.0");
// Ensuring not null
if (tree == null) {
return layout;
} else {
layout = new TiffDatasetLayoutImpl();
}
// Checking Childs
NodeList list = tree.getChildNodes();
int len = list.getLength();
for (int i = 0; i < len; i++) {
Node node = list.item(i);
// Ensuring not null
if (node == null) {
continue;
}
// Getting the name
String nodeName = node.getNodeName();
// Getting Attribute Value
String value = node.getAttributes().item(0).getNodeValue();
// Getting the Enum related to the input Element
MetadataNode mnode = MetadataNode.getFromName(nodeName);
// Setting Attribute value
switch(mnode) {
case N_INT_MASK:
layout.setNumInternalMasks(Integer.parseInt(value));
break;
case N_EXT_MASK:
layout.setNumExternalMasks(Integer.parseInt(value));
break;
case N_INT_OVR:
layout.setNumInternalOverviews(Integer.parseInt(value));
break;
case N_EXT_OVR:
layout.setNumExternalOverviews(Integer.parseInt(value));
break;
case N_EXT_OVR_MASK:
layout.setNumExternalMaskOverviews(Integer.parseInt(value));
break;
case EXT_MASK_FILE:
layout.setExternalMasks((value != null && !value.isEmpty()) ? new File(value) : null);
break;
case EXT_OVR_FILE:
layout.setExternalOverviews((value != null && !value.isEmpty()) ? new File(value) : null);
break;
case EXT_OVR_MASK_FILE:
layout.setExternalMaskOverviews((value != null && !value.isEmpty()) ? new File(value) : null);
break;
default:
break;
}
}
return layout;
}
use of it.geosolutions.imageioimpl.plugins.tiff.TIFFStreamMetadata.MetadataNode in project imageio-ext by geosolutions-it.
the class TIFFReadTest method readExternalMasksOvr.
@Test
public void readExternalMasksOvr() throws IOException {
// Reading file with external mask and external mask overviews
final File file = TestData.file(this, "external2.tif");
// Read parameters
final ImageReadParam param = new ImageReadParam();
param.setSourceRegion(new Rectangle(0, 0, 2, 2));
// Creating a new Reader
final TIFFImageReader reader = (TIFFImageReader) new TIFFImageReaderSpi().createReaderInstance();
// Using FileImageInputStreamExt for being able to locate the file path
FileImageInputStreamExt inputStream = new FileImageInputStreamExtImpl(file);
try {
// Reading
reader.setInput(inputStream);
// IMAGE 0
BufferedImage image = reader.read(0, param);
Assert.assertEquals(2, image.getWidth());
Assert.assertEquals(2, image.getHeight());
image.flush();
image = null;
// Getting Stream Metadata
IIOMetadata metadata = reader.getStreamMetadata();
Node tree = metadata.getAsTree("com_sun_media_imageio_plugins_tiff_stream_1.0");
// Ensuring not null
Assert.assertNotNull(tree);
// Checking Childs
NodeList list = tree.getChildNodes();
int len = list.getLength();
// Loop on the Node list
for (int i = 0; i < len; i++) {
Node node = list.item(i);
// Ensuring not null
Assert.assertNotNull(node);
// Getting the name
String nodeName = node.getNodeName();
// Checking attributes
Assert.assertTrue(node.hasAttributes());
// Getting Attribute Value
String value = node.getAttributes().item(0).getNodeValue();
// Getting related enum
MetadataNode mnode = MetadataNode.getFromName(nodeName);
// Checking Attribute value
switch(mnode) {
case B_ORDER:
Assert.assertTrue(value.equalsIgnoreCase(ByteOrder.LITTLE_ENDIAN.toString()));
break;
case N_INT_MASK:
Assert.assertEquals(0, Integer.parseInt(value));
break;
case N_EXT_MASK:
Assert.assertEquals(1, Integer.parseInt(value));
break;
case N_INT_OVR:
Assert.assertEquals(0, Integer.parseInt(value));
break;
case N_EXT_OVR:
Assert.assertEquals(0, Integer.parseInt(value));
break;
case N_EXT_OVR_MASK:
Assert.assertEquals(4, Integer.parseInt(value));
break;
case EXT_MASK_FILE:
Assert.assertTrue(value.contains("external2.tif.msk"));
break;
case EXT_OVR_FILE:
Assert.assertTrue(value.isEmpty());
break;
case EXT_OVR_MASK_FILE:
Assert.assertTrue(value.contains("external2.tif.msk.ovr"));
break;
default:
// Wrong element
Assert.assertTrue(false);
}
}
} catch (Exception e) {
// If an exception occurred the logger catch the exception and print
// the message
logger.log(Level.SEVERE, e.getMessage(), e);
} finally {
// and the input stream are closed
if (inputStream != null) {
inputStream.flush();
inputStream.close();
}
if (reader != null) {
reader.dispose();
}
}
}
use of it.geosolutions.imageioimpl.plugins.tiff.TIFFStreamMetadata.MetadataNode in project imageio-ext by geosolutions-it.
the class TIFFReadTest method readMasks.
@Test
public void readMasks() throws IOException {
// Reading a File with internal masks
final File file = TestData.file(this, "masks.tif");
// Setting Read parameters
final ImageReadParam param = new ImageReadParam();
param.setSourceRegion(new Rectangle(0, 0, 2, 2));
// Reader creation
final TIFFImageReader reader = (TIFFImageReader) new TIFFImageReaderSpi().createReaderInstance();
// Stream creation
FileImageInputStream inputStream = new FileImageInputStream(file);
try {
// Setting input
reader.setInput(inputStream);
// IMAGE 0
BufferedImage image = reader.read(0, param);
Assert.assertEquals(2, image.getWidth());
Assert.assertEquals(2, image.getHeight());
image.flush();
image = null;
// Getting Stream Metadata
IIOMetadata metadata = reader.getStreamMetadata();
Node tree = metadata.getAsTree("com_sun_media_imageio_plugins_tiff_stream_1.0");
// Ensuring not null
Assert.assertNotNull(tree);
// Checking Childs
NodeList list = tree.getChildNodes();
int len = list.getLength();
// Loop on the list
for (int i = 0; i < len; i++) {
// Node i-th
Node node = list.item(i);
// Ensuring not null
Assert.assertNotNull(node);
// Getting the name
String nodeName = node.getNodeName();
// Checking attributes
Assert.assertTrue(node.hasAttributes());
// Getting Attribute Value
String value = node.getAttributes().item(0).getNodeValue();
// Getting related enum
MetadataNode mnode = MetadataNode.getFromName(nodeName);
// Checking Attribute value
switch(mnode) {
case B_ORDER:
Assert.assertTrue(value.equalsIgnoreCase(ByteOrder.LITTLE_ENDIAN.toString()));
break;
case N_INT_MASK:
Assert.assertEquals(5, Integer.parseInt(value));
break;
case N_EXT_MASK:
Assert.assertEquals(-1, Integer.parseInt(value));
break;
case N_INT_OVR:
Assert.assertEquals(4, Integer.parseInt(value));
break;
case N_EXT_OVR:
Assert.assertEquals(-1, Integer.parseInt(value));
break;
case N_EXT_OVR_MASK:
Assert.assertEquals(-1, Integer.parseInt(value));
break;
case EXT_MASK_FILE:
Assert.assertTrue(value.isEmpty());
break;
case EXT_OVR_FILE:
Assert.assertTrue(value.isEmpty());
break;
case EXT_OVR_MASK_FILE:
Assert.assertTrue(value.isEmpty());
break;
default:
// Wrong element
Assert.assertTrue(false);
}
}
} catch (Exception e) {
// If an exception occurred the logger catch the exception and print
// the message
logger.log(Level.SEVERE, e.getMessage(), e);
Assert.assertTrue(false);
} finally {
// and the input stream are closed
if (inputStream != null) {
inputStream.flush();
inputStream.close();
}
if (reader != null) {
reader.dispose();
}
}
}
use of it.geosolutions.imageioimpl.plugins.tiff.TIFFStreamMetadata.MetadataNode in project imageio-ext by geosolutions-it.
the class TIFFReadTest method readExternalMasks.
@Test
public void readExternalMasks() throws IOException {
// Reading file with external masks
final File file = TestData.file(this, "external.tif");
// Setting read parameters
final ImageReadParam param = new ImageReadParam();
param.setSourceRegion(new Rectangle(0, 0, 2, 2));
// Creating the reader
final TIFFImageReader reader = (TIFFImageReader) new TIFFImageReaderSpi().createReaderInstance();
// Using FileImageInputStreamExt for being able to locate the file path
FileImageInputStreamExt inputStream = new FileImageInputStreamExtImpl(file);
try {
// reading phase
reader.setInput(inputStream);
// IMAGE 0
BufferedImage image = reader.read(0, param);
Assert.assertEquals(2, image.getWidth());
Assert.assertEquals(2, image.getHeight());
image.flush();
image = null;
// Getting Stream Metadata
IIOMetadata metadata = reader.getStreamMetadata();
Node tree = metadata.getAsTree("com_sun_media_imageio_plugins_tiff_stream_1.0");
// Ensuring not null
Assert.assertNotNull(tree);
// Checking Childs
NodeList list = tree.getChildNodes();
int len = list.getLength();
// Loop the nodes
for (int i = 0; i < len; i++) {
// Node i-th
Node node = list.item(i);
// Ensuring not null
Assert.assertNotNull(node);
// Getting the name
String nodeName = node.getNodeName();
// Checking attributes
Assert.assertTrue(node.hasAttributes());
// Getting Attribute Value
String value = node.getAttributes().item(0).getNodeValue();
// Getting related enum
MetadataNode mnode = MetadataNode.getFromName(nodeName);
// Checking Attribute value
switch(mnode) {
case B_ORDER:
Assert.assertTrue(value.equalsIgnoreCase(ByteOrder.LITTLE_ENDIAN.toString()));
break;
case N_INT_MASK:
Assert.assertEquals(0, Integer.parseInt(value));
break;
case N_EXT_MASK:
Assert.assertEquals(5, Integer.parseInt(value));
break;
case N_INT_OVR:
Assert.assertEquals(4, Integer.parseInt(value));
break;
case N_EXT_OVR:
Assert.assertEquals(0, Integer.parseInt(value));
break;
case N_EXT_OVR_MASK:
Assert.assertEquals(0, Integer.parseInt(value));
break;
case EXT_MASK_FILE:
Assert.assertTrue(value.contains("external.tif.msk"));
break;
case EXT_OVR_FILE:
Assert.assertTrue(value.isEmpty());
break;
case EXT_OVR_MASK_FILE:
Assert.assertTrue(value.isEmpty());
break;
default:
// Wrong element
Assert.assertTrue(false);
}
}
} catch (Exception e) {
// If an exception occurred the logger catch the exception and print
// the message
logger.log(Level.SEVERE, e.getMessage(), e);
Assert.assertTrue(false);
} finally {
// and the input stream are closed
if (inputStream != null) {
inputStream.flush();
inputStream.close();
}
if (reader != null) {
reader.dispose();
}
}
}
Aggregations