jp2codec.codestream.reader
Class HeaderDecoder

java.lang.Object
  extended by jp2codec.codestream.reader.HeaderDecoder
All Implemented Interfaces:
Markers, ProgressionType, StdEntropyCoderOptions

public class HeaderDecoder
extends java.lang.Object
implements ProgressionType, Markers, StdEntropyCoderOptions

This class reads Main and Tile-part headers from the codestream. It is created by the run() method of the Decoder instance.

A marker segment includes a marker and eventually marker segment parameters. It is designed by the three letters code of the marker associated with the marker segment. JPEG 2000 part 1 defines 6 types of markers:

The main header is read when the constructor is called whereas tile-part headers are read when the BitstreamReaderAgent instance is created. The reading is done in 2 passes:

Whenever a marker segment is not recognized a warning message is displayed and its length parameter is used to skip it.

See Also:
DecoderSpecs, BitstreamReaderAgent

Field Summary
static int CRG_FOUND
          Flag bit for CRG marker segment found
 int initPos
          The starting position of the codestream in the file
 int[] nTileParts
          The number of tile parts per tile
static int PPM_FOUND
          Flag bit for SOD marker segment found
static int PPT_FOUND
          Flag bit for SOD marker segment found
static int SOD_FOUND
          Flag bit for SOD marker segment found
 java.util.Vector tileOfTileParts
          Vector containing info as to which tile each tilepart belong
 
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.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.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
HeaderDecoder(javax.imageio.stream.ImageInputStream iis)
          Creates a HeaderDecoder instance and read in two passes the main header of the codestream.
 
Method Summary
 void checkMarkerLength(java.io.DataInputStream ehs, java.lang.String str)
          Checks that the marker length is correct.
 void extractTilePartMarkSeg(short marker, javax.imageio.stream.ImageInputStream ehs, int tileIdx)
          This method extract a marker segment in a tile-part header and stores it into a byte buffer for the second pass.
 int getCodeStreamCaps()
          Returns the codestream capabilities, as defined in the 'Markers' interface.
 int getCompSubsX(int c)
          Returns the component subsampling factor, with respect to the reference grid,along the horizontal direction for the specified component.
 int getCompSubsY(int c)
          Returns the component subsampling factor, with respect to the reference grid, along the vertical direction for the specified component.
 DecoderSpecs getDecoderSpecs()
          Return the DecoderSpecs instance filled when reading the headers
 int getImgHeight()
          Returns the image height, in the reference grid.
 int getImgULX()
          Return the horizontal coordinate of the image origin with respect to the canvas one, in the reference grid.
 int getImgULY()
          Return the vertical coordinate of the image origin with respect to the canvas one, in the reference grid.
 int getImgWidth()
          Returns the image width, in the reference grid.
 int[] getMaxBoost()
          Returns the scaling value to use if the maxshift method was specified

NOTE: All ROI parameters should be grouped in an ROI spec object.

 int getNomTileHeight()
          Returns the nominal width of the tiles in the reference grid.
 int getNomTileWidth()
          Returns the nominal width of the tiles in the reference grid.
 int getNumComps()
          Returns the number of components in the image.
 int getNumTiles()
          Return the number of tiles in the image
 int getOriginalBitDepth(int c)
          Returns the original bitdepth of the specified component.
 java.io.ByteArrayInputStream getPackedPktHead(int tile)
          Return the packed packet headers for a given tile
 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 component, tile and resolution level.
 int getPPY(int t, int c, int rl)
          Returns the precinct partition height for the specified component, tile and resolution level.
 Coord getTilingOrigin(Coord co)
          Returns the tiling origin, refferred to as '(Px,Py)' in the 'ImgData' interface.
 int getTotalHeaderLength()
          Returns the total header length, including the magic number, header length number and encoded header length.
 boolean isOriginalSigned(int c)
          Returns true if the original data of the specified component was signed.
 boolean precinctPartitionUsed()
          Returns the boolean used to know if the precinct partition is used
 void readFoundTilePartMarkSeg(int tileIdx)
          Retrieve and read all marker segment previously found in the tile header.
 void resetHeaderMarkers()
          Method that resets members indicating which markers have already been found
 void setTileOfTileParts(int tile)
          Sets the tile of each tile part in order.
 java.lang.String toString()
          Print information about the current header.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

nTileParts

public int[] nTileParts
The number of tile parts per tile


SOD_FOUND

public static final int SOD_FOUND
Flag bit for SOD marker segment found

See Also:
Constant Field Values

PPM_FOUND

public static final int PPM_FOUND
Flag bit for SOD marker segment found

See Also:
Constant Field Values

PPT_FOUND

public static final int PPT_FOUND
Flag bit for SOD marker segment found

See Also:
Constant Field Values

CRG_FOUND

public static final int CRG_FOUND
Flag bit for CRG marker segment found

See Also:
Constant Field Values

initPos

public int initPos
The starting position of the codestream in the file


tileOfTileParts

public java.util.Vector tileOfTileParts
Vector containing info as to which tile each tilepart belong

Constructor Detail

HeaderDecoder

public HeaderDecoder(javax.imageio.stream.ImageInputStream iis)
              throws java.io.IOException
Creates a HeaderDecoder instance and read in two passes the main header of the codestream. The first and last marker segments shall be respectively SOC and SOT.

Parameters:
iis - The encoded header stream where marker segment are extracted.
Throws:
java.io.IOException - If an I/O error occurs while reading from the encoded header stream.
java.io.EOFException - If the end of the encoded header stream is reached before getting all the data.
CorruptedCodestreamException - If invalid data is found in the codestream main header.
Method Detail

getTotalHeaderLength

public final int getTotalHeaderLength()
Returns the total header length, including the magic number, header length number and encoded header length.

Returns:
The total header length.

getCodeStreamCaps

public final int getCodeStreamCaps()
Returns the codestream capabilities, as defined in the 'Markers' interface. These capabilities are flag bits, the different flags are defined in 'Markers' as constants with the 'RSIZ' prefix.

Returns:
The codestream capabilities
See Also:
Markers

getImgWidth

public final int getImgWidth()
Returns the image width, in the reference grid.

Returns:
The image width in the reference grid

getImgHeight

public final int getImgHeight()
Returns the image height, in the reference grid.

Returns:
The image height in the reference grid

getImgULX

public final int getImgULX()
Return the horizontal coordinate of the image origin with respect to the canvas one, in the reference grid.

Returns:
The horizontal coordinate of the image origin.

getImgULY

public final int getImgULY()
Return the vertical coordinate of the image origin with respect to the canvas one, in the reference grid.

Returns:
The vertical coordinate of the image origin.

getNomTileWidth

public final int getNomTileWidth()
Returns the nominal width of the tiles in the reference grid.

Returns:
The nominal tile width, in the reference grid.

getNomTileHeight

public final int getNomTileHeight()
Returns the nominal width of the tiles in the reference grid.

Returns:
The nominal tile width, in the reference grid.

getTilingOrigin

public final Coord getTilingOrigin(Coord co)
Returns the tiling origin, refferred to as '(Px,Py)' in the 'ImgData' interface.

Parameters:
co - If not null this object is used to return the information. If null a new one is created and returned.
Returns:
The coordinate of the tiling origin, in the canvas system, on the reference grid.
See Also:
ImgData

isOriginalSigned

public final boolean isOriginalSigned(int c)
Returns true if the original data of the specified component was signed. If the data was not signed a level shift has to be applied at the end of the decompression chain.

Parameters:
c - The index of the component
Returns:
True if the original image component was signed.

getOriginalBitDepth

public final int getOriginalBitDepth(int c)
Returns the original bitdepth of the specified component.

Parameters:
c - The index of the component
Returns:
The bitdepth of the component

getNumComps

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

