C# Class CSJ2K.j2k.codestream.reader.HeaderDecoder

This class reads main and tile-part headers from the codestream given a RandomAccessIO instance located at the beginning of the codestream (i.e just before the SOC marker) or at the beginning of a tile-part (i.e. just before a SOT marker segment) respectively.

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 segments:

  • Delimiting : SOC, SOT, SOD, EOC
  • Fixed information: SIZ.
  • Functional: COD, COC, RGN, QCD, QCC,POC.
  • In bit-stream: SOP, EPH.
  • Pointer: TLM, PLM, PLT, PPM, PPT.
  • Informational: CRG, COM.

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

  1. All marker segments are buffered and their corresponding flag is activated (extractMainMarkSeg and extractTilePartMarkSeg methods).
  2. Buffered marker segment are analyzed in a logical way and specifications are stored in appropriate member of DecoderSpecs instance (readFoundMainMarkSeg and readFoundTilePartMarkSeg methods).

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

The information found in this header is stored in HeaderInfo and DecoderSpecs instances.

Mostra file Open project: cureos/csj2k Class Usage Examples

Public Properties

Property Type Description
mainHeadOff int
nTileParts int[]

Public Methods

Method Description
HeaderDecoder ( RandomAccessIO ehs, CSJ2K.j2k.util.ParameterList pl, HeaderInfo hi ) : System

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.

ToString ( ) : System.String

Print information about the current header.

checkMarkerLength ( System ehs, System str ) : void

Checks that the marker segment length is correct.

createChannelDefinitionMapper ( BlkImgDataSrc src, CSJ2K csMap ) : BlkImgDataSrc

Creates and returns the ChannelDefinitonMapper which maps the input channels to the channel definition for the appropriate colorspace.

createColorSpaceMapper ( BlkImgDataSrc src, CSJ2K csMap ) : BlkImgDataSrc

Creates and returns the EnumeratedColorSpaceMapper corresponding to the information read from the JP2 image file via the ColorSpace parameter.

createDequantizer ( CBlkQuantDataSrcDec src, int rb, DecoderSpecs decSpec2 ) : CSJ2K.j2k.quantization.dequantizer.Dequantizer

Returns the dequantizer parameters. Dequantizer parameters normally are the quantization step sizes, see DequantizerParams.

createEntropyDecoder ( CodedCBlkDataSrcDec src, CSJ2K.j2k.util.ParameterList pl ) : CSJ2K.j2k.entropy.decoder.EntropyDecoder

Creates and returns the entropy decoder corresponding to the information read from the codestream header and with the special additional parameters from the parameter list.

createPalettizedColorSpaceMapper ( BlkImgDataSrc src, CSJ2K csMap ) : BlkImgDataSrc

Creates and returns the PalettizedColorSpaceMapper which uses the input samples as indicies into a sample palette to construct the output.

createROIDeScaler ( CBlkQuantDataSrcDec src, CSJ2K.j2k.util.ParameterList pl, DecoderSpecs decSpec2 ) : CSJ2K.j2k.roi.ROIDeScaler

Creates and returns the ROIDeScaler corresponding to the information read from the codestream header and with the special additional parameters from the parameter list.

createResampler ( BlkImgDataSrc src, CSJ2K csMap ) : BlkImgDataSrc

Creates and returns the Resampler which converts the input source to one in which all channels have the same number of samples. This is required for colorspace conversions.

extractTilePartMarkSeg ( short marker, RandomAccessIO ehs, int tileIdx, int tilePartIdx ) : void

This method extracts 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.

getCompSubsX ( int c ) : int

Returns the component sub-sampling factor, with respect to the reference grid, along the horizontal direction for the specified component.

getCompSubsY ( int c ) : int

Returns the component sub-sampling factor, with respect to the reference grid, along the vertical direction for the specified component.

getOriginalBitDepth ( int c ) : int

Returns the original bitdepth of the specified component.

getPPX ( int t, int c, int rl ) : int

