00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
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
00050
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
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
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;
00151 double wgt;
00152 int dpth;
00153 OneDArray<int> qfac;
00154 int prt;
00155 std::vector<int> childvec;
00156 int max_bit;
00157 };
00158
00160 class SubbandList
00161 {
00162 public:
00164 SubbandList(){}
00165
00167 ~SubbandList(){}
00168
00169
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
00203
00205
00206
00207
00208
00209
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
00236
00237
00238
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
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
00305
00306
00307 SubbandList band_list;
00308
00310 int depth;
00311
00313 WltFilter filt_sort;
00314
00315
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 }
00333
00334 #endif