⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 invwtfull.java

📁 java 实现的小波压缩库代码,内部包含了分析器
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        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 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 wavelet2DReconstruction(DataBlk img, 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 = img.getData();
        
        ulx = sb.ulx;
        uly = sb.uly;
        w = sb.w;
        h = sb.h;

        buf = null;  // To keep compiler happy
        
        switch (sb.hFilter.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-img.uly)*img.w + ulx-img.ulx;
        if (sb.ulcx%2==0) { // start index is even => use LPF
            for(i=0; i<h; i++, offset += img.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 += img.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-img.uly)*img.w+ulx-img.ulx;
        switch (sb.hFilter.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*img.w; i>=0; i--, k-= img.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, img.w);
                }
            }
            else { // start index is odd => use HPF
                for(j=0; j<w; j++, offset++) {
                    for(i=h-1, k=offset+i*img.w; i>=0; i--, k-= img.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, img.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*img.w; i>=0; i--, k-= img.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, img.w);
                }
            }
            else { // start index is odd => use HPF
                for(j=0; j<w; j++, offset++) {
                    for(i=h-1, k=offset+i*img.w; i>=0; i--, k-= img.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, img.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 = src.getNumCodeBlocks(sb,c,null);
            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();
                    // 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 the subband resolution is not greater than the wanted
            //(image) resolution level
            if(sb.level >= (decSpec.dls.getMin()-reslvl) ){
                //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);
        
        // Reset the decomposed component buffers.
        if (reconstructedComps != null) {
            for (i=reconstructedComps.length-1; i>=0; i--) {
                reconstructedComps[i] = null;
            }
        }
    }

    /**
     * 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();
        
        // 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 + -