Returns the precinct partition width for the specified tile-component and resolution level.

getPPY ( int t, int c, int rl ) : int

Returns the precinct partition height for the specified tile-component and resolution level.

getPackedPktHead ( int tile ) : System.IO.MemoryStream

Return the packed packet headers for a given tile.

getTilingOrigin ( Coord co ) : Coord

Returns the tiling origin, referred to as '(Px,Py)' in the 'ImgData' interface.

isOriginalSigned ( int c ) : bool

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.

precinctPartitionUsed ( ) : bool

Returns the boolean used to know if the precinct partition is used

readFoundTilePartMarkSeg ( int tileIdx, int tpIdx ) : void

Retrieves and reads all marker segments previously found in the tile-part header.

resetHeaderMarkers ( ) : void

Method that resets members indicating which markers have already been found

Private Methods

Method Description
extractMainMarkSeg ( short marker, RandomAccessIO ehs ) : void

This method extract a marker segment from the main header and stores it into a byte buffer for the second pass. The marker segment is first identified. Then its flag is activated. Finally, its content is buffered into a byte array stored in an hashTable.

If the marker is not recognized, it prints a warning and skips it according to its length.

SIZ marker segment shall be the first encountered marker segment.

readCOC ( System ehs, bool mainh, int tileIdx, int tpIdx ) : void

Reads the COC marker segment and realigns the codestream where the next marker should be found.

readCOD ( System ehs, bool mainh, int tileIdx, int tpIdx ) : void

Reads a COD marker segment and realigns the codestream where the next marker should be found.

readCOM ( System ehs, bool mainh, int tileIdx, int comIdx ) : void

Reads a COM marker segments and realigns the bit stream at the point where the next marker segment should be found. COM is an informational marker segment that allows to include unstructured data in the main and tile-part headers.

readCRG ( System ehs ) : void

Reads a CRG marker segment and checks its length. CRG is an informational marker segment that allows specific registration of components with respect to each other.

readFilter ( System ehs, int filtIdx ) : CSJ2K.j2k.wavelet.synthesis.SynWTFilter

Reads a wavelet filter from the codestream and returns the filter object that implements it.

readFoundMainMarkSeg ( ) : void

Retrieves and reads all marker segments found in the main header during the first pass.

readPLM ( System ehs ) : void

Reads PLM marker segment and realigns the codestream where the next marker should be found. Informations stored in these fields are currently not taken into account.

readPLTFields ( System ehs ) : void

Reads the PLT fields and realigns the codestream where the next marker should be found. Informations stored in these fields are currently NOT taken into account.

readPOC ( System ehs, bool mainh, int t, int tpIdx ) : void

Reads the POC marker segment and realigns the codestream where the next marker should be found.

readPPM ( System ehs ) : void

Reads the PPM marker segment of the main header.

readPPT ( System ehs, int tile, int tpIdx ) : void

Reads the PPT marker segment of the main header.

readQCC ( System ehs, bool mainh, int tileIdx, int tpIdx ) : void

Reads a QCC marker segment and realigns the codestream at the point where the next marker should be found. QCC is a functional marker segment that describes the quantization of one component.

readQCD ( System ehs, bool mainh, int tileIdx, int tpIdx ) : void

Reads a QCD marker segment and realigns the codestream at the point where the next marker should be found. QCD is a functional marker segment that describes the quantization default.

readRGN ( System ehs, bool mainh, int tileIdx, int tpIdx ) : void

Reads the RGN marker segment of the codestream header.

May be used in tile or main header. If used in main header, it refers to the maxshift value of a component in all tiles. When used in tile header, only the particular tile-component is affected.

readSIZ ( System ehs ) : void

Reads the SIZ marker segment and realigns the codestream at the point where the next marker segment should be found.

SIZ is a fixed information marker segment containing informations about image and tile sizes. It is required in the main header immediately after SOC.

readTLM ( System ehs ) : void

Reads TLM marker segment and realigns the codestream where the next marker should be found. Informations stored in these fields are currently NOT taken into account.

Method Details

HeaderDecoder() public method

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.
If an I/O error occurs while reading from the /// encoded header stream. /// If the end of the encoded header stream is /// reached before getting all the data. /// If invalid data is found in the /// codestream main header. /// ///
public HeaderDecoder ( RandomAccessIO ehs, CSJ2K.j2k.util.ParameterList pl, HeaderInfo hi ) : System
ehs RandomAccessIO The encoded header stream where marker segments are /// extracted. /// ///
pl CSJ2K.j2k.util.ParameterList The ParameterList object of the decoder /// ///
hi CSJ2K.j2k.codestream.HeaderInfo The HeaderInfo holding information found in marker segments /// ///
return System

ToString() public method

Print information about the current header.
public ToString ( ) : System.String
return System.String

checkMarkerLength() public method

Checks that the marker segment length is correct.
If an I/O error occurs /// ///
public checkMarkerLength ( System ehs, System str ) : void
ehs System The encoded header stream /// ///
str System The string identifying the marker, such as "SIZ marker" /// ///
return void

createChannelDefinitionMapper() public method

Creates and returns the ChannelDefinitonMapper which maps the input channels to the channel definition for the appropriate colorspace.
image access exception /// if image contains a bad colorspace box /// ///
public createChannelDefinitionMapper ( BlkImgDataSrc src, CSJ2K csMap ) : BlkImgDataSrc
src BlkImgDataSrc The bit stream reader agent where to get code-block /// data from. ///
csMap CSJ2K provides color space information from the image file /// ///
return BlkImgDataSrc

createColorSpaceMapper() public method

Creates and returns the EnumeratedColorSpaceMapper corresponding to the information read from the JP2 image file via the ColorSpace parameter.
image access exception /// if image contains a bad icc profile /// if image contains a bad colorspace box /// ///
public createColorSpaceMapper ( BlkImgDataSrc src, CSJ2K csMap ) : BlkImgDataSrc
src BlkImgDataSrc The bit stream reader agent where to get code-block /// data from. ///
csMap CSJ2K provides color space information from the image file /// ///
return BlkImgDataSrc

createDequantizer() public method

Returns the dequantizer parameters. Dequantizer parameters normally are the quantization step sizes, see DequantizerParams.
public createDequantizer ( CBlkQuantDataSrcDec src, int rb, DecoderSpecs decSpec2 ) : CSJ2K.j2k.quantization.dequantizer.Dequantizer
src CBlkQuantDataSrcDec The source of data for the dequantizer. /// ///
rb int The number of range bits for each component. Must be /// the number of range bits of the mixed components. /// ///
decSpec2 CSJ2K.j2k.decoder.DecoderSpecs The DecoderSpecs instance after any image manipulation. /// ///
return CSJ2K.j2k.quantization.dequantizer.Dequantizer

createEntropyDecoder() public method

Creates and returns the entropy decoder corresponding to the information read from the codestream header and with the special additional parameters from the parameter list.
public createEntropyDecoder ( CodedCBlkDataSrcDec src, CSJ2K.j2k.util.ParameterList pl ) : CSJ2K.j2k.entropy.decoder.EntropyDecoder
src CodedCBlkDataSrcDec The bit stream reader agent where to get code-block data /// from. /// ///
pl CSJ2K.j2k.util.ParameterList The parameter list containing parameters applicable to the /// entropy decoder (other parameters can also be present). /// ///
return CSJ2K.j2k.entropy.decoder.EntropyDecoder

createPalettizedColorSpaceMapper() public method

Creates and returns the PalettizedColorSpaceMapper which uses the input samples as indicies into a sample palette to construct the output.
image access exception /// if image contains a bad colorspace box /// ///
public createPalettizedColorSpaceMapper ( BlkImgDataSrc src, CSJ2K csMap ) : BlkImgDataSrc
src BlkImgDataSrc The bit stream reader agent where to get code-block /// data from. ///
csMap CSJ2K provides color space information from the image file /// ///
return BlkImgDataSrc

