wavelet_utils.h

00001 /* ***** BEGIN LICENSE BLOCK *****
00002 *
00003 * $Id: wavelet_utils.h,v 1.2 2005/01/30 05:11:40 gabest Exp $ $Name:  $
00004 *
00005 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00006 *
00007 * The contents of this file are subject to the Mozilla Public License
00008 * Version 1.1 (the "License"); you may not use this file except in compliance
00009 * with the License. You may obtain a copy of the License at
00010 * http://www.mozilla.org/MPL/
00011 *
00012 * Software distributed under the License is distributed on an "AS IS" basis,
00013 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
00014 * the specific language governing rights and limitations under the License.
00015 *
00016 * The Original Code is BBC Research and Development code.
00017 *
00018 * The Initial Developer of the Original Code is the British Broadcasting
00019 * Corporation.
00020 * Portions created by the Initial Developer are Copyright (C) 2004.
00021 * All Rights Reserved.
00022 *
00023 * Contributor(s): Thomas Davies (Original Author), Scott R Ladd
00024 *
00025 * Alternatively, the contents of this file may be used under the terms of
00026 * the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser
00027 * Public License Version 2.1 (the "LGPL"), in which case the provisions of
00028 * the GPL or the LGPL are applicable instead of those above. If you wish to
00029 * allow use of your version of this file only under the terms of the either
00030 * the GPL or LGPL and not to allow others to use your version of this file
00031 * under the MPL, indicate your decision by deleting the provisions above
00032 * and replace them with the notice and other provisions required by the GPL
00033 * or LGPL. If you do not delete the provisions above, a recipient may use
00034 * your version of this file under the terms of any one of the MPL, the GPL
00035 * or the LGPL.
00036 * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef _WAVELET_UTILS_H_
00039 #define _WAVELET_UTILS_H_
00040 
00041 #include <libdirac_common/arrays.h>
00042 #include <libdirac_common/common.h>
00043 #include <vector>
00044 #include <cmath>
00045 #include <iostream>
00046 
00047 namespace dirac
00048 {
00049     //utilities for subband and wavelet transforms
00050     //Includes fast transform using lifting
00051 
00052     class PicArray;
00053 
00055     class Subband
00056     {
00057     public:
00058 
00060         Subband();
00061 
00063 
00070         Subband(int xpos, int ypos, int xlen, int ylen);
00071 
00073 
00081         Subband(int xpos, int ypos, int xlen, int ylen, int d);
00082 
00084         ~Subband();
00085 
00086         //Default (shallow) copy constructor and operator= used
00087 
00089         int Xl() const {return xln;}
00090         
00092         int Xp() const {return xps;}
00093         
00095         int Yl() const {return yln;}
00096         
00098         int Yp() const {return yps;}
00099         
00101         int Max() const {return max_bit;}
00102         
00104         double Wt() const {return wgt;}
00105         
00107         int Depth() const {return dpth;}
00108         
00110         int Scale() const {return (1<<dpth);}
00111         
00113         int Qf(int n) const {return qfac[n];}
00114         
00116         int Parent() const {return prt;}
00117         
00119         std::vector<int> Children() const {return childvec;}
00120         
00121         int Child(int n) const {return childvec[n];}
00122 
00123         // ... and sets
00125         void SetQf(int n, int q)
00126         {
00127             if (n >= qfac.First() && n<=qfac.Last() )
00128                 qfac[n]=q;
00129         }
00130         
00132         void SetWt(float w){wgt=w;}
00133         
00135         void SetParent(int p){prt=p;}
00136         
00138         void SetDepth(int d){dpth=d;}
00139         
00141         void SetMax(int m){max_bit=m;};
00142         
00144         void SetChildren(std::vector<int>& clist){childvec=clist;}
00145         
00147         void AddChild(int c){childvec.push_back(c);}
00148 
00149     private:
00150         int xps,yps,xln,yln;        //subband bounds
00151         double wgt;                    //perceptual weight for quantisation
00152         int dpth;                    //depth in the transform
00153         OneDArray<int> qfac;        //quantisers
00154         int prt;                    //position of parent in a subband list
00155         std::vector<int> childvec;    //positions of children in the subband list
00156         int max_bit;                //position of the MSB of the largest absolute value
00157     };
00158 
00160     class SubbandList
00161     {
00162     public:
00164         SubbandList(){}
00165 
00167         ~SubbandList(){}
00168 
00169         //Default (shallow) copy constructor and operator= used
00171         void Init(const int depth,const int xlen,const int ylen);
00172         
00174         int Length() const {return bands.size();}
00175         
00177         Subband& operator()(int n){return bands[n-1];}
00178         
00180         const Subband& operator()(int n) const {return bands[n-1];}    
00181         
00183         void AddBand(Subband& b){bands.push_back(b);}
00184         
00186         void Clear(){bands.clear();}
00187         
00188     private:    
00189         std::vector<Subband> bands;
00190     };
00191 
00192 
00194     template <int gain> class PredictStep
00195     {
00196 
00197     public:
00198 
00200         PredictStep(){}
00201 
00202         // Assume default copy constructor, assignment= and destructor //
00203 
00205         /*
00206             Do the filtering.
00207             \param   in_val   the value being predicted
00208             \param   val1   the first value being used for prediction
00209             \param   val2   the second value being used for prediction
00210         */
00211         void Filter(ValueType& in_val, const ValueType& val1, const ValueType& val2) const;
00212 
00213     private:
00214 
00215     }; 
00216 
00217     template <int gain>
00218     inline void  PredictStep<gain>::Filter( ValueType& in_val, 
00219                                                 const ValueType& val1, 
00220                                                 const ValueType& val2) const
00221     {
00222         in_val -= static_cast< ValueType >( (gain * static_cast< int >( val1 + val2 )) >>12 );
00223     }
00224 
00226     template <int gain> class UpdateStep
00227     {
00228 
00229     public:
00231         UpdateStep(){}
00232 
00234         /*
00235             Do the filtering.
00236             \param   in_val   the value being updated
00237             \param   val1   the first value being used for updating
00238             \param   val2   the second value being used for updating
00239         */
00240         void Filter(ValueType& in_val, const ValueType& val1, const ValueType& val2) const;
00241 
00242     private:
00243 
00244     };  
00245 
00246     template <int gain>
00247     inline void UpdateStep<gain>::Filter(ValueType& in_val,
00248                                               const ValueType& val1, 
00249                                               const ValueType& val2) const
00250     {
00251         in_val += static_cast< ValueType >( (gain * static_cast< int >( val1 + val2 )) >>12 );
00252     }
00253 
00254 
00255 
00256 
00257 
00259 
00263     class WaveletTransform
00264     {
00265     public:
00267         // WaveletTransform(WaveletTransformParams p);
00268         WaveletTransform(int d = 4, WltFilter f = DAUB);
00269             
00271         virtual ~WaveletTransform();
00272 
00274 
00279         void Transform(const Direction d, PicArray& pic_data);
00280         
00282         SubbandList& BandList(){return band_list;}
00283         
00285         const SubbandList& BandList() const {return band_list;}
00286         
00288 
00298         void SetBandWeights (const float cpd, 
00299                              const FrameSort& fsort,
00300                              const ChromaFormat& cformat,
00301                              const CompSort csort);
00302 
00303     private:
00304         //other private variables    
00305         // WaveletTransformParams params;
00306 
00307         SubbandList band_list;
00308 
00310         int depth;
00311         
00313         WltFilter filt_sort;    
00314 
00315         //functions
00317         WaveletTransform(const WaveletTransform& cpy);
00318         
00320         WaveletTransform& operator=(const WaveletTransform& rhs);
00321 
00323         float PerceptualWeight(float xf,float yf,CompSort cs);
00324 
00326         void VHSplit(const int xp, const int yp, const int xl, const int yl, PicArray&pic_data); 
00327 
00329         void VHSynth(const int xp, const int yp, const int xl, const int yl, PicArray& pic_data);
00330 };
00331 
00332 } // namespace dirac
00333 
00334 #endif

Generated on Tue Dec 13 14:47:15 2005 for guliverkli by  doxygen 1.4.5