Search in sources :

Example 21 with ParameterBlock

use of java.awt.image.renderable.ParameterBlock in project vcell by virtualcell.

the class OverlayImageDisplayJAI method makeAlpha.

/**
 * Method makeAlpha.
 * @param src RenderedImage
 * @param b float
 * @return RenderedImage
 */
private RenderedImage makeAlpha(int width, int height, float b) {
    // get color band
    // src.getColorModel().getNumColorComponents();
    int band = 1;
    // ignore alpha channel
    band = band > 3 ? 3 : band;
    // make alpha channel paramenter
    Byte[] bandValues = new Byte[band];
    for (int i = 0; i < band; i++) {
        bandValues[i] = new Byte((byte) (b * SCALE_MAX));
    }
    // make alpha channel paramenter
    ParameterBlock pb = new ParameterBlock();
    pb.add((float) width);
    pb.add((float) height);
    pb.add(bandValues);
    // make alpha channel
    return JAI.create("constant", pb, null);
}
Also used : ParameterBlock(java.awt.image.renderable.ParameterBlock) DataBufferByte(java.awt.image.DataBufferByte) Point(java.awt.Point)

Example 22 with ParameterBlock

use of java.awt.image.renderable.ParameterBlock in project imageio-ext by geosolutions-it.

the class ImageReadPropertyGenerator method createCollection.

/**
 * Type-safe convenience method for creating a {@link Collection}
 * representing the "ImageRead" operation in collection mode. The
 * method packs the parameters into a new <code>ParameterBlock</code>
 * and invokes
 * {@link JAI#createCollection(String,ParameterBlock, RenderingHints)}.
 *
 * @param input The input source.
 * @param imageChoice The indices of the images to read.
 * @param readMetadata Whether metadata should be read if available.
 * @param readThumbnails Whether thumbnails should be read if available.
 * @param verifyInput Whether to verify the validity of the input source.
 * @param listeners EventListeners to be registered with the ImageReader.
 * @param locale The Locale for the ImageReader to use.
 * @param readParam Java Image I/O read parameter instance.
 * @param reader Java Image I/O reader instance.
 * @param hints Hints possibly including an <code>ImageLayout</code>.
 * @return a collection of images derived from the input source.
 */
public static Collection createCollection(ImageInputStream input, int[] imageChoice, Boolean readMetadata, Boolean readThumbnails, Boolean verifyInput, EventListener[] listeners, Locale locale, ImageReadParam readParam, ImageReader reader, RenderingHints hints) {
    ParameterBlock args = new ParameterBlock();
    args.add(input);
    args.add(imageChoice);
    args.add(readMetadata);
    args.add(readThumbnails);
    args.add(verifyInput);
    args.add(listeners);
    args.add(locale);
    args.add(readParam);
    args.add(reader);
    return JAI.createCollection(OPERATION_NAME, args, hints);
}
Also used : ParameterBlock(java.awt.image.renderable.ParameterBlock)

Example 23 with ParameterBlock

use of java.awt.image.renderable.ParameterBlock in project imageio-ext by geosolutions-it.

the class ImageReadMTCIF method createStatic.

static CollectionImage createStatic(ParameterBlock args, RenderingHints hints) {
    // Clone the ParameterBlock as the ImageChoice will be overwritten.
    ParameterBlock renderedPB = (ParameterBlock) args.clone();
    // Get the ImageChoice.
    int[] imageIndices = (int[]) args.getObjectParameter(1);
    // Variables to be set in the subsequent "if" block.
    // XXX Could probably collapse the if block into a single code seq.
    int numSources;
    ImageIOCollectionImageMT imageList = null;
    if (imageIndices == null) {
        // null-valued ImageChoice: load all images.
        // Load the first image.
        renderedPB.set(0, 1);
        PlanarImage image = JAI.create("ImageRead", renderedPB, hints);
        // Get the ImageReader property.
        Object readerProperty = image.getProperty(ImageReadDescriptor.PROPERTY_NAME_IMAGE_READER);
        // Try to read the number of images.
        if (readerProperty instanceof ImageReader) {
            try {
                // XXX Really should not allow search here. If search
                // is disallowed and -1 is returned from getNumImages(),
                // then "ImageRead" should just be called until an
                // IndexOutOfBoundsException is caught.
                numSources = ((ImageReader) readerProperty).getNumImages(true);
            } catch (Exception e) {
                // IOException
                // Default to one source.
                numSources = 1;
            }
        } else {
            numSources = 1;
        }
        // Allocate and fill index array.
        imageIndices = new int[numSources];
        for (int i = 0; i < numSources; i++) {
            imageIndices[i] = i;
        }
        // Allocate list and add first image.
        imageList = new ImageIOCollectionImageMT(numSources);
        imageList.add(image);
    } else {
        // Set the number of sources and create the list.
        numSources = imageIndices.length;
        imageList = new ImageIOCollectionImageMT(numSources);
        // Load the first image requested.
        renderedPB.set(imageIndices[0], 1);
        PlanarImage image = JAI.create("ImageRead", renderedPB, hints);
        // Add the first image to the list.
        imageList.add(image);
    }
    // Read subsequent images and add to the list.
    for (int idx = 1; idx < numSources; idx++) {
        renderedPB.set(imageIndices[idx], 1);
        PlanarImage image = JAI.create("ImageRead", renderedPB, hints);
        imageList.add(image);
    }
    // Get the first image in the Collection.
    PlanarImage firstImage = (PlanarImage) imageList.get(0);
    // Transfer properties to the Collection.
    ImageReadMTCRIF.copyProperty(firstImage, imageList, ImageReadDescriptor.PROPERTY_NAME_IMAGE_READ_PARAM);
    ImageReadMTCRIF.copyProperty(firstImage, imageList, ImageReadDescriptor.PROPERTY_NAME_IMAGE_READER);
    ImageReadMTCRIF.copyProperty(firstImage, imageList, ImageReadDescriptor.PROPERTY_NAME_METADATA_STREAM);
    return imageList;
}
Also used : ParameterBlock(java.awt.image.renderable.ParameterBlock) ImageReader(javax.imageio.ImageReader) PlanarImage(javax.media.jai.PlanarImage)

Example 24 with ParameterBlock

use of java.awt.image.renderable.ParameterBlock in project ant by apache.

the class Rotate method performRotate.

/**
 * Rotate an image.
 * @param image the image to rotate.
 * @return the rotated image.
 */
public PlanarImage performRotate(PlanarImage image) {
    float tAngle = (float) (angle * (Math.PI / HALF_CIRCLE));
    ParameterBlock pb = new ParameterBlock();
    pb.addSource(image);
    pb.add(0.0F);
    pb.add(0.0F);
    pb.add(tAngle);
    pb.add(new InterpolationNearest());
    return JAI.create("Rotate", pb, null);
}
Also used : InterpolationNearest(javax.media.jai.InterpolationNearest) ParameterBlock(java.awt.image.renderable.ParameterBlock)

Example 25 with ParameterBlock

use of java.awt.image.renderable.ParameterBlock in project ant by apache.

the class Scale method performScale.

/**
 * Scale an image.
 * @param image the image to scale.
 * @return the scaled image.
 */
public PlanarImage performScale(PlanarImage image) {
    ParameterBlock pb = new ParameterBlock();
    pb.addSource(image);
    float xFl = getWidth();
    float yFl = getHeight();
    if (!xPercent) {
        xFl = xFl / image.getWidth();
    }
    if (!yPercent) {
        yFl = yFl / image.getHeight();
    }
    if ("width".equals(proportions)) {
        yFl = xFl;
    } else if ("height".equals(proportions)) {
        xFl = yFl;
    } else if ("fit".equals(proportions)) {
        yFl = Math.min(xFl, yFl);
        xFl = yFl;
    } else if ("cover".equals(proportions)) {
        yFl = Math.max(xFl, yFl);
        xFl = yFl;
    }
    pb.add(Float.valueOf(xFl));
    pb.add(Float.valueOf(yFl));
    log("\tScaling to " + (xFl * HUNDRED) + "% x " + (yFl * HUNDRED) + "%");
    return JAI.create("scale", pb);
}
Also used : ParameterBlock(java.awt.image.renderable.ParameterBlock)

Aggregations

ParameterBlock (java.awt.image.renderable.ParameterBlock)29 RenderingHints (java.awt.RenderingHints)5 RenderedImage (java.awt.image.RenderedImage)5 FileOpException (digilib.io.FileOpException)3 BufferedImage (java.awt.image.BufferedImage)3 Point (java.awt.Point)2 ColorModel (java.awt.image.ColorModel)2 ComponentColorModel (java.awt.image.ComponentColorModel)2 DirectColorModel (java.awt.image.DirectColorModel)2 IndexColorModel (java.awt.image.IndexColorModel)2 PackedColorModel (java.awt.image.PackedColorModel)2 BorderExtender (javax.media.jai.BorderExtender)2 BorderExtenderConstant (javax.media.jai.BorderExtenderConstant)2 PlanarImage (javax.media.jai.PlanarImage)2 TransposeType (javax.media.jai.operator.TransposeType)2 Color (java.awt.Color)1 Graphics2D (java.awt.Graphics2D)1 AffineTransform (java.awt.geom.AffineTransform)1 AffineTransformOp (java.awt.image.AffineTransformOp)1 DataBufferByte (java.awt.image.DataBufferByte)1