use of javax.media.jai.ParameterBlockJAI in project imageio-ext by geosolutions-it.
the class ErdasImgTest method jaiOperations.
/**
* Test read exploiting common JAI operations (Crop-Translate-Rotate)
*
* @throws FileNotFoundException
* @throws IOException
*/
@Test
public void jaiOperations() throws FileNotFoundException, IOException {
if (!isGDALAvailable) {
return;
}
File file;
try {
TestData.unzipFile(this, "test.zip");
file = TestData.file(this, fileName);
} catch (FileNotFoundException fnfe) {
warningMessage();
return;
}
// ////////////////////////////////////////////////////////////////
// preparing to read
// ////////////////////////////////////////////////////////////////
final ParameterBlockJAI pbjImageRead;
pbjImageRead = new ParameterBlockJAI("ImageRead");
pbjImageRead.setParameter("Input", file);
// get a RenderedImage
RenderedOp image = JAI.create("ImageRead", pbjImageRead);
if (TestData.isInteractiveTest())
Viewer.visualizeAllInformation(image, "Read");
else
Assert.assertNotNull(image.getTiles());
ImageIOUtilities.disposeImage(image);
}
use of javax.media.jai.ParameterBlockJAI in project imageio-ext by geosolutions-it.
the class GeoTiffTest 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");
ImageReadParam rparam = new ImageReadParam();
rparam.setSourceRegion(new Rectangle(1, 1, 300, 500));
rparam.setSourceSubsampling(1, 2, 0, 0);
ImageReader reader = new GeoTiffImageReaderSpi().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 javax.media.jai.ParameterBlockJAI in project imageio-ext by geosolutions-it.
the class GeoTiffTest 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");
ImageReader reader = new GeoTiffImageReaderSpi().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);
}
use of javax.media.jai.ParameterBlockJAI in project imageio-ext by geosolutions-it.
the class GeoTiffTest method readWithWarp.
/**
* Test Read exploiting JAI-ImageIO tools capabilities
* and GDAL warp.
*
* @throws FileNotFoundException
* @throws IOException
*/
@Test
public void readWithWarp() throws FileNotFoundException, IOException {
if (!isGDALAvailable) {
return;
}
final ParameterBlockJAI pbjImageRead;
String fileName = "utmByte.tif";
final File file = TestData.file(this, fileName);
SpatialReference destinationReference = new SpatialReference();
destinationReference.SetProjCS("UTM 17 (WGS84) in northern hemisphere.");
destinationReference.SetWellKnownGeogCS("WGS84");
destinationReference.SetUTM(17, 1);
GDALImageReadParam readParam = new GDALImageReadParam();
readParam.setDestinationWkt(destinationReference.ExportToWkt());
readParam.setResampleAlgorithm(ResampleAlgorithm.CUBIC);
pbjImageRead = new ParameterBlockJAI("ImageRead");
pbjImageRead.setParameter("Input", new FileImageInputStreamExtImpl(file));
pbjImageRead.setParameter("Reader", new GeoTiffImageReaderSpi().createReaderInstance());
pbjImageRead.setParameter("ReadParam", readParam);
RenderedOp image = JAI.create("ImageRead", pbjImageRead);
if (TestData.isInteractiveTest())
Viewer.visualizeAllInformation(image, "", true);
else
Assert.assertNotNull(image.getTiles());
}
use of javax.media.jai.ParameterBlockJAI in project imageio-ext by geosolutions-it.
the class IdrisiReadTest method readJAI.
/**
* Simple test read through JAI - ImageIO
*
* @throws FileNotFoundException
* @throws IOException
*/
@org.junit.Test
public void readJAI() throws FileNotFoundException, IOException {
if (!isGDALAvailable) {
return;
}
final ParameterBlockJAI pbjImageRead;
final String fileName = "idrisi.rst";
TestData.unzipFile(this, "idrisi.zip");
final File file = TestData.file(this, fileName);
pbjImageRead = new ParameterBlockJAI("ImageRead");
pbjImageRead.setParameter("Input", file);
RenderedOp image = JAI.create("ImageRead", pbjImageRead);
if (TestData.isInteractiveTest())
Viewer.visualizeAllInformation(image, fileName);
else
image.getTiles();
Assert.assertEquals(86, image.getWidth());
Assert.assertEquals(43, image.getHeight());
ImageIOUtilities.disposeImage(image);
}
Aggregations