📄 pktencoder.java
字号:
maxsb = (r==0) ? 1 : 4; for(int p=0; p<nPrec; p++) { // loop on precincts if(p>=ppinfo[t][c][r].length) continue; prec = ppinfo[t][c][r][p]; for(int s=minsb; s<maxsb; s++) { // loop on subbands sb = (SubbandAn)root.getSubbandByIdx(r,s); if(prec.nblk[s]==0) continue; ccb = cblks[t][c][r][s]; mend = (prec.cblk[s]==null) ? 0 : prec.cblk[s].length; for(int m=0; m<mend; m++) { // Vert. code-blocks nend = (prec.cblk[s][m]==null) ? 0 : prec.cblk[s][m].length; for(int n=0; n<nend; n++) { cbCoord = prec.cblk[s][m][n].idx; b = cbCoord.x+cbCoord.y*sb.numCb.x; // If code-block has not to be scrambled if(!ccb[b].scrambled) continue; // If code-block not included in // any layer if(ccb[b].lastContribIdx<0) continue; realIdx = ccb[b]. truncIdxs[ccb[b].lastContribIdx]; // Add termination (Scrambling. // MIN_SIDE_INFO_LEN bytes + 2 // bytes (if layer scrambling) + // 1 byte (if seed ends with // 0xff)). // Check first if byte array is // enough big pos = ccb[b].truncRates[realIdx]; len = Scrambling.MIN_SIDE_INFO_LEN; if(ccb[b].scramblingType== ScramblingTypes. COMP_DOMAIN_SCRAMBLING) { len += 2; } byte[] eSeedBytes = null; int eSeedLen = 4; if(isEncryptionNeeded) { BigInteger eSeed; BigInteger neSeed = new BigInteger(""+ccb[b].seed); eSeed = RSAAlgorithm.rsa(neSeed, rsaMod, rsaExp); eSeedBytes = eSeed.toByteArray(); eSeedLen = eSeedBytes.length; len += eSeedLen; if((eSeedBytes[eSeedLen-1]&0xFF)== 0xFF) { len += 1; } } else { len += 4; if((ccb[b].seed&0xFF)==0xFF) { len += 1; } } if(ccb[b].data.length<pos+len) { // Enlarge the buffer byte[] tmpByte = new byte[pos+len]; int tLen = ccb[b].data.length; for(int pp=0; pp<tLen; pp++) { tmpByte[pp] = ccb[b].data[pp]; } ccb[b].data = tmpByte; } // Stopping marker ccb[b].data[pos++] = (byte)0xFF; ccb[b].data[pos++] = (byte)0x94; // Marker length ccb[b].data[pos++] = (byte)(len>>8); ccb[b].data[pos++] = (byte)(len&0xFF); // Psee if(ccb[b].scramblingType == ScramblingTypes. COMP_DOMAIN_SCRAMBLING) { ccb[b].data[pos++] = 0x2; } else { ccb[b].data[pos++] = 0x1; } if(isEncryptionNeeded) { // RSA flag ccb[b].data[pos-1] |= 0x10; } // PPsee if(ccb[b].scramblingType == ScramblingTypes. COMP_DOMAIN_SCRAMBLING) { ccb[b].data[pos++] = (byte) ((ccb[b].scrambOff>>8)&0xFF); ccb[b].data[pos++] = (byte) (ccb[b].scrambOff&0xFF); } // (Encrypted) seed if(isEncryptionNeeded) { int i=0; for(i=0; i<eSeedLen-1; i++) { ccb[b].data[pos++] = eSeedBytes[i]; } if((eSeedBytes[eSeedLen-1]&0xFF)== 0xFF) { ccb[b].data[pos++] = (byte)0xFE; ccb[b].data[pos++] = (byte)0x80; } else { ccb[b].data[pos++] = eSeedBytes[i]; } } else { seed = ccb[b].seed; ccb[b].data[pos++] = (byte)(0xFF&(seed>>8)); if((seed&0xFF)==0xFF) { ccb[b].data[pos++] = (byte)0xFE; ccb[b].data[pos++] = (byte)0x80; } else { ccb[b].data[pos++] = (byte)(0xFF&(seed)); } } // Correct truncation length ccb[b].truncRates[realIdx] += len; } // Horiz. code-blocks } // Vert. code-blocks } // loop on subbands } // loop on precincts } // loop on resolution levels } // loop on components } // loop on tiles } /** Add stopping marker and encrypted seed at the end of protected * code-blocks bit streams. */ public void scrambleLayersFrom(int lyStart,int numLayers, CBlkRateDistStats[][][][][] cblks, int[][][][][][] truncIdxs, Coord[][][] numPrec) { int nc = infoSrc.getNumComps(); int nt = infoSrc.getNumTiles(); SubbandAn sb,root; int mrl,nPrec,mend,nend,minsb,maxsb,b,ll,pos; CBlkRateDistStats[] ccb; Coord cbCoord; PrecInfo prec; long seed; int l,offScramb,stopScramb; int tmp; int[] mask = { 0x1, 0x2, 0x4, 0x8, 0x16, 0x32, 0x64, 0x128 }; int i,j,len; BitOutputBuffer bob = new BitOutputBuffer(); byte[] buf; int tmpIn, tmpOut; for(int t=0; t<nt; t++) { // loop on tiles for(int c=0; c<nc; c++) { // loop on components root = infoSrc.getAnSubbandTree(t,c); mrl = root.resLvl+1; for(int r=0; r<mrl ; r++) { // loop on resolution levels nPrec = numPrec[t][c][r].x*numPrec[t][c][r].y; minsb = (r==0) ? 0 : 1; maxsb = (r==0) ? 1 : 4; for(int p=0; p<nPrec; p++) { // loop on precincts if(p>=ppinfo[t][c][r].length) continue; prec = ppinfo[t][c][r][p]; for(int s=minsb; s<maxsb; s++) { // loop on subbands sb = (SubbandAn)root.getSubbandByIdx(r,s); if(prec.nblk[s]==0) continue; ccb = cblks[t][c][r][s]; mend = (prec.cblk[s]==null) ? 0 : prec.cblk[s].length; for(int m=0; m<mend; m++) { // Vert. code-blocks nend = (prec.cblk[s][m]==null) ? 0 : prec.cblk[s][m].length; for(int n=0; n<nend; n++) { cbCoord = prec.cblk[s][m][n].idx; b = cbCoord.x+cbCoord.y*sb.numCb.x; // If code-block has not to be scrambled if(!ccb[b].scrambled) continue; // If scrambling technique is in // the wavelet domain if(ccb[b].scramblingType!= ScramblingTypes. COMP_DOMAIN_SCRAMBLING) { continue; } // If code-block has not contribution if(lyStart>=numLayers) { ccb[b].scrambled = false; continue; } // If code-block not included in // any layer if(ccb[b].lastContribIdx<0) continue; // Find index of the last layer // this code-block contributed for(l=lyStart-1; l>=0; l--) { if(truncIdxs[t][l][c][r][s][b]!=-1) break; } if(l<=0) { offScramb = 0; } else { offScramb = ccb[b]. truncRates[ccb[b]. truncIdxs[truncIdxs [t][l][c] [r][s][b]]]; } // End the scrambling at the end // of the last coding pass stopScramb = ccb[b]. truncRates[ccb[b]. truncIdxs[ccb[b]. lastContribIdx]]; // Pseudo random inversion and // bit stuffing Random rd = new Random(ccb[b].seed); bob.reset(); for(i=offScramb; i<stopScramb; i++) { tmp = ccb[b].data[i]; tmpOut = 0; for(j=7; j>=0; j--) { tmpIn = (tmp>>j)&0x1; if(rd.nextBoolean()) { bob.writeBit(1-tmpIn); } else { bob.writeBit(tmpIn); } } } ccb[b].scrambOff = offScramb; buf = bob.getBuffer(); len = bob.getLength(); // Increase size if needed if(ccb[b].data.length<offScramb+len) { // Enlarge the buffer byte[] tmpByte = new byte[offScramb+len]; int tLen = ccb[b].data.length; for(int pp=0; pp<tLen; pp++) { tmpByte[pp] = ccb[b].data[pp]; } ccb[b].data = tmpByte; ccb[b]. truncRates[ccb[b]. truncIdxs[ccb[b]. lastContribIdx]] = offScramb+len; } // Copy scrambled bytes ccb[b].scrambOff = offScramb; for(i=0, pos=offScramb; i<len; i++) { ccb[b].data[pos++] = buf[i]; } } // Horiz. code-blocks } // Vert. code-blocks } // loop on subbands } // loop on precincts } // loop on resolution levels } // loop on components } // loop on tiles } /** * 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.</p> * * @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. *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -