use of it.geosolutions.imageio.stream.output.FileImageOutputStreamExtImpl in project imageio-ext by geosolutions-it.
the class StringImageOutputStreamSpi method createOutputStreamInstance.
/**
* Returns an instance of the {@link ImageOutputStream} implementation
* associated with this service provider.
*
* @return an ImageOutputStream instance.
*
* @throws IllegalArgumentException
* if input is not an instance of the correct class or is
* null.
*/
public ImageOutputStream createOutputStreamInstance(Object output, boolean useCache, File cacheDir) {
// is it a String?
if (!(output instanceof String)) {
if (LOGGER.isLoggable(Level.FINE))
LOGGER.fine("Provided input is not a String.");
return null;
}
// String that point to an url
final String outputURL = ((String) output);
// ////////////////////////////////////////////////////////////////////
//
// URL
//
// ////////////////////////////////////////////////////////////////////
URL tempURL;
try {
tempURL = new URL(outputURL);
} catch (MalformedURLException e) {
if (LOGGER.isLoggable(Level.FINE))
LOGGER.log(Level.FINE, e.getLocalizedMessage(), e);
return null;
}
if (tempURL.getProtocol().compareToIgnoreCase("eraf") == 0) {
File tempFile;
try {
tempFile = Utilities.urlToFile(tempURL);
return new FileImageOutputStreamExtImpl(tempFile);
} catch (UnsupportedEncodingException e) {
if (LOGGER.isLoggable(Level.FINE))
LOGGER.log(Level.FINE, e.getLocalizedMessage(), e);
} catch (FileNotFoundException e) {
if (LOGGER.isLoggable(Level.FINE))
LOGGER.log(Level.FINE, e.getLocalizedMessage(), e);
} catch (IOException e) {
if (LOGGER.isLoggable(Level.FINE))
LOGGER.log(Level.FINE, e.getLocalizedMessage(), e);
}
}
return null;
}
use of it.geosolutions.imageio.stream.output.FileImageOutputStreamExtImpl 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);
}
use of it.geosolutions.imageio.stream.output.FileImageOutputStreamExtImpl 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);
}
}
use of it.geosolutions.imageio.stream.output.FileImageOutputStreamExtImpl in project imageio-ext by geosolutions-it.
the class JP2KWriteTest method write_Cmodes.
// ////////////////////////////////////////////////////////////////////////
//
// Testing "CModes" Create Option.
//
// ////////////////////////////////////////////////////////////////////////
@Test
public void write_Cmodes() throws IOException, FileNotFoundException {
if (!isJp2KakDriverAvailable)
return;
LOGGER.info("Testing JP2 Write operation with CModes 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(4, 4, 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 = { "BYPASS", "BYPASS|RESTART|CAUSAL", "RESTART|ERTERM", "RESET" };
final String[] filenameVersions = { "BYPASS", "BYPASSRESTARTCAUSAL", "RESTARTERTERM", "RESET" };
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("CModes").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).setCmodes(createVersions[i]);
pbjImageWrite.setParameter("writeParam", param);
// Writing
final RenderedOp op = JAI.create("ImageWrite", pbjImageWrite);
}
}
use of it.geosolutions.imageio.stream.output.FileImageOutputStreamExtImpl in project imageio-ext by geosolutions-it.
the class JP2KWriteTest method write_Clevels.
// ////////////////////////////////////////////////////////////////////////
//
// Testing "Clevels" Create Option.
//
// ////////////////////////////////////////////////////////////////////////
@Test
public void write_Clevels() throws IOException, FileNotFoundException {
if (!isJp2KakDriverAvailable)
return;
LOGGER.info("Testing JP2 Write operation with Clevels 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 Clevels.
final int firstClevelsParam = 2;
final int secondClevelsParam = 6;
final String fileName1 = new StringBuffer("Clevels-").append(Integer.toString(firstClevelsParam)).append("-.jp2").toString();
final String fileName2 = new StringBuffer("Clevels-").append(Integer.toString(secondClevelsParam)).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).setClevels(firstClevelsParam);
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).setClevels(secondClevelsParam);
pbjImageWrite2.setParameter("writeParam", param2);
// Writing
final RenderedOp op2 = JAI.create("ImageWrite", pbjImageWrite2);
}
Aggregations