ebcotrateallocator.java

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

JAVA
1,684
字号
                            // 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,                                             nextPrec[c][r]);                                                        hBuff = pktEnc.encodePacket(l+1,c,r,t,                                                        cblks[t][c][r],                                                        truncIdxs[t][l][c][r],                                                        hBuff,bBuff,                                                        nextPrec[c][r]);					                                if(pktEnc.isPacketWritable()) {                                bsWriter.writePacketHead(hBuff.getBuffer(),                                                         hBuff.getLength(),                                                          false,sopUsed,                                                         ephUsed);                                bsWriter.writePacketBody(pktEnc.                                                         getLastBodyBuf(),                                                         pktEnc.                                                         getLastBodyLen(),                                                         false,                                                         pktEnc.isROIinPkt(),                                                         pktEnc.getROILen());                            }                        } // layers                        nextPrec[c][r]++;                    } // Resolution levels                } // Components                if(px!=pxend) {                    x = minx+px*gcd_x;                } else {                    x = tx0;                }            } // Horizontal precincts            if(py!=pyend) {                y = miny+py*gcd_y;            } else {                y = ty0;            }        } // Vertical precincts        // Check that all precincts have been written        for(int c=cs; c<ce; c++) {            mrl = src.getAnSubbandTree(t,c).resLvl;            for(int r=rs; r<re; r++) {                if(r>mrl) continue;                if(nextPrec[c][r]<numPrec[t][c][r].x*numPrec[t][c][r].y-1) {                    throw new Error("JJ2000 bug: One precinct at least has "+                                    "not been written for resolution level "+r                                    +" of component "+c+" in tile "+t+".");                }            }        }    }    /**      * 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 writeCompPosResLy(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;            for(int r=rs; r<re; r++) {                if(r>mrl) continue;                nextPrec[c] = new int[mrl+1];                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;        int x;        for(int c=cs; c<ce; c++) { // Loop on components            y = ty0;            x = tx0;            mrl = src.getAnSubbandTree(t,c).resLvl;            for(int py=0; py<=pyend; py++) { // Vertical precincts                for(int px=0; px<=pxend; px++) { // Horiz. precincts                    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");                            // 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,                                             nextPrec[c][r]);                                                        hBuff = pktEnc.encodePacket(l+1,c,r,t,                                                        cblks[t][c][r],                                                        truncIdxs[t][l][c][r],                                                        hBuff,bBuff,                                                        nextPrec[c][r]);					                                if(pktEnc.isPacketWritable()) {                                bsWriter.writePacketHead(hBuff.getBuffer(),                                                         hBuff.getLength(),                                                          false,sopUsed,                                                         ephUsed);                                bsWriter.writePacketBody(pktEnc.                                                         getLastBodyBuf(),                                                         pktEnc.                                                         getLastBodyLen(),                                                         false,                                                         pktEnc.isROIinPkt(),                                                         pktEnc.getROILen());                            }                         } // Layers                        nextPrec[c][r]++;                    } // Resolution levels                                        if(px!=pxend) {                        x = minx+px*gcd_x;                    } else {                        x = tx0;                    }                } // Horizontal precincts                if(py!=pyend) {                    y = miny+py*gcd_y;                } else {                    y = ty0;                }            } // Vertical precincts        } // components        // Check that all precincts have been written        for(int c=cs; c<ce; c++) {            mrl = src.getAnSubbandTree(t,c).resLvl;            for(int r=rs; r<re; r++) {                                if(r>mrl) continue;                if(nextPrec[c][r]<numPrec[t][c][r].x*numPrec[t][c][r].y-1) {                    throw new Error("JJ2000 bug: One precinct at least has "+                                    "not been written for resolution level "+r                                    +" of component "+c+" in tile "+t+".");                }            }        }    }    /**      * Write a piece of bit stream according to the     * RES_POS_COMP_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 Last layer index.     * */    public void writeResPosCompLy(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;                 

⌨️ 快捷键说明

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