00001 /* ***** BEGIN LICENSE BLOCK ***** 00002 * 00003 * $Id: block_match.h,v 1.2 2005/01/30 05:11:42 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) 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 _BLOCK_MATCH_H_ 00039 #define _BLOCK_MATCH_H_ 00040 00041 #include <libdirac_motionest/me_utils.h> 00042 #include <vector> 00043 //handles the business of finding the best block match 00044 00045 namespace dirac 00046 { 00047 00048 typedef std::vector< std::vector< MVector > > CandidateList; 00049 00051 /* 00052 Add a new motion vector list to the set of lists consisting of the 00053 square neighbourhood [mv.x-xr,mv.x+xr] by 00054 [mv.y-yr,mv.y+yr]. Vectors that already occur in previous lists are 00055 not added. 00056 */ 00057 void AddNewVlist( CandidateList& vect_list , const MVector& mv , const int xr , const int yr ); 00058 00060 /* 00061 Add a new motion vector list to the set of lists consisting of the 00062 vectors of the form (mv.x+m*step,mv.y+n*step) where m lies between 00063 -xr and xr and n lies between -yr and yr. Vectors that already occur 00064 in previous lists are not added. 00065 */ 00066 void AddNewVlist( CandidateList& vect_list , const MVector& mv , const int xr , const int yr , const int step ); 00067 00069 /* 00070 Add a new motion vector list to the set of lists consisting of the 00071 diagonal neighbourhood of height 2yr+1 pixels and width 2xr+1 centred 00072 on \param mv. 00073 Vectors that already occur in previous lists are not added. 00074 */ 00075 void AddNewVlistD( CandidateList& vect_list , const MVector& mv , const int xr, const int yr); 00076 00078 00082 void AddVect( CandidateList& vect_list , const MVector& mv , const int list_num); 00083 00085 00089 ValueType GetVar(const MVector& mv1,const MVector& mv2); 00090 00092 00098 ValueType GetVar(const std::vector<MVector>& pred_list,const MVector& mv); 00099 00100 00102 00103 // Subsumes FindBestMatch and FindBestMatchSubpel 00104 class BlockMatcher 00105 { 00106 public: 00108 00117 BlockMatcher( const PicArray& ref_data , 00118 const PicArray& pic_data , 00119 const OLBParams& bparams , 00120 const MvArray& mv_array , 00121 const TwoDArray< MvCostData >& cost_array); 00122 00124 00132 void FindBestMatch(int xpos , int ypos, 00133 const CandidateList& cand_list, 00134 const MVector& mv_prediction, 00135 float lambda); 00136 00138 00146 void FindBestMatchSubp(int xpos, int ypos, 00147 const CandidateList& cand_list, 00148 const MVector& mv_prediction, 00149 float lambda); 00150 00151 private: 00152 // Local copies of the picture and reference 00153 const PicArray& m_pic_data; 00154 const PicArray& m_ref_data; 00155 00156 // Local copy of the motion vector array being populated 00157 const MvArray& m_mv_array; 00158 00159 // Local copy of the costs being determined through the matching 00160 const TwoDArray< MvCostData >& m_cost_array; 00161 00162 // Block difference elements. Will choose between them depending 00163 // on whether we're at the edge of the picture 00164 SimpleBlockDiff m_simplediff; 00165 BChkBlockDiff m_checkdiff; 00166 SimpleBlockDiffUp m_simplediffup; 00167 BChkBlockDiffUp m_checkdiffup; 00168 00169 // The block parameters we're using 00170 OLBParams m_bparams; 00171 00172 }; 00173 00174 } // namespace dirac 00175 #endif