use of it.geosolutions.imageio.plugins.geotiff.GeoTiffImageReaderSpi in project imageio-ext by geosolutions-it.
the class GeoTiffVrtTest method write.
/**
* Test Writing capabilities.
*
* @throws FileNotFoundException
* @throws IOException
*/
@Test
public void write() throws IOException, FileNotFoundException {
if (!isGDALAvailable) {
return;
}
final File outputFile = TestData.temp(this, "writetest.tif", false);
outputFile.deleteOnExit();
final File inputFile = TestData.file(this, "utmByte.tif.vrt");
ImageReadParam rparam = new ImageReadParam();
rparam.setSourceRegion(new Rectangle(1, 1, 300, 500));
rparam.setSourceSubsampling(1, 2, 0, 0);
ImageReader reader = new VRTImageReaderSpi().createReaderInstance();
reader.setInput(inputFile);
final IIOMetadata metadata = reader.getImageMetadata(0);
final ParameterBlockJAI pbjImageRead = new ParameterBlockJAI("ImageRead");
pbjImageRead.setParameter("Input", inputFile);
pbjImageRead.setParameter("reader", reader);
pbjImageRead.setParameter("readParam", rparam);
final ImageLayout l = new ImageLayout();
l.setTileGridXOffset(0).setTileGridYOffset(0).setTileHeight(256).setTileWidth(256);
RenderedOp image = JAI.create("ImageRead", pbjImageRead, new RenderingHints(JAI.KEY_IMAGE_LAYOUT, l));
if (TestData.isInteractiveTest())
Viewer.visualizeAllInformation(image, "geotiff");
// ////////////////////////////////////////////////////////////////
// preparing to write
// ////////////////////////////////////////////////////////////////
final ParameterBlockJAI pbjImageWrite = new ParameterBlockJAI("ImageWrite");
ImageWriter writer = new GeoTiffImageWriterSpi().createWriterInstance();
pbjImageWrite.setParameter("Output", outputFile);
pbjImageWrite.setParameter("writer", writer);
pbjImageWrite.setParameter("ImageMetadata", metadata);
pbjImageWrite.setParameter("Transcode", false);
ImageWriteParam param = new ImageWriteParam(Locale.getDefault());
param.setSourceRegion(new Rectangle(10, 10, 100, 100));
param.setSourceSubsampling(2, 1, 0, 0);
pbjImageWrite.setParameter("writeParam", param);
pbjImageWrite.addSource(image);
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 GeoTiffImageReaderSpi().createReaderInstance());
final RenderedOp image2 = JAI.create("ImageRead", pbjImageReRead);
if (TestData.isInteractiveTest())
Viewer.visualizeAllInformation(image2, "geotif2");
else
Assert.assertNotNull(image2.getTiles());
}
use of it.geosolutions.imageio.plugins.geotiff.GeoTiffImageReaderSpi in project imageio-ext by geosolutions-it.
the class GeoTiffVrtTest method palette.
/**
* Test Read on a Paletted Image
*
* @throws FileNotFoundException
* @throws IOException
*/
@Test
public void palette() throws FileNotFoundException, IOException {
if (!isGDALAvailable) {
return;
}
final File outputFile = TestData.temp(this, "writetest.tif", false);
outputFile.deleteOnExit();
final File inputFile = TestData.file(this, "paletted.tif.vrt");
ImageReader reader = new VRTImageReaderSpi().createReaderInstance();
reader.setInput(inputFile);
final IIOMetadata metadata = reader.getImageMetadata(0);
final ParameterBlockJAI pbjImageRead = new ParameterBlockJAI("ImageRead");
pbjImageRead.setParameter("Input", inputFile);
pbjImageRead.setParameter("reader", reader);
final ImageLayout l = new ImageLayout();
l.setTileGridXOffset(0).setTileGridYOffset(0).setTileHeight(256).setTileWidth(256);
RenderedOp image = JAI.create("ImageRead", pbjImageRead, new RenderingHints(JAI.KEY_IMAGE_LAYOUT, l));
if (TestData.isInteractiveTest())
Viewer.visualizeAllInformation(image, "Paletted image read");
// ////////////////////////////////////////////////////////////////
// preparing to write
// ////////////////////////////////////////////////////////////////
final ParameterBlockJAI pbjImageWrite = new ParameterBlockJAI("ImageWrite");
ImageWriter writer = new GeoTiffImageWriterSpi().createWriterInstance();
pbjImageWrite.setParameter("Output", outputFile);
pbjImageWrite.setParameter("writer", writer);
pbjImageWrite.setParameter("ImageMetadata", metadata);
pbjImageWrite.setParameter("Transcode", false);
pbjImageWrite.addSource(image);
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 GeoTiffImageReaderSpi().createReaderInstance());
final RenderedOp image2 = JAI.create("ImageRead", pbjImageReRead);
if (TestData.isInteractiveTest())
Viewer.visualizeAllInformation(image2, "Paletted image read back after writing");
else
Assert.assertNotNull(image2.getTiles());
ImageIOUtilities.disposeImage(image2);
ImageIOUtilities.disposeImage(image);
}
Aggregations