📄 pktencoder.java
字号:
* @param infoSrc The source of information to construct the * object. * * @param encSpec The parameters for the encoding * * @param maxNumPrec Maximum number of precinct in each tile, component * and resolution level. * * @param pl ParameterList instance that holds command line options * */ public PktEncoder(CodedCBlkDataSrcEnc infoSrc, EncoderSpecs encSpec, Coord[][][] maxNumPrec, ParameterList pl) { SubbandAn sb,sb2; Coord orTCoord; // Original tile X and Y Coord tmpCoord = null; int numcb; // Number of code-blocks Vector cblks = null; // Check parameters pl.checkList(OPT_PREFIX,pl.toNameArray(pinfo)); // Parse the Psop option i.e. whether or not start of packet // (SOP) markers should be used. String sopopt = pl.getParameter("Psop"); if (sopopt == null) { throw new IllegalArgumentException("Missing option 'Psop'"); } // Parse the Peph option i.e. whether or not end of packet // headers (EPH) markers should be used. String ephopt = pl.getParameter("Peph"); if (ephopt == null) { throw new IllegalArgumentException("Missing option 'Peph'"); } this.infoSrc = infoSrc; this.encSpec = encSpec; this.maxNumPrec = maxNumPrec; // Save current tile indices orTCoord = infoSrc.getTile(null); // Get number of components and tiles int ncomp = infoSrc.getNumComps(); int ntiles = infoSrc.getNumTiles(); // Do initial allocation ttIncl = new TagTreeEncoder[ntiles][ncomp][][][]; ttMaxBP = new TagTreeEncoder[ntiles][ncomp][][][]; lblock = new int[ntiles][ncomp][][][]; prevtIdxs = new int[ntiles][ncomp][][][]; cbArrayI = new CBlkCoordInfo[ntiles][ncomp][][][]; precArrayI = new PrecCoordInfo[ntiles][ncomp][][][]; incArray = new Coord[ntiles][ncomp][]; incArrayMax = new Coord[ntiles][ncomp]; sot_eotArray = new Coord[ntiles][ncomp][][]; sot_eotArrayMax = new Coord[ntiles][ncomp][2]; mrl = new int[ntiles][ncomp]; subRange = new int[ntiles][ncomp][][]; savedSbTree = new SubbandAn[ntiles][ncomp]; // Goto first tile infoSrc.setTile(0,0); // Finish allocation for(int t=0; t<ntiles; t++){ // Loop on tiles for(int c=0; c<ncomp; c++){ // Loop on components // Get number of resolution levels savedSbTree[t][c] = infoSrc.getSubbandTree(t,c); sb = savedSbTree[t][c]; mrl[t][c] = sb.resLvl; subRange[t][c] = findSubInResLvl(c,t); incArray[t][c] = new Coord[mrl[t][c]+1]; sot_eotArray[t][c] =new Coord[mrl[t][c]+1][2]; // Create and initialise the increment arrays buildIncArrays(c,t); // Initialise the start/end of tile arrays buildSotEotArrays(c,t); lblock[t][c] = new int[mrl[t][c]+1][][]; ttIncl[t][c] = new TagTreeEncoder[mrl[t][c]+1][][]; ttMaxBP[t][c] = new TagTreeEncoder[mrl[t][c]+1][][]; prevtIdxs[t][c] = new int[mrl[t][c]+1][][]; cbArrayI[t][c] = new CBlkCoordInfo[mrl[t][c]+1][][]; precArrayI[t][c] = new PrecCoordInfo[mrl[t][c]+1][][]; for(int r=mrl[t][c]; r>=0; r--){ // Loop on resolution levels int maxPrec = maxNumPrec[t][c][r].x * maxNumPrec[t][c][r].y; // Allocate for subbands ttIncl[t][c][r] = new TagTreeEncoder[subRange[t][c][r][1]+1][maxPrec]; ttMaxBP[t][c][r] = new TagTreeEncoder[subRange[t][c][r][1]+1][maxPrec]; prevtIdxs[t][c][r] = new int[subRange[t][c][r][1]+1][]; lblock[t][c][r] = new int[subRange[t][c][r][1]+1][]; cbArrayI[t][c][r] = new CBlkCoordInfo[subRange[t][c][r][1]+1][]; precArrayI[t][c][r] = new PrecCoordInfo[subRange[t][c][r][1]+1][]; // Initialize code-blocks and precincts information in // this resolution level buildCblkPrec(t,c,r); for(int subIdx=subRange[t][c][r][0]; subIdx <= subRange[t][c][r][1]; subIdx ++){ // Loop on subbands sb2 = (SubbandAn)sb.getSubbandByIdx(r,subIdx); tmpCoord = infoSrc.getNumCodeBlocks(sb2,tmpCoord); numcb = tmpCoord.x*tmpCoord.y; lblock[t][c][r][subIdx] = new int[numcb]; ArrayUtil.intArraySet(lblock[t][c][r][subIdx], INIT_LBLOCK); prevtIdxs[t][c][r][subIdx] = new int[numcb]; ArrayUtil.intArraySet(prevtIdxs[t][c][r][subIdx],-1); // For each precinct, get the number of code-blocks in // the packet and create the tag trees for(int pIdx=0 ; pIdx<maxPrec ; pIdx++){ cblks = getCBlkInPrec(t,c,r,subIdx,pIdx,cblks); // the first element contains the number of // code-blocks in the precinct in each direction tmpCoord = (Coord)cblks.elementAt(0); ttIncl[t][c][r][subIdx][pIdx] = new TagTreeEncoder(tmpCoord.y,tmpCoord.x); ttMaxBP[t][c][r][subIdx][pIdx] = new TagTreeEncoder(tmpCoord.y,tmpCoord.x); } } } } // Goto next tile if (t<ntiles-1) { // not at last tile infoSrc.nextTile(); } } // Reset tile to original one infoSrc.setTile(orTCoord.x,orTCoord.y); } /** * Encodes a packet and returns the buffer containing the encoded packet * header. The code-blocks appear in a 3D array of CBlkRateDistStats, * 'cbs'. The first index is the tile index in lexicographical order, the * second index is the subband index (as defined in the Subband class), * and the third index is the code-block index (whithin the subband tile) * in lexicographical order as well. The indexes of the new truncation * points for each code-block are specified by the 3D array of int * 'tIndx'. The indices of this array are the same as for cbs. The * truncation point indices in 'tIndx' are the indices of the elements of * the 'truncIdxs' array, of the CBlkRateDistStats class, that give the * real truncation points. If a truncation point index is negative it * means that the code-block has not been included in any layer yet. If * the truncation point is less than or equal to the highest truncation * point used in previous layers then the code-block is not included in * the packet. Otherwise, if larger, the code-block is included in the * packet. The body of the packet can be obtained with the * getLastBodyBuf() and getLastBodyLen() methods. * * <P>Layers must be coded in increasing order, in consecutive manner, for * each tile, component and resolution level (e.g., layer 1, then layer 2, * etc.). For different tile, component and/or resolution level no * particular order must be followed. * * @param ly The layer index (starts at 1). * * @param c The component index. * * @param r The resolution level * * @param t Index of the current tile * * @param cbs The 3D array of coded code-blocks. * * @param tIndx The truncation point indices for each code-block. * * @param hbuf The header buffer. If null a new BitOutputBuffer is created * and returned. This buffer is reset before anything is written to it. * * @param bbuf The body buffer. If null a new one is created. If not large * enough a new one is created. * * @param pIdx The precinct index * * @return The buffer containing the packet header. * */ public BitOutputBuffer encodePacket(int ly, int c, int r, int t, CBlkRateDistStats cbs[][], int tIndx[][], BitOutputBuffer hbuf, byte bbuf[], int pIdx) { int b,by,bx,s,i,maxi; int ncb,ncbx,ncby; int thmax; int newtp; int cblen; int prednbits,nbits,deltabits; TagTreeEncoder cur_ttIncl,cur_ttMaxBP; int cur_prevtIdxs[]; // last encoded truncation points CBlkRateDistStats cur_cbs[]; int cur_tIndx[]; // truncation points to encode int minsb,maxsb; Vector cbv = null; Coord cbCoord = null; boolean precinctPartitionUsed = infoSrc.precinctPartitionUsed(c,t); int firstCB_horIdx = -1; int firstCB_vertIdx = -1; boolean pktPresentWritten = false; boolean precIdxExist = false; SubbandAn sb = null; roiInPkt = false; roiLen = 0; maxsb = subRange[t][c][r][1]+1; minsb = subRange[t][c][r][0]; // First, we check if packet is empty (i.e precinct 'p' is empty // in all subbands) boolean isPktEmpty = true; for (s=minsb; s<maxsb; s++) { if( precArrayI[t][c][r][s] == null ){ // The precinct is empty in the subband continue; } else{ cbv = getCBlkInPrec(t,c,r,s,pIdx,cbv); if(cbv.size()==1) // Precinct is not empty but there is no // code-block inside (Is it possible ?) continue; else { // The precinct is not empty in at least one subband -> // stop isPktEmpty = false; break; } } } if(isPktEmpty){ packetWritable = true; if(hbuf == null){ hbuf = new BitOutputBuffer(); } else{ hbuf.reset(); } if (bbuf == null) { lbbuf = bbuf = new byte[1]; } hbuf.writeBit(0); lblen = 0; return hbuf; } if(hbuf == null){ hbuf = new BitOutputBuffer(); } else{ hbuf.reset(); } // Invalidate last body buffer lbbuf = null; lblen = 0; // Signal that packet is present hbuf.writeBit(1); for(s=minsb; s<maxsb; s++){ // Loop on subbands // Do not try to write any code-block inclusion if the precinct // does not contain element of this subband if(precArrayI[t][c][r][s]==null){ continue; } if(pIdx>=precArrayI[t][c][r][s].length){ // If we arrive here, it means that there is no code-block for // this subband but the others subband might have some // code-blocks. if(precinctPartitionUsed){ continue; } } // If we arrive here, it means that the precinct exists in this // subband. precIdxExist = true; // Get in the vector cbv the code-blocks that "belong" to the // precinct whose index is 'pIdx' cbv = getCBlkInPrec(t,c,r,s,pIdx,cbv); cur_ttIncl = ttIncl[t][c][r][s][pIdx]; cur_ttMaxBP = ttMaxBP[t][c][r][s][pIdx]; cur_prevtIdxs = prevtIdxs[t][c][r][s]; cur_cbs = cbs[s]; cur_tIndx = tIndx[s]; ncbx = cur_ttIncl.getWidth(); ncby = cur_ttIncl.getHeight(); // Set tag tree values for this subband for( int numcb=1 ; numcb<cbv.size() ; numcb++ ){ b = ((Integer)cbv.elementAt(numcb)).intValue(); cbCoord = cbArrayI[t][c][r][s][b].idx; bx = cbCoord.x; by = cbCoord.y; // Save "offset" as tag trees are indexed from 0 if ( numcb==1 ) { firstCB_horIdx = bx; firstCB_vertIdx = by; } if (cur_tIndx[b] > cur_prevtIdxs[b] &&
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -