Example usage for java.awt.image.renderable ParameterBlock getObjectParameter

List of usage examples for java.awt.image.renderable ParameterBlock getObjectParameter

Introduction

In this page you can find the example usage for java.awt.image.renderable ParameterBlock getObjectParameter.

Prototype

public Object getObjectParameter(int index) 

Source Link

Document

Gets a parameter as an object.

Usage

From source file:fr.gael.drb.cortex.topic.sentinel3.jai.operator.QuicklookSlstrRIF.java

/**
 * Should create a new instance of <code>QuicklookSlstrOpImage</code> in the 
 * rendered layer.//ww  w.ja va2 s .co  m
 * This operator could be called by chunks of images.
 * A set of additional information are required to compute the pixels 
 * adjustment such as sun azimuth/elevation and detectors... The methods to
 * extract these informations are also provided here before. 
 * 
 * @param paramBlock The three R/G/B sources images to be "Merged" together
 * to produce the Quicklook.
 * @param renderHints Optionally contains destination image layout.
 */
public RenderedImage create(ParameterBlock paramBlock, RenderingHints hints) {
    long start = System.currentTimeMillis();
    RenderedImage computed_image = null;

    DrbImage red = (DrbImage) paramBlock.getSource(4); // S5
    DrbImage green = (DrbImage) paramBlock.getSource(2); // S3
    DrbImage blue = (DrbImage) paramBlock.getSource(1); // S2

    PixelCorrection[] pc = (PixelCorrection[]) paramBlock.getObjectParameter(0);
    PixelCorrection red_correction = pc != null ? pc[0] : null;
    PixelCorrection green_correction = pc != null ? pc[1] : null;
    PixelCorrection blue_correction = pc != null ? pc[2] : null;

    try {
        computed_image = naturalColors(red.getData(), red_correction, green.getData(), green_correction,
                blue.getData(), blue_correction);
    } catch (Exception e) {
        // Image access problem: try to reprocess this other bands
        LOGGER.info("Natural color band looks bad. Trying S8...");
        DrbImage image = (DrbImage) paramBlock.getSource(7); // S8
        PixelCorrection corr = pc != null ? pc[3] : null;
        try {
            computed_image = grayScaleBand(image.getData(), corr, true);
        } catch (Exception e1) {
            // S8 also bad band: try with S9...
            LOGGER.info("Thermal band S8 looks bad. Trying S9...");
            image = (DrbImage) paramBlock.getSource(8); // S9
            corr = pc != null ? pc[4] : null;
            try {
                computed_image = grayScaleBand(image.getData(), corr, false);
            } catch (Exception e2) {
                throw new UnsupportedOperationException("Image cannot be processed (" + e1.getMessage() + ").",
                        e2);
            }
        }
    }

    LOGGER.info("Quicklook generated in " + (System.currentTimeMillis() - start) / 1000 + " secs");

    return computed_image;
}

From source file:it.geosolutions.jaiext.JAIEXTTest.java

@Test
public void testInterpolation() {
    // Getting the registry
    ConcurrentOperationRegistry registry = JAIExt.getRegistry();
    // Using JAI-EXT for changing the descriptor from JAI-EXT to JAI
    JAIExt.registerJAIDescriptor(SCALE);

    // NEAREST INTERPOLATION

    // Trying to execute the Scale operation by passing JAI-EXT interpolation objects
    // and checking if the registry is able to convert them to JAI interpolation objects
    Object[] args = new Object[1];
    ParameterBlock block = new ParameterBlock();
    // Setting of a JAIEXT interpolation object
    block.set(new InterpolationNearest(null, false, 0, 0), 0);
    // Setting of the parameterblock
    args[0] = block;//from w  ww  .  j  a v a  2 s .com
    registry.checkInterpolation(SCALE, args);

    // Ensure that the modified parameterblock contains a JAI interpolation object
    Object interp = block.getObjectParameter(0);
    assertTrue(interp.getClass().isAssignableFrom(javax.media.jai.InterpolationNearest.class));

    // BILINEAR INTERPOLATION

    // Trying to execute the Scale operation by passing JAI-EXT interpolation objects
    // and checking if the registry is able to convert them to JAI interpolation objects
    args = new Object[1];
    block = new ParameterBlock();
    // Setting of a JAIEXT interpolation object
    int subsampleBits = 8;
    block.set(new InterpolationBilinear(subsampleBits, null, false, 0, 0), 0);
    // Setting of the parameterblock
    args[0] = block;
    registry.checkInterpolation(SCALE, args);

    // Ensure that the modified parameterblock contains a JAI interpolation object
    interp = block.getObjectParameter(0);
    assertTrue(interp.getClass().isAssignableFrom(javax.media.jai.InterpolationBilinear.class));
    assertTrue(((javax.media.jai.InterpolationBilinear) interp).getSubsampleBitsH() == subsampleBits);

    // BICUBIC INTERPOLATION

    // Trying to execute the Scale operation by passing JAI-EXT interpolation objects
    // and checking if the registry is able to convert them to JAI interpolation objects
    args = new Object[1];
    block = new ParameterBlock();
    // Setting of a JAIEXT interpolation object
    block.set(new InterpolationBicubic(subsampleBits, null, false, 0, 0, true, subsampleBits), 0);
    // Setting of the parameterblock
    args[0] = block;
    registry.checkInterpolation(SCALE, args);

    // Ensure that the modified parameterblock contains a JAI interpolation object
    interp = block.getObjectParameter(0);
    assertTrue(interp.getClass().isAssignableFrom(javax.media.jai.InterpolationBicubic.class));
    assertTrue(((javax.media.jai.InterpolationBicubic) interp).getSubsampleBitsH() == subsampleBits);
    assertTrue(((javax.media.jai.InterpolationBicubic) interp).getPrecisionBits() == subsampleBits);

    // BICUBIC 2 INTERPOLATION

    // Trying to execute the Scale operation by passing JAI-EXT interpolation objects
    // and checking if the registry is able to convert them to JAI interpolation objects
    args = new Object[1];
    block = new ParameterBlock();
    // Setting of a JAIEXT interpolation object
    block.set(new InterpolationBicubic(subsampleBits, null, false, 0, 0, false, subsampleBits), 0);
    // Setting of the parameterblock
    args[0] = block;
    registry.checkInterpolation(SCALE, args);

    // Ensure that the modified parameterblock contains a JAI interpolation object
    interp = block.getObjectParameter(0);
    assertTrue(interp.getClass().isAssignableFrom(javax.media.jai.InterpolationBicubic2.class));
    assertTrue(((javax.media.jai.InterpolationBicubic2) interp).getSubsampleBitsH() == subsampleBits);
    assertTrue(((javax.media.jai.InterpolationBicubic2) interp).getPrecisionBits() == subsampleBits);
}