📄 bitstreamreaderagent.java
字号:
* @param rl The resolution level, from 0 to L. * * @return The vertical coordinate of the upper-left corner of the active * tile, with respect to the canvas origin, for component 'c', in the * component coordinates, at resolution level 'rl'. * */ public final int getULY(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); } return (culy[c]+(1<<dl)-1)/(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>The number of magnitude bits ('magBits' member variable) for each * subband is not initialized. * * @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 getSubbandTree(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]; } /** * Returns the number of code-blocks in a subband, along the horizontal * and vertical dimensions. * * @param sb The subband for which to return the number of blocks. * * @param c The component where the subband is. * * @param co If not null the values are returned in this object. If null a * new object is allocated and returned. * * @return The number of code-blocks along the horizontal dimension in * 'Coord.x' and the number of code-blocks along the vertical dimension in * 'Coord.y'. * */ public final Coord getNumCodeBlocks(SubbandSyn sb, int c, Coord co) { int pox = getPartitionULX(); int poy = getPartitionULY(); if (co == null) { co = new Coord(); } if ( sb.w==0 || sb.h==0 ) { co.x = 0; co.y = 0; } else { int apox, apoy; // Projected code-block partition origin int tmp; // Project 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. apox = pox; apoy = poy; Subband sb2; switch (sb.gOrient) { case Subband.WT_ORIENT_LL: // No need to project since all low-pass => nothing to do break; case Subband.WT_ORIENT_HL: // There is at least a high-pass step on the horizontal // decomposition => project to 0 apox = 0; // We need to find out if there has been a high-pass step on // the vertical decomposition sb2 = sb; do { if (sb2.orientation == Subband.WT_ORIENT_HH || sb2.orientation == Subband.WT_ORIENT_LH) { // Vertical high-pass step => project to 0 and done apoy = 0; break; } if (sb2.gOrient == Subband.WT_ORIENT_LL) { // Only low-pass steps left, no need to continue // checking break; } sb2 = sb2.getParent(); } while (sb2 != null); break; case Subband.WT_ORIENT_LH: // We need to find out if there has been a high-pass step on // the horizontal decomposition sb2 = sb; do { if (sb2.orientation == Subband.WT_ORIENT_HH || sb2.orientation == Subband.WT_ORIENT_HL) { // Horizontal high-pass step => project to 0 and done apox = 0; break; } if (sb2.gOrient == Subband.WT_ORIENT_LL) { // Only low-pass steps left, no need to continue // checking break; } sb2 = sb2.getParent(); } while (sb2 != null); // There is at least a high-pass step on the vertical // decomposition => project to 0 apoy = 0; break; case Subband.WT_ORIENT_HH: // There is at least a high-pass step on the horiz. and // vertical decomposition => project to 0 apox = 0; apoy = 0; break; default: throw new Error("Internal JJ2000 error"); } // 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-apox+sb.nomCBlkW; co.x = (tmp+sb.w-1)/sb.nomCBlkW - (tmp/sb.nomCBlkW-1); tmp = sb.ulcy-apoy+sb.nomCBlkH; co.y = (tmp+sb.h-1)/sb.nomCBlkH - (tmp/sb.nomCBlkH-1); } return co; } /** * 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 * * @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) throws IOException { // Check parameters pl.checkList(BitstreamReaderAgent.OPT_PREFIX, pl.toNameArray(BitstreamReaderAgent.getParameterInfo())); // Check header length if (in.getPos() != hd.getTotalHeaderLength() + hd.initPos) { throw new IllegalArgumentException("Invalid header length"); } return new FileBitstreamReaderAgent(hd,in,decSpec,pl); } /** * 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 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 ){ 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; } 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 res; } /** * 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.getImgWidth()/hd.getImgHeight(); 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; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -