Search in sources :

Example 16 with ImageLayout

use of javax.media.jai.ImageLayout in project imageio-ext by geosolutions-it.

the class BsbVrtTest method imageRead.

/**
 * Test read exploiting common JAI operations (Crop-Translate-Rotate)
 *
 * @throws FileNotFoundException
 * @throws IOException
 */
@org.junit.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);
    final ImageLayout l = new ImageLayout();
    l.setTileGridXOffset(0).setTileGridYOffset(0).setTileHeight(32).setTileWidth(32);
    // get a RenderedImage
    RenderedOp image = JAI.create("ImageRead", pbjImageRead, new RenderingHints(JAI.KEY_IMAGE_LAYOUT, l));
    if (TestData.isInteractiveTest()) {
        ImageIOUtilities.visualize(image, "test", true);
    } else {
        Assert.assertNotNull(image.getData());
    }
    Assert.assertEquals(50, image.getWidth());
    Assert.assertEquals(50, image.getHeight());
    ImageIOUtilities.disposeImage(image);
}
Also used : ImageReadParam(javax.imageio.ImageReadParam) RenderedOp(javax.media.jai.RenderedOp) ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) File(java.io.File) ImageLayout(javax.media.jai.ImageLayout)

Example 17 with ImageLayout

use of javax.media.jai.ImageLayout 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);
}
Also used : IIOMetadata(javax.imageio.metadata.IIOMetadata) RenderedOp(javax.media.jai.RenderedOp) ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) ImageWriter(javax.imageio.ImageWriter) GeoTiffImageWriterSpi(it.geosolutions.imageio.plugins.geotiff.GeoTiffImageWriterSpi) ImageReader(javax.imageio.ImageReader) GeoTiffImageReaderSpi(it.geosolutions.imageio.plugins.geotiff.GeoTiffImageReaderSpi) File(java.io.File) ImageLayout(javax.media.jai.ImageLayout) AbstractGDALTest(it.geosolutions.imageio.gdalframework.AbstractGDALTest) Test(org.junit.Test)

Example 18 with ImageLayout

use of javax.media.jai.ImageLayout 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 19 with ImageLayout

use of javax.media.jai.ImageLayout in project imageio-ext by geosolutions-it.

the class JpegVrtTest method read.

/**
 * Simple test read
 *
 * @throws FileNotFoundException
 * @throws IOException
 */
@Test
public void read() throws FileNotFoundException, IOException {
    if (!isGDALAvailable) {
        return;
    }
    final ParameterBlockJAI pbjImageRead;
    final ImageReadParam irp = new ImageReadParam();
    final String fileName = "bw_sample.jpg.vrt";
    final File file = TestData.file(this, fileName);
    irp.setSourceSubsampling(1, 2, 0, 0);
    pbjImageRead = new ParameterBlockJAI("ImageRead");
    pbjImageRead.setParameter("Input", file);
    pbjImageRead.setParameter("readParam", irp);
    final ImageLayout l = new ImageLayout();
    l.setTileGridXOffset(0).setTileGridYOffset(0).setTileHeight(512).setTileWidth(512);
    RenderedOp image = JAI.create("ImageRead", pbjImageRead, new RenderingHints(JAI.KEY_IMAGE_LAYOUT, l));
    if (TestData.isInteractiveTest())
        Viewer.visualizeAllInformation(image, fileName);
    else
        Assert.assertNotNull(image.getTiles());
    ImageIOUtilities.disposeImage(image);
}
Also used : ImageReadParam(javax.imageio.ImageReadParam) RenderedOp(javax.media.jai.RenderedOp) ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) File(java.io.File) ImageLayout(javax.media.jai.ImageLayout) Test(org.junit.Test) AbstractGDALTest(it.geosolutions.imageio.gdalframework.AbstractGDALTest)

Example 20 with ImageLayout

use of javax.media.jai.ImageLayout 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)

Aggregations

ImageLayout (javax.media.jai.ImageLayout)36 File (java.io.File)29 RenderedOp (javax.media.jai.RenderedOp)28 ParameterBlockJAI (javax.media.jai.ParameterBlockJAI)26 RenderingHints (java.awt.RenderingHints)23 Test (org.junit.Test)23 ImageReadParam (javax.imageio.ImageReadParam)20 AbstractGDALTest (it.geosolutions.imageio.gdalframework.AbstractGDALTest)18 ImageReader (javax.imageio.ImageReader)12 Rectangle (java.awt.Rectangle)8 FileNotFoundException (java.io.FileNotFoundException)7 ImageWriter (javax.imageio.ImageWriter)6 RenderedImage (java.awt.image.RenderedImage)5 ImageTypeSpecifier (javax.imageio.ImageTypeSpecifier)5 ImageWriteParam (javax.imageio.ImageWriteParam)4 IIOMetadata (javax.imageio.metadata.IIOMetadata)4 ColorSpace (java.awt.color.ColorSpace)3 BufferedImage (java.awt.image.BufferedImage)3 ColorModel (java.awt.image.ColorModel)3 SampleModel (java.awt.image.SampleModel)3