it.tidalwave.imageio.raw
Class RasterReader

java.lang.Object
  extended by it.tidalwave.imageio.raw.RasterReader
Direct Known Subclasses:
CR2RasterReader, CRWRasterReader, DNGRasterReader, NEFRasterReader, RasterReader16bits, SRFRasterReader

public class RasterReader
extends java.lang.Object

A RasterReader is capable of reading raster data from an image stream. Different format SPI will subclass it to implement specialized versions. This class should be invoked by a subclass of RAWImageReaderSupport.
This class must be filled with the proper raster attributes, then the method loadRaster(RAWImageInputStream, RAWImageReaderSupport) must be called.
The following attributes are mandatory:

Version:
CVS $Id: RasterReader.java,v 1.2 2006/02/08 20:19:09 fabriziogiudici Exp $
Author:
Fabrizio Giudici

Field Summary
static int B_OFFSET
           
protected  int bitsPerSample
          The number of bits per sample.
protected  int[] cfaOffsets
          The CFA offsets.
protected  int compression
          The compression type.
static int G_OFFSET
           
protected  int[] linearizationTable
          The linearization table.
static int R_OFFSET
           
protected  long rasterOffset
          The offset of the raster data.
protected  int stripByteCount
          The number of strips for stripped rasters.
protected  int tileHeight
          The height of a tile for tiled rasters.
protected  int[] tileOffsets
          The offsets of tiles.
protected  int tilesAcross
          The count of tiles that span horizontally.
protected  int tilesDown
          The count of tiles that span vertically.
protected  int tileWidth
          The width of a tile for tiled rasters.
 
Constructor Summary
RasterReader()
           
 
Method Summary
protected  java.awt.image.WritableRaster createRaster()
          Creates a raster compatible with the specified attributes.
protected  int getRow(int interlacedRow, int height)
          This method returns the row number given the current row.
protected  int getSkipCountAtColumn(int x)
          Some RAW formats require that a certain number of bits is skipped at certain columns.
protected  int getSkipCountAtEndOfRow()
          Some RAW formats require that a certain number of bits s skipped at the end of each row.
protected  boolean isCompressedRaster()
          This method returns true if a compressed raster is supported.
protected  void loadCompressedRaster(RAWImageInputStream iis, java.awt.image.WritableRaster raster, RAWImageReaderSupport ir)
          Reads a compressed raster.
 java.awt.image.WritableRaster loadRaster(RAWImageInputStream iis, RAWImageReaderSupport ir)
          Loads the raster from the stream and creates a WritableRaster.
protected  void loadUncompressedRaster(RAWImageInputStream iis, java.awt.image.WritableRaster raster, RAWImageReaderSupport ir)
          Reads an uncompressed raster.
protected  void selectBitReader(RAWImageInputStream iis, java.awt.image.WritableRaster raster, int bitsPerSample)
          Creates the most efficient BitReader, which is the faster for the given number of bits per sample.
 void setBitsPerSample(int bitsPerSample)
          Sets the bits per sample of the raster to read.
 void setCFAPattern(byte[] cfaPattern)
          Sets the CFA pattern of the raster to read
 void setCompression(int compression)
          Sets the compression type.
 void setHeight(int height)
          Sets the height of the raster to read.
 void setLinearizationTable(int[] linearizationTable)
          Sets the linearization table.
 void setRasterOffset(long rasterOffset)
          Sets the offset of the raster data
 void setStripByteCount(int stripByteCount)
          Sets the number of strips for stripped rasters.
 void setTileHeight(int tileHeight)
          Sets the tile height of tiled rasters.
 void setTileOffsets(int[] tileOffsets)
          Sets the offsets to tile data for tiled rasters.
 void setTilesAcross(int tilesAcross)
          Sets the count of horizontal tiles for tiled rasters.
 void setTilesDown(int tilesDown)
          Sets the count of vertical tiles for tiled rasters.
 void setTileWidth(int tileWidth)
          Sets the tile width of tiled rasters.
 void setWidth(int width)
          Sets the width of the raster to read.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

R_OFFSET

public static final int R_OFFSET
See Also:
Constant Field Values

G_OFFSET

public static final int G_OFFSET
See Also:
Constant Field Values

B_OFFSET

public static final int B_OFFSET
See Also:
Constant Field Values

bitsPerSample

protected int bitsPerSample
The number of bits per sample.


cfaOffsets

protected int[] cfaOffsets
The CFA offsets.


stripByteCount

protected int stripByteCount
The number of strips for stripped rasters.


tileWidth

protected int tileWidth
The width of a tile for tiled rasters.


tileHeight

protected int tileHeight
The height of a tile for tiled rasters.


tilesAcross

protected int tilesAcross
The count of tiles that span horizontally.


tilesDown

protected int tilesDown
The count of tiles that span vertically.


tileOffsets

protected int[] tileOffsets
The offsets of tiles.


linearizationTable

protected int[] linearizationTable
The linearization table.


compression

protected int compression
The compression type.


rasterOffset

protected long rasterOffset
The offset of the raster data.

Constructor Detail

RasterReader

public RasterReader()
Method Detail

setWidth

public void setWidth(int width)
Sets the width of the raster to read.

Parameters:
width - the width of the raster

setHeight

public void setHeight(int height)
Sets the height of the raster to read.

Parameters:
height - the height of the raster

setCFAPattern

public void setCFAPattern(byte[] cfaPattern)
Sets the CFA pattern of the raster to read

