Search in sources :

Example 6 with ParameterBlockJAI

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

the class JP2KWriteTest method write_ROI.

// ////////////////////////////////////////////////////////////////////////
// 
// Testing "ROI" Create Options and related options.
// 
// ////////////////////////////////////////////////////////////////////////
@Test
public void write_ROI() throws IOException, FileNotFoundException {
    if (!isJp2KakDriverAvailable)
        return;
    LOGGER.info("Testing JP2 Write operation with ROI option setting");
    // //
    // Preparing input/output files
    // //
    final File inputFile = TestData.file(this, testFileName);
    Assert.assertTrue(inputFile.exists());
    // Output files resulting from 2 different values of the same create
    // option. In this test, the create option is SProfile.
    final File outputFile1 = TestData.temp(this, "ROI-NO_ROI-.jp2", deleteTempFilesOnExit);
    final File outputFile2 = TestData.temp(this, "ROI-parametrized-.jp2", 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
    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).setClayers(20);
    ((JP2GDALKakaduImageWriteParam) param2).setROI("400,400,400,400");
    ((JP2GDALKakaduImageWriteParam) param2).setRweight(64000f);
    ((JP2GDALKakaduImageWriteParam) param2).setCprecincts("{256,256},{128,128},{64,64},{32,32}");
    pbjImageWrite2.setParameter("writeParam", param2);
    // Writing
    final RenderedOp op2 = JAI.create("ImageWrite", pbjImageWrite2);
}
Also used : ImageReadParam(javax.imageio.ImageReadParam) RenderedOp(javax.media.jai.RenderedOp) ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) ImageWriter(javax.imageio.ImageWriter) FileImageOutputStreamExtImpl(it.geosolutions.imageio.stream.output.FileImageOutputStreamExtImpl) ImageWriteParam(javax.imageio.ImageWriteParam) File(java.io.File) Test(org.junit.Test)

Example 7 with ParameterBlockJAI

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

the class JP2KWriteTest method write_Qguard.

// ////////////////////////////////////////////////////////////////////////
// 
// Testing "Qguard" Create Option.
// 
// ////////////////////////////////////////////////////////////////////////
@Test
public void write_Qguard() throws IOException, FileNotFoundException {
    if (!isJp2KakDriverAvailable)
        return;
    LOGGER.info("Testing JP2 Write operation with Qguard option setting");
    // //
    // Preparing input/output files
    // //
    final File inputFile = TestData.file(this, testFileName);
    Assert.assertTrue(inputFile.exists());
    // Output files resulting from 2 different values of the same create
    // option. In this test, the create option is Qguard.
    final File outputFile1 = TestData.temp(this, "Qguard1-.jp2", deleteTempFilesOnExit);
    final File outputFile2 = TestData.temp(this, "Qguard2-.jp2", 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).setQguard(1);
    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).setQguard(2);
    pbjImageWrite2.setParameter("writeParam", param2);
    // Writing
    final RenderedOp op2 = JAI.create("ImageWrite", pbjImageWrite2);
}
Also used : ImageReadParam(javax.imageio.ImageReadParam) RenderedOp(javax.media.jai.RenderedOp) ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) ImageWriter(javax.imageio.ImageWriter) FileImageOutputStreamExtImpl(it.geosolutions.imageio.stream.output.FileImageOutputStreamExtImpl) ImageWriteParam(javax.imageio.ImageWriteParam) File(java.io.File) Test(org.junit.Test)

Example 8 with ParameterBlockJAI

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

the class JP2KWriteTest method write_Parametrized.

