JIGL
v1.6

jigl.image.io
Class ImageInputStream

java.lang.Object
  |
  +--java.awt.Component
        |
        +--jigl.image.io.ImageInputStream
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable

public class ImageInputStream
extends Component

ImageInputStream will read a image file(PBM, PGM, PPM, PRGM, PRCM, GIF, JPG or JPEG) and store the content in a InputSream object.

         .pgm and .pbm -> GrayImage
         .prgm -> RealGrayImage
         .ppm -> ColorImage
         .prcm -> RealColorImage
         .gif, .jpg and .jpeg -> ColorImage
 

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
private  int bits
          Current bytes value.
private  int bitshift
          Current bit position in the current byte.
protected  BufferedInputStream data
          InputStream for the Data
protected  Image img
          Image that will be loaded (Protected)
private static int JIGL_COLOR
          Flag of one file type
private static int JIGL_GRAY
          Flag of one file type
protected  int maxval
          Maximum value (integer) of the Image (Protected)
protected  float maxvalf
          Maximum value (float) of the Image (Protected)
protected  int ndims
          Number of dimensions the image has (Protected)
private static int PBM_ASCII
          Flag of one file type
private static int PBM_RAW
          Flag of one file type
private static int PGM_ASCII
          Flag of one file type
private static int PGM_RAW
          Flag of one file type
private static int PPM_ASCII
          Flag of one file type
private static int PPM_RAW
          Flag of one file type
private static int PRCM_RAW
          Flag of one file type
private static int PRGM_RAW
          Flag of one file type
private static int TIFF
          Flag of one file type
private  int type
          Type of the file:
private static int UNKNOWN
          Flag of one file type
protected  int X
          Width of the image (Protected)
protected  int Y
          Height of the image (Protected)
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
ImageInputStream(ImageInputStream stream)
          Constructs a ImageInputStream object from another ImageInputStream object (shallow copy).
ImageInputStream(String fn)
          Constructs a ImageInputStream object from a image file.
ImageInputStream(String url, int i)
          Constructs a ImageInputStream object from an online file.
 
Method Summary
 void close()
          Closes the InputStream
private  float fixDepth(float p)
           
private  int fixDepth(int p)
          Utility routine to rescale a pixel value from a non-eight-bit maxval.
 int ndims()
          Returns the number of Dimensions that the image has
 Image read()
          Reads in the Image
private  boolean readBit(InputStream in)
          Utility routine to read a bit, packed eight to a byte, big-endian.
private  int readByte(InputStream data)
          Utility routine to read a byte.
private  float readBytef(InputStream data)
           
private  char readChar(InputStream data)
          Utility routine to read a character, ignoring comments.
private  float readFloat(InputStream data)
          Utility function
 void readHeader()
          Reads the file header: determines type, size and range of values
private  int readInt(InputStream data)
          Utility routine to read an ASCII integer, ignoring comments.
 int readMagic()
          Gets the magic number and returns the type
private  char readNonwhiteChar(InputStream data)
          Utility routine to read the first non-whitespace character.
 int type()
          Returns the type of image UNKNOWN = 0 PGM_ASCII = 1 PGM_ASCII = 2 PPM_ASCII = 3 PBM_RAW = 4 PGM_RAW = 5 PPM_RAW = 6 GIF = 7 -- not yet implemented JPEG = 8 -- not yet implemented TIFF = 9 -- not yet implemented JIGL_GRAY = 10 JIGL_COLOR = 11
 int X()
          Returns the width of the image
 int Y()
          Returns the height of the image
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

data

protected BufferedInputStream data
InputStream for the Data


ndims

protected int ndims
Number of dimensions the image has (Protected)


X

protected int X
Width of the image (Protected)


Y

protected int Y
Height of the image (Protected)


img

protected Image img
Image that will be loaded (Protected)


type

private int type
Type of the file:

UNKNOWN = 0
PGM_ASCII = 1
PGM_ASCII = 2
PPM_ASCII = 3
PBM_RAW = 4
PGM_RAW = 5
PPM_RAW = 6
PRGM_RAW = 7
PRCM_RAW = 8
TIFF = 9 -- not yet implemented
JIGL_GRAY = 10
JIGL_COLOR = 11
GIFF = N/A uses Java read-in method and then converted to a JIGL image
JPEG = N/A uses Java read-in method and then converted to a JIGL image
JPG = N/A uses Java read-in method and then converted to a JIGL image


UNKNOWN

private static final int UNKNOWN
Flag of one file type

