home *** CD-ROM | disk | FTP | other *** search
- package sun.awt.image;
-
- import java.awt.image.BufferedImage;
- import java.awt.image.ColorModel;
- import java.awt.image.DirectColorModel;
- import java.awt.image.ImageConsumer;
- import java.awt.image.ImageProducer;
- import java.awt.image.IndexColorModel;
- import java.awt.image.Raster;
- import java.awt.image.WritableRaster;
- import java.util.Hashtable;
-
- public class OffScreenImageSource implements ImageProducer {
- BufferedImage image;
- int width;
- int height;
- private ImageConsumer theConsumer;
-
- public OffScreenImageSource(BufferedImage var1) {
- this.image = var1;
- this.width = var1.getWidth();
- this.height = var1.getHeight();
- }
-
- public synchronized void addConsumer(ImageConsumer var1) {
- this.theConsumer = var1;
- this.produce();
- }
-
- public synchronized boolean isConsumer(ImageConsumer var1) {
- return var1 == this.theConsumer;
- }
-
- public synchronized void removeConsumer(ImageConsumer var1) {
- if (this.theConsumer == var1) {
- this.theConsumer = null;
- }
-
- }
-
- public void startProduction(ImageConsumer var1) {
- this.addConsumer(var1);
- }
-
- public void requestTopDownLeftRightResend(ImageConsumer var1) {
- }
-
- private void sendPixels() {
- ColorModel var1 = this.image.getColorModel();
- WritableRaster var2 = this.image.getRaster();
- int var3 = ((Raster)var2).getNumDataElements();
- int var4 = ((Raster)var2).getDataBuffer().getDataType();
- int[] var5 = new int[this.width * var3];
- boolean var6 = true;
- if (var1 instanceof IndexColorModel) {
- byte[] var7 = new byte[this.width];
- this.theConsumer.setColorModel(var1);
- if (var2 instanceof ByteComponentRaster) {
- var6 = false;
-
- for(int var8 = 0; var8 < this.height; ++var8) {
- ((Raster)var2).getDataElements(0, var8, this.width, 1, var7);
- this.theConsumer.setPixels(0, var8, this.width, 1, var1, var7, 0, this.width);
- }
- } else if (var2 instanceof BytePackedRaster) {
- var6 = false;
-
- for(int var15 = 0; var15 < this.height; ++var15) {
- ((Raster)var2).getPixels(0, var15, this.width, 1, var5);
-
- for(int var9 = 0; var9 < this.width; ++var9) {
- var7[var9] = (byte)var5[var9];
- }
-
- this.theConsumer.setPixels(0, var15, this.width, 1, var1, var7, 0, this.width);
- }
- } else if (var4 == 2 || var4 == 3) {
- var6 = false;
-
- for(int var16 = 0; var16 < this.height; ++var16) {
- ((Raster)var2).getPixels(0, var16, this.width, 1, var5);
- this.theConsumer.setPixels(0, var16, this.width, 1, var1, var5, 0, this.width);
- }
- }
- } else if (var1 instanceof DirectColorModel) {
- this.theConsumer.setColorModel(var1);
- var6 = false;
- switch (var4) {
- case 0:
- byte[] var17 = new byte[this.width];
-
- for(int var19 = 0; var19 < this.height; ++var19) {
- ((Raster)var2).getDataElements(0, var19, this.width, 1, var17);
-
- for(int var21 = 0; var21 < this.width; ++var21) {
- var5[var21] = var17[var21] & 255;
- }
-
- this.theConsumer.setPixels(0, var19, this.width, 1, var1, var5, 0, this.width);
- }
- break;
- case 1:
- short[] var10 = new short[this.width];
-
- for(int var11 = 0; var11 < this.height; ++var11) {
- ((Raster)var2).getDataElements(0, var11, this.width, 1, var10);
-
- for(int var12 = 0; var12 < this.width; ++var12) {
- var5[var12] = var10[var12] & '\uffff';
- }
-
- this.theConsumer.setPixels(0, var11, this.width, 1, var1, var5, 0, this.width);
- }
- break;
- case 2:
- default:
- var6 = true;
- break;
- case 3:
- for(int var13 = 0; var13 < this.height; ++var13) {
- ((Raster)var2).getDataElements(0, var13, this.width, 1, var5);
- this.theConsumer.setPixels(0, var13, this.width, 1, var1, var5, 0, this.width);
- }
- }
- }
-
- if (var6) {
- ColorModel var14 = ColorModel.getRGBdefault();
- this.theConsumer.setColorModel(var14);
-
- for(int var18 = 0; var18 < this.height; ++var18) {
- for(int var20 = 0; var20 < this.width; ++var20) {
- var5[var20] = this.image.getRGB(var20, var18);
- }
-
- this.theConsumer.setPixels(0, var18, this.width, 1, var14, var5, 0, this.width);
- }
- }
-
- }
-
- private void produce() {
- if (this.theConsumer != null) {
- this.theConsumer.setDimensions(this.image.getWidth(), this.image.getHeight());
- }
-
- if (this.theConsumer != null) {
- this.theConsumer.setProperties(new Hashtable());
- }
-
- this.sendPixels();
- if (this.theConsumer != null) {
- this.theConsumer.imageComplete(2);
- }
-
- }
- }
-