Parameters:
cfaPattern - the CFA pattern

setBitsPerSample

public void setBitsPerSample(int bitsPerSample)
Sets the bits per sample of the raster to read.

Parameters:
bitsPerSample - the bits per sample value

setTileWidth

public void setTileWidth(int tileWidth)
Sets the tile width of tiled rasters.

Parameters:
tileWidth - the tile width

setTileHeight

public void setTileHeight(int tileHeight)
Sets the tile height of tiled rasters.

Parameters:
tileHeight - the tile height

setTilesAcross

public void setTilesAcross(int tilesAcross)
Sets the count of horizontal tiles for tiled rasters.

Parameters:
tilesAcross - the count of horizontal tiles

setTilesDown

public void setTilesDown(int tilesDown)
Sets the count of vertical tiles for tiled rasters.

Parameters:
tilesDown - the count of vertical tiles

setTileOffsets

public void setTileOffsets(int[] tileOffsets)
Sets the offsets to tile data for tiled rasters. The size of the array must be equal to the total number of tiles, which is tilesAcross * tilesDown.

Parameters:
tileOffsets - the tile offsets

setRasterOffset

public void setRasterOffset(long rasterOffset)
Sets the offset of the raster data

Parameters:
rasterOffset - the offset of raster data

setStripByteCount

public void setStripByteCount(int stripByteCount)
Sets the number of strips for stripped rasters.

Parameters:
stripByteCount - the number of strips

setCompression

public void setCompression(int compression)
Sets the compression type.

Parameters:
compression - the compression type

setLinearizationTable

public void setLinearizationTable(int[] linearizationTable)
Sets the linearization table. The table should hold 2^16 entries. If it is shorter, is padded to 2^16 entries equals to the last specified value.

Parameters:
linearizationTable - the linearization table

loadRaster

public final java.awt.image.WritableRaster loadRaster(RAWImageInputStream iis,
                                                      RAWImageReaderSupport ir)
                                               throws java.io.IOException
Loads the raster from the stream and creates a WritableRaster. This method makes sure that the mandatory attributes have been set, then asks to isCompressedRaster() if the current raster is compressed. If it is, the method loadCompressedRaster(RAWImageInputStream,WritableRaster,RAWImageReaderSupport) will be invoked; otherwise the method loadUncompressedRaster(RAWImageInputStream,WritableRaster,RAWImageReaderSupport) is invoked. The raster is created by calling the method createRaster().
See the class general documentation to learn about mandatory attributes.

Parameters:
iis - the image input stream
ir - the image reader
Returns:
the raster
Throws:
java.io.IOException - if an I/O error occurs

loadUncompressedRaster

protected void loadUncompressedRaster(RAWImageInputStream iis,
                                      java.awt.image.WritableRaster raster,
                                      RAWImageReaderSupport ir)
                               throws java.io.IOException
Reads an uncompressed raster. This method provides a reasonable implementation for most RAW types which use plain, uncompressed rasters.

Parameters:
iis - the image input stream
raster - the raster to read data into
ir - the image reader
Throws:
java.io.IOException - if an I/O error occurs

loadCompressedRaster

protected void loadCompressedRaster(RAWImageInputStream iis,
                                    java.awt.image.WritableRaster raster,
                                    RAWImageReaderSupport ir)
                             throws java.io.IOException
Reads a compressed raster. This method is empty and specific subclasses for various RAW formats should override it, if a compressed raster is available.

Parameters:
iis - the image input stream
raster - the raster to read data into
ir - the image reader
Throws:
java.io.IOException - if an I/O error occurs

createRaster

protected java.awt.image.WritableRaster createRaster()
Creates a raster compatible with the specified attributes. The current implementation creates a PixelInterleavedSampleModel rather than a sun.awt.image.ShortBandedRaster, since the latter triggers bugs in the image filtering engine.
TODO: it should be possible to specify the kind of raster to use, so that the best performer can be used.

Returns:
the raster

selectBitReader

protected void selectBitReader(RAWImageInputStream iis,
                               java.awt.image.WritableRaster raster,
                               int bitsPerSample)
Creates the most efficient BitReader, which is the faster for the given number of bits per sample.

Parameters:
iis - the image input stream
raster - the raster to read data into
bitsPerSample - the number of bits per sample

isCompressedRaster

protected boolean isCompressedRaster()
This method returns true if a compressed raster is supported. It returns false by default: subclasses should implement a test and return the most appropriate value.

Returns:
true if a compressed raster is supported

getRow

protected int getRow(int interlacedRow,
                     int height)
This method returns the row number given the current row. It returns the row value unchanged by default. For RAW formats that implements interlaced rasters (i.e. the sequence of rows is not 0,1,2... but something else) this method should be overridden.

Parameters:
interlacedRow - the current row
height - the height of the raster
Returns:
the row number

getSkipCountAtColumn

protected int getSkipCountAtColumn(int x)
Some RAW formats require that a certain number of bits is skipped at certain columns. This method controls this behaviour. It returns 0 by default, and should be overridden by subclasses that need a different behaviour.

Parameters:
x - the column
Returns:
the number of bits to skip

getSkipCountAtEndOfRow

protected int getSkipCountAtEndOfRow()
Some RAW formats require that a certain number of bits s skipped at the end of each row. This method controls this behaviour. It returns 0 by default, and should be overridden by subclasses that need a different behaviour.

Returns:
the number of bits to skip