Search in sources :

Example 1 with TIFFImageReaderSpi

use of it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReaderSpi in project imageio-ext by geosolutions-it.

the class TIFFWriteTest method readFromFileJAI.

@Test
public void readFromFileJAI() throws IOException {
    final File file = TestData.file(this, "test.tif");
    // double sum = 0;
    // final long num = 10000l;
    // for (long i = 0; i < num; i++) {
    // final double time = System.nanoTime();
    // IMAGE 0
    RenderedImage image = ImageReadDescriptor.create(new FileImageInputStream(file), Integer.valueOf(0), false, false, false, null, null, null, new TIFFImageReaderSpi().createReaderInstance(), null);
    if (TestData.isInteractiveTest())
        ImageIOUtilities.visualize(image, "testManualRead");
    else
        Assert.assertNotNull(PlanarImage.wrapRenderedImage(image).getTiles());
    // sum += System.nanoTime() - time;
    Assert.assertEquals(30, image.getWidth());
    Assert.assertEquals(26, image.getHeight());
    PlanarImage.wrapRenderedImage(image).dispose();
    image = null;
    // }
    // IMAGE 2
    final ImageReadParam readParam = new ImageReadParam();
    readParam.setSourceRegion(new Rectangle(0, 0, 10, 10));
    image = ImageReadDescriptor.create(new FileImageInputStream(file), Integer.valueOf(2), false, false, false, null, null, readParam, new TIFFImageReaderSpi().createReaderInstance(), null);
    if (TestData.isInteractiveTest())
        ImageIOUtilities.visualize(image, "testManualRead");
    else
        Assert.assertNotNull(image.getData());
    // sum+=System.nanoTime()-time;
    Assert.assertEquals(8, image.getWidth());
    Assert.assertEquals(7, image.getHeight());
    PlanarImage.wrapRenderedImage(image).dispose();
    image = null;
    // IMAGE 4
    image = ImageReadDescriptor.create(new FileImageInputStream(file), Integer.valueOf(4), false, false, false, null, null, null, new TIFFImageReaderSpi().createReaderInstance(), null);
    if (TestData.isInteractiveTest())
        ImageIOUtilities.visualize(image, "testManualRead");
    else
        Assert.assertNotNull(image.getData());
    // sum+=System.nanoTime()-time;
    Assert.assertEquals(2, image.getWidth());
    Assert.assertEquals(2, image.getHeight());
    PlanarImage.wrapRenderedImage(image).dispose();
    image = null;
    // IMAGE 1
    image = ImageReadDescriptor.create(new FileImageInputStream(file), Integer.valueOf(1), false, false, false, null, null, null, new TIFFImageReaderSpi().createReaderInstance(), null);
    if (TestData.isInteractiveTest())
        ImageIOUtilities.visualize(image, "testManualRead");
    else
        Assert.assertNotNull(image.getData());
    // sum+=System.nanoTime()-time;
    Assert.assertEquals(15, image.getWidth());
    Assert.assertEquals(13, image.getHeight());
    PlanarImage.wrapRenderedImage(image).dispose();
    image = null;
    // IMAGE 3
    image = ImageReadDescriptor.create(new FileImageInputStream(file), Integer.valueOf(3), false, false, false, null, null, null, new TIFFImageReaderSpi().createReaderInstance(), null);
    if (TestData.isInteractiveTest())
        ImageIOUtilities.visualize(image, "testManualRead");
    else
        Assert.assertNotNull(image.getData());
    // sum+=System.nanoTime()-time;
    Assert.assertEquals(4, image.getWidth());
    Assert.assertEquals(4, image.getHeight());
    PlanarImage.wrapRenderedImage(image).dispose();
    image = null;
    // IMAGE 5
    image = ImageReadDescriptor.create(new FileImageInputStream(file), Integer.valueOf(5), false, false, false, null, null, null, new TIFFImageReaderSpi().createReaderInstance(), null);
    if (TestData.isInteractiveTest())
        ImageIOUtilities.visualize(image, "testManualRead");
    else
        Assert.assertNotNull(image.getData());
    // sum+=System.nanoTime()-time;
    Assert.assertEquals(1, image.getWidth());
    Assert.assertEquals(1, image.getHeight());
    PlanarImage.wrapRenderedImage(image).dispose();
    image = null;
// IMAGE 7
}
Also used : FileImageInputStream(javax.imageio.stream.FileImageInputStream) ImageReadParam(javax.imageio.ImageReadParam) Rectangle(java.awt.Rectangle) RenderedImage(java.awt.image.RenderedImage) File(java.io.File) TIFFImageReaderSpi(it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReaderSpi) Test(org.junit.Test)

