CSJ2K.j2k.codestream.reader.PktDecoder.readPktBody C# (CSharp) Method

readPktBody() public method

Reads specificied packet body in order to find offset of each code-block's piece of codeword. This use the list of found code-blocks in previous red packet head.
public readPktBody ( int l, int r, int c, int p, CSJ2K.j2k.codestream.reader.CBlkInfo cbI, int nb ) : bool
l int layer index /// ///
r int Resolution level index /// ///
c int Component index /// ///
p int Precinct index /// ///
cbI CSJ2K.j2k.codestream.reader.CBlkInfo CBlkInfo array of relevant component and resolution /// level. /// ///
nb int The remainding number of bytes to read from the bit stream in /// each tile before reaching the decoding rate (in truncation mode) /// ///
return bool
        public virtual bool readPktBody(int l, int r, int c, int p, CBlkInfo[][][] cbI, int[] nb)
        {
            int curOff = ehs.Pos;
            //Coord curCB;
            CBlkInfo ccb;
            bool stopRead = false;
            int tIdx = src.TileIdx;
            Coord cbc;

            bool precFound = false;
            int mins = (r == 0)?0:1;
            int maxs = (r == 0)?1:4;
            for (int s = mins; s < maxs; s++)
            {
                if (p < ppinfo[c][r].Length)
                {
                    precFound = true;
                }
            }
            if (!precFound)
            {
                return false;
            }

            for (int s = mins; s < maxs; s++)
            {
                for (int numCB = 0; numCB < cblks[s].Count; numCB++)
                {
                    cbc = ((CBlkCoordInfo) cblks[s][numCB]).idx;
                    ccb = cbI[s][cbc.y][cbc.x];
                    ccb.off[l] = curOff;
                    curOff += ccb.len[l];
                    try
                    {
                        ehs.seek(curOff);
                    }
                    catch (System.IO.EndOfStreamException e)
                    {
                        if (l == 0)
                        {
                            cbI[s][cbc.y][cbc.x] = null;
                        }
                        else
                        {
                            ccb.off[l] = ccb.len[l] = 0;
                            ccb.ctp -= ccb.ntp[l];
                            ccb.ntp[l] = 0;
                            ccb.pktIdx[l] = - 1;
                        }
                        throw new System.IO.EndOfStreamException();
                    }

                    // If truncation mode
                    if (isTruncMode)
                    {
                        if (stopRead || ccb.len[l] > nb[tIdx])
                        {
                            // Remove found information in this code-block
                            if (l == 0)
                            {
                                cbI[s][cbc.y][cbc.x] = null;
                            }
                            else
                            {
                                ccb.off[l] = ccb.len[l] = 0;
                                ccb.ctp -= ccb.ntp[l];
                                ccb.ntp[l] = 0;
                                ccb.pktIdx[l] = - 1;
                            }
                            stopRead = true;
                        }
                        if (!stopRead)
                        {
                            nb[tIdx] -= ccb.len[l];
                        }
                    }
                    // If ncb quit condition reached
                    if (ncbQuit && r == rQuit && s == sQuit && cbc.x == xQuit && cbc.y == yQuit && tIdx == tQuit && c == cQuit)
                    {
                        cbI[s][cbc.y][cbc.x] = null;
                        stopRead = true;
                    }
                } // Loop on code-blocks
            } // End loop on subbands

            // Seek to the end of the packet
            ehs.seek(curOff);

            if (stopRead)
            {
                return true;
            }
            else
            {
                return false;
            }
        }