Search in sources :

Example 11 with TIFFImageReaderSpi

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

the class TIFFWriteTest method readWriteFromFileDirect.

@Test
public void readWriteFromFileDirect() throws IOException {
    // JAI.getDefaultInstance().getTileCache().setMemoryCapacity(512*1024*1024);
    // final TCTool tc= new TCTool((SunTileCache)JAI.getDefaultInstance().getTileCache());
    // new File("c:\\work\\dem30_final.tiff");
    final File inputFile = TestData.file(this, "test.tif");
    final File outputFile = TestData.temp(this, "testw.tif", true);
    final ImageReadParam param = new ImageReadParam();
    param.setSourceRegion(new Rectangle(0, 0, 10, 10));
    TIFFImageReader reader = (TIFFImageReader) new TIFFImageReaderSpi().createReaderInstance();
    reader.setInput(new FileImageInputStream(inputFile));
    BufferedImage image = reader.read(0, param);
    // RenderedImage image = ImageReadDescriptor.create(new FileImageInputStream(inputFile),
    // Integer.valueOf(0), false, false, false, null, null, null,
    // reader, new RenderingHints(JAI.KEY_IMAGE_LAYOUT, new ImageLayout().setTileGridXOffset(0).setTileGridYOffset(0).setTileHeight(512).setTileWidth(512)));
    final TIFFImageWriter writer = (TIFFImageWriter) new TIFFImageWriterSpi().createWriterInstance();
    final ImageWriteParam writeParam = new TIFFImageWriteParam(Locale.getDefault());
    writeParam.setTilingMode(ImageWriteParam.MODE_EXPLICIT);
    writeParam.setTiling(512, 512, 0, 0);
    // for( int i=0;i<1;i++){
    writer.setOutput(new FileImageOutputStream(outputFile));
    // BUG
    // writer.write(metadata, new IIOImage(image, null, metadata), null);
    writer.addIIOWriteProgressListener(new IIOWriteProgressListener() {

        public void writeAborted(ImageWriter source) {
        // TODO Auto-generated method stub
        }

        public void thumbnailStarted(ImageWriter source, int imageIndex, int thumbnailIndex) {
            assertTrue(imageIndex >= 0);
            assertTrue(thumbnailIndex == 0);
        }

        public void thumbnailProgress(ImageWriter source, float percentageDone) {
            assertTrue(percentageDone >= 0 && percentageDone <= 100);
        }

        public void thumbnailComplete(ImageWriter source) {
        // TODO Auto-generated method stub
        }

        public void imageStarted(ImageWriter source, int imageIndex) {
            assertTrue(imageIndex >= 0);
            LOGGER.info("imageStarted");
        }

        public void imageProgress(ImageWriter source, float percentageDone) {
            assertTrue(percentageDone >= 0 && percentageDone <= 100);
            LOGGER.info(percentageDone + "%");
        }

        public void imageComplete(ImageWriter source) {
            LOGGER.info("imageComplete");
        }
    });
    writer.write(null, new IIOImage(image, null, null), writeParam);
    // }
    writer.dispose();
    reader.reset();
    reader.setInput(new FileImageInputStream(outputFile));
    image = reader.read(0);
    Assert.assertEquals(10, image.getWidth());
    Assert.assertEquals(10, image.getHeight());
    image.flush();
    image = null;
    reader.dispose();
}
Also used : TIFFImageWriterSpi(it.geosolutions.imageioimpl.plugins.tiff.TIFFImageWriterSpi) FileImageOutputStream(javax.imageio.stream.FileImageOutputStream) Rectangle(java.awt.Rectangle) TIFFImageWriteParam(it.geosolutions.imageio.plugins.tiff.TIFFImageWriteParam) TIFFImageWriter(it.geosolutions.imageioimpl.plugins.tiff.TIFFImageWriter) ImageWriter(javax.imageio.ImageWriter) TIFFImageWriteParam(it.geosolutions.imageio.plugins.tiff.TIFFImageWriteParam) ImageWriteParam(javax.imageio.ImageWriteParam) TIFFImageReader(it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader) TIFFImageReaderSpi(it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReaderSpi) BufferedImage(java.awt.image.BufferedImage) IIOWriteProgressListener(javax.imageio.event.IIOWriteProgressListener) IIOImage(javax.imageio.IIOImage) FileImageInputStream(javax.imageio.stream.FileImageInputStream) ImageReadParam(javax.imageio.ImageReadParam) TIFFImageWriter(it.geosolutions.imageioimpl.plugins.tiff.TIFFImageWriter) File(java.io.File) 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