Search in sources :

Example 56 with RenderedOp

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

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

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

Example 59 with RenderedOp

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

the class JP2KWriteTest method write_Qstep.

// ////////////////////////////////////////////////////////////////////////
// 
// Testing "Qstep" Create Option.
// 
// ////////////////////////////////////////////////////////////////////////
@Test
public void write_Qstep() throws IOException, FileNotFoundException {
    if (!isJp2KakDriverAvailable)
        return;
    LOGGER.info("Testing JP2 Write operation with Qstep option setting");
    // //
    // Preparing input/output files
    // //
    final File inputFile = TestData.file(this, testFileName);
    Assert.assertTrue(inputFile.exists());
    // Output files resulting from 3 different values of the same create
    // option. In this test, the create option is Qstep.
    final float firstQstepParam = 0.2f;
    final float secondQstepParam = 1.7f;
    final String fileName1 = new StringBuffer("Qstep-").append(Float.toString(firstQstepParam)).append("f-.jp2").toString();
    final String fileName2 = new StringBuffer("Qstep-").append(Float.toString(secondQstepParam)).append("f-.jp2").toString();
    final String fileName3 = "Qstep-Default-.jp2";
    final File outputFile1 = TestData.temp(this, fileName1, deleteTempFilesOnExit);
    final File outputFile2 = TestData.temp(this, fileName2, deleteTempFilesOnExit);
    final File outputFile3 = TestData.temp(this, fileName3, deleteTempFilesOnExit);
    // //
    // Preparing to read
    // //
    final ParameterBlockJAI pbjImageRead = new ParameterBlockJAI("ImageRead");
    pbjImageRead.setParameter("Input", inputFile);
    if (ENABLE_SUBSAMPLING) {
        ImageReadParam readParam = new ImageReadParam();
        readParam.setSourceSubsampling(4, 4, 0, 0);
        pbjImageRead.setParameter("readParam", readParam);
    }
    pbjImageRead.setParameter("Reader", new JP2GDALKakaduImageReaderSpi().createReaderInstance());
    RenderedOp image = JAI.create("ImageRead", pbjImageRead);
    // ////////////////////////////////////////////////////////////////////
    // 
    // preparing to write (1ST version of the create option test)
    // 
    // ////////////////////////////////////////////////////////////////////
    // Setting output and writer
    final ParameterBlockJAI pbjImageWrite = new ParameterBlockJAI("ImageWrite");
    pbjImageWrite.setParameter("Output", new FileImageOutputStreamExtImpl(outputFile1));
    ImageWriter writer = new JP2GDALKakaduImageWriterSpi().createWriterInstance();
    pbjImageWrite.setParameter("Writer", writer);
    // Specifying image source to write
    pbjImageWrite.addSource(image);
    ImageWriteParam param = writer.getDefaultWriteParam();
    // Specifying the required create option
    ((JP2GDALKakaduImageWriteParam) param).setQstep(firstQstepParam);
    pbjImageWrite.setParameter("writeParam", param);
    // Writing
    final RenderedOp op = JAI.create("ImageWrite", pbjImageWrite);
    // ////////////////////////////////////////////////////////////////////
    // 
    // preparing to write (2ND version of the create option test)
    // 
    // ////////////////////////////////////////////////////////////////////
    // Setting output and writer
    final ParameterBlockJAI pbjImageWrite2 = new ParameterBlockJAI("ImageWrite");
    pbjImageWrite2.setParameter("Output", new FileImageOutputStreamExtImpl(outputFile2));
    ImageWriter writer2 = new JP2GDALKakaduImageWriterSpi().createWriterInstance();
    pbjImageWrite2.setParameter("Writer", writer2);
    // Specifying image source to write
    pbjImageWrite2.addSource(image);
    ImageWriteParam param2 = writer2.getDefaultWriteParam();
    // Specifying the required create option
    ((JP2GDALKakaduImageWriteParam) param2).setQstep(secondQstepParam);
    pbjImageWrite2.setParameter("writeParam", param2);
    // Writing
    final RenderedOp op2 = JAI.create("ImageWrite", pbjImageWrite2);
    // ////////////////////////////////////////////////////////////////////
    // 
    // preparing to write (3ND version of the create option - DEFAULT)
    // 
    // ////////////////////////////////////////////////////////////////////
    // Setting output and writer
    final ParameterBlockJAI pbjImageWrite3 = new ParameterBlockJAI("ImageWrite");
    pbjImageWrite3.setParameter("Output", new FileImageOutputStreamExtImpl(outputFile3));
    ImageWriter writer3 = new JP2GDALKakaduImageWriterSpi().createWriterInstance();
    pbjImageWrite3.setParameter("Writer", writer3);
    // Specifying image source to write
    pbjImageWrite3.addSource(image);
    ImageWriteParam param3 = writer3.getDefaultWriteParam();
    // Specifying the required create option
    pbjImageWrite3.setParameter("writeParam", param3);
    // Writing
    final RenderedOp op3 = JAI.create("ImageWrite", pbjImageWrite3);
}
Also used : ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) ImageWriter(javax.imageio.ImageWriter) FileImageOutputStreamExtImpl(it.geosolutions.imageio.stream.output.FileImageOutputStreamExtImpl) ImageWriteParam(javax.imageio.ImageWriteParam) ImageReadParam(javax.imageio.ImageReadParam) RenderedOp(javax.media.jai.RenderedOp) File(java.io.File) Test(org.junit.Test)

