jj2000.j2k.codestream.reader
Class FileBitstreamReaderAgent

java.lang.Object
  |
  +--jj2000.j2k.codestream.reader.BitstreamReaderAgent
        |
        +--jj2000.j2k.codestream.reader.FileBitstreamReaderAgent
All Implemented Interfaces:
CodedCBlkDataSrcDec, InvWTData, Markers, MultiResImgData, ProgressionType, StdEntropyCoderOptions

public class FileBitstreamReaderAgent
extends BitstreamReaderAgent
implements Markers, ProgressionType, StdEntropyCoderOptions

This class reads the bit stream (with the help of HeaderDecoder for tile headers and PktDecoder for packets header and body) and retrives location of all code-block's codewords.

Note: All tile-parts headers are read by the constructor whereas packets are processed when decoding related tile (when setTile method is called).

In parsing mode, the reader simulates a virtual layer-resolution progressive bit stream with the same truncation points in each code-block, whereas in truncation mode, only the first bytes are taken into account (it behaves like if it is a real truncated codestream).

See Also:
HeaderDecoder, PktDecoder

Field Summary
private  int[] baknBytes
          Backup of the number of bytes allocated to each tile.
private  CBlkInfo[][][][][] cbI
          Array containing information for all the code-blocks: 1st dim: component index. 2nd dim: resolution level index. 3rd dim: subband index. 4th/5th dim: code-block index (vert.
private  int curTilePart
          The current tile part being used
private  int[][] firstPackOff
          Offset of the first packet in each tile-part in each tile
private  int firstTilePartHeadLen
          First tile part header length
private  int headLen
          Length of main and tile-parts headers
private  HeaderInfo hi
          Reference to the HeaderInfo instance (used when reading SOT marker segments)
private  RandomAccessIO in
          The RandomAccessIO where to get data from
private  boolean isEOCFound
          Whether or not a EOC marker has been found instead of a SOT
private  boolean isPsotEqualsZero
          Whether or not the last read Psot value was zero.
private  boolean isTruncMode
          True if truncation mode is used.
private  int lQuit
          The maximum number of layers to decode for any code-block
private  int mainHeadLen
          Length of main header
private  int[] nBytes
          Number of bytes allocated to each tile.
 PktDecoder pktDec
          Reference to the PktDecoder instance
private  java.util.Vector pktHL
          Length of each packet head found in the tile
private  ParameterList pl
          Reference to the ParameterList instance
private  boolean printInfo
          Whether or not to print information found in codestream
private  int remainingTileParts
          The number of tile-parts that remain to read
private  int[][] tilePartHeadLen
          Length of all tile-part headers
private  int[][] tilePartLen
          Length of each tile-part (written in Psot)
private  int[][] tilePartNum
          The number of the tile-parts found in the codestream after reading the tp'th tile-part of tile t
private  int[] tileParts
          The number of found tile-parts in each tile.
private  int[] tilePartsRead
          The number of tile-parts read so far for each tile
private  double totAllTileLen
          Total length of all tile parts in all tiles
private  int[] totTileHeadLen
          Total length of tiles' header
private  int[] totTileLen
          Total length of each tile
private  int totTilePartsRead
          Thetotal number of tile-parts read so far
private  boolean usePOCQuit
          Whether or not to use only first progression order
 
Fields inherited from class jj2000.j2k.codestream.reader.BitstreamReaderAgent
anbytes, arate, ax, ay, ctX, ctY, culx, culy, decSpec, derived, gb, hd, imgH, imgW, mdl, nc, nt, ntH, ntW, ntX, ntY, offX, offY, OPT_PREFIX, params, px, py, subbTrees, targetRes, tnbytes, trate
 
Fields inherited from interface jj2000.j2k.codestream.Markers
COC, COD, COM, CRG, EOC, EPH, EPH_LENGTH, ERS_SEG_SYMBOLS, ERS_SOP, MAX_COMP_BITDEPTH, MAX_LPPM, MAX_LPPT, PLM, PLT, POC, PPM, PPT, PRECINCT_PARTITION_DEF_SIZE, QCC, QCD, RCOM_GEN_USE, RGN, RSIZ_BASELINE, RSIZ_ER_FLAG, RSIZ_ROI, SCOX_HOR_CB_PART, SCOX_PRECINCT_PARTITION, SCOX_USE_EPH, SCOX_USE_SOP, SCOX_VER_CB_PART, SIZ, SOC, SOD, SOP, SOP_LENGTH, SOT, SQCX_EXP_MASK, SQCX_EXP_SHIFT, SQCX_GB_MSK, SQCX_GB_SHIFT, SQCX_NO_QUANTIZATION, SQCX_SCALAR_DERIVED, SQCX_SCALAR_EXPOUNDED, SRGN_IMPLICIT, SSIZ_DEPTH_BITS, TLM
 
Fields inherited from interface jj2000.j2k.codestream.ProgressionType
COMP_POS_RES_LY_PROG, LY_RES_COMP_POS_PROG, POS_COMP_RES_LY_PROG, RES_LY_COMP_POS_PROG, RES_POS_COMP_LY_PROG
 
Fields inherited from interface jj2000.j2k.entropy.StdEntropyCoderOptions
FIRST_BYPASS_PASS_IDX, MAX_CB_AREA, MAX_CB_DIM, MIN_CB_DIM, NUM_EMPTY_PASSES_IN_MS_BP, NUM_NON_BYPASS_MS_BP, NUM_PASSES, OPT_BYPASS, OPT_PRED_TERM, OPT_RESET_MQ, OPT_SEG_SYMBOLS, OPT_TERM_PASS, OPT_VERT_STR_CAUSAL, STRIPE_HEIGHT
 
Constructor Summary
FileBitstreamReaderAgent(HeaderDecoder hd, RandomAccessIO ehs, DecoderSpecs decSpec, ParameterList pl, boolean cdstrInfo, HeaderInfo hi)
          Reads all tiles headers and keep offset of their first packet.
 
Method Summary
private  void allocateRate()
          Allocates output bit-rate for each tile in parsing mode: The allocator simulates the truncation of a virtual layer-resolution progressive codestream.
 CBlkInfo[][][][][] getCBlkInfo()
          Gets the reference to the CBlkInfo array
 DecLyrdCBlk getCodeBlock(int c, int m, int n, SubbandSyn sb, int fl, int nl, DecLyrdCBlk ccb)
          Returns the specified coded code-block, for the specified component, in the current tile.
 int getNumTileParts(int t)
          Returns the number of tile-part found for a given tile
 void nextTile()
          Advances to the next tile, in standard scan-line order (by rows then columns).
private  boolean readCompPosResLy(int[][] lys, int lye, int ress, int rese, int comps, int compe)
          Reads packets of the current tile according to the component-position-resolution-layer progressiveness.
private  boolean readLyResCompPos(int[][] lys, int lye, int ress, int rese, int comps, int compe)
          Reads packets of the current tile according to the layer-resolution-component-position progressiveness.
private  boolean readPosCompResLy(int[][] lys, int lye, int ress, int rese, int comps, int compe)
          Reads packets of the current tile according to the position-component-resolution-layer progressiveness.
private  boolean readResLyCompPos(int[][] lys, int lye, int ress, int rese, int comps, int compe)
          Reads packets of the current tile according to the resolution-layer-component-position progressiveness.
private  boolean readResPosCompLy(int[][] lys, int lye, int ress, int rese, int comps, int compe)
          Reads packets of the current tile according to the resolution-position-component-layer progressiveness.
private  int readTilePartHeader()
          Reads SOT marker segment of the tile-part header and calls related methods of the HeaderDecoder to read other markers segments.
private  void readTilePkts(int t)
          Finish initialization of members for specified tile, reads packets head of each tile and keeps location of each code-block's codewords.
 void setTile(int x, int y)
          Changes the current tile, given the new indexes.
 
Methods inherited from class jj2000.j2k.codestream.reader.BitstreamReaderAgent
createInstance, getActualNbytes, getActualRate, getCbULX, getCbULY, getCompImgHeight, getCompImgWidth, getCompSubsX, getCompSubsY, getImgHeight, getImgRes, getImgULX, getImgULY, getImgWidth, getNomTileHeight, getNomTileWidth, getNumComps, getNumTiles, getNumTiles, getParameterInfo, getPPX, getPPY, getResULX, getResULY, getSynSubbandTree, getTargetNbytes, getTargetRate, getTile, getTileCompHeight, getTileCompWidth, getTileHeight, getTileIdx, getTilePartULX, getTilePartULY, getTileWidth, initSubbandsFields
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

isPsotEqualsZero

private boolean isPsotEqualsZero
Whether or not the last read Psot value was zero. Only the Psot in the last tile-part in the codestream can have such a value.


pktDec

public PktDecoder pktDec
Reference to the PktDecoder instance


pl

private ParameterList pl
Reference to the ParameterList instance


in

private RandomAccessIO in
The RandomAccessIO where to get data from


firstPackOff

private int[][] firstPackOff
Offset of the first packet in each tile-part in each tile


nBytes

private int[] nBytes
Number of bytes allocated to each tile. In parsing mode, this number is related to the tile length in the codestream whereas in truncation mode all the rate is affected to the first tiles.


printInfo

private boolean printInfo
Whether or not to print information found in codestream


baknBytes

private int[] baknBytes
Backup of the number of bytes allocated to each tile. This array is used to restore the number of bytes to read in each tile when the codestream is read several times (for instance when decoding an R,G,B image to three output files)


tilePartLen

private int[][] tilePartLen
Length of each tile-part (written in Psot)


totTileLen

private int[] totTileLen
Total length of each tile


totTileHeadLen

private int[] totTileHeadLen
Total length of tiles' header


firstTilePartHeadLen

private int firstTilePartHeadLen
First tile part header length


totAllTileLen

private double totAllTileLen
Total length of all tile parts in all tiles


mainHeadLen

private int mainHeadLen
Length of main header


headLen

private int headLen
Length of main and tile-parts headers


tilePartHeadLen

private int[][] tilePartHeadLen
Length of all tile-part headers


pktHL

private java.util.Vector pktHL
Length of each packet head found in the tile


isTruncMode

private boolean isTruncMode
True if truncation mode is used. False if parsing mode


remainingTileParts

private int remainingTileParts
The number of tile-parts that remain to read


tilePartsRead

private int[] tilePartsRead
The number of tile-parts read so far for each tile


totTilePartsRead

private int totTilePartsRead
Thetotal number of tile-parts read so far


tileParts

private int[] tileParts
The number of found tile-parts in each tile.


curTilePart

private int curTilePart
The current tile part being used


tilePartNum

private int[][] tilePartNum
The number of the tile-parts found in the codestream after reading the tp'th tile-part of tile t


isEOCFound

private boolean isEOCFound
Whether or not a EOC marker has been found instead of a SOT


hi

private HeaderInfo hi
Reference to the HeaderInfo instance (used when reading SOT marker segments)


cbI

private CBlkInfo[][][][][] cbI
Array containing information for all the code-blocks:


lQuit

private int lQuit
The maximum number of layers to decode for any code-block


usePOCQuit

private boolean usePOCQuit
Whether or not to use only first progression order

Constructor Detail

FileBitstreamReaderAgent

public FileBitstreamReaderAgent(HeaderDecoder hd,
                                RandomAccessIO ehs,
                                DecoderSpecs decSpec,
                                ParameterList pl,
                                boolean cdstrInfo,
                                HeaderInfo hi)
                         throws java.io.IOException
Reads all tiles headers and keep offset of their first packet. Finally it calls the rate allocation method.

Parameters:
hd - HeaderDecoder of the codestream.
ehs - The input stream where to read bit-stream.
decSpec - The decoder specifications
pl - The ParameterList instance created from the command-line arguments.
cdstrInfo - Whether or not to print information found in codestream.
See Also:
allocateRate()
Method Detail

getNumTileParts

public int getNumTileParts(int t)
Returns the number of tile-part found for a given tile

Parameters:
t - Tile index

getCBlkInfo

public CBlkInfo[][][][][] getCBlkInfo()
Gets the reference to the CBlkInfo array


allocateRate

private void allocateRate()
Allocates output bit-rate for each tile in parsing mode: The allocator simulates the truncation of a virtual layer-resolution progressive codestream.


readTilePartHeader

private int readTilePartHeader()
                        throws java.io.IOException
Reads SOT marker segment of the tile-part header and calls related methods of the HeaderDecoder to read other markers segments. The tile-part header is entirely read when a SOD marker is encountered.

Returns:
The tile number of the tile part that was read
java.io.IOException

readLyResCompPos

private boolean readLyResCompPos(int[][] lys,
                                 int lye,
                                 int ress,
                                 int rese,
                                 int comps,
                                 int compe)
                          throws java.io.IOException
Reads packets of the current tile according to the layer-resolution-component-position progressiveness.

Parameters:
lys - Index of the first layer for each component and resolution.
lye - Index of the last layer.
ress - Index of the first resolution level.
rese - Index of the last resolution level.
comps - Index of the first component.
compe - Index of the last component.
Returns:
True if rate has been reached.
java.io.IOException

readResLyCompPos

private boolean readResLyCompPos(int[][] lys,
                                 int lye,
                                 int ress,
                                 int rese,
                                 int comps,
                                 int compe)
                          throws java.io.IOException
Reads packets of the current tile according to the resolution-layer-component-position progressiveness.

Parameters:
lys - Index of the first layer for each component and resolution.
lye - Index of the last layer.
ress - Index of the first resolution level.
rese - Index of the last resolution level.
comps - Index of the first component.
compe - Index of the last component.
Returns:
True if rate has been reached.
java.io.IOException

readResPosCompLy

private boolean readResPosCompLy(int[][] lys,
                                 int lye,
                                 int ress,
                                 int rese,
                                 int comps,
                                 int compe)
                          throws java.io.IOException
Reads packets of the current tile according to the resolution-position-component-layer progressiveness.

Parameters:
lys - Index of the first layer for each component and resolution.
lye - Index of the last layer.
ress - Index of the first resolution level.
rese - Index of the last resolution level.
comps - Index of the first component.
compe - Index of the last component.
Returns:
True if rate has been reached.
java.io.IOException

readPosCompResLy

private boolean readPosCompResLy(int[][] lys,
                                 int lye,
                                 int ress,
                                 int rese,
                                 int comps,
                                 int compe)
                          throws java.io.IOException
Reads packets of the current tile according to the position-component-resolution-layer progressiveness.

Parameters:
lys - Index of the first layer for each component and resolution.
lye - Index of the last layer.
ress - Index of the first resolution level.
rese - Index of the last resolution level.
comps - Index of the first component.
compe - Index of the last component.
Returns:
True if rate has been reached.
java.io.IOException

readCompPosResLy

private boolean readCompPosResLy(int[][] lys,
                                 int lye,
                                 int ress,
                                 int rese,
                                 int comps,
                                 int compe)
                          throws java.io.IOException
Reads packets of the current tile according to the component-position-resolution-layer progressiveness.

Parameters:
lys - Index of the first layer for each component and resolution.
lye - Index of the last layer.
ress - Index of the first resolution level.
rese - Index of the last resolution level.
comps - Index of the first component.
compe - Index of the last component.
Returns:
True if rate has been reached.
java.io.IOException

readTilePkts

private void readTilePkts(int t)
                   throws java.io.IOException
Finish initialization of members for specified tile, reads packets head of each tile and keeps location of each code-block's codewords. The last 2 tasks are done by calling specific methods of PktDecoder.

Then, if a parsing output rate is defined, it keeps information of first layers only. This operation simulates a creation of a layer-resolution-component progressive bit-stream which will be next truncated and decoded.

Parameters:
t - Tile index
java.io.IOException
See Also:
PktDecoder

setTile

public void setTile(int x,
                    int y)
Changes the current tile, given the new indexes. An IllegalArgumentException is thrown if the indexes do not correspond to a valid tile.

Specified by:
setTile in interface MultiResImgData
Specified by:
setTile in class BitstreamReaderAgent
Parameters:
x - The horizontal indexes the tile.
y - The vertical indexes of the new tile.

nextTile

public void nextTile()
Advances to the next tile, in standard scan-line order (by rows then columns). A NoNextElementException is thrown if the current tile is the last one (i.e. there is no next tile).

Specified by:
nextTile in interface MultiResImgData
Specified by:
nextTile in class BitstreamReaderAgent

getCodeBlock

public DecLyrdCBlk getCodeBlock(int c,
                                int m,
                                int n,
                                SubbandSyn sb,
                                int fl,
                                int nl,
                                DecLyrdCBlk ccb)
Returns the specified coded code-block, for the specified component, in the current tile. The first layer to return is indicated by 'fl'. The number of layers that is returned depends on 'nl' and the amount of available data.

The argument 'fl' is to be used by subsequent calls to this method for the same code-block. In this way supplemental data can be retrieved at a later time. The fact that data from more than one layer can be returned means that several packets from the same code-block, of the same component, and the same tile, have been concatenated.

The returned compressed code-block can have its progressive attribute set. If this attribute is set it means that more data can be obtained by subsequent calls to this method (subject to transmission delays, etc). If the progressive attribute is not set it means that the returned data is all the data that can be obtained for the specified code-block.

The compressed code-block is uniquely specified by the current tile, the component (identified by 'c'), the subband (indentified by 'sb') and the code-block vertical and horizontal indexes 'n' and 'm'.

The 'ulx' and 'uly' members of the returned 'DecLyrdCBlk' object contain the coordinates of the top-left corner of the block, with respect to the tile, not the subband.

Specified by:
getCodeBlock in interface CodedCBlkDataSrcDec
Parameters:
c - The index of the component, from 0 to N-1.
m - The vertical index of the code-block to return, in the specified subband.
n - The horizontal index of the code-block to return, in the specified subband.
sb - The subband in whic the requested code-block is.
fl - The first layer to return.
nl - The number of layers to return, if negative all available layers are returned, starting at 'fl'.
ccb - If not null this object is used to return the compressed code-block. If null a new object is created and returned. If the data array in ccb is not null then it can be reused to return the compressed data.
Returns:
The compressed code-block, with a certain number of layers determined by the available data and 'nl'.