Class BitstreamReaderAgent
- All Implemented Interfaces:
CodedCBlkDataSrcDec,InvWTData,MultiResImgData
- Direct Known Subclasses:
FileBitstreamReaderAgent
The bit stream reader agent allows to make request for compressed block data in any order. The amount of data returned would normally depend on the data available at the time of the request, be it from a file or from a network connection.
The bit stream reader agent has the notion of a current tile, and coordinates are relative to the current tile, where applicable.
Resolution level 0 is the lowest resolution level, i.e. the LL subband alone.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intActual number of read bytesprotected floatActual decoding rate in bppprotected final intThe horizontal coordinate of the image origin in the canvas system, on the reference grid.protected final intThe vertical coordinate of the image origin in the canvas system, on the reference grid.protected intThe current tile horizontal indexprotected intThe current tile vertical indexprotected final int[]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 final int[]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 DecoderSpecsThe decoder specificationsprotected boolean[]Whether or not the components in the current tile uses a derived quantization step size (only relevant in non reversible quantization mode).protected int[]Number of guard bits off all component in the current tile.protected final HeaderDecoderThe decoded bit stream headerprotected final intThe image width on the hi-res reference gridprotected final intThe image width on the hi-res reference gridprotected int[]The maximum number of decompostion levels for each component of the current tile.protected final intThe number of componentsprotected final intThe total number of tiles.protected final intThe nominal tile height, in the hi-res reference gridprotected final intThe nominal tile width, in the hi-res reference gridprotected final intThe number of tile in the horizontal directionprotected final intThe number of tiles in the vertical directionprotected final int[]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 final int[]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.static final charThe prefix for bit stream reader options: 'B'protected StdDequantizerParams[]Dequantization parameters of all subbands and all components in the current tile.protected final intThe horizontal coordinate of the tiling origin in the canvas system, on the reference grid.protected final intThe vertical coordinate of the tiling origin in the canvas system, on the reference grid.protected SubbandSyn[]The subband trees for each component in the current tile.protected intImage resolution level to generateprotected intNumber of bytes targeted to be readprotected floatTarget decoding rate in bpp -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBitstreamReaderAgent(HeaderDecoder hd, DecoderSpecs decSpec) Initializes members of this class. -
Method Summary
Modifier and TypeMethodDescriptionstatic BitstreamReaderAgentcreateInstance(RandomAccessIO in, HeaderDecoder hd, J2KImageReadParamJava j2krparam, DecoderSpecs decSpec, boolean cdstrInfo, HeaderInfo hi) Creates a bit stream reader of the correct type that works on the provided RandomAccessIO, with the special parameters from the parameter list.intReturn the actual number of read bytes.floatReturn the actual decoding rate in bits per pixel.final intgetCbULX()Returns the vertical code-block partition origin.intgetCbULY()Returns the vertical code-block partition origin.final intgetCompImgHeight(int c, int rl) Returns the height in pixels of the specified component in the overall image, for the given (component) resolution level.final intgetCompImgWidth(int c, int rl) Returns the width in pixels of the specified component in the overall image, for the given (component) resolution level.final intgetCompSubsX(int c) Returns the component subsampling factor in the horizontal direction, for the specified component.intgetCompSubsY(int c) Returns the component subsampling factor in the vertical direction, for the specified component.intgetImgHeight(int rl) Returns the overall height of the image in pixels, for the given resolution level.intReturns the image resolution level to reconstruct from the codestream.intgetImgULX(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.intgetImgULY(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.intgetImgWidth(int rl) Returns the overall width of the image in pixels, for the given (image) resolution level.intReturns the nominal tile heightintReturns the nominal tile widthfinal intReturns the number of components in the image.final intReturns the total number of tiles in the image.final PointgetNumTiles(Point co) Returns the number of tiles in the horizontal and vertical directions.static String[][]Returns the parameters that are used in this class and implementing classes.final intgetPPX(int t, int c, int rl) Returns the precinct partition width for the specified tile-component and (tile-component) resolution level.final intgetPPY(int t, int c, int rl) Returns the precinct partition height for the specified tile-component and (tile-component) resolution level.final intgetResULX(int c, int rl) Returns the horizontal coordinate of the upper-left corner of the specified resolution in the given component of the current tile.final intgetResULY(int c, int rl) Returns the vertical coordinate of the upper-left corner of the specified component in the given component of the current tile.final SubbandSyngetSynSubbandTree(int t, int c) Returns the subband tree, for the specified tile-component.intReturn the target number of read bytes.floatReturn the target decoding rate in bits per pixel.final PointReturns the indexes of the current tile.final intgetTileCompHeight(int t, int c, int rl) Returns the height in pixels of the specified tile-component for the given (tile-component) resolution level.final intgetTileCompWidth(int t, int c, int rl) Returns the width in pixels of the specified tile-component for the given (tile-component) resolution level.intgetTileHeight(int rl) Returns the overall height of the current tile in pixels, for the given resolution level.final intReturns the index of the current tile, relative to a standard scan-line order.intReturns the horizontal offset of tile partitionintReturns the vertical offset of tile partitionintgetTileWidth(int rl) Returns the overall width of the current tile in pixels for the given (tile) resolution level.protected voidinitSubbandsFields(int c, SubbandSyn sb) Initialises subbands fields, such as code-blocks dimension and number of magnitude bits, in the subband tree.abstract voidnextTile()Advances to the next tile, in standard scan-line order (by rows then columns).abstract voidsetTile(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, waitMethods inherited from interface jj2000.j2k.entropy.decoder.CodedCBlkDataSrcDec
getCodeBlock
-
Field Details
-
decSpec
The decoder specifications -
derived
protected boolean[] derivedWhether 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 FileBitstreamReaderAgent. -
gb
protected int[] gbNumber of guard bits off all component in the current tile. This field is actualized by the setTile method in FileBitstreamReaderAgent. -
params
Dequantization parameters of all subbands and all components in the current tile. The value is actualized by the setTile method in FileBitstreamReaderAgent. -
OPT_PREFIX
public static final char OPT_PREFIXThe prefix for bit stream reader options: 'B'- See Also:
-
mdl
protected int[] mdlThe 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 ncThe number of components -
targetRes
protected int targetResImage resolution level to generate -
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 imgWThe image width on the hi-res reference grid -
imgH
protected final int imgHThe image width on the hi-res reference grid -
ax
protected final int axThe horizontal coordinate of the image origin in the canvas system, on the reference grid. -
ay
protected final int ayThe vertical coordinate of the image origin in the canvas system, on the reference grid. -
px
protected final int pxThe horizontal coordinate of the tiling origin in the canvas system, on the reference grid. -
py
protected final int pyThe vertical coordinate of the tiling origin in the canvas system, on the reference grid. -
offX
protected final int[] offXThe 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[] offYThe 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[] culxThe 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[] culyThe 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 ntWThe nominal tile width, in the hi-res reference grid -
ntH
protected final int ntHThe nominal tile height, in the hi-res reference grid -
ntX
protected final int ntXThe number of tile in the horizontal direction -
ntY
protected final int ntYThe number of tiles in the vertical direction -
nt
protected final int ntThe total number of tiles. -
ctX
protected int ctXThe current tile horizontal index -
ctY
protected int ctYThe current tile vertical index -
hd
The decoded bit stream header -
tnbytes
protected int tnbytesNumber of bytes targeted to be read -
anbytes
protected int anbytesActual number of read bytes -
trate
protected float trateTarget decoding rate in bpp -
arate
protected float arateActual decoding rate in bpp
-
-
Constructor Details
-
BitstreamReaderAgent
Initializes members of this class. This constructor takes a HeaderDecoder object. This object must be initialized by the constructor of the implementing class from the header of the bit stream.- Parameters:
hd- The decoded header of the bit stream from where to initialize the values.decSpec- The decoder specifications
-
-
Method Details
-
getCbULX
public final int getCbULX()Returns the vertical code-block partition origin. Allowable values are 0 and 1, nothing else. -
getCbULY
public int getCbULY()Returns the vertical code-block partition origin. Allowable values are 0 and 1, nothing else. -
getNumComps
public final int getNumComps()Returns the number of components in the image.- Specified by:
getNumCompsin interfaceMultiResImgData- 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:
getCompSubsXin interfaceMultiResImgData- Parameters:
c- The index of the component (between 0 and N-1)- Returns:
- The horizontal subsampling factor of component 'c'
- See Also:
-
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:
getCompSubsYin interfaceMultiResImgData- Parameters:
c- The index of the component (between 0 and C-1)- Returns:
- The vertical subsampling factor of component 'c'
- See Also:
-
getTileWidth
public int getTileWidth(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:
getTileWidthin interfaceMultiResImgData- Parameters:
rl- The (tile) resolution level.- Returns:
- The current tile's width in pixels.
-
getTileHeight
public int getTileHeight(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:
getTileHeightin interfaceMultiResImgData- 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:
getImgWidthin interfaceMultiResImgData- 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:
getImgHeightin interfaceMultiResImgData- 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:
getImgULXin interfaceMultiResImgData- 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:
getImgULYin interfaceMultiResImgData- 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.
-
getTileCompWidth
public final int getTileCompWidth(int t, int c, int rl) Returns the width in pixels of the specified tile-component for the given (tile-component) resolution level.- Specified by:
getTileCompWidthin interfaceMultiResImgData- Parameters:
t- The tile indexc- 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 tile t for resolution level rl.
-
getTileCompHeight
public final int getTileCompHeight(int t, int c, int rl) Returns the height in pixels of the specified tile-component for the given (tile-component) resolution level.- Specified by:
getTileCompHeightin interfaceMultiResImgData- Parameters:
t- The tile index.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:
getCompImgWidthin interfaceMultiResImgData- 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:
getCompImgHeightin interfaceMultiResImgData- 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.
-
setTile
public abstract 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:
setTilein interfaceMultiResImgData- Parameters:
x- The horizontal indexes the tile.y- The vertical indexes of the new tile.
-
nextTile
public abstract 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:
nextTilein interfaceMultiResImgData
-
getTile
Returns the indexes of the current tile. These are the horizontal and vertical indexes of the current tile.- Specified by:
getTilein interfaceMultiResImgData- 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:
getTileIdxin interfaceMultiResImgData- Returns:
- The current tile's index (starts at 0).
-
getResULX
public final int getResULX(int c, int rl) Returns the horizontal coordinate of the upper-left corner of the specified resolution in the given component of the current tile.- Specified by:
getResULXin interfaceMultiResImgData- Parameters:
c- The component index.rl- The resolution level index.
-
getResULY
public final int getResULY(int c, int rl) Returns the vertical coordinate of the upper-left corner of the specified component in the given component of the current tile.- Specified by:
getResULYin interfaceMultiResImgData- Parameters:
c- The component index.rl- The resolution level index.
-
getNumTiles
Returns the number of tiles in the horizontal and vertical directions.- Specified by:
getNumTilesin interfaceMultiResImgData- 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 (Point.x) and vertical (Point.y) directions.
-
getNumTiles
public final int getNumTiles()Returns the total number of tiles in the image.- Specified by:
getNumTilesin interfaceMultiResImgData- Returns:
- The total number of tiles in the image.
-
getSynSubbandTree
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:
getSynSubbandTreein interfaceInvWTData- Specified by:
getSynSubbandTreein interfaceMultiResImgData- Parameters:
t- The tile indexc- The index of the component, from 0 to C-1.- Returns:
- The root of the tree structure.
-
createInstance
public static BitstreamReaderAgent createInstance(RandomAccessIO in, HeaderDecoder hd, J2KImageReadParamJava j2krparam, DecoderSpecs decSpec, boolean cdstrInfo, HeaderInfo hi) throws IOException Creates a bit stream reader of the correct type that works on the provided RandomAccessIO, with the special parameters from the parameter list.- Parameters:
in- The RandomAccessIO source from which to read the bit stream.hd- Header of the codestream.j2krparam- The parameters applicable to the bit stream read (other parameters may also be present).decSpec- The decoder specificationscdstrInfo- Whether or not to print information found in codestream.hi- Reference to the HeaderInfo instance.- Throws:
IOException- If an I/O error occurs while reading initial data from the bit stream.IllegalArgumentException- If an unrecognised bit stream reader option is present.
-
getParameterInfo
Returns the parameters that are used in this class and implementing classes. It returns a 2D String array. Each of the 1D arrays is for a different option, and they have 3 elements. The first element is the option name, the second one is the synopsis and the third one is a long description of what the parameter is. The synopsis or description may be 'null', in which case it is assumed that there is no synopsis or description of the option, respectively. Null may be returned if no options are supported.- Returns:
- the options name, their synopsis and their explanation, or null if no options are supported.
-
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 indexc- 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 indexc- 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
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 indexsb- 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.
-
getTilePartULX
public int getTilePartULX()Returns the horizontal offset of tile partition- Specified by:
getTilePartULXin interfaceMultiResImgData
-
getTilePartULY
public int getTilePartULY()Returns the vertical offset of tile partition- Specified by:
getTilePartULYin interfaceMultiResImgData
-
getNomTileWidth
public int getNomTileWidth()Returns the nominal tile width- Specified by:
getNomTileWidthin interfaceMultiResImgData
-
getNomTileHeight
public int getNomTileHeight()Returns the nominal tile height- Specified by:
getNomTileHeightin interfaceMultiResImgData
-