Returns:
The number of components in the image.

getCompSubsX

public final int getCompSubsX(int c)
Returns the component subsampling factor, with respect to the reference grid,along the horizontal direction for the specified component.

Parameters:
c - The index of the component
Returns:
The component subsampling factor X-wise.

getCompSubsY

public final int getCompSubsY(int c)
Returns the component subsampling factor, with respect to the reference grid, along the vertical direction for the specified component.

Parameters:
c - The index of the component
Returns:
The component subsampling factor Y-wise.

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.

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

Returns:
The vertical coordinate of the origin of the cell and code-block partitions, with respect to the canvas origin, on the reference grid.

getMaxBoost

public final int[] getMaxBoost()
Returns the scaling value to use if the maxshift method was specified

NOTE: All ROI parameters should be grouped in an ROI spec object.

Returns:
The scaling value to use if the maxshift method was specifiedn

getPPX

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

Parameters:
c - the component
t - the tile index
rl - the resolution level
Returns:
The precinct partition width for the specified component, tile and resolution level

getPPY

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

Parameters:
c - the component
t - the tile index
rl - the resolution level
Returns:
The precinct partition height for the specified component, tile and resolution level

precinctPartitionUsed

public final boolean precinctPartitionUsed()
Returns the boolean used to know if the precinct partition is used


checkMarkerLength

public void checkMarkerLength(java.io.DataInputStream ehs,
                              java.lang.String str)
                       throws java.io.IOException
Checks that the marker length is correct. The filler (i.e. "res") byte is skipped if there is one. If less bytes than the given length ('mlen') are read a warning is printed and the "useless" bytes are skipped. If more bytes than the given length ('mlen') have been read then a 'CorruptedCodestreamException' is thrown.

Parameters:
ehs - The encoded header stream
str - The string identifying the marker, such as "SIZ marker"
Throws:
CorruptedCodestreamException - If too much marker data was read, according to the given length.
java.io.IOException - If an I/O error occurs

extractTilePartMarkSeg

public void extractTilePartMarkSeg(short marker,
                                   javax.imageio.stream.ImageInputStream ehs,
                                   int tileIdx)
                            throws java.io.IOException
This method extract a marker segment in a tile-part header and stores it into a byte buffer for the second pass. The marker is first recognized, then its flag is activated and, finally, its content is buffered in an element of byte arrays accessible thanks to a hashTable. If a marker segment is not recognized, it prints a warning and skip it according to its length.

Parameters:
marker - The marker to process
ehs - The encoded header stream
tileIdx - The index of the current tile
Throws:
java.io.IOException

readFoundTilePartMarkSeg

public void readFoundTilePartMarkSeg(int tileIdx)
                              throws java.io.IOException
Retrieve and read all marker segment previously found in the tile header.

Parameters:
tileIdx - The index of the current tile
Throws:
java.io.IOException

getDecoderSpecs

public DecoderSpecs getDecoderSpecs()
Return the DecoderSpecs instance filled when reading the headers

Returns:
The DecoderSpecs of the decoder

resetHeaderMarkers

public void resetHeaderMarkers()
Method that resets members indicating which markers have already been found


toString

public java.lang.String toString()
Print information about the current header.

Overrides:
toString in class java.lang.Object
Returns:
Information in a String

getNumTiles

public int getNumTiles()
Return the number of tiles in the image

Returns:
The number of tiles

getPackedPktHead

public java.io.ByteArrayInputStream getPackedPktHead(int tile)
                                              throws java.io.IOException
Return the packed packet headers for a given tile

Returns:
An input stream containing the packed packet headers for a particular tile
Throws:
java.io.IOException - If an I/O error occurs while reading from the encoder header stream

setTileOfTileParts

public void setTileOfTileParts(int tile)
Sets the tile of each tile part in order. This information is needed for identifying which packet header belongs to which tile when using the PPM marker

Parameters:
tile - The tile number that the present tile part belongs to