Search in sources :

Example 26 with ImageLayout

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

the class MrSIDTest method jaiOperations.

/**
 * Test read exploiting common JAI operations (Crop-Translate-Rotate)
 *
 * @throws FileNotFoundException
 * @throws IOException
 */
@Test
public void jaiOperations() throws FileNotFoundException, IOException {
    if (!isMrSidAvailable) {
        return;
    }
    try {
        final 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);
        // re-tile on the fly to 512x512
        final ImageLayout l = new ImageLayout();
        l.setTileGridXOffset(0).setTileGridYOffset(0).setTileHeight(512).setTileWidth(512);
        pbjImageRead = new ParameterBlockJAI("ImageRead");
        pbjImageRead.setParameter("Input", file);
        pbjImageRead.setParameter("readParam", irp);
        // get a RenderedImage
        RenderedOp image = JAI.create("ImageRead", pbjImageRead, new RenderingHints(JAI.KEY_IMAGE_LAYOUT, l));
        if (TestData.isInteractiveTest())
            Viewer.visualizeAllInformation(image, "Subsampling Read");
        else
            Assert.assertNotNull(image.getTiles());
        // ////////////////////////////////////////////////////////////////
        // preparing to crop
        // ////////////////////////////////////////////////////////////////
        final ParameterBlockJAI pbjCrop = new ParameterBlockJAI("Crop");
        pbjCrop.addSource(image);
        Float xCrop = new Float(image.getWidth() * 3 / 4.0 + image.getMinX());
        Float yCrop = new Float(image.getHeight() * 3 / 4.0 + image.getMinY());
        Float cropWidth = new Float(image.getWidth() / 4.0);
        Float cropHeigth = new Float(image.getHeight() / 4.0);
        pbjCrop.setParameter("x", xCrop);
        pbjCrop.setParameter("y", yCrop);
        pbjCrop.setParameter("width", cropWidth);
        pbjCrop.setParameter("height", cropHeigth);
        final RenderedOp croppedImage = JAI.create("Crop", pbjCrop);
        if (TestData.isInteractiveTest())
            Viewer.visualizeAllInformation(croppedImage, "Cropped Image");
        else
            Assert.assertNotNull(croppedImage.getTiles());
        // ////////////////////////////////////////////////////////////////
        // preparing to translate
        // ////////////////////////////////////////////////////////////////
        final ParameterBlockJAI pbjTranslate = new ParameterBlockJAI("Translate");
        pbjTranslate.addSource(croppedImage);
        Float xTrans = new Float(-croppedImage.getMinX());
        Float yTrans = new Float(-croppedImage.getMinY());
        pbjTranslate.setParameter("xTrans", xTrans);
        pbjTranslate.setParameter("yTrans", yTrans);
        final RenderedOp translatedImage = JAI.create("Translate", pbjTranslate);
        if (TestData.isInteractiveTest())
            Viewer.visualizeAllInformation(translatedImage, "Translated Image");
        else
            Assert.assertNotNull(image.getTiles());
        // ////////////////////////////////////////////////////////////////
        // preparing to rotate
        // ////////////////////////////////////////////////////////////////
        final ParameterBlockJAI pbjRotate = new ParameterBlockJAI("Rotate");
        pbjRotate.addSource(translatedImage);
        Float xOrigin = new Float(cropWidth.floatValue() / 2);
        Float yOrigin = new Float(cropHeigth.floatValue() / 2);
        Float angle = new Float(java.lang.Math.PI / 2);
        pbjRotate.setParameter("xOrigin", xOrigin);
        pbjRotate.setParameter("yOrigin", yOrigin);
        pbjRotate.setParameter("angle", angle);
        final RenderedOp rotatedImage = JAI.create("Rotate", pbjRotate);
        if (TestData.isInteractiveTest())
            Viewer.visualizeAllInformation(rotatedImage, "Rotated Image");
        else {
            Assert.assertNotNull(image.getTiles());
            ImageIOUtilities.disposeImage(image);
        }
    } catch (FileNotFoundException fnfe) {
        warningMessage();
    }
}
Also used : ImageReadParam(javax.imageio.ImageReadParam) RenderedOp(javax.media.jai.RenderedOp) ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) ImageLayout(javax.media.jai.ImageLayout) Point(java.awt.Point) RenderingHints(java.awt.RenderingHints) AbstractGDALTest(it.geosolutions.imageio.gdalframework.AbstractGDALTest) Test(org.junit.Test)

Example 27 with ImageLayout

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

the class Doq1VrtTest 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(32).setTileWidth(32);
    // 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);
}
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 28 with ImageLayout

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

the class DtedVrtTest 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 ImageLayout l = new ImageLayout();
    l.setTileGridXOffset(0).setTileGridYOffset(0).setTileHeight(32).setTileWidth(32);
    // get a RenderedImage
    ImageReader reader = new VRTImageReaderSpi().createReaderInstance();
    reader.setInput(file);
    RenderedImage image = reader.read(0);
    if (TestData.isInteractiveTest()) {
        ImageIOUtilities.visualize(image, "test", true);
    } else {
        Assert.assertNotNull(image.getData());
    }
    Assert.assertEquals(121, image.getWidth());
    Assert.assertEquals(121, image.getHeight());
    reader.dispose();
}
Also used : ImageReader(javax.imageio.ImageReader) RenderedImage(java.awt.image.RenderedImage) File(java.io.File) ImageLayout(javax.media.jai.ImageLayout)

Example 29 with ImageLayout

use of javax.media.jai.ImageLayout 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());
}
Also used : ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) Rectangle(java.awt.Rectangle) ImageWriter(javax.imageio.ImageWriter) ImageWriteParam(javax.imageio.ImageWriteParam) RenderingHints(java.awt.RenderingHints) IIOMetadata(javax.imageio.metadata.IIOMetadata) ImageReadParam(javax.imageio.ImageReadParam) GDALImageReadParam(it.geosolutions.imageio.gdalframework.GDALImageReadParam) RenderedOp(javax.media.jai.RenderedOp) ImageReader(javax.imageio.ImageReader) File(java.io.File) ImageLayout(javax.media.jai.ImageLayout) AbstractGDALTest(it.geosolutions.imageio.gdalframework.AbstractGDALTest) Test(org.junit.Test)

Example 30 with ImageLayout

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

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