📄 ebcotrateallocator.java
字号:
for(int l=0; l<numLayers; l++){ //loop on layers maxBytes = layers[l].maxBytes; if(layers[l].optimize){ rdThreshold = optimizeBitstreamLayer(l,rdThreshold,maxBytes,actualBytes); } else{ if( (l<=0) || (l>=numLayers-1) ) throw new IllegalArgumentException("The first and the"+ " last layer "+ "thresholds"+ " must be optimized"); rdThreshold = estimateLayerThreshold(maxBytes,layers[l-1]); } src.setTile(0,0); for(int t=0; t<numTiles; t++){ //loop on tiles if(l==0){ // Tile header headEnc.reset(); headEnc.encodeTilePartHeader(0,t); tileLengths[t] += headEnc.getLength(); } for(int c=0; c < numComps; c++){ //loop on components // set boolean sopUsed here (SOP markers) sopUsed = ((String)encSpec.sops.getTileDef(t)). equalsIgnoreCase("on"); // set boolean ephUsed here (EPH markers) ephUsed = ((String)encSpec.ephs.getTileDef(t)). equalsIgnoreCase("on"); // Go to LL band sb = src.getSubbandTree(t,c); while (sb.subb_LL != null) { sb = sb.subb_LL; } numLvls = mrl[t][c]+1; for(int r=0; r<numLvls ; r++) { precinctIdx = 0; // Start-end of tile-component xys = packetEnc.getSotEotArrayMax(t,c); x0 = xys[0].x; y0 = xys[0].y; x1 = xys[1].x; y1 = xys[1].y; xyInc = packetEnc.getIncArrayMax(t,c); x_inc = xyInc.x; y_inc = xyInc.y; xyInc = packetEnc.getIncArray(t,c,r); x_inc_rl = xyInc.x; y_inc_rl = xyInc.y; xys = packetEnc.getSotEotArray(t,c,r); x0_rl = xys[0].x; y0_rl = xys[0].y; for(int yr=y0 ; yr<y1 ; yr+=y_inc ) for(int xr=x0 ; xr<x1 ; xr+=x_inc ) if ( ( (xr==x0) || (xr%x_inc_rl==0) ) && ( (yr==y0) || (yr%y_inc_rl==0) ) ){ if(precinctIdx>=maxNumPrec[t][c][r].x* maxNumPrec[t][c][r].y) continue; findTruncIndices(l,c,r,t,sb,rdThreshold, precinctIdx); hBuff = packetEnc. encodePacket(l+1,c,r,t, cblks[t][c][r], truncIdxs[t][l][c][r], hBuff, bBuff, precinctIdx); if(packetEnc.isPacketWritable()){ tmp = bsWriter. writePacketHead(hBuff.getBuffer(), hBuff.getLength(), true, sopUsed, ephUsed); tmp += bsWriter. writePacketBody(packetEnc. getLastBodyBuf(), packetEnc. getLastBodyLen(), true,packetEnc. isROIinPkt(), packetEnc. getROILen()); actualBytes += tmp; tileLengths[t] += tmp; } precinctIdx++; } // End loop on precincts sb = sb.parent; } // End loop on resolution levels } // End loop on components if( t!=numTiles-1 ){ src.nextTile(); } } // end loop on tiles layers[l].rdThreshold = rdThreshold; layers[l].actualBytes = actualBytes; } // end loop on layers if (DO_TIMING) buildTime += System.currentTimeMillis()-stime; // The bit-stream was not yet generated (only simulated). if (DO_TIMING) stime = System.currentTimeMillis(); // +--------------------------------------------------+ // | Write tiles according to their Progression order | // +--------------------------------------------------+ // Reset the packet encoder before writing all packets packetEnc.reset(); Progression[] prog; // Progression(s) in each tile int cs,ce,rs,re,lye; for(int t=0; t<numTiles; t++){ //loop on tiles int[][] lysA; // layer index start for each component and // resolution level int[][] lys = new int[numComps][]; for(int c=0; c<numComps; c++){ lys[c] = new int[mrl[t][c]+1]; } // Tile header headEnc.reset(); headEnc.encodeTilePartHeader(tileLengths[t],t); bsWriter.commitBitstreamHeader(headEnc); prog = (Progression[])encSpec.ps.getTileDef(t); for(int prg=0; prg<prog.length;prg++){ // Loop on progression lye = prog[prg].lye; cs = prog[prg].cs; ce = prog[prg].ce; rs = prog[prg].rs; re = prog[prg].re; switch(prog[prg].type){ case ProgressionType.RES_LY_COMP_POS_PROG: writeResLyCompPos(t,rs,re,cs,ce,lys,lye); break; case ProgressionType.LY_RES_COMP_POS_PROG: writeLyResCompPos(t,rs,re,cs,ce,lys,lye); break; case ProgressionType.POS_COMP_RES_LY_PROG: writePosCompResLy(t,rs,re,cs,ce,lys,lye); break; case ProgressionType.COMP_POS_RES_LY_PROG: writeCompPosResLy(t,rs,re,cs,ce,lys,lye); break; case ProgressionType.RES_POS_COMP_LY_PROG: writeResPosCompLy(t,rs,re,cs,ce,lys,lye); break; default: throw new Error("Unsupported bit stream progression type"); } // switch on progression // Update next first layer index for(int c=cs; c<ce; c++) for(int r=rs; r<re; r++){ if(r>mrl[t][c]) continue; lys[c][r] = lye; } } // End loop on progression } // End loop on tiles if (DO_TIMING) writeTime += System.currentTimeMillis()-stime; } /** * Write a piece of bit stream according to the * RES_LY_COMP_POS_PROG progression mode and between given bounds * * @param t Tile index * * @param rs First resolution level index * * @param re Last resolution level index * * @param cs First component index * * @param ce Last component index * * @param lys First layer index for each component and resolution * * @param lye Index of the last layer * */ public void writeResLyCompPos(int t,int rs,int re,int cs,int ce, int lys[][],int lye) throws IOException{ boolean sopUsed; // Should SOP markers be used ? boolean ephUsed; // Should EPH markers be used ? int[][] mrl = packetEnc.getMRL(); int numComps = src.getNumComps(); int x0, y0, x1, y1; int x_inc, y_inc, x_inc_rl, y_inc_rl; int x0_rl, y0_rl, precinctIdx; int precinctIdxA[][][]; Coord xys[],xyInc; SubbandAn sb; float threshold; BitOutputBuffer hBuff = null; byte[] bBuff = null; // Max number of decomposition levels in the tile int numLvls = mrl[t][0]; for(int c=0; c < numComps; c++) if(mrl[t][c]>numLvls) numLvls = mrl[t][c]; numLvls++; precinctIdxA = new int[numComps][numLvls][numLayers]; int minlys; // minimum layer start index of each component for(int r=rs; r<re; r++){ //loop on resolution levels if(r>=numLvls) continue; minlys = 100000; for(int c=cs; c<ce; c++) { if( r<lys[c].length && lys[c][r]<minlys ) minlys = lys[c][r]; } for(int l=minlys; l<lye; l++){ //loop on layers for(int c=cs; c<ce; c++){//loop on components if(r>=lys[c].length) continue; if(l<lys[c][r]) continue; // If no more decomposition levels for this // component if(r>mrl[t][c]) continue; xys = packetEnc.getSotEotArrayMax(t,c); x0 = xys[0].x; y0 = xys[0].y; x1 = xys[1].x; y1 = xys[1].y; xyInc = packetEnc.getIncArrayMax(t, c); x_inc = xyInc.x; y_inc = xyInc.y; xyInc = packetEnc.getIncArray(t,c,r); x_inc_rl = xyInc.x; y_inc_rl = xyInc.y; xys = packetEnc.getSotEotArray(t,c,r); x0_rl = xys[0].x; y0_rl = xys[0].y; for(int yr=y0 ; yr<y1 ; yr+=y_inc ) for(int xr=x0 ; xr<x1 ; xr+=x_inc ) if ( ( (xr==x0) || (xr%x_inc_rl==0) ) && ( (yr==y0) || (yr%y_inc_rl==0) ) ){ if(precinctIdxA[c][r][l]>= maxNumPrec[t][c][r].x*maxNumPrec[t][c][r].y) continue; precinctIdx = precinctIdxA[c][r][l]; // set boolean sopUsed here (SOP markers) sopUsed = ((String)encSpec.sops. getTileDef(t)).equals("on"); // set boolean ephUsed here (EPH // markers) ephUsed = ((String)encSpec.ephs. getTileDef(t)).equals("on"); sb = src.getSubbandTree(t,c); for(int i=mrl[t][c]; i>r; i--){ sb = sb.subb_LL; } threshold = layers[l].rdThreshold; findTruncIndices(l,c,r,t,sb,threshold, precinctIdx); hBuff = packetEnc. encodePacket(l+1,c,r,t,cblks[t][c][r], truncIdxs[t][l][c][r], hBuff,bBuff,precinctIdx); if(packetEnc.isPacketWritable()){ bsWriter. writePacketHead(hBuff.getBuffer(), hBuff.getLength(), false,sopUsed,ephUsed); bsWriter. writePacketBody(packetEnc. getLastBodyBuf(), packetEnc. getLastBodyLen(), false, packetEnc.isROIinPkt(), packetEnc.getROILen()); } precinctIdxA[c][r][l]++; } // End loop on precincts } // End loop on components } // End loop on layers } // End loop on resolution levels } /** * Write a piece of bit stream according to the * LY_RES_COMP_POS_PROG progression mode and between given bounds * * @param t Tile index * * @param rs First resolution level index * * @param re Last resolution level index * * @param cs First component index * * @param ce Last component index * * @param lys First layer index for each component and resolution * * @param lye Index of the last layer * */ public void writeLyResCompPos(int t,int rs,int re,int cs,int ce, int[][] lys,int lye) throws IOException{ boolean sopUsed; // Should SOP markers be used ? boolean ephUsed; // Should EPH markers be used ? int[][] mrl = packetEnc.getMRL(); int numComps = src.getNumComps(); int x0, y0, x1, y1; int x_inc, y_inc, x_inc_rl, y_inc_rl; int x0_rl, y0_rl, precinctIdx; int precinctIdxA[][][]; Coord xys[],xyInc; SubbandAn sb; float threshold; BitOutputBuffer hBuff = null; byte[] bBuff = null; // Max number of decomposition levels in each tile int numLvls = mrl[t][0]; for(int c=0; c < numComps; c++) if(mrl[t][c]>numLvls) numLvls = mrl[t][c]; numLvls++; int minlys; // minimum layer start index of each component and // resolution minlys = 10000; for(int c=cs; c<ce; c++){ //loop on components if(c>=lys.length) continue; for(int r=rs; r<re; r++) {//loop on resolution levels if(r>=lys[c].length) continue;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -