/// Description: Reads packets heads and keeps location of
/// code-blocks' codewords
///
///
///
/// COPYRIGHT:
///
/// This software module was originally developed by Rapha<68>l Grosbois and
/// Diego Santa Cruz (Swiss Federal Institute of Technology-EPFL); Joel
/// Askel<65>f (Ericsson Radio Systems AB); and Bertrand Berthelot, David
/// Bouchard, F<>lix Henry, Gerard Mozelle and Patrice Onno (Canon Research
/// Centre France S.A) in the course of development of the JPEG2000
/// standard as specified by ISO/IEC 15444 (JPEG 2000 Standard). This
/// software module is an implementation of a part of the JPEG 2000
/// Standard. Swiss Federal Institute of Technology-EPFL, Ericsson Radio
/// Systems AB and Canon Research Centre France S.A (collectively JJ2000
/// Partners) agree not to assert against ISO/IEC and users of the JPEG
/// 2000 Standard (Users) any of their rights under the copyright, not
/// including other intellectual property rights, for this software module
/// with respect to the usage by ISO/IEC and Users of this software module
/// or modifications thereof for use in hardware or software products
/// claiming conformance to the JPEG 2000 Standard. Those intending to use
/// this software module in hardware or software products are advised that
/// their use may infringe existing patents. The original developers of
/// this software module, JJ2000 Partners and ISO/IEC assume no liability
/// for use of this software module or modifications thereof. No license
/// or right to this software module is granted for non JPEG 2000 Standard
/// conforming products. JJ2000 Partners have full right to use this
/// software module for his/her own purpose, assign or donate this
/// software module to any third party and to inhibit third parties from
/// using this software module for non JPEG 2000 Standard conforming
/// products. This copyright notice must be included in all copies or
/// derivative works of this software module.
///
/// Copyright (c) 1999/2000 JJ2000 Partners.
///
/// </summary>
usingSystem;
usingCSJ2K.j2k.wavelet.synthesis;
usingCSJ2K.j2k.codestream;
usingCSJ2K.j2k.entropy;
usingCSJ2K.j2k.wavelet;
usingCSJ2K.j2k.decoder;
usingCSJ2K.j2k.image;
usingCSJ2K.j2k.util;
usingCSJ2K.j2k.io;
namespaceCSJ2K.j2k.codestream.reader
{
/// <summary> This class is used to read packet's head and body. All the members must be
/// re-initialized at the beginning of each tile thanks to the restart()
/// method.
///
/// </summary>
publicclassPktDecoder
{
/// <summary>Reference to the codestream reader agent </summary>
privateBitstreamReaderAgentsrc;
/// <summary>Flag indicating whether packed packet header was used for this tile </summary>
privateboolpph=false;
/// <summary>The packed packet header if it was used </summary>
privateSystem.IO.MemoryStreampphbais;
/// <summary>Reference to decoder specifications </summary>
privateDecoderSpecsdecSpec;
/// <summary>Reference to the HeaderDecoder </summary>
privateHeaderDecoderhd;
/// <summary>Initial value of the state variable associated with code-block
/// length.
/// </summary>
//UPGRADE_NOTE: Final was removed from the declaration of 'INIT_LBLOCK '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
privateintINIT_LBLOCK=3;
/// <summary>The wrapper to read bits for the packet heads </summary>
privatePktHeaderBitReaderbin;
/// <summary>Reference to the stream where to read from </summary>
privateRandomAccessIOehs;
/// <summary> Maximum number of precincts :
///
/// <ul>
/// <li> 1st dim: component index.</li>
/// <li> 2nd dim: resolution level index.</li>
/// </ul>
///
/// </summary>
privateCoord[][]numPrec;
/// <summary>Index of the current tile </summary>
privateinttIdx;
/// <summary> Array containing the coordinates, width, height, indexes, ... of the
/// precincts in the current tile:
///
/// <ul>
/// <li> 1st dim: component index.</li>
/// <li> 2nd dim: resolution level index.</li>
/// <li> 3rd dim: precinct index.</li>
/// </ul>
///
/// </summary>
privatePrecInfo[][][]ppinfo;
/// <summary> Lblock value used to read code size information in each packet head:
///
/// <ul>
/// <li> 1st dim: component index.</li>
/// <li> 2nd dim: resolution level index.</li>
/// <li> 3rd dim: subband index.</li>
/// <li> 4th/5th dim: code-block index (vert. and horiz.).</li>
/// </ul>
///
/// </summary>
privateint[][][][][]lblock;
/// <summary> Tag tree used to read inclusion informations in packet's head:
///
/// <ul>
/// <li> 1st dim: component index.</li>
/// <li> 2nd dim: resolution level index.</li>
/// <li> 3rd dim: precinct index.</li>
/// <li> 4th dim: subband index.</li>
///
/// </summary>
privateTagTreeDecoder[][][][]ttIncl;
/// <summary> Tag tree used to read bit-depth information in packet's head:
///
/// <ul>
/// <li> 1st dim: component index.</li>
/// <li> 2nd dim: resolution level index.</li>
/// <li> 3rd dim: precinct index.</li>
/// <li> 4th dim: subband index.</li>
/// </ul>
///
/// </summary>
privateTagTreeDecoder[][][][]ttMaxBP;
/// <summary>Number of layers in t he current tile </summary>
privateintnl=0;
/// <summary>The number of components </summary>
privateintnc;
/// <summary>Whether or not SOP marker segment are used </summary>
privateboolsopUsed=false;
/// <summary>Whether or not EPH marker are used </summary>
privateboolephUsed=false;
/// <summary>Index of the current packet in the tile. Used with SOP marker segment
///
/// </summary>
privateintpktIdx;
/// <summary>List of code-blocks found in last read packet head (one list
/// per subband)
/// </summary>
privateSystem.Collections.ArrayList[]cblks;
/// <summary>Number of codeblocks encountered. used for ncb quit condition</summary>
privateintncb;
/// <summary>Maximum number of codeblocks to read before ncb quit condition is
/// reached
/// </summary>
privateintmaxCB;
/// <summary>Flag indicating whether ncb quit condition has been reached </summary>
privateboolncbQuit;
/// <summary>The tile in which the ncb quit condition was reached </summary>
privateinttQuit;
/// <summary>The component in which the ncb quit condition was reached </summary>
privateintcQuit;
/// <summary>The subband in which the ncb quit condition was reached </summary>
privateintsQuit;
/// <summary>The resolution in which the ncb quit condition was reached </summary>
privateintrQuit;
/// <summary>The x position of the last code block before ncb quit reached </summary>
privateintxQuit;
/// <summary>The y position of the last code block before ncb quit reached </summary>
privateintyQuit;
/// <summary>True if truncation mode is used. False if it is parsing mode </summary>
privateboolisTruncMode;
/// <summary> Creates an empty PktDecoder object associated with given decoder
/// specifications and HeaderDecoder. This object must be initialized
/// thanks to the restart method before being used.
// Get the tile-component coordinates on the reference grid
tcx0=src.getResULX(c,mdl[c]);
tcy0=src.getResULY(c,mdl[c]);
tcx1=tcx0+src.getTileCompWidth(tIdx,c,mdl[c]);
tcy1=tcy0+src.getTileCompHeight(tIdx,c,mdl[c]);
for(intr=0;r<=mdl[c];r++)
{
// Tile's coordinates in the reduced resolution image domain
//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'"
//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'"
//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'"
//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'"
// Calculate the maximum number of precincts for each
// resolution level taking into account tile specific options.
doubletwoppx=(double)getPPX(tIdx,c,r);
doubletwoppy=(double)getPPY(tIdx,c,r);
numPrec[c][r]=newCoord();
if(trx1>trx0)
{
//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'"
//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'"
//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'"
//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'"
//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'"
//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'"
//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'"
inttwoppx2=(int)(twoppx/2);
//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'"
inttwoppy2=(int)(twoppy/2);
// Precincts are located at (cb0x+i*twoppx,cb0y+j*twoppy)
// Valid precincts are those which intersect with the current
// resolution level
intmaxPrec=ppinfo[c][r].Length;
intnPrec=0;
//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'"
//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'"
//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'"
//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'"
intp0x,p0y,p1x,p1y;// Precinct projection in subband
ints0x,s0y,s1x,s1y;// Active subband portion
intcw,ch;
intkstart,kend,lstart,lend,k0,l0;
intprg_ulx,prg_uly;
//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'"
intprg_w=(int)twoppx<<ndl;
//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'"
intprg_h=(int)twoppy<<ndl;
inttmp1,tmp2;
CBlkCoordInfocb;
for(inti=istart;i<=iend;i++)
{
// Vertical precincts
for(intj=jstart;j<=jend;j++,nPrec++)
{
// Horizontal precincts
//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'"
//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'"
prg_ulx=cb0x+j*xrsiz*((int)twoppx<<ndl);
}
//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'"
//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'"
prg_uly=cb0y+i*yrsiz*((int)twoppy<<ndl);
}
//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'"
//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'"
p0x=acb0x+j*(int)twoppx;
//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'"
p1x=p0x+(int)twoppx;
//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'"
p0y=acb0y+i*(int)twoppy;
//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'"
p1y=p0y+(int)twoppy;
sb=(SubbandSyn)root.getSubbandByIdx(0,0);
s0x=(p0x<sb.ulcx)?sb.ulcx:p0x;
s1x=(p1x>sb.ulcx+sb.w)?sb.ulcx+sb.w:p1x;
s0y=(p0y<sb.ulcy)?sb.ulcy:p0y;
s1y=(p1y>sb.ulcy+sb.h)?sb.ulcy+sb.h:p1y;
// Code-blocks are located at (acb0x+k*cw,acb0y+l*ch)
cw=sb.nomCBlkW;
ch=sb.nomCBlkH;
//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'"
//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'"
//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'"
//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'"
//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'"
//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'"
// Code-blocks are located at (acb0x+k*cw,acb0y+l*ch)
cw=sb.nomCBlkW;
ch=sb.nomCBlkH;
//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'"
//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'"
//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'"
//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'"
//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'"
//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'"
// Code-blocks are located at (acb0x+k*cw,acb0y+l*ch)
cw=sb.nomCBlkW;
ch=sb.nomCBlkH;
//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'"
//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'"
//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'"
//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'"
//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'"
//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'"
// Code-blocks are located at (acb0x+k*cw,acb0y+l*ch)
cw=sb.nomCBlkW;
ch=sb.nomCBlkH;
//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'"
//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'"
//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'"
//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'"
//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'"
//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'"