mv_codec.h

00001 /* ***** BEGIN LICENSE BLOCK *****
00002 *
00003 * $Id: mv_codec.h,v 1.2 2005/01/30 05:11:40 gabest Exp $ $Name:  $
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 _MV_CODEC_H_
00039 #define _MV_CODEC_H_
00040 
00042 //Class to do motion vector coding and decoding//
00043 //------using adaptive arithmetic coding-------//
00045 
00046 #include <libdirac_common/arith_codec.h>
00047 #include <libdirac_common/common.h>
00048 #include <libdirac_common/motion.h>
00049 #include <libdirac_common/wavelet_utils.h>
00050 #include <vector>
00051 
00052 namespace dirac
00053 {
00055 
00059     class MvDataCodec: public ArithCodec<MvData>
00060     {
00061     public:
00063 
00069         MvDataCodec(BasicOutputManager* bits_out,
00070                     size_t number_of_contexts,
00071                     const ChromaFormat & cf);
00072 
00074 
00080         MvDataCodec(BitInputManager* bits_in,
00081                     size_t number_of_contexts,
00082                     const ChromaFormat & cf); 
00083 
00085         void InitContexts();
00086         
00087     private:
00088         int MB_count;
00089         const ChromaFormat & m_cformat;
00090 
00091         int b_xp, b_yp;            //position of current block
00092         int mb_xp, mb_yp;        //position of current MB
00093         int mb_tlb_x, mb_tlb_y;    //position of top-left block of current MB
00094 
00095         // functions    
00096         MvDataCodec(const MvDataCodec& cpy);            //private, bodyless copy constructor: class should not be copied
00097         MvDataCodec& operator=(const MvDataCodec& rhs); //private, bodyless copy operator=: class should not be assigned
00098 
00099         // coding functions    
00100         void CodeMBSplit(const MvData& in_data);    //code the MB splitting mode
00101         void CodeMBCom(const MvData& in_data);    //code the MB common ref mode
00102         void CodePredmode(const MvData& in_data);    //code the block prediction mode
00103         void CodeMv1(const MvData& in_data);        //code the first motion vector
00104         void CodeMv2(const MvData& in_data);        //code the second motion vector
00105         void CodeDC(const MvData& in_data);        //code the dc value of intra blocks
00106 
00107         // decoding functions
00108         void DecodeMBSplit( MvData& out_data);    //decode the MB splitting mode
00109         void DecodeMBCom( MvData& out_data);//decode the MB common ref mode
00110         void DecodePredmode(MvData& out_data);//decode the block prediction mode
00111         void DecodeMv1( MvData& out_data);    //decode the first motion vector
00112         void DecodeMv2( MvData& out_data);    //decode the second motion vector
00113         void DecodeDC( MvData& out_data);    //decode the dc value of intra blocks    
00114 
00115         void DoWorkCode( MvData& in_data );
00116         void DoWorkDecode(MvData& out_data, int num_bits);
00117 
00118         // Context stuff    
00119         void Update( const bool symbol , const int context_num );
00120         void Resize(const int context_num);
00121         void ResetAll();
00122 
00123         int ChooseContext(const MvData& data, const int BinNumber) const;
00124         int ChooseContext(const MvData& data) const;
00125         int ChooseSignContext(const MvData& data) const;
00126 
00127         int ChooseMBSContext(const MvData& data, const int BinNumber) const;
00128         int ChooseMBCContext(const MvData& data) const;
00129         int ChoosePredContext(const MvData& data, const int BinNumber) const;
00130         int ChooseREF1xContext(const MvData& data, const int BinNumber) const;
00131         int ChooseREF1xSignContext(const MvData& data) const;
00132         int ChooseREF1yContext(const MvData& data, const int BinNumber) const;
00133         int ChooseREF1ySignContext(const MvData& data) const;
00134         int ChooseREF2xContext(const MvData& data, const int BinNumber) const;
00135         int ChooseREF2xSignContext(const MvData& data) const;
00136         int ChooseREF2yContext(const MvData& data, const int BinNumber) const;
00137         int ChooseREF2ySignContext(const MvData& data) const;
00138         int ChooseYDCContext(const MvData& data, const int BinNumber) const;
00139         int ChooseUDCContext(const MvData& data, const int BinNumber) const;
00140         int ChooseVDCContext(const MvData& data, const int BinNumber) const;
00141         int ChooseYDCSignContext(const MvData& data) const;
00142         int ChooseUDCSignContext(const MvData& data) const;
00143         int ChooseVDCSignContext(const MvData& data) const;
00144 
00145         //prediction stuff
00146         unsigned int MBSplitPrediction(const TwoDArray<int>& mbdata) const;
00147         bool MBCBModePrediction(const TwoDArray<bool>& mbdata) const;
00148         unsigned int BlockModePrediction(const TwoDArray<PredMode>& preddata) const;
00149         MVector Mv1Prediction(const MvArray& mvarray,const TwoDArray<PredMode>& preddata) const;
00150         MVector Mv2Prediction(const MvArray& mvarray,const TwoDArray<PredMode>& preddata) const;
00151         ValueType DCPrediction(const TwoDArray<ValueType>& dcdata,const TwoDArray<PredMode>& preddata) const;
00152     };
00153 
00154 } // namespace dirac
00155 
00156 #endif

Generated on Tue Dec 13 14:47:14 2005 for guliverkli by  doxygen 1.4.5