Search in sources :

Example 1 with ImageConsumer

use of java.awt.image.ImageConsumer in project jdk8u_jdk by JetBrains.

the class MemoryImageSource method newPixels.

/**
     * Sends a rectangular region of the buffer of pixels to any
     * ImageConsumers that are currently interested in the data for
     * this image.
     * If the framenotify parameter is true then the consumers are
     * also notified that an animation frame is complete.
     * This method only has effect if the animation flag has been
     * turned on through the setAnimated() method.
     * If the full buffer update flag was turned on with the
     * setFullBufferUpdates() method then the rectangle parameters
     * will be ignored and the entire buffer will always be sent.
     * @param x the x coordinate of the upper left corner of the rectangle
     * of pixels to be sent
     * @param y the y coordinate of the upper left corner of the rectangle
     * of pixels to be sent
     * @param w the width of the rectangle of pixels to be sent
     * @param h the height of the rectangle of pixels to be sent
     * @param framenotify <code>true</code> if the consumers should be sent a
     * {@link ImageConsumer#SINGLEFRAMEDONE SINGLEFRAMEDONE} notification
     * @see ImageConsumer
     * @see #setAnimated
     * @see #setFullBufferUpdates
     */
public synchronized void newPixels(int x, int y, int w, int h, boolean framenotify) {
    if (animating) {
        if (fullbuffers) {
            x = y = 0;
            w = width;
            h = height;
        } else {
            if (x < 0) {
                w += x;
                x = 0;
            }
            if (x + w > width) {
                w = width - x;
            }
            if (y < 0) {
                h += y;
                y = 0;
            }
            if (y + h > height) {
                h = height - y;
            }
        }
        if ((w <= 0 || h <= 0) && !framenotify) {
            return;
        }
        Enumeration enum_ = theConsumers.elements();
        while (enum_.hasMoreElements()) {
            ImageConsumer ic = (ImageConsumer) enum_.nextElement();
            if (w > 0 && h > 0) {
                sendPixels(ic, x, y, w, h);
            }
            if (framenotify && isConsumer(ic)) {
                ic.imageComplete(ImageConsumer.SINGLEFRAMEDONE);
            }
        }
    }
}
Also used : Enumeration(java.util.Enumeration) ImageConsumer(java.awt.image.ImageConsumer)

Example 2 with ImageConsumer

use of java.awt.image.ImageConsumer in project jdk8u_jdk by JetBrains.

the class MemoryImageSource method setFullBufferUpdates.

/**
     * Specifies whether this animated memory image should always be
     * updated by sending the complete buffer of pixels whenever
     * there is a change.
     * This flag is ignored if the animation flag is not turned on
     * through the setAnimated() method.
     * <p>This method should be called immediately after the
     * MemoryImageSource is constructed and before an image is
     * created with it to ensure that all ImageConsumers will
     * receive the correct pixel delivery hints.
     * @param fullbuffers <code>true</code> if the complete pixel
     *             buffer should always
     * be sent
     * @see #setAnimated
     */
public synchronized void setFullBufferUpdates(boolean fullbuffers) {
    if (this.fullbuffers == fullbuffers) {
        return;
    }
    this.fullbuffers = fullbuffers;
    if (animating) {
        Enumeration enum_ = theConsumers.elements();
        while (enum_.hasMoreElements()) {
            ImageConsumer ic = (ImageConsumer) enum_.nextElement();
            ic.setHints(fullbuffers ? (ImageConsumer.TOPDOWNLEFTRIGHT | ImageConsumer.COMPLETESCANLINES) : ImageConsumer.RANDOMPIXELORDER);
        }
    }
}
Also used : Enumeration(java.util.Enumeration) ImageConsumer(java.awt.image.ImageConsumer)

Example 3 with ImageConsumer

use of java.awt.image.ImageConsumer in project jdk8u_jdk by JetBrains.

the class RenderableImageProducer method run.

/**
     * The runnable method for this class. This will produce an image using
     * the current RenderableImage and RenderContext and send it to all the
     * ImageConsumer currently registered with this class.
     */
public void run() {
    // First get the rendered image
    RenderedImage rdrdImage;
    if (rc != null) {
        rdrdImage = rdblImage.createRendering(rc);
    } else {
        rdrdImage = rdblImage.createDefaultRendering();
    }
    // And its ColorModel
    ColorModel colorModel = rdrdImage.getColorModel();
    Raster raster = rdrdImage.getData();
    SampleModel sampleModel = raster.getSampleModel();
    DataBuffer dataBuffer = raster.getDataBuffer();
    if (colorModel == null) {
        colorModel = ColorModel.getRGBdefault();
    }
    int minX = raster.getMinX();
    int minY = raster.getMinY();
    int width = raster.getWidth();
    int height = raster.getHeight();
    Enumeration icList;
    ImageConsumer ic;
    // Set up the ImageConsumers
    icList = ics.elements();
    while (icList.hasMoreElements()) {
        ic = (ImageConsumer) icList.nextElement();
        ic.setDimensions(width, height);
        ic.setHints(ImageConsumer.TOPDOWNLEFTRIGHT | ImageConsumer.COMPLETESCANLINES | ImageConsumer.SINGLEPASS | ImageConsumer.SINGLEFRAME);
    }
    // Get RGB pixels from the raster scanline by scanline and
    // send to consumers.
    int[] pix = new int[width];
    int i, j;
    int numBands = sampleModel.getNumBands();
    int[] tmpPixel = new int[numBands];
    for (j = 0; j < height; j++) {
        for (i = 0; i < width; i++) {
            sampleModel.getPixel(i, j, tmpPixel, dataBuffer);
            pix[i] = colorModel.getDataElement(tmpPixel, 0);
        }
        // Now send the scanline to the Consumers
        icList = ics.elements();
        while (icList.hasMoreElements()) {
            ic = (ImageConsumer) icList.nextElement();
            ic.setPixels(0, j, width, 1, colorModel, pix, 0, width);
        }
    }
    // Now tell the consumers we're done.
    icList = ics.elements();
    while (icList.hasMoreElements()) {
        ic = (ImageConsumer) icList.nextElement();
        ic.imageComplete(ImageConsumer.STATICIMAGEDONE);
    }
}
Also used : SampleModel(java.awt.image.SampleModel) Enumeration(java.util.Enumeration) ColorModel(java.awt.image.ColorModel) DirectColorModel(java.awt.image.DirectColorModel) ImageConsumer(java.awt.image.ImageConsumer) Raster(java.awt.image.Raster) RenderedImage(java.awt.image.RenderedImage) DataBuffer(java.awt.image.DataBuffer)

Example 4 with ImageConsumer

use of java.awt.image.ImageConsumer in project jdk8u_jdk by JetBrains.

the class MemoryImageSource method setAnimated.

/**
     * Changes this memory image into a multi-frame animation or a
     * single-frame static image depending on the animated parameter.
     * <p>This method should be called immediately after the
     * MemoryImageSource is constructed and before an image is
     * created with it to ensure that all ImageConsumers will
     * receive the correct multi-frame data.  If an ImageConsumer
     * is added to this ImageProducer before this flag is set then
     * that ImageConsumer will see only a snapshot of the pixel
     * data that was available when it connected.
     * @param animated <code>true</code> if the image is a
     *       multi-frame animation
     */
public synchronized void setAnimated(boolean animated) {
    this.animating = animated;
    if (!animating) {
        Enumeration enum_ = theConsumers.elements();
        while (enum_.hasMoreElements()) {
            ImageConsumer ic = (ImageConsumer) enum_.nextElement();
            ic.imageComplete(ImageConsumer.STATICIMAGEDONE);
            if (isConsumer(ic)) {
                ic.imageComplete(ImageConsumer.IMAGEERROR);
            }
        }
        theConsumers.removeAllElements();
    }
}
Also used : Enumeration(java.util.Enumeration) ImageConsumer(java.awt.image.ImageConsumer)

Aggregations

ImageConsumer (java.awt.image.ImageConsumer)4 Enumeration (java.util.Enumeration)4 ColorModel (java.awt.image.ColorModel)1 DataBuffer (java.awt.image.DataBuffer)1 DirectColorModel (java.awt.image.DirectColorModel)1 Raster (java.awt.image.Raster)1 RenderedImage (java.awt.image.RenderedImage)1 SampleModel (java.awt.image.SampleModel)1