See Also:
Constant Field Values

PBM_ASCII

private static final int PBM_ASCII
Flag of one file type

See Also:
Constant Field Values

PGM_ASCII

private static final int PGM_ASCII
Flag of one file type

See Also:
Constant Field Values

PPM_ASCII

private static final int PPM_ASCII
Flag of one file type

See Also:
Constant Field Values

PBM_RAW

private static final int PBM_RAW
Flag of one file type

See Also:
Constant Field Values

PGM_RAW

private static final int PGM_RAW
Flag of one file type

See Also:
Constant Field Values

PPM_RAW

private static final int PPM_RAW
Flag of one file type

See Also:
Constant Field Values

PRGM_RAW

private static final int PRGM_RAW
Flag of one file type

See Also:
Constant Field Values

PRCM_RAW

private static final int PRCM_RAW
Flag of one file type

See Also:
Constant Field Values

TIFF

private static final int TIFF
Flag of one file type

See Also:
Constant Field Values

JIGL_GRAY

private static final int JIGL_GRAY
Flag of one file type

See Also:
Constant Field Values

JIGL_COLOR

private static final int JIGL_COLOR
Flag of one file type

See Also:
Constant Field Values

maxval

protected int maxval
Maximum value (integer) of the Image (Protected)


maxvalf

protected float maxvalf
Maximum value (float) of the Image (Protected)


bitshift

private int bitshift
Current bit position in the current byte.


bits

private int bits
Current bytes value.

Constructor Detail

ImageInputStream

public ImageInputStream(String fn)
                 throws InterruptedException,
                        FileNotFoundException,
                        ImageNotSupportedException,
                        IOException
Constructs a ImageInputStream object from a image file. Please note, GIF, JPG, and JPEG files are dependant on the filename extension (not on the header).

Parameters:
fn - the filename to open

ImageInputStream

public ImageInputStream(String url,
                        int i)
                 throws InterruptedException,
                        IOException,
                        ImageNotSupportedException,
                        MalformedURLException
Constructs a ImageInputStream object from an online file.

Parameters:
url - the complete URL

ImageInputStream

public ImageInputStream(ImageInputStream stream)
Constructs a ImageInputStream object from another ImageInputStream object (shallow copy).

Method Detail

ndims

public int ndims()
Returns the number of Dimensions that the image has


X

public int X()
Returns the width of the image


Y

public int Y()
Returns the height of the image


type

public int type()
Returns the type of image
UNKNOWN = 0
PGM_ASCII = 1
PGM_ASCII = 2
PPM_ASCII = 3
PBM_RAW = 4
PGM_RAW = 5
PPM_RAW = 6
GIF = 7 -- not yet implemented
JPEG = 8 -- not yet implemented
TIFF = 9 -- not yet implemented
JIGL_GRAY = 10
JIGL_COLOR = 11


close

public void close()
           throws IOException
Closes the InputStream

IOException

readMagic

public int readMagic()
              throws ImageNotSupportedException,
                     IOException
Gets the magic number and returns the type

ImageNotSupportedException
IOException

readHeader

public void readHeader()
                throws ImageNotSupportedException,
                       IOException
Reads the file header: determines type, size and range of values

ImageNotSupportedException
IOException

read

public Image read()
           throws ImageNotSupportedException,
                  IllegalPBMFormatException,
                  IOException
Reads in the Image

ImageNotSupportedException
IllegalPBMFormatException
IOException

readByte

private int readByte(InputStream data)
              throws IOException
Utility routine to read a byte.

IOException

readBytef

private float readBytef(InputStream data)
                 throws IOException
IOException

readInt

private int readInt(InputStream data)
             throws IOException
Utility routine to read an ASCII integer, ignoring comments.

IOException

readFloat

private float readFloat(InputStream data)
                 throws IOException
Utility function

IOException

readChar

private char readChar(InputStream data)
               throws IOException
Utility routine to read a character, ignoring comments.

IOException

readNonwhiteChar

private char readNonwhiteChar(InputStream data)
                       throws IOException
Utility routine to read the first non-whitespace character.

IOException

fixDepth

private int fixDepth(int p)
Utility routine to rescale a pixel value from a non-eight-bit maxval.


fixDepth

private float fixDepth(float p)

readBit

private boolean readBit(InputStream in)
                 throws IOException
Utility routine to read a bit, packed eight to a byte, big-endian.

IOException

JIGL
v1.6

Submit a bug or feature
Revised in May 2002 by Weiming Liu