📄 pktencoder.java
字号:
if (cur_prevtIdxs[b]<0) { cblen = cur_cbs[b]. truncRates[cur_cbs[b].truncIdxs[cur_tIndx[b]]]; System.arraycopy(cur_cbs[b].data,0, lbbuf,lblen,cblen); } else { cblen = cur_cbs[b]. truncRates[cur_cbs[b]. truncIdxs[cur_tIndx[b]]] - cur_cbs[b]. truncRates[cur_cbs[b]. truncIdxs[cur_prevtIdxs[b]]]; System. arraycopy(cur_cbs[b].data, cur_cbs[b]. truncRates[cur_cbs[b]. truncIdxs[cur_prevtIdxs [b]]], lbbuf,lblen,cblen); } lblen += cblen; // Verifies if this code-block contains new ROI // information if(cur_cbs[b].nROIcoeff!=0 && (cur_prevtIdxs[b]==-1 || cur_cbs[b].truncIdxs[cur_prevtIdxs[b]] <= cur_cbs[b].nROIcp-1) ) { roiInPkt = true; roiLen = lblen; } // Update truncation point cur_prevtIdxs[b] = cur_tIndx[b]; } } // End loop on horizontal code-blocks } // End loop on vertical code-blocks } // End loop on subbands packetWritable = true; // Must never happen if(hbuf.getLength()==0) { throw new Error("You have found a bug in PktEncoder, method:"+ " encodePacket"); } return hbuf; } /** * Returns the buffer of the body of the last encoded packet. The length * of the body can be retrieved with the getLastBodyLen() method. The * length of the array returned by this method may be larger than the * actual body length. * * @return The buffer of body of the last encoded packet. * * @exception IllegalArgumentException If no packet has been coded since * last reset(), last restore(), or object creation. * * @see #getLastBodyLen * */ public byte[] getLastBodyBuf() { if (lbbuf==null) { throw new IllegalArgumentException(); } return lbbuf; } /** * Returns the length of the body of the last encoded packet, in * bytes. The body itself can be retrieved with the getLastBodyBuf() * method. * * @return The length of the body of last encoded packet, in bytes. * * @see #getLastBodyBuf * */ public int getLastBodyLen() { return lblen; } /** * Saves the current state of this object. The last saved state * can be restored with the restore() method. * * @see #restore * */ public void save() { int maxsbi,minsbi; // Have we done any save yet? if (bak_lblock==null) { // Allocate backup buffers bak_lblock = new int[ttIncl.length][][][][]; bak_prevtIdxs = new int[ttIncl.length][][][][]; for (int t=ttIncl.length-1; t>=0; t--) { bak_lblock[t] = new int[ttIncl[t].length][][][]; bak_prevtIdxs[t] = new int[ttIncl[t].length][][][]; for (int c=ttIncl[t].length-1; c>=0; c--) { bak_lblock[t][c] = new int[lblock[t][c].length][][]; bak_prevtIdxs[t][c] = new int[ttIncl[t][c].length][][]; for (int r=lblock[t][c].length-1; r>=0; r--) { bak_lblock[t][c][r] = new int[lblock[t][c][r].length][]; bak_prevtIdxs[t][c][r] = new int[prevtIdxs[t][c][r].length][]; minsbi = (r==0) ? 0 : 1; maxsbi = (r==0) ? 1 : 4; for (int s=minsbi; s<maxsbi; s++) { bak_lblock[t][c][r][s] = new int[lblock[t][c][r][s].length]; bak_prevtIdxs[t][c][r][s] = new int[prevtIdxs[t][c][r][s].length]; } } } } } //-- Save the data // Use reference caches to minimize array access overhead TagTreeEncoder ttIncl_t_c[][][], ttMaxBP_t_c[][][], ttIncl_t_c_r[][], ttMaxBP_t_c_r[][]; int lblock_t_c[][][], bak_lblock_t_c[][][], prevtIdxs_t_c_r[][], bak_prevtIdxs_t_c_r[][]; // Loop on tiles for (int t=ttIncl.length-1; t>=0; t--) { // Loop on components for (int c=ttIncl[t].length-1; c>=0; c--) { // Initialize reference caches lblock_t_c = lblock[t][c]; bak_lblock_t_c = bak_lblock[t][c]; ttIncl_t_c = ttIncl[t][c]; ttMaxBP_t_c = ttMaxBP[t][c]; // Loop on resolution levels for (int r=lblock_t_c.length-1; r>=0; r--) { // Initialize reference caches ttIncl_t_c_r = ttIncl_t_c[r]; ttMaxBP_t_c_r = ttMaxBP_t_c[r]; prevtIdxs_t_c_r = prevtIdxs[t][c][r]; bak_prevtIdxs_t_c_r = bak_prevtIdxs[t][c][r]; // Loop on subbands minsbi = (r==0) ? 0 : 1; maxsbi = (r==0) ? 1 : 4; for (int s=minsbi; s<maxsbi; s++) { // Save 'lblock' System.arraycopy(lblock_t_c[r][s],0, bak_lblock_t_c[r][s],0, lblock_t_c[r][s].length); // Save 'prevtIdxs' System.arraycopy(prevtIdxs_t_c_r[s],0, bak_prevtIdxs_t_c_r[s],0, prevtIdxs_t_c_r[s].length); } // End loop on subbands // Loop on precincts for(int p=ppinfo[t][c][r].length-1; p>=0; p--) { if(p<ttIncl_t_c_r.length) { // Loop on subbands for(int s=minsbi; s<maxsbi; s++) { ttIncl_t_c_r[p][s].save(); ttMaxBP_t_c_r[p][s].save(); } // End loop on subbands } } // End loop on precincts } // End loop on resolutions } // End loop on components } // End loop on tiles // Set the saved state saved = true; } /** * Restores the last saved state of this object. An * IllegalArgumentException is thrown if no state has been saved. * * @see #save * */ public void restore() { int maxsbi,minsbi; if (!saved) { throw new IllegalArgumentException(); } // Invalidate last encoded body buffer lbbuf = null; //-- Restore tha data // Use reference caches to minimize array access overhead TagTreeEncoder ttIncl_t_c[][][],ttMaxBP_t_c[][][],ttIncl_t_c_r[][], ttMaxBP_t_c_r[][]; int lblock_t_c[][][],bak_lblock_t_c[][][],prevtIdxs_t_c_r[][], bak_prevtIdxs_t_c_r[][]; // Loop on tiles for (int t=ttIncl.length-1; t>=0; t--) { // Loop on components for (int c=ttIncl[t].length-1; c>=0; c--) { // Initialize reference caches lblock_t_c = lblock[t][c]; bak_lblock_t_c = bak_lblock[t][c]; ttIncl_t_c = ttIncl[t][c]; ttMaxBP_t_c = ttMaxBP[t][c]; // Loop on resolution levels for (int r=lblock_t_c.length-1; r>=0; r--) { // Initialize reference caches ttIncl_t_c_r = ttIncl_t_c[r]; ttMaxBP_t_c_r = ttMaxBP_t_c[r]; prevtIdxs_t_c_r = prevtIdxs[t][c][r]; bak_prevtIdxs_t_c_r = bak_prevtIdxs[t][c][r]; // Loop on subbands minsbi = (r==0) ? 0 : 1; maxsbi = (r==0) ? 1 : 4; for (int s=minsbi; s<maxsbi; s++) { // Restore 'lblock' System.arraycopy(bak_lblock_t_c[r][s],0, lblock_t_c[r][s],0, lblock_t_c[r][s].length); // Restore 'prevtIdxs' System.arraycopy(bak_prevtIdxs_t_c_r[s],0, prevtIdxs_t_c_r[s],0, prevtIdxs_t_c_r[s].length); } // End loop on subbands // Loop on precincts for(int p=ppinfo[t][c][r].length-1; p>=0; p--) { if(p<ttIncl_t_c_r.length) { // Loop on subbands for(int s=minsbi; s<maxsbi; s++) { ttIncl_t_c_r[p][s].restore(); ttMaxBP_t_c_r[p][s].restore(); } // End loop on subbands } } // End loop on precincts } // End loop on resolution levels } // End loop on components } // End loop on tiles } /** * Resets the state of the object to the initial state, as if the object * was just created. * */ public void reset() { int maxsbi,minsbi; // Invalidate save saved = false; // Invalidate last encoded body buffer lbbuf = null; // Reinitialize each element in the arrays // Use reference caches to minimize array access overhead TagTreeEncoder ttIncl_t_c[][][],ttMaxBP_t_c[][][],ttIncl_t_c_r[][], ttMaxBP_t_c_r[][]; int lblock_t_c[][][],prevtIdxs_t_c_r[][]; // Loop on tiles for (int t=ttIncl.length-1; t>=0; t--) { // Loop on components for (int c=ttIncl[t].length-1; c>=0; c--) { // Initialize reference caches lblock_t_c = lblock[t][c]; ttIncl_t_c = ttIncl[t][c]; ttMaxBP_t_c = ttMaxBP[t][c]; // Loop on resolution levels for (int r=lblock_t_c.length-1; r>=0; r--) { // Initialize reference caches ttIncl_t_c_r = ttIncl_t_c[r]; ttMaxBP_t_c_r = ttMaxBP_t_c[r]; prevtIdxs_t_c_r = prevtIdxs[t][c][r]; // Loop on subbands minsbi = (r==0) ? 0 : 1; maxsbi = (r==0) ? 1 : 4; for (int s=minsbi; s<maxsbi; s++) { // Reset 'prevtIdxs' ArrayUtil.intArraySet(prevtIdxs_t_c_r[s],-1); // Reset 'lblock' ArrayUtil.intArraySet(lblock_t_c[r][s],INIT_LBLOCK); } // End loop on subbands // Loop on precincts for(int p=ppinfo[t][c][r].length-1; p>=0; p--) { if(p<ttIncl_t_c_r.length) { // Loop on subbands for(int s=minsbi; s<maxsbi; s++) { ttIncl_t_c_r[p][s].reset(); ttMaxBP_t_c_r[p][s].reset(); } // End loop on subbands } } // End loop on precincts } // End loop on resolution levels } // End loop on components } // End loop on tiles } /** * Returns true if the current packet is writable i.e. should be written. * Returns false otherwise. * */ public boolean isPacketWritable() { return packetWritable; } /** * Tells if there was ROI information in the last written packet * */ public boolean isROIinPkt(){ return roiInPkt; } /** Gives the length to read in cur
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -