Search in sources :

Example 76 with ImageTypeSpecifier

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);
}
Also used : ImageReadParam(javax.imageio.ImageReadParam) SampleModel(java.awt.image.SampleModel) RenderedOp(javax.media.jai.RenderedOp) ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) ColorSpace(java.awt.color.ColorSpace) ColorModel(java.awt.image.ColorModel) File(java.io.File) ImageLayout(javax.media.jai.ImageLayout) ImageTypeSpecifier(javax.imageio.ImageTypeSpecifier) Test(org.junit.Test) AbstractGDALTest(it.geosolutions.imageio.gdalframework.AbstractGDALTest)

Example 77 with ImageTypeSpecifier

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();
    }
}
Also used : ImageLayout(javax.media.jai.ImageLayout) ImageTypeSpecifier(javax.imageio.ImageTypeSpecifier)

Example 78 with ImageTypeSpecifier

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);
}
Also used : ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) ColorSpace(java.awt.color.ColorSpace) Rectangle(java.awt.Rectangle) ImageTypeSpecifier(javax.imageio.ImageTypeSpecifier) RenderingHints(java.awt.RenderingHints) ImageReadParam(javax.imageio.ImageReadParam) SampleModel(java.awt.image.SampleModel) RenderedOp(javax.media.jai.RenderedOp) ColorModel(java.awt.image.ColorModel) ImageReader(javax.imageio.ImageReader) File(java.io.File) ImageLayout(javax.media.jai.ImageLayout) Test(org.junit.Test) AbstractGDALTest(it.geosolutions.imageio.gdalframework.AbstractGDALTest)

Example 79 with ImageTypeSpecifier

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();
}
Also used : ImageTypeSpecifier(javax.imageio.ImageTypeSpecifier)

Example 80 with ImageTypeSpecifier

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);
}
Also used : ImageTypeSpecifier(javax.imageio.ImageTypeSpecifier)

Aggregations

ImageTypeSpecifier (javax.imageio.ImageTypeSpecifier)88 BufferedImage (java.awt.image.BufferedImage)36 IIOMetadata (javax.imageio.metadata.IIOMetadata)32 ImageWriter (javax.imageio.ImageWriter)29 IIOImage (javax.imageio.IIOImage)23 IOException (java.io.IOException)22 ImageOutputStream (javax.imageio.stream.ImageOutputStream)22 ColorModel (java.awt.image.ColorModel)20 ImageReader (javax.imageio.ImageReader)20 SampleModel (java.awt.image.SampleModel)18 ImageWriteParam (javax.imageio.ImageWriteParam)18 ImageReadParam (javax.imageio.ImageReadParam)16 Rectangle (java.awt.Rectangle)14 File (java.io.File)13 Iterator (java.util.Iterator)12 ColorSpace (java.awt.color.ColorSpace)11 IndexColorModel (java.awt.image.IndexColorModel)11 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 Point (java.awt.Point)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9