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.19 2008/01/31 11:25:16 tjdwave Exp $ $Name: Dirac_0_10_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/picture_buffer.h>
00057 
00058 namespace dirac
00059 {
00060     class PictureBuffer;
00061     class Picture;
00062 
00063  
00065 
00071     class MotionCompensator
00072     {
00073 
00074     public:
00076 
00079         MotionCompensator( const CodecParams &cp );
00081         virtual ~MotionCompensator();
00082 
00084 
00094         static void CompensatePicture ( const CodecParams &cp, 
00095                                       const AddOrSub direction , 
00096                                       PictureBuffer& buffer , 
00097                                       const int pnum, 
00098                                       const MvData& mv_data );
00099 
00101 
00109         void CompensatePicture( const AddOrSub direction , 
00110                               PictureBuffer& my_buffer , 
00111                               int pnum , 
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( Picture& pic , 
00124                                   const Picture& ref1picture , 
00125                                   const Picture& ref2picture ,
00126                                   const MvData& mv_data , const CompSort cs);
00127 
00130         void DCBlock( TwoDArray<ValueType> &block_data ,
00131                       const ValueType dc);
00132         void ReConfig();
00133 
00134         // Calculates a weighting arrays blocks.
00135         void CalculateWeights(int xbsep, int ybsep, TwoDArray<ValueType>* wt_array);
00136 
00138 
00149         void CreateBlock(int xbsep, int ybsep, bool FullX, bool FullY, TwoDArray<ValueType>& WeightArray);
00150 
00152         void FlipX(const TwoDArray<ValueType>& Original, TwoDArray<ValueType>& Flipped);
00153 
00155         void FlipY(const TwoDArray<ValueType>& Original, TwoDArray<ValueType>& Flipped);
00156 
00157         virtual void CompensateBlock( TwoDArray<ValueType>& pic_data , 
00158                               const ImageCoords& pos , 
00159                               const ImageCoords &orig_pic_size,
00160                               PredMode block_mode,
00161                               ValueType dc,
00162                               const PicArray& ref1up_data , 
00163                               const MVector& mv1 ,
00164                               const PicArray& ref2up_data , 
00165                               const MVector& mv2 ,
00166                               const TwoDArray<ValueType>& Weights );
00168         virtual void BlockPixelPred( TwoDArray<ValueType>& block_data , 
00169                               const ImageCoords& pos,
00170                               const ImageCoords &orig_pic_size,
00171                               const PicArray& refup_data , 
00172                               const MVector& mv) = 0;
00173      
00174         // Adjust the block value based on reference weights
00175         /*
00176         * Adjust the block value based on reference weights of each
00177         * reference picture.
00178         * val1_block - Block predicted from a single reference picture
00179         * val2_block - Block predicted from second reference picture
00180         *              mode is REF1AND2
00181         * block_mode  - Block prediction mode.
00182         *
00183         * On return, val1_block will contain the weight reference weight 
00184         * adjusted block values
00185         */
00186         void AdjustBlockByRefWeights (TwoDArray<ValueType>& val1_block, 
00187                                       TwoDArray<ValueType>& val2_block, 
00188                                       PredMode block_mode);
00189      
00190         // Adjust the block value based spatial weighting matrix
00191         /*
00192         * Adjust the block value based on spatial weighting matrix
00193         * val_block - Predicted block
00194         * pos       - position of top lef corner of block in picture
00195         * wt_array  - spatial weighting matrix
00196         *
00197         * On return, val_block will contain the spatial weight adjusted block 
00198         * values
00199         */
00200         void AdjustBlockBySpatialWeights (TwoDArray<ValueType>& val_block,
00201                                           const ImageCoords &pos,
00202                                           const TwoDArray<ValueType> &wt_array);
00203     protected:
00204         //variables    
00205 
00207         CodecParams m_cparams;
00208 
00210         ChromaFormat m_cformat;
00211         bool luma_or_chroma;    //true if we're doing luma, false if we're coding chroma  
00212         
00213         // A marker saying whether we're doing MC addition or subtraction
00214         AddOrSub m_add_or_sub;                    
00215 
00216         // Block information
00217         OLBParams m_bparams;
00218         // Arrays of  block weights
00219         TwoDArray<ValueType>* m_block_weights;
00220         // Arrays of super block weights
00221         TwoDArray<ValueType>* m_macro_block_weights;
00222         // Arrays of  sub super block weights
00223         TwoDArray<ValueType>* m_sub_block_weights;
00224     };
00225 
00227     class MotionCompensator_Pixel : public MotionCompensator
00228     {
00229 
00230     public:
00232 
00235         MotionCompensator_Pixel (const CodecParams &cp);
00236 
00237     private:
00239         virtual void BlockPixelPred( TwoDArray<ValueType>& block_data , 
00240                               const ImageCoords& pos,
00241                               const ImageCoords &orig_pic_size,
00242                               const PicArray& refup_data , 
00243                               const MVector& mv);
00244     };
00245 
00247     class MotionCompensator_HalfPixel : public MotionCompensator
00248     {
00249     public:
00251 
00254         MotionCompensator_HalfPixel (const CodecParams &cp);
00255     private:
00257         virtual void BlockPixelPred( TwoDArray<ValueType>& block_data , 
00258                               const ImageCoords& pos,
00259                               const ImageCoords &orig_pic_size,
00260                               const PicArray& refup_data , 
00261                               const MVector& mv);
00262     };
00263 
00265     class MotionCompensator_QuarterPixel : public MotionCompensator
00266     {
00267     public:
00269 
00272         MotionCompensator_QuarterPixel (const CodecParams &cp);
00273     private:
00275         virtual void BlockPixelPred( TwoDArray<ValueType>& block_data , 
00276                               const ImageCoords& pos,
00277                               const ImageCoords &orig_pic_size,
00278                               const PicArray& refup_data , 
00279                               const MVector& mv);
00280     };
00281 
00283     class MotionCompensator_EighthPixel : public MotionCompensator
00284     {
00285     public:
00287 
00290         MotionCompensator_EighthPixel (const CodecParams &cp);
00291     private:
00293         virtual void BlockPixelPred( TwoDArray<ValueType>& block_data , 
00294                               const ImageCoords& pos,
00295                               const ImageCoords &orig_pic_size,
00296                               const PicArray& refup_data , 
00297                               const MVector& mv);
00298     };
00299 
00300 
00301 } // namespace dirac
00302 
00303 #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.