Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.websody.util
Class ImageInfo  view ImageInfo download ImageInfo.java

java.lang.Object
  extended byorg.websody.util.ImageInfo

public class ImageInfo
extends java.lang.Object

Allows basic information about a graphic file to be obtained without the overhead of instanciating an image object. This is particularly valuable for servlets and other programs which may not have access to a graphics context, but which may need dimensions etc. to calculate page layout etc. Note that the filename supplied must be accessible to the program, since the file must be partially read.


Field Summary
protected  java.lang.String encoding
           
protected  java.lang.String errorMessage
           
protected  int format
           
static int GIF
           
protected  short height
           
static int JPEG
           
static int MAX_HEADER_SIZE
           
protected  java.io.InputStream stream
           
static int UNKNOWN_FORMAT
           
protected  short width
           
 
Constructor Summary
protected ImageInfo(java.io.InputStream stream)
          To obtain information about images use the factory methods above.
protected ImageInfo(java.io.InputStream stream, int format)
          To obtain information about images use the factory methods above.
 
Method Summary
protected  void decodeGifHeader()
          Reads the first 13 bytes from a GIF file, and interprets it according to the following rules.
protected  void decodeHeader()
          Looks for a GIF header, if no valid header is found this method looks for a JPEG header.
protected  void decodeJpegHeader()
          Retrieves information on JPG images, according to ISO standard 10918-1 and CCITT T.81.
 java.lang.String getEncoding()
           
 java.lang.String getErrorMessage()
           
 int getFormat()
           
static ImageInfo getGifInfo(java.io.InputStream stream)
          ImageInfo factory for GIF images
 short getHeight()
           
static ImageInfo getImageInfo(java.io.InputStream stream)
          ImageInfo factory for GIF or JPEG images.
static ImageInfo getJpegInfo(java.io.InputStream stream)
          ImageInfo factory for JPEG images
 short getWidth()
           
protected  short shortBigEndian(byte firstRead, byte lastRead)
          Converts bytes in big-endian order to a short
protected  short shortLittleEndian(byte firstRead, byte lastRead)
          Converts bytes in little-endian order to a short
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNKNOWN_FORMAT

public static final int UNKNOWN_FORMAT
See Also:
Constant Field Values

GIF

public static final int GIF
See Also:
Constant Field Values

JPEG

public static final int JPEG
See Also:
Constant Field Values

MAX_HEADER_SIZE

public static final int MAX_HEADER_SIZE
See Also:
Constant Field Values

stream

protected java.io.InputStream stream

format

protected int format

height

protected short height

width

protected short width

encoding

protected java.lang.String encoding

errorMessage

protected java.lang.String errorMessage
Constructor Detail

ImageInfo

protected ImageInfo(java.io.InputStream stream)
To obtain information about images use the factory methods above.


ImageInfo

protected ImageInfo(java.io.InputStream stream,
                    int format)
To obtain information about images use the factory methods above.

Method Detail

getImageInfo

public static ImageInfo getImageInfo(java.io.InputStream stream)
ImageInfo factory for GIF or JPEG images.


getGifInfo

public static ImageInfo getGifInfo(java.io.InputStream stream)
ImageInfo factory for GIF images


getJpegInfo

public static ImageInfo getJpegInfo(java.io.InputStream stream)
ImageInfo factory for JPEG images


decodeHeader

protected void decodeHeader()
                     throws java.io.IOException
Looks for a GIF header, if no valid header is found this method looks for a JPEG header. Useful if the content type is unknown.


decodeGifHeader

protected void decodeGifHeader()
                        throws java.io.IOException
Reads the first 13 bytes from a GIF file, and interprets it according to the following rules.
   Bytes 1-3  FILE TYPE = Should be "GIF" for all valid GIF files.
   Bytes 4-6  ENCODING = '87a' or '89a' at this point in time.
   Bytes 7-13 SCREEN DESCRIPTOR
 

The Screen Descriptor describes the overall parameters for all GIF images following. It defines the overall dimensions of the image space or logical screen required, the existance of color mapping information, background screen color, and color depth information. This information is stored in a series of 8-bit bytes as described below.

            bits
       7 6 5 4 3 2 1 0  Byte #
      +---------------+
      |               |  1
      +-Screen Width -+      Raster width in pixels (LSB first)
      |               |  2
      +---------------+
      |               |  3
      +-Screen Height-+      Raster height in pixels (LSB first)
      |               |  4
      +-+-----+-+-----+      M = 1, Global color map follows Descriptor
      |M|  cr |0|pixel|  5   cr+1 = # bits of color resolution
      +-+-----+-+-----+      pixel+1 = # bits/pixel in image
      |   background  |  6   background=Color index of screen background
      +---------------+      (color is defined from the Global color
      |0 0 0 0 0 0 0 0|  7   map or default map if none specified)
      +---------------+
 


decodeJpegHeader

protected void decodeJpegHeader()
                         throws java.io.IOException
Retrieves information on JPG images, according to ISO standard 10918-1 and CCITT T.81.


shortBigEndian

protected short shortBigEndian(byte firstRead,
                               byte lastRead)
Converts bytes in big-endian order to a short


shortLittleEndian

protected short shortLittleEndian(byte firstRead,
                                  byte lastRead)
Converts bytes in little-endian order to a short


getFormat

public int getFormat()

getEncoding

public java.lang.String getEncoding()

getHeight

public short getHeight()

getWidth

public short getWidth()

getErrorMessage

public java.lang.String getErrorMessage()