jj2000.j2k.codestream.reader
Class PktDecoder

java.lang.Object
  |
  +--jj2000.j2k.codestream.reader.PktDecoder
All Implemented Interfaces:
StdEntropyCoderOptions

public class PktDecoder
extends java.lang.Object
implements StdEntropyCoderOptions

This class is used to read packet's head and body. All the members must be re-initialized at the beginning of each tile thanks to the restart() method.


Field Summary
private  PktHeaderBitReader bin
          The wrapper to read bits for the packet heads
private  java.util.Vector[] cblks
          List of code-blocks found in last read packet head (one list per subband)
private  int cQuit
          The component in which the ncb quit condition was reached
private  DecoderSpecs decSpec
          Reference to decoder specifications
private  RandomAccessIO ehs
          Reference to the stream where to read from
private  boolean ephUsed
          Whether or not EPH marker are used
private  HeaderDecoder hd
          Reference to the HeaderDecoder
private  int INIT_LBLOCK
          Initial value of the state variable associated with code-block length.
private  boolean isTruncMode
          True if truncation mode is used.
private  int[][][][][] lblock
          Lblock value used to read code size information in each packet head: 1st dim: component index. 2nd dim: resolution level index. 3rd dim: subband index. 4th/5th dim: code-block index (vert.
private  int maxCB
          Maximum number of codeblocks to read before ncb quit condition is reached
private  int nc
          The number of components
private  int ncb
          Number of codeblocks encountered.
private  boolean ncbQuit
          Flag indicating whether ncb quit condition has been reached
private  int nl
          Number of layers in t he current tile
private  Coord[][] numPrec
          Maximum number of precincts : 1st dim: component index. 2nd dim: resolution level index.
private  int pktIdx
          Index of the current packet in the tile.
private  boolean pph
          Flag indicating whether packed packet header was used for this tile
private  java.io.ByteArrayInputStream pphbais
          The packed packet header if it was used
private  PrecInfo[][][] ppinfo
          Array containing the coordinates, width, height, indexes, ...
private  int rQuit
          The resolution in which the ncb quit condition was reached
private  boolean sopUsed
          Whether or not SOP marker segment are used
private  int sQuit
          The subband in which the ncb quit condition was reached
private  BitstreamReaderAgent src
          Reference to the codestream reader agent
private  int tIdx
          Index of the current tile
private  int tQuit
          The tile in which the ncb quit condition was reached
private  TagTreeDecoder[][][][] ttIncl
          Tag tree used to read inclusion informations in packet's head: 1st dim: component index. 2nd dim: resolution level index. 3rd dim: precinct index. 4th dim: subband index.
private  TagTreeDecoder[][][][] ttMaxBP
          Tag tree used to read bit-depth information in packet's head: 1st dim: component index. 2nd dim: resolution level index. 3rd dim: precinct index. 4th dim: subband index.
private  int xQuit
          The x position of the last code block before ncb quit reached
private  int yQuit
          The y position of the last code block before ncb quit reached
 
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
PktDecoder(DecoderSpecs decSpec, HeaderDecoder hd, RandomAccessIO ehs, BitstreamReaderAgent src, boolean isTruncMode, int maxCB)
          Creates an empty PktDecoder object associated with given decoder specifications and HeaderDecoder.
 
Method Summary
private  void fillPrecInfo(int c, int r, int mdl)
          Retrives precincts and code-blocks coordinates in the given resolution, level and component.
 int getNumPrecinct(int c, int r)
          Gets the number of precincts in a given component and resolution level.
 int getPPX(int t, int c, int r)
          Returns the precinct partition width for the specified component, resolution level and tile.
 int getPPY(int t, int c, int rl)
          Returns the precinct partition height for the specified component, resolution level and tile.
 PrecInfo getPrecInfo(int c, int r, int p)
          Get PrecInfo instance of the specified resolution level, component and precinct.
 void readEPHMarker(PktHeaderBitReader bin)
          Try to read an EPH marker.
 boolean readPktBody(int l, int r, int c, int p, CBlkInfo[][][] cbI, int[] nb)
          Reads specificied packet body in order to find offset of each code-block's piece of codeword.
 boolean readPktHead(int l, int r, int c, int p, CBlkInfo[][][] cbI, int[] nb)
          Read specified packet head and found length of each code-block's piece of codewords as well as number of skipped most significant bit-planes.
 boolean readSOPMarker(int[] nBytes, int p, int c, int r)
          Try to read a SOP marker and check that its sequence number if not out of sequence.
 CBlkInfo[][][][][] restart(int nc, int[] mdl, int nl, CBlkInfo[][][][][] cbI, boolean pph, java.io.ByteArrayInputStream pphbais)
          Re-initialize the PktDecoder instance at the beginning of a new tile.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

src

private BitstreamReaderAgent src
Reference to the codestream reader agent


pph

private boolean pph
Flag indicating whether packed packet header was used for this tile


pphbais

private java.io.ByteArrayInputStream pphbais
The packed packet header if it was used


decSpec

private DecoderSpecs decSpec
Reference to decoder specifications


hd

private HeaderDecoder hd
Reference to the HeaderDecoder


INIT_LBLOCK

private final int INIT_LBLOCK
Initial value of the state variable associated with code-block length.

See Also:
Constant Field Values

bin

private PktHeaderBitReader bin
The wrapper to read bits for the packet heads


ehs

private RandomAccessIO ehs
Reference to the stream where to read from


numPrec

private Coord[][] numPrec
Maximum number of precincts :


tIdx

private int tIdx
Index of the current tile


ppinfo

private PrecInfo[][][] ppinfo
Array containing the coordinates, width, height, indexes, ... of the precincts in the current tile:


lblock

private int[][][][][] lblock
Lblock value used to read code size information in each packet head:


ttIncl

private TagTreeDecoder[][][][] ttIncl
Tag tree used to read inclusion informations in packet's head:

ttMaxBP

private TagTreeDecoder[][][][] ttMaxBP
Tag tree used to read bit-depth information in packet's head:


nl

private int nl
Number of layers in t he current tile


nc

private int nc
The number of components


sopUsed

private boolean sopUsed
Whether or not SOP marker segment are used


ephUsed

private boolean ephUsed
Whether or not EPH marker are used


pktIdx

private int pktIdx
Index of the current packet in the tile. Used with SOP marker segment


cblks

private java.util.Vector[] cblks
List of code-blocks found in last read packet head (one list per subband)


ncb

private int ncb
Number of codeblocks encountered. used for ncb quit condition


maxCB

private int maxCB
Maximum number of codeblocks to read before ncb quit condition is reached


ncbQuit

private boolean ncbQuit
Flag indicating whether ncb quit condition has been reached


tQuit

private int tQuit
The tile in which the ncb quit condition was reached


cQuit

private int cQuit
The component in which the ncb quit condition was reached


sQuit

private int sQuit
The subband in which the ncb quit condition was reached


rQuit

private int rQuit
The resolution in which the ncb quit condition was reached


xQuit

private int xQuit
The x position of the last code block before ncb quit reached


yQuit

private int yQuit
The y position of the last code block before ncb quit reached


isTruncMode

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

Constructor Detail

PktDecoder

public PktDecoder(DecoderSpecs decSpec,
                  HeaderDecoder hd,
                  RandomAccessIO ehs,
                  BitstreamReaderAgent src,
                  boolean isTruncMode,
                  int maxCB)
Creates an empty PktDecoder object associated with given decoder specifications and HeaderDecoder. This object must be initialized thanks to the restart method before being used.

Parameters:
decSpec - The decoder specifications.
hd - The HeaderDecoder instance.
ehs - The stream where to read data from.
src - The bit stream reader agent.
isTruncMode - Whether or not truncation mode is required.
maxCB - The maximum number of code-blocks to read before ncbquit
Method Detail

restart

public CBlkInfo[][][][][] restart(int nc,
                                  int[] mdl,
                                  int nl,
                                  CBlkInfo[][][][][] cbI,
                                  boolean pph,
                                  java.io.ByteArrayInputStream pphbais)
Re-initialize the PktDecoder instance at the beginning of a new tile.

Parameters:
nc - The number of components in this tile
mdl - The maximum number of decomposition level in each component of this tile
nl - The number of layers in this tile
cbI - The code-blocks array
pph - Flag indicating whether packed packet headers was used
pphbais - Stream containing the packed packet headers

fillPrecInfo

private void fillPrecInfo(int c,
                          int r,
                          int mdl)
Retrives precincts and code-blocks coordinates in the given resolution, level and component. Finishes TagTreeEncoder initialization as well.

Parameters:
c - Component index.
r - Resolution level index.
mdl - Number of decomposition level in component c.

getNumPrecinct

public int getNumPrecinct(int c,
                          int r)
Gets the number of precincts in a given component and resolution level.

Parameters:
c - Component index
r - Resolution index

readPktHead

public boolean readPktHead(int l,
                           int r,
                           int c,
                           int p,
                           CBlkInfo[][][] cbI,
                           int[] nb)
                    throws java.io.IOException
Read specified packet head and found length of each code-block's piece of codewords as well as number of skipped most significant bit-planes.

Parameters:
l - layer index
r - Resolution level index
c - Component index
p - Precinct index
cbI - CBlkInfo array of relevant component and resolution level.
nb - The number of bytes to read in each tile before reaching output rate (used by truncation mode)
Returns:
True if specified output rate or EOF is reached.
java.io.IOException

readPktBody

public boolean readPktBody(int l,
                           int r,
                           int c,
                           int p,
                           CBlkInfo[][][] cbI,
                           int[] nb)
                    throws java.io.IOException
Reads specificied packet body in order to find offset of each code-block's piece of codeword. This use the list of found code-blocks in previous red packet head.

Parameters:
l - layer index
r - Resolution level index
c - Component index
p - Precinct index
cbI - CBlkInfo array of relevant component and resolution level.
nb - The remainding number of bytes to read from the bit stream in each tile before reaching the decoding rate (in truncation mode)
Returns:
True if decoding rate is reached
java.io.IOException

getPPX

public final int getPPX(int t,
                        int c,
                        int r)
Returns the precinct partition width for the specified component, resolution level and tile.

Parameters:
t - the tile index
c - The index of the component (between 0 and C-1)
r - The resolution level, from 0 to L.
Returns:
the precinct partition width for the specified component, resolution level and tile.

getPPY

public final int getPPY(int t,
                        int c,
                        int rl)
Returns the precinct partition height for the specified component, resolution level and tile.

Parameters:
t - the tile index
c - The index of the component (between 0 and C-1)
rl - The resolution level, from 0 to L.
Returns:
the precinct partition height in the specified component, for the specified resolution level, for the current tile.

readSOPMarker

public boolean readSOPMarker(int[] nBytes,
                             int p,
                             int c,
                             int r)
                      throws java.io.IOException
Try to read a SOP marker and check that its sequence number if not out of sequence. If so, an error is thrown.

Parameters:
nBytes - The number of bytes left to read from each tile
p - Precinct index
r - Resolution level index
c - Component index
java.io.IOException

readEPHMarker

public void readEPHMarker(PktHeaderBitReader bin)
                   throws java.io.IOException
Try to read an EPH marker. If it is not possible then an Error is thrown.

Parameters:
bin - The packet header reader to read the EPH marker from
java.io.IOException

getPrecInfo

public PrecInfo getPrecInfo(int c,
                            int r,
                            int p)
Get PrecInfo instance of the specified resolution level, component and precinct.

Parameters:
c - Component index.
r - Resolution level index.
p - Precinct index.