jp2codec.codestream.reader
Class BitstreamReaderAgent

java.lang.Object
  extended by jp2codec.codestream.reader.BitstreamReaderAgent
All Implemented Interfaces:
java.lang.Runnable, Markers, ProgressionType, CodedCBlkDataSrcDec, StdEntropyCoderOptions, InvWTData, MultiResImgData

public class BitstreamReaderAgent
extends java.lang.Object
implements Markers, ProgressionType, StdEntropyCoderOptions, CodedCBlkDataSrcDec, java.lang.Runnable

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
 int acb
           
protected  int anbytes
          Actual number of read bytes
protected  float arate
          Actual decoding rate in bpp
protected  int ax
          The horizontal coordinate of the image origin in the canvas system, on the reference grid.
protected  int ay
          The vertical coordinate of the image origin in the canvas system, on the reference grid.
 int cbUsed
           
protected  int ctX
          The current tile horizontal index
protected  int ctY
          The current tile vertical index
protected  int[] culx
          The horizontal coordinates of the upper-left corner of the active tile, with respect to the canvas origin, in the component hi-res grid, for each component.
protected  int[] culy
          The vertical coordinates of the upper-left corner of the active tile, with respect to the canvas origin, in the component hi-res grid, for each component.
protected  DecoderSpecs decSpec
          The decoder specifications
protected  boolean[] derived
          Whether or not the components in the current tile uses a derived quantization step size (only relevant in non reversible quantization mode).
protected  int[] gb
          Number of guard bits off all component in the current tile.
protected  HeaderDecoder hd
          The decoded bit stream header
protected  int imgH
          The image width on the hi-res reference grid
protected  int imgW
          The image width on the hi-res reference grid
protected  int[] mdl
          The maximum number of decompostion levels for each component of the current tile.
protected  int nc
          The number of components
protected  int ntH
          The nominal tile height, in the hi-res reference grid
protected  int ntW
          The nominal tile width, in the hi-res reference grid
protected  int ntX
          The number of tile in the horizontal direction
protected  int ntY
          The number of tiles in the vertical direction
protected  int[] offX
          The horizontal offsets of the upper-left corner of the current tile (not active tile) with respect to the canvas origin, in the component hi-res grid, for each component.
protected  int[] offY
          The vertical offsets of the upper-left corner of the current tile (not active tile) with respect to the canvas origin, in the component hi-res grid, for each component.
protected  StdDequantizerParams[] params
          Dequantization parameters of all subbands and all components in the current tile.
 PktDecoder pktDec
          Reference to the PktDecoder instance
protected  int px
          The horizontal coordinate of the tiling origin in the canvas system, on the reference grid.
protected  int py
          The vertical coordinate of the tiling origin in the canvas system, on the reference grid.
protected  int res
          Image resolution level to generate
protected  SubbandSyn[] subbTrees
          The subband trees for each component in the current tile.
protected  int tnbytes
          Number of bytes targeted to be read
protected  float trate
          Target decoding rate in bpp
 
Fields inherited from interface jp2codec.codestream.Markers
COC, COD, COM, CRG, EOC, EPH, EPH_LENGTH, ERS_SEG_MARKERS, 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_PRECINCT_PARTITION, SCOX_USE_EPH, SCOX_USE_SOP, 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 jp2codec.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 jp2codec.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
BitstreamReaderAgent(HeaderDecoder hd, javax.imageio.stream.ImageInputStream ehs, DecoderSpecs decSpec, float rate, int nbytes, boolean parsing, int resolution)
          Reads all tiles headers and keep offset of their first packet.
 