createROIDeScaler() public method

Creates and returns the ROIDeScaler corresponding to the information read from the codestream header and with the special additional parameters from the parameter list.
public createROIDeScaler ( CBlkQuantDataSrcDec src, CSJ2K.j2k.util.ParameterList pl, DecoderSpecs decSpec2 ) : CSJ2K.j2k.roi.ROIDeScaler
src CBlkQuantDataSrcDec The bit stream reader agent where to get code-block data /// from. /// ///
pl CSJ2K.j2k.util.ParameterList The parameter list containing parameters applicable to the /// entropy decoder (other parameters can also be present). /// ///
decSpec2 CSJ2K.j2k.decoder.DecoderSpecs The DecoderSpecs instance after any image manipulation. /// ///
return CSJ2K.j2k.roi.ROIDeScaler

createResampler() public method

Creates and returns the Resampler which converts the input source to one in which all channels have the same number of samples. This is required for colorspace conversions.
image access exception /// if image contains a bad colorspace box /// ///
public createResampler ( BlkImgDataSrc src, CSJ2K csMap ) : BlkImgDataSrc
src BlkImgDataSrc The bit stream reader agent where to get code-block /// data from. ///
csMap CSJ2K provides color space information from the image file /// ///
return BlkImgDataSrc

extractTilePartMarkSeg() public method

This method extracts 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.
public extractTilePartMarkSeg ( short marker, RandomAccessIO ehs, int tileIdx, int tilePartIdx ) : void
marker short The marker to process /// ///
ehs RandomAccessIO The encoded header stream /// ///
tileIdx int The index of the current tile /// ///
tilePartIdx int The index of the current tile part /// ///
return void

getCompSubsX() public method

Returns the component sub-sampling factor, with respect to the reference grid, along the horizontal direction for the specified component.
public getCompSubsX ( int c ) : int
c int The index of the component /// ///
return int

getCompSubsY() public method

Returns the component sub-sampling factor, with respect to the reference grid, along the vertical direction for the specified component.
public getCompSubsY ( int c ) : int
c int The index of the component /// ///
return int

getOriginalBitDepth() public method

Returns the original bitdepth of the specified component.
public getOriginalBitDepth ( int c ) : int
c int The index of the component /// ///
return int

getPPX() public method

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

getPPY() public method

Returns the precinct partition height for the specified tile-component and resolution level.
public getPPY ( int t, int c, int rl ) : int
t int the tile index /// ///
c int the component index /// ///
rl int the resolution level /// ///
return int

getPackedPktHead() public method

Return the packed packet headers for a given tile.
If an I/O error occurs while reading from the /// encoder header stream /// ///
public getPackedPktHead ( int tile ) : System.IO.MemoryStream
tile int
return System.IO.MemoryStream

getTilingOrigin() public method

Returns the tiling origin, referred to as '(Px,Py)' in the 'ImgData' interface.
public getTilingOrigin ( Coord co ) : Coord
co Coord If not null this object is used to return the information. If /// null a new one is created and returned. /// ///
return Coord

isOriginalSigned() public method

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.
public isOriginalSigned ( int c ) : bool
c int The index of the component /// ///
return bool

precinctPartitionUsed() public method

Returns the boolean used to know if the precinct partition is used
public precinctPartitionUsed ( ) : bool
return bool

readFoundTilePartMarkSeg() public method

Retrieves and reads all marker segments previously found in the tile-part header.
public readFoundTilePartMarkSeg ( int tileIdx, int tpIdx ) : void
tileIdx int The index of the current tile /// ///
tpIdx int Index of the current tile-part /// ///
return void

resetHeaderMarkers() public method

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

Property Details

mainHeadOff public_oe property

The offset of the main header in the input stream
public int mainHeadOff
return int

nTileParts public_oe property

The number of tile parts in each tile
public int[] nTileParts
return int[]