Dirac - A Video Codec

Created by the British Broadcasting Corporation.


wavelet_utils.h

Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK ***** 00002 * 00003 * $Id: wavelet_utils.h,v 1.10 2004/08/03 09:22:59 asuraparaju Exp $ $Name: Dirac_0_4_3 $ 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 //utilities for subband and wavelet transforms 00048 //Includes fast transform using lifting 00049 00050 class PicArray; 00051 00053 class Subband 00054 { 00055 public: 00056 00058 Subband(); 00059 00061 00068 Subband(int xpos, int ypos, int xlen, int ylen); 00069 00071 00079 Subband(int xpos, int ypos, int xlen, int ylen, int d); 00080 00082 ~Subband(); 00083 00084 //Default (shallow) copy constructor and operator= used 00085 00087 int Xl() const {return xln;} 00088 00090 int Xp() const {return xps;} 00091 00093 int Yl() const {return yln;} 00094 00096 int Yp() const {return yps;} 00097 00099 int Max() const {return max_bit;} 00100 00102 double Wt() const {return wgt;} 00103 00105 int Depth() const {return dpth;} 00106 00108 int Scale() const {return (1<<dpth);} 00109 00111 int Qf(int n) const {return qfac[n];} 00112 00114 int Parent() const {return prt;} 00115 00117 std::vector<int> Children() const {return childvec;} 00118 00119 int Child(int n) const {return childvec[n];} 00120 00121 // ... and sets 00123 void SetQf(int n, int q) 00124 { 00125 if (n >= qfac.First() && n<=qfac.Last() ) 00126 qfac[n]=q; 00127 } 00128 00130 void SetWt(float w){wgt=w;} 00131 00133 void SetParent(int p){prt=p;} 00134 00136 void SetDepth(int d){dpth=d;} 00137 00139 void SetMax(int m){max_bit=m;}; 00140 00142 void SetChildren(std::vector<int>& clist){childvec=clist;} 00143 00145 void AddChild(int c){childvec.push_back(c);} 00146 00147 private: 00148 int xps,yps,xln,yln; //subband bounds 00149 double wgt; //perceptual weight for quantisation 00150 int dpth; //depth in the transform 00151 OneDArray<int> qfac; //quantisers 00152 int prt; //position of parent in a subband list 00153 std::vector<int> childvec; //positions of children in the subband list 00154 int max_bit; //position of the MSB of the largest absolute value 00155 }; 00156 00158 class SubbandList 00159 { 00160 public: 00162 SubbandList(){} 00163 00165 ~SubbandList(){} 00166 00167 //Default (shallow) copy constructor and operator= used 00169 void Init(const int depth,const int xlen,const int ylen); 00170 00172 int Length() const {return bands.size();} 00173 00175 Subband& operator()(int n){return bands[n-1];} 00176 00178 const Subband& operator()(int n) const {return bands[n-1];} 00179 00181 void AddBand(Subband& b){bands.push_back(b);} 00182 00184 void Clear(){bands.clear();} 00185 00186 private: 00187 std::vector<Subband> bands; 00188 }; 00189 00190 00192 template <int gain> class PredictStep 00193 { 00194 00195 public: 00196 00198 PredictStep(){} 00199 00200 // Assume default copy constructor, assignment= and destructor // 00201 00203 /* 00204 Do the filtering. 00205 \param in_val the value being predicted 00206 \param val1 the first value being used for prediction 00207 \param val2 the second value being used for prediction 00208 */ 00209 void Filter(ValueType& in_val, const ValueType& val1, const ValueType& val2) const; 00210 00211 private: 00212 00213 }; 00214 00215 template <int gain> 00216 inline void PredictStep<gain>::Filter( ValueType& in_val, 00217 const ValueType& val1, 00218 const ValueType& val2) const 00219 { 00220 in_val -= static_cast< ValueType >( (gain * static_cast< int >( val1 + val2 )) >>12 ); 00221 } 00222 00224 template <int gain> class UpdateStep 00225 { 00226 00227 public: 00229 UpdateStep(){} 00230 00232 /* 00233 Do the filtering. 00234 \param in_val the value being updated 00235 \param val1 the first value being used for updating 00236 \param val2 the second value being used for updating 00237 */ 00238 void Filter(ValueType& in_val, const ValueType& val1, const ValueType& val2) const; 00239 00240 private: 00241 00242 }; 00243 00244 template <int gain> 00245 inline void UpdateStep<gain>::Filter(ValueType& in_val, 00246 const ValueType& val1, 00247 const ValueType& val2) const 00248 { 00249 in_val += static_cast< ValueType >( (gain * static_cast< int >( val1 + val2 )) >>12 ); 00250 } 00251 00252 00253 00254 00255 00257 00261 class WaveletTransform 00262 { 00263 public: 00265 // WaveletTransform(WaveletTransformParams p); 00266 WaveletTransform(int d = 4, WltFilter f = DAUB); 00267 00269 virtual ~WaveletTransform(); 00270 00272 00277 void Transform(const Direction d, PicArray& pic_data); 00278 00280 SubbandList& BandList(){return band_list;} 00281 00283 const SubbandList& BandList() const {return band_list;} 00284 00286 00296 void SetBandWeights (const float cpd, 00297 const FrameSort& fsort, 00298 const ChromaFormat& cformat, 00299 const CompSort csort); 00300 00301 private: 00302 //other private variables 00303 // WaveletTransformParams params; 00304 00305 SubbandList band_list; 00306 00308 int depth; 00309 00311 WltFilter filt_sort; 00312 00313 //functions 00315 WaveletTransform(const WaveletTransform& cpy); 00316 00318 WaveletTransform& operator=(const WaveletTransform& rhs); 00319 00321 float PerceptualWeight(float xf,float yf,CompSort cs); 00322 void VHSplit(const int xp, const int yp, const int xl, const int yl, PicArray&pic_data); 00323 void VHSplit2(const int xp, const int yp, const int xl, const int yl, PicArray&pic_data); 00324 void VHSynth(const int xp, const int yp, const int xl, const int yl, PicArray& pic_data); 00325 void VHSynth2(const int xp, const int yp, const int xl, const int yl, PicArray& pic_data); 00326 }; 00327 00328 #endif

© 2004 British Broadcasting Corporation. Dirac code licensed under the Mozilla Public License (MPL) Version 1.1.
HTML documentation generated by Dimitri van Heesch's excellent Doxygen tool.