home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &… the Search for Life CD 3 / 0_CD-ROM.iso / install / jre1_3 / lib / rt.jar / sun / awt / image / OffScreenImageSource.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  2.7 KB  |  158 lines

  1. package sun.awt.image;
  2.  
  3. import java.awt.image.BufferedImage;
  4. import java.awt.image.ColorModel;
  5. import java.awt.image.DirectColorModel;
  6. import java.awt.image.ImageConsumer;
  7. import java.awt.image.ImageProducer;
  8. import java.awt.image.IndexColorModel;
  9. import java.awt.image.Raster;
  10. import java.awt.image.WritableRaster;
  11. import java.util.Hashtable;
  12.  
  13. public class OffScreenImageSource implements ImageProducer {
  14.    BufferedImage image;
  15.    int width;
  16.    int height;
  17.    private ImageConsumer theConsumer;
  18.  
  19.    public OffScreenImageSource(BufferedImage var1) {
  20.       this.image = var1;
  21.       this.width = var1.getWidth();
  22.       this.height = var1.getHeight();
  23.    }
  24.  
  25.    public synchronized void addConsumer(ImageConsumer var1) {
  26.       this.theConsumer = var1;
  27.       this.produce();
  28.    }
  29.  
  30.    public synchronized boolean isConsumer(ImageConsumer var1) {
  31.       return var1 == this.theConsumer;
  32.    }
  33.  
  34.    public synchronized void removeConsumer(ImageConsumer var1) {
  35.       if (this.theConsumer == var1) {
  36.          this.theConsumer = null;
  37.       }
  38.  
  39.    }
  40.  
  41.    public void startProduction(ImageConsumer var1) {
  42.       this.addConsumer(var1);
  43.    }
  44.  
  45.    public void requestTopDownLeftRightResend(ImageConsumer var1) {
  46.    }
  47.  
  48.    private void sendPixels() {
  49.       ColorModel var1 = this.image.getColorModel();
  50.       WritableRaster var2 = this.image.getRaster();
  51.       int var3 = ((Raster)var2).getNumDataElements();
  52.       int var4 = ((Raster)var2).getDataBuffer().getDataType();
  53.       int[] var5 = new int[this.width * var3];
  54.       boolean var6 = true;
  55.       if (var1 instanceof IndexColorModel) {
  56.          byte[] var7 = new byte[this.width];
  57.          this.theConsumer.setColorModel(var1);
  58.          if (var2 instanceof ByteComponentRaster) {
  59.             var6 = false;
  60.  
  61.             for(int var8 = 0; var8 < this.height; ++var8) {
  62.                ((Raster)var2).getDataElements(0, var8, this.width, 1, var7);
  63.                this.theConsumer.setPixels(0, var8, this.width, 1, var1, var7, 0, this.width);
  64.             }
  65.          } else if (var2 instanceof BytePackedRaster) {
  66.             var6 = false;
  67.  
  68.             for(int var15 = 0; var15 < this.height; ++var15) {
  69.                ((Raster)var2).getPixels(0, var15, this.width, 1, var5);
  70.  
  71.                for(int var9 = 0; var9 < this.width; ++var9) {
  72.                   var7[var9] = (byte)var5[var9];
  73.                }
  74.  
  75.                this.theConsumer.setPixels(0, var15, this.width, 1, var1, var7, 0, this.width);
  76.             }
  77.          } else if (var4 == 2 || var4 == 3) {
  78.             var6 = false;
  79.  
  80.             for(int var16 = 0; var16 < this.height; ++var16) {
  81.                ((Raster)var2).getPixels(0, var16, this.width, 1, var5);
  82.                this.theConsumer.setPixels(0, var16, this.width, 1, var1, var5, 0, this.width);
  83.             }
  84.          }
  85.       } else if (var1 instanceof DirectColorModel) {
  86.          this.theConsumer.setColorModel(var1);
  87.          var6 = false;
  88.          switch (var4) {
  89.             case 0:
  90.                byte[] var17 = new byte[this.width];
  91.  
  92.                for(int var19 = 0; var19 < this.height; ++var19) {
  93.                   ((Raster)var2).getDataElements(0, var19, this.width, 1, var17);
  94.  
  95.                   for(int var21 = 0; var21 < this.width; ++var21) {
  96.                      var5[var21] = var17[var21] & 255;
  97.                   }
  98.  
  99.                   this.theConsumer.setPixels(0, var19, this.width, 1, var1, var5, 0, this.width);
  100.                }
  101.                break;
  102.             case 1:
  103.                short[] var10 = new short[this.width];
  104.  
  105.                for(int var11 = 0; var11 < this.height; ++var11) {
  106.                   ((Raster)var2).getDataElements(0, var11, this.width, 1, var10);
  107.  
  108.                   for(int var12 = 0; var12 < this.width; ++var12) {
  109.                      var5[var12] = var10[var12] & '\uffff';
  110.                   }
  111.  
  112.                   this.theConsumer.setPixels(0, var11, this.width, 1, var1, var5, 0, this.width);
  113.                }
  114.                break;
  115.             case 2:
  116.             default:
  117.                var6 = true;
  118.                break;
  119.             case 3:
  120.                for(int var13 = 0; var13 < this.height; ++var13) {
  121.                   ((Raster)var2).getDataElements(0, var13, this.width, 1, var5);
  122.                   this.theConsumer.setPixels(0, var13, this.width, 1, var1, var5, 0, this.width);
  123.                }
  124.          }
  125.       }
  126.  
  127.       if (var6) {
  128.          ColorModel var14 = ColorModel.getRGBdefault();
  129.          this.theConsumer.setColorModel(var14);
  130.  
  131.          for(int var18 = 0; var18 < this.height; ++var18) {
  132.             for(int var20 = 0; var20 < this.width; ++var20) {
  133.                var5[var20] = this.image.getRGB(var20, var18);
  134.             }
  135.  
  136.             this.theConsumer.setPixels(0, var18, this.width, 1, var14, var5, 0, this.width);
  137.          }
  138.       }
  139.  
  140.    }
  141.  
  142.    private void produce() {
  143.       if (this.theConsumer != null) {
  144.          this.theConsumer.setDimensions(this.image.getWidth(), this.image.getHeight());
  145.       }
  146.  
  147.       if (this.theConsumer != null) {
  148.          this.theConsumer.setProperties(new Hashtable());
  149.       }
  150.  
  151.       this.sendPixels();
  152.       if (this.theConsumer != null) {
  153.          this.theConsumer.imageComplete(2);
  154.       }
  155.  
  156.    }
  157. }
  158.