home *** CD-ROM | disk | FTP | other *** search
- package sun.awt.image;
-
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.Rectangle;
- import java.awt.image.ColorModel;
- import java.awt.image.ImageConsumer;
- import java.awt.image.ImageObserver;
- import java.util.Hashtable;
-
- public class ImageRepresentation extends ImageWatched implements ImageConsumer {
- int pData;
- InputStreamImageSource src;
- Image image;
- int tag;
- int srcW;
- int srcH;
- int width;
- int height;
- int hints;
- int availinfo;
- boolean offscreen;
- Rectangle newbits;
- private boolean consuming = false;
- private int numWaiters;
-
- ImageRepresentation(Image im, int w, int h, int t) {
- this.image = im;
- this.tag = t;
- if (w != 0 && h != 0) {
- if (w > 0) {
- this.width = w;
- this.availinfo |= 1;
- }
-
- if (h > 0) {
- this.height = h;
- this.availinfo |= 2;
- }
-
- if (this.image.getSource() instanceof InputStreamImageSource) {
- this.src = (InputStreamImageSource)this.image.getSource();
- }
-
- } else {
- throw new IllegalArgumentException();
- }
- }
-
- native void offscreenInit();
-
- public synchronized void reconstruct(int flags) {
- if (this.src != null) {
- this.src.checkSecurity((Object)null, false);
- }
-
- int missinginfo = flags & ~this.availinfo;
- if (missinginfo != 0) {
- ++this.numWaiters;
-
- try {
- this.startProduction();
-
- for(int var9 = flags & ~this.availinfo; var9 != 0; var9 = flags & ~this.availinfo) {
- try {
- this.wait();
- } catch (InterruptedException var7) {
- Thread.currentThread().interrupt();
- return;
- }
- }
-
- } finally {
- this.decrementWaiters();
- }
- }
- }
-
- public synchronized void setDimensions(int w, int h) {
- if (this.src != null) {
- this.src.checkSecurity((Object)null, false);
- }
-
- this.srcW = w;
- this.srcH = h;
- if ((this.availinfo & 1) == 0 && (this.availinfo & 2) == 0) {
- this.width = w;
- this.height = h;
- } else if ((this.availinfo & 1) == 0) {
- this.width = w * this.height / h;
- } else {
- if ((this.availinfo & 2) != 0) {
- return;
- }
-
- this.height = h * this.width / w;
- }
-
- if (this.srcW > 0 && this.srcH > 0 && this.width > 0 && this.height > 0) {
- this.availinfo |= 3;
- } else {
- this.imageComplete(1);
- }
- }
-
- public void setProperties(Hashtable props) {
- if (this.src != null) {
- this.src.checkSecurity((Object)null, false);
- }
-
- }
-
- public void setColorModel(ColorModel model) {
- if (this.src != null) {
- this.src.checkSecurity((Object)null, false);
- }
-
- }
-
- public void setHints(int h) {
- if (this.src != null) {
- this.src.checkSecurity((Object)null, false);
- }
-
- this.hints = h;
- }
-
- private native boolean setBytePixels(int var1, int var2, int var3, int var4, ColorModel var5, byte[] var6, int var7, int var8);
-
- public void setPixels(int x, int y, int w, int h, ColorModel model, byte[] pix, int off, int scansize) {
- if (this.src != null) {
- this.src.checkSecurity((Object)null, false);
- }
-
- boolean ok = false;
- synchronized(this){}
-
- int cx;
- int cy;
- int cw;
- int ch;
- try {
- if (this.newbits == null) {
- this.newbits = new Rectangle(0, 0, this.width, this.height);
- }
-
- if (this.setBytePixels(x, y, w, h, model, pix, off, scansize)) {
- this.availinfo |= 8;
- ok = true;
- }
-
- cx = this.newbits.x;
- cy = this.newbits.y;
- cw = this.newbits.width;
- ch = this.newbits.height;
- } catch (Throwable var16) {
- throw var16;
- }
-
- if (ok && !this.offscreen) {
- ((ImageWatched)this).newInfo(this.image, 8, cx, cy, cw, ch);
- }
-
- }
-
- private native boolean setIntPixels(int var1, int var2, int var3, int var4, ColorModel var5, int[] var6, int var7, int var8);
-
- public void setPixels(int x, int y, int w, int h, ColorModel model, int[] pix, int off, int scansize) {
- if (this.src != null) {
- this.src.checkSecurity((Object)null, false);
- }
-
- boolean ok = false;
- synchronized(this){}
-
- int cx;
- int cy;
- int cw;
- int ch;
- try {
- if (this.newbits == null) {
- this.newbits = new Rectangle(0, 0, this.width, this.height);
- }
-
- if (this.setIntPixels(x, y, w, h, model, pix, off, scansize)) {
- this.availinfo |= 8;
- ok = true;
- }
-
- cx = this.newbits.x;
- cy = this.newbits.y;
- cw = this.newbits.width;
- ch = this.newbits.height;
- } catch (Throwable var16) {
- throw var16;
- }
-
- if (ok && !this.offscreen) {
- ((ImageWatched)this).newInfo(this.image, 8, cx, cy, cw, ch);
- }
-
- }
-
- private native boolean finish(boolean var1);
-
- public void imageComplete(int status) {
- if (this.src != null) {
- this.src.checkSecurity((Object)null, false);
- }
-
- boolean done;
- int info;
- switch (status) {
- case 1:
- this.image.addInfo(64);
- done = true;
- info = 64;
- this.dispose();
- break;
- case 2:
- done = false;
- info = 16;
- break;
- case 3:
- done = true;
- info = 32;
- if (this.finish(false)) {
- this.image.getSource().requestTopDownLeftRightResend(this);
- this.finish(true);
- }
- break;
- case 4:
- default:
- done = true;
- info = 128;
- }
-
- synchronized(this){}
-
- try {
- if (done) {
- this.image.getSource().removeConsumer(this);
- this.consuming = false;
- this.newbits = null;
- }
-
- this.availinfo |= info;
- this.notifyAll();
- } catch (Throwable var6) {
- throw var6;
- }
-
- if (!this.offscreen) {
- ((ImageWatched)this).newInfo(this.image, info, 0, 0, this.width, this.height);
- }
-
- }
-
- void startProduction() {
- if (!this.consuming) {
- this.consuming = true;
- this.image.getSource().startProduction(this);
- }
-
- }
-
- private synchronized void checkConsumption() {
- if (super.watchers == null && this.numWaiters == 0 && (this.availinfo & 32) == 0) {
- this.dispose();
- }
-
- }
-
- public synchronized void removeWatcher(ImageObserver iw) {
- super.removeWatcher(iw);
- this.checkConsumption();
- }
-
- private synchronized void decrementWaiters() {
- --this.numWaiters;
- this.checkConsumption();
- }
-
- public boolean prepare(ImageObserver iw) {
- if (this.src != null) {
- this.src.checkSecurity((Object)null, false);
- }
-
- if ((this.availinfo & 64) != 0) {
- if (iw != null) {
- iw.imageUpdate(this.image, 192, -1, -1, -1, -1);
- }
-
- return false;
- } else {
- boolean done = (this.availinfo & 32) != 0;
- if (!done) {
- ((ImageWatched)this).addWatcher(iw);
- this.startProduction();
- }
-
- return done;
- }
- }
-
- public int check(ImageObserver iw) {
- if (this.src != null) {
- this.src.checkSecurity((Object)null, false);
- }
-
- if ((this.availinfo & 96) != 0) {
- ((ImageWatched)this).addWatcher(iw);
- }
-
- return this.availinfo;
- }
-
- synchronized native void imageDraw(Graphics var1, int var2, int var3, Color var4);
-
- public boolean drawImage(Graphics g, int x, int y, Color c, ImageObserver iw) {
- if (this.src != null) {
- this.src.checkSecurity((Object)null, false);
- }
-
- if ((this.availinfo & 64) != 0) {
- if (iw != null) {
- iw.imageUpdate(this.image, 192, -1, -1, -1, -1);
- }
-
- return false;
- } else {
- boolean done = (this.availinfo & 32) != 0;
- if (!done) {
- ((ImageWatched)this).addWatcher(iw);
- this.startProduction();
- }
-
- this.imageDraw(g, x, y, c);
- return done;
- }
- }
-
- private native void disposeImage();
-
- synchronized void abort() {
- this.image.getSource().removeConsumer(this);
- this.consuming = false;
- this.newbits = null;
- this.disposeImage();
- ((ImageWatched)this).newInfo(this.image, 128, -1, -1, -1, -1);
- this.availinfo &= -121;
- }
-
- synchronized void dispose() {
- this.image.getSource().removeConsumer(this);
- this.consuming = false;
- this.newbits = null;
- this.disposeImage();
- this.availinfo &= -57;
- }
-
- public void finalize() {
- this.disposeImage();
- }
- }
-