Example 60 with RenderedOp

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

the class JP2KWriteTest method write_ORGtparts.

// ////////////////////////////////////////////////////////////////////////
// 
// Testing "ORGtparts" Create Option.
// 
// ////////////////////////////////////////////////////////////////////////
@Test
public void write_ORGtparts() throws IOException, FileNotFoundException {
    if (!isJp2KakDriverAvailable)
        return;
    LOGGER.info("Testing JP2 Write operation with ORGtparts option setting");
    // //
    // Preparing input/output files
    // //
    final File inputFile = TestData.file(this, testFileName);
    Assert.assertTrue(inputFile.exists());
    // //
    // Preparing to read
    // //
    final ParameterBlockJAI pbjImageRead = new ParameterBlockJAI("ImageRead");
    pbjImageRead.setParameter("Input", inputFile);
    if (ENABLE_SUBSAMPLING) {
        ImageReadParam readParam = new ImageReadParam();
        readParam.setSourceSubsampling(8, 8, 0, 0);
        pbjImageRead.setParameter("readParam", readParam);
    }
    pbjImageRead.setParameter("Reader", new JP2GDALKakaduImageReaderSpi().createReaderInstance());
    RenderedOp image = JAI.create("ImageRead", pbjImageRead);
    // ////////////////////////////////////////////////////////////////////
    // 
    // preparing to write (i-TH version of the create option test)
    // 
    // ////////////////////////////////////////////////////////////////////
    final String[] createVersions = { "R", "C", "L", "R|C", "R|L", "L|C", "R|L|C" };
    final String[] filenameVersions = { "R", "C", "L", "RC", "RL", "LC", "RLC" };
    final int numberOfVersions = createVersions.length;
    for (int i = 0; i < numberOfVersions; i++) {
        // Output files resulting from different values of the same create
        // option. In this test, the create option is ORGtparts.
        final String filenameVersion = filenameVersions[i];
        final StringBuffer fileName = new StringBuffer("ORGtparts").append(filenameVersion).append("-.jp2");
        final File outputFile = TestData.temp(this, fileName.toString(), deleteTempFilesOnExit);
        // Setting output and writer
        final ParameterBlockJAI pbjImageWrite = new ParameterBlockJAI("ImageWrite");
        pbjImageWrite.setParameter("Output", new FileImageOutputStreamExtImpl(outputFile));
        ImageWriter writer = new JP2GDALKakaduImageWriterSpi().createWriterInstance();
        pbjImageWrite.setParameter("Writer", writer);
        // Specifying image source to write
        pbjImageWrite.addSource(image);
        ImageWriteParam param = writer.getDefaultWriteParam();
        // Specifying the required create option
        ((JP2GDALKakaduImageWriteParam) param).setORGgen_plt("yes");
        ((JP2GDALKakaduImageWriteParam) param).setLayers(10);
        ((JP2GDALKakaduImageWriteParam) param).setCorder("LRCP");
        ((JP2GDALKakaduImageWriteParam) param).setTiling(1024, 1024);
        ((JP2GDALKakaduImageWriteParam) param).setORGtparts(createVersions[i]);
        pbjImageWrite.setParameter("writeParam", param);
        // Writing
        final RenderedOp op = JAI.create("ImageWrite", pbjImageWrite);
    }
}
Also used : ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) ImageWriter(javax.imageio.ImageWriter) FileImageOutputStreamExtImpl(it.geosolutions.imageio.stream.output.FileImageOutputStreamExtImpl) ImageWriteParam(javax.imageio.ImageWriteParam) ImageReadParam(javax.imageio.ImageReadParam) RenderedOp(javax.media.jai.RenderedOp) File(java.io.File) Test(org.junit.Test)

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