FileDocCategorySizeDatePackage
MemoryImageSource.javaAPI DocAndroid 1.5 API18578Wed May 06 22:41:54 BST 2009java.awt.image

MemoryImageSource

public class MemoryImageSource extends Object implements ImageProducer
The MemoryImageSource class is used to produces pixels of an image from an array. This class can manage a memory image which contains an animation or custom rendering.
since
Android 1.0

Fields Summary
int
width
The width.
int
height
The height.
ColorModel
cm
The cm.
byte[]
bData
The b data.
int[]
iData
The i data.
int
offset
The offset.
int
scanline
The scanline.
Hashtable
properties
The properties.
Vector
consumers
The consumers.
boolean
animated
The animated.
boolean
fullbuffers
The fullbuffers.
int
dataType
The data type.
static final int
DATA_TYPE_BYTE
The Constant DATA_TYPE_BYTE.
static final int
DATA_TYPE_INT
The Constant DATA_TYPE_INT.
Constructors Summary
public MemoryImageSource(int w, int h, ColorModel cm, int[] pix, int off, int scan, Hashtable props)
Instantiates a new MemoryImageSource with the specified parameters.

param
w the width of the rectangular area of pixels.
param
h the height of the rectangular area of pixels.
param
cm the specified ColorModel.
param
pix the pixel array.
param
off the offset in the pixel array.
param
scan the distance from one pixel's row to the next in the pixel array.
param
props the set of properties to be used for image processing.


                                                                                                                                                                           
                
               
        init(w, h, cm, pix, off, scan, props);
    
public MemoryImageSource(int w, int h, ColorModel cm, byte[] pix, int off, int scan, Hashtable props)
Instantiates a new MemoryImageSource with the specified parameters.

param
w the width of the rectangular area of pixels.
param
h the height of the rectangular area of pixels.
param
cm the specified ColorModel.
param
pix the pixel array.
param
off the offset in the pixel array.
param
scan the distance from one pixel's row to the next in the pixel array.
param
props the set of properties to be used for image processing.

        init(w, h, cm, pix, off, scan, props);
    
public MemoryImageSource(int w, int h, int[] pix, int off, int scan, Hashtable props)
Instantiates a new MemoryImageSource with the specified parameters and default RGB ColorModel.

param
w the width of the rectangular area of pixels.
param
h the height of the rectangular area of pixels.
param
pix the pixel array.
param
off the offset in the pixel array.
param
scan the distance from one pixel's row to the next in the pixel array.
param
props the set of properties to be used for image processing.

        init(w, h, ColorModel.getRGBdefault(), pix, off, scan, props);
    
public MemoryImageSource(int w, int h, ColorModel cm, int[] pix, int off, int scan)
Instantiates a new MemoryImageSource with the specified parameters.

param
w the width of the rectangular area of pixels.
param
h the height of the rectangular area of pixels.
param
cm the specified ColorModel.
param
pix the pixel array.
param
off the offset in the pixel array.
param
scan the distance from one pixel's row to the next in the pixel array.

        init(w, h, cm, pix, off, scan, null);
    
public MemoryImageSource(int w, int h, ColorModel cm, byte[] pix, int off, int scan)
Instantiates a new MemoryImageSource with the specified parameters.

param
w the width of the rectangular area of pixels.
param
h the height of the rectangular area of pixels.
param
cm the specified ColorModel.
param
pix the pixel array.
param
off the offset in the pixel array.
param
scan the distance from one pixel's row to the next in the pixel array.

        init(w, h, cm, pix, off, scan, null);
    
public MemoryImageSource(int w, int h, int[] pix, int off, int scan)
Instantiates a new MemoryImageSource with the specified parameters and default RGB ColorModel.

param
w the width of the rectangular area of pixels.
param
h the height of the rectangular area of pixels.
param
pix the pixels array.
param
off the offset in the pixel array.
param
scan the distance from one pixel's row to the next in the pixel array.

        init(w, h, ColorModel.getRGBdefault(), pix, off, scan, null);
    
Methods Summary
public synchronized voidaddConsumer(java.awt.image.ImageConsumer ic)

        if (ic == null || consumers.contains(ic)) {
            return;
        }
        consumers.addElement(ic);
    
private voidinit(int width, int height, java.awt.image.ColorModel model, byte[] pixels, int off, int scan, java.util.Hashtable prop)
Inits the.

param
width the width.
param
height the height.
param
model the model.
param
pixels the pixels.
param
off the off.
param
scan the scan.
param
prop the prop.


        this.width = width;
        this.height = height;
        this.cm = model;
        this.bData = pixels;
        this.offset = off;
        this.scanline = scan;
        this.properties = prop;
        this.dataType = DATA_TYPE_BYTE;
        this.consumers = new Vector<ImageConsumer>();

    
private voidinit(int width, int height, java.awt.image.ColorModel model, int[] pixels, int off, int scan, java.util.Hashtable prop)
Inits the.

param
width the width.
param
height the height.
param
model the model.
param
pixels the pixels.
param
off the off.
param
scan the scan.
param
prop the prop.


        this.width = width;
        this.height = height;
        this.cm = model;
        this.iData = pixels;
        this.offset = off;
        this.scanline = scan;
        this.properties = prop;
        this.dataType = DATA_TYPE_INT;
        this.consumers = new Vector<ImageConsumer>();
    
public synchronized booleanisConsumer(java.awt.image.ImageConsumer ic)

        return consumers.contains(ic);
    
public synchronized voidnewPixels(int[] newpix, java.awt.image.ColorModel newmodel, int offset, int scansize)
Replaces the pixel data with a new pixel array for holding the pixels for this image. If an animation flag is set to true value by the setAnimated() method, the new pixels will be immediately delivered to the ImageConsumers.

param
newpix the new pixel array.
param
newmodel the new ColorModel.
param
offset the offset in the array.
param
scansize the distance from one row of pixels to the next row in the pixel array.

        this.dataType = DATA_TYPE_INT;
        this.iData = newpix;
        this.cm = newmodel;
        this.offset = offset;
        this.scanline = scansize;
        newPixels();
    
public synchronized voidnewPixels(byte[] newpix, java.awt.image.ColorModel newmodel, int offset, int scansize)
Replaces the pixel data with a new pixel array for holding the pixels for this image. If an animation flag is set to true value by the setAnimated() method, the new pixels will be immediately delivered to the ImageConsumers.

param
newpix the new pixel array.
param
newmodel the new ColorModel.
param
offset the offset in the array.
param
scansize the distance from one row of pixels to the next row in the pixel array.

        this.dataType = DATA_TYPE_BYTE;
        this.bData = newpix;
        this.cm = newmodel;
        this.offset = offset;
        this.scanline = scansize;
        newPixels();
    
public synchronized voidnewPixels(int x, int y, int w, int h, boolean framenotify)
Sends the specified rectangular area of the buffer to ImageConsumers and notifies them that an animation frame is completed only if the {@code framenotify} parameter is true. That works only if the animated flag has been set to true by the setAnimated() method. If the full buffer update flag has been set to true by the setFullBufferUpdates() method, then the entire buffer will always be sent ignoring parameters.

param
x the X coordinate of the rectangular area.
param
y the Y coordinate of the rectangular area.
param
w the width of the rectangular area.
param
h the height of the rectangular area.
param
framenotify true if a SINGLEFRAMEDONE notification should be sent to the registered consumers, false otherwise.

        if (animated) {
            if (fullbuffers) {
                x = 0;
                y = 0;
                w = width;
                h = height;
            } else {
                if (x < 0) {
                    w += x;
                    x = 0;
                }
                if (w > width) {
                    w = width - x;
                }
                if (y < 0) {
                    h += y;
                    y = 0;
                }
            }
            if (h > height) {
                h = height - y;
            }
            Object consAr[] = consumers.toArray();
            for (Object element : consAr) {
                ImageConsumer con = (ImageConsumer)element;
                try {
                    if (w > 0 && h > 0) {
                        setPixels(con, x, y, w, h);
                    }
                    if (framenotify) {
                        con.imageComplete(ImageConsumer.SINGLEFRAMEDONE);
                    }
                } catch (Exception ex) {
                    if (isConsumer(con)) {
                        con.imageComplete(ImageConsumer.IMAGEERROR);
                    }
                    if (isConsumer(con)) {
                        removeConsumer(con);
                    }
                }
            }
        }
    
public synchronized voidnewPixels(int x, int y, int w, int h)
Sends the specified rectangular area of the buffer to the ImageConsumers and notifies them that an animation frame is completed if the animated flag has been set to true by the setAnimated() method. If the full buffer update flag has been set to true by the setFullBufferUpdates() method, then the entire buffer will always be sent ignoring parameters.

param
x the X coordinate of the rectangular area.
param
y the Y coordinate of the rectangular area.
param
w the width of the rectangular area.
param
h the height of the rectangular area.

        newPixels(x, y, w, h, true);
    
public voidnewPixels()
Sends a new buffer of pixels to the ImageConsumers and notifies them that an animation frame is completed if the animated flag has been set to true by the setAnimated() method.

        newPixels(0, 0, width, height, true);
    
public synchronized voidremoveConsumer(java.awt.image.ImageConsumer ic)

        consumers.removeElement(ic);
    
public voidrequestTopDownLeftRightResend(java.awt.image.ImageConsumer ic)

    
public synchronized voidsetAnimated(boolean animated)
Sets the flag that tells whether this memory image has more than one frame (for animation): true for multiple frames, false if this class represents a single frame image.

param
animated whether this image represents an animation.

        if (this.animated == animated) {
            return;
        }
        Object consAr[] = consumers.toArray();
        for (Object element : consAr) {
            ImageConsumer con = (ImageConsumer)element;
            try {
                con.imageComplete(ImageConsumer.STATICIMAGEDONE);
            } catch (Exception e) {
                if (isConsumer(con)) {
                    con.imageComplete(ImageConsumer.IMAGEERROR);
                }
            }
            if (isConsumer(con)) {
                removeConsumer(con);
            }
        }
        this.animated = animated;
    
public synchronized voidsetFullBufferUpdates(boolean fullbuffers)
Sets the full buffer updates flag to true. If this is an animated image, the image consumers hints are updated accordingly.

param
fullbuffers the true if the pixel buffer should be sent always.

        if (this.fullbuffers == fullbuffers) {
            return;
        }
        this.fullbuffers = fullbuffers;
        if (animated) {
            Object consAr[] = consumers.toArray();
            for (Object element : consAr) {
                ImageConsumer con = (ImageConsumer)element;
                try {
                    if (fullbuffers) {
                        con.setHints(ImageConsumer.TOPDOWNLEFTRIGHT
                                | ImageConsumer.COMPLETESCANLINES);
                    } else {
                        con.setHints(ImageConsumer.RANDOMPIXELORDER);
                    }
                } catch (Exception e) {
                    if (isConsumer(con)) {
                        con.imageComplete(ImageConsumer.IMAGEERROR);
                    }
                    if (isConsumer(con)) {
                        removeConsumer(con);
                    }
                }
            }
        }
    
private synchronized voidsetHeader(java.awt.image.ImageConsumer con)
Sets the header.

param
con the new header.

        con.setDimensions(width, height);
        con.setProperties(properties);
        con.setColorModel(cm);
        con
                .setHints(animated ? (fullbuffers ? (ImageConsumer.TOPDOWNLEFTRIGHT | ImageConsumer.COMPLETESCANLINES)
                        : ImageConsumer.RANDOMPIXELORDER)
                        : (ImageConsumer.TOPDOWNLEFTRIGHT | ImageConsumer.COMPLETESCANLINES
                                | ImageConsumer.SINGLEPASS | ImageConsumer.SINGLEFRAME));
    
private voidsetPixels(java.awt.image.ImageConsumer con, int x, int y, int w, int h)
Sets the pixels.

param
con the con.
param
x the x.
param
y the y.
param
w the w.
param
h the h.

        int pixelOff = scanline * y + offset + x;

        switch (dataType) {
            case DATA_TYPE_BYTE:
                con.setPixels(x, y, w, h, cm, bData, pixelOff, scanline);
                break;
            case DATA_TYPE_INT:
                con.setPixels(x, y, w, h, cm, iData, pixelOff, scanline);
                break;
            default:
                // awt.22A=Wrong type of pixels array
                throw new IllegalArgumentException(Messages.getString("awt.22A")); //$NON-NLS-1$
        }
    
public voidstartProduction(java.awt.image.ImageConsumer ic)

        if (!isConsumer(ic) && ic != null) {
            consumers.addElement(ic);
        }
        try {
            setHeader(ic);
            setPixels(ic, 0, 0, width, height);
            if (animated) {
                ic.imageComplete(ImageConsumer.SINGLEFRAMEDONE);
            } else {
                ic.imageComplete(ImageConsumer.STATICIMAGEDONE);
                if (isConsumer(ic)) {
                    removeConsumer(ic);
                }
            }
        } catch (Exception e) {
            if (isConsumer(ic)) {
                ic.imageComplete(ImageConsumer.IMAGEERROR);
            }
            if (isConsumer(ic)) {
                removeConsumer(ic);
            }
        }