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.15 2005/02/15 11:15:33 asuraparaju Exp $ $Name: Dirac_0_5_1 $
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 namespace dirac
00051 {
00052 
00053     class PicArray;
00054     class Subband;
00055 
00057     class CodeBlock
00058     {
00059 
00060     friend class Subband;
00061 
00062     public:
00064         /*
00065             Default constructor - sets all dimensions to zero
00066         */
00067         CodeBlock();
00068 
00070         /*
00071             Initialise the code block
00072             \param    xstart  the x-coord of the first coefficient in the block
00073             \param    xend    one past the last coefficient, horizontally    
00074             \param    ystart  the y-coord of the first coefficient in the block
00075             \param    yend    one past the last coefficient, vertically    
00076         */
00077         CodeBlock( const int xstart , const int ystart , const int xend , const int yend);
00078 
00080         int Xstart() const { return m_xstart; }
00081 
00083         int Ystart() const { return m_ystart; }
00084     
00086         int Xend() const { return m_xend; }
00087 
00089         int Yend() const { return m_yend; }
00090 
00092         int Xl() const { return m_xl; }
00093 
00095         int Yl() const { return m_yl; }
00096 
00098         int QIndex() const{ return m_qindex; }
00099 
00101         float Wt() const { return m_wt; }
00102 
00104         bool Skipped() const { return m_skipped; }
00105 
00107         void SetQIndex( const int qindex ){ m_qindex = qindex; }
00108 
00110         void SetSkip( bool skip ){ m_skipped = skip; }
00111 
00112     private:
00113 
00115         /*
00116             Initialise the code block
00117             \param    xstart  the x-coord of the first coefficient in the block
00118             \param    xend    one past the last coefficient, horizontally    
00119             \param    ystart  the y-coord of the first coefficient in the block
00120             \param    yend    one past the last coefficient, vertically    
00121         */
00122         void Init( const int xstart , const int ystart , const int xend , const int yend );
00123 
00125         void SetWt( const float w ){ m_wt = w; }
00126 
00127 
00128     private:
00129 
00130         int m_xstart;
00131         int m_ystart;
00132         int m_xend;
00133         int m_yend;
00134         int m_xl;
00135         int m_yl;
00136 
00137         int m_qindex;
00138         float m_wt;
00139 
00140         bool m_skipped;
00141     };
00142 
00143 
00145     class Subband
00146     {
00147     public:
00148 
00150         Subband();
00151 
00153 
00161         Subband(int xpos, int ypos, int xlen, int ylen);
00162 
00164 
00173         Subband(int xpos, int ypos, int xlen, int ylen, int d);
00174 
00176         ~Subband();
00177 
00178         //Default (shallow) copy constructor and operator= used
00179 
00181         int Xl() const {return m_xl;}
00182     
00184         int Xp() const {return m_xp;}
00185     
00187         int Yl() const {return m_yl;}
00188     
00190         int Yp() const {return m_yp;}
00191     
00193         int Max() const {return m_max_bit;}
00194     
00196         double Wt() const {return m_wt;}
00197     
00199         int Depth() const {return m_depth;}
00200     
00202         int Scale() const {return ( 1<<m_depth );}
00203     
00205         int QIndex() const {return m_qindex;}
00206 
00208         bool UsingMultiQuants() const {return m_multi_quants; } 
00209     
00211         int Parent() const {return m_parent;}
00212     
00214         const std::vector<int>& Children() const {return m_children;}
00215 
00217         int Child(const int n) const {return m_children[n];}
00218 
00220         TwoDArray<CodeBlock>& GetCodeBlocks(){ return m_code_block_array; } 
00221 
00223         const TwoDArray<CodeBlock>& GetCodeBlocks() const { return m_code_block_array; } 
00224 
00226         bool Skipped() const { return m_skipped; }
00227     
00229         void SetWt( const float w );
00230     
00232         void SetParent( const int p ){ m_parent=p; }
00233     
00235         void SetDepth( const int d ){ m_depth=d;}
00236     
00238         void SetMax( const int m ){ m_max_bit=m; };
00239     
00241         void SetChildren( const std::vector<int>& clist ){ m_children = clist; }
00242     
00244         void AddChild( const int c ){ m_children.push_back(c); }
00245 
00247         void SetNumBlocks( const int ynum , const int xnum );
00248 
00250         void SetQIndex( const int idx){ m_qindex = idx; }
00251 
00253         void SetUsingMultiQuants( const bool multi){ m_multi_quants = multi; }
00254 
00256         void SetSkip(const bool skip ){ m_skipped = skip; }
00257 
00258     private:
00259         // subband bounds
00260         int m_xp , m_yp , m_xl , m_yl; 
00261 
00262         // perceptual weight for quantisation
00263         double m_wt;
00264 
00265         // depth in the transform
00266         int m_depth;
00267 
00268         // quantiser index
00269         int m_qindex;
00270 
00271         // position of parent in a subband list
00272         int m_parent;
00273 
00274         // positions of children in the subband list
00275         std::vector<int> m_children;
00276 
00277         // position of the MSB of the largest absolute value
00278         int m_max_bit;              
00279 
00280         // The code blocks
00281         TwoDArray<CodeBlock> m_code_block_array;
00282 
00283         // A flag indicating whether we're using one qf for each code block
00284         bool m_multi_quants;
00285 
00286         // Whether the subband is skipped or not
00287         bool m_skipped;
00288     };
00289 
00291     class SubbandList
00292     {
00293     public:
00295         SubbandList(){}
00296 
00298         ~SubbandList(){}
00299 
00300         //Default (shallow) copy constructor and operator= used
00302         void Init(const int depth,const int xlen,const int ylen);
00303     
00305         int Length() const {return bands.size();}
00306     
00308         Subband& operator()(const int n){return bands[n-1];}
00309     
00311         const Subband& operator()(const int n) const {return bands[n-1];}    
00312     
00314         void AddBand(const Subband& b){bands.push_back(b);}
00315         
00317         void Clear(){bands.clear();}
00318 
00320 
00330         void SetBandWeights (const float cpd, 
00331                              const FrameSort& fsort,
00332                              const ChromaFormat& cformat,
00333                              const CompSort csort);
00334     
00335     private:
00336 
00338         float PerceptualWeight( const float xf , const float yf , const CompSort cs);
00339 
00340     private:    
00341         std::vector<Subband> bands;
00342     };
00343 
00344 
00346     template <int gain> class PredictStep
00347     {
00348 
00349     public:
00350 
00352         PredictStep(){}
00353 
00354         // Assume default copy constructor, assignment= and destructor //
00355 
00357         /*
00358             Do the filtering.
00359             \param   in_val   the value being predicted
00360             \param   val1   the first value being used for prediction
00361             \param   val2   the second value being used for prediction
00362         */
00363         void Filter(ValueType& in_val, const ValueType& val1, const ValueType& val2) const;
00364 
00365     private:
00366 
00367     }; 
00368 
00369     template <int gain>
00370     inline void  PredictStep<gain>::Filter( ValueType& in_val, 
00371                                             const ValueType& val1, 
00372                                             const ValueType& val2) const
00373     {
00374         in_val -= static_cast< ValueType >( (gain * static_cast< int >( val1 + val2 )) >>12 );
00375     }
00376 
00378     template <int gain> class UpdateStep
00379     {
00380 
00381     public:
00383         UpdateStep(){}
00384 
00386         /*
00387             Do the filtering.
00388             \param   in_val   the value being updated
00389             \param   val1   the first value being used for updating
00390             \param   val2   the second value being used for updating
00391         */
00392         void Filter(ValueType& in_val, const ValueType& val1, const ValueType& val2) const;
00393 
00394     private:
00395 
00396     };  
00397 
00398     template <int gain>
00399     inline void UpdateStep<gain>::Filter(ValueType& in_val,
00400                                               const ValueType& val1, 
00401                                               const ValueType& val2) const
00402     {
00403         in_val += static_cast< ValueType >( (gain * static_cast< int >( val1 + val2 )) >>12 );
00404     }
00405 
00407 
00411     class WaveletTransform
00412     {
00413     public:
00415         WaveletTransform(int d = 4, WltFilter f = DAUB);
00416         
00418         virtual ~WaveletTransform();
00419 
00421 
00426         void Transform(const Direction d, PicArray& pic_data);
00427     
00429         SubbandList& BandList(){return band_list;}
00430     
00432         const SubbandList& BandList() const {return band_list;}
00433     
00435 
00445         void SetBandWeights (const float cpd, 
00446                              const FrameSort& fsort,
00447                              const ChromaFormat& cformat,
00448                              const CompSort csort);
00449 
00450     private:
00451         //other private variables    
00452 
00453         SubbandList band_list;
00454 
00456         int depth;
00457     
00459         WltFilter filt_sort;    
00460 
00461     private:
00462         //functions
00464         WaveletTransform(const WaveletTransform& cpy);
00465     
00467         WaveletTransform& operator=(const WaveletTransform& rhs);
00468     
00470         float PerceptualWeight(float xf,float yf,CompSort cs);
00471 
00473         void VHSplit(const int xp, const int yp, const int xl, const int yl, PicArray&pic_data); 
00474 
00476         void VHSynth(const int xp, const int yp, const int xl, const int yl, PicArray& pic_data);
00477   
00478     };
00479 
00480 }// end namespace dirac
00481 
00482 #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.