use of it.geosolutions.imageio.stream.input.FileImageInputStreamExtImpl in project imageio-ext by geosolutions-it.
the class JPEGWriterTest method testExifReplace.
@Test
@Ignore
public void testExifReplace() throws IOException {
EXIFMetadata exif = initExif();
FileImageInputStreamExt inStream = new FileImageInputStreamExtImpl(new File("/media/bigdisk/data/turbojpeg/lastExif.jpeg"));
EXIFUtilities.replaceEXIFs(inStream, exif);
}
use of it.geosolutions.imageio.stream.input.FileImageInputStreamExtImpl 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.imageio.stream.input.FileImageInputStreamExtImpl 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();
}
}
}
use of it.geosolutions.imageio.stream.input.FileImageInputStreamExtImpl in project imageio-ext by geosolutions-it.
the class GeoTiffTest method read.
/**
* Test Read exploiting JAI-ImageIO tools capabilities
*
* @throws FileNotFoundException
* @throws IOException
*/
@Test
public void read() throws FileNotFoundException, IOException {
if (!isGDALAvailable) {
return;
}
final ParameterBlockJAI pbjImageRead;
String fileName = "utmByte.tif";
final File file = TestData.file(this, fileName);
pbjImageRead = new ParameterBlockJAI("ImageRead");
pbjImageRead.setParameter("Input", new FileImageInputStreamExtImpl(file));
pbjImageRead.setParameter("Reader", new GeoTiffImageReaderSpi().createReaderInstance());
RenderedOp image = JAI.create("ImageRead", pbjImageRead);
if (TestData.isInteractiveTest())
Viewer.visualizeAllInformation(image, "", true);
else
Assert.assertNotNull(image.getTiles());
}
use of it.geosolutions.imageio.stream.input.FileImageInputStreamExtImpl in project imageio-ext by geosolutions-it.
the class TIFFImageReader method getNumImages.
/**
* Simple method for accessing the number of images inside an input file
*
* @param inputFile Input {@link File} to check
* @return An integer defining the number of images contained in the input file
* @throws IIOException
*/
private int getNumImages(File inputFile) throws IIOException {
// Init value to 0
int numImg = 0;
// Creating a new TIFFImageReader instance for reading
ImageReader reader = null;
// Initializing a null stream
FileImageInputStreamExtImpl stream = null;
// Searching for external Overviews
if (inputFile != null) {
try {
// Getting mask data stream
stream = new FileImageInputStreamExtImpl(inputFile);
// Creating the Reader
reader = originatingProvider.createReaderInstance();
reader.setInput(stream);
// Getting the image number (Indicates the Mask number)
numImg = reader.getNumImages(true);
} catch (IOException e) {
throw new IIOException("Unable to open input .msk file", e);
} finally {
// Closing reader
if (reader != null) {
try {
reader.dispose();
} catch (Exception e) {
// Eat the Exception
}
}
// Closing stream
if (stream != null) {
try {
stream.close();
} catch (Exception e) {
// Eat the Exception
}
}
}
}
return numImg;
}
Aggregations