use of javax.imageio.ImageTypeSpecifier in project imageio-ext by geosolutions-it.
the class JpegVrtTest method sourceBands.
/**
* Test sourceBands management capabilities.
*
* @throws FileNotFoundException
* @throws IOException
*/
@Test
public void sourceBands() throws IOException, FileNotFoundException {
if (!isGDALAvailable) {
return;
}
final File inputFile = TestData.file(this, "small_world.jpg.vrt");
// //
//
// Preparing srcRegion constants
//
// //
final int srcRegionX = 40;
final int srcRegionY = 50;
final int srcRegionWidth = 400;
final int srcRegionHeight = 300;
final int subSamplingX = 2;
final int subSamplingY = 1;
// //
//
// Setting source settings parameters
//
// //
ImageReadParam rparam = new ImageReadParam();
rparam.setSourceRegion(new Rectangle(srcRegionX, srcRegionY, srcRegionWidth, srcRegionHeight));
rparam.setSourceSubsampling(subSamplingX, subSamplingY, 0, 0);
rparam.setSourceBands(new int[] { 0 });
// //
//
// Setting destination settings parameters
//
// //
rparam.setDestinationBands(new int[] { 0 });
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
ColorModel cm = RasterFactory.createComponentColorModel(// dataType
DataBuffer.TYPE_BYTE, // color space
cs, // has alpha
false, // is alphaPremultiplied
false, // transparency
Transparency.OPAQUE);
final int destWidth = srcRegionWidth / subSamplingX;
final int destHeight = srcRegionHeight / subSamplingY;
Assert.assertEquals(destWidth, 200);
Assert.assertEquals(destHeight, 300);
final SampleModel sm = cm.createCompatibleSampleModel(destWidth, destHeight);
rparam.setDestinationType(new ImageTypeSpecifier(cm, sm));
// //
//
// Preparing for image read operation
//
// //
final ParameterBlockJAI pbjImageRead = new ParameterBlockJAI("ImageRead");
pbjImageRead.setParameter("Input", inputFile);
pbjImageRead.setParameter("readParam", rparam);
final ImageLayout l = new ImageLayout();
l.setTileGridXOffset(0).setTileGridYOffset(0).setTileHeight(128).setTileWidth(128);
RenderedOp image = JAI.create("ImageRead", pbjImageRead, new RenderingHints(JAI.KEY_IMAGE_LAYOUT, l));
if (TestData.isInteractiveTest())
Viewer.visualizeAllInformation(image, "imageread");
else
Assert.assertNotNull(image.getTiles());
ImageIOUtilities.disposeImage(image);
}
use of javax.imageio.ImageTypeSpecifier in project imageio-ext by geosolutions-it.
the class JpegJMagickImageReader method getImageTypes.
public Iterator<ImageTypeSpecifier> getImageTypes(int imageIndex) throws IOException {
synchronized (imagesLayouts) {
checkImageIndex(imageIndex);
final ImageLayout layout = (imagesLayouts.get(imageIndex)).getLayout();
return Collections.singletonList(new ImageTypeSpecifier(layout.getColorModel(null), layout.getSampleModel(null))).iterator();
}
}
use of javax.imageio.ImageTypeSpecifier in project imageio-ext by geosolutions-it.
the class JPEGReadTest method sourceBands.
/**
* Test sourceBands management capabilities.
*
* @throws FileNotFoundException
* @throws IOException
*/
@Test
public void sourceBands() throws IOException, FileNotFoundException {
if (!isGDALAvailable) {
return;
}
final File inputFile = TestData.file(this, "small_world.jpg");
// //
//
// Preparing srcRegion constants
//
// //
final int srcRegionX = 40;
final int srcRegionY = 50;
final int srcRegionWidth = 400;
final int srcRegionHeight = 300;
final int subSamplingX = 2;
final int subSamplingY = 1;
// //
//
// Setting source settings parameters
//
// //
ImageReadParam rparam = new ImageReadParam();
rparam.setSourceRegion(new Rectangle(srcRegionX, srcRegionY, srcRegionWidth, srcRegionHeight));
rparam.setSourceSubsampling(subSamplingX, subSamplingY, 0, 0);
rparam.setSourceBands(new int[] { 0 });
// //
//
// Setting destination settings parameters
//
// //
rparam.setDestinationBands(new int[] { 0 });
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
ColorModel cm = RasterFactory.createComponentColorModel(// dataType
DataBuffer.TYPE_BYTE, // color space
cs, // has alpha
false, // is alphaPremultiplied
false, // transparency
Transparency.OPAQUE);
final int destWidth = srcRegionWidth / subSamplingX;
final int destHeight = srcRegionHeight / subSamplingY;
Assert.assertEquals(destWidth, 200);
Assert.assertEquals(destHeight, 300);
final SampleModel sm = cm.createCompatibleSampleModel(destWidth, destHeight);
rparam.setDestinationType(new ImageTypeSpecifier(cm, sm));
// //
//
// Preparing for image read operation
//
// //
ImageReader reader = new JpegGDALImageReaderSpi().createReaderInstance();
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(128).setTileWidth(128);
RenderedOp image = JAI.create("ImageRead", pbjImageRead, new RenderingHints(JAI.KEY_IMAGE_LAYOUT, l));
if (TestData.isInteractiveTest())
Viewer.visualizeAllInformation(image, "imageread");
else
Assert.assertNotNull(image.getTiles());
ImageIOUtilities.disposeImage(image);
}
use of javax.imageio.ImageTypeSpecifier in project imageio-ext by geosolutions-it.
the class GDALImageReader method getImageTypes.
/**
* Returns an <code>Iterator</code> containing possible image types to
* which the given image may be decoded, in the form of
* <code>ImageTypeSpecifiers</code>s. At least one legal image type will
* be returned. This implementation simply returns an
* <code>ImageTypeSpecifier</code> set in compliance with the property of
* the dataset contained within the underlying data source.
*
* @param imageIndex
* the index of the image to be retrieved.
*
* @return an <code>Iterator</code> containing possible image types to
* which the given image may be decoded, in the form of
* <code>ImageTypeSpecifiers</code>s
*/
public Iterator<ImageTypeSpecifier> getImageTypes(int imageIndex) throws IOException {
final List<ImageTypeSpecifier> l = new java.util.ArrayList<ImageTypeSpecifier>(4);
final GDALCommonIIOImageMetadata item = getDatasetMetadata(imageIndex);
imageType = new ImageTypeSpecifier(item.getColorModel(), item.getSampleModel());
l.add(imageType);
return l.iterator();
}
use of javax.imageio.ImageTypeSpecifier in project imageio-ext by geosolutions-it.
the class AsciiGridsImageReader method initializeReader.
/**
* This method initializes the {@link AsciiGridsImageReader} (if it has
* already decoded an input source) by setting some fields, like the
* imageInputStream, the {@link ColorModel} and the {@link SampleModel},
* the image dimensions and so on.
*/
private void initializeReader() {
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.info("Data Initializing");
LOGGER.info("\tImageInputStream: \t" + imageInputStream.toString());
LOGGER.info("\tRasterType:\t\t\t " + rasterReader.getRasterType().toString());
}
// Image dimensions initialization
width = rasterReader.getNCols();
height = rasterReader.getNRows();
// calculating the imageSize. Its value is given by
// nRows*nCols*sampleSizeByte (if DataType is Float
// the size of each sample is 32 bit = 4 Byte)
final int sampleSizeBit = cm.getPixelSize();
final int sampleSizeByte = (sampleSizeBit + 7) / 8;
imageSize = width * height * sampleSizeByte;
// (MIN_SIZE_NEED_TILING), the image needs to be tiled
if (imageSize >= MIN_SIZE_NEED_TILING) {
isTiled = true;
// This implementation supposes that tileWidth is equal to the width
// of the whole image
tileWidth = width;
// actually (need improvements) tileHeight is given by
// the default tile size divided by the tileWidth multiplied by the
// sample size (in byte)
tileHeight = DEFAULT_TILE_SIZE / (tileWidth * sampleSizeByte);
// if computed tileHeight is zero, it is setted to 1 as precaution
if (tileHeight < 1) {
tileHeight = 1;
}
// //
//
// Trick to handle very large rasters
//
// //
sm = cm.createCompatibleSampleModel(tileWidth, tileHeight);
rasterReader.setTilesSize(tileWidth, tileHeight);
} else {
// If no Tiling needed, I set the tile sizes equal to the image
// sizes
tileWidth = width;
tileHeight = height;
}
// this is a trick to workaround
sm = cm.createCompatibleSampleModel(tileHeight, tileWidth);
// image type specifier
imageType = new ImageTypeSpecifier(cm, sm);
}
Aggregations