Search in sources :

Example 51 with ParameterBlockJAI

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

the class NITFTest method testJaiOperations.

/**
 * Test read exploiting common JAI operations (Crop-Translate-Rotate)
 *
 * @throws FileNotFoundException
 * @throws IOException
 */
@Test
public void testJaiOperations() 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
        Assert.assertNotNull(image.getTiles());
    ImageIOUtilities.disposeImage(image);
}
Also used : ImageReadParam(javax.imageio.ImageReadParam) RenderedOp(javax.media.jai.RenderedOp) ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) Test(org.junit.Test) AbstractGDALTest(it.geosolutions.imageio.gdalframework.AbstractGDALTest)

Example 52 with ParameterBlockJAI

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

the class ImageIOExtTest method testImageReadMT.

@org.junit.Test
public void testImageReadMT() {
    ImageReadDescriptorMT.register(JAI.getDefaultInstance());
    final ParameterBlockJAI pbj = new ParameterBlockJAI("ImageReadMT");
    Assert.assertNotNull(pbj);
}
Also used : ParameterBlockJAI(javax.media.jai.ParameterBlockJAI)

Example 53 with ParameterBlockJAI

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

the class AsciiGridTest method testReadAsEsriAndWriteAsGrass.

/**
 * Read an ESRI ArcGrid file and write it back as GRASS
 */
public void testReadAsEsriAndWriteAsGrass() throws FileNotFoundException, IOException {
    String title = new String("Simple JAI ImageRead operation test");
    File testFile = TestData.file(this, "095b_dem_90m.asc");
    ParameterBlockJAI pbjImageRead = new ParameterBlockJAI("ImageRead");
    pbjImageRead.setParameter("Input", testFile);
    RenderedOp image = JAI.create("ImageRead", pbjImageRead);
    if (TestData.isInteractiveTest()) {
        ImageIOUtilities.visualize(image, title, true);
    } else {
        assertNotNull(image.getTiles());
    }
    // //
    // 
    // Writing it out
    // 
    // //
    final File foutput = TestData.temp(this, "file.asc", true);
    final ParameterBlockJAI pbjImageWrite = new ParameterBlockJAI("ImageWrite");
    pbjImageWrite.setParameter("Output", foutput);
    pbjImageWrite.addSource(image);
    final ImageReader reader = (ImageReader) image.getProperty(ImageReadDescriptor.PROPERTY_NAME_IMAGE_READER);
    final AsciiGridRaster raster = ((AsciiGridsImageReader) reader).getRasterReader();
    AsciiGridsImageMetadata grassMetadata = new AsciiGridsImageMetadata(raster.getNCols(), raster.getNRows(), raster.getCellSizeX(), raster.getCellSizeY(), raster.getXllCellCoordinate(), raster.getYllCellCoordinate(), raster.isCorner(), true, raster.getNoData());
    // writer.write (new IIOImage(image, null, grassMetadata));
    // writer.dispose();
    pbjImageWrite.setParameter("ImageMetadata", grassMetadata);
    pbjImageWrite.setParameter("Transcode", false);
    // //
    // 
    // What I am doing here is crucial, that is getting the used writer and
    // disposing it. This will force the underlying stream to write data on
    // disk.
    // 
    // //
    final RenderedOp op = JAI.create("ImageWrite", pbjImageWrite);
    final ImageWriter writer = (ImageWriter) op.getProperty(ImageWriteDescriptor.PROPERTY_NAME_IMAGE_WRITER);
    writer.dispose();
    // //
    // 
    // Reading it back
    // 
    // //
    pbjImageRead = new ParameterBlockJAI("ImageRead");
    pbjImageRead.setParameter("Input", foutput);
    RenderedOp image2 = JAI.create("ImageRead", pbjImageRead);
    title = new String("Read Back the just written image");
    if (TestData.isInteractiveTest()) {
        ImageIOUtilities.visualize(image2, title, true);
    } else {
        assertNotNull(image2.getTiles());
    }
    final String[] error = new String[1];
    final boolean result = compare(image, image2, error, raster.getNoData());
    assertTrue(error[0], result);
}
Also used : RenderedOp(javax.media.jai.RenderedOp) ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) ImageWriter(javax.imageio.ImageWriter) ImageReader(javax.imageio.ImageReader) File(java.io.File) AsciiGridRaster(it.geosolutions.imageio.plugins.arcgrid.raster.AsciiGridRaster)

Example 54 with ParameterBlockJAI

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

the class AsciiGridTest method testReadWrite.

/**
 * Read an ArcGrid file and write it back to another file
 */
public void testReadWrite() throws FileNotFoundException, IOException {
    String title = new String("Simple JAI ImageRead operation test");
    final String[] files = TestData.file(this, ".").list(new FilenameFilter() {

        public boolean accept(File dir, String name) {
            return name.endsWith("asc") | name.endsWith("arx");
        }
    });
    File inputDirectory = TestData.file(this, ".");
    for (String fileName : files) {
        ParameterBlockJAI pbjImageRead = new ParameterBlockJAI("ImageRead");
        pbjImageRead.setParameter("Input", new File(inputDirectory, fileName));
        RenderedOp image = JAI.create("ImageRead", pbjImageRead);
        if (TestData.isInteractiveTest())
            ImageIOUtilities.visualize(image, title, true);
        else
            image.getTiles();
        // //
        // 
        // Writing it out
        // 
        // //
        final File foutput = TestData.temp(this, "file.asc", true);
        final ParameterBlockJAI pbjImageWrite = new ParameterBlockJAI("ImageWrite");
        pbjImageWrite.setParameter("Output", foutput);
        pbjImageWrite.addSource(image);
        // //
        // 
        // What I am doing here is crucial, that is getting the used writer and
        // disposing it. This will force the underlying stream to write data on
        // disk.
        // 
        // //
        final RenderedOp op = JAI.create("ImageWrite", pbjImageWrite);
        final ImageWriter writer = (ImageWriter) op.getProperty(ImageWriteDescriptor.PROPERTY_NAME_IMAGE_WRITER);
        writer.dispose();
        // //
        // 
        // Reading it back
        // 
        // //
        pbjImageRead = new ParameterBlockJAI("ImageRead");
        pbjImageRead.setParameter("Input", foutput);
        RenderedOp image2 = JAI.create("ImageRead", pbjImageRead);
        title = new String("Read Back the just written image");
        if (TestData.isInteractiveTest())
            ImageIOUtilities.visualize(image, title, true);
        else
            Assert.assertNotNull(image2.getTiles());
        final String[] error = new String[1];
        final boolean result = compare(image, image2, error);
        assertTrue(error[0], result);
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) RenderedOp(javax.media.jai.RenderedOp) ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) ImageWriter(javax.imageio.ImageWriter) File(java.io.File)

Example 55 with ParameterBlockJAI

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

the class AsciiGridTest method testReadRegionAndMetadata.

/**
 * Read a file using subSampling and sourceRegion settings
 */