Method Summary
 boolean anyCodeBlockRemains()
           
 int getActualNbytes()
          Return the actual number of read bytes.
 float getActualRate()
          Return the actual decoding rate in bits per pixel.
 DecLyrdCBlk getCodeBlock(int c, int r, int s, int m, int n)
           
 DecLyrdCBlk getCodeBlock(int c, int m, int n, SubbandSyn sb, int fl, int nl, DecLyrdCBlk dlcb)
          Returns the specified coded code-block, for the specified component, in the current tile.
 DecLyrdCBlk getCodeBlockOld(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 getCompHeight(int c, int rl)
          Returns the height in pixels of the specified component in the current tile, for the given (tile-component) resolution level.
 int getCompImgHeight(int c, int rl)
          Returns the height in pixels of the specified component in the overall image, for the given (component) resolution level.
 int getCompImgWidth(int c, int rl)
          Returns the width in pixels of the specified component in the overall image, for the given (component) resolution level.
 int getCompSubsX(int c)
          Returns the component subsampling factor in the horizontal direction, for the specified component.
 int getCompSubsY(int c)
          Returns the component subsampling factor in the vertical direction, for the specified component.
 int getCompWidth(int c, int rl)
          Returns the width in pixels of the specified component in the current tile, for the given (tile-component) resolution level.
 int getHeight(int rl)
          Returns the overall height of the current tile in pixels, for the given resolution level.
 int getImgHeight(int rl)
          Returns the overall height of the image in pixels, for the given resolution level.
 int getImgRes()
          Returns the image resolution level to reconstruct from the codestream.
 int getImgULX(int rl)
          Returns the horizontal coordinate of the image origin, the top-left corner, in the canvas system, on the reference grid at the specified resolution level.
 int getImgULY(int rl)
          Returns the vertical coordinate of the image origin, the top-left corner, in the canvas system, on the reference grid at the specified resolution level.
 int getImgWidth(int rl)
          Returns the overall width of the image in pixels, for the given (image) resolution level.
 Coord getNumCodeBlocks(SubbandSyn sb, int c, Coord co)
          Returns the number of code-blocks in a subband, along the horizontal and vertical dimensions.
 int getNumComps()
          Returns the number of components in the image.
 int getNumTiles()
          Returns the total number of tiles in the image.
 Coord getNumTiles(Coord co)
          Returns the number of tiles in the horizontal and vertical directions.
 int getPartitionULX()
          Returns the horizontal coordinate of the origin of the cell and code-block partition, with respect to the canvas origin, on the reference grid.
 int getPartitionULY()
          Returns the vertical coordinate of the origin of the cell and code-block partition, with respect to the canvas origin, on the reference grid.
 int getPPX(int t, int c, int rl)
          Returns the precinct partition width for the specified tile-component and (tile-component) resolution level.
 int getPPY(int t, int c, int rl)
          Returns the precinct partition height for the specified tile-component and (tile-component) resolution level.
 SubbandSyn getSubbandTree(int t, int c)
          Returns the subband tree, for the specified tile-component.
 int getTargetNbytes()
          Return the target number of read bytes.
 float getTargetRate()
          Return the target decoding rate in bits per pixel.
 Coord getTile(Coord co)
          Returns the indexes of the current tile.
 int getTileIdx()
          Returns the index of the current tile, relative to a standard scan-line order.
 Coord getTileOff(Coord co, int c, int rl)
          Returns the horizontal and vertical offset of the upper-left corner of the current tile, in the specified component, relative to the canvas origin, for the specified resolution level.
 int getULX(int c, int rl)
          Returns the horizontal coordinate of the upper-left corner of the active tile, with respect to the canvas origin, in the component coordinates, for the specified component and resolution level.
 int getULY(int c, int rl)
          Returns the vertical coordinate of the upper-left corner of the active tile, with respect to the canvas origin, in the component coordinates, for the specified component and resolution level.
 int getWidth(int rl)
          Returns the overall width of the current tile in pixels for the given (tile) resolution level.
protected  void initSubbandsFields(int c, SubbandSyn sb)
          Initialises subbands fields, such as code-blocks dimension and number of magnitude bits, in the subband tree.
 void nextTile()
          Advances to the next tile, in standard scan-line order (by rows then columns).
 void run()
           
 void setROI(int x, int y, int w, int h)
           
 void setTile(int x, int y)
          Changes the current tile, given the new indexes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

decSpec

protected DecoderSpecs decSpec
The decoder specifications


derived

protected boolean[] derived
Whether or not the components in the current tile uses a derived quantization step size (only relevant in non reversible quantization mode). This field is actualized by the setTile method in BitstreamReaderAgent.

See Also:
initSubbandsFields(int, jp2codec.wavelet.synthesis.SubbandSyn)

gb

protected int[] gb
Number of guard bits off all component in the current tile. This field is actualized by the setTile method in BitstreamReaderAgent.

See Also:
initSubbandsFields(int, jp2codec.wavelet.synthesis.SubbandSyn)

params

protected StdDequantizerParams[] params
Dequantization parameters of all subbands and all components in the current tile. The value is actualized by the setTile method in BitstreamReaderAgent.

See Also:
initSubbandsFields(int, jp2codec.wavelet.synthesis.SubbandSyn)

mdl

protected int[] mdl
The maximum number of decompostion levels for each component of the current tile. It means that component c has mdl[c]+1 resolution levels (indexed from 0 to mdl[c])


nc

protected final int nc
The number of components


res

protected int res
Image resolution level to generate


subbTrees

protected SubbandSyn[] subbTrees
The subband trees for each component in the current tile. Each element in the array is the root element of the subband tree for a component. The number of magnitude bits in each subband (magBits member variable) is not initialized.


imgW

protected final int imgW
The image width on the hi-res reference grid


imgH

protected final int imgH
The image width on the hi-res reference grid


ax

protected final int ax
The horizontal coordinate of the image origin in the canvas system, on the reference grid.


ay

protected final int ay
The vertical coordinate of the image origin in the canvas system, on the reference grid.


px

protected final int px
The horizontal coordinate of the tiling origin in the canvas system, on the reference grid.


py

protected final int py
The vertical coordinate of the tiling origin in the canvas system, on the reference grid.


offX

protected final int[] offX
The horizontal offsets of the upper-left corner of the current tile (not active tile) with respect to the canvas origin, in the component hi-res grid, for each component.


offY

protected final int[] offY
The vertical offsets of the upper-left corner of the current tile (not active tile) with respect to the canvas origin, in the component hi-res grid, for each component.


culx

protected final int[] culx
The horizontal coordinates of the upper-left corner of the active tile, with respect to the canvas origin, in the component hi-res grid, for each component.


culy

protected final int[] culy
The vertical coordinates of the upper-left corner of the active tile, with respect to the canvas origin, in the component hi-res grid, for each component.


ntW

protected final int ntW
The nominal tile width, in the hi-res reference grid


ntH

protected final int ntH
The nominal tile height, in the hi-res reference grid


ntX

protected final int ntX
The number of tile in the horizontal direction


ntY

protected final int ntY
The number of tiles in the vertical direction


ctX

protected int ctX
The current tile horizontal index


ctY

protected int ctY
The current tile vertical index


hd

protected final HeaderDecoder hd
The decoded bit stream header


tnbytes

protected int tnbytes
Number of bytes targeted to be read


anbytes

protected int anbytes
Actual number of read bytes


trate

protected float trate
Target decoding rate in bpp


arate

protected float arate
Actual decoding rate in bpp


pktDec

public PktDecoder pktDec
Reference to the PktDecoder instance


acb

public int acb

cbUsed

public int cbUsed
Constructor Detail

BitstreamReaderAgent

public BitstreamReaderAgent(HeaderDecoder hd,
                            javax.imageio.stream.ImageInputStream ehs,
                            DecoderSpecs decSpec,
                            float rate,
                            int nbytes,
                            boolean parsing,
                            int resolution)
                     throws java.io.IOException
Reads all tiles headers and keep offset of their first packet. Finally the rate allocation method is called.

Parameters:
hd - HeaderDecoder of the codestream.
ehs - The input stream where to read bit-stream.
decSpec - The decoder specifications
Throws:
java.io.IOException
See Also:
allocateRate()
Method Detail

getPartitionULX

public final int getPartitionULX()
Returns the horizontal coordinate of the origin of the cell and code-block partition, with respect to the canvas origin, on the reference grid. Allowable values are 0 and 1, nothing else.

Specified by:
getPartitionULX in interface InvWTData
Returns:
The horizontal coordinate of the origin of the cell and code-block partitions, with respect to the canvas origin, on the reference grid.

getPartitionULY

public int getPartitionULY()
Returns the vertical coordinate of the origin of the cell and code-block partition, with respect to the canvas origin, on the reference grid. Allowable values are 0 and 1, nothing else.

Specified by:
getPartitionULY in interface InvWTData
Returns:
The vertical coordinate of the origin of the cell and code-block partitions, with respect to the canvas origin, on the reference grid.

getNumComps

public final int getNumComps()
Returns the number of components in the image.

Specified by:
getNumComps in interface MultiResImgData
Returns:
The number of components in the image.

getCompSubsX

public final int getCompSubsX(int c)
Returns the component subsampling factor in the horizontal direction, for the specified component. This is, approximately, the ratio of dimensions between the reference grid and the component itself, see the 'ImgData' interface desription for details.

Specified by:
getCompSubsX in interface MultiResImgData
Parameters:
c - The index of the component (between 0 and N-1)
Returns:
The horizontal subsampling factor of component 'c'
See Also:
ImgData

getCompSubsY

public int getCompSubsY(int c)
Returns the component subsampling factor in the vertical direction, for the specified component. This is, approximately, the ratio of dimensions between the reference grid and the component itself, see the 'ImgData' interface desription for details.

Specified by:
getCompSubsY in interface MultiResImgData
Parameters:
c - The index of the component (between 0 and C-1)
Returns:
The vertical subsampling factor of component 'c'
See Also:
ImgData

getWidth

public int getWidth(int rl)
Returns the overall width of the current tile in pixels for the given (tile) resolution level. This is the tile's width without accounting for any component subsampling.

Note: Tile resolution level indexes may be different from tile-component resolution index. They are indeed indexed starting from the lowest number of decomposition levels of each component of the tile.

For an image (1 tile) with 2 components (component 0 having 2 decomposition levels and component 1 having 3 decomposition levels), the first (tile-)component has 3 resolution levels and the second one has 4 resolution levels, whereas the tile has only 3 resolution levels available.

Specified by:
getWidth in interface MultiResImgData
Parameters:
rl - The (tile) resolution level.
Returns:
The current tile's width in pixels.

getHeight

public int getHeight(int rl)
Returns the overall height of the current tile in pixels, for the given resolution level. This is the tile's height without accounting for any component subsampling.

Note: Tile resolution level indexes may be different from tile-component resolution index. They are indeed indexed starting from the lowest number of decomposition levels of each component of the tile.

For an image (1 tile) with 2 components (component 0 having 2 decomposition levels and component 1 having 3 decomposition levels), the first (tile-)component has 3 resolution levels and the second one has 4 resolution levels, whereas the tile has only 3 resolution levels available.

Specified by:
getHeight in interface MultiResImgData
Parameters:
rl - The (tile) resolution level.
Returns:
The total current tile's height in pixels.

getImgWidth

public int getImgWidth(int rl)
Returns the overall width of the image in pixels, for the given (image) resolution level. This is the image's width without accounting for any component subsampling or tiling.

Note: Image resolution level indexes may differ from tile-component resolution index. They are indeed indexed starting from the lowest number of decomposition levels of each component of each tile.

Example: For an image (1 tile) with 2 components (component 0 having 2 decomposition levels and component 1 having 3 decomposition levels), the first (tile-) component has 3 resolution levels and the second one has 4 resolution levels, whereas the image has only 3 resolution levels available.

Specified by:
getImgWidth in interface MultiResImgData
Parameters:
rl - The image resolution level.
Returns:
The total image's width in pixels.

getImgHeight

public int getImgHeight(int rl)
Returns the overall height of the image in pixels, for the given resolution level. This is the image's height without accounting for any component subsampling or tiling.

Note: Image resolution level indexes may differ from tile-component resolution index. They are indeed indexed starting from the lowest number of decomposition levels of each component of each tile.

Example: For an image (1 tile) with 2 components (component 0 having 2 decomposition levels and component 1 having 3 decomposition levels), the first (tile-) component has 3 resolution levels and the second one has 4 resolution levels, whereas the image has only 3 resolution levels available.

Specified by:
getImgHeight in interface MultiResImgData
Parameters:
rl - The image resolution level, from 0 to L.
Returns:
The total image's height in pixels.

getImgULX

public int getImgULX(int rl)
Returns the horizontal coordinate of the image origin, the top-left corner, in the canvas system, on the reference grid at the specified resolution level.

Note: Image resolution level indexes may differ from tile-component resolution index. They are indeed indexed starting from the lowest number of decomposition levels of each component of each tile.

Example: For an image (1 tile) with 2 components (component 0 having 2 decomposition levels and component 1 having 3 decomposition levels), the first (tile-) component has 3 resolution levels and the second one has 4 resolution levels, whereas the image has only 3 resolution levels available.

Specified by:
getImgULX in interface MultiResImgData
Parameters:
rl - The resolution level, from 0 to L.
Returns:
The horizontal coordinate of the image origin in the canvas system, on the reference grid.

getImgULY

public int getImgULY(int rl)
Returns the vertical coordinate of the image origin, the top-left corner, in the canvas system, on the reference grid at the specified resolution level.

Note: Image resolution level indexes may differ from tile-component resolution index. They are indeed indexed starting from the lowest number of decomposition levels of each component of each tile.

Example: For an image (1 tile) with 2 components (component 0 having 2 decomposition levels and component 1 having 3 decomposition levels), the first (tile-) component has 3 resolution levels and the second one has 4 resolution levels, whereas the image has only 3 resolution levels available.

Specified by:
getImgULY in interface MultiResImgData
Parameters:
rl - The resolution level, from 0 to L.
Returns:
The vertical coordinate of the image origin in the canvas system, on the reference grid.

getCompWidth

public final int getCompWidth(int c,
                              int rl)
Returns the width in pixels of the specified component in the current tile, for the given (tile-component) resolution level.

Specified by:
getCompWidth in interface MultiResImgData
Parameters:
c - The index of the component, from 0 to N-1.
rl - The resolution level, from 0 to L.
Returns:
The width in pixels of component c in the current tile.

getCompHeight

public final int getCompHeight(int c,
                               int rl)
Returns the height in pixels of the specified component in the current tile, for the given (tile-component) resolution level.

Specified by:
getCompHeight in interface MultiResImgData
Parameters:
c - The index of the component, from 0 to N-1.
rl - The resolution level, from 0 to L.
Returns:
The height in pixels of component c in the current tile.

getCompImgWidth

public final int getCompImgWidth(int c,
                                 int rl)
Returns the width in pixels of the specified component in the overall image, for the given (component) resolution level.

Note: Component resolution level indexes may differ from tile-component resolution index. They are indeed indexed starting from the lowest number of decomposition levels of same component of each tile.

Example: For an image (2 tiles) with 1 component (tile 0 having 2 decomposition levels and tile 1 having 3 decomposition levels), the first tile(-component) has 3 resolution levels and the second one has 4 resolution levels, whereas the component has only 3 resolution levels available.

Specified by:
getCompImgWidth in interface MultiResImgData
Parameters:
c - The index of the component, from 0 to N-1.
rl - The resolution level, from 0 to L.
Returns:
The width in pixels of component c in the overall image.

getCompImgHeight

public final int getCompImgHeight(int c,
                                  int rl)
Returns the height in pixels of the specified component in the overall image, for the given (component) resolution level.

Note: Component resolution level indexes may differ from tile-component resolution index. They are indeed indexed starting from the lowest number of decomposition levels of same component of each tile.

Example: For an image (2 tiles) with 1 component (tile 0 having 2 decomposition levels and tile 1 having 3 decomposition levels), the first tile(-component) has 3 resolution levels and the second one has 4 resolution levels, whereas the component has only 3 resolution levels available.

Specified by:
getCompImgHeight in interface MultiResImgData
Parameters:
c - The index of the component, from 0 to N-1.
rl - The resolution level, from 0 to L.
Returns:
The height in pixels of component c in the overall image.

getTile

public final Coord getTile(Coord co)
Returns the indexes of the current tile. These are the horizontal and vertical indexes of the current tile.

Specified by:
getTile in interface MultiResImgData
Parameters:
co - If not null this object is used to return the information. If null a new one is created and returned.
Returns:
The current tile's indexes (vertical and horizontal indexes).

getTileIdx

public final int getTileIdx()
Returns the index of the current tile, relative to a standard scan-line order.

Specified by:
getTileIdx in interface MultiResImgData
Returns:
The current tile's index (starts at 0).

getTileOff

public final Coord getTileOff(Coord co,
                              int c,
                              int rl)
Returns the horizontal and vertical offset of the upper-left corner of the current tile, in the specified component, relative to the canvas origin, for the specified resolution level. This is returned in the component coordinates (not in the reference grid coordinates) reduced to the specified resolution. These are the coordinates of the current tile's (not active tile) upper-left corner relative to the canvas, in the specified component, at the specified resolution.

Specified by:
getTileOff in interface MultiResImgData
Parameters:
co - If not null the object is used to return the values, if null a new one is created and returned.
c - The index of the component (between 0 and N-1)
rl - The resolution level, from 0 to L.
Returns:
The horizontal and vertical offsets of the upper-left corner of the current tile, for the specified component and resolution level, relative to the canvas origin, in the component coordinates.

getULX

public final int getULX(int c,
                        int rl)
Returns the horizontal coordinate of the upper-left corner of the active tile, with respect to the canvas origin, in the component coordinates, for the specified component and resolution level. This is actually the horizontal coordinate of the top-left corner of the image data within the current tile.

Specified by:
getULX in interface MultiResImgData
Parameters:
c - The index of the component (between 0 and N-1)
rl - The resolution level, from 0 to L.
Returns:
The horizontal coordinate of the upper-left corner of the active tile, with respect to the canvas origin, for component 'c', in the component coordinates, at resolution level 'rl'.

getULY

public final int getULY(int c,
                        int rl)
Returns the vertical coordinate of the upper-left corner of the active tile, with respect to the canvas origin, in the component coordinates, for the specified component and resolution level. This is actually the vertical coordinate of the top-left corner of the image data within the current tile.

Specified by:
getULY in interface MultiResImgData
Parameters:
c - The index of the component (between 0 and N-1)
rl - The resolution level, from 0 to L.
Returns:
The vertical coordinate of the upper-left corner of the active tile, with respect to the canvas origin, for component 'c', in the component coordinates, at resolution level 'rl'.

getNumTiles

public final Coord getNumTiles(Coord co)
Returns the number of tiles in the horizontal and vertical directions.

Specified by:
getNumTiles in interface MultiResImgData
Parameters:
co - If not null this object is used to return the information. If null a new one is created and returned.
Returns:
The number of tiles in the horizontal (Coord.x) and vertical (Coord.y) directions.

getNumTiles

public final int getNumTiles()
Returns the total number of tiles in the image.

Specified by:
getNumTiles in interface MultiResImgData
Returns:
The total number of tiles in the image.

getSubbandTree

public final SubbandSyn getSubbandTree(int t,
                                       int c)
Returns the subband tree, for the specified tile-component. This method returns the root element of the subband tree structure, see Subband and SubbandSyn. The tree comprises all the available resolution levels.

Note: this method is not able to return subband tree for a tile different than the current one.

The number of magnitude bits ('magBits' member variable) for each subband is not initialized.

Specified by:
getSubbandTree in interface InvWTData
Parameters:
t - The tile index
c - The index of the component, from 0 to C-1.
Returns:
The root of the tree structure.

getNumCodeBlocks

public final Coord getNumCodeBlocks(SubbandSyn sb,
                                    int c,
                                    Coord co)
Returns the number of code-blocks in a subband, along the horizontal and vertical dimensions.

Specified by:
getNumCodeBlocks in interface CodedCBlkDataSrcDec
Parameters:
sb - The subband for which to return the number of blocks.
c - The component where the subband is.
co - If not null the values are returned in this object. If null a new object is allocated and returned.
Returns:
The number of code-blocks along the horizontal dimension in 'Coord.x' and the number of code-blocks along the vertical dimension in 'Coord.y'.

getPPX

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

Parameters:
t - the tile index
c - The index of the component (between 0 and N-1)
rl - 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 tile-component and (tile-component) resolution level.

Parameters:
t - The tile index
c - The index of the component (between 0 and N-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.

initSubbandsFields

protected void initSubbandsFields(int c,
                                  SubbandSyn sb)
Initialises subbands fields, such as code-blocks dimension and number of magnitude bits, in the subband tree. The nominal code-block width/height depends on the precincts dimensions if used. The way the number of magnitude bits is computed depends on the quantization type (reversible, derived, expounded).

Parameters:
c - The component index
sb - The subband tree to be initialised.

getImgRes

public int getImgRes()
Returns the image resolution level to reconstruct from the codestream. This value cannot be computed before every main and tile headers are read.

Returns:
The image resolution level

getTargetRate

public float getTargetRate()
Return the target decoding rate in bits per pixel.

Returns:
Target decoding rate in bpp.

getActualRate

public float getActualRate()
Return the actual decoding rate in bits per pixel.

Returns:
Actual decoding rate in bpp.

getTargetNbytes

public int getTargetNbytes()
Return the target number of read bytes.

Returns:
Target decoding rate in bytes.

getActualNbytes

public int getActualNbytes()
Return the actual number of read bytes.

Returns:
Actual decoding rate in bytes.

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
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). An NoNextElementException is thrown if the current tile is the last one (i.e. there is no next tile).

Specified by:
nextTile in interface MultiResImgData

setROI

public void setROI(int x,
                   int y,
                   int w,
                   int h)

anyCodeBlockRemains

public boolean anyCodeBlockRemains()

run

public void run()
Specified by:
run in interface java.lang.Runnable

getCodeBlock

public DecLyrdCBlk getCodeBlock(int c,
                                int r,
                                int s,
                                int m,
                                int n)

getCodeBlock

public DecLyrdCBlk getCodeBlock(int c,
                                int m,
                                int n,
                                SubbandSyn sb,
                                int fl,
                                int nl,
                                DecLyrdCBlk dlcb)
Description copied from interface: CodedCBlkDataSrcDec
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 data available.

The argument 'fl' is to be used by subsequent calls to this method for the same code-block. In this way supplamental 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 subblock.

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

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'.
dlcb - 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'.

getCodeBlockOld

public DecLyrdCBlk getCodeBlockOld(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 data available.

The argument 'fl' is to be used by subsequent calls to this method for the same code-block. In this way supplamental 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 subblock.

The compressed code-block is uniquely specified by the current tile, the component (identified by 'c'), the subband (indentified by 'sb') and the code-bock 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.

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'.