home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 September / PCO_0998.ISO / browser / ns405lyc / nav40.z / java40.jar / sun / awt / image / JPEGImageDecoder.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-03-24  |  3.0 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.    private static void error(String var0) throws ImageFormatException {
  37.       throw new ImageFormatException(var0);
  38.    }
  39.  
  40.    public boolean sendHeaderInfo(int var1, int var2, boolean var3, boolean var4) {
  41.       super.source.setDimensions(var1, var2);
  42.       this.makeStore(var1, var2, var3);
  43.       super.source.setProperties(this.props);
  44.       this.store.setProperties(this.props);
  45.       ColorModel var5 = var3 ? Graycolormodel : RGBcolormodel;
  46.       super.source.setColorModel(var5);
  47.       this.store.setColorModel(var5);
  48.       int var6 = 22;
  49.       if (!var4) {
  50.          var6 |= 8;
  51.       }
  52.  
  53.       super.source.setHints(22);
  54.       this.store.setHints(22);
  55.       return true;
  56.    }
  57.  
  58.    public boolean sendPixels(int[] var1, int var2) {
  59.       int var3 = super.source.setPixels(0, var2, var1.length, 1, RGBcolormodel, var1, 0, var1.length);
  60.       if (this.store.setPixels(0, var2, var1.length, 1, var1, 0, var1.length)) {
  61.          ++var3;
  62.       }
  63.  
  64.       return var3 > 0;
  65.    }
  66.  
  67.    public boolean sendPixels(byte[] var1, int var2) {
  68.       int var3 = super.source.setPixels(0, var2, var1.length, 1, Graycolormodel, var1, 0, var1.length);
  69.       if (this.store.setPixels(0, var2, var1.length, 1, var1, 0, var1.length)) {
  70.          ++var3;
  71.       }
  72.  
  73.       return var3 > 0;
  74.    }
  75.  
  76.    public void produceImage() throws IOException, ImageFormatException {
  77.       try {
  78.          this.readImage(super.input, new byte[1024]);
  79.          this.store.imageComplete();
  80.          if (this.store.getBitState() != 2) {
  81.             super.source.setPixelStore(this.store);
  82.          }
  83.  
  84.          super.source.imageComplete(3);
  85.       } finally {
  86.          try {
  87.             super.input.close();
  88.          } catch (IOException var6) {
  89.          }
  90.  
  91.       }
  92.  
  93.    }
  94.  
  95.    static {
  96.       SecurityManager.enablePrivilege("UniversalLinkAccess");
  97.       SecurityManager.enablePrivilege("UniversalPropertyRead");
  98.       System.loadLibrary(System.getProperty("netscape.jpw.dll", "jpw"));
  99.       SecurityManager.revertPrivilege();
  100.       RGBcolormodel = new DirectColorModel(24, 16711680, 65280, 255);
  101.       byte[] var0 = new byte[256];
  102.  
  103.       for(int var1 = 0; var1 < 256; ++var1) {
  104.          var0[var1] = (byte)var1;
  105.       }
  106.  
  107.       Graycolormodel = new IndexColorModel(8, 256, var0, var0, var0);
  108.    }
  109. }
  110.