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

📄 filebitstreamreaderagent.java

📁 jpeg2000算法实现
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            // Should never happen. Truncated codestream are normally found in            // FileBitstreamReaderAgent constructor            throw e;	}		// In truncation mode, update the number of read bytes	if(isTruncMode){            anbytes += nb-nBytes[t];	    // If truncation rate is reached	    if(status)                nBytes[t] = 0;	}       	// In parsing mode, if there is not enough rate to entirely read the       	// tile. Then, parses the bit stream so as to create a virtual       	// layer-resolution-component progressive bit stream that will be       	// truncated and decoded afterwards.        else if(nBytes[t]<(totTileLen[t]-totTileHeadLen[t])){            CBlkInfo cb;            // Systematicaly reject all remaining code-blocks if one            // code-block, at least, is refused.            boolean reject;             // Stop reading any data from the bit stream            boolean stopCount = false;            // Length of each packet's head (in an array)            int[] pktHeadLen = new int[pktHL.size()];            for(int i=pktHL.size()-1;i>=0;i--)                pktHeadLen[i] = ((Integer)pktHL.elementAt(i)).intValue();                        // Parse each code-block, layer per layer until nBytes[t] is            // reached            reject = false;            for(int l=0; l<nl; l++){ // layers                if(cbI==null) continue;                int nc = cbI.length;                                int mres = 0;                for(int c=0; c<nc; c++){                    if(cbI[c]!=null && cbI[c].length>mres)                        mres = cbI[c].length;                }                for(int r=0; r<mres; r++){ // resolutions                                            int msub = 0;                    for(int c=0; c<nc; c++){                        if(cbI[c]!=null && cbI[c][r]!=null                            && cbI[c][r].length>msub)                            msub = cbI[c][r].length;                    }                    for(int s=0; s<msub; s++){ // subbands                        // Only LL subband resolution level 0                        if(r==0 && s!=0)                            continue;                        // No LL subband in resolution level > 0                        else if(r!=0 && s==0)                            continue;                        int mnby=0;                        for(int c=0; c<nc; c++){                            if(cbI[c]!=null && cbI[c][r]!=null &&                                cbI[c][r][s]!=null &&                               cbI[c][r][s].length>mnby)                                mnby = cbI[c][r][s].length;                        }                        for(int m=0; m<mnby; m++){                            int mnbx = 0;                            for(int c=0; c<nc; c++){                                if(cbI[c]!=null && cbI[c][r]!=null &&                                    cbI[c][r][s]!=null && cbI[c][r][s][m]!=null                                   && cbI[c][r][s][m].length>mnbx)                                    mnbx = cbI[c][r][s][m].length;                            }                            for(int n=0; n<mnbx; n++){                                                                for(int c=0; c<nc; c++){                                                                        if(cbI[c]==null || cbI[c][r]==null ||                                        cbI[c][r][s]==null ||                                        cbI[c][r][s][m]==null ||                                       cbI[c][r][s][m][n]==null )                                        continue;                                    cb = cbI[c][r][s][m][n];                                                                        // If no code-block has been refused until                                    // now                                    if(!reject){                                        // Rate is to low to allow reading of                                        // packet's head                                        if(nBytes[t]<pktHeadLen[cb.pktIdx[l]]){                                            // Stop parsing                                            stopCount = true;                                            // Reject all next                                            // code-blocks                                            reject=true;                                        }                                        // Rate is enough to read packet's                                        // head                                        else{                                            // If parsing was not stopped                                            if(!stopCount){                                                // Takes into account packet's                                                // head length                                                nBytes[t] -=                                                     pktHeadLen[cb.pktIdx[l]];                                                anbytes +=                                                     pktHeadLen[cb.pktIdx[l]];                                                // Set packet's head length to                                                // 0, so that it won't be                                                // taken into account next                                                // time                                                pktHeadLen[cb.pktIdx[l]]=0;                                            }                                        }                                    }                                    // Code-block has no data in this layer                                    if(cb.len[l]==0){                                        continue;                                    }                                                                        // Accepts code-block if length is enough,                                    // if this code-block was not refused in a                                    // previous layer and if no code-block was                                    // refused in current component                                    if(cb.len[l]<nBytes[t]                                        && !reject){                                        nBytes[t] -= cb.len[l];                                        anbytes += cb.len[l];                                    }                                    // Refuses code-block                                    else{                                        // Forgets code-block's data                                        cb.len[l]=cb.off[l]=cb.ntp[l]= 0;                                        // Refuses all other code-block in                                        // current and next component                                        reject=true;                                    }                                                                    } // End loop on components                            } // End loop on horiz. code-blocks                        } // End loop on vert. code-blocks                    } // End loop on subbands                } // End loop on resolutions            } // End loop on layers        }        // No parsing for this tile, adds tile's body to the total        // number of read bytes.        else{            anbytes += totTileLen[t]-totTileHeadLen[t];            if(t<getNumTiles()-1){                nBytes[t+1] += nBytes[t]-(totTileLen[t]-totTileHeadLen[t]);            }        }    }    /**     * Changes the current tile, given the new indexes. An     * IllegalArgumentException is thrown if the indexes do not     * correspond to a valid tile.     *     * @param x The horizontal indexes the tile.     *     * @param y The vertical indexes of the new tile.     * */    public void setTile(int x,int y){        int i;          // counter        int ctox,ctoy;  // new current tile origin in the reference grid        // Check validity of tile indexes        if (x<0 || y<0 || x>=ntX || y>=ntY) {            throw new IllegalArgumentException();        }        int t = (y*ntX+x);        // Set the new current tile        ctX = x;        ctY = y;        // Calculate tile relative points        ctox = (x == 0) ? ax : px+x*ntW;        ctoy = (y == 0) ? ay : py+y*ntH;        for (i = nc-1; i >= 0; i--) {            culx[i] = (ctox+hd.getCompSubsX(i)-1)/hd.getCompSubsX(i);            culy[i] = (ctoy+hd.getCompSubsY(i)-1)/hd.getCompSubsY(i);            offX[i] = (px+x*ntW+hd.getCompSubsX(i)-1)/hd.getCompSubsX(i);            offY[i] = (py+y*ntH+hd.getCompSubsY(i)-1)/hd.getCompSubsY(i);        }                // Initialize subband tree and number of resolution levels        subbTrees = new SubbandSyn[nc];        mdl = new int[nc];        derived = new boolean[nc];        params = new StdDequantizerParams[nc];        gb = new int[nc];        for(int c=0; c<nc; c++){            derived[c] = decSpec.qts.isDerived(t,c);            params[c] =                 (StdDequantizerParams)decSpec.qsss.getTileCompVal(t,c);            gb[c] = ((Integer)decSpec.gbs.getTileCompVal(t,c)).intValue();            mdl[c] = ((Integer)decSpec.dls.getTileCompVal(t,c)).intValue();            subbTrees[c] =                new SubbandSyn(getCompWidth(c,mdl[c]),                               getCompHeight(c,mdl[c]),                               getULX(c,mdl[c]),getULY(c,mdl[c]),mdl[c],                               decSpec.wfs.getHFilters(t,c),                               decSpec.wfs.getVFilters(t,c));            initSubbandsFields(c,subbTrees[c]);        }                // Read tile's packets        try{            initTile(t);        }        catch(IOException e){            e.printStackTrace();            throw new Error("IO Error when reading tile "+x+" x "+y);        }    }    /**     * Advances to the next tile, in standard scan-line order (by rows     * then columns). An NoNextElementException is thrown if the     * current tile is the last one (i.e. there is no next tile).     * */    public void nextTile(){        if (ctX == ntX-1 && ctY == ntY-1) { // Already at last tile            throw new NoNextElementException();        }        else if (ctX < ntX-1) { // If not at end of current tile line            setTile(ctX+1,ctY);        }        else { // Go to first tile at next line            setTile(0,ctY+1);        }    }    /**     * Returns the specified coded code-block, for the specified     * component, in the current tile. The first layer to return is     * indicated by 'fl'. The number of layers that is returned depends     * on 'nl' and the amount of data available.     *     * <P>The argument 'fl' is to be used by subsequent calls to this     * method for the same code-block. In this way supplamental data     * can be retrieved at a later time. The fact that data from more     * than one layer can be returned means that several packets from     * the same code-block, of the same component, and the same tile,     * have been concatenated.     *     * <P>The returned compressed code-block can have its progressive     * attribute set. If this attribute is set it means that more data      * can be obtained by subsequent calls to this method (subject to     * transmission delays, etc). If the progressive attribute is not     * set it means that the returned data is all the data that can be      * obtained for the specified subblock.     *     * <P>The compressed code-block is uniquely specified by the     * current tile, the component (identified by 'c'), the subband     * (indentified by 'sb') and the code-bock vertical     * and horizontal indexes 'n' and 'm'.     *     * <P>The 'ulx' and 'uly' members of the returned 'DecLyrdCBlk'     * object contain the coordinates of the top-left corner of the block,     * with respect to the tile, not the subband.     *     * @param c The index of the component, from 0 to N-1.     *     * @param m The vertical index of the code-block to return, in the     * specified subband.     *     * @param n The horizontal index of the code-block to return, in the     * specified subband.     *     * @param sb The subband in whic the requested code-block is.     *     * @param fl The first layer to return.     *     * @param nl The number of layers to return, if negative all     * available layers are returned, starting at 'fl'.     *     * @param ccb If not null this object is used to return the     * compressed code-block. If null a new object is created and     * returned. If the data array in ccb is not null then it can be     * reused to return the compressed data.     *     * @return The compressed code-block, with a certain number of     * layers determined by the available data and 'nl'.     * */    public DecLyrdCBlk getCodeBlock(int c, int m, int n,                                    SubbandSyn sb, int fl, int nl,                                    DecLyrdCBlk ccb){        int t = getTileIdx();        CBlkInfo rcb; // requested code-block        int r = sb.resLvl;  // Resolution level        int s = sb.sbandIdx; // Sub-band index        int tpidx;        int passtype;        // Number of layers        int numLayers = ((Integer)decSpec.nls.getTileDef(t)).intValue();        int options =            ((Integer)decSpec.ecopts.getTileCompVal(t,c)).intValue();        if(nl<0){            nl = numLayers-fl+1;        }                // Check validity of all the arguments        try{            rcb = cbI[c][r][s][m][n];            if(fl < 1 || fl > numLayers || fl+nl-1 > numLayers){                throw new IllegalArgumentException();            }        }        catch(ArrayIndexOutOfBoundsException e){            throw new IllegalArgumentException("Block (t:"+t+", c:"+                                               c+", r:"+r+", s:"+s+", "+m+"x"+                                               +n+") not found in bit stream");        }        catch(NullPointerException e){            throw new IllegalArgumentException("Block (t:"+t+", c:"+                                               c+", r:"+r+", s:"+s+", "+m+"x"                                               +n+") not found in bit stream");        }                // Create DecLyrdCBlk object if necessary        if(ccb == null){            ccb = new DecLyrdCBlk();        }        ccb.m = m;        ccb.n = n;        ccb.nl = 0;        ccb.dl = 0;        ccb.nTrunc = 0;        if(rcb==null){            // This code-block was skipped when reading. Returns no data            ccb.skipMSBP = 0;            ccb.prog = fals

⌨️ 快捷键说明

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