Example 2 with TIFFImageReaderSpi

use of it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReaderSpi 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 TIFFImageReaderSpi

use of it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReaderSpi 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();
        }
    }
}
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) FileImageInputStream(javax.imageio.stream.FileImageInputStream) IIOMetadata(javax.imageio.metadata.IIOMetadata) ImageReadParam(javax.imageio.ImageReadParam) File(java.io.File) Test(org.junit.Test)

Example 4 with TIFFImageReaderSpi

use of it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReaderSpi in project imageio-ext by geosolutions-it.

the class TIFFReadTest method readFromFileJAI.

@Test
public void readFromFileJAI() throws IOException {
    final File file = TestData.file(this, "test.tif");
    // double sum = 0;
    // final long num = 10000l;
    // for (long i = 0; i < num; i++) {
    // final double time = System.nanoTime();
    // IMAGE 0
    RenderedImage image = ImageReadDescriptor.create(new FileImageInputStream(file), Integer.valueOf(0), false, false, false, null, null, null, new TIFFImageReaderSpi().createReaderInstance(), null);
    if (TestData.isInteractiveTest())
        ImageIOUtilities.visualize(image, "testManualRead");
    else
        Assert.assertNotNull(PlanarImage.wrapRenderedImage(image).getTiles());
    // sum += System.nanoTime() - time;
    Assert.assertEquals(30, image.getWidth());
    Assert.assertEquals(26, image.getHeight());
    PlanarImage.wrapRenderedImage(image).dispose();
    image = null;
    // }
    // IMAGE 2
    final ImageReadParam readParam = new ImageReadParam();
    readParam.setSourceRegion(new Rectangle(0, 0, 10, 10));
    image = ImageReadDescriptor.create(new FileImageInputStream(file), Integer.valueOf(2), false, false, false, null, null, readParam, new TIFFImageReaderSpi().createReaderInstance(), null);
    if (TestData.isInteractiveTest())
        ImageIOUtilities.visualize(image, "testManualRead");
    else
        Assert.assertNotNull(image.getData());
    // sum+=System.nanoTime()-time;
    Assert.assertEquals(8, image.getWidth());
    Assert.assertEquals(7, image.getHeight());
    PlanarImage.wrapRenderedImage(image).dispose();
    image = null;
    // IMAGE 4
    image = ImageReadDescriptor.create(new FileImageInputStream(file), Integer.valueOf(4), false, false, false, null, null, null, new TIFFImageReaderSpi().createReaderInstance(), null);
    if (TestData.isInteractiveTest())
        ImageIOUtilities.visualize(image, "testManualRead");
    else
        Assert.assertNotNull(image.getData());
    // sum+=System.nanoTime()-time;
    Assert.assertEquals(2, image.getWidth());
    Assert.assertEquals(2, image.getHeight());
    PlanarImage.wrapRenderedImage(image).dispose();
    image = null;
    // IMAGE 5
    image = ImageReadDescriptor.create(new FileImageInputStream(file), Integer.valueOf(5), false, false, false, null, null, null, new TIFFImageReaderSpi().createReaderInstance(), null);
    if (TestData.isInteractiveTest())
        ImageIOUtilities.visualize(image, "testManualRead");
    else
        Assert.assertNotNull(image.getData());
    // sum+=System.nanoTime()-time;
    Assert.assertEquals(1, image.getWidth());
    Assert.assertEquals(1, image.getHeight());
    PlanarImage.wrapRenderedImage(image).dispose();
    image = null;
    // IMAGE 1
    image = ImageReadDescriptor.create(new FileImageInputStream(file), Integer.valueOf(1), false, false, false, null, null, null, new TIFFImageReaderSpi().createReaderInstance(), null);
    if (TestData.isInteractiveTest())
        ImageIOUtilities.visualize(image, "testManualRead");
    else
        Assert.assertNotNull(image.getData());
    // sum+=System.nanoTime()-time;
    Assert.assertEquals(15, image.getWidth());
    Assert.assertEquals(13, image.getHeight());
    PlanarImage.wrapRenderedImage(image).dispose();
    image = null;
    // IMAGE 3
    image = ImageReadDescriptor.create(new FileImageInputStream(file), Integer.valueOf(3), false, false, false, null, null, null, new TIFFImageReaderSpi().createReaderInstance(), null);
    if (TestData.isInteractiveTest())
        ImageIOUtilities.visualize(image, "testManualRead");
    else
        Assert.assertNotNull(image.getData());
    // sum+=System.nanoTime()-time;
    Assert.assertEquals(4, image.getWidth());
    Assert.assertEquals(4, image.getHeight());
    PlanarImage.wrapRenderedImage(image).dispose();
    image = null;
    // IMAGE 5
    image = ImageReadDescriptor.create(new FileImageInputStream(file), Integer.valueOf(5), false, false, false, null, null, null, new TIFFImageReaderSpi().createReaderInstance(), null);
    if (TestData.isInteractiveTest())
        ImageIOUtilities.visualize(image, "testManualRead");
    else
        Assert.assertNotNull(image.getData());
    // sum+=System.nanoTime()-time;
    Assert.assertEquals(1, image.getWidth());
    Assert.assertEquals(1, image.getHeight());
    PlanarImage.wrapRenderedImage(image).dispose();
    image = null;
}
Also used : FileImageInputStream(javax.imageio.stream.FileImageInputStream) ImageReadParam(javax.imageio.ImageReadParam) Rectangle(java.awt.Rectangle) RenderedImage(java.awt.image.RenderedImage) File(java.io.File) TIFFImageReaderSpi(it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReaderSpi) Test(org.junit.Test)

