Dirac - A Video Codec

Created by the British Broadcasting Corporation.


mot_comp.h

Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002 *
00003 * $Id: mot_comp.h,v 1.15 2006/02/15 14:24:37 asuraparaju Exp $ $Name: Dirac_0_6_0 $
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): Richard Felton (Original Author),
00024 *                 Thomas Davies
00025 *                 Anuradha Suraparaju
00026 *
00027 * Alternatively, the contents of this file may be used under the terms of
00028 * the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser
00029 * Public License Version 2.1 (the "LGPL"), in which case the provisions of
00030 * the GPL or the LGPL are applicable instead of those above. If you wish to
00031 * allow use of your version of this file only under the terms of the either
00032 * the GPL or LGPL and not to allow others to use your version of this file
00033 * under the MPL, indicate your decision by deleting the provisions above
00034 * and replace them with the notice and other provisions required by the GPL
00035 * or LGPL. If you do not delete the provisions above, a recipient may use
00036 * your version of this file under the terms of any one of the MPL, the GPL
00037 * or the LGPL.
00038 * ***** END LICENSE BLOCK ***** */
00039 
00040 //  Motion Compensation routines.
00041 //  Supports different sizes of blocks as long as the parameters
00042 //     describing them are 'legal'. Blocks overlap the edge of the image
00043 //     being written to but blocks in the reference image are forced to
00044 //     lie completely within the image bounds.
00045 
00046 #ifndef _INCLUDED_MOT_COMP
00047 #define _INCLUDED_MOT_COMP
00048 
00049 #include <cstdlib>
00050 #include <ctime>
00051 #include <iostream>
00052 #include <vector>
00053 #include <libdirac_common/common.h>
00054 #include <libdirac_common/upconvert.h>
00055 #include <libdirac_common/motion.h>
00056 #include <libdirac_common/frame_buffer.h>
00057 
00058 namespace dirac
00059 {
00060     class FrameBuffer;
00061     class Frame;
00062 
00063  
00065 
00071     class MotionCompensator
00072     {
00073 
00074     public:
00076 
00079         MotionCompensator( const CodecParams &cp );
00081         virtual ~MotionCompensator();
00082 
00084 
00094         static void CompensateFrame ( const CodecParams &cp, 
00095                                       const AddOrSub direction , 
00096                                       FrameBuffer& buffer , 
00097                                       const int fnum, 
00098                                       const MvData& mv_data );
00099 
00101 
00109         void CompensateFrame( const AddOrSub direction , 
00110                               FrameBuffer& my_buffer , 
00111                               int fnum , 
00112                               const MvData& mv_data );
00113 
00114     private:
00115         //private, body-less copy constructor: this class should not be copied
00116         MotionCompensator( const MotionCompensator& cpy );
00117         //private, body-less assignment=: this class should not be assigned
00118         MotionCompensator& operator=( const MotionCompensator& rhs );
00119 
00120         //functions
00121 
00123         void CompensateComponent( Frame& picframe , 
00124                                   const Frame& ref1frame , 
00125                                   const Frame& ref2frame ,
00126                                   const MvData& mv_data , const CompSort cs);
00127 
00130         void DCBlock( TwoDArray<CalcValueType> &pic_data ,
00131                       const ImageCoords &orig_pic_size,
00132                       const ValueType dc ,
00133                       const ImageCoords& Pos , 
00134                       const TwoDArray<ValueType>& Weights );
00135         void ReConfig();
00136 
00137         // Overlapping blocks are acheived by applying a 2D raised cosine shape
00138         // to them. This function facilitates the calculations
00139         float RaisedCosine(float t, float B);
00140 
00141         // Overlapping blocks are acheived by applying a 2D linear shape
00142         // to them. This function facilitates the calculations
00143         float Linear(float t, float B);
00144 
00146 
00157         void CreateBlock(int xblen, int yblen, int xbsep, int ybsep, bool FullX, bool FullY, TwoDArray<ValueType>& WeightArray);
00158 
00160         void FlipX(const TwoDArray<ValueType>& Original, int xblen, int yblen, TwoDArray<ValueType>& Flipped);
00161 
00163         void FlipY(const TwoDArray<ValueType>& Original, int xblen, int yblen, TwoDArray<ValueType>& Flipped);
00164 
00166         virtual void CompensateBlock( TwoDArray<CalcValueType>& pic_data , 
00167                               const ImageCoords &orig_pic_size,
00168                               const PicArray& refup_data , 
00169                               const MVector& Vec ,
00170                               const ImageCoords& Pos , 
00171                               const TwoDArray<ValueType>& Weights ) = 0;
00172         
00173     protected:
00174         //variables    
00175 
00177         CodecParams m_cparams;
00178 
00180         ChromaFormat m_cformat;
00181         bool luma_or_chroma;    //true if we're doing luma, false if we're coding chroma  
00182         
00183         // A marker saying whether we're doing MC addition or subtraction
00184         AddOrSub m_add_or_sub;                    
00185 
00186         // Block information
00187         OLBParams m_bparams;
00188         TwoDArray<ValueType>* m_block_weights;
00189         TwoDArray<ValueType>* m_half_block_weights;
00190         TwoDArray<ValueType>* m_macro_block_weights;
00191         TwoDArray<ValueType>* m_half_macro_block_weights;
00192         TwoDArray<ValueType>* m_sub_block_weights;
00193         TwoDArray<ValueType>* m_half_sub_block_weights;
00194     };
00195 
00197     class MotionCompensator_Pixel : public MotionCompensator
00198     {
00199 
00200     public:
00202 
00205         MotionCompensator_Pixel (const CodecParams &cp);
00206 
00207     private:
00209         virtual void CompensateBlock( TwoDArray<CalcValueType>& pic_data , 
00210                               const ImageCoords &orig_pic_size,
00211                               const PicArray& refup_data , 
00212                               const MVector& Vec ,
00213                               const ImageCoords& Pos , 
00214                               const TwoDArray<ValueType>& Weights );
00215     };
00216 
00218     class MotionCompensator_HalfPixel : public MotionCompensator
00219     {
00220     public:
00222 
00225         MotionCompensator_HalfPixel (const CodecParams &cp);
00226     private:
00228         virtual void CompensateBlock( TwoDArray<CalcValueType>& pic_data , 
00229                               const ImageCoords &orig_pic_size,
00230                               const PicArray& refup_data , 
00231                               const MVector& Vec ,
00232                               const ImageCoords& Pos , 
00233                               const TwoDArray<ValueType>& Weights );
00234     };
00235 
00237     class MotionCompensator_QuarterPixel : public MotionCompensator
00238     {
00239     public:
00241 
00244         MotionCompensator_QuarterPixel (const CodecParams &cp);
00245     private:
00247         virtual void CompensateBlock( TwoDArray<CalcValueType>& pic_data , 
00248                               const ImageCoords &orig_pic_size,
00249                               const PicArray& refup_data , 
00250                               const MVector& Vec ,
00251                               const ImageCoords& Pos , 
00252                               const TwoDArray<ValueType>& Weights );
00253     };
00254 
00256     class MotionCompensator_EighthPixel : public MotionCompensator
00257     {
00258     public:
00260 
00263         MotionCompensator_EighthPixel (const CodecParams &cp);
00264     private:
00266         virtual void CompensateBlock( TwoDArray<CalcValueType>& pic_data , 
00267                               const ImageCoords &orig_pic_size,
00268                               const PicArray& refup_data , 
00269                               const MVector& Vec ,
00270                               const ImageCoords& Pos , 
00271                               const TwoDArray<ValueType>& Weights );
00272     };
00273 
00274 
00275 } // namespace dirac
00276 
00277 #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.