home *** CD-ROM | disk | FTP | other *** search
- package sun.awt.image;
-
- import java.awt.image.ColorModel;
- import java.awt.image.ImageConsumer;
- import java.awt.image.ImageProducer;
- import java.util.Hashtable;
- import sun.misc.Ref;
-
- public abstract class PixelStore extends Ref {
- int width;
- int height;
- ColorModel colormodel;
- Hashtable properties;
- boolean[] seen;
- int numlines;
- int availinfo;
- int hints;
- static final int NO_BITS_YET = 0;
- static final int BITS_ALLOCATED = 1;
- static final int BITS_LOST = 2;
- int bit_state;
- int[] offsets;
-
- public PixelStore() {
- }
-
- public PixelStore(int w, int h) {
- this.setDimensions(w, h);
- }
-
- public PixelStore(int w, int h, ColorModel cm) {
- this.setDimensions(w, h);
- this.setColorModel(cm);
- }
-
- public synchronized void setDimensions(int w, int h) {
- this.width = w;
- this.height = h;
- this.availinfo |= 3;
- }
-
- public synchronized void setProperties(Hashtable props) {
- this.properties = props;
- this.availinfo |= 4;
- }
-
- public synchronized void setColorModel(ColorModel cm) {
- this.colormodel = cm;
- }
-
- public synchronized void setHints(int h) {
- this.hints = h;
- }
-
- protected void recordPixels(int x, int y, int w, int h) {
- this.numlines = Math.max(this.numlines, y + h);
- if ((this.hints & 2) == 0) {
- if (this.seen == null) {
- this.seen = new boolean[this.height];
- }
-
- for(int i = 0; i < h; ++i) {
- this.seen[y + i] = true;
- }
- }
-
- }
-
- public synchronized boolean setPixels(int x, int y, int w, int h, byte[] pix, int srcoff, int scansize) {
- this.recordPixels(x, y, w, h);
- Object[] lines = ((Ref)this).get();
- if (lines != null) {
- int i = srcoff;
-
- for(int Y = y; Y < y + h; ++Y) {
- byte[] ras = (byte[])lines[Y];
- int dstoff = this.offsets[Y] + x;
- System.arraycopy(pix, i, ras, dstoff, w);
- i += scansize;
- }
-
- this.availinfo |= 8;
- }
-
- return lines != null;
- }
-
- public synchronized boolean setPixels(int x, int y, int w, int h, int[] pix, int srcoff, int scansize) {
- this.recordPixels(x, y, w, h);
- Object[] lines = ((Ref)this).get();
- if (lines != null) {
- int i = srcoff;
-
- for(int Y = y; Y < y + h; ++Y) {
- int[] ras = (int[])lines[Y];
- int dstoff = this.offsets[Y] + x;
- System.arraycopy(pix, i, ras, dstoff, w);
- i += scansize;
- }
-
- this.availinfo |= 8;
- }
-
- return lines != null;
- }
-
- public synchronized void imageComplete() {
- if (((Ref)this).get() != null && this.bit_state == 1) {
- this.numlines = this.height;
- this.hints = 30;
- this.availinfo |= 32;
- }
-
- }
-
- public synchronized int getWidth() {
- return this.width;
- }
-
- public synchronized int getHeight() {
- return this.height;
- }
-
- public synchronized ColorModel getColorModel() {
- return this.colormodel;
- }
-
- public synchronized int getBitState() {
- if (this.bit_state == 1 && this.numlines > 0) {
- ((Ref)this).get();
- }
-
- return this.bit_state;
- }
-
- abstract void replayLines(ImageConsumer var1, int var2, int var3, Object var4);
-
- public synchronized boolean replay(ImageProducer ip, ImageConsumer ic) {
- return this.replay(ip, ic, true);
- }
-
- public synchronized boolean replay(ImageProducer ip, ImageConsumer ic, boolean full) {
- if (full && (this.availinfo & 1) != 0 && (this.availinfo & 2) != 0) {
- ic.setDimensions(this.width, this.height);
- if (!ip.isConsumer(ic)) {
- return true;
- }
- }
-
- if (full && (this.availinfo & 4) != 0) {
- ic.setProperties(this.properties);
- }
-
- if (full && this.colormodel != null) {
- ic.setColorModel(this.colormodel);
- if (!ip.isConsumer(ic)) {
- return true;
- }
- }
-
- if (this.hints != 0) {
- ic.setHints(this.hints & 30);
- if (!ip.isConsumer(ic)) {
- return true;
- }
- }
-
- Object[] lines = null;
- if (this.bit_state == 1 && this.numlines > 0) {
- lines = ((Ref)this).get();
- }
-
- if (this.bit_state == 2) {
- return false;
- } else {
- Thread me = Thread.currentThread();
- if (ImageFetcher.isFetcher(me) && me.getPriority() > 3) {
- SecurityManager.setScopePermission();
- me.setPriority(3);
- SecurityManager.resetScopePermission();
- }
-
- if (lines != null) {
- Object prevline = null;
- int prevcount = 0;
-
- for(int i = 0; i < this.numlines; ++i) {
- if (this.seen != null && !this.seen[i]) {
- if (prevline != null) {
- this.replayLines(ic, i - prevcount, prevcount, prevline);
- if (!ip.isConsumer(ic)) {
- return true;
- }
-
- prevline = null;
- prevcount = 0;
- }
- } else {
- Object line = lines[i];
- if (prevline != line && prevline != null) {
- this.replayLines(ic, i - prevcount, prevcount, prevline);
- if (!ip.isConsumer(ic)) {
- return true;
- }
-
- prevcount = 0;
- }
-
- prevline = line;
- ++prevcount;
- }
- }
-
- if (prevline != null) {
- this.replayLines(ic, this.numlines - prevcount, prevcount, prevline);
- if (!ip.isConsumer(ic)) {
- return true;
- }
- }
- }
-
- if (full && this.bit_state == 1 && (this.availinfo & 32) != 0) {
- ic.imageComplete(3);
- }
-
- return true;
- }
- }
-
- abstract Object allocateLines(int var1);
-
- public Object reconstitute() {
- Object[] lines = null;
- if (this.bit_state == 0) {
- if ((this.availinfo & 2) == 0 || (this.availinfo & 1) == 0 || this.colormodel == null) {
- return null;
- }
-
- this.bit_state = 1;
- lines = new Object[this.height];
- this.offsets = new int[this.height];
- int i = 0;
-
- while(i < this.height) {
- int trylines = this.height - i;
- Object chunk = null;
-
- while(chunk == null && trylines > 0) {
- try {
- chunk = this.allocateLines(trylines);
- if (chunk == null) {
- break;
- }
- } catch (OutOfMemoryError var6) {
- chunk = null;
- trylines /= 2;
- }
- }
-
- if (chunk == null) {
- this.bit_state = 2;
- return null;
- }
-
- for(int off = 0; trylines > 0; --trylines) {
- lines[i] = chunk;
- this.offsets[i] = off;
- off += this.width;
- ++i;
- }
- }
- } else if (this.bit_state == 1) {
- this.bit_state = 2;
- }
-
- return lines;
- }
- }
-