Search in sources :

Example 51 with ImageWriteParam

use of javax.imageio.ImageWriteParam 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 52 with ImageWriteParam

use of javax.imageio.ImageWriteParam 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 53 with ImageWriteParam

use of javax.imageio.ImageWriteParam 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 54 with ImageWriteParam

use of javax.imageio.ImageWriteParam 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)

Example 55 with ImageWriteParam

use of javax.imageio.ImageWriteParam in project imageio-ext by geosolutions-it.

the class JP2KWriteTest method write_ORGgen_tlm.

// ////////////////////////////////////////////////////////////////////////
// 
// Testing "ORGgen_tlm" Create Option.
// 
// ////////////////////////////////////////////////////////////////////////
// Setting this parameter requires a bit of attention. Here below, there is
// the kakadu documentation related to this paramater:
// ------------------------------------------------------------------------
// Requests the insertion of TLM (tile-part-length) marker segments in the
// main header, to facilitate random access to the code-stream. This
// attribute takes a single integer-valued parameter, which identifies the
// maximum number of tile-parts which will be written to the code-stream for
// each tile. The reason for including this parameter is that space for the
// TLM information must be reserved ahead of time; once the entire
// code-stream has been written the generation machinery goes back and
// overwrites this reserved space with actual TLM data. If the actual number
// of tile-parts which are generated is less than the value supplied here,
// empty tile-parts will be inserted into the code-stream so as to use up
// all of the reserved TLM space. For this reason, you should try to
// estimate the maximum number of tile-parts you will need as accurately as
// possible, noting that the actual value may be hard to determine ahead of
// time if incremental flushing features are to be employed. An error will
// be generated at run-time if the number of declared maximum number of
// tile-parts turns out to be insufficient.
// ------------------------------------------------------------------------
@Test
public void write_ORGgen_tlm() throws IOException, FileNotFoundException {
    if (!isJp2KakDriverAvailable)
        return;
    LOGGER.info("Testing JP2 Write operation with ORGgen_tlm option setting");
    // //
    // Preparing input/output files
    // //
    final File inputFile = TestData.file(this, testFileName);
    Assert.assertTrue(inputFile.exists());
    final File outputFile1 = TestData.temp(this, "ORGgen_tlm0-.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
    // 
    // ////////////////////////////////////////////////////////////////////
    // 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).setORGgen_tlm(0);
    pbjImageWrite.setParameter("writeParam", param);
}
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)

Aggregations

ImageWriteParam (javax.imageio.ImageWriteParam)120 ImageWriter (javax.imageio.ImageWriter)100 IIOImage (javax.imageio.IIOImage)74 ImageOutputStream (javax.imageio.stream.ImageOutputStream)53 BufferedImage (java.awt.image.BufferedImage)51 File (java.io.File)51 IOException (java.io.IOException)38 Test (org.junit.Test)33 ByteArrayOutputStream (java.io.ByteArrayOutputStream)28 ImageReadParam (javax.imageio.ImageReadParam)24 ParameterBlockJAI (javax.media.jai.ParameterBlockJAI)23 RenderedOp (javax.media.jai.RenderedOp)23 IIOMetadata (javax.imageio.metadata.IIOMetadata)22 FileImageOutputStreamExtImpl (it.geosolutions.imageio.stream.output.FileImageOutputStreamExtImpl)20 ImageTypeSpecifier (javax.imageio.ImageTypeSpecifier)18 ByteArrayInputStream (java.io.ByteArrayInputStream)17 Graphics2D (java.awt.Graphics2D)12 JPEGImageWriteParam (javax.imageio.plugins.jpeg.JPEGImageWriteParam)12 FileImageOutputStream (javax.imageio.stream.FileImageOutputStream)12 MemoryCacheImageOutputStream (javax.imageio.stream.MemoryCacheImageOutputStream)12