home *** CD-ROM | disk | FTP | other *** search
- package java.awt.image;
-
- import java.util.Hashtable;
-
- public class MemoryImageSource implements ImageProducer {
- int width;
- int height;
- ColorModel model;
- Object pixels;
- int pixeloffset;
- int pixelscan;
- Hashtable properties;
- private ImageConsumer theConsumer;
-
- public MemoryImageSource(int w, int h, ColorModel cm, byte[] pix, int off, int scan) {
- this.initialize(w, h, cm, pix, off, scan, (Hashtable)null);
- }
-
- public MemoryImageSource(int w, int h, ColorModel cm, byte[] pix, int off, int scan, Hashtable props) {
- this.initialize(w, h, cm, pix, off, scan, props);
- }
-
- public MemoryImageSource(int w, int h, ColorModel cm, int[] pix, int off, int scan) {
- this.initialize(w, h, cm, pix, off, scan, (Hashtable)null);
- }
-
- public MemoryImageSource(int w, int h, ColorModel cm, int[] pix, int off, int scan, Hashtable props) {
- this.initialize(w, h, cm, pix, off, scan, props);
- }
-
- private void initialize(int w, int h, ColorModel cm, Object pix, int off, int scan, Hashtable props) {
- this.width = w;
- this.height = h;
- this.model = cm;
- this.pixels = pix;
- this.pixeloffset = off;
- this.pixelscan = scan;
- if (props == null) {
- props = new Hashtable();
- }
-
- this.properties = props;
- }
-
- public MemoryImageSource(int w, int h, int[] pix, int off, int scan) {
- this.initialize(w, h, ColorModel.getRGBdefault(), pix, off, scan, (Hashtable)null);
- }
-
- public MemoryImageSource(int w, int h, int[] pix, int off, int scan, Hashtable props) {
- this.initialize(w, h, ColorModel.getRGBdefault(), pix, off, scan, props);
- }
-
- public synchronized void addConsumer(ImageConsumer ic) {
- this.theConsumer = ic;
-
- try {
- this.produce();
- } catch (Exception var2) {
- if (this.theConsumer != null) {
- this.theConsumer.imageComplete(1);
- }
- }
-
- this.theConsumer = null;
- }
-
- public synchronized boolean isConsumer(ImageConsumer ic) {
- return ic == this.theConsumer;
- }
-
- public synchronized void removeConsumer(ImageConsumer ic) {
- if (this.theConsumer == ic) {
- this.theConsumer = null;
- }
-
- }
-
- public void startProduction(ImageConsumer ic) {
- this.addConsumer(ic);
- }
-
- public void requestTopDownLeftRightResend(ImageConsumer ic) {
- }
-
- private void produce() {
- if (this.theConsumer != null) {
- this.theConsumer.setDimensions(this.width, this.height);
- }
-
- if (this.theConsumer != null) {
- this.theConsumer.setProperties(this.properties);
- }
-
- if (this.theConsumer != null) {
- this.theConsumer.setColorModel(this.model);
- }
-
- if (this.theConsumer != null) {
- this.theConsumer.setHints(30);
- }
-
- if (this.theConsumer != null) {
- if (this.pixels instanceof byte[]) {
- this.theConsumer.setPixels(0, 0, this.width, this.height, this.model, (byte[])this.pixels, this.pixeloffset, this.pixelscan);
- } else {
- this.theConsumer.setPixels(0, 0, this.width, this.height, this.model, (int[])this.pixels, this.pixeloffset, this.pixelscan);
- }
- }
-
- if (this.theConsumer != null) {
- this.theConsumer.imageComplete(3);
- }
-
- }
- }
-