public void testReadRegionAndMetadata() throws FileNotFoundException, IOException {
    String title = new String("JAI ImageRead using subSampling and sourceRegion ");
    LOGGER.info("\n\n " + title + " \n");
    // 
    // DEM.asc
    // 
    // 
    // Preparing ImageRead parameters
    // 
    File inputFile = TestData.file(this, "dem.asc");
    ParameterBlockJAI pbjImageRead = new ParameterBlockJAI("ImageRead");
    pbjImageRead.setParameter("Input", inputFile);
    ImageReadParam irp = new ImageReadParam();
    // Setting sourceRegion on the original image
    irp.setSourceRegion(new Rectangle(200, 300, 1000, 1000));
    // Setting subSampling factors
    irp.setSourceSubsampling(2, 2, 0, 0);
    pbjImageRead.setParameter("ReadParam", irp);
    RenderedOp image = JAI.create("ImageRead", pbjImageRead);
    if (TestData.isInteractiveTest())
        ImageIOUtilities.visualize(image, title, true);
    else {
        // load data
        assertNotNull(image.getTiles());
        // chec metadata
        final AsciiGridsImageMetadata metadata = (AsciiGridsImageMetadata) image.getProperty(ImageReadDescriptor.PROPERTY_NAME_METADATA_IMAGE);
        assertNotNull(metadata);
        final Node mf = metadata.getAsTree(metadata.getNativeMetadataFormatName());
        // not grass
        assertEquals(Boolean.parseBoolean(mf.getChildNodes().item(0).getNodeValue()), false);
        // raster space type
        assertEquals(mf.getChildNodes().item(1).getAttributes().getNamedItem("rasterSpaceType").getNodeValue(), RasterSpaceType.PixelIsArea.toString());
        // no data
        assertEquals(mf.getChildNodes().item(1).getAttributes().getNamedItem("noDataValue").getNodeValue(), "-9999.0");
        // width
        assertEquals(mf.getChildNodes().item(1).getAttributes().getNamedItem("nColumns").getNodeValue(), "1404");
        // height
        assertEquals(mf.getChildNodes().item(1).getAttributes().getNamedItem("nRows").getNodeValue(), "1400");
        // cellsizeX
        assertEquals(mf.getChildNodes().item(2).getAttributes().getNamedItem("cellsizeX").getNodeValue(), "22.5");
        // cellsizeY
        assertEquals(mf.getChildNodes().item(2).getAttributes().getNamedItem("cellsizeY").getNodeValue(), "22.5");
        // xll
        assertEquals(mf.getChildNodes().item(2).getAttributes().getNamedItem("xll").getNodeValue(), "969870.0");
        // yll
        assertEquals(mf.getChildNodes().item(2).getAttributes().getNamedItem("yll").getNodeValue(), "642840.0");
    }
    image.dispose();
    // 
    // DEM.asc
    // 
    // 
    // Preparing ImageRead parameters
    // 
    inputFile = TestData.file(this, "spearfish_dem.arx");
    pbjImageRead = new ParameterBlockJAI("ImageRead");
    pbjImageRead.setParameter("Input", inputFile);
    irp = new ImageReadParam();
    // Setting subSampling factors
    irp.setSourceSubsampling(4, 4, 0, 0);
    pbjImageRead.setParameter("ReadParam", irp);
    image = JAI.create("ImageRead", pbjImageRead);
    if (TestData.isInteractiveTest())
        ImageIOUtilities.visualize(image, title, true);
    else {
        // load data
        assertNotNull(image.getTiles());
        // chec metadata
        final AsciiGridsImageMetadata metadata = (AsciiGridsImageMetadata) image.getProperty(ImageReadDescriptor.PROPERTY_NAME_METADATA_IMAGE);
        assertNotNull(metadata);
        final Node mf = metadata.getAsTree(metadata.getNativeMetadataFormatName());
        // not grass
        assertEquals(Boolean.parseBoolean(mf.getChildNodes().item(0).getNodeValue()), false);
        // raster space type
        assertEquals(mf.getChildNodes().item(1).getAttributes().getNamedItem("rasterSpaceType").getNodeValue(), RasterSpaceType.PixelIsArea.toString());
        // no data
        assertEquals(mf.getChildNodes().item(1).getAttributes().getNamedItem("noDataValue").getNodeValue(), "NaN");
        // width
        assertEquals(mf.getChildNodes().item(1).getAttributes().getNamedItem("nColumns").getNodeValue(), "634");
        // height
        assertEquals(mf.getChildNodes().item(1).getAttributes().getNamedItem("nRows").getNodeValue(), "477");
        // cellsizeX
        assertEquals(mf.getChildNodes().item(2).getAttributes().getNamedItem("cellsizeX").getNodeValue(), "30.0");
        // cellsizeY
        assertEquals(mf.getChildNodes().item(2).getAttributes().getNamedItem("cellsizeY").getNodeValue(), "30.0");
        // xll
        assertEquals(mf.getChildNodes().item(2).getAttributes().getNamedItem("xll").getNodeValue(), "589980.0");
        // yll
        assertEquals(mf.getChildNodes().item(2).getAttributes().getNamedItem("yll").getNodeValue(), "4913700.0");
    }
    // 
    // SWAN_NURC_LigurianSeaL07_HSIGN.asc
    // 
    // 
    // Preparing ImageRead parameters
    // 
    inputFile = TestData.file(this, "SWAN_NURC_LigurianSeaL07_HSIGN.asc");
    pbjImageRead = new ParameterBlockJAI("ImageRead");
    pbjImageRead.setParameter("Input", inputFile);
    irp = new ImageReadParam();
    // Setting subSampling factors
    irp.setSourceSubsampling(4, 4, 0, 0);
    pbjImageRead.setParameter("ReadParam", irp);
    image = JAI.create("ImageRead", pbjImageRead);
    if (TestData.isInteractiveTest())
        ImageIOUtilities.visualize(image, title, true);
    else {
        // load data
        assertNotNull(image.getTiles());
        // chec metadata
        final AsciiGridsImageMetadata metadata = (AsciiGridsImageMetadata) image.getProperty(ImageReadDescriptor.PROPERTY_NAME_METADATA_IMAGE);
        assertNotNull(metadata);
        final Node mf = metadata.getAsTree(metadata.getNativeMetadataFormatName());
        // not grass
        assertEquals(Boolean.parseBoolean(mf.getChildNodes().item(0).getNodeValue()), false);
        // raster space type
        assertEquals(mf.getChildNodes().item(1).getAttributes().getNamedItem("rasterSpaceType").getNodeValue(), RasterSpaceType.PixelIsPoint.toString());
        // no data
        assertEquals(mf.getChildNodes().item(1).getAttributes().getNamedItem("noDataValue").getNodeValue(), "-9.0");
        // width
        assertEquals(mf.getChildNodes().item(1).getAttributes().getNamedItem("nColumns").getNodeValue(), "278");
        // height
        assertEquals(mf.getChildNodes().item(1).getAttributes().getNamedItem("nRows").getNodeValue(), "144");
        // cellsizeX
        assertEquals(mf.getChildNodes().item(2).getAttributes().getNamedItem("cellsizeX").getNodeValue(), "0.008999999478566561");
        // cellsizeY
        assertEquals(mf.getChildNodes().item(2).getAttributes().getNamedItem("cellsizeY").getNodeValue(), "0.008999999478566561");
        // xll
        assertEquals(mf.getChildNodes().item(2).getAttributes().getNamedItem("xll").getNodeValue(), "8.118000030517578");
        // yll
        assertEquals(mf.getChildNodes().item(2).getAttributes().getNamedItem("yll").getNodeValue(), "43.191001892089844");
    }
}
Also used : ImageReadParam(javax.imageio.ImageReadParam) RenderedOp(javax.media.jai.RenderedOp) ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) Node(org.w3c.dom.Node) Rectangle(java.awt.Rectangle) File(java.io.File)

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