ebcotrateallocator.java

来自「jpeg2000编解码」· Java 代码 · 共 1,684 行 · 第 1/5 页

JAVA
1,684
字号
		    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>mrlc[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 nc = src.getNumComps();	int[] mrl = new int[nc];        SubbandAn sb;        float threshold;        BitOutputBuffer hBuff = null;        byte[] bBuff = null;        int nPrec = 0;	// Max number of resolution levels in the tile	int maxResLvl = 0;	for(int c=0; c<nc; c++) {            mrl[c] = src.getAnSubbandTree(t,c).resLvl;	    if(mrl[c]>maxResLvl) maxResLvl = mrl[c];        }		int minlys; // minimum layer start index of each component		    	for(int r=rs; r<re; r++) { //loop on resolution levels            if(r>maxResLvl) 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[c]) continue;		                        nPrec = numPrec[t][c][r].x*numPrec[t][c][r].y;                    for(int p=0; p<nPrec; p++) { // loop on precincts							// 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.getAnSubbandTree(t,c);                        for(int i=mrl[c]; i>r; i--) {                            sb = sb.subb_LL;                        }				                        threshold = layers[l].rdThreshold;                        findTruncIndices(l,c,r,t,sb,threshold,p);				                        hBuff = pktEnc.encodePacket(l+1,c,r,t,cblks[t][c][r],                                                    truncIdxs[t][l][c][r],                                                    hBuff,bBuff,p);					                            if(pktEnc.isPacketWritable()) {                            bsWriter.writePacketHead(hBuff.getBuffer(),                                                     hBuff.getLength(),                                                      false,sopUsed,ephUsed);                            bsWriter.writePacketBody(pktEnc.getLastBodyBuf(),                                                     pktEnc.getLastBodyLen(),                                                     false,pktEnc.isROIinPkt(),                                                     pktEnc.getROILen());                        }                                            } // 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 nc = src.getNumComps();	int mrl;        SubbandAn sb;        float threshold;        BitOutputBuffer hBuff = null;        byte[] bBuff = null;        int nPrec = 0;	int minlys = 100000; // minimum layer start index of each component        for(int c=cs; c<ce; c++) {            for(int r=0; r<lys.length; r++) {                if(lys[c]!=null && r<lys[c].length && lys[c][r]<minlys ) {		    minlys = lys[c][r];                }            }        }        for(int l=minlys; l<lye; l++) { // loop on layers            for(int r=rs; r<re; r++) { // loop on resolution level                for(int c=cs; c<ce; c++) { // loop on components                    mrl = src.getAnSubbandTree(t,c).resLvl;                    if(r>mrl) continue;                    if(r>=lys[c].length) continue;                    if(l<lys[c][r]) continue;                    nPrec = numPrec[t][c][r].x*numPrec[t][c][r].y;                    for(int p=0; p<nPrec; p++) { // loop on precincts                        			// 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.getAnSubbandTree(t,c);                        for(int i=mrl; i>r; i--) {                            sb = sb.subb_LL;                        }                        threshold = layers[l].rdThreshold;                        findTruncIndices(l,c,r,t,sb,threshold,p);				                        hBuff = pktEnc.encodePacket(l+1,c,r,t,cblks[t][c][r],                                                    truncIdxs[t][l][c][r],                                                    hBuff,bBuff,p);					                            if(pktEnc.isPacketWritable()) {                            bsWriter.writePacketHead(hBuff.getBuffer(),                                                     hBuff.getLength(),                                                      false,sopUsed,ephUsed);                            bsWriter.writePacketBody(pktEnc.getLastBodyBuf(),                                                     pktEnc.getLastBodyLen(),                                                     false,pktEnc.isROIinPkt(),                                                     pktEnc.getROILen());                        }                    } // end loop on precincts                } // end loop on components            } // end loop on resolution levels        } // end loop on layers    }    /**      * Write a piece of bit stream according to the     * COMP_POS_RES_LY_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 writePosCompResLy(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 nc = src.getNumComps();	int mrl;        SubbandAn sb;        float threshold;        BitOutputBuffer hBuff = null;        byte[] bBuff = null;        // Computes current tile offset in the reference grid        Coord nTiles = src.getNumTiles(null);        Coord tileI = src.getTile(null);        int x0siz = src.getImgULX();        int y0siz = src.getImgULY();        int xsiz = x0siz + src.getImgWidth();        int ysiz = y0siz + src.getImgHeight();        int xt0siz = src.getTilePartULX();        int yt0siz = src.getTilePartULY();        int xtsiz = src.getNomTileWidth();        int ytsiz = src.getNomTileHeight();        int tx0 = (tileI.x==0) ? x0siz : xt0siz+tileI.x*xtsiz;        int ty0 = (tileI.y==0) ? y0siz : yt0siz+tileI.y*ytsiz;        int tx1 = (tileI.x!=nTiles.x-1) ? xt0siz+(tileI.x+1)*xtsiz : xsiz;        int ty1 = (tileI.y!=nTiles.y-1) ? yt0siz+(tileI.y+1)*ytsiz : ysiz;        // Get precinct information (number,distance between two consecutive        // precincts in the reference grid) in each component and resolution        // level        PrecInfo prec; // temporary variable        int p; // Current precinct index        int gcd_x = 0; // Horiz. distance between 2 precincts in the ref. grid        int gcd_y = 0; // Vert. distance between 2 precincts in the ref. grid        int nPrec = 0; // Total number of found precincts        int[][] nextPrec = new int [ce][]; // Next precinct index in each        // component and resolution level        int minlys = 100000; // minimum layer start index of each component        int minx = tx1; // Horiz. offset of the second precinct in the        // reference grid        int miny = ty1; // Vert. offset of the second precinct in the        // reference grid.         int maxx = tx0; // Max. horiz. offset of precincts in the ref. grid        int maxy = ty0; // Max. vert. offset of precincts in the ref. grid        for(int c=cs; c<ce; c++) {            mrl = src.getAnSubbandTree(t,c).resLvl;            nextPrec[c] = new int[mrl+1];            for(int r=rs; r<re; r++) {                if(r>mrl) continue;                if (r<lys[c].length && lys[c][r]<minlys) {		    minlys = lys[c][r];                }                p = numPrec[t][c][r].y*numPrec[t][c][r].x-1;                for(; p>=0; p--) {                    prec = pktEnc.getPrecInfo(t,c,r,p);                    if(prec.rgulx!=tx0) {                        if(prec.rgulx<minx) minx = prec.rgulx;                        if(prec.rgulx>maxx) maxx = prec.rgulx;                    }                    if(prec.rguly!=ty0){                        if(prec.rguly<miny) miny = prec.rguly;                        if(prec.rguly>maxy) maxy = prec.rguly;                    }                    if(nPrec==0) {                        gcd_x = prec.rgw;                        gcd_y = prec.rgh;                    } else {                        gcd_x = MathUtil.gcd(gcd_x,prec.rgw);                        gcd_y = MathUtil.gcd(gcd_y,prec.rgh);                    }                    nPrec++;                } // precincts            } // resolution levels        } // components        if(nPrec==0) {            throw new Error("Image cannot have no precinct");        }        int pyend = (maxy-miny)/gcd_y+1;        int pxend = (maxx-minx)/gcd_x+1;        int y = ty0;        int x = tx0;        for(int py=0; py<=pyend; py++) { // Vertical precincts            for(int px=0; px<=pxend; px++) { // Horiz. precincts                for(int c=cs; c<ce; c++) { // Components                    mrl = src.getAnSubbandTree(t,c).resLvl;                    for(int r=rs; r<re; r++) { // Resolution levels                        if(r>mrl) continue;                                                if(nextPrec[c][r] >=                           numPrec[t][c][r].x*numPrec[t][c][r].y) {                            continue;                        }                        prec = pktEnc.getPrecInfo(t,c,r,nextPrec[c][r]);                        if((prec.rgulx!=x) || (prec.rguly!=y)) {                            continue;                        }                         for(int l=minlys; l<lye; l++) { // Layers                            if(r>=lys[c].length) continue;                            if(l<lys[c][r]) continue;                                                    // set boolean sopUsed here (SOP markers)                            sopUsed = ((String)encSpec.sops.                                       getTileDef(t)).equals("on");

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?