com.eteks.awt.image
Class GIFDecoder

java.lang.Object
  |
  +--com.eteks.awt.image.GIFDecoder
All Implemented Interfaces:
ImageProducer

public class GIFDecoder
extends Object
implements ImageProducer

An ImageProducer implementation that builds an image from a GIF input stream.
Image data is sent to consumers only when image build is complete. This class can be used without any link to java.awt package and an AWT toolkit.
The color model for this image is either an instance of java.awt.image.IndexColorModel or the default ARGB model. Default RGB model is used if java.awt.image.ColorModel class can't be instantiated for security or other reason (java.awt.image.ColorModel requires AWT library to be loaded). In that case, the method setPixels () of the interface java.awt.image.ImageConsumer will be called with the color model parameter set to null. No support for animated GIFs.

Since:
PJA1.2
Author:
Emmanuel Puybaret

Field Summary
private  byte[] b
           
private  int bitOffset
           
private  byte[] bytePixels
           
private  boolean classColorModelAccessible
           
private static byte COLORMAPMASK
           
(package private)  ColorModel colorModel
           
private  String comment
           
private  Vector consumers
           
private static short[][] EGA_PALETTE
           
private static byte EXTENSION
           
private  String fullInfo
           
private  byte[] g
           
private  int height
           
private static String id87
           
private static String id89
           
private static byte IMAGESEP
           
private  int imageStatus
           
private  InputStream input
           
private static byte INTERLACEMASK
           
private  int[] intPixels
           
private  int oldYC
           
private  int pass
           
private  int ptr
           
private  byte[] r
           
private  String shortInfo
           
private static byte TRAILER
           
private  int transparentIndex
           
private  int width
           
private  int XC
           
private  int YC
           
 
Constructor Summary
GIFDecoder(InputStream input)
          Creates an instance of a GIF decoder for further reading from input.
 
Method Summary
(package private)  void ()
           
 void addConsumer(ImageConsumer ic)
          ImageProducer implementation.
private  void doInterlace(int index)
           
private  void gifWarning(InputStream input, String st)
           
 boolean isConsumer(ImageConsumer ic)
          ImageProducer implementation.
private  void loadGIF(InputStream input)
           
private  int readCode(DataInputStream input, byte[] raster, int codeSize, int readMask)
          Fetch the next code from the raster data stream.
private  void readImage(DataInputStream dataInput, int bitsPerPixel, int bitMask, boolean hasColormap, boolean gif89)
           
 void removeConsumer(ImageConsumer ic)
          ImageProducer implementation.
 void requestTopDownLeftRightResend(ImageConsumer ic)
          ImageProducer implementation.
 void startProduction(ImageConsumer ic)
          ImageProducer implementation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

consumers

private Vector consumers

bytePixels

private byte[] bytePixels

intPixels

private int[] intPixels

width

private int width

height

private int height

colorModel

ColorModel colorModel

imageStatus

private int imageStatus

fullInfo

private String fullInfo

shortInfo

private String shortInfo

comment

private String comment

input

private InputStream input

classColorModelAccessible

private boolean classColorModelAccessible

bitOffset

private int bitOffset

XC

private int XC

YC

private int YC

pass

private int pass

ptr

private int ptr

oldYC

private int oldYC

r

private byte[] r

g

private byte[] g

b

private byte[] b

transparentIndex

private int transparentIndex

id87

private static final String id87

id89

private static final String id89

EGA_PALETTE

private static final short[][] EGA_PALETTE

EXTENSION

private static final byte EXTENSION

IMAGESEP

private static final byte IMAGESEP

TRAILER

private static final byte TRAILER

INTERLACEMASK

private static final byte INTERLACEMASK

COLORMAPMASK

private static final byte COLORMAPMASK
Constructor Detail

GIFDecoder

public GIFDecoder(InputStream input)
Creates an instance of a GIF decoder for further reading from input. Image reading from the stream starts only at startProduction () or addConsumer () call.
Method Detail

void ()
Overrides:
in class Object

startProduction

public void startProduction(ImageConsumer ic)
ImageProducer implementation.
Specified by:
startProduction in interface ImageProducer

addConsumer

public void addConsumer(ImageConsumer ic)
ImageProducer implementation.
Specified by:
addConsumer in interface ImageProducer

isConsumer

public boolean isConsumer(ImageConsumer ic)
ImageProducer implementation.
Specified by:
isConsumer in interface ImageProducer

removeConsumer

public void removeConsumer(ImageConsumer ic)
ImageProducer implementation.
Specified by:
removeConsumer in interface ImageProducer

requestTopDownLeftRightResend

public void requestTopDownLeftRightResend(ImageConsumer ic)
ImageProducer implementation.
Specified by:
requestTopDownLeftRightResend in interface ImageProducer

loadGIF

private void loadGIF(InputStream input)
              throws IOException

readImage

private void readImage(DataInputStream dataInput,
                       int bitsPerPixel,
                       int bitMask,
                       boolean hasColormap,
                       boolean gif89)
                throws IOException

readCode

private int readCode(DataInputStream input,
                     byte[] raster,
                     int codeSize,
                     int readMask)
              throws IOException
Fetch the next code from the raster data stream. The codes can be any length from 3 to 12 bits, packed into 8-bit bytes, so we have to maintain our location in the raster array as a BIT Offset. We compute the byte Offset into the raster array by dividing this by 8, pick up three bytes, compute the bit Offset into our 24-bit chunk, shift to bring the desired code to the bottom, then mask it off and return it.

doInterlace

private void doInterlace(int index)

gifWarning

private void gifWarning(InputStream input,
                        String st)
                 throws IOException