⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pktdecoder.java

📁 jpeg2000编解码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                            new CBlkCoordInfo[kend-kstart+1][lend-lstart+1];                        ppinfo[c][r][nPrec].                            nblk[3] = (kend-kstart+1)*(lend-lstart+1);                                            for(int k=kstart; k<=kend; k++) { // Vertical cblks                            for(int l=lstart; l<=lend; l++) { // Horiz cblks                                cb = new CBlkCoordInfo(k-k0,l-l0);                                if(l==l0) {                                    cb.ulx = sb.ulx;                                } else {                                    cb.ulx = sb.ulx+l*cw-(sb.ulcx-acb0x);                                }                                if(k==k0) {                                    cb.uly = sb.uly;                                } else {                                    cb.uly = sb.uly+k*ch-(sb.ulcy-acb0y);                                }                                tmp1 = acb0x+l*cw;                                tmp1 = (tmp1>sb.ulcx) ? tmp1 : sb.ulcx;                                tmp2 = acb0x+(l+1)*cw;                                tmp2 = (tmp2>sb.ulcx+sb.w) ?                                    sb.ulcx+sb.w : tmp2;                                cb.w = tmp2-tmp1;                                tmp1 = acb0y+k*ch;                                tmp1 = (tmp1>sb.ulcy) ? tmp1 : sb.ulcy;                                tmp2 = acb0y+(k+1)*ch;                                tmp2 = (tmp2>sb.ulcy+sb.h) ?                                    sb.ulcy+sb.h : tmp2;                                cb.h = tmp2-tmp1;                                ppinfo[c][r][nPrec].                                    cblk[3][k-kstart][l-lstart] = cb;                            } // Horizontal code-blocks                        } // Vertical code-blocks                    }                }            } // Horizontal precincts        } // Vertical precincts   }   /**      * Gets the number of precincts in a given component and resolution level.     *     * @param c Component index     *     * @param r Resolution index     * */    public int getNumPrecinct(int c,int r) {	return numPrec[c][r].x*numPrec[c][r].y;    }        /**      * Read specified packet head and found length of each code-block's piece     * of codewords as well as number of skipped most significant bit-planes.     *     * @param l layer index     *     * @param r Resolution level index     *     * @param c Component index     *     * @param p Precinct index     *     * @param cbI CBlkInfo array of relevant component and resolution     * level.     *     * @param nb The number of bytes to read in each tile before reaching     * output rate (used by truncation mode)     *     * @return True if specified output rate or EOF is reached.     * */    public boolean readPktHead(int l,int r,int c,int p,CBlkInfo[][][] cbI,                               int[] nb) throws IOException {        CBlkInfo ccb;        int nSeg;                   // number of segment to read        int cbLen;                  // Length of cblk's code-words        int ltp;                    // last truncation point index        int passtype;               // coding pass type        TagTreeDecoder tdIncl,tdBD;        int tmp,tmp2,totnewtp,lblockCur,tpidx;        int sumtotnewtp = 0;        Coord cbc;	int startPktHead = ehs.getPos();	if(startPktHead>=ehs.length()) {	    // EOF reached at the beginning of this packet head	    return true;	}	int tIdx = src.getTileIdx();        PktHeaderBitReader bin;        int mend,nend;        int b;        SubbandSyn sb;        SubbandSyn root = src.getSynSubbandTree(tIdx,c);        // If packed packet headers was used, use separate stream for reading        // of packet headers	if(pph) {            bin = new PktHeaderBitReader(pphbais);        } else {            bin = this.bin;        }        int mins = (r==0) ? 0 : 1;        int maxs = (r==0) ? 1 : 4;        boolean precFound = false;        for(int s=mins; s<maxs; s++) {            if(p<ppinfo[c][r].length) {                precFound = true;            }        }        if(!precFound) {            return false;        }        PrecInfo prec = ppinfo[c][r][p];        // Synchronize for bit reading        bin.sync();                // If packet is empty there is no info in it (i.e. no code-blocks)        if(bin.readBit()==0) {            // No code-block is included            cblks = new Vector[maxs+1];            for(int s=mins; s<maxs; s++){                cblks[s] = new Vector();            }	    pktIdx++;	    	    // If truncation mode, checks if output rate is reached            // unless ncb quit condition is used in which case headers            // are not counted	    if(isTruncMode && maxCB == -1) {		tmp = ehs.getPos()-startPktHead;		if(tmp>nb[tIdx]) {		    nb[tIdx] = 0;		    return true;		} else {		    nb[tIdx] -= tmp;                }	    }            // Read EPH marker if needed            if(ephUsed) {                readEPHMarker(bin);            }	    return false;        }        // Packet is not empty => decode info        // Loop on each subband in this resolution level        if(cblks==null || cblks.length<maxs+1) {            cblks = new Vector[maxs+1];        }        for(int s=mins; s<maxs; s++) {            if(cblks[s]==null) {                cblks[s] = new Vector();            } else {                cblks[s].removeAllElements();            }            sb = (SubbandSyn)root.getSubbandByIdx(r,s);            // No code-block in this precinct            if(prec.nblk[s]==0) {                // Go to next subband                continue;            }            tdIncl = ttIncl[c][r][p][s];            tdBD = ttMaxBP[c][r][p][s];            mend = (prec.cblk[s]==null) ? 0 : prec.cblk[s].length;            for(int m=0; m<mend; m++) { // Vertical code-blocks                nend = (prec.cblk[s][m]==null) ? 0 : prec.cblk[s][m].length;                for (int n=0; n<nend; n++) { // Horizontal code-blocks                    cbc = prec.cblk[s][m][n].idx;                    b = cbc.x+cbc.y*sb.numCb.x;                    ccb = cbI[s][cbc.y][cbc.x];                    try {                        // If code-block not included in previous layer(s)                        if(ccb==null || ccb.ctp==0) {                             if(ccb==null) {                                ccb = cbI[s][cbc.y][cbc.x] =                                     new CBlkInfo(prec.cblk[s][m][n].ulx,                                                 prec.cblk[s][m][n].uly,                                                 prec.cblk[s][m][n].w,                                                 prec.cblk[s][m][n].h,nl);                            }                            ccb.pktIdx[l] = pktIdx;			                            // Read inclusion using tag-tree                            tmp = tdIncl.update(m,n,l+1,bin);                            if(tmp>l) { // Not included                                continue;                            }                            // Read bitdepth using tag-tree                            tmp = 1;// initialization                            for(tmp2=1; tmp>=tmp2; tmp2++) {                                tmp = tdBD.update(m,n,tmp2,bin);                            }                            ccb.msbSkipped = tmp2-2;                            // New code-block => at least one truncation point                            totnewtp = 1;                            ccb.addNTP(l,0);                            // Check whether ncb quit condition is reached                            ncb++;                            if(maxCB != -1 && !ncbQuit && ncb == maxCB){                                 // ncb quit contidion reached                                ncbQuit = true;                                tQuit = tIdx;                                cQuit = c;                                sQuit = s;                                rQuit = r;                                xQuit = cbc.x;                                yQuit = cbc.y;                           }                        } else { // If code-block already included in one of                            // the previous layers.			                            ccb.pktIdx[l] = pktIdx;			                            // If not inclused                            if(bin.readBit()!=1) {                                continue;                            }			                            // At least 1 more truncation point than                            // prev. packet                            totnewtp = 1;                        }		                            // Read new truncation points                        if(bin.readBit()==1) {// if bit is 1                            totnewtp++;			                            // if next bit is 0 do nothing                            if(bin.readBit()==1) {//if is 1                                totnewtp++;                                                                tmp = bin.readBits(2);                                totnewtp += tmp;                                                                // If next 2 bits are not 11 do nothing                                if(tmp==0x3) { //if 11                                    tmp = bin.readBits(5);                                    totnewtp += tmp;                                    				// If next 5 bits are not 11111 do nothing                                    if(tmp==0x1F) { //if 11111                                        totnewtp += bin.readBits(7);                                    }                                }                            }                        }                        ccb.addNTP(l,totnewtp);                        sumtotnewtp += totnewtp;                        cblks[s].addElement(prec.cblk[s][m][n]);                        // Code-block length                                                // -- Compute the number of bit to read to obtain                        // code-block length.                          // numBits = betaLamda + log2(totnewtp);		                            // The length is signalled for each segment in                        // addition to the final one. The total length is the                        // sum of all segment lengths.		                            // If regular termination in use, then there is one                        // segment per truncation point present. Otherwise, if                        // selective arithmetic bypass coding mode is present,                        // then there is one termination per bypass/MQ and                        // MQ/bypass transition. Otherwise the only                        // termination is at the end of the code-block.                        int options =                             ((Integer)decSpec.ecopts.getTileCompVal(tIdx,c)).                            intValue();		                            if( (options&OPT_TERM_PASS) != 0) {                            // Regular termination in use, one segment per new                            // pass (i.e. truncation point)                            nSeg = totnewtp;                        } else if( (options&OPT_BYPASS) != 0) {                            // Selective arithmetic coding bypass coding mode                            // in use, but no regular termination 1 segment up                            // to the end of the last pass of the 4th most                            // significant bit-plane, and, in each following                            // bit-plane, one segment upto the end of the 2nd                            // pass and one upto the end of the 3rd pass.			                            if(ccb.ctp<=FIRST_BYPASS_PASS_IDX) {                                nSeg = 1;                            } else {                                nSeg = 1; // One at least for last pass                                // And one for each other terminated pass                                for(tpidx = ccb.ctp-totnewtp;                                    tpidx < ccb.ctp-1; tpidx++) {                                    if(tpidx >= FIRST_BYPASS_PASS_IDX-1) {                                        passtype =                                            (tpidx+NUM_EMPTY_PASSES_IN_MS_BP)%                                            NUM_PASSES;                                        if (passtype==1 || passtype==2) {                                            // bypass coding just before MQ                                            // pass or MQ pass just before                                            // bypass coding => terminated                                            nSeg++;                                        }                                    }                                }                            }                        } else {                            // Nothing special in use, just one segment                            nSeg = 1;                        }                                                // Reads lblock increment (common to all segments)                        while(bin.readBit()!=0) {                            lblock[c][r][s][cbc.y][cbc.x]++;                        }                        if(nSeg==1) { // Only one segment in packet                            cbLen = bin.readBits(lblock[c][r][s][cbc.y][cbc.x]+                                                 MathUtil.log2(totnewtp));                        } else {                            // We must read one length per segment                            ccb.segLen[l] = new int[nSeg];                            cbLen = 0;                            int j;                            if((options&OPT_TERM_PASS) != 0) {                                // Regular termination: each pass is terminated                                for(tpidx=ccb.ctp-totnewtp,j=0;                                    tpidx<ccb.ctp;tpidx++,j++) {                                                                        lblockCur = lblock[c][r][s][cbc.y][cbc.x];                                                                  tmp = bin.readBits(lblockCur);                                    ccb.segLen[l][j] = tmp;                                    cbLen += tmp;                                }                            } else {                                // Bypass coding: only some passes are                                // terminated                                ltp = ccb.ctp-totnewtp-1;

⌨️ 快捷键说明

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