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

📄 forwwtfull.java

📁 java 实现的小波压缩库代码,内部包含了分析器
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        }
        cblk.setData(dst_data);
        cblk.offset = 0;
        cblk.scanw = w;
	
        return cblk;
    }
    
    /** 
     * Return the data type of this CBlkWTDataSrc. Its value should be either
     * DataBlk.TYPE_INT or DataBlk.TYPE_FLOAT but can change according to the
     * current tile-component.
     *
     * @param t The index of the tile for which to return the data type.
     *
     * @param c The index of the component for which to return the data type.
     *
     * @return Current data type
     * */
    public int getDataType(int t,int c){
	return filters.getWTDataType(t,c);
    }

    /**
     * Returns the next subband that will be used to get the next code-block
     * to return by the getNext[Intern]CodeBlock method.
     *
     * @param c The component
     *
     * @return Its returns the next subband that will be used to get the next
     * code-block to return by the getNext[Intern]CodeBlock method.
     **/
    private SubbandAn getNextSubband(int c) {
        int down = 1;
        int up = 0;
        int direction = down;
        SubbandAn nextsb;
        
        nextsb = currentSubband[c];
        //If it is the first call to this method
        if(nextsb == null) {
            nextsb = this.getSubbandTree(tIdx,c);
            //If there is no decomposition level then send the whole image
            if(!nextsb.isNode) {
                return nextsb;
            }
        }
        
        //Find the next subband to send
        do {
            //If the current subband is null then break
            if(nextsb == null) {
                break;
            }
                
            //If the current subband is a leaf then select the next leaf to
            //send or go up in the decomposition tree if the leaf was a LL
            //one.
            else if(!nextsb.isNode) {
                switch (nextsb.orientation) {
                    case Subband.WT_ORIENT_HH :
                        nextsb = (SubbandAn)nextsb.getParent().getLH();
                        direction = down;
                        break;
                    case Subband.WT_ORIENT_LH :
                        nextsb = (SubbandAn)nextsb.getParent().getHL();
                        direction = down;
                        break;
                    case Subband.WT_ORIENT_HL :
                        nextsb = (SubbandAn)nextsb.getParent().getLL();
                        direction = down;
                        break;
                    case Subband.WT_ORIENT_LL :
                        nextsb = (SubbandAn)nextsb.getParent();
                        direction = up;
                        break;
                }
            }
            
            //Else if the current subband is a node 
            else if(nextsb.isNode) {
                //If the direction is down the select the HH subband of the
                //current node.
                if(direction == down) {
                    nextsb = (SubbandAn)nextsb.getHH();
                }
                //Else the direction is up the select the next node to cover
                //or still go up in the decomposition tree if the node is a LL
                //subband
                else if(direction == up) {
                    switch (nextsb.orientation) {
                        case Subband.WT_ORIENT_HH :
                            nextsb = (SubbandAn)nextsb.getParent().getLH();
                            direction = down;
                            break;
                        case Subband.WT_ORIENT_LH :
                            nextsb = (SubbandAn)nextsb.getParent().getHL();
                            direction = down;
                            break;
                        case Subband.WT_ORIENT_HL :
                            nextsb = (SubbandAn)nextsb.getParent().getLL();
                            direction = down;
                            break;
                        case Subband.WT_ORIENT_LL :
                            nextsb = (SubbandAn)nextsb.getParent();
                            direction = up;
                            break;
                    }
                }
            }
            
            if(nextsb == null) {
                break;               
            }
        } while(nextsb.isNode);
        return nextsb;   
    }
    
    /**
     * Performs the forward wavelet transform on the whole band. It
     * iteratively decomposes the subbands from the top node to the leaves.
     *
     * @param band The band containing the float data to decompose
     *
     * @param subband The structure containing the coordinates of the current
     * subband in the whole band to decompose.
     *
     * @param c The index of the current component to decompose
     * */
    private void waveletTreeDecomposition(DataBlk band,
                                          SubbandAn subband, int c) {
    
        //If the current subband is a leaf then nothing to be done (a leaf is
        //not decomposed).
        if(!subband.isNode) {
            return;
        }
        else {
            //Perform the 2D wavelet decomposition of the current subband
            wavelet2DDecomposition(band, (SubbandAn)subband, c);
            
            //Perform the decomposition of the four resulting subbands
            waveletTreeDecomposition(band, (SubbandAn)subband.getHH(), c);
            waveletTreeDecomposition(band, (SubbandAn)subband.getLH(), c);
            waveletTreeDecomposition(band, (SubbandAn)subband.getHL(), c);
            waveletTreeDecomposition(band, (SubbandAn)subband.getLL(), c);
        }
    }
    
    /**
     * Performs the 2D forward wavelet transform on a subband of the initial
     * band. This method will successively perform 1D filtering steps on all
     * lines and then all columns of the subband. In this class only filters
     * with floating point implementations can be used.
     *
     * @param band The band containing the float data to decompose
     *
     * @param subband The structure containing the coordinates of the subband
     * in the whole band to decompose.
     *
     * @param c The index of the current component to decompose
     * */
    private void wavelet2DDecomposition(DataBlk band,SubbandAn subband,int c) {
        
        int ulx, uly, w, h;
        int band_w, band_h;

        // If subband is empty (i.e. zero size) nothing to do
        if (subband.w == 0 || subband.h == 0) {
            return;
        }

        ulx = subband.ulx;
        uly = subband.uly;
        w = subband.w;
        h = subband.h;
        band_w = getCompWidth(c);
        band_h = getCompHeight(c);
        
        if ( intData ) {
            //Perform the decompositions if the filter is implemented with an
            //integer arithmetic.
            int i, j;
            int offset;
            int[] tmpVector = new int[java.lang.Math.max(w,h)];
            int[] data = ((DataBlkInt)band).getDataInt();

            //Perform the vertical decomposition
            if (subband.ulcy%2==0) { // Even start index => use LPF
                for(j=0; j<w; j++) {
                    offset = uly*band_w + ulx+j;
                    for(i=0; i<h; i++)
                        tmpVector[i] = data[offset+(i*band_w)];
                    subband.vFilter.analyze_lpf(tmpVector, 0, h, 1,
                                             data, offset, band_w,
                                             data, offset+((h+1)/2)*band_w,
                                             band_w);
                }
            }
            else { // Odd start index => use HPF
                for(j=0; j<w; j++) {
                    offset = uly*band_w + ulx+j;
                    for(i=0; i<h; i++)
                        tmpVector[i] = data[offset+(i*band_w)];
                    subband.vFilter.analyze_hpf(tmpVector, 0, h, 1,
                                             data, offset, band_w,
                                             data, offset+(h/2)*band_w,
                                             band_w);
                }
            }

            //Perform the horizontal decomposition.
            if (subband.ulcx%2==0) { // Even start index => use LPF
                for(i=0; i<h; i++) {
                    offset = (uly+i)*band_w + ulx;
                    for(j=0; j<w; j++)
                        tmpVector[j] = data[offset+j];
                    subband.hFilter.analyze_lpf(tmpVector, 0, w, 1, 
                                             data, offset, 1, 
                                             data, offset+(w+1)/2, 1);
                }
            }
            else { // Odd start index => use HPF
                for(i=0; i<h; i++) {
                    offset = (uly+i)*band_w + ulx;
                    for(j=0; j<w; j++)
                        tmpVector[j] = data[offset+j];
                    subband.hFilter.analyze_hpf(tmpVector, 0, w, 1, 
                                             data, offset, 1, 
                                             data, offset+w/2, 1);
                }
            }
        }
        else {
            //Perform the decompositions if the filter is implemented with a
            //float arithmetic.
            int i, j;
            int offset;
            float[] tmpVector = new float[java.lang.Math.max(w,h)];
            float[]data = ((DataBlkFloat)band).getDataFloat();

            //Perform the vertical decomposition.
            if (subband.ulcy%2==0) { // Even start index => use LPF
                for(j=0; j<w; j++) {
                    offset = uly*band_w + ulx+j;
                    for(i=0; i<h; i++)
                        tmpVector[i] = data[offset+(i*band_w)];
                    subband.vFilter.analyze_lpf(tmpVector, 0, h, 1,
                                             data, offset, band_w,
                                             data, offset+((h+1)/2)*band_w,
                                             band_w);
                }
            }
            else { // Odd start index => use HPF
                for(j=0; j<w; j++) {
                    offset = uly*band_w + ulx+j;
                    for(i=0; i<h; i++)
                        tmpVector[i] = data[offset+(i*band_w)];
                    subband.vFilter.analyze_hpf(tmpVector, 0, h, 1,
                                             data, offset, band_w,
                                             data, offset+(h/2)*band_w,
                                             band_w);
                }
            }
            //Perform the horizontal decomposition.
            if (subband.ulcx%2==0) { // Even start index => use LPF
                for(i=0; i<h; i++) {
                    offset = (uly+i)*band_w + ulx;
                    for(j=0; j<w; j++)
                        tmpVector[j] = data[offset+j];
                    subband.hFilter.analyze_lpf(tmpVector, 0, w, 1, 
                                             data, offset, 1, 
                                             data, offset+(w+1)/2, 1);
                }
            }
            else { // Odd start index => use HPF
                for(i=0; i<h; i++) {
                    offset = (uly+i)*band_w + ulx;
                    for(j=0; j<w; j++)
                        tmpVector[j] = data[offset+j];
                    subband.hFilter.analyze_hpf(tmpVector, 0, w, 1, 
                                             data, offset, 1, 
                                             data, offset+w/2, 1);
                }
            }
        }
    }
    
    /**
     * Changes the current tile, given the new coordinates. 
     *
     * <p>This method resets the 'subbTrees' array, and recalculates the
     * values of the 'reversible' array. It also resets the decomposed
     * component buffers.</p>
     *
     * @param x The horizontal coordinate of the tile.
     *
     * @param y The vertical coordinate 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 (decomposedComps != null) {
            for (i=decomposedComps.length-1; i>=0; i--) {
                decomposedComps[i] = null;
                currentSubband[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).
     *
     * <p>This method resets the 'subbTrees' array, and recalculates the
     * values of the 'reversible' array. It also resets the decomposed
     * component buffers.</p>
     * */
    public void nextTile() {
        int i;

        // Change tile
        super.nextTile();
        // Reset the decomposed component buffers
        if (decomposedComps != null) {
            for (i=decomposedComps.length-1; i>=0; i--) {
                decomposedComps[i] = null;
                currentSubband[i] = null;
            }
        }

    }
    
    /** 
     * Returns a reference to the subband tree structure representing the
     * subband decomposition for the specified tile-component of the source.
     * 
     * @param t The index of the tile. 
     * 
     * @param c The index of the component. 
     * 
     * @return The subband tree structure, see Subband. 
     * 
     * @see SubbandAn 
     * @see Subband 
     * */ 
    public SubbandAn getSubbandTree(int t,int c) { 
        if (subbTrees[t][c] == null) {
            subbTrees[t][c] =
                new SubbandAn(getCompWidth(c),getCompHeight(c),
                              getULX(c),getULY(c),
                              getDecompLevels(t,c),
                              getHorAnWaveletFilters(t,c),
                              getVertAnWaveletFilters(t,c));
        }
        return subbTrees[t][c];
    } 
     

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -