MemoryImageSourcepublic class MemoryImageSource extends Object implements ImageProducerThe 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. |
Fields Summary |
---|
int | widthThe width. | int | heightThe height. | ColorModel | cmThe cm. | byte[] | bDataThe b data. | int[] | iDataThe i data. | int | offsetThe offset. | int | scanlineThe scanline. | Hashtable | propertiesThe properties. | Vector | consumersThe consumers. | boolean | animatedThe animated. | boolean | fullbuffersThe fullbuffers. | int | dataTypeThe data type. | static final int | DATA_TYPE_BYTEThe Constant DATA_TYPE_BYTE. | static final int | DATA_TYPE_INTThe 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.
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.
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.
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.
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.
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.
init(w, h, ColorModel.getRGBdefault(), pix, off, scan, null);
|
Methods Summary |
---|
public synchronized void | addConsumer(java.awt.image.ImageConsumer ic)
if (ic == null || consumers.contains(ic)) {
return;
}
consumers.addElement(ic);
| private void | init(int width, int height, java.awt.image.ColorModel model, byte[] pixels, int off, int scan, java.util.Hashtable prop)Inits the.
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 void | init(int width, int height, java.awt.image.ColorModel model, int[] pixels, int off, int scan, java.util.Hashtable prop)Inits the.
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 boolean | isConsumer(java.awt.image.ImageConsumer ic)
return consumers.contains(ic);
| public synchronized void | newPixels(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.
this.dataType = DATA_TYPE_INT;
this.iData = newpix;
this.cm = newmodel;
this.offset = offset;
this.scanline = scansize;
newPixels();
| public synchronized void | newPixels(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.
this.dataType = DATA_TYPE_BYTE;
this.bData = newpix;
this.cm = newmodel;
this.offset = offset;
this.scanline = scansize;
newPixels();
| public synchronized void | newPixels(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.
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 void | newPixels(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.
newPixels(x, y, w, h, true);
| public void | newPixels()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 void | removeConsumer(java.awt.image.ImageConsumer ic)
consumers.removeElement(ic);
| public void | requestTopDownLeftRightResend(java.awt.image.ImageConsumer ic)
| public synchronized void | setAnimated(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.
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 void | setFullBufferUpdates(boolean fullbuffers)Sets the full buffer updates flag to true. If this is an animated image,
the image consumers hints are updated accordingly.
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 void | setHeader(java.awt.image.ImageConsumer con)Sets the 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 void | setPixels(java.awt.image.ImageConsumer con, int x, int y, int w, int h)Sets the pixels.
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 void | startProduction(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);
}
}
|
|