Search in sources :

Example 6 with ImageLayout

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

the class JP2KReadTest method jaiOperations.

/**
 * Test read exploiting common JAI operations (Crop-Translate-Rotate)
 *
 * @throws FileNotFoundException
 * @throws IOException
 */
@Test
public void jaiOperations() throws IOException {
    if (!isJp2MrSidDriverAvailable) {
        return;
    }
    final File inputFile = TestData.file(this, fileName);
    // ////////////////////////////////////////////////////////////////
    // preparing to read
    // ////////////////////////////////////////////////////////////////
    final ParameterBlockJAI pbjImageRead;
    final ImageReadParam irp = new ImageReadParam();
    Integer xSubSampling = new Integer(2);
    Integer ySubSampling = new Integer(2);
    Integer xSubSamplingOffset = new Integer(0);
    Integer ySubSamplingOffset = new Integer(0);
    irp.setSourceSubsampling(xSubSampling.intValue(), ySubSampling.intValue(), xSubSamplingOffset.intValue(), ySubSamplingOffset.intValue());
    pbjImageRead = new ParameterBlockJAI("ImageRead");
    pbjImageRead.setParameter("Input", inputFile);
    pbjImageRead.setParameter("readParam", irp);
    pbjImageRead.setParameter("Reader", new JP2GDALMrSidImageReaderSpi().createReaderInstance());
    final ImageLayout layout = new ImageLayout();
    layout.setTileGridXOffset(0).setTileGridYOffset(0).setTileHeight(512).setTileWidth(512);
    RenderedOp image = JAI.create("ImageRead", pbjImageRead, new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout));
    if (TestData.isInteractiveTest())
        Viewer.visualizeAllInformation(image, "subsampled");
    // ////////////////////////////////////////////////////////////////
    // preparing to crop
    // ////////////////////////////////////////////////////////////////
    final ParameterBlockJAI pbjCrop = new ParameterBlockJAI("Crop");
    pbjCrop.addSource(image);
    // Setting a square crop to avoid blanks zone when rotating.
    Float xCrop = new Float(image.getMinX() + image.getWidth() / 4);
    Float yCrop = new Float(image.getMinX() + image.getWidth() / 4);
    Float cropWidth = new Float(image.getWidth() / 4);
    Float cropHeigth = new Float(image.getWidth() / 4);
    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");
    // ////////////////////////////////////////////////////////////////
    // preparing to translate
    // ////////////////////////////////////////////////////////////////
    final ParameterBlockJAI pbjTranslate = new ParameterBlockJAI("Translate");
    pbjTranslate.addSource(croppedImage);
    Float xTrans = new Float(xCrop.floatValue() * (-1));
    Float yTrans = new Float(yCrop.floatValue() * (-1));
    pbjTranslate.setParameter("xTrans", xTrans);
    pbjTranslate.setParameter("yTrans", yTrans);
    final RenderedOp translatedImage = JAI.create("Translate", pbjTranslate);
    if (TestData.isInteractiveTest())
        Viewer.visualizeAllInformation(translatedImage, "translated");
    // ////////////////////////////////////////////////////////////////
    // 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);
    StringBuilder title = new StringBuilder("SUBSAMP:").append("X[").append(xSubSampling.toString()).append("]-Y[").append(ySubSampling.toString()).append("]-Xof[").append(xSubSamplingOffset.toString()).append("]-Yof[").append(ySubSamplingOffset).append("]CROP:X[").append(xCrop.toString()).append("]-Y[").append(yCrop.toString()).append("]-W[").append(cropWidth.toString()).append("]-H[").append(cropHeigth.toString()).append("]TRANS:X[").append(xTrans.toString()).append("]-Y[").append(yTrans.toString()).append("]ROTATE:xOrig[").append(xOrigin.toString()).append("]-yOrig[").append(yOrigin.toString()).append("]-ang[").append(angle.toString()).append("]");
    if (TestData.isInteractiveTest())
        Viewer.visualizeAllInformation(rotatedImage, title.toString());
    else
        Assert.assertNotNull(rotatedImage.getTiles());
    ImageIOUtilities.disposeImage(rotatedImage);
}
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) RenderingHints(java.awt.RenderingHints) Test(org.junit.Test) AbstractGDALTest(it.geosolutions.imageio.gdalframework.AbstractGDALTest)

Example 7 with ImageLayout

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

the class JP2KReadTest method testRead.

/**
 * Simple test read
 *
 * @throws FileNotFoundException
 * @throws IOException
 */
@org.junit.Test
public void testRead() throws FileNotFoundException, IOException {
    if (!isJP2ECWAvailable) {
        return;
    }
    final ParameterBlockJAI pbjImageRead;
    final File file = TestData.file(this, fileName);
    pbjImageRead = new ParameterBlockJAI("ImageRead");
    pbjImageRead.setParameter("Input", file);
    pbjImageRead.setParameter("Reader", new JP2GDALEcwImageReaderSpi().createReaderInstance());
    final ImageLayout layout = new ImageLayout();
    layout.setTileGridXOffset(0).setTileGridYOffset(0).setTileHeight(256).setTileWidth(256);
    RenderedOp image = JAI.create("ImageRead", pbjImageRead, new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout));
    if (TestData.isInteractiveTest())
        Viewer.visualizeAllInformation(image, "gdaljp2k");
    else
        Assert.assertNotNull(image.getTiles());
    ImageIOUtilities.disposeImage(image);
}
Also used : RenderedOp(javax.media.jai.RenderedOp) ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) File(java.io.File) ImageLayout(javax.media.jai.ImageLayout) RenderingHints(java.awt.RenderingHints)

Example 8 with ImageLayout

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

the class ECWTest method imageRead.

// ecwp
/**
 * Test reading of a RGB image
 *
 * @throws FileNotFoundException
 * @throws IOException
 */
@Test
public void imageRead() throws FileNotFoundException, IOException {
    if (!isECWAvailable)
        return;
    final ParameterBlockJAI pbjImageRead;
    final EnhancedImageReadParam irp = new EnhancedImageReadParam();
    final String fileName = "sample.ecw";
    final File file = TestData.file(this, fileName);
    irp.setSourceSubsampling(2, 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
        image.getTiles();
    Assert.assertEquals(200, image.getWidth());
    Assert.assertEquals(100, image.getHeight());
    ImageIOUtilities.disposeImage(image);
}
Also used : EnhancedImageReadParam(it.geosolutions.imageio.imageioimpl.EnhancedImageReadParam) RenderedOp(javax.media.jai.RenderedOp) ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) File(java.io.File) ImageLayout(javax.media.jai.ImageLayout) RenderingHints(java.awt.RenderingHints) Test(org.junit.Test) AbstractGDALTest(it.geosolutions.imageio.gdalframework.AbstractGDALTest)

Example 9 with ImageLayout

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

the class DOQ2Test 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;
    try {
        file = TestData.file(this, fileName);
    } catch (FileNotFoundException fnfe) {
        super.warningMessage();
        return;
    }
    // ////////////////////////////////////////////////////////////////
    // 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);
}
Also used : ImageReadParam(javax.imageio.ImageReadParam) RenderedOp(javax.media.jai.RenderedOp) ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) FileNotFoundException(java.io.FileNotFoundException) Rectangle(java.awt.Rectangle) File(java.io.File) ImageLayout(javax.media.jai.ImageLayout) RenderingHints(java.awt.RenderingHints) Test(org.junit.Test) AbstractGDALTest(it.geosolutions.imageio.gdalframework.AbstractGDALTest)

Example 10 with ImageLayout

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

the class ImageReadMTCRIF method create.

public RenderedImage create(ParameterBlock pb, RenderingHints rh) {
    // Value to be returned.
    RenderedImage image = null;
    // Get the reader.
    readerProvided = pb.getObjectParameter(0) != null && pb.getObjectParameter(0) instanceof ImageReader;
    ImageReader reader = getImageReader(pb);
    // Proceed if a compatible reader was found.
    if (reader != null) {
        // Get the remaining parameters required.
        int imageIndex = pb.getIntParameter(1);
        ImageReadParam param = (ImageReadParam) pb.getObjectParameter(7);
        boolean readThumbnails = ((Boolean) pb.getObjectParameter(3)).booleanValue();
        // Initialize the layout.
        ImageLayout layout = (rh != null && rh.containsKey(JAI.KEY_IMAGE_LAYOUT)) ? (ImageLayout) rh.get(JAI.KEY_IMAGE_LAYOUT) : new ImageLayout();
        try {
            // Get the parameter input.
            Object paramInput = pb.getObjectParameter(0);
            // Get the reader input.
            Object readerInput = reader.getInput();
            // Set the stream to close when the OpImage is disposed.
            ImageInputStream streamToClose = null;
            if (readerInput != paramInput && readerInput instanceof ImageInputStream) {
                streamToClose = (ImageInputStream) readerInput;
            }
            // Create the rendering.
            image = new ImageReadOpImageMT(layout, rh, param, reader, imageIndex, readThumbnails, streamToClose, readerProvided);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    return image;
}
Also used : ImageReadParam(javax.imageio.ImageReadParam) ImageInputStream(javax.imageio.stream.ImageInputStream) RenderedImage(java.awt.image.RenderedImage) ImageReader(javax.imageio.ImageReader) ImageLayout(javax.media.jai.ImageLayout) IOException(java.io.IOException)

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