📄 pktencoder.java
字号:
* * @see #restore * */ public void save() { int s,r,n,t,p; 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 (t=ttIncl.length-1; t>=0; t--) { bak_lblock[t] = new int[ttIncl[t].length][][][]; bak_prevtIdxs[t] = new int[ttIncl[t].length][][][]; for (n=ttIncl[t].length-1; n>=0; n--) { bak_lblock[t][n] = new int[lblock[t][n].length][][]; bak_prevtIdxs[t][n] = new int[ttIncl[t][n].length][][]; for (r=lblock[t][n].length-1; r>=0; r--) { bak_lblock[t][n][r] = new int[lblock[t][n][r].length][]; bak_prevtIdxs[t][n][r] = new int[ttIncl[t][n][r].length][]; maxsbi = ttIncl[t][n][r].length; minsbi = maxsbi>>2; // minsbi = maxsbi/4; for (s = minsbi; s<maxsbi; s++) { bak_lblock[t][n][r][s] = new int[lblock[t][n][r][s].length]; bak_prevtIdxs[t][n][r][s] = new int[prevtIdxs[t][n][r][s].length]; } } } } } //-- Save the data // Use reference caches to minimize array access overhead TagTreeEncoder ttIncl_t_n[][][], ttMaxBP_t_n[][][], ttIncl_t_n_r[][], ttMaxBP_t_n_r[][]; int lblock_t_n[][][], bak_lblock_t_n[][][], prevtIdxs_t_n_r[][], bak_prevtIdxs_t_n_r[][]; // Loop on tiles for (t=ttIncl.length-1; t>=0; t--) { // Loop on components for (n=ttIncl[t].length-1; n>=0; n--) { // Initialize reference caches lblock_t_n = lblock[t][n]; bak_lblock_t_n = bak_lblock[t][n]; ttIncl_t_n = ttIncl[t][n]; ttMaxBP_t_n = ttMaxBP[t][n]; // Loop on resolution levels for (r=lblock_t_n.length-1; r>=0; r--) { // Initialize reference caches ttIncl_t_n_r = ttIncl_t_n[r]; ttMaxBP_t_n_r = ttMaxBP_t_n[r]; prevtIdxs_t_n_r = prevtIdxs[t][n][r]; bak_prevtIdxs_t_n_r = bak_prevtIdxs[t][n][r]; // Loop on subbands maxsbi = ttIncl_t_n_r.length; minsbi = maxsbi>>2; // minsbi = maxsbi/4; for (s = minsbi; s<maxsbi; s++) { // Save 'lblock' System.arraycopy(lblock_t_n[r][s],0, bak_lblock_t_n[r][s],0, lblock_t_n[r][s].length); // Save 'prevtIdxs' System.arraycopy(prevtIdxs_t_n_r[s],0, bak_prevtIdxs_t_n_r[s],0, prevtIdxs_t_n_r[s].length); if ( precArrayI[t][n][r][s] != null ) { for (p=precArrayI[t][n][r][s].length-1 ; p>=0 ; p--) { if ( p<ttIncl_t_n_r[s].length ) { // Save tag trees ttIncl_t_n_r[s][p].save(); ttMaxBP_t_n_r[s][p].save(); } } } } } } } // 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 s,r,n,t,p; 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_n[][][], ttMaxBP_t_n[][][], ttIncl_t_n_r[][], ttMaxBP_t_n_r[][]; int lblock_t_n[][][], bak_lblock_t_n[][][], prevtIdxs_t_n_r[][], bak_prevtIdxs_t_n_r[][]; // Loop on tiles for (t=ttIncl.length-1; t>=0; t--) { // Loop on components for (n=ttIncl[t].length-1; n>=0; n--) { // Initialize reference caches lblock_t_n = lblock[t][n]; bak_lblock_t_n = bak_lblock[t][n]; ttIncl_t_n = ttIncl[t][n]; ttMaxBP_t_n = ttMaxBP[t][n]; // Loop on resolution levels for (r=lblock_t_n.length-1; r>=0; r--) { // Initialize reference caches ttIncl_t_n_r = ttIncl_t_n[r]; ttMaxBP_t_n_r = ttMaxBP_t_n[r]; prevtIdxs_t_n_r = prevtIdxs[t][n][r]; bak_prevtIdxs_t_n_r = bak_prevtIdxs[t][n][r]; // Loop on subbands maxsbi = ttIncl_t_n_r.length; minsbi = maxsbi>>2; // minsbi = maxsbi/4; for (s = minsbi; s<maxsbi; s++) { // Restore 'lblock' System.arraycopy(bak_lblock_t_n[r][s],0, lblock_t_n[r][s],0, lblock_t_n[r][s].length); // Restore 'prevtIdxs' System.arraycopy(bak_prevtIdxs_t_n_r[s],0, prevtIdxs_t_n_r[s],0, prevtIdxs_t_n_r[s].length); // Loop on precincts if ( precArrayI[t][n][r][s] != null ) { for(p=precArrayI[t][n][r][s].length-1 ; p>=0 ; p--) { if ( p<ttIncl_t_n_r[s].length ) { // Restore tag trees ttIncl_t_n_r[s][p].restore(); ttMaxBP_t_n_r[s][p].restore(); } } } } } } } } /** * Resets the state of the object to the initial state, as if the object * was just created. * */ public void reset() { int s,r,n,t,p; 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_n[][][], ttMaxBP_t_n[][][], ttIncl_t_n_r[][], ttMaxBP_t_n_r[][]; int lblock_t_n[][][], prevtIdxs_t_n_r[][]; // Loop on tiles for (t=ttIncl.length-1; t>=0; t--) { // Loop on components for (n=ttIncl[t].length-1; n>=0; n--) { // Initialize reference caches lblock_t_n = lblock[t][n]; ttIncl_t_n = ttIncl[t][n]; ttMaxBP_t_n = ttMaxBP[t][n]; // Loop on resolution levels for (r=lblock_t_n.length-1; r>=0; r--) { // Initialize reference caches ttIncl_t_n_r = ttIncl_t_n[r]; ttMaxBP_t_n_r = ttMaxBP_t_n[r]; prevtIdxs_t_n_r = prevtIdxs[t][n][r]; // Loop on subbands maxsbi = ttIncl_t_n_r.length; minsbi = maxsbi>>2; // minsbi = maxsbi/4; for (s = minsbi; s<maxsbi; s++) { // Reset 'prevtIdxs' ArrayUtil.intArraySet(prevtIdxs_t_n_r[s],-1); // Reset 'lblock' ArrayUtil.intArraySet(lblock_t_n[r][s], INIT_LBLOCK); // Loop on precincts if ( precArrayI[t][n][r][s] != null ) { for (p=precArrayI[t][n][r][s].length-1;p>=0;p--) { if ( p<ttIncl_t_n_r[s].length ) { // Reset tag trees ttIncl_t_n_r[s][p].reset(); ttMaxBP_t_n_r[s][p].reset(); } } } } } } } } /** * Creates the arrays incArray and incArrayMax. The first array (incArray) * contains the increment step used for each component, each tile and each * resolution level. The second one (incArrayMax) contains the smallest * increment. This is used when looking for precinct inclusion. * * @param t the tile index * * @param c the component index * */ private void buildIncArrays(int c, int t) { int ppx, ppy; // Precinct partition dimensions int l; // Resolution level Coord inc, incMax; if ( incArrayMax[t][c]==null ) { // Allocate maximum increment array if it does not exist incArrayMax[t][c] = new Coord(); } else { // Already allocated and filled return; } incMax = incArrayMax[t][c]; for ( l=0 ; l<mrl[t][c]+1 ; l++ ) { // Get precinct partition dimensions ppx = infoSrc.getPPX(t, c, l); ppy = infoSrc.getPPY(t, c, l); if ( incArray[t][c][l]==null ) { // Allocate increment array for resolution level 'l' if it // does not exist incArray[t][c][l] = new Coord(); } inc = incArray[t][c][l]; inc.x = infoSrc.getCompSubsX(c); inc.x <<= MathUtil.log2(ppx) + mrl[t][c] - l; if ( incMax.x==0 || inc.x<incMax.x ) { // Save smallest horizontal increment incMax.x = inc.x; } inc.y = infoSrc.getCompSubsY(c); inc.y <<= MathUtil.log2(ppy) + mrl[t][c] - l; if ( incMax.y==0 || inc.y<incMax.y ) { // Save smallest vertical increment incMax.y = inc.y; } } } /** * Creates the arrays sot_eotArray and sot_eotArrayMax. The first array * (sot_eotArray) contains the start/end of tile coordinates at each * resolution level and the second array (sot_eotArrayMax) contains the * start/end of tile coordinates for the highest resolution level using * the smallest increment step * * @param t the tile index * * @param c the component index * */ private void buildSotEotArrays(int c, int t) { int l; Coord sot_eotMax[] = null; Coord sot_eot[] = null; // Create and initialise the maximum increment array // Allocate and initialise if elements do not exist if ( sot_eotArrayMax[t][c][0]==null ) { sot_eotArrayMax[t][c][0] = new Coord(); // start of tile sot_eotArrayMax[t][c][1] = new Coord(); // end of tile sot_eotMax = sot_eotArrayMax[t][c]; // Calculate the start/enf of tile for the highest resolution and // smallest increment step if (incArrayMax[t][c].x == 0) { sot_eotMax[0].x = 0; sot_eotMax[1].x = 1; incArrayMax[t][c].x = 1; } else { sot_eotMax[0].x = infoSrc.getULX(c); sot_eotMax[1].x = sot_eotMax[0].x + infoSrc.getWidth(); sot_eotMax[0].x &= ~(incArrayMax[t][c].x-1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -