📄 pktdecoder.java
字号:
if((xr==sotEotArrayMax[c][0].x) && (sotEotArrayMax[c][0].x != (sotEotArray[c][r][0].x >> (mdl[c]-r)))){ if(r==0){ Px=(int)(sotEotArray[c][r][0].x/ Math.pow(2,mdl[c]-r)-sb.ulcx); } else { // If resolution level is not 0, then // divide packets' size by 2 - Not // documented in CD Px=(int)(sotEotArray[c][r][0].x/ Math.pow(2,mdl[c]-r+1)-sb.ulcx); ppx=ppx>>1; } } else{ if(r==0){ Px=(int)(xr/Math.pow(2,mdl[c]-r)-sb.ulcx); } else { // If resolution level is not 0, then // divide packets' size by 2 - Not // documented in CD Px=(int)(xr/Math.pow(2,mdl[c]-r+1) - sb.ulcx); ppx=ppx>>1; } } // Calculate vertical coordinate within subband // (including missing image) if((yr==sotEotArrayMax[c][0].y) && (sotEotArrayMax[c][0].y != (sotEotArray[c][r][0].y >> (mdl[c]-r)))){ if(r==0){ Py=(int)(sotEotArray[c][r][0].y/ Math.pow(2,mdl[c]-r)-sb.ulcy); } else { // If resolution level is not 0, // then divide packets' size by 2 // - Not documented in CD Py=(int)(sotEotArray[c][r][0].y/ Math.pow(2,mdl[c]-r+1)-sb.ulcy); ppy=ppy>>1; } } else{ if(r==0){ Py=(int)(yr/Math.pow(2,mdl[c]-r)-sb.ulcy); } else { // If resolution level is not 0, // then divide packets' size by 2 // - Not documented in CD Py=(int)(yr/Math.pow(2,mdl[c]-r+1) - sb.ulcy); ppy=ppy>>1; } } if( ((Px+ppx)<=0) || ((Py+ppy)<=0) || (Px>=sb.w) || (Py>=sb.h) ) { // Packet in missing image or after // the subband continue; } else{ // Create the packet precCoord[c][r][s][precIdx] = new PrecCoordInfo( (Px<0) ? 0 : Px, (Py<0) ? 0 : Py, (Px+ppx>=sb.w) ? sb.w : Px+ppx, (Py+ppy>=sb.h) ? sb.h : Py+ppy, xr, yr ); incrPrecIdx = true; } } } // End loop on subbands // Precinct partition is used and at least one // packet has been created for the current // resolution level so we increment the packet // index for each subband in the resolution level if( hd.precinctPartitionUsed() && incrPrecIdx ){ for(int s=subRange[c][r][0];s<=subRange[c][r][1];s++){ precIdxA[s]++; } } } // test packet } // End loop on horizontal coordinate } // End loop on vertical coordinate } /** * 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); } /** * Returns the code-blocks contained in the precinct which index is p for * component c, the resolution level r and the subband index s.The * returned object is a Vector object whose first element is a Coord * object containing the number of code-blocks in each direction and then, * cblks contains all the code-blocks indexes. * * @param c the component index * * @param r the resolution level * * @param s the subband index * * @param p the precinct index * * @return The code-blocks contained in the precinct as the first Coord * object stored in the Vector and then the code-blocks indexes * */ private Vector getCBlkInPrecinct(int c,int r,int s,int p) { Vector cblks = new Vector(); int pulx, puly, pw, ph; int cbIdx, culx, culy, cw, ch; int maxulx, maxuly; Coord numCB = new Coord(); SubbandSyn curSub = null; curSub = (SubbandSyn) src.getSubbandTree(tIdx,c). getSubbandByIdx(r,s); // No precinct or code-block in this resolution level or subband if( (curSub.h==0) || (curSub.w==0) || (precCoord[c][r]==null) || (precCoord[c][r][s]==null) || (precCoord[c][r][s][p]==null) || (cbCoord[c][r][s]==null) ){ cblks.addElement(new Coord(0,0)); return cblks; } pulx = precCoord[c][r][s][p].ulx; puly = precCoord[c][r][s][p].uly; pw = precCoord[c][r][s][p].w; ph = precCoord[c][r][s][p].h; numCB.x = numCB.y = 0; maxulx = maxuly = -1; for(int m=0;m<cbCoord[c][r][s].length;m++){ for(int n=0;n<cbCoord[c][r][s][m].length;n++){ culx = cbCoord[c][r][s][m][n].ulx - curSub.ulx; culy = cbCoord[c][r][s][m][n].uly - curSub.uly; cw = cbCoord[c][r][s][m][n].w; ch = cbCoord[c][r][s][m][n].h; // If precinct partition is used if(hd.precinctPartitionUsed()){ // If code-block is in packet if( (culx>=pulx) && ((culx+cw)<=(pw)) && (culy>=puly) && ((culy+ch)<=(ph)) ) { // Code block is in packet if( culx>maxulx ){ maxulx = culx; numCB.x++; } if( culy>maxuly ){ maxuly = culy; numCB.y++; } cblks.addElement(new Coord(m,n)); } } else { // Precinct partition is not used i.e. all the code-blocks // are in the packet if( culx>maxulx ){ numCB.x++; maxulx = culx; } if( culy>maxuly ){ numCB.y++; maxuly = culy; } cblks.addElement(new Coord(m,n)); } } } // Insert the number of code-blocks contained in a Coord object at the // begining of the vector cblks.insertElementAt(numCB, 0); return cblks; } /** * Finds the number of subbands in each resolution level according to the * decomposition tree of each component. JPEG 2000 part I supports only * dyadic decomposition. * * @return Minimun and maximum subband identifier for each resolution * level (First index= resolution level, second index = 0(minimum) or * 1(maximum)) * */ private int[][][] findSubInResLvl(){ int[][][] subRange = new int[nc][][]; for(int c=0;c<nc;c++){ subRange[c]= new int[mdl[c]+1][2]; // Dyadic decomposition for(int i=mdl[c]; i>0; i--){ subRange[c][i][0] = 1; subRange[c][i][1] = 3; } subRange[c][0][0] = 0; subRange[c][0][1] = 0; } return subRange; } /** * 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(); boolean precFound = false; for(int s=subRange[c][r][0]; s<=subRange[c][r][1];s++){ if(p<precCoord[c][r][s].length){ precFound = true; } } if(!precFound) { return false; } // If SOP markers are not used, return if(!sopUsed) return false; // 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 befor // SOP marker sgment 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]; // bin.sync(); 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 ! "); } } /** * Returns the 'sotEotArray' for the specified component and resolution * level. This method is used by the bit stream reader. * * @param c The component * * @param r The resolution level * */ public Coord[] getSotEotArray(int c,int r){ return sotEotArray[c][r]; } /** * Returns the 'sotEotArrayMax' for the specified component. This method * is used by the bit stream reader. * * @param c The component * */ public Coord[] getSotEotArrayMax(int c){ return sotEotArrayMax[c]; } /** * Returns the 'incArray' for the specified component and resolution * level. This method is used by the bit stream reader. * * @param c The component * * @param r The resolution level * */ public Coord getIncArray(int c,int r){ return incArray[c][r]; } /** * Returns the 'incArrayMax' for the specified component. This method is * used by the bit stream reader. * * @param c The component * */ public Coord getIncArrayMax(int c){ return incArrayMax[c]; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -