bitstreamreaderagent.java

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

JAVA
1,084
字号
        return (int)Math.ceil(tcx0/(double)(1<<dl));    }    /**     * Returns the vertical coordinate of the upper-left corner of the     * specified component in the given component of the current tile.     *     * @param c The component index.     *     * @param rl The resolution level index.     * */    public final int getResULY(int c,int rl) {	int dl = mdl[c]-rl;        if(dl<0){            throw new IllegalArgumentException("Requested resolution level"+                                               " is not available for, at "+                                               "least, one component in "+					       "tile: "+ctX+"x"+ctY);        }        int ty0 = (int)Math.max(py+ctY*ntH,ay);        int tcy0 = (int)Math.ceil(ty0/(double)getCompSubsY(c));        return (int)Math.ceil(tcy0/(double)(1<<dl));    }    /**     * Returns the number of tiles in the horizontal and vertical directions.     *     * @param co If not null this object is used to return the information. If     * null a new one is created and returned.     *     * @return The number of tiles in the horizontal (Coord.x) and vertical     * (Coord.y) directions.     * */    public final Coord getNumTiles(Coord co) {        if (co != null) {            co.x = ntX;            co.y = ntY;            return co;        }        else {            return new Coord(ntX,ntY);        }    }    /**     * Returns the total number of tiles in the image.     *     * @return The total number of tiles in the image.     * */    public final int getNumTiles() {        return ntX*ntY;    }    /**     * Returns the subband tree, for the specified tile-component. This method     * returns the root element of the subband tree structure, see Subband and     * SubbandSyn. The tree comprises all the available resolution levels.     *     * <p>Note: this method is not able to return subband tree for a tile     * different than the current one.</p>     *     * <p>The number of magnitude bits ('magBits' member variable) for each     * subband is not initialized.</p>     *     * @param t The tile index     *     * @param c The index of the component, from 0 to C-1.     *     * @return The root of the tree structure.     * */    public final SubbandSyn getSynSubbandTree(int t,int c) {        if(t!=getTileIdx()) {            throw new IllegalArgumentException("Can not request subband"+                                               " tree of a different tile"+                                               " than the current one");        }        if(c<0 || c>=nc) {            throw new IllegalArgumentException("Component index out of range");        }        return subbTrees[c];    }    /**     * Creates a bit stream reader of the correct type that works on the     * provided RandomAccessIO, with the special parameters from the parameter     * list.     *     * @param in The RandomAccessIO source from which to read the bit stream.     *     * @param hd Header of the codestream.     *     * @param pl The parameter list containing parameters applicable to the     * bit stream read (other parameters may also be present).     *     * @param decSpec The decoder specifications     *     * @param cdstrInfo Whether or not to print information found in     * codestream.      *     * @param hi Reference to the HeaderInfo instance.     *     * @exception IOException If an I/O error occurs while reading initial     * data from the bit stream.     * @exception IllegalArgumentException If an unrecognised bit stream     * reader option is present.     * */    public static BitstreamReaderAgent createInstance(RandomAccessIO in,                                                      HeaderDecoder hd,                                                      ParameterList pl,                                                      DecoderSpecs decSpec,                                                      boolean cdstrInfo,                                                      HeaderInfo hi)        throws IOException {        // Check parameters        pl.checkList(BitstreamReaderAgent.OPT_PREFIX,                     pl.toNameArray(BitstreamReaderAgent.getParameterInfo()));        return new FileBitstreamReaderAgent(hd,in,decSpec,pl,cdstrInfo,hi);    }    /**     * Returns the parameters that are used in this class and implementing     * classes. It returns a 2D String array. Each of the 1D arrays is for a     * different option, and they have 3 elements. The first element is the     * option name, the second one is the synopsis and the third one is a long     * description of what the parameter is. The synopsis or description may     * be 'null', in which case it is assumed that there is no synopsis or     * description of the option, respectively. Null may be returned if no     * options are supported.     *     * @return the options name, their synopsis and their explanation, or null     * if no options are supported.     * */    public static String[][] getParameterInfo() {        return pinfo;    }    /**     * Returns the precinct partition width for the specified tile-component     * and (tile-component) resolution level.     *     * @param t the tile index     *     * @param c The index of the component (between 0 and N-1)     *     * @param rl 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 rl) {        return decSpec.pss.getPPX(t,c,rl);    }    /**     * Returns the precinct partition height for the specified tile-component     * and (tile-component) resolution level.     *     * @param t The tile index     *     * @param c The index of the component (between 0 and N-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);    }        /**      * Initialises subbands fields, such as number of code-blocks, code-blocks     * dimension and number of magnitude bits, in the subband tree. The     * nominal code-block width/height depends on the precincts dimensions if     * used. The way the number of magnitude bits is computed depends on the     * quantization type (reversible, derived, expounded).     *     * @param c The component index     *     * @param sb The subband tree to be initialised.     * */    protected void initSubbandsFields(int c,SubbandSyn sb) {        int t = getTileIdx();        int rl = sb.resLvl;        int cbw, cbh;        cbw = decSpec.cblks.getCBlkWidth(ModuleSpec.SPEC_TILE_COMP,t,c);        cbh = decSpec.cblks.getCBlkHeight(ModuleSpec.SPEC_TILE_COMP,t,c);        if (!sb.isNode) {            // Code-block dimensions            if( hd.precinctPartitionUsed() ) {                // The precinct partition is used                int ppxExp, ppyExp, cbwExp, cbhExp;                                // Get exponents                ppxExp = MathUtil.log2(getPPX(t,c,rl));                ppyExp = MathUtil.log2(getPPY(t,c,rl));                cbwExp = MathUtil.log2(cbw);                cbhExp = MathUtil.log2(cbh);                                switch (sb.resLvl) {                    case 0:                        sb.nomCBlkW = ( cbwExp<ppxExp ?                             (1<<cbwExp) : (1<<ppxExp) );                        sb.nomCBlkH = ( cbhExp<ppyExp ?                             (1<<cbhExp) : (1<<ppyExp) );                        break;                                            default:                        sb.nomCBlkW = ( cbwExp<ppxExp-1 ?                             (1<<cbwExp) : (1<<(ppxExp-1)) );                        sb.nomCBlkH = ( cbhExp<ppyExp-1 ?                             (1<<cbhExp) : (1<<(ppyExp-1)) );                        break;                }            } else {                sb.nomCBlkW = cbw;                sb.nomCBlkH = cbh;            }            // Number of code-blocks            if(sb.numCb == null) sb.numCb = new Coord();            if (sb.w==0 || sb.h==0) {                sb.numCb.x = 0;                sb.numCb.y = 0;            } else {                int cb0x = getCbULX();                int cb0y = getCbULY();                int tmp;                // Projects code-block partition origin to subband. Since the                // origin is always 0 or 1, it projects to the low-pass side                // (throught the ceil operator) as itself (i.e. no change) and                // to the high-pass side (through the floor operator) as 0,                // always.                int acb0x = cb0x;                int acb0y = cb0y;                            switch (sb.sbandIdx) {                case Subband.WT_ORIENT_LL:                    // No need to project since all low-pass => nothing to do                    break;                case Subband.WT_ORIENT_HL:                    acb0x = 0;                    break;                case Subband.WT_ORIENT_LH:                    acb0y = 0;                    break;                case Subband.WT_ORIENT_HH:                    acb0x = 0;                    acb0y = 0;                    break;                default:                    throw new Error("Internal JJ2000 error");                }                if(sb.ulcx-acb0x<0 || sb.ulcy-acb0y<0) {                    throw new IllegalArgumentException("Invalid code-blocks "+                                                       "partition origin or "+                                                       "image offset in the "+                                                       "reference grid.");                }                // NOTE: when calculating "floor()" by integer division the                // dividend and divisor must be positive, we ensure that by                // adding the divisor to the dividend and then substracting 1                // to the result of the division                tmp = sb.ulcx-acb0x+sb.nomCBlkW;                sb.numCb.x = (tmp+sb.w-1)/sb.nomCBlkW - (tmp/sb.nomCBlkW-1);                                tmp = sb.ulcy-acb0y+sb.nomCBlkH;                sb.numCb.y = (tmp+sb.h-1)/sb.nomCBlkH - (tmp/sb.nomCBlkH-1);            }            // Number of magnitude bits            if(derived[c]) {                sb.magbits = gb[c]+(params[c].exp[0][0]-(mdl[c]-sb.level))-1;            } else {                sb.magbits = gb[c]+params[c].exp[sb.resLvl][sb.sbandIdx]-1;            }        } else {            initSubbandsFields(c,(SubbandSyn)sb.getLL());            initSubbandsFields(c,(SubbandSyn)sb.getHL());            initSubbandsFields(c,(SubbandSyn)sb.getLH());            initSubbandsFields(c,(SubbandSyn)sb.getHH());        }    }    /**      * Returns the image resolution level to reconstruct from the     * codestream. This value cannot be computed before every main and tile     * headers are read.     *     * @return The image  resolution level     * */    public int getImgRes() {	return targetRes;    }    /**      * Return the target decoding rate in bits per pixel.     *      * @return Target decoding rate in bpp.     * */    public float getTargetRate() {        return trate;    }    /**      * Return the actual decoding rate in bits per pixel.     *     * @return Actual decoding rate in bpp.     * */    public float getActualRate() {        arate = anbytes*8f/hd.getMaxCompImgWidth()/hd.getMaxCompImgHeight();        return arate;    }    /**      * Return the target number of read bytes.     *      * @return Target decoding rate in bytes.     * */    public int getTargetNbytes() {        return tnbytes;    }    /**      * Return the actual number of read bytes.     *     * @return Actual decoding rate in bytes.     * */    public int getActualNbytes(){        return anbytes;    }    /** Returns the horizontal offset of tile partition */    public int getTilePartULX() {        return hd.getTilingOrigin(null).x;    }    /** Returns the vertical offset of tile partition */    public int getTilePartULY() {        return hd.getTilingOrigin(null).y;    }    /** Returns the nominal tile width */    public int getNomTileWidth() {        return hd.getNomTileWidth();    }    /** Returns the nominal tile height */    public int getNomTileHeight() {        return hd.getNomTileHeight();    }}

⌨️ 快捷键说明

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