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);
}
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();
}
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);
}
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);
}
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);
}
Aggregations