Search in sources :

Example 16 with ParameterBlockJAI

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

the class MrSIDTest method metadataAccess.

/**
 * Test retrieving all available metadata properties
 *
 * @throws FileNotFoundException
 * @throws IOException
 */
@Test
public void metadataAccess() throws FileNotFoundException, IOException {
    if (!isMrSidAvailable) {
        return;
    }
    try {
        final File file = TestData.file(this, fileName);
        final ParameterBlockJAI pbjImageRead = new ParameterBlockJAI("ImageRead");
        pbjImageRead.setParameter("Input", file);
        RenderedOp image = JAI.create("ImageRead", pbjImageRead);
        IIOMetadata metadata = (IIOMetadata) image.getProperty(ImageReadDescriptor.PROPERTY_NAME_METADATA_IMAGE);
        Assert.assertTrue(metadata instanceof GDALCommonIIOImageMetadata);
        Assert.assertTrue(metadata instanceof MrSIDIIOImageMetadata);
        GDALCommonIIOImageMetadata commonMetadata = (GDALCommonIIOImageMetadata) metadata;
        ImageIOUtilities.displayImageIOMetadata(commonMetadata.getAsTree(GDALCommonIIOImageMetadata.nativeMetadataFormatName));
        ImageIOUtilities.displayImageIOMetadata(commonMetadata.getAsTree(MrSIDIIOImageMetadata.mrsidImageMetadataName));
        if (TestData.isInteractiveTest())
            Viewer.visualizeAllInformation(image, "", TestData.isInteractiveTest());
        else {
            ImageIOUtilities.disposeImage(image);
        }
    } catch (FileNotFoundException fnfe) {
        warningMessage();
    }
    try {
        final File file = TestData.file(this, fileName);
        ImageReader reader = new MrSIDImageReaderSpi().createReaderInstance();
        reader.setInput(ImageIO.createImageInputStream(file));
        Assert.assertEquals(618, reader.getWidth(0));
        Assert.assertEquals(1265, reader.getHeight(0));
        IIOMetadata metadata = (IIOMetadata) reader.getImageMetadata(0);
        Assert.assertTrue(metadata instanceof GDALCommonIIOImageMetadata);
        Assert.assertTrue(metadata instanceof MrSIDIIOImageMetadata);
        GDALCommonIIOImageMetadata commonMetadata = (GDALCommonIIOImageMetadata) metadata;
        ImageIOUtilities.displayImageIOMetadata(commonMetadata.getAsTree(GDALCommonIIOImageMetadata.nativeMetadataFormatName));
        ImageIOUtilities.displayImageIOMetadata(commonMetadata.getAsTree(MrSIDIIOImageMetadata.mrsidImageMetadataName));
        reader.dispose();
    } catch (FileNotFoundException fnfe) {
        warningMessage();
    }
}
Also used : IIOMetadata(javax.imageio.metadata.IIOMetadata) RenderedOp(javax.media.jai.RenderedOp) ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) FileNotFoundException(java.io.FileNotFoundException) GDALCommonIIOImageMetadata(it.geosolutions.imageio.gdalframework.GDALCommonIIOImageMetadata) ImageReader(javax.imageio.ImageReader) File(java.io.File) AbstractGDALTest(it.geosolutions.imageio.gdalframework.AbstractGDALTest) Test(org.junit.Test)

Example 17 with ParameterBlockJAI

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

the class SPRTest method read.

@Test
public void read() throws FileNotFoundException, IOException {
    if (!isGDALAvailable) {
        return;
    }
    File file;
    try {
        file = TestData.file(this, fileName);
    } catch (FileNotFoundException fnfe) {
        warningMessage();
        return;
    }
    // ////////////////////////////////////////////////////////////////
    // preparing to read
    // ////////////////////////////////////////////////////////////////
    final ParameterBlockJAI pbjImageRead;
    final ImageReadParam irp = new ImageReadParam();
    // subsample by 2 on both dimensions
    final int xSubSampling = 2;
    final int ySubSampling = 2;
    final int xSubSamplingOffset = 0;
    final int ySubSamplingOffset = 0;
    irp.setSourceSubsampling(xSubSampling, ySubSampling, xSubSamplingOffset, ySubSamplingOffset);
    pbjImageRead = new ParameterBlockJAI("ImageRead");
    pbjImageRead.setParameter("Input", file);
    pbjImageRead.setParameter("readParam", irp);
    // get a RenderedImage
    RenderedOp image = JAI.create("ImageRead", pbjImageRead);
    if (TestData.isInteractiveTest())
        Viewer.visualizeAllInformation(image, "Subsampling Read");
    else {
        Raster[] io = image.getTiles();
        Assert.assertNotNull(io);
        Assert.assertEquals(64, image.getWidth());
        Assert.assertEquals(64, image.getHeight());
    }
    ImageIOUtilities.disposeImage(image);
}
Also used : ImageReadParam(javax.imageio.ImageReadParam) RenderedOp(javax.media.jai.RenderedOp) ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) Raster(java.awt.image.Raster) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) Test(org.junit.Test) AbstractGDALTest(it.geosolutions.imageio.gdalframework.AbstractGDALTest)

Example 18 with ParameterBlockJAI

use of javax.media.jai.ParameterBlockJAI 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 19 with ParameterBlockJAI

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

the class JP2KReadTest method jaiOperations.

/**
 * Test read exploiting common JAI operations (Crop-Translate-Rotate)
 *
 * @throws FileNotFoundException
 * @throws IOException
 */
@Test
public void jaiOperations() throws IOException {
    if (!isJp2MrSidDriverAvailable) {
        return;
    }
    final File inputFile = TestData.file(this, fileName);
    // ////////////////////////////////////////////////////////////////
    // preparing to read
    // ////////////////////////////////////////////////////////////////
    final ParameterBlockJAI pbjImageRead;
    final ImageReadParam irp = new ImageReadParam();
    Integer xSubSampling = new Integer(2);
    Integer ySubSampling = new Integer(2);
    Integer xSubSamplingOffset = new Integer(0);
    Integer ySubSamplingOffset = new Integer(0);
    irp.setSourceSubsampling(xSubSampling.intValue(), ySubSampling.intValue(), xSubSamplingOffset.intValue(), ySubSamplingOffset.intValue());
    pbjImageRead = new ParameterBlockJAI("ImageRead");
    pbjImageRead.setParameter("Input", inputFile);
    pbjImageRead.setParameter("readParam", irp);
    pbjImageRead.setParameter("Reader", new JP2GDALMrSidImageReaderSpi().createReaderInstance());
    final ImageLayout layout = new ImageLayout();
    layout.setTileGridXOffset(0).setTileGridYOffset(0).setTileHeight(512).setTileWidth(512);
    RenderedOp image = JAI.create("ImageRead", pbjImageRead, new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout));
    if (TestData.isInteractiveTest())
        Viewer.visualizeAllInformation(image, "subsampled");
    // ////////////////////////////////////////////////////////////////
    // preparing to crop
    // ////////////////////////////////////////////////////////////////
    final ParameterBlockJAI pbjCrop = new ParameterBlockJAI("Crop");
    pbjCrop.addSource(image);
    // Setting a square crop to avoid blanks zone when rotating.
    Float xCrop = new Float(image.getMinX() + image.getWidth() / 4);
    Float yCrop = new Float(image.getMinX() + image.getWidth() / 4);
    Float cropWidth = new Float(image.getWidth() / 4);
    Float cropHeigth = new Float(image.getWidth() / 4);
    pbjCrop.setParameter("x", xCrop);
    pbjCrop.setParameter("y", yCrop);
    pbjCrop.setParameter("width", cropWidth);
    pbjCrop.setParameter("height", cropHeigth);
    final RenderedOp croppedImage = JAI.create("Crop", pbjCrop);
    if (TestData.isInteractiveTest())
        Viewer.visualizeAllInformation(croppedImage, "cropped");
    // ////////////////////////////////////////////////////////////////
    // preparing to translate
    // ////////////////////////////////////////////////////////////////
    final ParameterBlockJAI pbjTranslate = new ParameterBlockJAI("Translate");
    pbjTranslate.addSource(croppedImage);
    Float xTrans = new Float(xCrop.floatValue() * (-1));
    Float yTrans = new Float(yCrop.floatValue() * (-1));
    pbjTranslate.setParameter("xTrans", xTrans);
    pbjTranslate.setParameter("yTrans", yTrans);
    final RenderedOp translatedImage = JAI.create("Translate", pbjTranslate);
    if (TestData.isInteractiveTest())
        Viewer.visualizeAllInformation(translatedImage, "translated");
    // ////////////////////////////////////////////////////////////////
    // preparing to rotate
    // ////////////////////////////////////////////////////////////////
    final ParameterBlockJAI pbjRotate = new ParameterBlockJAI("Rotate");
    pbjRotate.addSource(translatedImage);
    Float xOrigin = new Float(cropWidth.floatValue() / 2);
    Float yOrigin = new Float(cropHeigth.floatValue() / 2);
    Float angle = new Float(java.lang.Math.PI / 2);
    pbjRotate.setParameter("xOrigin", xOrigin);
    pbjRotate.setParameter("yOrigin", yOrigin);
    pbjRotate.setParameter("angle", angle);
    final RenderedOp rotatedImage = JAI.create("Rotate", pbjRotate);
    StringBuilder title = new StringBuilder("SUBSAMP:").append("X[").append(xSubSampling.toString()).append("]-Y[").append(ySubSampling.toString()).append("]-Xof[").append(xSubSamplingOffset.toString()).append("]-Yof[").append(ySubSamplingOffset).append("]CROP:X[").append(xCrop.toString()).append("]-Y[").append(yCrop.toString()).append("]-W[").append(cropWidth.toString()).append("]-H[").append(cropHeigth.toString()).append("]TRANS:X[").append(xTrans.toString()).append("]-Y[").append(yTrans.toString()).append("]ROTATE:xOrig[").append(xOrigin.toString()).append("]-yOrig[").append(yOrigin.toString()).append("]-ang[").append(angle.toString()).append("]");
    if (TestData.isInteractiveTest())
        Viewer.visualizeAllInformation(rotatedImage, title.toString());
    else
        Assert.assertNotNull(rotatedImage.getTiles());
    ImageIOUtilities.disposeImage(rotatedImage);
}
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) RenderingHints(java.awt.RenderingHints) Test(org.junit.Test) AbstractGDALTest(it.geosolutions.imageio.gdalframework.AbstractGDALTest)

Example 20 with ParameterBlockJAI

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

the class JP2KReadTest method testRead.

/**
 * Simple test read
 *
 * @throws FileNotFoundException
 * @throws IOException
 */
@org.junit.Test
public void testRead() throws FileNotFoundException, IOException {
    if (!isJP2ECWAvailable) {
        return;
    }
    final ParameterBlockJAI pbjImageRead;
    final File file = TestData.file(this, fileName);
    pbjImageRead = new ParameterBlockJAI("ImageRead");
    pbjImageRead.setParameter("Input", file);
    pbjImageRead.setParameter("Reader", new JP2GDALEcwImageReaderSpi().createReaderInstance());
    final ImageLayout layout = new ImageLayout();
    layout.setTileGridXOffset(0).setTileGridYOffset(0).setTileHeight(256).setTileWidth(256);
    RenderedOp image = JAI.create("ImageRead", pbjImageRead, new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout));
    if (TestData.isInteractiveTest())
        Viewer.visualizeAllInformation(image, "gdaljp2k");
    else
        Assert.assertNotNull(image.getTiles());
    ImageIOUtilities.disposeImage(image);
}
Also used : RenderedOp(javax.media.jai.RenderedOp) ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) File(java.io.File) ImageLayout(javax.media.jai.ImageLayout) RenderingHints(java.awt.RenderingHints)

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