# Dirac - A Video Codec

Created by the British Broadcasting Corporation.

block_match.h
Go to the documentation of this file.
1 /* ***** BEGIN LICENSE BLOCK *****
2 *
3 * $Id: block_match.h,v 1.10 2007/09/03 14:52:40 asuraparaju Exp $ $Name: Dirac_1_0_2 $
4 *
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 *
7 * The contents of this file are subject to the Mozilla Public License
8 * Version 1.1 (the "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/
11 *
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
14 * the specific language governing rights and limitations under the License.
15 *
16 * The Original Code is BBC Research and Development code.
17 *
18 * The Initial Developer of the Original Code is the British Broadcasting
19 * Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 2004.
21 * All Rights Reserved.
22 *
23 * Contributor(s): Thomas Davies (Original Author)
24 *
25 * Alternatively, the contents of this file may be used under the terms of
26 * the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser
27 * Public License Version 2.1 (the "LGPL"), in which case the provisions of
28 * the GPL or the LGPL are applicable instead of those above. If you wish to
29 * allow use of your version of this file only under the terms of the either
30 * the GPL or LGPL and not to allow others to use your version of this file
31 * under the MPL, indicate your decision by deleting the provisions above
32 * and replace them with the notice and other provisions required by the GPL
33 * or LGPL. If you do not delete the provisions above, a recipient may use
34 * your version of this file under the terms of any one of the MPL, the GPL
35 * or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
37
38 #ifndef _BLOCK_MATCH_H_
39 #define _BLOCK_MATCH_H_
40
41 #include <libdirac_motionest/me_utils.h>
42 #include <vector>
43 //handles the business of finding the best block match
44
45 namespace dirac
46 {
47
48 typedef std::vector< std::vector< MVector > > CandidateList;
49
51 /*
52 Add a new motion vector list to the set of lists consisting of the
53 square neighbourhood [mv.x-xr,mv.x+xr] by
54 [mv.y-yr,mv.y+yr]. Vectors that already occur in previous lists are
55 not added.
56 */
57 void AddNewVlist( CandidateList& vect_list , const MVector& mv , const int xr , const int yr );
58
60 /*
61 Add a new motion vector list to the set of lists consisting of the
62 vectors of the form (mv.x+m*step,mv.y+n*step) where m lies between
63 -xr and xr and n lies between -yr and yr. Vectors that already occur
64 in previous lists are not added.
65 */
66 void AddNewVlist( CandidateList& vect_list , const MVector& mv , const int xr , const int yr , const int step );
67
69 /*
70 Add a new motion vector list to the set of lists consisting of the
71 diagonal neighbourhood of height 2yr+1 pixels and width 2xr+1 centred
72 on \param mv.
73 Vectors that already occur in previous lists are not added.
74 */
75 void AddNewVlistD( CandidateList& vect_list , const MVector& mv , const int xr, const int yr);
76
78
82 void AddVect( CandidateList& vect_list , const MVector& mv , const int list_num);
83
85
89 ValueType GetVar(const MVector& mv1,const MVector& mv2);
90
92
98 ValueType GetVar(const std::vector<MVector>& pred_list,const MVector& mv);
99
100
102
103 // Subsumes FindBestMatch and FindBestMatchSubpel
104 class BlockMatcher
105 {
106 public:
108
118 BlockMatcher( const PicArray& ref_data ,
119 const PicArray& pic_data ,
120 const OLBParams& bparams ,
121 const int precision ,
122 const MvArray& mv_array ,
123 const TwoDArray< MvCostData >& cost_array);
124
125 ~BlockMatcher();
126
128
136 void FindBestMatchPel( const int xpos , const int ypos ,
137 const CandidateList& cand_list,
138 const MVector& mv_prediction,
139 const int list_start);
140
142
150 void FindBestMatchSubp( const int xpos, const int ypos,
151 const CandidateList& cand_list,
152 const MVector& mv_prediction,
153 const float lambda);
154
155 void RefineMatchSubp(const int xpos, const int ypos,
156 const MVector& mv_prediction,
157 const float lambda);
158
160
165 ValueType GetVar( const MVector& predmv , const MVector& mv ) const;
166
168
173 ValueType GetVarUp( const MVector& predmv , const MVector& mv ) const;
174
175 void SetPrecision( const int n ){ m_precision = n; }
176
177 private:
178 // Local copies of the picture and reference
179 const PicArray& m_pic_data;
180 const PicArray& m_ref_data;
181
182 // Local copy of the motion vector array being populated
183 const MvArray& m_mv_array;
184
185 // Local copy of the costs being determined through the matching
186 const TwoDArray< MvCostData >& m_cost_array;
187
188 // Block difference elements. Will choose between them depending
189 // on whether we're at the edge of the picture
190 PelBlockDiff m_peldiff;
191
192 OneDArray<BlockDiffUp* > m_subpeldiff;
193
194 // The block parameters we're using
195 OLBParams m_bparams;
196
197 // The maximum variations allowed in calculating motion vector costs
198 const int m_var_max;
199 const int m_var_max_up;
200
201 // The motion vector precision
202 int m_precision;
203
204 };
205
206 } // namespace dirac
207 #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.