Package jj2000.j2k.codestream.reader
Class HeaderDecoder
java.lang.Object
jj2000.j2k.codestream.reader.HeaderDecoder
- All Implemented Interfaces:
Markers,ProgressionType,StdEntropyCoderOptions
public class HeaderDecoder
extends 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:
- Delimiting : SOC,SOT (read in FileBitstreamReaderAgent),SOD,EOC (read in FileBitstreamReaderAgent).
- 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:
- All marker segments are buffered and their corresponding flag is activated (extractMainMarkSeg and extractTilePartMarkSeg methods).
- 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.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intFlag bit for CRG marker segment foundintThe offset of the main header in the input streamint[]The number of tile parts per tilestatic final charThe prefix for header decoder options: 'H'static final intFlag bit for SOD marker segment foundstatic final intFlag bit for SOD marker segment foundstatic final intFlag bit for SOD marker segment foundVector containing info as to which tile each tilepart belongFields inherited from interface jj2000.j2k.codestream.Markers
COC, COD, COM, CRG, EOC, EPH, EPH_LENGTH, ERS_SEG_SYMBOLS, 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_HOR_CB_PART, SCOX_PRECINCT_PARTITION, SCOX_USE_EPH, SCOX_USE_SOP, SCOX_VER_CB_PART, 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, TLMFields inherited from interface jj2000.j2k.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_PROGFields inherited from interface jj2000.j2k.entropy.StdEntropyCoderOptions
FIRST_BYPASS_PASS_IDX, MAX_CB_AREA, MAX_CB_DIM, MIN_CB_DIM, NUM_EMPTY_PASSES_IN_MS_BP, NUM_NON_BYPASS_MS_BP, NUM_PASSES, OPT_BYPASS, OPT_PRED_TERM, OPT_RESET_MQ, OPT_SEG_SYMBOLS, OPT_TERM_PASS, OPT_VERT_STR_CAUSAL, STRIPE_HEIGHT -
Constructor Summary
ConstructorsConstructorDescriptionHeaderDecoder(RandomAccessIO ehs, J2KImageReadParamJava j2krparam, HeaderInfo hi) Creates a HeaderDecoder instance and read in two passes the main header of the codestream. -
Method Summary
Modifier and TypeMethodDescriptionvoidcheckMarkerLength(DataInputStream ehs, String str) Checks that the marker segment length is correct.final DequantizercreateDequantizer(CBlkQuantDataSrcDec src, int[] rb, DecoderSpecs decSpec2) Returns the dequantizer parameters.createEntropyDecoder(CodedCBlkDataSrcDec src, J2KImageReadParamJava j2krparam) 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.createROIDeScaler(CBlkQuantDataSrcDec src, J2KImageReadParamJava j2krparam, DecoderSpecs decSpec2) Creates and returns the ROIDeScaler corresponding to the information read from the codestream header and with the special additional parameters from the parameter list.voidextractTilePartMarkSeg(short marker, RandomAccessIO ehs, int tileIdx, int tilePartIdx) This method extracts a marker segment in a tile-part header and stores it into a byte buffer for the second pass.final intgetCbULX()Returns the horizontal code-block partition origin.Allowable values are 0 and 1, nothing else.final intgetCbULY()Returns the vertical code-block partition origin.final intgetCompSubsX(int c) Returns the component sub-sampling factor, with respect to the reference grid, along the horizontal direction for the specified component.final intgetCompSubsY(int c) Returns the component sub-sampling factor, with respect to the reference grid, along the vertical direction for the specified component.Return the DecoderSpecs instance filled when reading the headersfinal intReturns the image height in the reference grid.final intReturn the horizontal upper-left coordinate of the image in the reference grid.final intReturn the vertical upper-left coordinate of the image in the reference grid.final intReturns the image width in the reference grid.intReturn the maximum height among all componentsintReturn the maximum width among all componentsfinal intReturns the nominal width of the tiles in the reference grid.final intReturns the nominal width of the tiles in the reference grid.final intReturns the number of components in the image.intReturns the number of found marker segments in the current header.intReturn the number of tiles in the imagefinal intgetOriginalBitDepth(int c) Returns the original bitdepth of the specified component.getPackedPktHead(int tile) Return the packed packet headers for a given tile.static String[][]Returns the parameters that are used in this class.final intgetPPX(int t, int c, int rl) Returns the precinct partition width for the specified tile-component and resolution level.final intgetPPY(int t, int c, int rl) Returns the precinct partition height for the specified component, tile and resolution level.final PointgetTilingOrigin(Point co) Returns the tiling origin, referred to as '(Px,Py)' in the 'ImgData' interface.final booleanisOriginalSigned(int c) Returns true if the original data of the specified component was signed.final booleanReturns the boolean used to know if the precinct partition is usedvoidreadFoundTilePartMarkSeg(int tileIdx, int tpIdx) Return the DecoderSpecs instance filled when reading the headers Retrieves and reads all marker segments previously found in the tile-part header.voidMethod that resets members indicating which markers have already been foundvoidsetTileOfTileParts(int tile) Sets the tile of each tile part in order.toString()Print information about the current header.
-
Field Details
-
OPT_PREFIX
public static final char OPT_PREFIXThe prefix for header decoder options: 'H'- See Also:
-
nTileParts
public int[] nTilePartsThe number of tile parts per tile -
SOD_FOUND
public static final int SOD_FOUNDFlag bit for SOD marker segment found- See Also:
-
PPM_FOUND
public static final int PPM_FOUNDFlag bit for SOD marker segment found- See Also:
-
PPT_FOUND
public static final int PPT_FOUNDFlag bit for SOD marker segment found- See Also:
-
CRG_FOUND
public static final int CRG_FOUNDFlag bit for CRG marker segment found- See Also:
-
mainHeadOff
public int mainHeadOffThe offset of the main header in the input stream -
tileOfTileParts
Vector containing info as to which tile each tilepart belong
-
-
Constructor Details
-
HeaderDecoder
public HeaderDecoder(RandomAccessIO ehs, J2KImageReadParamJava j2krparam, HeaderInfo hi) throws 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:
ehs- The encoded header stream where marker segment are extracted.j2krparam- The parameter list of the decoderhi- The HeaderInfo holding information found in marker segments- Throws:
IOException- If an I/O error occurs while reading from the encoded header stream.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 Details
-
getMaxCompImgHeight
public int getMaxCompImgHeight()Return the maximum height among all components- Returns:
- Maximum component height
-
getMaxCompImgWidth
public int getMaxCompImgWidth()Return the maximum width among all components- Returns:
- Maximum component width
-
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 upper-left coordinate of the image in the reference grid.- Returns:
- The horizontal coordinate of the image origin.
-
getImgULY
public final int getImgULY()Return the vertical upper-left coordinate of the image 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
Returns the tiling origin, referred 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:
-
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 sub-sampling 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 sub-sampling factor X-wise.
-
getCompSubsY
public final int getCompSubsY(int c) Returns the component sub-sampling 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 sub-sampling factor Y-wise.
-
createDequantizer
public final Dequantizer createDequantizer(CBlkQuantDataSrcDec src, int[] rb, DecoderSpecs decSpec2) Returns the dequantizer parameters. Dequantizer parameters normally are the quantization step sizes, see DequantizerParams.- Parameters:
src- The source of data for the dequantizer.rb- The number of range bits for each component. Must be the number of range bits of the mixed components.decSpec2- The DecoderSpecs instance after any image manipulation.- Returns:
- The dequantizer
-
getCbULX
public final int getCbULX()Returns the horizontal code-block partition origin.Allowable values are 0 and 1, nothing else. -
getCbULY
public final int getCbULY()Returns the vertical code-block partition origin. Allowable values are 0 and 1, nothing else. -
getPPX
public final int getPPX(int t, int c, int rl) Returns the precinct partition width for the specified tile-component and resolution level.- Parameters:
c- the component indext- the tile indexrl- the resolution level- Returns:
- The precinct partition width for the specified tile-component 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 componentt- the tile indexrl- 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
Checks that the marker segment length is correct.- Parameters:
ehs- The encoded header streamstr- The string identifying the marker, such as "SIZ marker"- Throws:
IOException- If an I/O error occurs
-
extractTilePartMarkSeg
public void extractTilePartMarkSeg(short marker, RandomAccessIO ehs, int tileIdx, int tilePartIdx) throws IOException 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.- Parameters:
marker- The marker to processehs- The encoded header streamtileIdx- The index of the current tiletilePartIdx- The index of the current tile part- Throws:
IOException
-
readFoundTilePartMarkSeg
Return the DecoderSpecs instance filled when reading the headers Retrieves and reads all marker segments previously found in the tile-part header.- Parameters:
tileIdx- The index of the current tiletpIdx- Index of the current tile-part- Throws:
IOException
-
getDecoderSpecs
Return the DecoderSpecs instance filled when reading the headers- Returns:
- The DecoderSpecs of the decoder
-
createEntropyDecoder
public EntropyDecoder createEntropyDecoder(CodedCBlkDataSrcDec src, J2KImageReadParamJava j2krparam) 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.- Parameters:
src- The bit stream reader agent where to get code-block data from.j2krparam- The parameter list containing parameters applicable to the entropy decoder (other parameters can also be present).- Returns:
- The entropy decoder
-
createROIDeScaler
public ROIDeScaler createROIDeScaler(CBlkQuantDataSrcDec src, J2KImageReadParamJava j2krparam, DecoderSpecs decSpec2) Creates and returns the ROIDeScaler corresponding to the information read from the codestream header and with the special additional parameters from the parameter list.- Parameters:
src- The bit stream reader agent where to get code-block data from.j2krparam- The parameters applicable to the entropy decoder.- Returns:
- The ROI descaler
-
resetHeaderMarkers
public void resetHeaderMarkers()Method that resets members indicating which markers have already been found -
toString
Print information about the current header. -
getParameterInfo
Returns the parameters that are used in this class. 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.- Returns:
- the options name, their synopsis and their explanation.
-
getNumTiles
public int getNumTiles()Return the number of tiles in the image- Returns:
- The number of tiles
-
getPackedPktHead
Return the packed packet headers for a given tile.- Returns:
- An input stream containing the packed packet headers for a particular tile
- Throws:
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.
-
getNumFoundMarkSeg
public int getNumFoundMarkSeg()Returns the number of found marker segments in the current header.- Returns:
- The number of marker segments found in the current header.
-