// ////////////////////////////////////////////////////////////////////////
// 
// Testing parameters-support capabilities for writer.
// 
// ////////////////////////////////////////////////////////////////////////
@Test
public void write_Parametrized() throws IOException, FileNotFoundException {
    if (!isJp2KakDriverAvailable)
        return;
    final File outputFile = TestData.temp(this, "writetest.jp2", false);
    outputFile.deleteOnExit();
    final File inputFile = TestData.file(this, "test.jp2");
    Assert.assertTrue(inputFile.exists());
    // ////////////////////////////////////////////////////////////////////
    // 
    // Reading
    // 
    // ////////////////////////////////////////////////////////////////////
    final ParameterBlockJAI pbjImageRead = new ParameterBlockJAI("ImageRead");
    ImageReader reader = new JP2GDALKakaduImageReaderSpi().createReaderInstance();
    ImageReadParam param = new ImageReadParam();
    param.setSourceSubsampling(2, 2, 0, 0);
    pbjImageRead.setParameter("readParam", param);
    pbjImageRead.setParameter("Input", inputFile);
    pbjImageRead.setParameter("reader", reader);
    RenderedOp image = JAI.create("ImageRead", pbjImageRead);
    image.getRendering();
    if (TestData.isInteractiveTest())
        ImageIOUtilities.visualize(image, "First Read Image");
    else
        image.getTiles();
    // ////////////////////////////////////////////////////////////////////
    // 
    // preparing to write
    // 
    // ////////////////////////////////////////////////////////////////////
    // Setting output and writer
    final ParameterBlockJAI pbjImageWrite = new ParameterBlockJAI("ImageWrite");
    pbjImageWrite.setParameter("Output", outputFile);
    ImageWriter writer = new JP2GDALKakaduImageWriterSpi().createWriterInstance();
    pbjImageWrite.addSource(image);
    ImageWriteParam param2 = writer.getDefaultWriteParam();
    pbjImageWrite.setParameter("writer", writer);
    pbjImageWrite.setParameter("ImageMetadata", reader.getImageMetadata(0));
    pbjImageWrite.setParameter("Transcode", false);
    param2.setSourceRegion(new Rectangle(100, 100, 500, 500));
    param2.setSourceSubsampling(2, 3, 0, 0);
    pbjImageWrite.setParameter("writeParam", param2);
    // Writing
    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 JP2GDALKakaduImageReaderSpi().createReaderInstance());
    final RenderedOp image2 = JAI.create("ImageRead", pbjImageReRead);
    if (TestData.isInteractiveTest())
        ImageIOUtilities.visualize(image2, "Written Image");
    else
        image2.getTiles();
}
Also used : ImageReadParam(javax.imageio.ImageReadParam) RenderedOp(javax.media.jai.RenderedOp) ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) ImageWriter(javax.imageio.ImageWriter) Rectangle(java.awt.Rectangle) ImageReader(javax.imageio.ImageReader) ImageWriteParam(javax.imageio.ImageWriteParam) File(java.io.File) Test(org.junit.Test)

Example 9 with ParameterBlockJAI

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

the class JP2KWriteTest method write_Cycc.

// ////////////////////////////////////////////////////////////////////////
// 
// Testing "Cycc" Create Option.
// 
// ////////////////////////////////////////////////////////////////////////
@Test
public void write_Cycc() throws IOException, FileNotFoundException {
    if (!isJp2KakDriverAvailable)
        return;
    LOGGER.info("Testing JP2 Write operation with Cycc option setting");
    // //
    // Preparing input/output files
    // //
    final File inputFile = TestData.file(this, testFileName);
    Assert.assertTrue(inputFile.exists());
    // Output files resulting from 2 different values of the same create
    // option. In this test, the create option is ORGgen_plt.
    final File outputFile1 = TestData.temp(this, "Cycc-Y-.jp2", deleteTempFilesOnExit);
    final File outputFile2 = TestData.temp(this, "Cycc-N-.jp2", 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).setCycc("yes");
    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).setCycc("no");
    pbjImageWrite2.setParameter("writeParam", param2);
    // Writing
    final RenderedOp op2 = JAI.create("ImageWrite", pbjImageWrite2);
}
Also used : ImageReadParam(javax.imageio.ImageReadParam) RenderedOp(javax.media.jai.RenderedOp) ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) ImageWriter(javax.imageio.ImageWriter) FileImageOutputStreamExtImpl(it.geosolutions.imageio.stream.output.FileImageOutputStreamExtImpl) ImageWriteParam(javax.imageio.ImageWriteParam) File(java.io.File) Test(org.junit.Test)

Example 10 with ParameterBlockJAI

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

the class JP2KWriteTest method write_Tiling.

// ////////////////////////////////////////////////////////////////////////
// 
// Testing "Tiling" Create Option.
// 
// ////////////////////////////////////////////////////////////////////////
@Test
public void write_Tiling() throws IOException, FileNotFoundException {
    if (!isJp2KakDriverAvailable)
        return;
    LOGGER.info("Testing JP2 Write operation with Tiling option setting");
    // //
    // Preparing input/output files
    // //
    final File inputFile = TestData.file(this, testFileName);
    Assert.assertTrue(inputFile.exists());
    // Output files resulting from 2 different values of the tiling.
    final int firstTilingParam = 128;
    final int secondTilingParam = 256;
    final String fileName1 = new StringBuffer("Tiled-").append(Integer.toString(firstTilingParam)).append("-.jp2").toString();
    final String fileName2 = new StringBuffer("Tiled-").append(Integer.toString(secondTilingParam)).append("-.jp2").toString();
    final File outputFile1 = TestData.temp(this, fileName1, deleteTempFilesOnExit);
    final File outputFile2 = TestData.temp(this, fileName2, 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);
    }
    // Reading
    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).setTiling(firstTilingParam, firstTilingParam);
    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).setTiling(secondTilingParam, secondTilingParam);
    pbjImageWrite2.setParameter("writeParam", param2);
    // Writing
    final RenderedOp op2 = JAI.create("ImageWrite", pbjImageWrite2);
}
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

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