use of javax.media.jai.RenderedOp in project imageio-ext by geosolutions-it.
the class RpftocVrtTest method read.
@Test
public void read() throws FileNotFoundException, IOException {
if (!isGDALAvailable) {
return;
}
TestData.unzipFile(this, "rpftoc.zip");
File file = TestData.file(this, fileName);
// ////////////////////////////////////////////////////////////////
// preparing to read
// ////////////////////////////////////////////////////////////////
final ParameterBlockJAI pbjImageRead;
final ImageReadParam irp = new ImageReadParam();
// subsample by 2 on both dimensions
final int xSubSampling = 2;
final int ySubSampling = 2;
final int xSubSamplingOffset = 0;
final int ySubSamplingOffset = 0;
irp.setSourceSubsampling(xSubSampling, ySubSampling, xSubSamplingOffset, ySubSamplingOffset);
pbjImageRead = new ParameterBlockJAI("ImageRead");
pbjImageRead.setParameter("Input", file);
pbjImageRead.setParameter("readParam", irp);
// get a RenderedImage
RenderedOp image = JAI.create("ImageRead", pbjImageRead);
if (TestData.isInteractiveTest())
Viewer.visualizeAllInformation(image, "Subsampling Read");
else {
Assert.assertTrue(image.getWidth() == 768);
Assert.assertTrue(image.getHeight() == 768);
}
ImageIOUtilities.disposeImage(image);
}
use of javax.media.jai.RenderedOp in project imageio-ext by geosolutions-it.
the class Doq2VrtTest method imageRead.
/**
* Test read exploiting common JAI operations (Crop-Translate-Rotate)
*
* @throws FileNotFoundException
* @throws IOException
*/
@Test
public void imageRead() throws FileNotFoundException, IOException {
if (!isGDALAvailable) {
return;
}
File file = TestData.file(this, fileName);
// ////////////////////////////////////////////////////////////////
// preparing to read
// ////////////////////////////////////////////////////////////////
final ParameterBlockJAI pbjImageRead;
final ImageReadParam irp = new ImageReadParam();
pbjImageRead = new ParameterBlockJAI("ImageRead");
pbjImageRead.setParameter("Input", file);
pbjImageRead.setParameter("readParam", irp);
// NOTE that the actual sample data (fakedoq1.doq) only contains a row.
// Therefore, we need to force the read on that reduced area.
// Requesting a bigger image height will result in a GDAL ReadBlock error.
irp.setSourceRegion(new Rectangle(0, 0, 500, 1));
final ImageLayout l = new ImageLayout();
l.setTileGridXOffset(0).setTileGridYOffset(0).setTileHeight(512).setTileWidth(512);
// get a RenderedImage
RenderedOp image = JAI.create("ImageRead", pbjImageRead, new RenderingHints(JAI.KEY_IMAGE_LAYOUT, l));
if (TestData.isInteractiveTest()) {
Viewer.visualizeAllInformation(image, "test");
} else {
Assert.assertNotNull(image.getTiles());
}
Assert.assertEquals(500, image.getWidth());
Assert.assertEquals(1, image.getHeight());
ImageIOUtilities.disposeImage(image);
}
use of javax.media.jai.RenderedOp in project imageio-ext by geosolutions-it.
the class MrSIDTest method subBandsRead.
/**
* Test read exploiting the setSourceBands and setDestinationType on
* imageReadParam
*
* @throws FileNotFoundException
* @throws IOException
*/
@Test
public void subBandsRead() throws IOException {
if (!isMrSidAvailable) {
return;
}
try {
ImageReader reader = new MrSIDImageReaderSpi().createReaderInstance();
final File file = TestData.file(this, fileName);
reader.setInput(file);
// //
//
// Getting image properties
//
// //
ImageTypeSpecifier spec = (ImageTypeSpecifier) reader.getImageTypes(0).next();
SampleModel sm = spec.getSampleModel();
final int width = reader.getWidth(0);
final int height = reader.getHeight(0);
// //
//
// Setting a ColorModel
//
// //
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
ColorModel cm = RasterFactory.createComponentColorModel(sm.getDataType(), // color space
cs, // has alpha
false, // is alphaPremultiplied
false, // transparency
Transparency.OPAQUE);
// //
//
// Setting Image Read Parameters
//
// //
final ImageReadParam param = new ImageReadParam();
final int ssx = 2;
final int ssy = 2;
param.setSourceSubsampling(ssx, ssy, 0, 0);
final Rectangle sourceRegion = new Rectangle(50, 50, 300, 300);
param.setSourceRegion(sourceRegion);
param.setSourceBands(new int[] { 0 });
Rectangle intersRegion = new Rectangle(0, 0, width, height);
intersRegion = intersRegion.intersection(sourceRegion);
int subsampledWidth = (intersRegion.width + ssx - 1) / ssx;
int subsampledHeight = (intersRegion.height + ssy - 1) / ssy;
param.setDestinationType(new ImageTypeSpecifier(cm, sm.createCompatibleSampleModel(subsampledWidth, subsampledHeight).createSubsetSampleModel(new int[] { 0 })));
// //
//
// Preparing the ImageRead operation
//
// //
ParameterBlockJAI pbjImageRead = new ParameterBlockJAI("ImageRead");
pbjImageRead.setParameter("Input", file);
pbjImageRead.setParameter("readParam", param);
pbjImageRead.setParameter("reader", reader);
// //
//
// Setting a Layout
//
// //
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, "SourceBand selection");
else {
Assert.assertNotNull(image.getTiles());
ImageIOUtilities.disposeImage(image);
}
} catch (FileNotFoundException fnfe) {
warningMessage();
}
}
use of javax.media.jai.RenderedOp in project imageio-ext by geosolutions-it.
the class MrSIDTest method metadataAccess.
/**
* Test retrieving all available metadata properties
*
* @throws FileNotFoundException
* @throws IOException
*/
@Test
public void metadataAccess() throws FileNotFoundException, IOException {
if (!isMrSidAvailable) {
return;
}
try {
final File file = TestData.file(this, fileName);
final ParameterBlockJAI pbjImageRead = new ParameterBlockJAI("ImageRead");
pbjImageRead.setParameter("Input", file);
RenderedOp image = JAI.create("ImageRead", pbjImageRead);
IIOMetadata metadata = (IIOMetadata) image.getProperty(ImageReadDescriptor.PROPERTY_NAME_METADATA_IMAGE);
Assert.assertTrue(metadata instanceof GDALCommonIIOImageMetadata);
Assert.assertTrue(metadata instanceof MrSIDIIOImageMetadata);
GDALCommonIIOImageMetadata commonMetadata = (GDALCommonIIOImageMetadata) metadata;
ImageIOUtilities.displayImageIOMetadata(commonMetadata.getAsTree(GDALCommonIIOImageMetadata.nativeMetadataFormatName));
ImageIOUtilities.displayImageIOMetadata(commonMetadata.getAsTree(MrSIDIIOImageMetadata.mrsidImageMetadataName));
if (TestData.isInteractiveTest())
Viewer.visualizeAllInformation(image, "", TestData.isInteractiveTest());
else {
ImageIOUtilities.disposeImage(image);
}
} catch (FileNotFoundException fnfe) {
warningMessage();
}
try {
final File file = TestData.file(this, fileName);
ImageReader reader = new MrSIDImageReaderSpi().createReaderInstance();
reader.setInput(ImageIO.createImageInputStream(file));
Assert.assertEquals(618, reader.getWidth(0));
Assert.assertEquals(1265, reader.getHeight(0));
IIOMetadata metadata = (IIOMetadata) reader.getImageMetadata(0);
Assert.assertTrue(metadata instanceof GDALCommonIIOImageMetadata);
Assert.assertTrue(metadata instanceof MrSIDIIOImageMetadata);
GDALCommonIIOImageMetadata commonMetadata = (GDALCommonIIOImageMetadata) metadata;
ImageIOUtilities.displayImageIOMetadata(commonMetadata.getAsTree(GDALCommonIIOImageMetadata.nativeMetadataFormatName));
ImageIOUtilities.displayImageIOMetadata(commonMetadata.getAsTree(MrSIDIIOImageMetadata.mrsidImageMetadataName));
reader.dispose();
} catch (FileNotFoundException fnfe) {
warningMessage();
}
}
use of javax.media.jai.RenderedOp in project imageio-ext by geosolutions-it.
the class SPRTest method read.
@Test
public void read() throws FileNotFoundException, IOException {
if (!isGDALAvailable) {
return;
}
File file;
try {
file = TestData.file(this, fileName);
} catch (FileNotFoundException fnfe) {
warningMessage();
return;
}
// ////////////////////////////////////////////////////////////////
// preparing to read
// ////////////////////////////////////////////////////////////////
final ParameterBlockJAI pbjImageRead;
final ImageReadParam irp = new ImageReadParam();
// subsample by 2 on both dimensions
final int xSubSampling = 2;
final int ySubSampling = 2;
final int xSubSamplingOffset = 0;
final int ySubSamplingOffset = 0;
irp.setSourceSubsampling(xSubSampling, ySubSampling, xSubSamplingOffset, ySubSamplingOffset);
pbjImageRead = new ParameterBlockJAI("ImageRead");
pbjImageRead.setParameter("Input", file);
pbjImageRead.setParameter("readParam", irp);
// get a RenderedImage
RenderedOp image = JAI.create("ImageRead", pbjImageRead);
if (TestData.isInteractiveTest())
Viewer.visualizeAllInformation(image, "Subsampling Read");
else {
Raster[] io = image.getTiles();
Assert.assertNotNull(io);
Assert.assertEquals(64, image.getWidth());
Assert.assertEquals(64, image.getHeight());
}
ImageIOUtilities.disposeImage(image);
}
Aggregations