📄 filebitstreamreaderagent.java
字号:
"index: "+res); } } catch(NumberFormatException f){ throw new IllegalArgumentException("Invalid resolution level "+ "index ('-res' option) " + pl.getParameter("res")); } } // Verify reduction in resolution level mdl = decSpec.dls.getMin(); if(res>mdl){ FacilityManager.getMsgLogger(). printmsg(MsgLogger.WARNING, "Specified resolution level ("+res+") is larger"+ " than the maximum value. Setting it to "+ mdl +" (maximum value)"); res = mdl; } return; } remainingTileParts = 0; // Update 'res' value once all tile-part headers are read if(pl.getParameter("res") == null){ res = decSpec.dls.getMin(); } else{ try { res = pl.getIntParameter("res"); if(res<0){ throw new IllegalArgumentException("Specified negative "+ "resolution level index: "+ res); } } catch(NumberFormatException e){ throw new IllegalArgumentException("Invalid resolution level "+ "index ('-res' option) " + pl.getParameter("res")); } } // Verify reduction in resolution level mdl = decSpec.dls.getMin(); if(res>mdl){ FacilityManager.getMsgLogger(). printmsg(MsgLogger.WARNING, "Specified resolution level ("+res+") is larger"+ " than the maximum possible. Setting it to "+ mdl +" (maximum possible)"); res = mdl; } if(pl.getBooleanParameter("cdstr_info")) FacilityManager.getMsgLogger().printmsg(MsgLogger.INFO,strInfo); // Check presence of EOC marker is decoding rate not reached try{ if(!rateReached && in.readShort() != EOC){ FacilityManager.getMsgLogger(). printmsg(MsgLogger.WARNING,"EOC marker not found. "+ "Codestream is corrupted."); } } catch(EOFException e){ FacilityManager.getMsgLogger(). printmsg(MsgLogger.WARNING,"EOC marker is missing"); } // Bit-rate allocation if(!isTruncMode) allocateRate(); else{ // Take EOC into account if rate is not reached if(in.getPos()>=tnbytes) anbytes += 2; } } /** * Allocates output bit-rate for each tile in parsing mode: The allocator * simulates the truncation of a virtual layer-resolution progressive * codestream. * */ private void allocateRate() throws IOException { int stopOff = tnbytes; // In parsing mode, the bitrate is allocated related to each tile's // length in the bit stream // EOC marker's length anbytes += 2; // If there are too few bytes to read the tile part headers throw an // error if(anbytes > stopOff){ throw new Error("Requested bitrate is too small for parsing"); } // Calculate bitrate for each tile int rem = stopOff-anbytes; int totnByte = rem; for(int t=nt-1; t>0; t--){ rem -= nBytes[t]=(int)(totnByte*(totTileLen[t]/totAllTileLen)); } nBytes[0] = rem; } /** * Reads SOT marker segment of the tile-part header and calls related * methods of the HeaderDecoder to read other markers segments. The * tile-part header is entirely read when a SOD marker is encountered. * * @return The tile number of the tile part that was read * */ private int readTilePartHeader() throws IOException{ int tile, psot, tilePart; // SOT marker if(in.readShort() != SOT){ // check for SOT flag throw new CorruptedCodestreamException("SOT tag not found "+ "in tile-part start"); } // Lsot (shall equals 10) int lsot = in.readUnsignedShort(); if(lsot != 10) throw new CorruptedCodestreamException("Wrong length for "+ "SOT marker segment: "+ lsot); // Isot tile = in.readUnsignedShort(); if(tile>65534){ throw new CorruptedCodestreamException("Tile index too high in "+ "tile-part."); } // Psot psot = in.readInt(); if(psot<0) { throw new NotImplementedError("Tile length larger "+ "than maximum supported"); } // TPsot tilePart = in.read(); if( tilePart!=tilePartsRead[tile] || tilePart<0 || tilePart>254 ) throw new CorruptedCodestreamException("Out of order tile-part"); // TNsot int nrOfTileParts=in.read(); if(tilePart == 0){ remainingTileParts += nrOfTileParts- 1; tileParts[tile] = nrOfTileParts; tilePartLen[tile] = new int[nrOfTileParts]; tilePartNum[tile] = new int[nrOfTileParts]; firstPackOff[tile] = new int[nrOfTileParts]; tilePartHeadLen[tile] = new int[nrOfTileParts]; } // Other markers hd.resetHeaderMarkers(); hd.nTileParts[tile] = nrOfTileParts; // Decode and store the tile-part header (i.e. until a SOD marker is // found) do { hd.extractTilePartMarkSeg(in.readShort(),in,tile); } while((hd.markersFound & hd.SOD_FOUND)==0); // Read each marker segment previously found hd.readFoundTilePartMarkSeg(tile); tilePartLen[tile][tilePart]=psot; tilePartNum[tile][tilePart]=totTilePartsRead; totTilePartsRead++; // add to list of which tile each successive tile part belongs. // This list is needed if there are PPM markers used hd.setTileOfTileParts(tile); return tile; } /** * Reads packets of the current tile according to the * layer-resolution-component-position progressiveness. * * @param lys Index of the first layer for each component and resolution * * @param lye Index of the last layer * * @param ress Index of the first resolution level * * @param rese Index of the last resolution level * * @param comps Index of the first component * * @param compe Index of the last component * * @return True if rate has been reached * */ private boolean readLyResCompPos(int[][] lys,int lye,int ress,int rese, int comps,int compe, int curTilePart) throws IOException{ boolean pph=false; int nPrec; // Number of precincts int start; // Offset of current packet's head Vector[] cblks; Coord co; CBlkInfo cb; int t = getTileIdx(); // Current tile index boolean status=false; // True if decoding rate is reached when int lastByte = in.getPos()+tilePartLen[t][curTilePart]-1- tilePartHeadLen[t][curTilePart]; int minlys; // minimum layer start index of each component and // resolution minlys = 10000; for(int c=comps; c<compe; c++){ //loop on components for(int r=ress; r<rese; r++) {//loop on resolution levels if(lys[c]!=null && r<lys[c].length && lys[c][r]<minlys) minlys = lys[c][r]; } } int hlen,plen; String strInfo = "Tile "+getTileIdx()+" (tile-part:"+curTilePart+ "): offset, length, header length\n";; if(((Boolean)decSpec.pphs.getTileDef(t)).booleanValue()){ pph = true; } // Loop on layers for(int l=minlys; l<lye; l++){ // Loop on resolution levels for(int r=ress; r<rese; r++){ // Loop on components for(int c=comps; c<compe; c++){ // Check if resolution level is defined for this component if(r>mdl[c]) continue; if(l<lys[c][r]) continue; nPrec = pktDec.getNumPrecinct(c,r); // Loop on precints for(int p=0;p<nPrec; p++){ start = in.getPos(); // If packed packet headers are used, there is no need // to check that there are bytes enough to read header if(pph) pktDec.readPktHead(l,r,c,p,cbI[c][r],nBytes); // If we are about to read outside of tile-part, // skip to next tile-part if(start>lastByte && curTilePart < firstPackOff[t].length-1){ curTilePart++; in.seek(firstPackOff[t][curTilePart]); lastByte = in.getPos()+ tilePartLen[t][curTilePart]-1- tilePartHeadLen[t][curTilePart]; } // Read SOP marker segment if necessary status = pktDec.readSOPMarker(nBytes,p,c,r); if(status){ if(pl.getBooleanParameter("cdstr_info")) FacilityManager.getMsgLogger(). printmsg(MsgLogger.INFO,strInfo); return true; } if(!pph) status = pktDec.readPktHead(l,r,c,p,cbI[c][r], nBytes); if(status) { if(pl.getBooleanParameter("cdstr_info")) FacilityManager.getMsgLogger(). printmsg(MsgLogger.INFO,strInfo); return true; } // Store packet's head length hlen = in.getPos()-start; pktHL.addElement(new Integer(hlen)); // Reads packet's body status = pktDec.readPktBody(l,r,c,p,cbI[c][r],nBytes); plen = in.getPos()-start; strInfo+= " Pkt l="+l+",r="+r+",c="+c+": "+start+ ", "+plen+", "+hlen+"\n"; if(status) { if(pl.getBooleanParameter("cdstr_info")) FacilityManager.getMsgLogger(). printmsg(MsgLogger.INFO,strInfo); return true; } } // End lopp on precincts } // End loop on components } // End loop on resolution levels } // End loop on layers if(pl.getBooleanParameter("cdstr_info")) FacilityManager.getMsgLogger().printmsg(MsgLogger.INFO,strInfo); return false; // Decoding rate was not reached } /** * Reads packets of the current tile according to the * resolution-layer-component-position progressiveness. * * @param lys Index of the first layer for each component and resolution * * @param lye Index of the last layer * * @param ress Index of the first resolution level * * @param rese Index of the last resolution level * * @param comps Index of the first component * * @param compe Index of the last component * * @return True if rate has been reached * */ private boolean readResLyCompPos(int lys[][],int lye,int ress,int rese, int comps,int compe, int curTilePart) throws IOException{ boolean pph=false; int nPrec; int start; int t = getTileIdx(); // Current tile index
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -