# Dirac - A Video Codec

Created by the British Broadcasting Corporation.

me_utils.h
Go to the documentation of this file.
1 /* ***** BEGIN LICENSE BLOCK *****
2 *
3 * $Id: me_utils.h,v 1.14 2008/08/14 00:58:24 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 _ME_UTILS_H_
39 #define _ME_UTILS_H_
40
41 #include <algorithm>
42 #include <libdirac_common/motion.h>
43 #include <libdirac_common/common.h>
44 namespace dirac
45 {
46
48 //Utilities for motion estimation//
49 //-------------------------------//
51
53 class BlockDiffParams
54 {
55
56 public:
58 BlockDiffParams(){}
59
61 BlockDiffParams( const int x_p , const int y_p , const int x_l , const int y_l):
62 m_xp(x_p),
63 m_yp(y_p),
64 m_xl(x_l),
65 m_yl(y_l),
66 m_xend(x_l+x_p),
67 m_yend(y_l+y_p)
68 {}
69
71 //NB: Assume default copy constructor, assignment = and destructor//
73
74 // Sets ...
75
76
78
79 void SetBlockLimits( const OLBParams& bparams ,
80 const PicArray& pic_data ,
81 const int xbpos , const int ybpos);
82
83 // ... and gets
84
86 int Xp() const {return m_xp;}
87
89 int Yp() const {return m_yp;}
90
92 int Xl() const {return m_xl;}
93
95 int Yl() const {return m_yl;}
96
98 int Xend() const {return m_xend;}
99
101 int Yend() const {return m_yend;}
102
103 private:
104
105 int m_xp;
106 int m_yp;
107 int m_xl;
108 int m_yl;
109 int m_xend;
110 int m_yend;
111 };
112
114 //----Different difference classes, so that-----//
115 //bounds-checking need only be done as necessary//
117
119 class BlockDiff
120 {
121 public:
123 /*
124 Constructor, initialising the reference and picture data
125 \param ref the reference picture
126 \param pic the picture being matched
127 */
128 BlockDiff( const PicArray& ref , const PicArray& pic );
129
131 virtual ~BlockDiff(){}
132
134
139 virtual float Diff( const BlockDiffParams& dparams , const MVector& mv )=0;
140
141 protected:
142
143 const PicArray& m_pic_data;
144 const PicArray& m_ref_data;
145
146 private:
148 BlockDiff( const BlockDiff& cpy );
149
151 BlockDiff& operator=( const BlockDiff& rhs );
152 };
153
155 class PelBlockDiff: public BlockDiff
156 {
157 public:
159 /*
160 Constructor, initialising the reference and picture data
161 \param ref the reference picture
162 \param pic the picture being matched
163 */
164 PelBlockDiff( const PicArray& ref , const PicArray& pic );
165
167
172 float Diff( const BlockDiffParams& dparams , const MVector& mv );
173
175
183 void Diff( const BlockDiffParams& dparams ,
184 const MVector& mv ,
185 float& best_sum ,
186 MVector& best_mv );
187
188 private:
190 PelBlockDiff(const PelBlockDiff& cpy);
191
193 PelBlockDiff& operator=(const PelBlockDiff& rhs);
194 };
195
196
198 class IntraBlockDiff
199 {
200 public:
202 /*
203 Constructor, initialising the picture data
204 \param pic the picture being matched
205 */
206 IntraBlockDiff( const PicArray& pic );
207
209
214 float Diff( const BlockDiffParams& dparams , ValueType& dc_val );
215
217 ValueType CalcDC( const BlockDiffParams& dparams);
218
219 private:
221 IntraBlockDiff(const IntraBlockDiff& cpy);
222
224 IntraBlockDiff& operator=(const IntraBlockDiff& rhs);
225
226 const PicArray& m_pic_data;
227 };
228
230 class BiBlockDiff
231 {
232 public:
234 /*
235 Constructor, initialising the references and picture data
236 \param ref1 the first reference picture
237 \param ref2 the second reference picture
238 \param pic the picture being matched
239 */
240 BiBlockDiff( const PicArray& ref1 , const PicArray& ref2 , const PicArray& pic);
241
243 virtual ~BiBlockDiff( ) {}
244
246
252 virtual float Diff( const BlockDiffParams& dparams , const MVector& mv1 , const MVector& mv2 )=0;
253
254 protected:
255 const PicArray& m_pic_data;
256 const PicArray& m_ref_data1;
257 const PicArray& m_ref_data2;
258
259 private:
261 BiBlockDiff(const BiBlockDiff& cpy);
262
264 BiBlockDiff& operator=(const BiBlockDiff& rhs);
265 };
266
267 // Classes where the reference is upconverted //
270 class BlockDiffUp: public BlockDiff
271 {
272
273 public:
274
276 /*
277 Constructor, initialising the reference and picture data
278 \param ref the reference picture
279 \param pic the picture being matched
280 */
281 BlockDiffUp( const PicArray& ref , const PicArray& pic );
282
284 virtual ~BlockDiffUp(){}
285
287
292 virtual float Diff( const BlockDiffParams& dparams , const MVector& mv )=0;
293
295
305 virtual void Diff( const BlockDiffParams& dparams,
306 const MVector& mv ,
307 const float mvcost,
308 const float lambda,
309 MvCostData& best_costs ,
310 MVector& best_mv)=0;
311 private:
313 BlockDiffUp(const BlockDiffUp& cpy);
314
316 BlockDiffUp& operator=(const BlockDiffUp& rhs);
317 };
318
320 class BlockDiffHalfPel: public BlockDiffUp
321 {
322
323 public:
325 /*
326 Constructor, initialising the reference and picture data
327 \param ref the reference picture
328 \param pic the picture being matched
329 */
330 BlockDiffHalfPel( const PicArray& ref , const PicArray& pic );
331
333 ~BlockDiffHalfPel(){}
334
336
341 float Diff( const BlockDiffParams& dparams , const MVector& mv );
342
344
354 void Diff( const BlockDiffParams& dparams,
355 const MVector& mv ,
356 const float mvcost,
357 const float lambda,
358 MvCostData& best_costs ,
359 MVector& best_mv);
360
361 private:
363 BlockDiffHalfPel(const BlockDiffHalfPel& cpy);
364
366 BlockDiffHalfPel& operator=(const BlockDiffHalfPel& rhs);
367
368 };
369
371 class BlockDiffQuarterPel: public BlockDiffUp
372 {
373 public:
375 /*
376 Constructor, initialising the reference and picture data
377 \param ref the reference picture
378 \param pic the picture being matched
379 */
380 BlockDiffQuarterPel( const PicArray& ref , const PicArray& pic );
381
383 ~BlockDiffQuarterPel(){}
384
386
391 float Diff( const BlockDiffParams& dparams , const MVector& mv );
392
394
404 void Diff( const BlockDiffParams& dparams,
405 const MVector& mv ,
406 const float mvcost,
407 const float lambda,
408 MvCostData& best_costs ,
409 MVector& best_mv);
410
411 private:
413 BlockDiffQuarterPel(const BlockDiffQuarterPel& cpy);
414
416 BlockDiffQuarterPel& operator=(const BlockDiffQuarterPel& rhs);
417 };
418
420 class BlockDiffEighthPel: public BlockDiffUp
421 {
422 public:
424 /*
425 Constructor, initialising the reference and picture data
426 \param ref the reference picture
427 \param pic the picture being matched
428 */
429 BlockDiffEighthPel( const PicArray& ref , const PicArray& pic );
430
432 ~BlockDiffEighthPel(){}
433
435
440 float Diff( const BlockDiffParams& dparams , const MVector& mv );
441
443
453 void Diff( const BlockDiffParams& dparams,
454 const MVector& mv ,
455 const float mvcost,
456 const float lambda,
457 MvCostData& best_costs ,
458 MVector& best_mv);
459
460 private:
462 BlockDiffEighthPel(const BlockDiffEighthPel& cpy);
463
465 BlockDiffEighthPel& operator=(const BlockDiffEighthPel& rhs);
466 };
467
469 class BiBlockHalfPel: public BiBlockDiff
470 {
471 public:
473 /*
474 Constructor, initialising the reference and picture data
475 \param ref1 the first reference picture
476 \param ref2 the second reference picture
477 \param pic the picture being matched
478 */
479 BiBlockHalfPel( const PicArray& ref1 , const PicArray& ref2 , const PicArray& pic );
480
482
488 float Diff( const BlockDiffParams& dparams , const MVector& mv1 , const MVector& mv2 );
489 private:
491 BiBlockHalfPel(const BiBlockHalfPel& cpy);
492
494 BiBlockHalfPel& operator=(const BiBlockHalfPel& rhs);
495 };
496
498 class BiBlockQuarterPel: public BiBlockDiff
499 {
500 public:
502 /*
503 Constructor, initialising the reference and picture data
504 \param ref1 the first reference picture
505 \param ref2 the second reference picture
506 \param pic the picture being matched
507 */
508 BiBlockQuarterPel( const PicArray& ref1 , const PicArray& ref2 , const PicArray& pic );
509
511
517 float Diff( const BlockDiffParams& dparams , const MVector& mv1 , const MVector& mv2 );
518
519 private:
521 BiBlockQuarterPel(const BiBlockQuarterPel& cpy);
522
524 BiBlockQuarterPel& operator=(const BiBlockQuarterPel& rhs);
525 };
526
528 class BiBlockEighthPel: public BiBlockDiff
529 {
530 public:
532 /*
533 Constructor, initialising the reference and picture data
534 \param ref1 the first reference picture
535 \param ref2 the second reference picture
536 \param pic the picture being matched
537 */
538 BiBlockEighthPel( const PicArray& ref1 , const PicArray& ref2 , const PicArray& pic );
539
541
547 float Diff( const BlockDiffParams& dparams , const MVector& mv1 , const MVector& mv2 );
548 private:
550 BiBlockEighthPel(const BiBlockEighthPel& cpy);
551
553 BiBlockEighthPel& operator=(const BiBlockEighthPel& rhs);
554 };
555
556 } // namespace dirac
557 #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.