us.zuercher.gpx2map.image.netpbm
Class PamImage

java.lang.Object
  extended by us.zuercher.gpx2map.image.netpbm.AbstractNetpbmImage
      extended by us.zuercher.gpx2map.image.netpbm.PamImage
All Implemented Interfaces:
Image, NetpbmImage

public class PamImage
extends AbstractNetpbmImage

PamImage is a read-only representation of a PAM image. It supports both reading 1- and 2-byte pixel color values. Images are converted to "maxval 255" as part of loading.

Author:
Stephan Zuercher

Field Summary
private  boolean blackWhite
          Flag indicating that the tuple type is TUPLTYPE_BLACKANDWHITE.
private  int depth
          File depth.
private static String DEPTH_HEADER
          Depth header keyord.
private  boolean grayscale
          Flag indicating that the tuple type is TUPLTYPE_GRAYSCALE.
private  boolean hasAlphaChannel
          Flag indicating whether the tuple type included the TUPLTYPE_ALPHA_SUFFIX suffix.
private static String HEIGHT_HEADER
          Height header keyord.
private static String MAXVAL_HEADER
          Maxval header keyord.
static String NETPBM_PAM_MAGIC_NUMBER
          Netpbm PAM image file magic number.
private  int[][] rasterLine
          Pixelized raster line.
private  byte[] rasterLineData
          Buffer space for a single raster-line of the image.
private static String TUPLTYPE_ALPHA_SUFFIX
          Tuple type suffix that indicates an alpha channel is present.
private static String TUPLTYPE_BLACKANDWHITE
          Black and white tuple type.
private static String TUPLTYPE_GRAYSCALE
          Grayscale tuple type.
private static String TUPLTYPE_HEADER
          Tuple type header keyword.
private static String TUPLTYPE_RGB
          RGB tuple type.
private static String WIDTH_HEADER
          Width header keyord.
 
Fields inherited from class us.zuercher.gpx2map.image.netpbm.AbstractNetpbmImage
header, height, input, width
 
Constructor Summary
PamImage(InputStream pamInputStream)
          Constructs a new PamImage from an InputStream.
 
Method Summary
 int getDepth()
          Returns this PAM image's depth.
 int[][] getNextRasterLine()
          Reads the next raster from the PAM file.
 boolean hasAlphaChannel()
          PAM images may not contain alpha-channel information.
protected  void readHeader()
          Reads the image's header block.
 
Methods inherited from class us.zuercher.gpx2map.image.netpbm.AbstractNetpbmImage
adjustToMaxVal255, close, getHeader, getHeight, getMaxVal, getOriginalBytesPerPixelPerColor, getRaster, getWidth, readWord, setOriginalMaxVal, skipWS
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NETPBM_PAM_MAGIC_NUMBER

public static final String NETPBM_PAM_MAGIC_NUMBER
Netpbm PAM image file magic number.

See Also:
Constant Field Values

WIDTH_HEADER

private static final String WIDTH_HEADER
Width header keyord.

See Also:
Constant Field Values

HEIGHT_HEADER

private static final String HEIGHT_HEADER
Height header keyord.

See Also:
Constant Field Values

DEPTH_HEADER

private static final String DEPTH_HEADER
Depth header keyord.

See Also:
Constant Field Values

MAXVAL_HEADER

private static final String MAXVAL_HEADER
Maxval header keyord.

See Also:
Constant Field Values

TUPLTYPE_HEADER

private static final String TUPLTYPE_HEADER
Tuple type header keyword.

See Also:
Constant Field Values

TUPLTYPE_RGB

private static final String TUPLTYPE_RGB
RGB tuple type.

See Also:
Constant Field Values

TUPLTYPE_GRAYSCALE

private static final String TUPLTYPE_GRAYSCALE
Grayscale tuple type.

See Also:
Constant Field Values

TUPLTYPE_BLACKANDWHITE

private static final String TUPLTYPE_BLACKANDWHITE
Black and white tuple type.

See Also:
Constant Field Values

TUPLTYPE_ALPHA_SUFFIX

private static final String TUPLTYPE_ALPHA_SUFFIX
Tuple type suffix that indicates an alpha channel is present.

See Also:
Constant Field Values

blackWhite

private boolean blackWhite
Flag indicating that the tuple type is TUPLTYPE_BLACKANDWHITE.


grayscale

private boolean grayscale
Flag indicating that the tuple type is TUPLTYPE_GRAYSCALE.


depth

private int depth
File depth. Indicates the number of channels in the file. Only depths 1 and 3 are supported without an alpha channel. With an alpha channel, only depths 2 and 4 are supported.


hasAlphaChannel

private boolean hasAlphaChannel
Flag indicating whether the tuple type included the TUPLTYPE_ALPHA_SUFFIX suffix.


rasterLineData

private byte[] rasterLineData
Buffer space for a single raster-line of the image. This is the image AbstractNetpbmImage.getWidth() multiplied by depth, multiplied by the number of bytes per pixel color (AbstractNetpbmImage.getOriginalBytesPerPixelPerColor(), 1 or 2).


rasterLine

private int[][] rasterLine
Pixelized raster line. Size is int[width][depth].

Constructor Detail

PamImage

PamImage(InputStream pamInputStream)
Constructs a new PamImage from an InputStream.

Parameters:
pamInputStream - PAM image input stream
Method Detail

hasAlphaChannel

public boolean hasAlphaChannel()
PAM images may not contain alpha-channel information.

Returns:
true if ths image supports alpha-channel, false otherwise

getDepth

public int getDepth()
Returns this PAM image's depth.

Returns:
the depth of this PAM image.

getNextRasterLine

public int[][] getNextRasterLine()
                          throws IOException
Reads the next raster from the PAM file. Note that the array returned by this method is re-used for each subsequent call to this method. If you need to keep a copy of the raster beyond the next call to this method, make a copy of it.

The dimension of the second rank of the array is always 3 or 4. If hasAlphaChannel() returns true, it will be 4. It is 3 otherwise. The first three indices are always the red, green and blue color values, respectively. This is true even if the underlying image format is grayscale or black and white. The PBM or PGM implementations are expected to expand their data to conform to this rule. Also, PBM images should invert the sense of their data such correct RGB values for black and white are returned.

Returns:
next raster or null if EOF
Throws:
IOException - on file error

readHeader

protected void readHeader()
                   throws IOException
Reads the image's header block.

Specified by:
readHeader in class AbstractNetpbmImage
Throws:
IOException - if the image head cannot be read or is invalid