jj2000.j2k.codestream.reader
Class HeaderDecoder

java.lang.Object
  |
  +--jj2000.j2k.codestream.reader.HeaderDecoder

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 FileBitstreamReaderAgent 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, Decoder, FileBitstreamReaderAgent

Field Summary
private  int cdstrmCap
          Denotes the capabilities of the codestream (e.g., error-resilience, ROI, etc.), as found in the SIZ tag.
private static int COC_FOUND
          Flag bit for COC marker segment found
private static int COD_FOUND
          Flag bit for COD marker segment found
private static int COM_FOUND
          Flag bit for COM marker segment found
private  int[] compSubsX
          Downsampling factors along X-axis for each component of the image
private  int[] compSubsY
          Downsampling factors along Y-axis for each component of the image
static int CRG_FOUND
          Flag bit for CRG marker segment found
private  DecoderSpecs decSpec
          The decoder specifications
private  java.lang.String hdStr
          Current header information in a string
private  java.util.Hashtable ht
          HashTable used to store marker segment byte buffers
private  int imgH
          The image height, in the reference grid
private  int imgOrigX
          The horizontal image origin, with respect to the canvas origin, in the reference grid
private  int imgOrigY
          The vertical image origin, with respect to the canvas origin, in the reference grid
private  int imgW
          The image width, in the reference grid
 int initPos
          The starting position of the codestream in the file
private  boolean[] isOrigSigned
          If the data was originally signed, for each component
private  int[] lastTilePartRead
          The last tile part that was read for each tile
(package private)  int markersFound
          Used to store which markers have been already read, by using flag bits.
private  int[] maxBoost
          The boost value used if maxshift was used
private  int nCOCmarker
          Counts number of COC markers found in the header
private  int nCOMmarker
          Counts number of COM markers found in the header
private  int nComp
          The number of components in the image
private  int nPPMmarker
          Counts number of PPM markers found in the header
private  int[] nPPTmarker
          Counts number of PPT markers found in the header
private  int nQCCmarker
          Counts number of QCC markers found in the header
private  int nReadPPMmarker
          Number of read PPT markers found in the header
private  int[] nReadPPTmarker
          Number of read PPT markers found in the header
private  int nRGNmarker
          Counts number of RGN markers found in the header
 int[] nTileParts
          The number of tile parts per tile
private  int nTiles
          The number of tiles within the image
static char OPT_PREFIX
          The prefix for header decoder options: 'H'
