home *** CD-ROM | disk | FTP | other *** search
/ PC for Alla 1998 November / PFA9811.ISO / docs / surf / ie3w95nt / install.exe / ieakjava.exe / classr.exe / sun / awt / image / JPEGImageDecoder.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-01-31  |  2.8 KB  |  110 lines

  1. package sun.awt.image;
  2.  
  3. import java.awt.image.ColorModel;
  4. import java.awt.image.DirectColorModel;
  5. import java.awt.image.ImageConsumer;
  6. import java.awt.image.IndexColorModel;
  7. import java.io.IOException;
  8. import java.io.InputStream;
  9. import java.util.Hashtable;
  10.  
  11. public class JPEGImageDecoder extends ImageDecoder {
  12.    private static ColorModel RGBcolormodel;
  13.    private static ColorModel Graycolormodel;
  14.    PixelStore store;
  15.    Hashtable props = new Hashtable();
  16.    private static final int hintflags = 22;
  17.  
  18.    private native void readImage(InputStream var1, byte[] var2) throws ImageFormatException;
  19.  
  20.    public JPEGImageDecoder(InputStreamImageSource var1, InputStream var2) {
  21.       super(var1, var2);
  22.    }
  23.  
  24.    public synchronized boolean catchupConsumer(InputStreamImageSource var1, ImageConsumer var2) {
  25.       return this.store == null || this.store.replay(var1, var2);
  26.    }
  27.  
  28.    public synchronized void makeStore(int var1, int var2, boolean var3) {
  29.       if (var3) {
  30.          this.store = new PixelStore8(var1, var2);
  31.       } else {
  32.          this.store = new PixelStore32(var1, var2);
  33.       }
  34.  
  35.    }
  36.  
  37.    private static void error(String var0) throws ImageFormatException {
  38.       throw new ImageFormatException(var0);
  39.    }
  40.  
  41.    public boolean sendHeaderInfo(int var1, int var2, boolean var3, boolean var4) {
  42.       super.source.setDimensions(var1, var2);
  43.       this.makeStore(var1, var2, var3);
  44.       super.source.setProperties(this.props);
  45.       this.store.setProperties(this.props);
  46.       ColorModel var5 = var3 ? Graycolormodel : RGBcolormodel;
  47.       super.source.setColorModel(var5);
  48.       this.store.setColorModel(var5);
  49.       int var6 = 22;
  50.       if (!var4) {
  51.          var6 |= 8;
  52.       }
  53.  
  54.       super.source.setHints(22);
  55.       this.store.setHints(22);
  56.       return true;
  57.    }
  58.  
  59.    public boolean sendPixels(int[] var1, int var2) {
  60.       int var3 = super.source.setPixels(0, var2, var1.length, 1, RGBcolormodel, var1, 0, var1.length);
  61.       if (this.store.setPixels(0, var2, var1.length, 1, var1, 0, var1.length)) {
  62.          ++var3;
  63.       }
  64.  
  65.       return var3 > 0;
  66.    }
  67.  
  68.    public boolean sendPixels(byte[] var1, int var2) {
  69.       int var3 = super.source.setPixels(0, var2, var1.length, 1, Graycolormodel, var1, 0, var1.length);
  70.       if (this.store.setPixels(0, var2, var1.length, 1, var1, 0, var1.length)) {
  71.          ++var3;
  72.       }
  73.  
  74.       return var3 > 0;
  75.    }
  76.  
  77.    public void produceImage() throws IOException, ImageFormatException {
  78.       try {
  79.          this.readImage(super.input, new byte[1024]);
  80.          this.store.imageComplete();
  81.          if (this.store.getBitState() != 2) {
  82.             super.source.setPixelStore(this.store);
  83.          }
  84.  
  85.          super.source.imageComplete(3);
  86.       } finally {
  87.          try {
  88.             super.input.close();
  89.          } catch (IOException var6) {
  90.          }
  91.  
  92.       }
  93.  
  94.    }
  95.  
  96.    static {
  97.       System.loadLibrary("msawt");
  98.       RGBcolormodel = new DirectColorModel(24, 16711680, 65280, 255);
  99.       byte[] var0 = new byte[256];
  100.       int var1 = 0;
  101.  
  102.       do {
  103.          var0[var1] = (byte)var1;
  104.          ++var1;
  105.       } while(var1 < 256);
  106.  
  107.       Graycolormodel = new IndexColorModel(8, 256, var0, var0, var0);
  108.    }
  109. }
  110.