/// <p>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:
///
/// <ol>
/// <li>All marker segments are buffered and their corresponding flag is
/// activated (extractMainMarkSeg and extractTilePartMarkSeg methods).</li>
///
/// <li>Buffered marker segment are analyzed in a logical way and
/// specifications are stored in appropriate member of DecoderSpecs instance
/// (readFoundMainMarkSeg and readFoundTilePartMarkSeg methods).</li>
/// </ol></p>
///
/// <p>Whenever a marker segment is not recognized a warning message is
/// displayed and its length parameter is used to skip it.</p>
///
/// <p>The information found in this header is stored in HeaderInfo and
/// DecoderSpecs instances.</p>
///
/// </summary>
/// <seealso cref="DecoderSpecs">
/// </seealso>
/// <seealso cref="HeaderInfo">
/// </seealso>
/// <seealso cref="Decoder">
/// </seealso>
/// <seealso cref="FileBitstreamReaderAgent">
///
/// </seealso>
publicclassHeaderDecoder
{
/// <summary> Return the maximum height among all components
///
/// </summary>
/// <returns> Maximum component height
///
/// </returns>
virtualpublicintMaxCompImgHeight
{
get
{
returnhi.sizValue.MaxCompHeight;
}
}
/// <summary> Return the maximum width among all components
///
/// </summary>
/// <returns> Maximum component width
///
/// </returns>
virtualpublicintMaxCompImgWidth
{
get
{
returnhi.sizValue.MaxCompWidth;
}
}
/// <summary> Returns the image width in the reference grid.
///
/// </summary>
/// <returns> The image width in the reference grid
///
/// </returns>
virtualpublicintImgWidth
{
get
{
returnhi.sizValue.xsiz-hi.sizValue.x0siz;
}
}
/// <summary> Returns the image height in the reference grid.
///
/// </summary>
/// <returns> The image height in the reference grid
///
/// </returns>
virtualpublicintImgHeight
{
get
{
returnhi.sizValue.ysiz-hi.sizValue.y0siz;
}
}
/// <summary> Return the horizontal upper-left coordinate of the image in the
/// reference grid.
///
/// </summary>
/// <returns> The horizontal coordinate of the image origin.
///
/// </returns>
virtualpublicintImgULX
{
get
{
returnhi.sizValue.x0siz;
}
}
/// <summary> Return the vertical upper-left coordinate of the image in the reference
/// grid.
///
/// </summary>
/// <returns> The vertical coordinate of the image origin.
///
/// </returns>
virtualpublicintImgULY
{
get
{
returnhi.sizValue.y0siz;
}
}
/// <summary> Returns the nominal width of the tiles in the reference grid.
///
/// </summary>
/// <returns> The nominal tile width, in the reference grid.
///
/// </returns>
virtualpublicintNomTileWidth
{
get
{
returnhi.sizValue.xtsiz;
}
}
/// <summary> Returns the nominal width of the tiles in the reference grid.
///
/// </summary>
/// <returns> The nominal tile width, in the reference grid.
///
/// </returns>
virtualpublicintNomTileHeight
{
get
{
returnhi.sizValue.ytsiz;
}
}
/// <summary> Returns the number of components in the image.
///
/// </summary>
/// <returns> The number of components in the image.
///
/// </returns>
virtualpublicintNumComps
{
get
{
returnnComp;
}
}
/// <summary> Returns the horizontal code-block partition origin.Allowable values are
/// 0 and 1, nothing else.
///
/// </summary>
virtualpublicintCbULX
{
get
{
returncb0x;
}
}
/// <summary> Returns the vertical code-block partition origin. Allowable values are
/// 0 and 1, nothing else.
///
/// </summary>
virtualpublicintCbULY
{
get
{
returncb0y;
}
}
/// <summary> Return the DecoderSpecs instance filled when reading the headers
///
/// </summary>
/// <returns> The DecoderSpecs of the decoder
///
/// </returns>
virtualpublicDecoderSpecsDecoderSpecs
{
get
{
returndecSpec;
}
}
/// <summary> 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.
///
/// </summary>
/// <returns> the options name, their synopsis and their explanation.
///
/// </returns>
publicstaticSystem.String[][]ParameterInfo
{
get
{
returnpinfo;
}
}
/// <summary> Return the number of tiles in the image
///
/// </summary>
/// <returns> The number of tiles
///
/// </returns>
virtualpublicintNumTiles
{
get
{
returnnTiles;
}
}
/// <summary> 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.
///
/// </summary>
/// <param name="tile">The tile number that the present tile part belongs to.
///
/// </param>
virtualpublicintTileOfTileParts
{
set
{
if(nPPMMarkSeg!=0)
{
tileOfTileParts.Add((System.Int32)value);
}
}
}
/// <summary> Returns the number of found marker segments in the current header.
///
/// </summary>
/// <returns> The number of marker segments found in the current header.
///
/// </returns>
virtualpublicintNumFoundMarkSeg
{
get
{
returnnfMarkSeg;
}
}
/// <summary>The prefix for header decoder options: 'H' </summary>
publicconstcharOPT_PREFIX='H';
/// <summary>The list of parameters that is accepted for quantization. Options
/// for quantization start with 'Q'.
/// </summary>
//UPGRADE_NOTE: Final was removed from the declaration of 'pinfo'. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
privatestaticreadonlySystem.String[][]pinfo=null;
/// <summary>The reference to the HeaderInfo instance holding the information found
/// in headers
/// </summary>
privateHeaderInfohi;
/// <summary>Whether or not to display general information </summary>
//private bool verbose;
/// <summary>Current header information in a string </summary>
privateSystem.StringhdStr="";
/// <summary>The number of tiles within the image </summary>
privateintnTiles;
/// <summary>The number of tile parts in each tile </summary>
publicint[]nTileParts;
/// <summary>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
/// </summary>
privateintnfMarkSeg=0;
/// <summary>Counts number of COC markers found in the header </summary>
privateintnCOCMarkSeg=0;
/// <summary>Counts number of QCC markers found in the header </summary>
privateintnQCCMarkSeg=0;
/// <summary>Counts number of COM markers found in the header </summary>
privateintnCOMMarkSeg=0;
/// <summary>Counts number of RGN markers found in the header </summary>
privateintnRGNMarkSeg=0;
/// <summary>Counts number of PPM markers found in the header </summary>
privateintnPPMMarkSeg=0;
/// <summary>Counts number of PPT markers found in the header </summary>
privateint[][]nPPTMarkSeg=null;
/// <summary>Flag bit for SIZ marker segment found </summary>
privateconstintSIZ_FOUND=1;
/// <summary>Flag bit for COD marker segment found </summary>
privateconstintCOD_FOUND=1<<1;
/// <summary>Flag bit for COC marker segment found </summary>
privateconstintCOC_FOUND=1<<2;
/// <summary>Flag bit for QCD marker segment found </summary>
privateconstintQCD_FOUND=1<<3;
/// <summary>Flag bit for TLM marker segment found </summary>
privateconstintTLM_FOUND=1<<4;
/// <summary>Flag bit for PLM marker segment found </summary>
privateconstintPLM_FOUND=1<<5;
/// <summary>Flag bit for SOT marker segment found </summary>
privateconstintSOT_FOUND=1<<6;
/// <summary>Flag bit for PLT marker segment found </summary>
privateconstintPLT_FOUND=1<<7;
/// <summary>Flag bit for QCC marker segment found </summary>
privateconstintQCC_FOUND=1<<8;
/// <summary>Flag bit for RGN marker segment found </summary>
privateconstintRGN_FOUND=1<<9;
/// <summary>Flag bit for POC marker segment found </summary>
privateconstintPOC_FOUND=1<<10;
/// <summary>Flag bit for COM marker segment found </summary>
privateconstintCOM_FOUND=1<<11;
/// <summary>Flag bit for SOD marker segment found </summary>
publicconstintSOD_FOUND=1<<13;
/// <summary>Flag bit for SOD marker segment found </summary>
publicconstintPPM_FOUND=1<<14;
/// <summary>Flag bit for SOD marker segment found </summary>
publicconstintPPT_FOUND=1<<15;
/// <summary>Flag bit for CRG marker segment found </summary>
publicconstintCRG_FOUND=1<<16;
/// <summary>The reset mask for new tiles </summary>
//UPGRADE_NOTE: Final was removed from the declaration of 'TILE_RESET '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
/// <summary> Returns the precinct partition width for the specified tile-component
/// and resolution level.
///
/// </summary>
/// <param name="c">the component index
///
/// </param>
/// <param name="t">the tile index
///
/// </param>
/// <param name="rl">the resolution level
///
/// </param>
/// <returns> The precinct partition width for the specified tile-component
/// and resolution level
///
/// </returns>
publicintgetPPX(intt,intc,intrl)
{
returndecSpec.pss.getPPX(t,c,rl);
}
/// <summary> Returns the precinct partition height for the specified tile-component
/// and resolution level.
///
/// </summary>
/// <param name="c">the component index
///
/// </param>
/// <param name="t">the tile index
///
/// </param>
/// <param name="rl">the resolution level
///
/// </param>
/// <returns> The precinct partition height for the specified tile-component
/// and resolution level
///
/// </returns>
publicintgetPPY(intt,intc,intrl)
{
returndecSpec.pss.getPPY(t,c,rl);
}
/// <summary> Returns the boolean used to know if the precinct partition is used
///
/// </summary>
publicboolprecinctPartitionUsed()
{
returnprecinctPartitionIsUsed;
}
/// <summary> Reads a wavelet filter from the codestream and returns the filter
/// object that implements it.
///
/// </summary>
/// <param name="ehs">The encoded header stream from where to read the info
///
/// </param>
/// <param name="filtIdx">Int array of one element to return the type of the
/// wavelet filter.
///
/// </param>
//UPGRADE_TODO: Class 'java.io.DataInputStream' was converted to 'System.IO.BinaryReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataInputStream'"
thrownewNotImplementedError("Custom filters not supported");
}
// Return filter based on ID
switch(kid)
{
caseCSJ2K.j2k.wavelet.FilterTypes_Fields.W9X7:
returnnewSynWTFilterFloatLift9x7();
caseCSJ2K.j2k.wavelet.FilterTypes_Fields.W5X3:
returnnewSynWTFilterIntLift5x3();
default:
thrownewCorruptedCodestreamException("Specified wavelet filter "+"not"+" JPEG 2000 part I "+"compliant");
}
}
/// <summary> Checks that the marker segment length is correct.
///
/// </summary>
/// <param name="ehs">The encoded header stream
///
/// </param>
/// <param name="str">The string identifying the marker, such as "SIZ marker"
///
/// </param>
/// <exception cref="IOException">If an I/O error occurs
///
/// </exception>
//UPGRADE_TODO: Class 'java.io.DataInputStream' was converted to 'System.IO.BinaryReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataInputStream'"
FacilityManager.getMsgLogger().printmsg(CSJ2K.j2k.util.MsgLogger_Fields.WARNING,str+" length was short, attempting to resync.");
}
}
/// <summary> Reads the SIZ marker segment and realigns the codestream at the point
/// where the next marker segment should be found.
///
/// <p>SIZ is a fixed information marker segment containing informations
/// about image and tile sizes. It is required in the main header
/// immediately after SOC.</p>
///
/// </summary>
/// <param name="ehs">The encoded header stream
///
/// </param>
/// <exception cref="IOException">If an I/O error occurs while reading from the
/// encoded header stream
///
/// </exception>
//UPGRADE_TODO: Class 'java.io.DataInputStream' was converted to 'System.IO.BinaryReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataInputStream'"
privatevoidreadSIZ(System.IO.BinaryReaderehs)
{
HeaderInfo.SIZms=hi.NewSIZ;
hi.sizValue=ms;
// Read the length of SIZ marker segment (Lsiz)
ms.lsiz=ehs.ReadUInt16();
// Read the capability of the codestream (Rsiz)
ms.rsiz=ehs.ReadUInt16();
if(ms.rsiz>2)
{
thrownewSystem.ApplicationException("Codestream capabiities not JPEG 2000 - Part I"+" compliant");
}
// Read image size
ms.xsiz=ehs.ReadInt32();
ms.ysiz=ehs.ReadInt32();
if(ms.xsiz<=0||ms.ysiz<=0)
{
thrownewSystem.IO.IOException("JJ2000 does not support images whose "+"width and/or height not in the "+"range: 1 -- (2^31)-1");
}
// Read image offset
ms.x0siz=ehs.ReadInt32();
ms.y0siz=ehs.ReadInt32();
if(ms.x0siz<0||ms.y0siz<0)
{
thrownewSystem.IO.IOException("JJ2000 does not support images offset "+"not in the range: 0 -- (2^31)-1");
}
// Read size of tile
ms.xtsiz=ehs.ReadInt32();
ms.ytsiz=ehs.ReadInt32();
if(ms.xtsiz<=0||ms.ytsiz<=0)
{
thrownewSystem.IO.IOException("JJ2000 does not support tiles whose "+"width and/or height are not in "+"the range: 1 -- (2^31)-1");
}
// Read upper-left tile offset
ms.xt0siz=ehs.ReadInt32();
ms.yt0siz=ehs.ReadInt32();
if(ms.xt0siz<0||ms.yt0siz<0)
{
thrownewSystem.IO.IOException("JJ2000 does not support tiles whose "+"offset is not in "+"the range: 0 -- (2^31)-1");
}
// Read number of components and initialize related arrays
nComp=ms.csiz=ehs.ReadUInt16();
if(nComp<1||nComp>16384)
{
thrownewSystem.ArgumentException("Number of component out of "+"range 1--16384: "+nComp);
}
ms.ssiz=newint[nComp];
ms.xrsiz=newint[nComp];
ms.yrsiz=newint[nComp];
// Read bit-depth and down-sampling factors of each component
for(inti=0;i<nComp;i++)
{
ms.ssiz[i]=ehs.ReadByte();
ms.xrsiz[i]=ehs.ReadByte();
ms.yrsiz[i]=ehs.ReadByte();
}
// Check marker length
checkMarkerLength(ehs,"SIZ marker");
// Create needed ModuleSpec
nTiles=ms.NumTiles;
// Finish initialization of decSpec
decSpec=newDecoderSpecs(nTiles,nComp);
}
/// <summary> 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.
///
/// </summary>
/// <param name="ehs">The encoded header stream
///
/// </param>
//UPGRADE_TODO: Class 'java.io.DataInputStream' was converted to 'System.IO.BinaryReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataInputStream'"
privatevoidreadCRG(System.IO.BinaryReaderehs)
{
HeaderInfo.CRGms=hi.NewCRG;
hi.crgValue=ms;
ms.lcrg=ehs.ReadUInt16();
ms.xcrg=newint[nComp];
ms.ycrg=newint[nComp];
FacilityManager.getMsgLogger().printmsg(CSJ2K.j2k.util.MsgLogger_Fields.WARNING,"Information in CRG marker segment "+"not taken into account. This may affect the display "+"of the decoded image.");
for(intc=0;c<nComp;c++)
{
ms.xcrg[c]=ehs.ReadUInt16();
ms.ycrg[c]=ehs.ReadUInt16();
}
// Check marker length
checkMarkerLength(ehs,"CRG marker");
}
/// <summary> 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.
///
/// </summary>
/// <param name="ehs">The encoded header stream
///
/// </param>
/// <param name="mainh">Flag indicating whether or not this marker segment is read
/// from the main header.
///
/// </param>
/// <param name="tileIdx">The index of the current tile
///
/// </param>
/// <param name="comIdx">Occurence of this COM marker in eith main or tile-part
/// header
///
/// </param>
/// <exception cref="IOException">If an I/O error occurs while reading from the
/// encoded header stream
///
/// </exception>
//UPGRADE_TODO: Class 'java.io.DataInputStream' was converted to 'System.IO.BinaryReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataInputStream'"
FacilityManager.getMsgLogger().printmsg(CSJ2K.j2k.util.MsgLogger_Fields.WARNING,"COM marker registered as 0x"+System.Convert.ToString(ms.rcom,16)+" unknown, ignoring (this might crash the "+"decoder or decode a quality degraded or even "+"useless image)");
intgeneratedAux2=(int)temp_Int64;//Ignore this field for the moment
break;
}
if(mainh)
{
hi.comValue["main_"+comIdx]=ms;
}
else
{
hi.comValue["t"+tileIdx+"_"+comIdx]=ms;
}
// Check marker length
checkMarkerLength(ehs,"COM marker");
}
/// <summary> 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.
///
/// </summary>
/// <param name="ehs">The encoded stream.
///
/// </param>
/// <param name="mainh">Flag indicating whether or not this marker segment is read
/// from the main header.
///
/// </param>
/// <param name="tileIdx">The index of the current tile
///
/// </param>
/// <param name="tpIdx">Tile-part index
///
/// </param>
/// <exception cref="IOException">If an I/O error occurs while reading from the
/// encoded header stream.
///
/// </exception>
//UPGRADE_TODO: Class 'java.io.DataInputStream' was converted to 'System.IO.BinaryReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataInputStream'"
// Find the number of subbands in the resolution level
if(rl==0)
{
// Only the LL subband
minb=0;
maxb=1;
}
else
{
// Dyadic decomposition
hpd=1;
// Adapt hpd to resolution level
if(hpd>maxrl-rl)
{
hpd-=(maxrl-rl);
}
else
{
hpd=1;
}
// Determine max and min subband index
minb=1<<((hpd-1)<<1);// minb = 4^(hpd-1)
maxb=1<<(hpd<<1);// maxb = 4^hpd
}
// Allocate array for subbands in resolution level
exp[rl]=newint[maxb];
nStep[rl]=newfloat[maxb];
for(j=minb;j<maxb;j++)
{
tmp=ms.spqcd[rl][j]=ehs.ReadUInt16();
exp[rl][j]=(tmp>>11)&0x1f;
// NOTE: the formula below does not support more than 5
// bits for the exponent, otherwise (-1<<exp) might
// overflow (the - is used to be able to represent 2**31)
//UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
/// <summary> 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.
///
/// </summary>
/// <param name="ehs">The encoded stream.
///
/// </param>
/// <param name="mainh">Flag indicating whether or not this marker segment is read
/// from the main header.
///
/// </param>
/// <param name="tileIdx">The index of the current tile
///
/// </param>
/// <param name="tpIdx">Tile-part index
///
/// </param>
/// <exception cref="IOException">If an I/O error occurs while reading from the
/// encoded header stream.
///
/// </exception>
//UPGRADE_TODO: Class 'java.io.DataInputStream' was converted to 'System.IO.BinaryReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataInputStream'"
// Find the number of subbands in the resolution level
if(rl==0)
{
// Only the LL subband
minb=0;
maxb=1;
}
else
{
// Dyadic decomposition
hpd=1;
// Adapt hpd to resolution level
if(hpd>maxrl-rl)
{
hpd-=(maxrl-rl);
}
else
{
hpd=1;
}
// Determine max and min subband index
minb=1<<((hpd-1)<<1);// minb = 4^(hpd-1)
maxb=1<<(hpd<<1);// maxb = 4^hpd
}
// Allocate array for subbands in resolution level
expC[rl]=newint[maxb];
nStepC[rl]=newfloat[maxb];
for(j=minb;j<maxb;j++)
{
tmp=ms.spqcc[rl][j]=ehs.ReadUInt16();
expC[rl][j]=(tmp>>11)&0x1f;
// NOTE: the formula below does not support more than 5
// bits for the exponent, otherwise (-1<<exp) might
// overflow (the - is used to be able to represent 2**31)
//UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
/// <summary> Reads a COD marker segment and realigns the codestream where the next
/// marker should be found.
///
/// </summary>
/// <param name="ehs">The encoder header stream.
///
/// </param>
/// <param name="mainh">Flag indicating whether or not this marker segment is read
/// from the main header.
///
/// </param>
/// <param name="tileIdx">The index of the current tile
///
/// </param>
/// <param name="tpIdx">Tile-part index
///
/// </param>
/// <exception cref="IOException">If an I/O error occurs while reading from the
/// encoder header stream
///
/// </exception>
//UPGRADE_TODO: Class 'java.io.DataInputStream' was converted to 'System.IO.BinaryReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataInputStream'"
FacilityManager.getMsgLogger().printmsg(CSJ2K.j2k.util.MsgLogger_Fields.WARNING,"Code-block partition origin "+"different from (0,0). This is defined in JPEG 2000"+" part 2 and may not be supported by all JPEG "+"2000 decoders.");
/// <summary> Reads the COC marker segment and realigns the codestream where the next
/// marker should be found.
///
/// </summary>
/// <param name="ehs">The encoder header stream.
///
/// </param>
/// <param name="mainh">Flag indicating whether or not this marker segment is read
/// from the main header.
///
/// </param>
/// <param name="tileIdx">The index of the current tile
///
/// </param>
/// <param name="tpIdx">Tile-part index
///
/// </param>
/// <exception cref="IOException">If an I/O error occurs while reading from the
/// encoder header stream
///
/// </exception>
//UPGRADE_TODO: Class 'java.io.DataInputStream' was converted to 'System.IO.BinaryReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataInputStream'"
/// <summary> Reads the POC marker segment and realigns the codestream where the next
/// marker should be found.
///
/// </summary>
/// <param name="ehs">The encoder header stream.
///
/// </param>
/// <param name="mainh">Flag indicating whether or not this marker segment is read
/// from the main header.
///
/// </param>
/// <param name="t">The index of the current tile
///
/// </param>
/// <param name="tpIdx">Tile-part index
///
/// </param>
/// <exception cref="IOException">If an I/O error occurs while reading from the
/// encoder header stream
///
/// </exception>
//UPGRADE_TODO: Class 'java.io.DataInputStream' was converted to 'System.IO.BinaryReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataInputStream'"
thrownewCorruptedCodestreamException("LYEpoc value must be greater than 1 in POC marker "+"segment of tile "+t+", tile-part "+tpIdx);
}
// REpoc
change[chg][3]=ms.repoc[chg]=ehs.ReadByte();
if(change[chg][3]<=change[chg][0])
{
thrownewCorruptedCodestreamException("REpoc value must be greater than RSpoc in POC marker "+"segment of tile "+t+", tile-part "+tpIdx);
}
// CEpoc
if(useShort)
{
change[chg][4]=ms.cepoc[chg]=ehs.ReadUInt16();
}
else
{
tmp=ms.cepoc[chg]=ehs.ReadByte();
if(tmp==0)
{
change[chg][4]=0;
}
else
{
change[chg][4]=tmp;
}
}
if(change[chg][4]<=change[chg][1])
{
thrownewCorruptedCodestreamException("CEpoc value must be greater than CSpoc in POC marker "+"segment of tile "+t+", tile-part "+tpIdx);
}
// Ppoc
change[chg][5]=ms.ppoc[chg]=ehs.ReadByte();
}
// Check marker length
checkMarkerLength(ehs,"POC marker");
// Register specifications
if(mainh)
{
hi.pocValue["main"]=ms;
decSpec.pcs.setDefault(change);
}
else
{
hi.pocValue["t"+t]=ms;
decSpec.pcs.setTileDef(t,change);
}
}
/// <summary> 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.
///
/// </summary>
/// <param name="ehs">The encoder header stream.
///
/// </param>
/// <exception cref="IOException">If an I/O error occurs while reading from the
/// encoder header stream
///
/// </exception>
//UPGRADE_TODO: Class 'java.io.DataInputStream' was converted to 'System.IO.BinaryReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataInputStream'"
/// <summary> 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.
///
/// </summary>
/// <param name="ehs">The encoder header stream.
///
/// </param>
/// <exception cref="IOException">If an I/O error occurs while reading from the
/// encoder header stream
///
/// </exception>
//UPGRADE_TODO: Class 'java.io.DataInputStream' was converted to 'System.IO.BinaryReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataInputStream'"
/// <summary> 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.
///
/// </summary>
/// <param name="ehs">The encoder header stream.
///
/// </param>
/// <exception cref="IOException">If an I/O error occurs while reading from the
/// encoder header stream
///
/// </exception>
//UPGRADE_TODO: Class 'java.io.DataInputStream' was converted to 'System.IO.BinaryReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataInputStream'"
/// <summary> Reads the RGN marker segment of the codestream header.
///
/// <p>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.</p>
///
/// </summary>
/// <param name="ehs">The encoder header stream.
///
/// </param>
/// <param name="mainh">Flag indicating whether or not this marker segment is read
/// from the main header.
///
/// </param>
/// <param name="tileIdx">The index of the current tile
///
/// </param>
/// <param name="tpIdx">Tile-part index
///
/// </param>
/// <exception cref="IOException">If an I/O error occurs while reading from the
/// encoder header stream
///
/// </exception>
//UPGRADE_TODO: Class 'java.io.DataInputStream' was converted to 'System.IO.BinaryReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataInputStream'"
/// <summary> Reads the PPM marker segment of the main header.
///
/// </summary>
/// <param name="ehs">The encoder header stream.
///
/// </param>
/// <exception cref="IOException">If an I/O error occurs while reading from the
/// encoder header stream
///
/// </exception>
//UPGRADE_TODO: Class 'java.io.DataInputStream' was converted to 'System.IO.BinaryReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataInputStream'"
privatevoidreadPPM(System.IO.BinaryReaderehs)
{
intcurMarkSegLen;
intindx;// i, len, off removed
intremSegLen;
//byte[] b;
// If first time readPPM method is called allocate arrays for packed
/// <summary> Reads the PPT marker segment of the main header.
///
/// </summary>
/// <param name="ehs">The encoder header stream.
///
/// </param>
/// <param name="tile">The tile to which the current tile part belongs
///
/// </param>
/// <param name="tpIdx">Tile-part index
///
/// </param>
/// <exception cref="IOException">If an I/O error occurs while reading from the
/// encoder header stream
///
/// </exception>
//UPGRADE_TODO: Class 'java.io.DataInputStream' was converted to 'System.IO.BinaryReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataInputStream'"
thrownewCorruptedCodestreamException("More than one SIZ marker "+"segment found in main "+"header");
}
nfMarkSeg|=SIZ_FOUND;
htKey="SIZ";
break;
caseCSJ2K.j2k.codestream.Markers.SOD:
thrownewCorruptedCodestreamException("SOD found in main header");
caseCSJ2K.j2k.codestream.Markers.EOC:
thrownewCorruptedCodestreamException("EOC found in main header");
caseCSJ2K.j2k.codestream.Markers.SOT:
if((nfMarkSeg&SOT_FOUND)!=0)
{
thrownewCorruptedCodestreamException("More than one SOT "+"marker "+"found right after "+"main "+"or tile header");
}
nfMarkSeg|=SOT_FOUND;
return;
caseCSJ2K.j2k.codestream.Markers.COD:
if((nfMarkSeg&COD_FOUND)!=0)
{
thrownewCorruptedCodestreamException("More than one COD "+"marker "+"found in main header");
}
nfMarkSeg|=COD_FOUND;
htKey="COD";
break;
caseCSJ2K.j2k.codestream.Markers.COC:
nfMarkSeg|=COC_FOUND;
htKey="COC"+(nCOCMarkSeg++);
break;
caseCSJ2K.j2k.codestream.Markers.QCD:
if((nfMarkSeg&QCD_FOUND)!=0)
{
thrownewCorruptedCodestreamException("More than one QCD "+"marker "+"found in main header");
}
nfMarkSeg|=QCD_FOUND;
htKey="QCD";
break;
caseCSJ2K.j2k.codestream.Markers.QCC:
nfMarkSeg|=QCC_FOUND;
htKey="QCC"+(nQCCMarkSeg++);
break;
caseCSJ2K.j2k.codestream.Markers.RGN:
nfMarkSeg|=RGN_FOUND;
htKey="RGN"+(nRGNMarkSeg++);
break;
caseCSJ2K.j2k.codestream.Markers.COM:
nfMarkSeg|=COM_FOUND;
htKey="COM"+(nCOMMarkSeg++);
break;
caseCSJ2K.j2k.codestream.Markers.CRG:
if((nfMarkSeg&CRG_FOUND)!=0)
{
thrownewCorruptedCodestreamException("More than one CRG "+"marker "+"found in main header");
}
nfMarkSeg|=CRG_FOUND;
htKey="CRG";
break;
caseCSJ2K.j2k.codestream.Markers.PPM:
nfMarkSeg|=PPM_FOUND;
htKey="PPM"+(nPPMMarkSeg++);
break;
caseCSJ2K.j2k.codestream.Markers.TLM:
if((nfMarkSeg&TLM_FOUND)!=0)
{
thrownewCorruptedCodestreamException("More than one TLM "+"marker "+"found in main header");
}
nfMarkSeg|=TLM_FOUND;
break;
caseCSJ2K.j2k.codestream.Markers.PLM:
if((nfMarkSeg&PLM_FOUND)!=0)
{
thrownewCorruptedCodestreamException("More than one PLM "+"marker "+"found in main header");
}
FacilityManager.getMsgLogger().printmsg(CSJ2K.j2k.util.MsgLogger_Fields.WARNING,"PLM marker segment found but "+"not used by by JJ2000 decoder.");
nfMarkSeg|=PLM_FOUND;
htKey="PLM";
break;
caseCSJ2K.j2k.codestream.Markers.POC:
if((nfMarkSeg&POC_FOUND)!=0)
{
thrownewCorruptedCodestreamException("More than one POC "+"marker segment found "+"in main header");
}
nfMarkSeg|=POC_FOUND;
htKey="POC";
break;
caseCSJ2K.j2k.codestream.Markers.PLT:
thrownewCorruptedCodestreamException("PLT found in main header");
caseCSJ2K.j2k.codestream.Markers.PPT:
thrownewCorruptedCodestreamException("PPT found in main header");
default:
htKey="UNKNOWN";
FacilityManager.getMsgLogger().printmsg(CSJ2K.j2k.util.MsgLogger_Fields.WARNING,"Non recognized marker segment (0x"+System.Convert.ToString(marker,16)+") in main header!");
thrownewCorruptedCodestreamException("More than one POC "+"marker segment found "+"in tile-part"+" header");
nfMarkSeg|=POC_FOUND;
htKey="POC";
break;
caseCSJ2K.j2k.codestream.Markers.PLT:
if((nfMarkSeg&PLM_FOUND)!=0)
{
thrownewCorruptedCodestreamException("PLT marker found even"+"though PLM marker "+"found in main header");
}
FacilityManager.getMsgLogger().printmsg(CSJ2K.j2k.util.MsgLogger_Fields.WARNING,"PLT marker segment found but "+"not used by JJ2000 decoder.");
htKey="UNKNOWN";
break;
default:
htKey="UNKNOWN";
FacilityManager.getMsgLogger().printmsg(CSJ2K.j2k.util.MsgLogger_Fields.WARNING,"Non recognized marker segment (0x"+System.Convert.ToString(marker,16)+") in tile-part header"+" of tile "+tileIdx+" !");
break;
}
// Read marker segment length and create corresponding byte buffer
intmarkSegLen=ehs.readUnsignedShort();
byte[]buf=newbyte[markSegLen];
// Copy data (after re-insertion of marker segment length);
buf[0]=(byte)((markSegLen>>8)&0xFF);
buf[1]=(byte)(markSegLen&0xFF);
ehs.readFully(buf,2,markSegLen-2);
if(!htKey.Equals("UNKNOWN"))
{
// Store array in hashTable
ht[htKey]=buf;
}
}
/// <summary> Retrieves and reads all marker segments found in the main header during
/// the first pass.
///
/// </summary>
privatevoidreadFoundMainMarkSeg()
{
//UPGRADE_TODO: Class 'java.io.DataInputStream' was converted to 'System.IO.BinaryReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataInputStream'"
//UPGRADE_TODO: Class 'java.io.DataInputStream' was converted to 'System.IO.BinaryReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataInputStream'"