Search in sources :

Example 36 with ParameterBlockJAI

use of javax.media.jai.ParameterBlockJAI in project imageio-ext by geosolutions-it.

the class JPEGReadTest method multithreadedJAIRead.

/**
 * Simple test read
 *
 * @throws FileNotFoundException
 * @throws IOException
 */
public void multithreadedJAIRead() throws FileNotFoundException, IOException {
    if (!isJmagickAvailable) {
        LOGGER.warning("JMagick Library is not Available; Skipping tests");
        return;
    }
    // register the image read mt operation
    ImageReadDescriptorMT.register(JAI.getDefaultInstance());
    // get the file we are going to read
    final String fileName = "001140.jpg";
    final File file = TestData.file(this, fileName);
    // acquire a reader for it but check that it is the right one
    final Iterator readersIt = ImageIO.getImageReaders(file);
    ImageReader reader = null;
    while (readersIt.hasNext()) {
        reader = (ImageReader) readersIt.next();
        if (reader instanceof JpegJMagickImageReader)
            break;
        reader = null;
    }
    assertNotNull(reader);
    // do an image read with jai
    final ParameterBlockJAI pbjImageRead;
    final ImageReadParam irp = reader.getDefaultReadParam();
    irp.setSourceSubsampling(4, 4, 0, 0);
    pbjImageRead = new ParameterBlockJAI("ImageReadMT");
    pbjImageRead.setParameter("Input", file);
    pbjImageRead.setParameter("Reader", reader);
    pbjImageRead.setParameter("readParam", irp);
    // set the layout so that we shrink the amount of memory needed to load
    // this image
    final ImageLayout l = new ImageLayout();
    l.setTileGridXOffset(0).setTileGridYOffset(0).setTileHeight(512).setTileWidth(512);
    RenderedOp image = JAI.create("ImageReadMT", pbjImageRead, new RenderingHints(JAI.KEY_IMAGE_LAYOUT, l));
    if (TestData.isInteractiveTest()) {
        final JFrame jf = new JFrame();
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jf.getContentPane().add(new ScrollingImagePanel(image, 1024, 768));
        jf.pack();
        jf.show();
    } else {
        assertNotNull(image.getTiles());
        // remember that if we do not explictly provide an Imagereader to
        // the ImageReadMT operation it consistently dispose the one it
        // creates once we dispose the ImageReadOpImage
        image.dispose();
    }
}
Also used : ImageReadParam(javax.imageio.ImageReadParam) RenderedOp(javax.media.jai.RenderedOp) ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) JFrame(javax.swing.JFrame) ScrollingImagePanel(javax.media.jai.widget.ScrollingImagePanel) Iterator(java.util.Iterator) ImageReader(javax.imageio.ImageReader) File(java.io.File) ImageLayout(javax.media.jai.ImageLayout) RenderingHints(java.awt.RenderingHints)

Example 37 with ParameterBlockJAI

use of javax.media.jai.ParameterBlockJAI in project imageio-ext by geosolutions-it.

the class BsbVrtTest method imageRead.

/**
 * Test read exploiting common JAI operations (Crop-Translate-Rotate)
 *
 * @throws FileNotFoundException
 * @throws IOException
 */
@org.junit.Test
public void imageRead() throws FileNotFoundException, IOException {
    if (!isGDALAvailable) {
        return;
    }
    File file = TestData.file(this, fileName);
    // ////////////////////////////////////////////////////////////////
    // preparing to read
    // ////////////////////////////////////////////////////////////////
    final ParameterBlockJAI pbjImageRead;
    final ImageReadParam irp = new ImageReadParam();
    pbjImageRead = new ParameterBlockJAI("ImageRead");
    pbjImageRead.setParameter("Input", file);
    pbjImageRead.setParameter("readParam", irp);
    final ImageLayout l = new ImageLayout();
    l.setTileGridXOffset(0).setTileGridYOffset(0).setTileHeight(32).setTileWidth(32);
    // get a RenderedImage
    RenderedOp image = JAI.create("ImageRead", pbjImageRead, new RenderingHints(JAI.KEY_IMAGE_LAYOUT, l));
    if (TestData.isInteractiveTest()) {
        ImageIOUtilities.visualize(image, "test", true);
    } else {
        Assert.assertNotNull(image.getData());
    }
    Assert.assertEquals(50, image.getWidth());
    Assert.assertEquals(50, image.getHeight());
    ImageIOUtilities.disposeImage(image);
}
Also used : ImageReadParam(javax.imageio.ImageReadParam) RenderedOp(javax.media.jai.RenderedOp) ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) File(java.io.File) ImageLayout(javax.media.jai.ImageLayout)

Example 38 with ParameterBlockJAI

use of javax.media.jai.ParameterBlockJAI in project imageio-ext by geosolutions-it.

the class ErdasImgVrtTest method jaiOperations.

/**
 * Test read exploiting common JAI operations (Crop-Translate-Rotate)
 *
 * @throws FileNotFoundException
 * @throws IOException
 */
@Test
public void jaiOperations() throws FileNotFoundException, IOException {
    if (!isGDALAvailable) {
        return;
    }
    File file = TestData.file(this, fileName);
    // ////////////////////////////////////////////////////////////////
    // preparing to read
    // ////////////////////////////////////////////////////////////////
    final ParameterBlockJAI pbjImageRead;
    pbjImageRead = new ParameterBlockJAI("ImageRead");
    pbjImageRead.setParameter("Input", file);
    // get a RenderedImage
    RenderedOp image = JAI.create("ImageRead", pbjImageRead);
    if (TestData.isInteractiveTest())
        Viewer.visualizeAllInformation(image, "Read");
    else
        Assert.assertNotNull(image.getTiles());
    ImageIOUtilities.disposeImage(image);
}
Also used : RenderedOp(javax.media.jai.RenderedOp) ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) File(java.io.File) Test(org.junit.Test) AbstractGDALTest(it.geosolutions.imageio.gdalframework.AbstractGDALTest)

Example 39 with ParameterBlockJAI

use of javax.media.jai.ParameterBlockJAI in project imageio-ext by geosolutions-it.

the class GeoTiffVrtTest 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.vrt";
    final File file = TestData.file(this, fileName);
    pbjImageRead = new ParameterBlockJAI("ImageRead");
    pbjImageRead.setParameter("Input", new FileImageInputStreamExtImpl(file));
    pbjImageRead.setParameter("Reader", new VRTImageReaderSpi().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 40 with ParameterBlockJAI

use of javax.media.jai.ParameterBlockJAI in project imageio-ext by geosolutions-it.

the class GeoTiffVrtTest method palette.

/**
 * Test Read on a Paletted Image
 *
 * @throws FileNotFoundException
 * @throws IOException
 */
@Test
public void palette() throws FileNotFoundException, IOException {
    if (!isGDALAvailable) {
        return;
    }
    final File outputFile = TestData.temp(this, "writetest.tif", false);
    outputFile.deleteOnExit();
    final File inputFile = TestData.file(this, "paletted.tif.vrt");
    ImageReader reader = new VRTImageReaderSpi().createReaderInstance();
    reader.setInput(inputFile);
    final IIOMetadata metadata = reader.getImageMetadata(0);
    final ParameterBlockJAI pbjImageRead = new ParameterBlockJAI("ImageRead");
    pbjImageRead.setParameter("Input", inputFile);
    pbjImageRead.setParameter("reader", reader);
    final ImageLayout l = new ImageLayout();
    l.setTileGridXOffset(0).setTileGridYOffset(0).setTileHeight(256).setTileWidth(256);
    RenderedOp image = JAI.create("ImageRead", pbjImageRead, new RenderingHints(JAI.KEY_IMAGE_LAYOUT, l));
    if (TestData.isInteractiveTest())
        Viewer.visualizeAllInformation(image, "Paletted image read");
    // ////////////////////////////////////////////////////////////////
    // preparing to write
    // ////////////////////////////////////////////////////////////////
    final ParameterBlockJAI pbjImageWrite = new ParameterBlockJAI("ImageWrite");
    ImageWriter writer = new GeoTiffImageWriterSpi().createWriterInstance();
    pbjImageWrite.setParameter("Output", outputFile);
    pbjImageWrite.setParameter("writer", writer);
    pbjImageWrite.setParameter("ImageMetadata", metadata);
    pbjImageWrite.setParameter("Transcode", false);
    pbjImageWrite.addSource(image);
    final RenderedOp op = JAI.create("ImageWrite", pbjImageWrite);
    final ImageWriter writer2 = (ImageWriter) op.getProperty(ImageWriteDescriptor.PROPERTY_NAME_IMAGE_WRITER);
    writer2.dispose();
    // ////////////////////////////////////////////////////////////////
    // preparing to read again
    // ////////////////////////////////////////////////////////////////
    final ParameterBlockJAI pbjImageReRead = new ParameterBlockJAI("ImageRead");
    pbjImageReRead.setParameter("Input", outputFile);
    pbjImageReRead.setParameter("Reader", new GeoTiffImageReaderSpi().createReaderInstance());
    final RenderedOp image2 = JAI.create("ImageRead", pbjImageReRead);
    if (TestData.isInteractiveTest())
        Viewer.visualizeAllInformation(image2, "Paletted image read back after writing");
    else
        Assert.assertNotNull(image2.getTiles());
    ImageIOUtilities.disposeImage(image2);
    ImageIOUtilities.disposeImage(image);
}
Also used : IIOMetadata(javax.imageio.metadata.IIOMetadata) RenderedOp(javax.media.jai.RenderedOp) ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) ImageWriter(javax.imageio.ImageWriter) GeoTiffImageWriterSpi(it.geosolutions.imageio.plugins.geotiff.GeoTiffImageWriterSpi) ImageReader(javax.imageio.ImageReader) GeoTiffImageReaderSpi(it.geosolutions.imageio.plugins.geotiff.GeoTiffImageReaderSpi) File(java.io.File) ImageLayout(javax.media.jai.ImageLayout) AbstractGDALTest(it.geosolutions.imageio.gdalframework.AbstractGDALTest) Test(org.junit.Test)

Aggregations

ParameterBlockJAI (javax.media.jai.ParameterBlockJAI)76 File (java.io.File)71 RenderedOp (javax.media.jai.RenderedOp)71 Test (org.junit.Test)57 ImageReadParam (javax.imageio.ImageReadParam)48 AbstractGDALTest (it.geosolutions.imageio.gdalframework.AbstractGDALTest)32 ImageWriter (javax.imageio.ImageWriter)28 ImageLayout (javax.media.jai.ImageLayout)26 ImageWriteParam (javax.imageio.ImageWriteParam)23 RenderingHints (java.awt.RenderingHints)22 FileImageOutputStreamExtImpl (it.geosolutions.imageio.stream.output.FileImageOutputStreamExtImpl)20 FileNotFoundException (java.io.FileNotFoundException)13 ImageReader (javax.imageio.ImageReader)13 Rectangle (java.awt.Rectangle)9 IIOMetadata (javax.imageio.metadata.IIOMetadata)5 FileImageInputStreamExtImpl (it.geosolutions.imageio.stream.input.FileImageInputStreamExtImpl)3 ColorSpace (java.awt.color.ColorSpace)3 ColorModel (java.awt.image.ColorModel)3 RenderedImage (java.awt.image.RenderedImage)3 SampleModel (java.awt.image.SampleModel)3