private  int[] origBitDepth
          The bit-depth (i.e.
private  int partOrigX
          The horizontal code-block and cell partitioning origin, with respect to the canvas origin.
private  int partOrigY
          The vertical code-block and cell partitioning origin, with respect to the canvas origin.
private static java.lang.String[][] pinfo
          The list of parameters that is accepted for quantization.
private  java.io.ByteArrayOutputStream[] pkdPktHeaders
          The packed packet headers if the PPM or PPT markers are used
private  ParameterList pl
          The ParameterList instance of the decoder
private static int PLM_FOUND
          Flag bit for PLM marker segment found
private static int PLT_FOUND
          Flag bit for PLT marker segment found
private static int POC_FOUND
          Flag bit for POC marker segment found
static int PPM_FOUND
          Flag bit for SOD marker segment found
static int PPT_FOUND
          Flag bit for SOD marker segment found
(package private)  boolean precinctPartitionIsUsed
          Is the precinct partition used
private  boolean printHeader
          Whether to display header information
private  boolean printInfo
          Whether to print 'INFO' type info
private static int QCC_FOUND
          Flag bit for QCC marker segment found
private static int QCD_FOUND
          Flag bit for QCD marker segment found
private  byte[] readIPPMData
          The last non-finished Ippm field read
private  int remPPMData
          The remaining Ippm data to read
private static int RGN_FOUND
          Flag bit for RGN marker segment found
private static int SIZ_FOUND
          Flag bit for SIZ marker segment found
static int SOD_FOUND
          Flag bit for SOD marker segment found
private static int SOT_FOUND
          Flag bit for SOT marker segment found
private  int thlen
          The total header length, including SOC marker segment, header length number, and encoded header length
private static int TILE_RESET
          The reset mask for new tiles
private  int tileH
          The nominal tile width, in thr reference grid
 java.util.Vector tileOfTileParts
          Vector containing info as to which tile each tilepart belong
private  java.util.Vector[] tilePartPktHeadLen
          The length of the packed packet headers for each tile part
private  int tileW
          The nominal tile width, in the reference grid
private  int tilingOrigX
          The horizontal tiling origin, with respect to the canvas origin, in the reference grid
private  int tilingOrigY
          The vertical tiling origin, with respect to the canvas origin, in the reference grid
private static int TLM_FOUND
          Flag bit for TLM marker segment found
private  java.util.Vector unsortedPkdPktHeaders
          The packed packet headers if the PPM markers are used
 
Fields 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_PROG
 
Fields inherited from interface jj2000.j2k.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 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_ER_TERM, OPT_REG_TERM, OPT_RESET_MQ, OPT_SEG_MARKERS, OPT_VERT_STR_CAUSAL, STRIPE_HEIGHT
 
Constructor Summary
HeaderDecoder(RandomAccessIO ehs, boolean info, ParameterList pl)
          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.
 Dequantizer createDequantizer(CBlkQuantDataSrcDec src, int[] rb)
          Returns the dequantizer parameters.
 EntropyDecoder createEntropyDecoder(BitstreamReaderAgent src, ParameterList pl)
          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.
 ROIDeScaler createROIDeScaler(CBlkQuantDataSrcDec src, ParameterList pl)
          Creates and returns the ROIDeScaler corresponding to the information read from the codestream header and with the special additional parameters from the parameter list.
private  void extractMainMarkSeg(short marker, RandomAccessIO ehs)
          This method extract a marker segment in main header and stores it into a byte buffer for the second pass.
 void extractTilePartMarkSeg(short marker, RandomAccessIO 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
 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
static java.lang.String[][] getParameterInfo()
          Returns the parameters that are used in this class.
 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
private  void readCOC(java.io.DataInputStream ehs, boolean mainh, int tileIdx)
          Reads the COC marker segment and realigns the codestream where the next marker should be found.
private  void readCOD(java.io.DataInputStream ehs, boolean mainh, int tileIdx)
          Reads COD marker segment and realigns the codestream where the next marker should be found.
private  void readCOM(java.io.DataInputStream ehs)
          Reads COM marker segments and realign the bistream at the point where the next marker should be found.
private  void readCRG(java.io.DataInputStream ehs)
          Reads the CRG marker segment and check segment length
private  SynWTFilter readFilter(java.io.DataInputStream ehs)
          Reads a wavelet filter from the codestream and returns the filter object that implements it.
private  void readFoundMainMarkSeg()
          Retrieve and read all marker segments previously found in the main header.
 void readFoundTilePartMarkSeg(int tileIdx)
          Retrieve and read all marker segment previously found in the tile header.
private  void readPLM(java.io.DataInputStream ehs)
          Reads PLM marker segment and realigns the codestream where the next marker should be found.
private  void readPLTFields(java.io.DataInputStream ehs)
          Reads the PLT fields and realigns the codestream where the next marker should be found.
private  void readPOC(java.io.DataInputStream ehs, boolean mainh, int t)
          Reads the POC marker segment and realigns the codestream where the next marker should be found.
private  void readPPM(java.io.DataInputStream ehs)
          Reads the PPM marker segment of the main header.
private  void readPPT(java.io.DataInputStream ehs, int tile)
          Reads the PPT marker segment of the main header.
private  void readQCC(java.io.DataInputStream ehs, boolean mainh, int tileIdx)
          Reads QCC marker segment and realigns the codestream at the point where the next marker should be found.
private  void readQCD(java.io.DataInputStream ehs, boolean mainh, int tileIdx)
          Reads QCD marker segment and realigns the codestream at the point where the next marker should be found.
private  void readRGN(java.io.DataInputStream ehs, boolean mainh, int tileIdx)
          Reads the RGN marker segment of the codestream header.
private  void readSIZ(java.io.DataInputStream ehs)
          Read SIZ marker segment, and realign the codestream at the point where the next marker should be found.
private  void readTLM(java.io.DataInputStream ehs)
          Reads TLM marker segment and realigns the codestream where the next marker should be found.
 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, registerNatives, wait, wait, wait
 

Field Detail

OPT_PREFIX

public static final char OPT_PREFIX
The prefix for header decoder options: 'H'

pinfo

private static final java.lang.String[][] pinfo
The list of parameters that is accepted for quantization. Options for quantization start with 'Q'.

printHeader

private boolean printHeader
Whether to display header information

hdStr

private java.lang.String hdStr
Current header information in a string

printInfo

private boolean printInfo
Whether to print 'INFO' type info

pl

private ParameterList pl
The ParameterList instance of the decoder

nTiles

private int nTiles
The number of tiles within the image

nTileParts

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

markersFound

int markersFound
Used to store which markers have been already read, by using flag bits. The different markers are marked with XXX_FOUND flags, such as SIZ_FOUND

nCOCmarker

private int nCOCmarker
Counts number of COC markers found in the header

nQCCmarker

private int nQCCmarker
Counts number of QCC markers found in the header

nCOMmarker

private int nCOMmarker
Counts number of COM markers found in the header

nRGNmarker

private int nRGNmarker
Counts number of RGN markers found in the header

nPPMmarker

private int nPPMmarker
Counts number of PPM markers found in the header

nPPTmarker

private int[] nPPTmarker
Counts number of PPT markers found in the header

nReadPPMmarker

private int nReadPPMmarker
Number of read PPT markers found in the header

nReadPPTmarker

private int[] nReadPPTmarker
Number of read PPT markers found in the header

SIZ_FOUND

private static final int SIZ_FOUND
Flag bit for SIZ marker segment found

COD_FOUND

private static final int COD_FOUND
Flag bit for COD marker segment found

COC_FOUND

private static final int COC_FOUND
Flag bit for COC marker segment found

QCD_FOUND

private static final int QCD_FOUND
Flag bit for QCD marker segment found

TLM_FOUND

private static final int TLM_FOUND
Flag bit for TLM marker segment found

PLM_FOUND

private static final int PLM_FOUND
Flag bit for PLM marker segment found

SOT_FOUND

private static final int SOT_FOUND
Flag bit for SOT marker segment found

PLT_FOUND

private static final int PLT_FOUND
Flag bit for PLT marker segment found

QCC_FOUND

private static final int QCC_FOUND
Flag bit for QCC marker segment found

RGN_FOUND

private static final int RGN_FOUND
Flag bit for RGN marker segment found

POC_FOUND

private static final int POC_FOUND
Flag bit for POC marker segment found

COM_FOUND

private static final int COM_FOUND
Flag bit for COM marker segment found

SOD_FOUND

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

PPM_FOUND

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

PPT_FOUND

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

CRG_FOUND

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

TILE_RESET

private static final int TILE_RESET
The reset mask for new tiles

ht

private java.util.Hashtable ht
HashTable used to store marker segment byte buffers

thlen

private int thlen
The total header length, including SOC marker segment, header length number, and encoded header length

cdstrmCap

private int cdstrmCap
Denotes the capabilities of the codestream (e.g., error-resilience, ROI, etc.), as found in the SIZ tag. The values are defined in Markers.

imgW

private int imgW
The image width, in the reference grid

imgH

private int imgH
The image height, in the reference grid

imgOrigX

private int imgOrigX
The horizontal image origin, with respect to the canvas origin, in the reference grid

imgOrigY

private int imgOrigY
The vertical image origin, with respect to the canvas origin, in the reference grid

tileW

private int tileW
The nominal tile width, in the reference grid

tileH

private int tileH
The nominal tile width, in thr reference grid

tilingOrigX

private int tilingOrigX
The horizontal tiling origin, with respect to the canvas origin, in the reference grid

tilingOrigY

private int tilingOrigY
The vertical tiling origin, with respect to the canvas origin, in the reference grid

nComp

private int nComp
The number of components in the image

compSubsX

private int[] compSubsX
Downsampling factors along X-axis for each component of the image

compSubsY

private int[] compSubsY
Downsampling factors along Y-axis for each component of the image

origBitDepth

private int[] origBitDepth
The bit-depth (i.e. precision) for each component, before the multiple component transform.

isOrigSigned

private boolean[] isOrigSigned
If the data was originally signed, for each component

partOrigX

private int partOrigX
The horizontal code-block and cell partitioning origin, with respect to the canvas origin.

partOrigY

private int partOrigY
The vertical code-block and cell partitioning origin, with respect to the canvas origin.

decSpec

private DecoderSpecs decSpec
The decoder specifications

maxBoost

private int[] maxBoost
The boost value used if maxshift was used

precinctPartitionIsUsed

boolean precinctPartitionIsUsed
Is the precinct partition used

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

unsortedPkdPktHeaders

private java.util.Vector unsortedPkdPktHeaders
The packed packet headers if the PPM markers are used

pkdPktHeaders

private java.io.ByteArrayOutputStream[] pkdPktHeaders
The packed packet headers if the PPM or PPT markers are used

remPPMData

private int remPPMData
The remaining Ippm data to read

readIPPMData

private byte[] readIPPMData
The last non-finished Ippm field read

tilePartPktHeadLen

private java.util.Vector[] tilePartPktHeadLen
The length of the packed packet headers for each tile part

lastTilePartRead

private int[] lastTilePartRead
The last tile part that was read for each tile
Constructor Detail

HeaderDecoder

public HeaderDecoder(RandomAccessIO ehs,
                     boolean info,
                     ParameterList pl)
              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:
ehs - The encoded header stream where marker segment are extracted.
info - If to print 'INFO' type information (warnings are always written) to the message logging facility.
pl - The parameter list of the decoder
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.

createDequantizer

public final Dequantizer createDequantizer(CBlkQuantDataSrcDec src,
                                           int[] rb)
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.
Returns:
The dequantizer

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

readFilter

private SynWTFilter readFilter(java.io.DataInputStream ehs)
                        throws java.io.IOException
Reads a wavelet filter from the codestream and returns the filter object that implements it.
Parameters:
ehs - The encoded header stream from where to read the info

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
spos - The marker start position in 'ehs'
mlen - The marker length, as written in the codestream
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

readSIZ

private void readSIZ(java.io.DataInputStream ehs)
              throws java.io.IOException
Read SIZ marker segment, and realign the codestream at the point where the next marker should be found. It is a fixed information marker segment containing informations about image and tile sizes. It is required in the main header immediately after SOC marker segment.
Parameters:
ehs - The encoded header stream
Throws:
java.io.IOException - If an I/O error occurs while reading from the encoded header stream

readCRG

private void readCRG(java.io.DataInputStream ehs)
              throws java.io.IOException
Reads the CRG marker segment and check segment length

readCOM

private void readCOM(java.io.DataInputStream ehs)
              throws java.io.IOException
Reads COM marker segments and realign the bistream at the point where the next marker should be found.
Parameters:
ehs - The encoded header stream
Throws:
java.io.IOException - If an I/O error occurs while reading from the encoded header stream

readQCD

private void readQCD(java.io.DataInputStream ehs,
                     boolean mainh,
                     int tileIdx)
              throws java.io.IOException
Reads QCD marker segment and realigns the codestream at the point where the next marker should be found.
Parameters:
ehs - The encoded stream.
mainh - Flag indicating whether or not the main header is read
tileIdx - The index of the current tile
Throws:
java.io.IOException - If an I/O error occurs while reading from the encoded header stream.

readQCC

private void readQCC(java.io.DataInputStream ehs,
                     boolean mainh,
                     int tileIdx)
              throws java.io.IOException
Reads QCC marker segment and realigns the codestream at the point where the next marker should be found.
Parameters:
ehs - The encoded stream.
mainh - Flag indicating whether or not the main header is read
tileIdx - The index of the current tile
Throws:
java.io.IOException - If an I/O error occurs while reading from the encoded header stream.

readCOD

private void readCOD(java.io.DataInputStream ehs,
                     boolean mainh,
                     int tileIdx)
              throws java.io.IOException
Reads COD marker segment and realigns the codestream where the next marker should be found.
Parameters:
ehs - The encoder header stream.
tileh - Flag indicating whether the main header is read
tileIdx - The index of the current tile
Throws:
java.io.IOException - If an I/O error occurs while reading from the encoder header stream

readCOC

private void readCOC(java.io.DataInputStream ehs,
                     boolean mainh,
                     int tileIdx)
              throws java.io.IOException
Reads the COC marker segment and realigns the codestream where the next marker should be found.
Parameters:
ehs - The encoder header stream.
mainh - Flag indicating whether or not the main header is read
tileIdx - The index of the current tile
Throws:
java.io.IOException - If an I/O error occurs while reading from the encoder header stream

readPOC

private void readPOC(java.io.DataInputStream ehs,
                     boolean mainh,
                     int t)
              throws java.io.IOException
Reads the POC marker segment and realigns the codestream where the next marker should be found.
Parameters:
ehs - The encoder header stream.
mainh - Flag indicating whether or not the main header is read
t - The index of the current tile
Throws:
java.io.IOException - If an I/O error occurs while reading from the encoder header stream

readTLM

private void readTLM(java.io.DataInputStream ehs)
              throws java.io.IOException
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.
Parameters:
ehs - The encoder header stream.
Throws:
java.io.IOException - If an I/O error occurs while reading from the encoder header stream

readPLM

private void readPLM(java.io.DataInputStream ehs)
              throws java.io.IOException
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.
Parameters:
ehs - The encoder header stream.
Throws:
java.io.IOException - If an I/O error occurs while reading from the encoder header stream

readPLTFields

private void readPLTFields(java.io.DataInputStream ehs)
                    throws java.io.IOException
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.
Parameters:
ehs - The encoder header stream.
Throws:
java.io.IOException - If an I/O error occurs while reading from the encoder header stream

readRGN

private void readRGN(java.io.DataInputStream ehs,
                     boolean mainh,
                     int tileIdx)
              throws java.io.IOException
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.

Parameters:
ehs - The encoder header stream.
mainh - Flag indicating whether or not the main header is read
tileIdx - The index of the current tile
Throws:
java.io.IOException - If an I/O error occurs while reading from the encoder header stream

readPPM

private void readPPM(java.io.DataInputStream ehs)
              throws java.io.IOException
Reads the PPM marker segment of the main header.
Parameters:
ehs - The encoder header stream.
Throws:
java.io.IOException - If an I/O error occurs while reading from the encoder header stream

readPPT

private void readPPT(java.io.DataInputStream ehs,
                     int tile)
              throws java.io.IOException
Reads the PPT marker segment of the main header.
Parameters:
ehs - The encoder header stream.
tile - The tile to which the current tile part belongs
Throws:
java.io.IOException - If an I/O error occurs while reading from the encoder header stream

extractMainMarkSeg

private void extractMainMarkSeg(short marker,
                                RandomAccessIO ehs)
                         throws java.io.IOException
This method extract a marker segment in main header and stores it into a byte buffer for the second pass. The marker segment 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. SIZ marker segment shall be the first encountered marker segment.
Parameters:
marker - The marker to process
ehs - The encoded header stream

extractTilePartMarkSeg

public void extractTilePartMarkSeg(short marker,
                                   RandomAccessIO 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

readFoundMainMarkSeg

private void readFoundMainMarkSeg()
                           throws java.io.IOException
Retrieve and read all marker segments previously found in the main header.

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

getDecoderSpecs

public DecoderSpecs getDecoderSpecs()
Return the DecoderSpecs instance filled when reading the headers
Returns:
The DecoderSpecs of the decoder

createEntropyDecoder

public EntropyDecoder createEntropyDecoder(BitstreamReaderAgent src,
                                           ParameterList pl)
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.
pl - 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,
                                     ParameterList pl)
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.
pl - The parameter list containing parameters applicable to the entropy decoder (other parameters can also be present).
Returns:
The ROI descaler

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

getParameterInfo

public static java.lang.String[][] 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

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