home *** CD-ROM | disk | FTP | other *** search
- package sun.awt.image;
-
- import java.awt.image.ColorModel;
- import java.awt.image.DirectColorModel;
- import java.awt.image.ImageConsumer;
- import java.awt.image.IndexColorModel;
- import java.io.IOException;
- import java.io.InputStream;
- import java.util.Hashtable;
-
- public class JPEGImageDecoder extends ImageDecoder {
- private static ColorModel RGBcolormodel;
- private static ColorModel Graycolormodel;
- PixelStore store;
- Hashtable props = new Hashtable();
- private static final int hintflags = 22;
-
- private native void readImage(InputStream var1, byte[] var2) throws ImageFormatException;
-
- public JPEGImageDecoder(InputStreamImageSource src, InputStream is) {
- super(src, is);
- }
-
- public synchronized boolean catchupConsumer(InputStreamImageSource src, ImageConsumer ic) {
- return this.store == null || this.store.replay(src, ic);
- }
-
- public synchronized void makeStore(int width, int height, boolean gray) {
- if (gray) {
- this.store = new PixelStore8(width, height);
- } else {
- this.store = new PixelStore32(width, height);
- }
- }
-
- private static void error(String s1) throws ImageFormatException {
- throw new ImageFormatException(s1);
- }
-
- public boolean sendHeaderInfo(int width, int height, boolean gray, boolean multipass) {
- super.source.setDimensions(width, height);
- this.makeStore(width, height, gray);
- super.source.setProperties(this.props);
- this.store.setProperties(this.props);
- ColorModel colormodel = gray ? Graycolormodel : RGBcolormodel;
- super.source.setColorModel(colormodel);
- this.store.setColorModel(colormodel);
- int flags = 22;
- if (!multipass) {
- flags |= 8;
- }
-
- super.source.setHints(22);
- this.store.setHints(22);
- return true;
- }
-
- public boolean sendPixels(int[] pixels, int y) {
- int count = super.source.setPixels(0, y, pixels.length, 1, RGBcolormodel, pixels, 0, pixels.length);
- if (this.store.setPixels(0, y, pixels.length, 1, pixels, 0, pixels.length)) {
- ++count;
- }
-
- return count > 0;
- }
-
- public boolean sendPixels(byte[] pixels, int y) {
- int count = super.source.setPixels(0, y, pixels.length, 1, Graycolormodel, pixels, 0, pixels.length);
- if (this.store.setPixels(0, y, pixels.length, 1, pixels, 0, pixels.length)) {
- ++count;
- }
-
- return count > 0;
- }
-
- public void produceImage() throws IOException, ImageFormatException {
- try {
- this.readImage(super.input, new byte[1024]);
- this.store.imageComplete();
- if (this.store.getBitState() != 2) {
- super.source.setPixelStore(this.store);
- }
-
- super.source.imageComplete(3);
- } finally {
- try {
- super.input.close();
- } catch (IOException var6) {
- }
-
- }
-
- }
-
- static {
- SecurityManager.setScopePermission();
- System.loadLibrary("jpeg");
- SecurityManager.resetScopePermission();
- RGBcolormodel = new DirectColorModel(24, 16711680, 65280, 255);
- byte[] g = new byte[256];
-
- for(int i = 0; i < 256; ++i) {
- g[i] = (byte)i;
- }
-
- Graycolormodel = new IndexColorModel(8, 256, g, g, g);
- }
- }
-