📄 invwtfull.java
字号:
* @param blk Its coordinates and dimensions specify the area to * return. If it contains a non-null data array, then it must be large * enough. If it contains a null data array a new one is created. The * fields in this object are modified to return the data. * * @param c The index of the component from which to get the data. * * @return The requested DataBlk * * @see #getCompData * */ public DataBlk getCompData(DataBlk blk, int c) { int j; Object src_data,dst_data; int src_data_int[],dst_data_int[]; float src_data_float[],dst_data_float[]; // To keep compiler happy dst_data = null; // Ensure output buffer switch (blk.getDataType()) { case DataBlk.TYPE_INT: dst_data_int = (int[]) blk.getData(); if (dst_data_int == null || dst_data_int.length < blk.w*blk.h) { dst_data_int = new int[blk.w*blk.h]; } dst_data = dst_data_int; break; case DataBlk.TYPE_FLOAT: dst_data_float = (float[]) blk.getData(); if (dst_data_float==null || dst_data_float.length<blk.w*blk.h) { dst_data_float = new float[blk.w*blk.h]; } dst_data = dst_data_float; break; } // Use getInternCompData() to get the data, since getInternCompData() // returns reference to internal buffer, we must copy it. blk = getInternCompData(blk,c); // Copy the data blk.setData(dst_data); blk.offset = 0; blk.scanw = blk.w; return blk; } /** * Performs the 2D inverse wavelet transform on a subband of the image, on * the specified component. This method will successively perform 1D * filtering steps on all columns and then all lines of the subband. * * @param db the buffer for the image/wavelet data. * * @param sb The subband to reconstruct. * * @param c The index of the component to reconstruct * */ private void wavelet2DReconstruction(DataBlk db,SubbandSyn sb,int c) { Object data; Object buf; int ulx, uly, w, h; int i,j,k; int offset; // If subband is empty (i.e. zero size) nothing to do if (sb.w==0 || sb.h==0) { return; } data = db.getData(); ulx = sb.ulx; uly = sb.uly; w = sb.w; h = sb.h; buf = null; // To keep compiler happy switch (sb.getHorWFilter().getDataType()) { case DataBlk.TYPE_INT: buf = new int[(w>=h) ? w : h]; break; case DataBlk.TYPE_FLOAT: buf = new float[(w>=h) ? w : h]; break; } //Perform the horizontal reconstruction offset = (uly-db.uly)*db.w + ulx-db.ulx; if (sb.ulcx%2==0) { // start index is even => use LPF for(i=0; i<h; i++, offset += db.w) { System.arraycopy(data,offset,buf,0,w); sb.hFilter.synthetize_lpf(buf,0,(w+1)/2,1,buf,(w+1)/2,w/2,1, data,offset,1); } } else { // start index is odd => use HPF for(i=0; i<h; i++, offset += db.w) { System.arraycopy(data,offset,buf,0,w); sb.hFilter.synthetize_hpf(buf,0,w/2,1,buf,w/2,(w+1)/2,1, data,offset,1); } } //Perform the vertical reconstruction offset = (uly-db.uly)*db.w+ulx-db.ulx; switch (sb.getVerWFilter().getDataType()) { case DataBlk.TYPE_INT: int data_int[], buf_int[]; data_int = (int[]) data; buf_int = (int[]) buf; if (sb.ulcy%2==0) { // start index is even => use LPF for(j=0; j<w; j++, offset++) { for(i=h-1, k=offset+i*db.w; i>=0; i--, k-=db.w) buf_int[i] = data_int[k]; sb.vFilter.synthetize_lpf(buf,0,(h+1)/2,1,buf,(h+1)/2, h/2,1,data,offset,db.w); } } else { // start index is odd => use HPF for(j=0; j<w; j++, offset++) { for(i=h-1, k=offset+i*db.w; i>=0; i--, k-= db.w) buf_int[i] = data_int[k]; sb.vFilter.synthetize_hpf(buf,0,h/2,1,buf,h/2,(h+1)/2,1, data,offset,db.w); } } break; case DataBlk.TYPE_FLOAT: float data_float[], buf_float[]; data_float = (float[]) data; buf_float = (float[]) buf; if (sb.ulcy%2==0) { // start index is even => use LPF for(j=0; j<w; j++, offset++) { for(i=h-1, k=offset+i*db.w; i>=0; i--, k-= db.w) buf_float[i] = data_float[k]; sb.vFilter.synthetize_lpf(buf,0,(h+1)/2,1,buf,(h+1)/2, h/2,1,data,offset,db.w); } } else { // start index is odd => use HPF for(j=0; j<w; j++, offset++) { for(i=h-1, k=offset+i*db.w; i>=0; i--, k-= db.w) buf_float[i] = data_float[k]; sb.vFilter.synthetize_hpf(buf,0,h/2,1,buf,h/2,(h+1)/2,1, data,offset,db.w); } } break; } } /** * Performs the inverse wavelet transform on the whole component. It * iteratively reconstructs the subbands from leaves up to the root * node. This method is recursive, the first call to it the 'sb' must be * the root of the subband tree. The method will then process the entire * subband tree by calling itslef recursively. * * @param img The buffer for the image/wavelet data. * * @param sb The subband to reconstruct. * * @param c The index of the component to reconstruct * */ private void waveletTreeReconstruction(DataBlk img,SubbandSyn sb,int c) { DataBlk subbData; // If the current subband is a leaf then get the data from the source if(!sb.isNode) { int i,m,n; Object src_data,dst_data; Coord ncblks; if (sb.w==0 || sb.h==0) { return; // If empty subband do nothing } // Get all code-blocks in subband if(dtype==DataBlk.TYPE_INT) { subbData = new DataBlkInt(); } else { subbData = new DataBlkFloat(); } ncblks = sb.numCb; dst_data = img.getData(); for (m=0; m<ncblks.y; m++) { for (n=0; n<ncblks.x; n++) { subbData = src.getInternCodeBlock(c,m,n,sb,subbData); src_data = subbData.getData(); if(pw!=null) { nDecCblk++; pw.updateProgressWatch(nDecCblk,null); } // Copy the data line by line for (i=subbData.h-1; i>=0; i--) { System.arraycopy(src_data, subbData.offset+i*subbData.scanw, dst_data, (subbData.uly+i)*img.w+subbData.ulx, subbData.w); } } } } else if(sb.isNode) { // Reconstruct the lower resolution levels if the current subbands // is a node //Perform the reconstruction of the LL subband waveletTreeReconstruction(img,(SubbandSyn)sb.getLL(),c); if(sb.resLvl<=reslvl-maxImgRes+ndl[c]){ //Reconstruct the other subbands waveletTreeReconstruction(img,(SubbandSyn)sb.getHL(),c); waveletTreeReconstruction(img,(SubbandSyn)sb.getLH(),c); waveletTreeReconstruction(img,(SubbandSyn)sb.getHH(),c); //Perform the 2D wavelet decomposition of the current subband wavelet2DReconstruction(img,(SubbandSyn)sb,c); } } } /** * Returns the implementation type of this wavelet transform, WT_IMPL_FULL * (full-page based transform). All components return the same. * * @param c The index of the component. * * @return WT_IMPL_FULL * * @see WaveletTransform#WT_IMPL_FULL * */ public int getImplementationType(int c) { return WaveletTransform.WT_IMPL_FULL; } /** * 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 index of the tile. * * @param y The vertical index of the new tile. * */ public void setTile(int x,int y) { int i; // Change tile super.setTile(x,y); int nc = src.getNumComps(); int tIdx = src.getTileIdx(); for(int c=0; c<nc; c++) { ndl[c] = src.getSynSubbandTree(tIdx,c).resLvl; } // Reset the decomposed component buffers. if (reconstructedComps != null) { for (i=reconstructedComps.length-1; i>=0; i--) { reconstructedComps[i] = null; } } cblkToDecode = 0; SubbandSyn root,sb; for(int c=0; c<nc; c++) { root = src.getSynSubbandTree(tIdx,c); for(int r=0; r<=reslvl-maxImgRes+root.resLvl; r++) { if(r==0) { sb = (SubbandSyn)root.getSubbandByIdx(0,0); if(sb!=null) cblkToDecode += sb.numCb.x*sb.numCb.y; } else { sb = (SubbandSyn)root.getSubbandByIdx(r,1); if(sb!=null) cblkToDecode += sb.numCb.x*sb.numCb.y; sb = (SubbandSyn)root.getSubbandByIdx(r,2); if(sb!=null) cblkToDecode += sb.numCb.x*sb.numCb.y; sb = (SubbandSyn)root.getSubbandByIdx(r,3); if(sb!=null) cblkToDecode += sb.numCb.x*sb.numCb.y; } } // Loop on resolution levels } // Loop on components nDecCblk = 0; if(pw!=null) { pw.initProgressWatch(0,cblkToDecode,"Decoding tile "+tIdx+"..."); } } /** * 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() { int i; // Change tile super.nextTile(); int nc = src.getNumComps(); int tIdx = src.getTileIdx(); for(int c=0; c<nc; c++) { ndl[c] = src.getSynSubbandTree(tIdx,c).resLvl; } // Reset the decomposed component buffers. if (reconstructedComps != null) { for (i=reconstructedComps.length-1; i>=0; i--) { reconstructedComps[i] = null; } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -