Search in sources :

Example 16 with RenderedOp

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

the class RpftocVrtTest method read.

@Test
public void read() throws FileNotFoundException, IOException {
    if (!isGDALAvailable) {
        return;
    }
    TestData.unzipFile(this, "rpftoc.zip");
    File file = TestData.file(this, fileName);
    // ////////////////////////////////////////////////////////////////
    // 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 {
        Assert.assertTrue(image.getWidth() == 768);
        Assert.assertTrue(image.getHeight() == 768);
    }
    ImageIOUtilities.disposeImage(image);
}
Also used : ImageReadParam(javax.imageio.ImageReadParam) 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 17 with RenderedOp

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

the class Doq2VrtTest method imageRead.

/**
 * Test read exploiting common JAI operations (Crop-Translate-Rotate)
 *
 * @throws FileNotFoundException
 * @throws IOException
 */
@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);
    // NOTE that the actual sample data (fakedoq1.doq) only contains a row.
    // Therefore, we need to force the read on that reduced area.
    // Requesting a bigger image height will result in a GDAL ReadBlock error.
    irp.setSourceRegion(new Rectangle(0, 0, 500, 1));
    final ImageLayout l = new ImageLayout();
    l.setTileGridXOffset(0).setTileGridYOffset(0).setTileHeight(512).setTileWidth(512);
    // get a RenderedImage
    RenderedOp image = JAI.create("ImageRead", pbjImageRead, new RenderingHints(JAI.KEY_IMAGE_LAYOUT, l));
    if (TestData.isInteractiveTest()) {
        Viewer.visualizeAllInformation(image, "test");
    } else {
        Assert.assertNotNull(image.getTiles());
    }
    Assert.assertEquals(500, image.getWidth());
    Assert.assertEquals(1, 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) Test(org.junit.Test) AbstractGDALTest(it.geosolutions.imageio.gdalframework.AbstractGDALTest)

Example 18 with RenderedOp

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

the class MrSIDTest method subBandsRead.

/**
 * Test read exploiting the setSourceBands and setDestinationType on
 * imageReadParam
 *
 * @throws FileNotFoundException
 * @throws IOException
 */
@Test
public void subBandsRead() throws IOException {
    if (!isMrSidAvailable) {
        return;
    }
    try {
        ImageReader reader = new MrSIDImageReaderSpi().createReaderInstance();
        final File file = TestData.file(this, fileName);
        reader.setInput(file);
        // //
        // 
        // Getting image properties
        // 
        // //
        ImageTypeSpecifier spec = (ImageTypeSpecifier) reader.getImageTypes(0).next();
        SampleModel sm = spec.getSampleModel();
        final int width = reader.getWidth(0);
        final int height = reader.getHeight(0);
        // //
        // 
        // Setting a ColorModel
        // 
        // //
        ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
        ColorModel cm = RasterFactory.createComponentColorModel(sm.getDataType(), // color space
        cs, // has alpha
        false, // is alphaPremultiplied
        false, // transparency
        Transparency.OPAQUE);
        // //
        // 
        // Setting Image Read Parameters
        // 
        // //
        final ImageReadParam param = new ImageReadParam();
        final int ssx = 2;
        final int ssy = 2;
        param.setSourceSubsampling(ssx, ssy, 0, 0);
        final Rectangle sourceRegion = new Rectangle(50, 50, 300, 300);
        param.setSourceRegion(sourceRegion);
        param.setSourceBands(new int[] { 0 });
        Rectangle intersRegion = new Rectangle(0, 0, width, height);
        intersRegion = intersRegion.intersection(sourceRegion);
        int subsampledWidth = (intersRegion.width + ssx - 1) / ssx;
        int subsampledHeight = (intersRegion.height + ssy - 1) / ssy;
        param.setDestinationType(new ImageTypeSpecifier(cm, sm.createCompatibleSampleModel(subsampledWidth, subsampledHeight).createSubsetSampleModel(new int[] { 0 })));
        // //
        // 
        // Preparing the ImageRead operation
        // 
        // //
        ParameterBlockJAI pbjImageRead = new ParameterBlockJAI("ImageRead");
        pbjImageRead.setParameter("Input", file);
        pbjImageRead.setParameter("readParam", param);
        pbjImageRead.setParameter("reader", reader);
        // //
        // 
        // Setting a Layout
        // 
        // //
        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, "SourceBand selection");
        else {
            Assert.assertNotNull(image.getTiles());
            ImageIOUtilities.disposeImage(image);
        }
    } catch (FileNotFoundException fnfe) {
        warningMessage();
    }
}
Also used : ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) ColorSpace(java.awt.color.ColorSpace) Rectangle(java.awt.Rectangle) FileNotFoundException(java.io.FileNotFoundException) ImageTypeSpecifier(javax.imageio.ImageTypeSpecifier) Point(java.awt.Point) RenderingHints(java.awt.RenderingHints) ImageReadParam(javax.imageio.ImageReadParam) SampleModel(java.awt.image.SampleModel) RenderedOp(javax.media.jai.RenderedOp) ColorModel(java.awt.image.ColorModel) ImageReader(javax.imageio.ImageReader) File(java.io.File) ImageLayout(javax.media.jai.ImageLayout) AbstractGDALTest(it.geosolutions.imageio.gdalframework.AbstractGDALTest) Test(org.junit.Test)

Example 19 with RenderedOp

use of javax.media.jai.RenderedOp 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 20 with RenderedOp

use of javax.media.jai.RenderedOp 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)

Aggregations

RenderedOp (javax.media.jai.RenderedOp)82 File (java.io.File)72 ParameterBlockJAI (javax.media.jai.ParameterBlockJAI)71 Test (org.junit.Test)61 ImageReadParam (javax.imageio.ImageReadParam)48 AbstractGDALTest (it.geosolutions.imageio.gdalframework.AbstractGDALTest)32 ImageWriter (javax.imageio.ImageWriter)28 ImageLayout (javax.media.jai.ImageLayout)28 ImageWriteParam (javax.imageio.ImageWriteParam)23 RenderingHints (java.awt.RenderingHints)21 FileImageOutputStreamExtImpl (it.geosolutions.imageio.stream.output.FileImageOutputStreamExtImpl)20 ImageReader (javax.imageio.ImageReader)14 FileNotFoundException (java.io.FileNotFoundException)13 Rectangle (java.awt.Rectangle)9 IIOMetadata (javax.imageio.metadata.IIOMetadata)5 IOException (java.io.IOException)4 ImageInputStream (javax.imageio.stream.ImageInputStream)4 FileImageInputStreamExtImpl (it.geosolutions.imageio.stream.input.FileImageInputStreamExtImpl)3 ColorSpace (java.awt.color.ColorSpace)3 ColorModel (java.awt.image.ColorModel)3