Search in sources :

Example 1 with FileImageInputStreamExtImpl

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);
}
Also used : EXIFMetadata(it.geosolutions.imageio.plugins.exif.EXIFMetadata) FileImageInputStreamExt(it.geosolutions.imageio.stream.input.FileImageInputStreamExt) FileImageInputStreamExtImpl(it.geosolutions.imageio.stream.input.FileImageInputStreamExtImpl) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with FileImageInputStreamExtImpl

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();
        }
    }
}
Also used : IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode) Node(org.w3c.dom.Node) MetadataNode(it.geosolutions.imageioimpl.plugins.tiff.TIFFStreamMetadata.MetadataNode) NodeList(org.w3c.dom.NodeList) 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) IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode) MetadataNode(it.geosolutions.imageioimpl.plugins.tiff.TIFFStreamMetadata.MetadataNode) IIOMetadata(javax.imageio.metadata.IIOMetadata) ImageReadParam(javax.imageio.ImageReadParam) FileImageInputStreamExt(it.geosolutions.imageio.stream.input.FileImageInputStreamExt) FileImageInputStreamExtImpl(it.geosolutions.imageio.stream.input.FileImageInputStreamExtImpl) File(java.io.File) Test(org.junit.Test)

Example 3 with FileImageInputStreamExtImpl

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();
        }
    }
}
Also used : IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode) Node(org.w3c.dom.Node) MetadataNode(it.geosolutions.imageioimpl.plugins.tiff.TIFFStreamMetadata.MetadataNode) NodeList(org.w3c.dom.NodeList) 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) IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode) MetadataNode(it.geosolutions.imageioimpl.plugins.tiff.TIFFStreamMetadata.MetadataNode) IIOMetadata(javax.imageio.metadata.IIOMetadata) ImageReadParam(javax.imageio.ImageReadParam) FileImageInputStreamExt(it.geosolutions.imageio.stream.input.FileImageInputStreamExt) FileImageInputStreamExtImpl(it.geosolutions.imageio.stream.input.FileImageInputStreamExtImpl) File(java.io.File) Test(org.junit.Test)

Example 4 with FileImageInputStreamExtImpl

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());
}
Also used : RenderedOp(javax.media.jai.RenderedOp) ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) FileImageInputStreamExtImpl(it.geosolutions.imageio.stream.input.FileImageInputStreamExtImpl) File(java.io.File) AbstractGDALTest(it.geosolutions.imageio.gdalframework.AbstractGDALTest) Test(org.junit.Test)

Example 5 with FileImageInputStreamExtImpl

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;
}
Also used : FileImageInputStreamExtImpl(it.geosolutions.imageio.stream.input.FileImageInputStreamExtImpl) IOException(java.io.IOException) IOException(java.io.IOException)

Aggregations

FileImageInputStreamExtImpl (it.geosolutions.imageio.stream.input.FileImageInputStreamExtImpl)13 File (java.io.File)12 Test (org.junit.Test)9 IOException (java.io.IOException)7 FileImageInputStreamExt (it.geosolutions.imageio.stream.input.FileImageInputStreamExt)4 AbstractGDALTest (it.geosolutions.imageio.gdalframework.AbstractGDALTest)3 HeadlessException (java.awt.HeadlessException)3 FileNotFoundException (java.io.FileNotFoundException)3 MalformedURLException (java.net.MalformedURLException)3 ParameterBlockJAI (javax.media.jai.ParameterBlockJAI)3 RenderedOp (javax.media.jai.RenderedOp)3 TIFFImageReader (it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader)2 TIFFImageReaderSpi (it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReaderSpi)2 MetadataNode (it.geosolutions.imageioimpl.plugins.tiff.TIFFStreamMetadata.MetadataNode)2 Rectangle (java.awt.Rectangle)2 BufferedImage (java.awt.image.BufferedImage)2 URI (java.net.URI)2 ImageReadParam (javax.imageio.ImageReadParam)2 IIOMetadata (javax.imageio.metadata.IIOMetadata)2 IIOMetadataNode (javax.imageio.metadata.IIOMetadataNode)2