1 /* ***** BEGIN LICENSE BLOCK *****
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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.
16 * The Original Code is BBC Research and Development code.
18 * The Initial Developer of the Original Code is the British Broadcasting
20 * Portions created by the Initial Developer are Copyright (C) 2004.
21 * All Rights Reserved.
23 * Contributor(s): Thomas Davies (Original Author)
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
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef _PIXEL_MATCH_H_
39 #define _PIXEL_MATCH_H_
41 /* *************************************************************************
43 * Class for getting motion vectors to pixel-accuracy
45 * The class could be implemented in any number of ways. The approach taken
46 * has been to do hierarchical matching, which means doing block matching
47 * on smaller, downcoverted versions of the pictures in order to get a wider
48 * effective search range. At each level of searching the vectors discovered
49 * can be used as guides to the next level of searching, and in this way
50 * large motions can be detected easily. The danger is that the motions of
51 * small objects can be overlooked.
53 * *************************************************************************/
55 #include <libdirac_common/common.h>
56 #include <libdirac_common/motion.h>
57 #include <libdirac_motionest/block_match.h>
71 PixelMatcher( const EncoderParams
& encp
);
73 //! Do the actual search
76 \param my_buffer the buffer of pictures from which pictures are taken
77 \param pic_num the number of the picture for which motion is to be estimated
78 \param mv_data class in which the measured motion vectors are stored, together with costs
81 void DoSearch( EncQueue
& my_buffer
, int pic_num
);
87 //! Local reference to the encoder params
88 const EncoderParams
& m_encparams
;
90 //! Local reference to the picture pred params
91 const PicturePredParams
* m_predparams
;
93 // the depth of the hierarchical match
96 // the level we're at (from 0 to depth)
99 // the search-range sizes for the hierarchical match
102 // the search-range sizes for when hierarchical match fails
103 int m_big_xr
, m_big_yr
;
105 // the temporal distances to the reference pictures
108 // the picture sort - I, L1 or L2
111 // list of candidate vectors for checking
112 CandidateList m_cand_list
;
114 // Prediction used for each block. This is derived from neighbouring blocks
115 // and is used to control the variation in the motion vector field.
116 MVector m_mv_prediction
;
118 // The value used in computing block cost means with a simple recursive filter
121 // The mean of the block cost
124 // The mean of the square of the block cost
125 double m_cost_mean_sq
;
131 //! Make down-converted pictures
132 void MakePicHierarchy(const PicArray
& data
, OneDArray
< PicArray
* >& down_data
);
134 //! Make a hierarchy of MvData structures
135 void MakeMEDataHierarchy(const OneDArray
< PicArray
*>& down_data
,
136 OneDArray
< MEData
* >& me_data_set
);
138 //! Tidy up the allocations made in building the picture hirearchy
139 void TidyPics( OneDArray
< PicArray
*>& down_data
);
141 //! Tidy up the allocations made in building the MV data hirearchy
142 void TidyMEData( OneDArray
< MEData
*>& me_data_set
);
144 //! Match the picture data
145 void MatchPic(const PicArray
& ref_data
, const PicArray
& pic_data
, MEData
& me_data
,
146 const MvData
& guide_data
, const int ref_id
);
149 void DoBlock(const int xpos
, const int ypos
,
150 const MvArray
& guide_array
,
151 BlockMatcher
& block_match
);