us.zuercher.gpx2map.image.netpbm
Class PpmImage

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

public class PpmImage
extends AbstractNetpbmImage

PpmImage is a read-only representation of a PPM image. It supports reading both 1- and 2-byte pixel color values, but only the binary PPM format. Images are converted to "maxval 255" as part of loading.

Author:
Stephan Zuercher

Field Summary
private static int DEPTH
          PPM depth is always 3.
static String NETPBM_PPM_MAGIC_NUMBER
          Magic number for a Netpbm PPM image.
private  int[][] rasterLine
          Pixelized raster line.
private  byte[] rasterLineData
          Buffer space for a single raster-line of the image.
 
Fields inherited from class us.zuercher.gpx2map.image.netpbm.AbstractNetpbmImage
header, height, input, width
 
Constructor Summary
PpmImage(InputStream input)
          Constructs a new PpmImage from the given InputStream.
 
Method Summary
 int getDepth()
          PPM images are always depth 3.
 int[][] getNextRasterLine()
          Reads the next raster from the PPM file.
 boolean hasAlphaChannel()
          PPM images do 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_PPM_MAGIC_NUMBER

public static final String NETPBM_PPM_MAGIC_NUMBER
Magic number for a Netpbm PPM image.

See Also:
Constant Field Values

DEPTH

private static final int DEPTH
PPM depth is always 3.

See Also:
Constant Field Values

rasterLineData

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


rasterLine

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

Constructor Detail

PpmImage

PpmImage(InputStream input)
Constructs a new PpmImage from the given InputStream.

Parameters:
input - the input stream
Method Detail

hasAlphaChannel

public boolean hasAlphaChannel()
PPM images do not contain alpha-channel information.

Returns:
always returns false.

getDepth

public int getDepth()
PPM images are always depth 3.

Returns:
raster depth

getNextRasterLine

public int[][] getNextRasterLine()
                          throws IOException
Reads the next raster from the PPM 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.

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