jj2000.j2k.codestream.reader
Class PktDecoder

java.lang.Object
  |
  +--jj2000.j2k.codestream.reader.PktDecoder

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  CBlkCoordInfo[][][][][] cbCoord
          Array containing the coordinates, width, height, indexes, ...
private  java.util.Vector[] cblks
          List of code-blocks found in last read packet head (one list per subband)
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  Coord[][] incArray
          Array containing the increment step 1st dim : component index 2nd dim : resolution level
private  Coord[] incArrayMax
          Array containing the maximum increment step 1st dim : component index
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  Coord[][] maxNumPrecincts
          Maximum number of precincts : 1st dim: component index. 2nd dim: resolution level index.
private  int[] mdl
          The maximum number of decomposition levels for each component
private  int nc
          The number of components
private  int nl
          Number of layers in t he current tile
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  PrecCoordInfo[][][][] precCoord
          Array containing the coordinates, width, height, indexes, ...
private  boolean sopUsed
          Whether or not SOP marker segment are used
private  Coord[][][] sotEotArray
          Array used to store the start/end of tile horizontal and vertical coordinates at each resolution level 1st dim : component index 2nd dim : resolution level 3rd dim : 0, start of tile, 1, end of tile
private  Coord[][] sotEotArrayMax
          Array used to store the start/end of tile horizontal and vertical coordinates at the highest resolution level using the smallest increments 1st dim : component index 2nd dim : 0, start of tile, 1, end of tile
private  FileBitstreamReaderAgent src
          Reference to the codestream reader agent
private  int[][][] subRange
          Keeps the first and the last subband index in the associated component and resolution level: 1st dim: component index 2nd dim: resolution level index 3rd dim: max and min value
private  TagTreeDecoder[][][][] tdBDA
          Tag tree used to read bit-depth information in packet's head: 1st dim: component index. 2nd dim: resolution level index. 3rd dim: subband index. 4th dim: precinct index.
private  TagTreeDecoder[][][][] tdInclA
          Tag tree used to read inclusion informations in packet's head: 1st dim: component index. 2nd dim: resolution level index. 3rd dim: subband index. 4th dim: precinct index.
private  int tIdx
          Index of the current tile
 
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_ER_TERM, OPT_REG_TERM, OPT_RESET_MQ, OPT_SEG_MARKERS, OPT_VERT_STR_CAUSAL, STRIPE_HEIGHT
 
Constructor Summary
PktDecoder(DecoderSpecs decSpec, HeaderDecoder hd, RandomAccessIO ehs, FileBitstreamReaderAgent src, boolean isTruncMode)
          Create an empty PktDecoder object associated with given decoder specifications and HeaderDecoder.
 
Method Summary
private  void buildCBlkPrecCoord(int c, int r)
          Builds the lists containing the ulx, uly, width, height and indexes of the code-blocks and of the precincts for each component, resolution level and subband.
private  void buildIncArrays(int c)
          Creates the arrays incArray and incArrayMax.
private  void buildSotEotArrays(int c)
          Creates the arrays sotEotArray and sotEotArrayMax.
private  int[][][] findSubInResLvl()
          Finds the number of subbands in each resolution level according to the decomposition tree of each component.
private  java.util.Vector getCBlkInPrecinct(int c, int r, int s, int p)
          Returns the code-blocks contained in the precinct which index is p for component c, the resolution level r and the subband index s.The returned object is a Vector object whose first element is a Coord object containing the number of code-blocks in each direction and then, cblks contains all the code-blocks indexes.
 Coord getIncArray(int c, int r)
          Returns the 'incArray' for the specified component and resolution level.
 Coord getIncArrayMax(int c)
          Returns the 'incArrayMax' for the specified component.
 int getNumPrecinct(int c, int r)
          Get the number of precinct in given component and resolution.
 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.
 Coord[] getSotEotArray(int c, int r)
          Returns the 'sotEotArray' for the specified component and resolution level.
 Coord[] getSotEotArrayMax(int c)
          Returns the 'sotEotArrayMax' for the specified component.
 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.
(package private)  CBlkInfo[][][][][] restart(int nc, int[] mdl, int nl, CBlkInfo[][][][][] cbI, boolean pph, java.io.ByteArrayInputStream pphbais)
          Re-initialize the PacketDecoder at the beginning of a new tile.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

src

private FileBitstreamReaderAgent 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.

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

maxNumPrecincts

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

tIdx

private int tIdx
Index of the current tile

cbCoord

private CBlkCoordInfo[][][][][] cbCoord
Array containing the coordinates, width, height, indexes, ... of the code-blocks in the current tile.

precCoord

private PrecCoordInfo[][][][] precCoord
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:

tdInclA

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

tdBDA

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

nl

private int nl
Number of layers in t he current tile

subRange

private int[][][] subRange
Keeps the first and the last subband index in the associated component and resolution level:

mdl

private int[] mdl
The maximum number of decomposition levels for each component

nc

private int nc
The number of components

incArray

private Coord[][] incArray
Array containing the increment step

incArrayMax

private Coord[] incArrayMax
Array containing the maximum increment step

sotEotArray

private Coord[][][] sotEotArray
Array used to store the start/end of tile horizontal and vertical coordinates at each resolution level

sotEotArrayMax

private Coord[][] sotEotArrayMax
Array used to store the start/end of tile horizontal and vertical coordinates at the highest resolution level using the smallest increments

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)

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,
                  FileBitstreamReaderAgent src,
                  boolean isTruncMode)
Create 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 used
Method Detail

restart

CBlkInfo[][][][][] restart(int nc,
                           int[] mdl,
                           int nl,
                           CBlkInfo[][][][][] cbI,
                           boolean pph,
                           java.io.ByteArrayInputStream pphbais)
Re-initialize the PacketDecoder 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 inicating whether packed packet headers was used
pphbais - Stream containing the packed packet headers

getNumPrecinct

public int getNumPrecinct(int c,
                          int r)
Get the number of precinct in given component and resolution.
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 output rate is reached

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

buildSotEotArrays

private void buildSotEotArrays(int c)
Creates the arrays sotEotArray and sotEotArrayMax. The first array contains the start/end of tile coordinates at each resolution level and the second array contains the start/end of tile coordinates for the highest resolution level using the smallest increment step
Parameters:
c - the component index

buildIncArrays

private void buildIncArrays(int c)
Creates the arrays incArray and incArrayMax. The first array (incArray) contains the increment step used for each component, each tile and each resolution level. The second one (incArrayMax) contains the smallest increment. This is used when looking for packet inclusion.
Parameters:
c - the component index

buildCBlkPrecCoord

private void buildCBlkPrecCoord(int c,
                                int r)
Builds the lists containing the ulx, uly, width, height and indexes of the code-blocks and of the precincts for each component, resolution level and subband. First, we compute the projected anchor point for the code-block partition. Then, the array containing the code-blocks coordinates is built. Finally, the array containing the precincts coordinates is built.
Parameters:
c - the component index
r - The resolution level

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.

getCBlkInPrecinct

private java.util.Vector getCBlkInPrecinct(int c,
                                           int r,
                                           int s,
                                           int p)
Returns the code-blocks contained in the precinct which index is p for component c, the resolution level r and the subband index s.The returned object is a Vector object whose first element is a Coord object containing the number of code-blocks in each direction and then, cblks contains all the code-blocks indexes.
Parameters:
c - the component index
r - the resolution level
s - the subband index
p - the precinct index
Returns:
The code-blocks contained in the precinct as the first Coord object stored in the Vector and then the code-blocks indexes

findSubInResLvl

private int[][][] findSubInResLvl()
Finds the number of subbands in each resolution level according to the decomposition tree of each component. JPEG 2000 part I supports only dyadic decomposition.
Returns:
Minimun and maximum subband identifier for each resolution level (First index= resolution level, second index = 0(minimum) or 1(maximum))

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

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

getSotEotArray

public Coord[] getSotEotArray(int c,
                              int r)
Returns the 'sotEotArray' for the specified component and resolution level. This method is used by the bit stream reader.
Parameters:
c - The component
r - The resolution level

getSotEotArrayMax

public Coord[] getSotEotArrayMax(int c)
Returns the 'sotEotArrayMax' for the specified component. This method is used by the bit stream reader.
Parameters:
c - The component

getIncArray

public Coord getIncArray(int c,
                         int r)
Returns the 'incArray' for the specified component and resolution level. This method is used by the bit stream reader.
Parameters:
c - The component
r - The resolution level

getIncArrayMax

public Coord getIncArrayMax(int c)
Returns the 'incArrayMax' for the specified component. This method is used by the bit stream reader.
Parameters:
c - The component