Example 5 with TIFFImageReaderSpi

use of it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReaderSpi in project imageio-ext by geosolutions-it.

the class TIFFReadTest method readLZWWithHorizontalDifferencingPredictorOn16Bits.

@Test
public void readLZWWithHorizontalDifferencingPredictorOn16Bits() throws IOException {
    // This image has been created from test.tif using the command:
    // gdal_translate -OT UInt16 -co COMPRESS=LZW -co PREDICTOR=2 test.tif lzwtest.tif
    final File file = TestData.file(this, "lzwtest.tif");
    final TIFFImageReader reader = (TIFFImageReader) new TIFFImageReaderSpi().createReaderInstance();
    FileImageInputStream inputStream = new FileImageInputStream(file);
    try {
        reader.setInput(inputStream);
        BufferedImage image = reader.read(0);
        image.flush();
        image = null;
    } finally {
        if (inputStream != null) {
            inputStream.flush();
            inputStream.close();
        }
        if (reader != null) {
            reader.dispose();
        }
    }
}
Also used : FileImageInputStream(javax.imageio.stream.FileImageInputStream) File(java.io.File) TIFFImageReader(it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader) TIFFImageReaderSpi(it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReaderSpi) BufferedImage(java.awt.image.BufferedImage) Test(org.junit.Test)

Aggregations

TIFFImageReaderSpi (it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReaderSpi)11 File (java.io.File)11 Test (org.junit.Test)11 TIFFImageReader (it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader)9 FileImageInputStream (javax.imageio.stream.FileImageInputStream)9 Rectangle (java.awt.Rectangle)8 BufferedImage (java.awt.image.BufferedImage)8 ImageReadParam (javax.imageio.ImageReadParam)8 IOException (java.io.IOException)6 MetadataNode (it.geosolutions.imageioimpl.plugins.tiff.TIFFStreamMetadata.MetadataNode)4 IIOMetadata (javax.imageio.metadata.IIOMetadata)4 IIOMetadataNode (javax.imageio.metadata.IIOMetadataNode)4 Node (org.w3c.dom.Node)4 RenderedImage (java.awt.image.RenderedImage)3 NodeList (org.w3c.dom.NodeList)3 FileImageInputStreamExt (it.geosolutions.imageio.stream.input.FileImageInputStreamExt)2 FileImageInputStreamExtImpl (it.geosolutions.imageio.stream.input.FileImageInputStreamExtImpl)2 CoreCommonImageMetadata (it.geosolutions.imageio.core.CoreCommonImageMetadata)1 TIFFImageReadParam (it.geosolutions.imageio.plugins.tiff.TIFFImageReadParam)1 TIFFImageWriteParam (it.geosolutions.imageio.plugins.tiff.TIFFImageWriteParam)1