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

📄 pktdecoder.java

📁 jpeg2000编解码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                                for(tpidx = ccb.ctp-totnewtp, j=0;                                    tpidx<ccb.ctp-1;tpidx++) {                                    if(tpidx >= FIRST_BYPASS_PASS_IDX-1) {                                        passtype =                                             (tpidx+NUM_EMPTY_PASSES_IN_MS_BP)%                                            NUM_PASSES;                                        if (passtype==0) continue;                                        lblockCur =                                             lblock[c][r][s][cbc.y][cbc.x];                                        tmp =                                            bin.                                            readBits(lblockCur+                                                     MathUtil.log2(tpidx-ltp));                                        ccb.segLen[l][j] = tmp;                                        cbLen += tmp;                                        ltp = tpidx;                                        j++;                                    }                                }                                // Last pass has always the length sent                                lblockCur = lblock[c][r][s][cbc.y][cbc.x];                                tmp = bin.readBits(lblockCur+                                                   MathUtil.log2(tpidx-ltp));                                cbLen += tmp;                                ccb.segLen[l][j] = tmp;                            }                        }                        ccb.len[l] = cbLen;                        // If truncation mode, checks if output rate is reached                        // unless ncb and lbody quit contitions used.                        if(isTruncMode && maxCB==-1) {                            tmp = ehs.getPos()-startPktHead;                            if(tmp>nb[tIdx]) {                                nb[tIdx] = 0;                                // Remove found information in this code-block                                if(l==0) {                                    cbI[s][cbc.y][cbc.x] = null;                                } else {                                    ccb.off[l]=ccb.len[l]=0;                                    ccb.ctp -= ccb.ntp[l];                                    ccb.ntp[l] = 0;                                    ccb.pktIdx[l] = -1;                                }                                return true;                            }                        }                                                } catch(EOFException e) {                        // Remove found information in this code-block                        if(l==0) {                            cbI[s][cbc.y][cbc.x] = null;                        } else {                            ccb.off[l]=ccb.len[l]=0;                            ccb.ctp -= ccb.ntp[l];                            ccb.ntp[l] = 0;                            ccb.pktIdx[l] = -1;                        }//                         throw new EOFException();			return true;                    }                } // End loop on horizontal code-blocks            } // End loop on vertical code-blocks        } // End loop on subbands                    // Read EPH marker if needed        if(ephUsed) {            readEPHMarker(bin);        }        pktIdx++;	// If truncation mode, checks if output rate is reached	if(isTruncMode && maxCB == -1) {	    tmp = ehs.getPos()-startPktHead;	    if(tmp>nb[tIdx]) {		nb[tIdx] = 0;		return true;	    } else {		nb[tIdx] -= tmp;            }	}	return false;    }    /**      * Reads specificied packet body in order to find offset of each     * code-block's piece of codeword. This use the list of found code-blocks     * in previous red packet head.     *     * @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 remainding number of bytes to read from the bit stream in     * each tile before reaching the decoding rate (in truncation mode)     *     * @return True if decoding rate is reached      * */    public boolean readPktBody(int l,int r,int c,int p,CBlkInfo[][][] cbI,                               int[] nb) throws IOException {        int curOff = ehs.getPos();        Coord curCB;        CBlkInfo ccb;	boolean stopRead = false;	int tIdx = src.getTileIdx();        Coord cbc;        boolean precFound = false;        int mins = (r==0) ? 0 : 1;        int maxs = (r==0) ? 1 : 4;        for(int s=mins; s<maxs; s++) {            if(p<ppinfo[c][r].length) {                precFound = true;            }        }        if(!precFound) {            return false;        }        for(int s=mins; s<maxs; s++) {            for(int numCB=0; numCB<cblks[s].size(); numCB++) {                cbc = ((CBlkCoordInfo)cblks[s].elementAt(numCB)).idx;                ccb = cbI[s][cbc.y][cbc.x];                ccb.off[l] = curOff;                curOff += ccb.len[l];		try {		    ehs.seek(curOff);		} catch(EOFException e) {		    if(l==0) {			cbI[s][cbc.y][cbc.x] = null;                    } else {			ccb.off[l] = ccb.len[l]=0;			ccb.ctp -= ccb.ntp[l];			ccb.ntp[l] = 0;			ccb.pktIdx[l] = -1;		    }		    throw new EOFException();		}		// If truncation mode		if(isTruncMode) {		    if(stopRead || ccb.len[l]>nb[tIdx]) {			// Remove found information in this code-block			if(l==0) {			    cbI[s][cbc.y][cbc.x] = null;			} else {			    ccb.off[l] = ccb.len[l] = 0;			    ccb.ctp -= ccb.ntp[l];			    ccb.ntp[l] = 0;			    ccb.pktIdx[l] = -1;			}			stopRead = true;		    }		    if(!stopRead) {			nb[tIdx] -= ccb.len[l];                    }		}		// If ncb quit condition reached		if(ncbQuit && r == rQuit && s == sQuit && cbc.x == xQuit &&                   cbc.y == yQuit && tIdx == tQuit && c == cQuit) {                    cbI[s][cbc.y][cbc.x] = null;                    stopRead = true;                }            } // Loop on code-blocks        } // End loop on subbands        // Seek to the end of the packet        ehs.seek(curOff);	if(stopRead) {	    return true;	} else {	    return false;        }    }        /**     * Returns the precinct partition width for the specified component,     * resolution level and tile.     *     * @param t the tile index     *     * @param c The index of the component (between 0 and C-1)     *     * @param r The resolution level, from 0 to L.     *     * @return the precinct partition width for the specified component,     * resolution level and tile.     * */    public final int getPPX(int t,int c,int r) {        return decSpec.pss.getPPX(t,c,r);    }    /**     * Returns the precinct partition height for the specified component,     * resolution level and tile.     *     * @param t the tile index     *     * @param c The index of the component (between 0 and C-1)     *     * @param rl The resolution level, from 0 to L.     *     * @return the precinct partition height in the specified component, for     * the specified resolution level, for the current tile.     * */    public final int getPPY(int t,int c,int rl) {        return decSpec.pss.getPPY(t,c,rl);    }    /**     * Try to read a SOP marker and check that its sequence number if not out     * of sequence. If so, an error is thrown.     *     * @param nBytes The number of bytes left to read from each tile     *     * @param p Precinct index     *     * @param r Resolution level index     *     * @param c Component index     * */    public boolean readSOPMarker(int[] nBytes,int p,int c,int r)         throws IOException {        int val;        byte sopArray[] = new byte[6];	int tIdx = src.getTileIdx();        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;        }        // If SOP markers are not used, return        if(!sopUsed) {            return false;        }        // Check if SOP is used for this packet        int pos = ehs.getPos();        if( (short)((ehs.read()<<8) | ehs.read()) != Markers.SOP ) {            ehs.seek(pos);            return false;        }        ehs.seek(pos);        // If length of SOP marker greater than remaining bytes to read for        // this tile return true        if(nBytes[tIdx]<6) {            return true;        }        nBytes[tIdx] -= 6;                // Read marker into array 'sopArray'        ehs.readFully(sopArray,0,Markers.SOP_LENGTH);        // Check if this is the correct marker        val = sopArray[0];        val <<= 8;        val |= sopArray[1];        if(val!=Markers.SOP) {            throw new Error("Corrupted Bitstream: Could not parse SOP "+                            "marker !");        }        // Check if length is correct        val = (sopArray[2]&0xff);        val <<= 8;        val |= (sopArray[3]&0xff);        if(val!=4) {            throw new Error("Corrupted Bitstream: Corrupted SOP marker !");        }        // Check if sequence number if ok        val = (sopArray[4]&0xff);        val <<= 8;        val |= (sopArray[5]&0xff);        if(!pph && val!=pktIdx) {             throw new Error("Corrupted Bitstream: SOP marker out of "                            +"sequence !");        }        if(pph && val!=pktIdx-1) {             // if packed packet headers are used, packet header was read            // before SOP marker segment            throw new Error("Corrupted Bitstream: SOP marker out of "                            +"sequence !");        }        return false;    }    /**     * Try to read an EPH marker. If it is not possible then an Error is     * thrown.     *     * @param bin The packet header reader to read the EPH marker from     * */    public void readEPHMarker(PktHeaderBitReader bin) throws IOException {        int val;        byte ephArray[] = new byte[2];        if(bin.usebais) {            bin.bais.read(ephArray,0,Markers.EPH_LENGTH);        } else {            bin.in.readFully(ephArray,0,Markers.EPH_LENGTH);        }        // Check if this is the correct marker        val = ephArray[0];        val <<= 8;        val |= ephArray[1];        if (val!=Markers.EPH) {            throw new Error("Corrupted Bitstream: Could not parse EPH "                            +"marker ! ");        }    }        /**      * Get PrecInfo instance of the specified resolution level, component and     * precinct.     *     * @param c Component index.     *     * @param r Resolution level index.     *     * @param p Precinct index.     * */    public PrecInfo getPrecInfo(int c,int r,int p) {        return ppinfo[c][r][p];    }}

⌨️ 快捷键说明

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