1 |
/************************************************************************** |
/***************************************************************************** |
2 |
* |
* |
3 |
* XVID MPEG-4 VIDEO CODEC |
* XVID MPEG-4 VIDEO CODEC |
4 |
* motion estimation |
* - Motion Estimation module - |
5 |
* |
* |
6 |
* This program is an implementation of a part of one or more MPEG-4 |
* Copyright(C) 2002 Christoph Lampert <gruel@web.de> |
7 |
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
* 2002 Michael Militzer <michael@xvid.org> |
|
* to use this software module in hardware or software products are |
|
|
* advised that its use may infringe existing patents or copyrights, and |
|
|
* any such use would be at such party's own risk. The original |
|
|
* developer of this software module and his/her company, and subsequent |
|
|
* editors and their companies, will have no liability for use of this |
|
|
* software or modifications or derivatives thereof. |
|
8 |
* |
* |
9 |
* This program is free software; you can redistribute it and/or modify |
* This file is part of XviD, a free MPEG-4 video encoder/decoder |
10 |
* it under the terms of the GNU General Public License as published by |
* |
11 |
|
* XviD is free software; you can redistribute it and/or modify it |
12 |
|
* under the terms of the GNU General Public License as published by |
13 |
* the Free Software Foundation; either version 2 of the License, or |
* the Free Software Foundation; either version 2 of the License, or |
14 |
* (at your option) any later version. |
* (at your option) any later version. |
15 |
* |
* |
20 |
* |
* |
21 |
* You should have received a copy of the GNU General Public License |
* You should have received a copy of the GNU General Public License |
22 |
* along with this program; if not, write to the Free Software |
* along with this program; if not, write to the Free Software |
23 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
24 |
* |
* |
25 |
*************************************************************************/ |
* Under section 8 of the GNU General Public License, the copyright |
26 |
|
* holders of XVID explicitly forbid distribution in the following |
27 |
/************************************************************************** |
* countries: |
28 |
|
* |
29 |
|
* - Japan |
30 |
|
* - United States of America |
31 |
|
* |
32 |
|
* Linking XviD statically or dynamically with other modules is making a |
33 |
|
* combined work based on XviD. Thus, the terms and conditions of the |
34 |
|
* GNU General Public License cover the whole combination. |
35 |
* |
* |
36 |
* Modifications: |
* As a special exception, the copyright holders of XviD give you |
37 |
|
* permission to link XviD with independent modules that communicate with |
38 |
|
* XviD solely through the VFW1.1 and DShow interfaces, regardless of the |
39 |
|
* license terms of these independent modules, and to copy and distribute |
40 |
|
* the resulting combined work under terms of your choice, provided that |
41 |
|
* every copy of the combined work is accompanied by a complete copy of |
42 |
|
* the source code of XviD (the version of XviD used to produce the |
43 |
|
* combined work), being distributed under the terms of the GNU General |
44 |
|
* Public License plus this exception. An independent module is a module |
45 |
|
* which is not derived from or based on XviD. |
46 |
* |
* |
47 |
* 01.05.2002 updated MotionEstimationBVOP |
* Note that people who make modified versions of XviD are not obligated |
48 |
* 25.04.2002 partial prevMB conversion |
* to grant this special exception for their modified versions; it is |
49 |
* 22.04.2002 remove some compile warning by chenm001 <chenm001@163.com> |
* their choice whether to do so. The GNU General Public License gives |
50 |
* 14.04.2002 added MotionEstimationBVOP() |
* permission to release a modified version without this exception; this |
51 |
* 02.04.2002 add EPZS(^2) as ME algorithm, use PMV_USESQUARES to choose between |
* exception also makes it possible to release a modified version which |
52 |
* EPZS and EPZS^2 |
* carries forward this exception. |
|
* 08.02.2002 split up PMVfast into three routines: PMVFast, PMVFast_MainLoop |
|
|
* PMVFast_Refine to support multiple searches with different start points |
|
|
* 07.01.2002 uv-block-based interpolation |
|
|
* 06.01.2002 INTER/INTRA-decision is now done before any SEARCH8 (speedup) |
|
|
* changed INTER_BIAS to 150 (as suggested by suxen_drol) |
|
|
* removed halfpel refinement step in PMVfastSearch8 + quality=5 |
|
|
* added new quality mode = 6 which performs halfpel refinement |
|
|
* filesize difference between quality 5 and 6 is smaller than 1% |
|
|
* (Isibaar) |
|
|
* 31.12.2001 PMVfastSearch16 and PMVfastSearch8 (gruel) |
|
|
* 30.12.2001 get_range/MotionSearchX simplified; blue/green bug fix |
|
|
* 22.12.2001 commented best_point==99 check |
|
|
* 19.12.2001 modified get_range (purple bug fix) |
|
|
* 15.12.2001 moved pmv displacement from mbprediction |
|
|
* 02.12.2001 motion estimation/compensation split (Isibaar) |
|
|
* 16.11.2001 rewrote/tweaked search algorithms; pross@cs.rmit.edu.au |
|
|
* 10.11.2001 support for sad16/sad8 functions |
|
|
* 28.08.2001 reactivated MODE_INTER4V for EXT_MODE |
|
|
* 24.08.2001 removed MODE_INTER4V_Q, disabled MODE_INTER4V for EXT_MODE |
|
|
* 22.08.2001 added MODE_INTER4V_Q |
|
|
* 20.08.2001 added pragma to get rid of internal compiler error with VC6 |
|
|
* idea by Cyril. Thanks. |
|
53 |
* |
* |
54 |
* Michael Militzer <isibaar@videocoding.de> |
* $Id: motion_est.c,v 1.53 2002-11-17 00:32:06 edgomez Exp $ |
55 |
* |
* |
56 |
**************************************************************************/ |
*************************************************************************/ |
57 |
|
|
58 |
#include <assert.h> |
#include <assert.h> |
59 |
#include <stdio.h> |
#include <stdio.h> |
161 |
const IMAGE *const pCurrent = ¤t->image; |
const IMAGE *const pCurrent = ¤t->image; |
162 |
const IMAGE *const pRef = &reference->image; |
const IMAGE *const pRef = &reference->image; |
163 |
|
|
164 |
const VECTOR zeroMV = { 0, 0 }; |
static const VECTOR zeroMV = { 0, 0 }; |
165 |
|
VECTOR predMV; |
166 |
|
|
167 |
int64_t time; |
uint32_t x, y; |
168 |
int32_t x, y; |
uint32_t iIntra = 0; |
|
int32_t iIntra = 0; |
|
169 |
VECTOR pmv; |
VECTOR pmv; |
170 |
|
|
171 |
if (sadInit) |
if (sadInit) |
176 |
|
|
177 |
MACROBLOCK *const pMB = &pMBs[x + y * iWcount]; |
MACROBLOCK *const pMB = &pMBs[x + y * iWcount]; |
178 |
|
|
179 |
|
predMV = get_pmv2(pMBs, pParam->mb_width, 0, x, y, 0); |
180 |
|
|
181 |
pMB->sad16 = |
pMB->sad16 = |
182 |
SEARCH16(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent, x, |
SEARCH16(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent, |
183 |
y, current->motion_flags, current->quant, |
x, y, predMV.x, predMV.y, predMV.x, predMV.y, |
184 |
|
current->motion_flags, current->quant, |
185 |
current->fcode, pParam, pMBs, prevMBs, &pMB->mv16, |
current->fcode, pParam, pMBs, prevMBs, &pMB->mv16, |
186 |
&pMB->pmvs[0]); |
&pMB->pmvs[0]); |
187 |
|
|
213 |
pMB->dquant == NO_CHANGE)) { |
pMB->dquant == NO_CHANGE)) { |
214 |
int32_t sad8 = IMV16X16 * current->quant; |
int32_t sad8 = IMV16X16 * current->quant; |
215 |
|
|
216 |
if (sad8 < pMB->sad16) |
if (sad8 < pMB->sad16) { |
|
|
|
217 |
sad8 += pMB->sad8[0] = |
sad8 += pMB->sad8[0] = |
218 |
SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, |
SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, |
219 |
pCurrent, 2 * x, 2 * y, pMB->mv16.x, |
pCurrent, 2 * x, 2 * y, |
220 |
pMB->mv16.y, current->motion_flags, |
pMB->mv16.x, pMB->mv16.y, predMV.x, predMV.y, |
221 |
|
current->motion_flags, |
222 |
current->quant, current->fcode, pParam, |
current->quant, current->fcode, pParam, |
223 |
pMBs, prevMBs, &pMB->mvs[0], |
pMBs, prevMBs, &pMB->mvs[0], |
224 |
&pMB->pmvs[0]); |
&pMB->pmvs[0]); |
225 |
|
} |
226 |
|
if (sad8 < pMB->sad16) { |
227 |
|
|
228 |
if (sad8 < pMB->sad16) |
predMV = get_pmv2(pMBs, pParam->mb_width, 0, x, y, 1); |
229 |
sad8 += pMB->sad8[1] = |
sad8 += pMB->sad8[1] = |
230 |
SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, |
SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, |
231 |
pCurrent, 2 * x + 1, 2 * y, pMB->mv16.x, |
pCurrent, 2 * x + 1, 2 * y, |
232 |
pMB->mv16.y, current->motion_flags, |
pMB->mv16.x, pMB->mv16.y, predMV.x, predMV.y, |
233 |
|
current->motion_flags, |
234 |
current->quant, current->fcode, pParam, |
current->quant, current->fcode, pParam, |
235 |
pMBs, prevMBs, &pMB->mvs[1], |
pMBs, prevMBs, &pMB->mvs[1], |
236 |
&pMB->pmvs[1]); |
&pMB->pmvs[1]); |
237 |
|
} |
238 |
if (sad8 < pMB->sad16) |
if (sad8 < pMB->sad16) { |
239 |
|
predMV = get_pmv2(pMBs, pParam->mb_width, 0, x, y, 2); |
240 |
sad8 += pMB->sad8[2] = |
sad8 += pMB->sad8[2] = |
241 |
SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, |
SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, |
242 |
pCurrent, 2 * x, 2 * y + 1, pMB->mv16.x, |
pCurrent, 2 * x, 2 * y + 1, |
243 |
pMB->mv16.y, current->motion_flags, |
pMB->mv16.x, pMB->mv16.y, predMV.x, predMV.y, |
244 |
|
current->motion_flags, |
245 |
current->quant, current->fcode, pParam, |
current->quant, current->fcode, pParam, |
246 |
pMBs, prevMBs, &pMB->mvs[2], |
pMBs, prevMBs, &pMB->mvs[2], |
247 |
&pMB->pmvs[2]); |
&pMB->pmvs[2]); |
248 |
|
} |
249 |
if (sad8 < pMB->sad16) |
if (sad8 < pMB->sad16) { |
250 |
|
predMV = get_pmv2(pMBs, pParam->mb_width, 0, x, y, 3); |
251 |
sad8 += pMB->sad8[3] = |
sad8 += pMB->sad8[3] = |
252 |
SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, |
SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, |
253 |
pCurrent, 2 * x + 1, 2 * y + 1, |
pCurrent, 2 * x + 1, 2 * y + 1, |
254 |
pMB->mv16.x, pMB->mv16.y, |
pMB->mv16.x, pMB->mv16.y, predMV.x, predMV.y, |
255 |
current->motion_flags, current->quant, |
current->motion_flags, |
256 |
current->fcode, pParam, pMBs, prevMBs, |
current->quant, current->fcode, pParam, |
257 |
&pMB->mvs[3], &pMB->pmvs[3]); |
pMBs, prevMBs, |
258 |
|
&pMB->mvs[3], |
259 |
|
&pMB->pmvs[3]); |
260 |
|
} |
261 |
|
|
262 |
/* decide: MODE_INTER or MODE_INTER4V |
/* decide: MODE_INTER or MODE_INTER4V |
263 |
mpeg4: if (sad8 < pMB->sad16 - nb/2+1) use_inter4v |
mpeg4: if (sad8 < pMB->sad16 - nb/2+1) use_inter4v |
285 |
return 0; |
return 0; |
286 |
} |
} |
287 |
|
|
288 |
|
|
289 |
#define CHECK_MV16_ZERO {\ |
#define CHECK_MV16_ZERO {\ |
290 |
if ( (0 <= max_dx) && (0 >= min_dx) \ |
if ( (0 <= max_dx) && (0 >= min_dx) \ |
291 |
&& (0 <= max_dy) && (0 >= min_dy) ) \ |
&& (0 <= max_dy) && (0 >= min_dy) ) \ |
292 |
{ \ |
{ \ |
293 |
iSAD = sad16( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 16, 0, 0 , iEdgedWidth), iEdgedWidth, MV_MAX_ERROR); \ |
iSAD = sad16( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 16, 0, 0 , iEdgedWidth), iEdgedWidth, MV_MAX_ERROR); \ |
294 |
iSAD += calc_delta_16(-pmv[0].x, -pmv[0].y, (uint8_t)iFcode, iQuant);\ |
iSAD += calc_delta_16(-center_x, -center_y, (uint8_t)iFcode, iQuant);\ |
295 |
if (iSAD < iMinSAD) \ |
if (iSAD < iMinSAD) \ |
296 |
{ iMinSAD=iSAD; currMV->x=0; currMV->y=0; } } \ |
{ iMinSAD=iSAD; currMV->x=0; currMV->y=0; } } \ |
297 |
} |
} |
298 |
|
|
299 |
#define NOCHECK_MV16_CANDIDATE(X,Y) { \ |
#define NOCHECK_MV16_CANDIDATE(X,Y) { \ |
300 |
iSAD = sad16( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 16, X, Y, iEdgedWidth),iEdgedWidth, iMinSAD); \ |
iSAD = sad16( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 16, X, Y, iEdgedWidth),iEdgedWidth, iMinSAD); \ |
301 |
iSAD += calc_delta_16((X) - pmv[0].x, (Y) - pmv[0].y, (uint8_t)iFcode, iQuant);\ |
iSAD += calc_delta_16((X) - center_x, (Y) - center_y, (uint8_t)iFcode, iQuant);\ |
302 |
if (iSAD < iMinSAD) \ |
if (iSAD < iMinSAD) \ |
303 |
{ iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); } \ |
{ iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); } \ |
304 |
} |
} |
308 |
&& ((Y) <= max_dy) && ((Y) >= min_dy) ) \ |
&& ((Y) <= max_dy) && ((Y) >= min_dy) ) \ |
309 |
{ \ |
{ \ |
310 |
iSAD = sad16( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 16, X, Y, iEdgedWidth),iEdgedWidth, iMinSAD); \ |
iSAD = sad16( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 16, X, Y, iEdgedWidth),iEdgedWidth, iMinSAD); \ |
311 |
iSAD += calc_delta_16((X) - pmv[0].x, (Y) - pmv[0].y, (uint8_t)iFcode, iQuant);\ |
iSAD += calc_delta_16((X) - center_x, (Y) - center_y, (uint8_t)iFcode, iQuant);\ |
312 |
if (iSAD < iMinSAD) \ |
if (iSAD < iMinSAD) \ |
313 |
{ iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); } } \ |
{ iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); } } \ |
314 |
} |
} |
318 |
&& ((Y) <= max_dy) && ((Y) >= min_dy) ) \ |
&& ((Y) <= max_dy) && ((Y) >= min_dy) ) \ |
319 |
{ \ |
{ \ |
320 |
iSAD = sad16( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 16, X, Y, iEdgedWidth),iEdgedWidth, iMinSAD); \ |
iSAD = sad16( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 16, X, Y, iEdgedWidth),iEdgedWidth, iMinSAD); \ |
321 |
iSAD += calc_delta_16((X) - pmv[0].x, (Y) - pmv[0].y, (uint8_t)iFcode, iQuant);\ |
iSAD += calc_delta_16((X) - center_x, (Y) - center_y, (uint8_t)iFcode, iQuant);\ |
322 |
if (iSAD < iMinSAD) \ |
if (iSAD < iMinSAD) \ |
323 |
{ iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); iDirection=(D); } } \ |
{ iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); iDirection=(D); } } \ |
324 |
} |
} |
328 |
&& ((Y) <= max_dy) && ((Y) >= min_dy) ) \ |
&& ((Y) <= max_dy) && ((Y) >= min_dy) ) \ |
329 |
{ \ |
{ \ |
330 |
iSAD = sad16( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 16, X, Y, iEdgedWidth),iEdgedWidth, iMinSAD); \ |
iSAD = sad16( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 16, X, Y, iEdgedWidth),iEdgedWidth, iMinSAD); \ |
331 |
iSAD += calc_delta_16((X) - pmv[0].x, (Y) - pmv[0].y, (uint8_t)iFcode, iQuant);\ |
iSAD += calc_delta_16((X) - center_x, (Y) - center_y, (uint8_t)iFcode, iQuant);\ |
332 |
if (iSAD < iMinSAD) \ |
if (iSAD < iMinSAD) \ |
333 |
{ iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); iDirection=(D); iFound=0; } } \ |
{ iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); iDirection=(D); iFound=0; } } \ |
334 |
} |
} |
336 |
|
|
337 |
#define CHECK_MV8_ZERO {\ |
#define CHECK_MV8_ZERO {\ |
338 |
iSAD = sad8( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 8, 0, 0 , iEdgedWidth), iEdgedWidth); \ |
iSAD = sad8( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 8, 0, 0 , iEdgedWidth), iEdgedWidth); \ |
339 |
iSAD += calc_delta_8(-pmv[0].x, -pmv[0].y, (uint8_t)iFcode, iQuant);\ |
iSAD += calc_delta_8(-center_x, -center_y, (uint8_t)iFcode, iQuant);\ |
340 |
if (iSAD < iMinSAD) \ |
if (iSAD < iMinSAD) \ |
341 |
{ iMinSAD=iSAD; currMV->x=0; currMV->y=0; } \ |
{ iMinSAD=iSAD; currMV->x=0; currMV->y=0; } \ |
342 |
} |
} |
344 |
#define NOCHECK_MV8_CANDIDATE(X,Y) \ |
#define NOCHECK_MV8_CANDIDATE(X,Y) \ |
345 |
{ \ |
{ \ |
346 |
iSAD = sad8( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 8, (X), (Y), iEdgedWidth),iEdgedWidth); \ |
iSAD = sad8( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 8, (X), (Y), iEdgedWidth),iEdgedWidth); \ |
347 |
iSAD += calc_delta_8((X)-pmv[0].x, (Y)-pmv[0].y, (uint8_t)iFcode, iQuant);\ |
iSAD += calc_delta_8((X)-center_x, (Y)-center_y, (uint8_t)iFcode, iQuant);\ |
348 |
if (iSAD < iMinSAD) \ |
if (iSAD < iMinSAD) \ |
349 |
{ iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); } \ |
{ iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); } \ |
350 |
} |
} |
354 |
&& ((Y) <= max_dy) && ((Y) >= min_dy) ) \ |
&& ((Y) <= max_dy) && ((Y) >= min_dy) ) \ |
355 |
{ \ |
{ \ |
356 |
iSAD = sad8( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 8, (X), (Y), iEdgedWidth),iEdgedWidth); \ |
iSAD = sad8( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 8, (X), (Y), iEdgedWidth),iEdgedWidth); \ |
357 |
iSAD += calc_delta_8((X)-pmv[0].x, (Y)-pmv[0].y, (uint8_t)iFcode, iQuant);\ |
iSAD += calc_delta_8((X)-center_x, (Y)-center_y, (uint8_t)iFcode, iQuant);\ |
358 |
if (iSAD < iMinSAD) \ |
if (iSAD < iMinSAD) \ |
359 |
{ iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); } } \ |
{ iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); } } \ |
360 |
} |
} |
364 |
&& ((Y) <= max_dy) && ((Y) >= min_dy) ) \ |
&& ((Y) <= max_dy) && ((Y) >= min_dy) ) \ |
365 |
{ \ |
{ \ |
366 |
iSAD = sad8( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 8, (X), (Y), iEdgedWidth),iEdgedWidth); \ |
iSAD = sad8( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 8, (X), (Y), iEdgedWidth),iEdgedWidth); \ |
367 |
iSAD += calc_delta_8((X)-pmv[0].x, (Y)-pmv[0].y, (uint8_t)iFcode, iQuant);\ |
iSAD += calc_delta_8((X)-center_x, (Y)-center_y, (uint8_t)iFcode, iQuant);\ |
368 |
if (iSAD < iMinSAD) \ |
if (iSAD < iMinSAD) \ |
369 |
{ iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); iDirection=(D); } } \ |
{ iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); iDirection=(D); } } \ |
370 |
} |
} |
374 |
&& ((Y) <= max_dy) && ((Y) >= min_dy) ) \ |
&& ((Y) <= max_dy) && ((Y) >= min_dy) ) \ |
375 |
{ \ |
{ \ |
376 |
iSAD = sad8( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 8, (X), (Y), iEdgedWidth),iEdgedWidth); \ |
iSAD = sad8( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 8, (X), (Y), iEdgedWidth),iEdgedWidth); \ |
377 |
iSAD += calc_delta_8((X)-pmv[0].x, (Y)-pmv[0].y, (uint8_t)iFcode, iQuant);\ |
iSAD += calc_delta_8((X)-center_x, (Y)-center_y, (uint8_t)iFcode, iQuant);\ |
378 |
if (iSAD < iMinSAD) \ |
if (iSAD < iMinSAD) \ |
379 |
{ iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); iDirection=(D); iFound=0; } } \ |
{ iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); iDirection=(D); iFound=0; } } \ |
380 |
} |
} |
381 |
|
|
382 |
|
#if 0 |
383 |
/* too slow and not fully functional at the moment */ |
/* too slow and not fully functional at the moment */ |
|
/* |
|
384 |
int32_t ZeroSearch16( |
int32_t ZeroSearch16( |
385 |
const uint8_t * const pRef, |
const uint8_t * const pRef, |
386 |
const uint8_t * const pRefH, |
const uint8_t * const pRefH, |
419 |
return iSAD; |
return iSAD; |
420 |
|
|
421 |
} |
} |
422 |
*/ |
#endif /* 0 */ |
423 |
|
|
424 |
int32_t |
int32_t |
425 |
Diamond16_MainSearch(const uint8_t * const pRef, |
Diamond16_MainSearch(const uint8_t * const pRef, |
429 |
const uint8_t * const cur, |
const uint8_t * const cur, |
430 |
const int x, |
const int x, |
431 |
const int y, |
const int y, |
432 |
int32_t startx, |
const int start_x, |
433 |
int32_t starty, |
const int start_y, |
434 |
int32_t iMinSAD, |
int iMinSAD, |
435 |
VECTOR * const currMV, |
VECTOR * const currMV, |
436 |
const VECTOR * const pmv, |
const int center_x, |
437 |
|
const int center_y, |
438 |
const int32_t min_dx, |
const int32_t min_dx, |
439 |
const int32_t max_dx, |
const int32_t max_dx, |
440 |
const int32_t min_dy, |
const int32_t min_dy, |
448 |
/* Do a diamond search around given starting point, return SAD of best */ |
/* Do a diamond search around given starting point, return SAD of best */ |
449 |
|
|
450 |
int32_t iDirection = 0; |
int32_t iDirection = 0; |
451 |
|
int32_t iDirectionBackup; |
452 |
int32_t iSAD; |
int32_t iSAD; |
453 |
VECTOR backupMV; |
VECTOR backupMV; |
454 |
|
|
455 |
backupMV.x = startx; |
backupMV.x = start_x; |
456 |
backupMV.y = starty; |
backupMV.y = start_y; |
457 |
|
|
458 |
/* It's one search with full Diamond pattern, and only 3 of 4 for all following diamonds */ |
/* It's one search with full Diamond pattern, and only 3 of 4 for all following diamonds */ |
459 |
|
|
462 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x, backupMV.y - iDiamondSize, 3); |
CHECK_MV16_CANDIDATE_DIR(backupMV.x, backupMV.y - iDiamondSize, 3); |
463 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x, backupMV.y + iDiamondSize, 4); |
CHECK_MV16_CANDIDATE_DIR(backupMV.x, backupMV.y + iDiamondSize, 4); |
464 |
|
|
465 |
if (iDirection) |
if (iDirection) { |
466 |
while (!iFound) { |
while (!iFound) { |
467 |
iFound = 1; |
iFound = 1; |
468 |
backupMV = *currMV; |
backupMV = *currMV; |
469 |
|
iDirectionBackup = iDirection; |
470 |
|
|
471 |
if (iDirection != 2) |
if (iDirectionBackup != 2) |
472 |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x - iDiamondSize, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x - iDiamondSize, |
473 |
backupMV.y, 1); |
backupMV.y, 1); |
474 |
if (iDirection != 1) |
if (iDirectionBackup != 1) |
475 |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x + iDiamondSize, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x + iDiamondSize, |
476 |
backupMV.y, 2); |
backupMV.y, 2); |
477 |
if (iDirection != 4) |
if (iDirectionBackup != 4) |
478 |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x, |
479 |
backupMV.y - iDiamondSize, 3); |
backupMV.y - iDiamondSize, 3); |
480 |
if (iDirection != 3) |
if (iDirectionBackup != 3) |
481 |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x, |
482 |
backupMV.y + iDiamondSize, 4); |
backupMV.y + iDiamondSize, 4); |
483 |
|
} |
484 |
} else { |
} else { |
485 |
currMV->x = startx; |
currMV->x = start_x; |
486 |
currMV->y = starty; |
currMV->y = start_y; |
487 |
} |
} |
488 |
return iMinSAD; |
return iMinSAD; |
489 |
} |
} |
496 |
const uint8_t * const cur, |
const uint8_t * const cur, |
497 |
const int x, |
const int x, |
498 |
const int y, |
const int y, |
499 |
int32_t startx, |
const int start_x, |
500 |
int32_t starty, |
const int start_y, |
501 |
int32_t iMinSAD, |
int iMinSAD, |
502 |
VECTOR * const currMV, |
VECTOR * const currMV, |
503 |
const VECTOR * const pmv, |
const int center_x, |
504 |
|
const int center_y, |
505 |
const int32_t min_dx, |
const int32_t min_dx, |
506 |
const int32_t max_dx, |
const int32_t max_dx, |
507 |
const int32_t min_dy, |
const int32_t min_dy, |
518 |
int32_t iSAD; |
int32_t iSAD; |
519 |
VECTOR backupMV; |
VECTOR backupMV; |
520 |
|
|
521 |
backupMV.x = startx; |
backupMV.x = start_x; |
522 |
backupMV.y = starty; |
backupMV.y = start_y; |
523 |
|
|
524 |
/* It's one search with full square pattern, and new parts for all following diamonds */ |
/* It's one search with full square pattern, and new parts for all following diamonds */ |
525 |
|
|
544 |
backupMV.y + iDiamondSize, 8); |
backupMV.y + iDiamondSize, 8); |
545 |
|
|
546 |
|
|
547 |
if (iDirection) |
if (iDirection) { |
548 |
while (!iFound) { |
while (!iFound) { |
549 |
iFound = 1; |
iFound = 1; |
550 |
backupMV = *currMV; |
backupMV = *currMV; |
553 |
case 1: |
case 1: |
554 |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x - iDiamondSize, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x - iDiamondSize, |
555 |
backupMV.y, 1); |
backupMV.y, 1); |
556 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x - iDiamondSize, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x - iDiamondSize, |
557 |
backupMV.y - iDiamondSize, 5); |
backupMV.y - iDiamondSize, 5); |
558 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x + iDiamondSize, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x + iDiamondSize, |
559 |
backupMV.y - iDiamondSize, 7); |
backupMV.y - iDiamondSize, 7); |
560 |
break; |
break; |
561 |
case 2: |
case 2: |
562 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x + iDiamondSize, backupMV.y, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x + iDiamondSize, backupMV.y, |
563 |
2); |
2); |
564 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x - iDiamondSize, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x - iDiamondSize, |
565 |
backupMV.y + iDiamondSize, 6); |
backupMV.y + iDiamondSize, 6); |
566 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x + iDiamondSize, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x + iDiamondSize, |
567 |
backupMV.y + iDiamondSize, 8); |
backupMV.y + iDiamondSize, 8); |
568 |
break; |
break; |
569 |
|
|
570 |
case 3: |
case 3: |
571 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x, backupMV.y + iDiamondSize, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x, backupMV.y + iDiamondSize, |
572 |
4); |
4); |
573 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x + iDiamondSize, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x + iDiamondSize, |
574 |
backupMV.y - iDiamondSize, 7); |
backupMV.y - iDiamondSize, 7); |
575 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x + iDiamondSize, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x + iDiamondSize, |
576 |
backupMV.y + iDiamondSize, 8); |
backupMV.y + iDiamondSize, 8); |
577 |
break; |
break; |
578 |
|
|
579 |
case 4: |
case 4: |
580 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x, backupMV.y - iDiamondSize, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x, backupMV.y - iDiamondSize, |
581 |
3); |
3); |
582 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x - iDiamondSize, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x - iDiamondSize, |
583 |
backupMV.y - iDiamondSize, 5); |
backupMV.y - iDiamondSize, 5); |
584 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x - iDiamondSize, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x - iDiamondSize, |
585 |
backupMV.y + iDiamondSize, 6); |
backupMV.y + iDiamondSize, 6); |
586 |
break; |
break; |
587 |
|
|
588 |
case 5: |
case 5: |
589 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x - iDiamondSize, backupMV.y, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x - iDiamondSize, backupMV.y, |
590 |
1); |
1); |
591 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x, backupMV.y - iDiamondSize, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x, backupMV.y - iDiamondSize, |
592 |
3); |
3); |
593 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x - iDiamondSize, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x - iDiamondSize, |
594 |
backupMV.y - iDiamondSize, 5); |
backupMV.y - iDiamondSize, 5); |
595 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x - iDiamondSize, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x - iDiamondSize, |
596 |
backupMV.y + iDiamondSize, 6); |
backupMV.y + iDiamondSize, 6); |
597 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x + iDiamondSize, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x + iDiamondSize, |
598 |
backupMV.y - iDiamondSize, 7); |
backupMV.y - iDiamondSize, 7); |
599 |
break; |
break; |
600 |
|
|
601 |
case 6: |
case 6: |
602 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x + iDiamondSize, backupMV.y, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x + iDiamondSize, backupMV.y, |
603 |
2); |
2); |
604 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x, backupMV.y - iDiamondSize, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x, backupMV.y - iDiamondSize, |
605 |
3); |
3); |
606 |
|
|
607 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x - iDiamondSize, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x - iDiamondSize, |
608 |
backupMV.y - iDiamondSize, 5); |
backupMV.y - iDiamondSize, 5); |
609 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x - iDiamondSize, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x - iDiamondSize, |
610 |
backupMV.y + iDiamondSize, 6); |
backupMV.y + iDiamondSize, 6); |
611 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x + iDiamondSize, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x + iDiamondSize, |
612 |
backupMV.y + iDiamondSize, 8); |
backupMV.y + iDiamondSize, 8); |
613 |
|
|
614 |
break; |
break; |
616 |
case 7: |
case 7: |
617 |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x - iDiamondSize, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x - iDiamondSize, |
618 |
backupMV.y, 1); |
backupMV.y, 1); |
619 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x, backupMV.y + iDiamondSize, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x, backupMV.y + iDiamondSize, |
620 |
4); |
4); |
621 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x - iDiamondSize, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x - iDiamondSize, |
622 |
backupMV.y - iDiamondSize, 5); |
backupMV.y - iDiamondSize, 5); |
623 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x + iDiamondSize, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x + iDiamondSize, |
624 |
backupMV.y - iDiamondSize, 7); |
backupMV.y - iDiamondSize, 7); |
625 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x + iDiamondSize, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x + iDiamondSize, |
626 |
backupMV.y + iDiamondSize, 8); |
backupMV.y + iDiamondSize, 8); |
627 |
break; |
break; |
628 |
|
|
629 |
case 8: |
case 8: |
630 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x + iDiamondSize, backupMV.y, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x + iDiamondSize, backupMV.y, |
631 |
2); |
2); |
632 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x, backupMV.y + iDiamondSize, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x, backupMV.y + iDiamondSize, |
633 |
4); |
4); |
634 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x - iDiamondSize, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x - iDiamondSize, |
635 |
backupMV.y + iDiamondSize, 6); |
backupMV.y + iDiamondSize, 6); |
636 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x + iDiamondSize, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x + iDiamondSize, |
637 |
backupMV.y - iDiamondSize, 7); |
backupMV.y - iDiamondSize, 7); |
638 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x + iDiamondSize, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x + iDiamondSize, |
639 |
backupMV.y + iDiamondSize, 8); |
backupMV.y + iDiamondSize, 8); |
640 |
break; |
break; |
641 |
default: |
default: |
642 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x - iDiamondSize, backupMV.y, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x - iDiamondSize, backupMV.y, |
643 |
1); |
1); |
644 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x + iDiamondSize, backupMV.y, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x + iDiamondSize, backupMV.y, |
645 |
2); |
2); |
646 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x, backupMV.y - iDiamondSize, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x, backupMV.y - iDiamondSize, |
647 |
3); |
3); |
648 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x, backupMV.y + iDiamondSize, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x, backupMV.y + iDiamondSize, |
649 |
4); |
4); |
650 |
|
|
651 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x - iDiamondSize, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x - iDiamondSize, |
652 |
backupMV.y - iDiamondSize, 5); |
backupMV.y - iDiamondSize, 5); |
653 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x - iDiamondSize, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x - iDiamondSize, |
654 |
backupMV.y + iDiamondSize, 6); |
backupMV.y + iDiamondSize, 6); |
655 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x + iDiamondSize, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x + iDiamondSize, |
656 |
backupMV.y - iDiamondSize, 7); |
backupMV.y - iDiamondSize, 7); |
657 |
CHECK_MV16_CANDIDATE_DIR(backupMV.x + iDiamondSize, |
CHECK_MV16_CANDIDATE_FOUND(backupMV.x + iDiamondSize, |
658 |
backupMV.y + iDiamondSize, 8); |
backupMV.y + iDiamondSize, 8); |
659 |
break; |
break; |
660 |
} |
} |
661 |
|
} |
662 |
} else { |
} else { |
663 |
currMV->x = startx; |
currMV->x = start_x; |
664 |
currMV->y = starty; |
currMV->y = start_y; |
665 |
} |
} |
666 |
return iMinSAD; |
return iMinSAD; |
667 |
} |
} |
675 |
const uint8_t * const cur, |
const uint8_t * const cur, |
676 |
const int x, |
const int x, |
677 |
const int y, |
const int y, |
678 |
int32_t startx, |
const int start_x, |
679 |
int32_t starty, |
const int start_y, |
680 |
int32_t iMinSAD, |
int iMinSAD, |
681 |
VECTOR * const currMV, |
VECTOR * const currMV, |
682 |
const VECTOR * const pmv, |
const int center_x, |
683 |
|
const int center_y, |
684 |
const int32_t min_dx, |
const int32_t min_dx, |
685 |
const int32_t max_dx, |
const int32_t max_dx, |
686 |
const int32_t min_dy, |
const int32_t min_dy, |
695 |
int32_t dx, dy; |
int32_t dx, dy; |
696 |
VECTOR backupMV; |
VECTOR backupMV; |
697 |
|
|
698 |
backupMV.x = startx; |
backupMV.x = start_x; |
699 |
backupMV.y = starty; |
backupMV.y = start_y; |
700 |
|
|
701 |
for (dx = min_dx; dx <= max_dx; dx += iDiamondSize) |
for (dx = min_dx; dx <= max_dx; dx += iDiamondSize) |
702 |
for (dy = min_dy; dy <= max_dy; dy += iDiamondSize) |
for (dy = min_dy; dy <= max_dy; dy += iDiamondSize) |
713 |
const uint8_t * const cur, |
const uint8_t * const cur, |
714 |
const int x, |
const int x, |
715 |
const int y, |
const int y, |
716 |
int32_t startx, |
const int start_xi, |
717 |
int32_t starty, |
const int start_yi, |
718 |
int32_t iMinSAD, |
int iMinSAD, |
719 |
VECTOR * const currMV, |
VECTOR * const currMV, |
720 |
const VECTOR * const pmv, |
const int center_x, |
721 |
|
const int center_y, |
722 |
const int32_t min_dx, |
const int32_t min_dx, |
723 |
const int32_t max_dx, |
const int32_t max_dx, |
724 |
const int32_t min_dy, |
const int32_t min_dy, |
731 |
{ |
{ |
732 |
|
|
733 |
int32_t iSAD; |
int32_t iSAD; |
734 |
|
int start_x = start_xi, start_y = start_yi; |
735 |
|
|
736 |
/* directions: 1 - left (x-1); 2 - right (x+1), 4 - up (y-1); 8 - down (y+1) */ |
/* directions: 1 - left (x-1); 2 - right (x+1), 4 - up (y-1); 8 - down (y+1) */ |
737 |
|
|
738 |
if (iDirection) { |
if (iDirection) { |
739 |
CHECK_MV16_CANDIDATE(startx - iDiamondSize, starty); |
CHECK_MV16_CANDIDATE(start_x - iDiamondSize, start_y); |
740 |
CHECK_MV16_CANDIDATE(startx + iDiamondSize, starty); |
CHECK_MV16_CANDIDATE(start_x + iDiamondSize, start_y); |
741 |
CHECK_MV16_CANDIDATE(startx, starty - iDiamondSize); |
CHECK_MV16_CANDIDATE(start_x, start_y - iDiamondSize); |
742 |
CHECK_MV16_CANDIDATE(startx, starty + iDiamondSize); |
CHECK_MV16_CANDIDATE(start_x, start_y + iDiamondSize); |
743 |
} else { |
} else { |
744 |
int bDirection = 1 + 2 + 4 + 8; |
int bDirection = 1 + 2 + 4 + 8; |
745 |
|
|
746 |
do { |
do { |
747 |
iDirection = 0; |
iDirection = 0; |
748 |
if (bDirection & 1) //we only want to check left if we came from the right (our last motion was to the left, up-left or down-left) |
if (bDirection & 1) //we only want to check left if we came from the right (our last motion was to the left, up-left or down-left) |
749 |
CHECK_MV16_CANDIDATE_DIR(startx - iDiamondSize, starty, 1); |
CHECK_MV16_CANDIDATE_DIR(start_x - iDiamondSize, start_y, 1); |
750 |
|
|
751 |
if (bDirection & 2) |
if (bDirection & 2) |
752 |
CHECK_MV16_CANDIDATE_DIR(startx + iDiamondSize, starty, 2); |
CHECK_MV16_CANDIDATE_DIR(start_x + iDiamondSize, start_y, 2); |
753 |
|
|
754 |
if (bDirection & 4) |
if (bDirection & 4) |
755 |
CHECK_MV16_CANDIDATE_DIR(startx, starty - iDiamondSize, 4); |
CHECK_MV16_CANDIDATE_DIR(start_x, start_y - iDiamondSize, 4); |
756 |
|
|
757 |
if (bDirection & 8) |
if (bDirection & 8) |
758 |
CHECK_MV16_CANDIDATE_DIR(startx, starty + iDiamondSize, 8); |
CHECK_MV16_CANDIDATE_DIR(start_x, start_y + iDiamondSize, 8); |
759 |
|
|
760 |
/* now we're doing diagonal checks near our candidate */ |
/* now we're doing diagonal checks near our candidate */ |
761 |
|
|
763 |
{ |
{ |
764 |
bDirection = iDirection; |
bDirection = iDirection; |
765 |
iDirection = 0; |
iDirection = 0; |
766 |
startx = currMV->x; |
start_x = currMV->x; |
767 |
starty = currMV->y; |
start_y = currMV->y; |
768 |
if (bDirection & 3) //our candidate is left or right |
if (bDirection & 3) //our candidate is left or right |
769 |
{ |
{ |
770 |
CHECK_MV16_CANDIDATE_DIR(startx, starty + iDiamondSize, 8); |
CHECK_MV16_CANDIDATE_DIR(start_x, start_y + iDiamondSize, 8); |
771 |
CHECK_MV16_CANDIDATE_DIR(startx, starty - iDiamondSize, 4); |
CHECK_MV16_CANDIDATE_DIR(start_x, start_y - iDiamondSize, 4); |
772 |
} else // what remains here is up or down |
} else // what remains here is up or down |
773 |
{ |
{ |
774 |
CHECK_MV16_CANDIDATE_DIR(startx + iDiamondSize, starty, 2); |
CHECK_MV16_CANDIDATE_DIR(start_x + iDiamondSize, start_y, 2); |
775 |
CHECK_MV16_CANDIDATE_DIR(startx - iDiamondSize, starty, 1); |
CHECK_MV16_CANDIDATE_DIR(start_x - iDiamondSize, start_y, 1); |
776 |
} |
} |
777 |
|
|
778 |
if (iDirection) { |
if (iDirection) { |
779 |
bDirection += iDirection; |
bDirection += iDirection; |
780 |
startx = currMV->x; |
start_x = currMV->x; |
781 |
starty = currMV->y; |
start_y = currMV->y; |
782 |
} |
} |
783 |
} else //about to quit, eh? not so fast.... |
} else //about to quit, eh? not so fast.... |
784 |
{ |
{ |
785 |
switch (bDirection) { |
switch (bDirection) { |
786 |
case 2: |
case 2: |
787 |
CHECK_MV16_CANDIDATE_DIR(startx + iDiamondSize, |
CHECK_MV16_CANDIDATE_DIR(start_x + iDiamondSize, |
788 |
starty - iDiamondSize, 2 + 4); |
start_y - iDiamondSize, 2 + 4); |
789 |
CHECK_MV16_CANDIDATE_DIR(startx + iDiamondSize, |
CHECK_MV16_CANDIDATE_DIR(start_x + iDiamondSize, |
790 |
starty + iDiamondSize, 2 + 8); |
start_y + iDiamondSize, 2 + 8); |
791 |
break; |
break; |
792 |
case 1: |
case 1: |
793 |
CHECK_MV16_CANDIDATE_DIR(startx - iDiamondSize, |
|
794 |
starty - iDiamondSize, 1 + 4); |
CHECK_MV16_CANDIDATE_DIR(start_x - iDiamondSize, |
795 |
CHECK_MV16_CANDIDATE_DIR(startx - iDiamondSize, |
start_y - iDiamondSize, 1 + 4); |
796 |
starty + iDiamondSize, 1 + 8); |
CHECK_MV16_CANDIDATE_DIR(start_x - iDiamondSize, |
797 |
|
start_y + iDiamondSize, 1 + 8); |
798 |
break; |
break; |
799 |
case 2 + 4: |
case 2 + 4: |
800 |
CHECK_MV16_CANDIDATE_DIR(startx - iDiamondSize, |
CHECK_MV16_CANDIDATE_DIR(start_x - iDiamondSize, |
801 |
starty - iDiamondSize, 1 + 4); |
start_y - iDiamondSize, 1 + 4); |
802 |
CHECK_MV16_CANDIDATE_DIR(startx + iDiamondSize, |
CHECK_MV16_CANDIDATE_DIR(start_x + iDiamondSize, |
803 |
starty - iDiamondSize, 2 + 4); |
start_y - iDiamondSize, 2 + 4); |
804 |
CHECK_MV16_CANDIDATE_DIR(startx + iDiamondSize, |
CHECK_MV16_CANDIDATE_DIR(start_x + iDiamondSize, |
805 |
starty + iDiamondSize, 2 + 8); |
start_y + iDiamondSize, 2 + 8); |
806 |
break; |
break; |
807 |
case 4: |
case 4: |
808 |
CHECK_MV16_CANDIDATE_DIR(startx + iDiamondSize, |
CHECK_MV16_CANDIDATE_DIR(start_x + iDiamondSize, |
809 |
starty - iDiamondSize, 2 + 4); |
start_y - iDiamondSize, 2 + 4); |
810 |
CHECK_MV16_CANDIDATE_DIR(startx - iDiamondSize, |
CHECK_MV16_CANDIDATE_DIR(start_x - iDiamondSize, |
811 |
starty - iDiamondSize, 1 + 4); |
start_y - iDiamondSize, 1 + 4); |
812 |
break; |
break; |
813 |
case 8: |
case 8: |
814 |
CHECK_MV16_CANDIDATE_DIR(startx + iDiamondSize, |
CHECK_MV16_CANDIDATE_DIR(start_x + iDiamondSize, |
815 |
starty + iDiamondSize, 2 + 8); |
start_y + iDiamondSize, 2 + 8); |
816 |
CHECK_MV16_CANDIDATE_DIR(startx - iDiamondSize, |
CHECK_MV16_CANDIDATE_DIR(start_x - iDiamondSize, |
817 |
starty + iDiamondSize, 1 + 8); |
start_y + iDiamondSize, 1 + 8); |
818 |
break; |
break; |
819 |
case 1 + 4: |
case 1 + 4: |
820 |
CHECK_MV16_CANDIDATE_DIR(startx - iDiamondSize, |
CHECK_MV16_CANDIDATE_DIR(start_x - iDiamondSize, |
821 |
starty + iDiamondSize, 1 + 8); |
start_y + iDiamondSize, 1 + 8); |
822 |
CHECK_MV16_CANDIDATE_DIR(startx - iDiamondSize, |
CHECK_MV16_CANDIDATE_DIR(start_x - iDiamondSize, |
823 |
starty - iDiamondSize, 1 + 4); |
start_y - iDiamondSize, 1 + 4); |
824 |
CHECK_MV16_CANDIDATE_DIR(startx + iDiamondSize, |
CHECK_MV16_CANDIDATE_DIR(start_x + iDiamondSize, |
825 |
starty - iDiamondSize, 2 + 4); |
start_y - iDiamondSize, 2 + 4); |
826 |
break; |
break; |
827 |
case 2 + 8: |
case 2 + 8: |
828 |
CHECK_MV16_CANDIDATE_DIR(startx - iDiamondSize, |
CHECK_MV16_CANDIDATE_DIR(start_x - iDiamondSize, |
829 |
starty - iDiamondSize, 1 + 4); |
start_y - iDiamondSize, 1 + 4); |
830 |
CHECK_MV16_CANDIDATE_DIR(startx - iDiamondSize, |
CHECK_MV16_CANDIDATE_DIR(start_x - iDiamondSize, |
831 |
starty + iDiamondSize, 1 + 8); |
start_y + iDiamondSize, 1 + 8); |
832 |
CHECK_MV16_CANDIDATE_DIR(startx + iDiamondSize, |
CHECK_MV16_CANDIDATE_DIR(start_x + iDiamondSize, |
833 |
starty + iDiamondSize, 2 + 8); |
start_y + iDiamondSize, 2 + 8); |
834 |
break; |
break; |
835 |
case 1 + 8: |
case 1 + 8: |
836 |
CHECK_MV16_CANDIDATE_DIR(startx + iDiamondSize, |
CHECK_MV16_CANDIDATE_DIR(start_x + iDiamondSize, |
837 |
starty - iDiamondSize, 2 + 4); |
start_y - iDiamondSize, 2 + 4); |
838 |
CHECK_MV16_CANDIDATE_DIR(startx + iDiamondSize, |
CHECK_MV16_CANDIDATE_DIR(start_x + iDiamondSize, |
839 |
starty + iDiamondSize, 2 + 8); |
start_y + iDiamondSize, 2 + 8); |
840 |
CHECK_MV16_CANDIDATE_DIR(startx - iDiamondSize, |
CHECK_MV16_CANDIDATE_DIR(start_x - iDiamondSize, |
841 |
starty + iDiamondSize, 1 + 8); |
start_y + iDiamondSize, 1 + 8); |
842 |
break; |
break; |
843 |
default: //1+2+4+8 == we didn't find anything at all |
default: //1+2+4+8 == we didn't find anything at all |
844 |
CHECK_MV16_CANDIDATE_DIR(startx - iDiamondSize, |
CHECK_MV16_CANDIDATE_DIR(start_x - iDiamondSize, |
845 |
starty - iDiamondSize, 1 + 4); |
start_y - iDiamondSize, 1 + 4); |
846 |
CHECK_MV16_CANDIDATE_DIR(startx - iDiamondSize, |
CHECK_MV16_CANDIDATE_DIR(start_x - iDiamondSize, |
847 |
starty + iDiamondSize, 1 + 8); |
start_y + iDiamondSize, 1 + 8); |
848 |
CHECK_MV16_CANDIDATE_DIR(startx + iDiamondSize, |
CHECK_MV16_CANDIDATE_DIR(start_x + iDiamondSize, |
849 |
starty - iDiamondSize, 2 + 4); |
start_y - iDiamondSize, 2 + 4); |
850 |
CHECK_MV16_CANDIDATE_DIR(startx + iDiamondSize, |
CHECK_MV16_CANDIDATE_DIR(start_x + iDiamondSize, |
851 |
starty + iDiamondSize, 2 + 8); |
start_y + iDiamondSize, 2 + 8); |
852 |
break; |
break; |
853 |
} |
} |
854 |
if (!iDirection) |
if (!iDirection) |
855 |
break; //ok, the end. really |
break; //ok, the end. really |
856 |
else { |
else { |
857 |
bDirection = iDirection; |
bDirection = iDirection; |
858 |
startx = currMV->x; |
start_x = currMV->x; |
859 |
starty = currMV->y; |
start_y = currMV->y; |
860 |
} |
} |
861 |
} |
} |
862 |
} |
} |
863 |
while (1); //forever |
while (1); //forever |
864 |
} |
} |
865 |
|
|
866 |
return iMinSAD; |
return iMinSAD; |
867 |
} |
} |
868 |
|
|
874 |
const uint8_t * const cur, |
const uint8_t * const cur, |
875 |
const int x, |
const int x, |
876 |
const int y, |
const int y, |
877 |
int32_t startx, |
const int start_xi, |
878 |
int32_t starty, |
const int start_yi, |
879 |
int32_t iMinSAD, |
int iMinSAD, |
880 |
VECTOR * const currMV, |
VECTOR * const currMV, |
881 |
const VECTOR * const pmv, |
const int center_x, |
882 |
|
const int center_y, |
883 |
const int32_t min_dx, |
const int32_t min_dx, |
884 |
const int32_t max_dx, |
const int32_t max_dx, |
885 |
const int32_t min_dy, |
const int32_t min_dy, |
892 |
{ |
{ |
893 |
|
|
894 |
int32_t iSAD; |
int32_t iSAD; |
895 |
|
int start_x = start_xi, start_y = start_yi; |
896 |
|
|
897 |
/* directions: 1 - left (x-1); 2 - right (x+1), 4 - up (y-1); 8 - down (y+1) */ |
/* directions: 1 - left (x-1); 2 - right (x+1), 4 - up (y-1); 8 - down (y+1) */ |
898 |
|
|
899 |
if (iDirection) { |
if (iDirection) { |
900 |
CHECK_MV8_CANDIDATE(startx - iDiamondSize, starty); |
CHECK_MV8_CANDIDATE(start_x - iDiamondSize, start_y); |
901 |
CHECK_MV8_CANDIDATE(startx + iDiamondSize, starty); |
CHECK_MV8_CANDIDATE(start_x + iDiamondSize, start_y); |
902 |
CHECK_MV8_CANDIDATE(startx, starty - iDiamondSize); |
CHECK_MV8_CANDIDATE(start_x, start_y - iDiamondSize); |
903 |
CHECK_MV8_CANDIDATE(startx, starty + iDiamondSize); |
CHECK_MV8_CANDIDATE(start_x, start_y + iDiamondSize); |
904 |
} else { |
} else { |
905 |
int bDirection = 1 + 2 + 4 + 8; |
int bDirection = 1 + 2 + 4 + 8; |
906 |
|
|
907 |
do { |
do { |
908 |
iDirection = 0; |
iDirection = 0; |
909 |
if (bDirection & 1) //we only want to check left if we came from the right (our last motion was to the left, up-left or down-left) |
if (bDirection & 1) //we only want to check left if we came from the right (our last motion was to the left, up-left or down-left) |
910 |
CHECK_MV8_CANDIDATE_DIR(startx - iDiamondSize, starty, 1); |
CHECK_MV8_CANDIDATE_DIR(start_x - iDiamondSize, start_y, 1); |
911 |
|
|
912 |
if (bDirection & 2) |
if (bDirection & 2) |
913 |
CHECK_MV8_CANDIDATE_DIR(startx + iDiamondSize, starty, 2); |
CHECK_MV8_CANDIDATE_DIR(start_x + iDiamondSize, start_y, 2); |
914 |
|
|
915 |
if (bDirection & 4) |
if (bDirection & 4) |
916 |
CHECK_MV8_CANDIDATE_DIR(startx, starty - iDiamondSize, 4); |
CHECK_MV8_CANDIDATE_DIR(start_x, start_y - iDiamondSize, 4); |
917 |
|
|
918 |
if (bDirection & 8) |
if (bDirection & 8) |
919 |
CHECK_MV8_CANDIDATE_DIR(startx, starty + iDiamondSize, 8); |
CHECK_MV8_CANDIDATE_DIR(start_x, start_y + iDiamondSize, 8); |
920 |
|
|
921 |
/* now we're doing diagonal checks near our candidate */ |
/* now we're doing diagonal checks near our candidate */ |
922 |
|
|
924 |
{ |
{ |
925 |
bDirection = iDirection; |
bDirection = iDirection; |
926 |
iDirection = 0; |
iDirection = 0; |
927 |
startx = currMV->x; |
start_x = currMV->x; |
928 |
starty = currMV->y; |
start_y = currMV->y; |
929 |
if (bDirection & 3) //our candidate is left or right |
if (bDirection & 3) //our candidate is left or right |
930 |
{ |
{ |
931 |
CHECK_MV8_CANDIDATE_DIR(startx, starty + iDiamondSize, 8); |
CHECK_MV8_CANDIDATE_DIR(start_x, start_y + iDiamondSize, 8); |
932 |
CHECK_MV8_CANDIDATE_DIR(startx, starty - iDiamondSize, 4); |
CHECK_MV8_CANDIDATE_DIR(start_x, start_y - iDiamondSize, 4); |
933 |
} else // what remains here is up or down |
} else // what remains here is up or down |
934 |
{ |
{ |
935 |
CHECK_MV8_CANDIDATE_DIR(startx + iDiamondSize, starty, 2); |
CHECK_MV8_CANDIDATE_DIR(start_x + iDiamondSize, start_y, 2); |
936 |
CHECK_MV8_CANDIDATE_DIR(startx - iDiamondSize, starty, 1); |
CHECK_MV8_CANDIDATE_DIR(start_x - iDiamondSize, start_y, 1); |
937 |
} |
} |
938 |
|
|
939 |
if (iDirection) { |
if (iDirection) { |
940 |
bDirection += iDirection; |
bDirection += iDirection; |
941 |
startx = currMV->x; |
start_x = currMV->x; |
942 |
starty = currMV->y; |
start_y = currMV->y; |
943 |
} |
} |
944 |
} else //about to quit, eh? not so fast.... |
} else //about to quit, eh? not so fast.... |
945 |
{ |
{ |
946 |
switch (bDirection) { |
switch (bDirection) { |
947 |
case 2: |
case 2: |
948 |
CHECK_MV8_CANDIDATE_DIR(startx + iDiamondSize, |
CHECK_MV8_CANDIDATE_DIR(start_x + iDiamondSize, |
949 |
starty - iDiamondSize, 2 + 4); |
start_y - iDiamondSize, 2 + 4); |
950 |
CHECK_MV8_CANDIDATE_DIR(startx + iDiamondSize, |
CHECK_MV8_CANDIDATE_DIR(start_x + iDiamondSize, |
951 |
starty + iDiamondSize, 2 + 8); |
start_y + iDiamondSize, 2 + 8); |
952 |
break; |
break; |
953 |
case 1: |
case 1: |
954 |
CHECK_MV8_CANDIDATE_DIR(startx - iDiamondSize, |
CHECK_MV8_CANDIDATE_DIR(start_x - iDiamondSize, |
955 |
starty - iDiamondSize, 1 + 4); |
start_y - iDiamondSize, 1 + 4); |
956 |
CHECK_MV8_CANDIDATE_DIR(startx - iDiamondSize, |
CHECK_MV8_CANDIDATE_DIR(start_x - iDiamondSize, |
957 |
starty + iDiamondSize, 1 + 8); |
start_y + iDiamondSize, 1 + 8); |
958 |
break; |
break; |
959 |
case 2 + 4: |
case 2 + 4: |
960 |
CHECK_MV8_CANDIDATE_DIR(startx - iDiamondSize, |
CHECK_MV8_CANDIDATE_DIR(start_x - iDiamondSize, |
961 |
starty - iDiamondSize, 1 + 4); |
start_y - iDiamondSize, 1 + 4); |
962 |
CHECK_MV8_CANDIDATE_DIR(startx + iDiamondSize, |
CHECK_MV8_CANDIDATE_DIR(start_x + iDiamondSize, |
963 |
starty - iDiamondSize, 2 + 4); |
start_y - iDiamondSize, 2 + 4); |
964 |
CHECK_MV8_CANDIDATE_DIR(startx + iDiamondSize, |
CHECK_MV8_CANDIDATE_DIR(start_x + iDiamondSize, |
965 |
starty + iDiamondSize, 2 + 8); |
start_y + iDiamondSize, 2 + 8); |
966 |
break; |
break; |
967 |
case 4: |
case 4: |
968 |
CHECK_MV8_CANDIDATE_DIR(startx + iDiamondSize, |
CHECK_MV8_CANDIDATE_DIR(start_x + iDiamondSize, |
969 |
starty - iDiamondSize, 2 + 4); |
start_y - iDiamondSize, 2 + 4); |
970 |
CHECK_MV8_CANDIDATE_DIR(startx - iDiamondSize, |
CHECK_MV8_CANDIDATE_DIR(start_x - iDiamondSize, |
971 |
starty - iDiamondSize, 1 + 4); |
start_y - iDiamondSize, 1 + 4); |
972 |
break; |
break; |
973 |
case 8: |
case 8: |
974 |
CHECK_MV8_CANDIDATE_DIR(startx + iDiamondSize, |
CHECK_MV8_CANDIDATE_DIR(start_x + iDiamondSize, |
975 |
starty + iDiamondSize, 2 + 8); |
start_y + iDiamondSize, 2 + 8); |
976 |
CHECK_MV8_CANDIDATE_DIR(startx - iDiamondSize, |
CHECK_MV8_CANDIDATE_DIR(start_x - iDiamondSize, |
977 |
starty + iDiamondSize, 1 + 8); |
start_y + iDiamondSize, 1 + 8); |
978 |
break; |
break; |
979 |
case 1 + 4: |
case 1 + 4: |
980 |
CHECK_MV8_CANDIDATE_DIR(startx - iDiamondSize, |
CHECK_MV8_CANDIDATE_DIR(start_x - iDiamondSize, |
981 |
starty + iDiamondSize, 1 + 8); |
start_y + iDiamondSize, 1 + 8); |
982 |
CHECK_MV8_CANDIDATE_DIR(startx - iDiamondSize, |
CHECK_MV8_CANDIDATE_DIR(start_x - iDiamondSize, |
983 |
starty - iDiamondSize, 1 + 4); |
start_y - iDiamondSize, 1 + 4); |
984 |
CHECK_MV8_CANDIDATE_DIR(startx + iDiamondSize, |
CHECK_MV8_CANDIDATE_DIR(start_x + iDiamondSize, |
985 |
starty - iDiamondSize, 2 + 4); |
start_y - iDiamondSize, 2 + 4); |
986 |
break; |
break; |
987 |
case 2 + 8: |
case 2 + 8: |
988 |
CHECK_MV8_CANDIDATE_DIR(startx - iDiamondSize, |
CHECK_MV8_CANDIDATE_DIR(start_x - iDiamondSize, |
989 |
starty - iDiamondSize, 1 + 4); |
start_y - iDiamondSize, 1 + 4); |
990 |
CHECK_MV8_CANDIDATE_DIR(startx - iDiamondSize, |
CHECK_MV8_CANDIDATE_DIR(start_x - iDiamondSize, |
991 |
starty + iDiamondSize, 1 + 8); |
start_y + iDiamondSize, 1 + 8); |
992 |
CHECK_MV8_CANDIDATE_DIR(startx + iDiamondSize, |
CHECK_MV8_CANDIDATE_DIR(start_x + iDiamondSize, |
993 |
starty + iDiamondSize, 2 + 8); |
start_y + iDiamondSize, 2 + 8); |
994 |
break; |
break; |
995 |
case 1 + 8: |
case 1 + 8: |
996 |
CHECK_MV8_CANDIDATE_DIR(startx + iDiamondSize, |
CHECK_MV8_CANDIDATE_DIR(start_x + iDiamondSize, |
997 |
starty - iDiamondSize, 2 + 4); |
start_y - iDiamondSize, 2 + 4); |
998 |
CHECK_MV8_CANDIDATE_DIR(startx + iDiamondSize, |
CHECK_MV8_CANDIDATE_DIR(start_x + iDiamondSize, |
999 |
starty + iDiamondSize, 2 + 8); |
start_y + iDiamondSize, 2 + 8); |
1000 |
CHECK_MV8_CANDIDATE_DIR(startx - iDiamondSize, |
CHECK_MV8_CANDIDATE_DIR(start_x - iDiamondSize, |
1001 |
starty + iDiamondSize, 1 + 8); |
start_y + iDiamondSize, 1 + 8); |
1002 |
break; |
break; |
1003 |
default: //1+2+4+8 == we didn't find anything at all |
default: //1+2+4+8 == we didn't find anything at all |
1004 |
CHECK_MV8_CANDIDATE_DIR(startx - iDiamondSize, |
CHECK_MV8_CANDIDATE_DIR(start_x - iDiamondSize, |
1005 |
starty - iDiamondSize, 1 + 4); |
start_y - iDiamondSize, 1 + 4); |
1006 |
CHECK_MV8_CANDIDATE_DIR(startx - iDiamondSize, |
CHECK_MV8_CANDIDATE_DIR(start_x - iDiamondSize, |
1007 |
starty + iDiamondSize, 1 + 8); |
start_y + iDiamondSize, 1 + 8); |
1008 |
CHECK_MV8_CANDIDATE_DIR(startx + iDiamondSize, |
CHECK_MV8_CANDIDATE_DIR(start_x + iDiamondSize, |
1009 |
starty - iDiamondSize, 2 + 4); |
start_y - iDiamondSize, 2 + 4); |
1010 |
CHECK_MV8_CANDIDATE_DIR(startx + iDiamondSize, |
CHECK_MV8_CANDIDATE_DIR(start_x + iDiamondSize, |
1011 |
starty + iDiamondSize, 2 + 8); |
start_y + iDiamondSize, 2 + 8); |
1012 |
break; |
break; |
1013 |
} |
} |
1014 |
if (!(iDirection)) |
if (!(iDirection)) |
1015 |
break; //ok, the end. really |
break; //ok, the end. really |
1016 |
else { |
else { |
1017 |
bDirection = iDirection; |
bDirection = iDirection; |
1018 |
startx = currMV->x; |
start_x = currMV->x; |
1019 |
starty = currMV->y; |
start_y = currMV->y; |
1020 |
} |
} |
1021 |
} |
} |
1022 |
} |
} |
1034 |
const uint8_t * const cur, |
const uint8_t * const cur, |
1035 |
const int x, |
const int x, |
1036 |
const int y, |
const int y, |
1037 |
int32_t startx, |
const int start_x, |
1038 |
int32_t starty, |
const int start_y, |
1039 |
int32_t iMinSAD, |
int iMinSAD, |
1040 |
VECTOR * const currMV, |
VECTOR * const currMV, |
1041 |
const VECTOR * const pmv, |
const int center_x, |
1042 |
|
const int center_y, |
1043 |
const int32_t min_dx, |
const int32_t min_dx, |
1044 |
const int32_t max_dx, |
const int32_t max_dx, |
1045 |
const int32_t min_dy, |
const int32_t min_dy, |
1054 |
int32_t dx, dy; |
int32_t dx, dy; |
1055 |
VECTOR backupMV; |
VECTOR backupMV; |
1056 |
|
|
1057 |
backupMV.x = startx; |
backupMV.x = start_x; |
1058 |
backupMV.y = starty; |
backupMV.y = start_y; |
1059 |
|
|
1060 |
for (dx = min_dx; dx <= max_dx; dx += iDiamondSize) |
for (dx = min_dx; dx <= max_dx; dx += iDiamondSize) |
1061 |
for (dy = min_dy; dy <= max_dy; dy += iDiamondSize) |
for (dy = min_dy; dy <= max_dy; dy += iDiamondSize) |
1064 |
return iMinSAD; |
return iMinSAD; |
1065 |
} |
} |
1066 |
|
|
1067 |
|
Halfpel8_RefineFuncPtr Halfpel8_Refine; |
1068 |
|
|
1069 |
int32_t |
int32_t |
1070 |
Halfpel16_Refine(const uint8_t * const pRef, |
Halfpel16_Refine(const uint8_t * const pRef, |
1076 |
const int y, |
const int y, |
1077 |
VECTOR * const currMV, |
VECTOR * const currMV, |
1078 |
int32_t iMinSAD, |
int32_t iMinSAD, |
1079 |
const VECTOR * const pmv, |
const int center_x, |
1080 |
|
const int center_y, |
1081 |
const int32_t min_dx, |
const int32_t min_dx, |
1082 |
const int32_t max_dx, |
const int32_t max_dx, |
1083 |
const int32_t min_dy, |
const int32_t min_dy, |
1106 |
#define PMV_HALFPEL16 (PMV_HALFPELDIAMOND16|PMV_HALFPELREFINE16) |
#define PMV_HALFPEL16 (PMV_HALFPELDIAMOND16|PMV_HALFPELREFINE16) |
1107 |
|
|
1108 |
|
|
1109 |
|
|
1110 |
int32_t |
int32_t |
1111 |
PMVfastSearch16(const uint8_t * const pRef, |
PMVfastSearch16(const uint8_t * const pRef, |
1112 |
const uint8_t * const pRefH, |
const uint8_t * const pRefH, |
1115 |
const IMAGE * const pCur, |
const IMAGE * const pCur, |
1116 |
const int x, |
const int x, |
1117 |
const int y, |
const int y, |
1118 |
|
const int start_x, /* start is searched first, so it should contain the most */ |
1119 |
|
const int start_y, /* likely motion vector for this block */ |
1120 |
|
const int center_x, /* center is from where length of MVs is measured */ |
1121 |
|
const int center_y, |
1122 |
const uint32_t MotionFlags, |
const uint32_t MotionFlags, |
1123 |
const uint32_t iQuant, |
const uint32_t iQuant, |
1124 |
const uint32_t iFcode, |
const uint32_t iFcode, |
1172 |
} |
} |
1173 |
|
|
1174 |
/* because we might use something like IF (dx>max_dx) THEN dx=max_dx; */ |
/* because we might use something like IF (dx>max_dx) THEN dx=max_dx; */ |
1175 |
bPredEq = get_pmvdata(pMBs, x, y, iWcount, 0, pmv, psad); |
bPredEq = get_pmvdata2(pMBs, iWcount, 0, x, y, 0, pmv, psad); |
|
// bPredEq = get_pmvdata2(pMBs, iWcount, 0, x, y, 0, pmv, psad); |
|
1176 |
|
|
|
/* fprintf(stderr,"pmv: %d %d / %d --- %d %d %d %d %d %d - %d %d %d\n", |
|
|
pmv[0].x,pmv[0].y,psad[0], |
|
|
pmv[1].x,pmv[1].y,pmv[2].x,pmv[2].y,pmv[3].x,pmv[3].y, |
|
|
psad[1],psad[2],psad[3]); |
|
|
*/ |
|
1177 |
if ((x == 0) && (y == 0)) { |
if ((x == 0) && (y == 0)) { |
1178 |
threshA = 512; |
threshA = 512; |
1179 |
threshB = 1024; |
threshB = 1024; |
1197 |
If SAD<=256 goto Step 10. |
If SAD<=256 goto Step 10. |
1198 |
*/ |
*/ |
1199 |
|
|
1200 |
*currMV = pmv[0]; /* current best := prediction */ |
currMV->x = start_x; |
1201 |
|
currMV->y = start_y; |
1202 |
|
|
1203 |
if (!(MotionFlags & PMV_HALFPEL16)) { /* This should NOT be necessary! */ |
if (!(MotionFlags & PMV_HALFPEL16)) { /* This should NOT be necessary! */ |
1204 |
currMV->x = EVEN(currMV->x); |
currMV->x = EVEN(currMV->x); |
1205 |
currMV->y = EVEN(currMV->y); |
currMV->y = EVEN(currMV->y); |
1223 |
get_ref_mv(pRef, pRefH, pRefV, pRefHV, x, y, 16, currMV, |
get_ref_mv(pRef, pRefH, pRefV, pRefHV, x, y, 16, currMV, |
1224 |
iEdgedWidth), iEdgedWidth, MV_MAX_ERROR); |
iEdgedWidth), iEdgedWidth, MV_MAX_ERROR); |
1225 |
iMinSAD += |
iMinSAD += |
1226 |
calc_delta_16(currMV->x - pmv[0].x, currMV->y - pmv[0].y, |
calc_delta_16(currMV->x - center_x, currMV->y - center_y, |
1227 |
(uint8_t) iFcode, iQuant); |
(uint8_t) iFcode, iQuant); |
1228 |
|
|
1229 |
if ((iMinSAD < 256) || |
if ((iMinSAD < 256) || |
1230 |
((MVequal(*currMV, prevMB->mvs[0])) && |
((MVequal(*currMV, prevMB->mvs[0])) && |
1231 |
((uint32_t) iMinSAD < prevMB->sad16))) { |
((int32_t) iMinSAD < prevMB->sad16))) { |
1232 |
if (iMinSAD < 2 * iQuant) // high chances for SKIP-mode |
if (iMinSAD < (int)(2 * iQuant)) // high chances for SKIP-mode |
1233 |
{ |
{ |
1234 |
if (!MVzero(*currMV)) { |
if (!MVzero(*currMV)) { |
1235 |
iMinSAD += MV16_00_BIAS; |
iMinSAD += MV16_00_BIAS; |
1332 |
|
|
1333 |
if ((iMinSAD <= threshA) || |
if ((iMinSAD <= threshA) || |
1334 |
(MVequal(*currMV, prevMB->mvs[0]) && |
(MVequal(*currMV, prevMB->mvs[0]) && |
1335 |
((uint32_t) iMinSAD < prevMB->sad16))) { |
((int32_t) iMinSAD < prevMB->sad16))) { |
1336 |
if (MotionFlags & PMV_QUICKSTOP16) |
if (MotionFlags & PMV_QUICKSTOP16) |
1337 |
goto PMVfast16_Terminate_without_Refine; |
goto PMVfast16_Terminate_without_Refine; |
1338 |
if (MotionFlags & PMV_EARLYSTOP16) |
if (MotionFlags & PMV_EARLYSTOP16) |
1360 |
backupMV = *currMV; /* save best prediction, actually only for EXTSEARCH */ |
backupMV = *currMV; /* save best prediction, actually only for EXTSEARCH */ |
1361 |
|
|
1362 |
|
|
|
// fprintf(stderr,"Entering Diamond %d %d (%d):\n",x,y,iMinSAD); |
|
|
|
|
1363 |
/* default: use best prediction as starting point for one call of PMVfast_MainSearch */ |
/* default: use best prediction as starting point for one call of PMVfast_MainSearch */ |
1364 |
iSAD = |
iSAD = |
1365 |
(*MainSearchPtr) (pRef, pRefH, pRefV, pRefHV, cur, x, y, currMV->x, |
(*MainSearchPtr) (pRef, pRefH, pRefV, pRefHV, cur, x, y, |
1366 |
currMV->y, iMinSAD, &newMV, pmv, min_dx, max_dx, |
currMV->x, currMV->y, iMinSAD, &newMV, center_x, center_y, |
1367 |
|
min_dx, max_dx, |
1368 |
min_dy, max_dy, iEdgedWidth, iDiamondSize, iFcode, |
min_dy, max_dy, iEdgedWidth, iDiamondSize, iFcode, |
1369 |
iQuant, iFound); |
iQuant, iFound); |
1370 |
|
|
1379 |
if (!(MVequal(pmv[0], backupMV))) { |
if (!(MVequal(pmv[0], backupMV))) { |
1380 |
iSAD = |
iSAD = |
1381 |
(*MainSearchPtr) (pRef, pRefH, pRefV, pRefHV, cur, x, y, |
(*MainSearchPtr) (pRef, pRefH, pRefV, pRefHV, cur, x, y, |
1382 |
pmv[0].x, pmv[0].y, iMinSAD, &newMV, pmv, |
center_x, center_y, iMinSAD, &newMV, center_x, center_y, |
1383 |
min_dx, max_dx, min_dy, max_dy, iEdgedWidth, |
min_dx, max_dx, min_dy, max_dy, iEdgedWidth, |
1384 |
iDiamondSize, iFcode, iQuant, iFound); |
iDiamondSize, iFcode, iQuant, iFound); |
1385 |
|
|
1392 |
if ((!(MVzero(pmv[0]))) && (!(MVzero(backupMV)))) { |
if ((!(MVzero(pmv[0]))) && (!(MVzero(backupMV)))) { |
1393 |
iSAD = |
iSAD = |
1394 |
(*MainSearchPtr) (pRef, pRefH, pRefV, pRefHV, cur, x, y, 0, 0, |
(*MainSearchPtr) (pRef, pRefH, pRefV, pRefHV, cur, x, y, 0, 0, |
1395 |
iMinSAD, &newMV, pmv, min_dx, max_dx, min_dy, |
iMinSAD, &newMV, center_x, center_y, |
1396 |
max_dy, iEdgedWidth, iDiamondSize, iFcode, |
min_dx, max_dx, min_dy, max_dy, |
1397 |
|
iEdgedWidth, iDiamondSize, iFcode, |
1398 |
iQuant, iFound); |
iQuant, iFound); |
1399 |
|
|
1400 |
if (iSAD < iMinSAD) { |
if (iSAD < iMinSAD) { |
1412 |
if (MotionFlags & PMV_HALFPELREFINE16) // perform final half-pel step |
if (MotionFlags & PMV_HALFPELREFINE16) // perform final half-pel step |
1413 |
iMinSAD = |
iMinSAD = |
1414 |
Halfpel16_Refine(pRef, pRefH, pRefV, pRefHV, cur, x, y, currMV, |
Halfpel16_Refine(pRef, pRefH, pRefV, pRefHV, cur, x, y, currMV, |
1415 |
iMinSAD, pmv, min_dx, max_dx, min_dy, max_dy, |
iMinSAD, center_x, center_y, min_dx, max_dx, min_dy, max_dy, |
1416 |
iFcode, iQuant, iEdgedWidth); |
iFcode, iQuant, iEdgedWidth); |
1417 |
|
|
|
/*fprintf(stderr,"Chosen for %d %d: %d %d - %d %d\n",x,y,currMV->x,currMV->y,pmv[0].x,pmv[0].y); |
|
|
*/ |
|
1418 |
PMVfast16_Terminate_without_Refine: |
PMVfast16_Terminate_without_Refine: |
1419 |
currPMV->x = currMV->x - pmv[0].x; |
currPMV->x = currMV->x - center_x; |
1420 |
currPMV->y = currMV->y - pmv[0].y; |
currPMV->y = currMV->y - center_y; |
1421 |
return iMinSAD; |
return iMinSAD; |
1422 |
} |
} |
1423 |
|
|
1434 |
const uint8_t * const cur, |
const uint8_t * const cur, |
1435 |
const int x, |
const int x, |
1436 |
const int y, |
const int y, |
1437 |
int32_t startx, |
const int32_t start_x, |
1438 |
int32_t starty, |
const int32_t start_y, |
1439 |
int32_t iMinSAD, |
int32_t iMinSAD, |
1440 |
VECTOR * const currMV, |
VECTOR * const currMV, |
1441 |
const VECTOR * const pmv, |
const int center_x, |
1442 |
|
const int center_y, |
1443 |
const int32_t min_dx, |
const int32_t min_dx, |
1444 |
const int32_t max_dx, |
const int32_t max_dx, |
1445 |
const int32_t min_dy, |
const int32_t min_dy, |
1453 |
/* Do a diamond search around given starting point, return SAD of best */ |
/* Do a diamond search around given starting point, return SAD of best */ |
1454 |
|
|
1455 |
int32_t iDirection = 0; |
int32_t iDirection = 0; |
1456 |
|
int32_t iDirectionBackup; |
1457 |
int32_t iSAD; |
int32_t iSAD; |
1458 |
VECTOR backupMV; |
VECTOR backupMV; |
1459 |
|
|
1460 |
backupMV.x = startx; |
backupMV.x = start_x; |
1461 |
backupMV.y = starty; |
backupMV.y = start_y; |
1462 |
|
|
1463 |
/* It's one search with full Diamond pattern, and only 3 of 4 for all following diamonds */ |
/* It's one search with full Diamond pattern, and only 3 of 4 for all following diamonds */ |
1464 |
|
|
1467 |
CHECK_MV8_CANDIDATE_DIR(backupMV.x, backupMV.y - iDiamondSize, 3); |
CHECK_MV8_CANDIDATE_DIR(backupMV.x, backupMV.y - iDiamondSize, 3); |
1468 |
CHECK_MV8_CANDIDATE_DIR(backupMV.x, backupMV.y + iDiamondSize, 4); |
CHECK_MV8_CANDIDATE_DIR(backupMV.x, backupMV.y + iDiamondSize, 4); |
1469 |
|
|
1470 |
if (iDirection) |
if (iDirection) { |
1471 |
while (!iFound) { |
while (!iFound) { |
1472 |
iFound = 1; |
iFound = 1; |
1473 |
backupMV = *currMV; // since iDirection!=0, this is well defined! |
backupMV = *currMV; // since iDirection!=0, this is well defined! |
1474 |
|
iDirectionBackup = iDirection; |
1475 |
|
|
1476 |
if (iDirection != 2) |
if (iDirectionBackup != 2) |
1477 |
CHECK_MV8_CANDIDATE_FOUND(backupMV.x - iDiamondSize, |
CHECK_MV8_CANDIDATE_FOUND(backupMV.x - iDiamondSize, |
1478 |
backupMV.y, 1); |
backupMV.y, 1); |
1479 |
if (iDirection != 1) |
if (iDirectionBackup != 1) |
1480 |
CHECK_MV8_CANDIDATE_FOUND(backupMV.x + iDiamondSize, |
CHECK_MV8_CANDIDATE_FOUND(backupMV.x + iDiamondSize, |
1481 |
backupMV.y, 2); |
backupMV.y, 2); |
1482 |
if (iDirection != 4) |
if (iDirectionBackup != 4) |
1483 |
CHECK_MV8_CANDIDATE_FOUND(backupMV.x, |
CHECK_MV8_CANDIDATE_FOUND(backupMV.x, |
1484 |
backupMV.y - iDiamondSize, 3); |
backupMV.y - iDiamondSize, 3); |
1485 |
if (iDirection != 3) |
if (iDirectionBackup != 3) |
1486 |
CHECK_MV8_CANDIDATE_FOUND(backupMV.x, |
CHECK_MV8_CANDIDATE_FOUND(backupMV.x, |
1487 |
backupMV.y + iDiamondSize, 4); |
backupMV.y + iDiamondSize, 4); |
1488 |
|
} |
1489 |
} else { |
} else { |
1490 |
currMV->x = startx; |
currMV->x = start_x; |
1491 |
currMV->y = starty; |
currMV->y = start_y; |
1492 |
} |
} |
1493 |
return iMinSAD; |
return iMinSAD; |
1494 |
} |
} |
1495 |
|
|
1496 |
|
|
1497 |
|
|
1498 |
|
|
1499 |
int32_t |
int32_t |
1500 |
Halfpel8_Refine(const uint8_t * const pRef, |
Square8_MainSearch(const uint8_t * const pRef, |
1501 |
|
const uint8_t * const pRefH, |
1502 |
|
const uint8_t * const pRefV, |
1503 |
|
const uint8_t * const pRefHV, |
1504 |
|
const uint8_t * const cur, |
1505 |
|
const int x, |
1506 |
|
const int y, |
1507 |
|
const int32_t start_x, |
1508 |
|
const int32_t start_y, |
1509 |
|
int32_t iMinSAD, |
1510 |
|
VECTOR * const currMV, |
1511 |
|
const int center_x, |
1512 |
|
const int center_y, |
1513 |
|
const int32_t min_dx, |
1514 |
|
const int32_t max_dx, |
1515 |
|
const int32_t min_dy, |
1516 |
|
const int32_t max_dy, |
1517 |
|
const int32_t iEdgedWidth, |
1518 |
|
const int32_t iDiamondSize, |
1519 |
|
const int32_t iFcode, |
1520 |
|
const int32_t iQuant, |
1521 |
|
int iFound) |
1522 |
|
{ |
1523 |
|
/* Do a square search around given starting point, return SAD of best */ |
1524 |
|
|
1525 |
|
int32_t iDirection = 0; |
1526 |
|
int32_t iSAD; |
1527 |
|
VECTOR backupMV; |
1528 |
|
|
1529 |
|
backupMV.x = start_x; |
1530 |
|
backupMV.y = start_y; |
1531 |
|
|
1532 |
|
/* It's one search with full square pattern, and new parts for all following diamonds */ |
1533 |
|
|
1534 |
|
/* new direction are extra, so 1-4 is normal diamond |
1535 |
|
537 |
1536 |
|
1*2 |
1537 |
|
648 |
1538 |
|
*/ |
1539 |
|
|
1540 |
|
CHECK_MV8_CANDIDATE_DIR(backupMV.x - iDiamondSize, backupMV.y, 1); |
1541 |
|
CHECK_MV8_CANDIDATE_DIR(backupMV.x + iDiamondSize, backupMV.y, 2); |
1542 |
|
CHECK_MV8_CANDIDATE_DIR(backupMV.x, backupMV.y - iDiamondSize, 3); |
1543 |
|
CHECK_MV8_CANDIDATE_DIR(backupMV.x, backupMV.y + iDiamondSize, 4); |
1544 |
|
|
1545 |
|
CHECK_MV8_CANDIDATE_DIR(backupMV.x - iDiamondSize, |
1546 |
|
backupMV.y - iDiamondSize, 5); |
1547 |
|
CHECK_MV8_CANDIDATE_DIR(backupMV.x - iDiamondSize, |
1548 |
|
backupMV.y + iDiamondSize, 6); |
1549 |
|
CHECK_MV8_CANDIDATE_DIR(backupMV.x + iDiamondSize, |
1550 |
|
backupMV.y - iDiamondSize, 7); |
1551 |
|
CHECK_MV8_CANDIDATE_DIR(backupMV.x + iDiamondSize, |
1552 |
|
backupMV.y + iDiamondSize, 8); |
1553 |
|
|
1554 |
|
|
1555 |
|
if (iDirection) { |
1556 |
|
while (!iFound) { |
1557 |
|
iFound = 1; |
1558 |
|
backupMV = *currMV; |
1559 |
|
|
1560 |
|
switch (iDirection) { |
1561 |
|
case 1: |
1562 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x - iDiamondSize, |
1563 |
|
backupMV.y, 1); |
1564 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x - iDiamondSize, |
1565 |
|
backupMV.y - iDiamondSize, 5); |
1566 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x + iDiamondSize, |
1567 |
|
backupMV.y - iDiamondSize, 7); |
1568 |
|
break; |
1569 |
|
case 2: |
1570 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x + iDiamondSize, backupMV.y, |
1571 |
|
2); |
1572 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x - iDiamondSize, |
1573 |
|
backupMV.y + iDiamondSize, 6); |
1574 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x + iDiamondSize, |
1575 |
|
backupMV.y + iDiamondSize, 8); |
1576 |
|
break; |
1577 |
|
|
1578 |
|
case 3: |
1579 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x, backupMV.y + iDiamondSize, |
1580 |
|
4); |
1581 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x + iDiamondSize, |
1582 |
|
backupMV.y - iDiamondSize, 7); |
1583 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x + iDiamondSize, |
1584 |
|
backupMV.y + iDiamondSize, 8); |
1585 |
|
break; |
1586 |
|
|
1587 |
|
case 4: |
1588 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x, backupMV.y - iDiamondSize, |
1589 |
|
3); |
1590 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x - iDiamondSize, |
1591 |
|
backupMV.y - iDiamondSize, 5); |
1592 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x - iDiamondSize, |
1593 |
|
backupMV.y + iDiamondSize, 6); |
1594 |
|
break; |
1595 |
|
|
1596 |
|
case 5: |
1597 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x - iDiamondSize, backupMV.y, |
1598 |
|
1); |
1599 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x, backupMV.y - iDiamondSize, |
1600 |
|
3); |
1601 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x - iDiamondSize, |
1602 |
|
backupMV.y - iDiamondSize, 5); |
1603 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x - iDiamondSize, |
1604 |
|
backupMV.y + iDiamondSize, 6); |
1605 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x + iDiamondSize, |
1606 |
|
backupMV.y - iDiamondSize, 7); |
1607 |
|
break; |
1608 |
|
|
1609 |
|
case 6: |
1610 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x + iDiamondSize, backupMV.y, |
1611 |
|
2); |
1612 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x, backupMV.y - iDiamondSize, |
1613 |
|
3); |
1614 |
|
|
1615 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x - iDiamondSize, |
1616 |
|
backupMV.y - iDiamondSize, 5); |
1617 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x - iDiamondSize, |
1618 |
|
backupMV.y + iDiamondSize, 6); |
1619 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x + iDiamondSize, |
1620 |
|
backupMV.y + iDiamondSize, 8); |
1621 |
|
|
1622 |
|
break; |
1623 |
|
|
1624 |
|
case 7: |
1625 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x - iDiamondSize, |
1626 |
|
backupMV.y, 1); |
1627 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x, backupMV.y + iDiamondSize, |
1628 |
|
4); |
1629 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x - iDiamondSize, |
1630 |
|
backupMV.y - iDiamondSize, 5); |
1631 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x + iDiamondSize, |
1632 |
|
backupMV.y - iDiamondSize, 7); |
1633 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x + iDiamondSize, |
1634 |
|
backupMV.y + iDiamondSize, 8); |
1635 |
|
break; |
1636 |
|
|
1637 |
|
case 8: |
1638 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x + iDiamondSize, backupMV.y, |
1639 |
|
2); |
1640 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x, backupMV.y + iDiamondSize, |
1641 |
|
4); |
1642 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x - iDiamondSize, |
1643 |
|
backupMV.y + iDiamondSize, 6); |
1644 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x + iDiamondSize, |
1645 |
|
backupMV.y - iDiamondSize, 7); |
1646 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x + iDiamondSize, |
1647 |
|
backupMV.y + iDiamondSize, 8); |
1648 |
|
break; |
1649 |
|
default: |
1650 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x - iDiamondSize, backupMV.y, |
1651 |
|
1); |
1652 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x + iDiamondSize, backupMV.y, |
1653 |
|
2); |
1654 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x, backupMV.y - iDiamondSize, |
1655 |
|
3); |
1656 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x, backupMV.y + iDiamondSize, |
1657 |
|
4); |
1658 |
|
|
1659 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x - iDiamondSize, |
1660 |
|
backupMV.y - iDiamondSize, 5); |
1661 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x - iDiamondSize, |
1662 |
|
backupMV.y + iDiamondSize, 6); |
1663 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x + iDiamondSize, |
1664 |
|
backupMV.y - iDiamondSize, 7); |
1665 |
|
CHECK_MV8_CANDIDATE_FOUND(backupMV.x + iDiamondSize, |
1666 |
|
backupMV.y + iDiamondSize, 8); |
1667 |
|
break; |
1668 |
|
} |
1669 |
|
} |
1670 |
|
} else { |
1671 |
|
currMV->x = start_x; |
1672 |
|
currMV->y = start_y; |
1673 |
|
} |
1674 |
|
return iMinSAD; |
1675 |
|
} |
1676 |
|
|
1677 |
|
|
1678 |
|
|
1679 |
|
|
1680 |
|
|
1681 |
|
int32_t |
1682 |
|
Halfpel8_Refine_c(const uint8_t * const pRef, |
1683 |
const uint8_t * const pRefH, |
const uint8_t * const pRefH, |
1684 |
const uint8_t * const pRefV, |
const uint8_t * const pRefV, |
1685 |
const uint8_t * const pRefHV, |
const uint8_t * const pRefHV, |
1688 |
const int y, |
const int y, |
1689 |
VECTOR * const currMV, |
VECTOR * const currMV, |
1690 |
int32_t iMinSAD, |
int32_t iMinSAD, |
1691 |
const VECTOR * const pmv, |
const int center_x, |
1692 |
|
const int center_y, |
1693 |
const int32_t min_dx, |
const int32_t min_dx, |
1694 |
const int32_t max_dx, |
const int32_t max_dx, |
1695 |
const int32_t min_dy, |
const int32_t min_dy, |
1728 |
const int y, |
const int y, |
1729 |
const int start_x, |
const int start_x, |
1730 |
const int start_y, |
const int start_y, |
1731 |
|
const int center_x, |
1732 |
|
const int center_y, |
1733 |
const uint32_t MotionFlags, |
const uint32_t MotionFlags, |
1734 |
const uint32_t iQuant, |
const uint32_t iQuant, |
1735 |
const uint32_t iFcode, |
const uint32_t iFcode, |
1786 |
} |
} |
1787 |
|
|
1788 |
/* because we might use IF (dx>max_dx) THEN dx=max_dx; */ |
/* because we might use IF (dx>max_dx) THEN dx=max_dx; */ |
1789 |
bPredEq = get_pmvdata(pMBs, (x >> 1), (y >> 1), iWcount, iSubBlock, pmv, psad); |
bPredEq = get_pmvdata2(pMBs, iWcount, 0, (x >> 1), (y >> 1), iSubBlock, pmv, psad); |
|
// bPredEq = get_pmvdata2(pMBs, iWcount, 0, (x >> 1), (y >> 1), iSubBlock, pmv, psad); |
|
1790 |
|
|
1791 |
if ((x == 0) && (y == 0)) { |
if ((x == 0) && (y == 0)) { |
1792 |
threshA = 512 / 4; |
threshA = 512 / 4; |
1793 |
threshB = 1024 / 4; |
threshB = 1024 / 4; |
1794 |
|
|
1795 |
} else { |
} else { |
1796 |
threshA = psad[0] / 4; /* good estimate */ |
threshA = psad[0] / 4; /* good estimate? */ |
1797 |
threshB = threshA + 256 / 4; |
threshB = threshA + 256 / 4; |
1798 |
if (threshA < 512 / 4) |
if (threshA < 512 / 4) |
1799 |
threshA = 512 / 4; |
threshA = 512 / 4; |
1815 |
|
|
1816 |
// Prepare for main loop |
// Prepare for main loop |
1817 |
|
|
1818 |
// if (MotionFlags & PMV_USESQUARES8) |
if (MotionFlags & PMV_USESQUARES8) |
1819 |
// MainSearchPtr = Square8_MainSearch; |
MainSearchPtr = Square8_MainSearch; |
1820 |
// else |
else |
1821 |
|
|
1822 |
if (MotionFlags & PMV_ADVANCEDDIAMOND8) |
if (MotionFlags & PMV_ADVANCEDDIAMOND8) |
1823 |
MainSearchPtr = AdvDiamond8_MainSearch; |
MainSearchPtr = AdvDiamond8_MainSearch; |
1832 |
get_ref_mv(pRef, pRefH, pRefV, pRefHV, x, y, 8, currMV, |
get_ref_mv(pRef, pRefH, pRefV, pRefHV, x, y, 8, currMV, |
1833 |
iEdgedWidth), iEdgedWidth); |
iEdgedWidth), iEdgedWidth); |
1834 |
iMinSAD += |
iMinSAD += |
1835 |
calc_delta_8(currMV->x - pmv[0].x, currMV->y - pmv[0].y, |
calc_delta_8(currMV->x - center_x, currMV->y - center_y, |
1836 |
(uint8_t) iFcode, iQuant); |
(uint8_t) iFcode, iQuant); |
1837 |
|
|
1838 |
if ((iMinSAD < 256 / 4) || ((MVequal(*currMV, prevMB->mvs[iSubBlock])) |
if ((iMinSAD < 256 / 4) || ((MVequal(*currMV, prevMB->mvs[iSubBlock])) |
1839 |
&& ((uint32_t) iMinSAD < |
&& ((int32_t) iMinSAD < |
1840 |
prevMB->sad8[iSubBlock]))) { |
prevMB->sad8[iSubBlock]))) { |
1841 |
if (MotionFlags & PMV_QUICKSTOP16) |
if (MotionFlags & PMV_QUICKSTOP16) |
1842 |
goto PMVfast8_Terminate_without_Refine; |
goto PMVfast8_Terminate_without_Refine; |
1875 |
// the median prediction might be even better than mv16 |
// the median prediction might be even better than mv16 |
1876 |
|
|
1877 |
if (!MVequal(pmv[0], startMV)) |
if (!MVequal(pmv[0], startMV)) |
1878 |
CHECK_MV8_CANDIDATE(pmv[0].x, pmv[0].y); |
CHECK_MV8_CANDIDATE(center_x, center_y); |
1879 |
|
|
1880 |
// (0,0) if needed |
// (0,0) if needed |
1881 |
if (!MVzero(pmv[0])) |
if (!MVzero(pmv[0])) |
1891 |
|
|
1892 |
if ((iMinSAD <= threshA) || |
if ((iMinSAD <= threshA) || |
1893 |
(MVequal(*currMV, prevMB->mvs[iSubBlock]) && |
(MVequal(*currMV, prevMB->mvs[iSubBlock]) && |
1894 |
((uint32_t) iMinSAD < prevMB->sad8[iSubBlock]))) { |
((int32_t) iMinSAD < prevMB->sad8[iSubBlock]))) { |
1895 |
if (MotionFlags & PMV_QUICKSTOP16) |
if (MotionFlags & PMV_QUICKSTOP16) |
1896 |
goto PMVfast8_Terminate_without_Refine; |
goto PMVfast8_Terminate_without_Refine; |
1897 |
if (MotionFlags & PMV_EARLYSTOP16) |
if (MotionFlags & PMV_EARLYSTOP16) |
1950 |
|
|
1951 |
if ((iMinSAD <= threshA) || |
if ((iMinSAD <= threshA) || |
1952 |
(MVequal(*currMV, prevMB->mvs[iSubBlock]) && |
(MVequal(*currMV, prevMB->mvs[iSubBlock]) && |
1953 |
((uint32_t) iMinSAD < prevMB->sad8[iSubBlock]))) { |
((int32_t) iMinSAD < prevMB->sad8[iSubBlock]))) { |
1954 |
if (MotionFlags & PMV_QUICKSTOP16) |
if (MotionFlags & PMV_QUICKSTOP16) |
1955 |
goto PMVfast8_Terminate_without_Refine; |
goto PMVfast8_Terminate_without_Refine; |
1956 |
if (MotionFlags & PMV_EARLYSTOP16) |
if (MotionFlags & PMV_EARLYSTOP16) |
1972 |
/* default: use best prediction as starting point for one call of PMVfast_MainSearch */ |
/* default: use best prediction as starting point for one call of PMVfast_MainSearch */ |
1973 |
iSAD = |
iSAD = |
1974 |
(*MainSearchPtr) (pRef, pRefH, pRefV, pRefHV, cur, x, y, currMV->x, |
(*MainSearchPtr) (pRef, pRefH, pRefV, pRefHV, cur, x, y, currMV->x, |
1975 |
currMV->y, iMinSAD, &newMV, pmv, min_dx, max_dx, |
currMV->y, iMinSAD, &newMV, center_x, center_y, min_dx, max_dx, |
1976 |
min_dy, max_dy, iEdgedWidth, iDiamondSize, iFcode, |
min_dy, max_dy, iEdgedWidth, iDiamondSize, iFcode, |
1977 |
iQuant, iFound); |
iQuant, iFound); |
1978 |
|
|
1987 |
if (!(MVequal(pmv[0], backupMV))) { |
if (!(MVequal(pmv[0], backupMV))) { |
1988 |
iSAD = |
iSAD = |
1989 |
(*MainSearchPtr) (pRef, pRefH, pRefV, pRefHV, cur, x, y, |
(*MainSearchPtr) (pRef, pRefH, pRefV, pRefHV, cur, x, y, |
1990 |
pmv[0].x, pmv[0].y, iMinSAD, &newMV, pmv, |
pmv[0].x, pmv[0].y, iMinSAD, &newMV, center_x, center_y, |
1991 |
min_dx, max_dx, min_dy, max_dy, iEdgedWidth, |
min_dx, max_dx, min_dy, max_dy, iEdgedWidth, |
1992 |
iDiamondSize, iFcode, iQuant, iFound); |
iDiamondSize, iFcode, iQuant, iFound); |
1993 |
|
|
2000 |
if ((!(MVzero(pmv[0]))) && (!(MVzero(backupMV)))) { |
if ((!(MVzero(pmv[0]))) && (!(MVzero(backupMV)))) { |
2001 |
iSAD = |
iSAD = |
2002 |
(*MainSearchPtr) (pRef, pRefH, pRefV, pRefHV, cur, x, y, 0, 0, |
(*MainSearchPtr) (pRef, pRefH, pRefV, pRefHV, cur, x, y, 0, 0, |
2003 |
iMinSAD, &newMV, pmv, min_dx, max_dx, min_dy, |
iMinSAD, &newMV, center_x, center_y, min_dx, max_dx, min_dy, |
2004 |
max_dy, iEdgedWidth, iDiamondSize, iFcode, |
max_dy, iEdgedWidth, iDiamondSize, iFcode, |
2005 |
iQuant, iFound); |
iQuant, iFound); |
2006 |
|
|
2019 |
if (MotionFlags & PMV_HALFPELREFINE8) // perform final half-pel step |
if (MotionFlags & PMV_HALFPELREFINE8) // perform final half-pel step |
2020 |
iMinSAD = |
iMinSAD = |
2021 |
Halfpel8_Refine(pRef, pRefH, pRefV, pRefHV, cur, x, y, currMV, |
Halfpel8_Refine(pRef, pRefH, pRefV, pRefHV, cur, x, y, currMV, |
2022 |
iMinSAD, pmv, min_dx, max_dx, min_dy, max_dy, |
iMinSAD, center_x, center_y, min_dx, max_dx, min_dy, max_dy, |
2023 |
iFcode, iQuant, iEdgedWidth); |
iFcode, iQuant, iEdgedWidth); |
2024 |
|
|
2025 |
|
|
2026 |
PMVfast8_Terminate_without_Refine: |
PMVfast8_Terminate_without_Refine: |
2027 |
currPMV->x = currMV->x - pmv[0].x; |
currPMV->x = currMV->x - center_x; |
2028 |
currPMV->y = currMV->y - pmv[0].y; |
currPMV->y = currMV->y - center_y; |
2029 |
|
|
2030 |
return iMinSAD; |
return iMinSAD; |
2031 |
} |
} |
2038 |
const IMAGE * const pCur, |
const IMAGE * const pCur, |
2039 |
const int x, |
const int x, |
2040 |
const int y, |
const int y, |
2041 |
|
const int start_x, |
2042 |
|
const int start_y, |
2043 |
|
const int center_x, |
2044 |
|
const int center_y, |
2045 |
const uint32_t MotionFlags, |
const uint32_t MotionFlags, |
2046 |
const uint32_t iQuant, |
const uint32_t iQuant, |
2047 |
const uint32_t iFcode, |
const uint32_t iFcode, |
2100 |
max_dy = EVEN(max_dy); |
max_dy = EVEN(max_dy); |
2101 |
} |
} |
2102 |
/* because we might use something like IF (dx>max_dx) THEN dx=max_dx; */ |
/* because we might use something like IF (dx>max_dx) THEN dx=max_dx; */ |
2103 |
bPredEq = get_pmvdata(pMBs, x, y, iWcount, 0, pmv, psad); |
bPredEq = get_pmvdata2(pMBs, iWcount, 0, x, y, 0, pmv, psad); |
|
// bPredEq = get_pmvdata2(pMBs, iWcount, 0, x, y, 0, pmv, psad); |
|
2104 |
|
|
2105 |
/* Step 4: Calculate SAD around the Median prediction. |
/* Step 4: Calculate SAD around the Median prediction. |
2106 |
MinSAD=SAD |
MinSAD=SAD |
2111 |
|
|
2112 |
// Prepare for main loop |
// Prepare for main loop |
2113 |
|
|
2114 |
*currMV = pmv[0]; /* current best := median prediction */ |
currMV->x = start_x; |
2115 |
|
currMV->y = start_y; |
2116 |
|
|
2117 |
if (!(MotionFlags & PMV_HALFPEL16)) { |
if (!(MotionFlags & PMV_HALFPEL16)) { |
2118 |
currMV->x = EVEN(currMV->x); |
currMV->x = EVEN(currMV->x); |
2119 |
currMV->y = EVEN(currMV->y); |
currMV->y = EVEN(currMV->y); |
2135 |
get_ref_mv(pRef, pRefH, pRefV, pRefHV, x, y, 16, currMV, |
get_ref_mv(pRef, pRefH, pRefV, pRefHV, x, y, 16, currMV, |
2136 |
iEdgedWidth), iEdgedWidth, MV_MAX_ERROR); |
iEdgedWidth), iEdgedWidth, MV_MAX_ERROR); |
2137 |
iMinSAD += |
iMinSAD += |
2138 |
calc_delta_16(currMV->x - pmv[0].x, currMV->y - pmv[0].y, |
calc_delta_16(currMV->x - center_x, currMV->y - center_y, |
2139 |
(uint8_t) iFcode, iQuant); |
(uint8_t) iFcode, iQuant); |
2140 |
|
|
2141 |
// thresh1 is fixed to 256 |
// thresh1 is fixed to 256 |
2142 |
if ((iMinSAD < 256) || |
if ((iMinSAD < 256) || |
2143 |
((MVequal(*currMV, prevMB->mvs[0])) && |
((MVequal(*currMV, prevMB->mvs[0])) && |
2144 |
((uint32_t) iMinSAD < prevMB->sad16))) { |
((int32_t) iMinSAD < prevMB->sad16))) { |
2145 |
if (MotionFlags & PMV_QUICKSTOP16) |
if (MotionFlags & PMV_QUICKSTOP16) |
2146 |
goto EPZS16_Terminate_without_Refine; |
goto EPZS16_Terminate_without_Refine; |
2147 |
if (MotionFlags & PMV_EARLYSTOP16) |
if (MotionFlags & PMV_EARLYSTOP16) |
2201 |
|
|
2202 |
if ((iMinSAD <= thresh2) |
if ((iMinSAD <= thresh2) |
2203 |
|| (MVequal(*currMV, prevMB->mvs[0]) && |
|| (MVequal(*currMV, prevMB->mvs[0]) && |
2204 |
((uint32_t) iMinSAD <= prevMB->sad16))) { |
((int32_t) iMinSAD <= prevMB->sad16))) { |
2205 |
if (MotionFlags & PMV_QUICKSTOP16) |
if (MotionFlags & PMV_QUICKSTOP16) |
2206 |
goto EPZS16_Terminate_without_Refine; |
goto EPZS16_Terminate_without_Refine; |
2207 |
if (MotionFlags & PMV_EARLYSTOP16) |
if (MotionFlags & PMV_EARLYSTOP16) |
2259 |
|
|
2260 |
iSAD = |
iSAD = |
2261 |
(*MainSearchPtr) (pRef, pRefH, pRefV, pRefHV, cur, x, y, currMV->x, |
(*MainSearchPtr) (pRef, pRefH, pRefV, pRefHV, cur, x, y, currMV->x, |
2262 |
currMV->y, iMinSAD, &newMV, pmv, min_dx, max_dx, |
currMV->y, iMinSAD, &newMV, center_x, center_y, min_dx, max_dx, |
2263 |
min_dy, max_dy, iEdgedWidth, 2, iFcode, iQuant, 0); |
min_dy, max_dy, iEdgedWidth, 2, iFcode, iQuant, 0); |
2264 |
|
|
2265 |
if (iSAD < iMinSAD) { |
if (iSAD < iMinSAD) { |
2274 |
if (!(MVequal(pmv[0], backupMV))) { |
if (!(MVequal(pmv[0], backupMV))) { |
2275 |
iSAD = |
iSAD = |
2276 |
(*MainSearchPtr) (pRef, pRefH, pRefV, pRefHV, cur, x, y, |
(*MainSearchPtr) (pRef, pRefH, pRefV, pRefHV, cur, x, y, |
2277 |
pmv[0].x, pmv[0].y, iMinSAD, &newMV, pmv, |
pmv[0].x, pmv[0].y, iMinSAD, &newMV, center_x, center_y, |
2278 |
min_dx, max_dx, min_dy, max_dy, iEdgedWidth, |
min_dx, max_dx, min_dy, max_dy, iEdgedWidth, |
2279 |
2, iFcode, iQuant, 0); |
2, iFcode, iQuant, 0); |
2280 |
} |
} |
2287 |
if ((!(MVzero(pmv[0]))) && (!(MVzero(backupMV)))) { |
if ((!(MVzero(pmv[0]))) && (!(MVzero(backupMV)))) { |
2288 |
iSAD = |
iSAD = |
2289 |
(*MainSearchPtr) (pRef, pRefH, pRefV, pRefHV, cur, x, y, 0, 0, |
(*MainSearchPtr) (pRef, pRefH, pRefV, pRefHV, cur, x, y, 0, 0, |
2290 |
iMinSAD, &newMV, pmv, min_dx, max_dx, min_dy, |
iMinSAD, &newMV, center_x, center_y, min_dx, max_dx, min_dy, |
2291 |
max_dy, iEdgedWidth, 2, iFcode, iQuant, 0); |
max_dy, iEdgedWidth, 2, iFcode, iQuant, 0); |
2292 |
|
|
2293 |
if (iSAD < iMinSAD) { |
if (iSAD < iMinSAD) { |
2303 |
if (MotionFlags & PMV_HALFPELREFINE16) // perform final half-pel step |
if (MotionFlags & PMV_HALFPELREFINE16) // perform final half-pel step |
2304 |
iMinSAD = |
iMinSAD = |
2305 |
Halfpel16_Refine(pRef, pRefH, pRefV, pRefHV, cur, x, y, currMV, |
Halfpel16_Refine(pRef, pRefH, pRefV, pRefHV, cur, x, y, currMV, |
2306 |
iMinSAD, pmv, min_dx, max_dx, min_dy, max_dy, |
iMinSAD, center_x, center_y, min_dx, max_dx, min_dy, max_dy, |
2307 |
iFcode, iQuant, iEdgedWidth); |
iFcode, iQuant, iEdgedWidth); |
2308 |
|
|
2309 |
EPZS16_Terminate_without_Refine: |
EPZS16_Terminate_without_Refine: |
2310 |
|
|
2311 |
*oldMB = *prevMB; |
*oldMB = *prevMB; |
2312 |
|
|
2313 |
currPMV->x = currMV->x - pmv[0].x; |
currPMV->x = currMV->x - center_x; |
2314 |
currPMV->y = currMV->y - pmv[0].y; |
currPMV->y = currMV->y - center_y; |
2315 |
return iMinSAD; |
return iMinSAD; |
2316 |
} |
} |
2317 |
|
|
2326 |
const int y, |
const int y, |
2327 |
const int start_x, |
const int start_x, |
2328 |
const int start_y, |
const int start_y, |
2329 |
|
const int center_x, |
2330 |
|
const int center_y, |
2331 |
const uint32_t MotionFlags, |
const uint32_t MotionFlags, |
2332 |
const uint32_t iQuant, |
const uint32_t iQuant, |
2333 |
const uint32_t iFcode, |
const uint32_t iFcode, |
2382 |
max_dy = EVEN(max_dy); |
max_dy = EVEN(max_dy); |
2383 |
} |
} |
2384 |
/* because we might use something like IF (dx>max_dx) THEN dx=max_dx; */ |
/* because we might use something like IF (dx>max_dx) THEN dx=max_dx; */ |
2385 |
bPredEq = get_pmvdata(pMBs, x >> 1, y >> 1, iWcount, iSubBlock, pmv, psad); |
bPredEq = get_pmvdata2(pMBs, iWcount, 0, x >> 1, y >> 1, iSubBlock, pmv, psad); |
|
// bPredEq = get_pmvdata2(pMBs, iWcount, 0, x >> 1, y >> 1, iSubBlock, pmv, psad); |
|
2386 |
|
|
2387 |
|
|
2388 |
/* Step 4: Calculate SAD around the Median prediction. |
/* Step 4: Calculate SAD around the Median prediction. |
2417 |
get_ref_mv(pRef, pRefH, pRefV, pRefHV, x, y, 8, currMV, |
get_ref_mv(pRef, pRefH, pRefV, pRefHV, x, y, 8, currMV, |
2418 |
iEdgedWidth), iEdgedWidth); |
iEdgedWidth), iEdgedWidth); |
2419 |
iMinSAD += |
iMinSAD += |
2420 |
calc_delta_8(currMV->x - pmv[0].x, currMV->y - pmv[0].y, |
calc_delta_8(currMV->x - center_x, currMV->y - center_y, |
2421 |
(uint8_t) iFcode, iQuant); |
(uint8_t) iFcode, iQuant); |
2422 |
|
|
2423 |
|
|
2493 |
|
|
2494 |
// there is no EPZS^2 for inter4v at the moment |
// there is no EPZS^2 for inter4v at the moment |
2495 |
|
|
2496 |
// if (MotionFlags & PMV_USESQUARES8) |
if (MotionFlags & PMV_USESQUARES8) |
2497 |
// MainSearchPtr = Square8_MainSearch; |
MainSearchPtr = Square8_MainSearch; |
2498 |
// else |
else |
2499 |
|
|
2500 |
if (MotionFlags & PMV_ADVANCEDDIAMOND8) |
if (MotionFlags & PMV_ADVANCEDDIAMOND8) |
2501 |
MainSearchPtr = AdvDiamond8_MainSearch; |
MainSearchPtr = AdvDiamond8_MainSearch; |
2504 |
|
|
2505 |
iSAD = |
iSAD = |
2506 |
(*MainSearchPtr) (pRef, pRefH, pRefV, pRefHV, cur, x, y, currMV->x, |
(*MainSearchPtr) (pRef, pRefH, pRefV, pRefHV, cur, x, y, currMV->x, |
2507 |
currMV->y, iMinSAD, &newMV, pmv, min_dx, max_dx, |
currMV->y, iMinSAD, &newMV, center_x, center_y, min_dx, max_dx, |
2508 |
min_dy, max_dy, iEdgedWidth, iDiamondSize, iFcode, |
min_dy, max_dy, iEdgedWidth, iDiamondSize, iFcode, |
2509 |
iQuant, 0); |
iQuant, 0); |
2510 |
|
|
2520 |
if (!(MVequal(pmv[0], backupMV))) { |
if (!(MVequal(pmv[0], backupMV))) { |
2521 |
iSAD = |
iSAD = |
2522 |
(*MainSearchPtr) (pRef, pRefH, pRefV, pRefHV, cur, x, y, |
(*MainSearchPtr) (pRef, pRefH, pRefV, pRefHV, cur, x, y, |
2523 |
pmv[0].x, pmv[0].y, iMinSAD, &newMV, pmv, |
pmv[0].x, pmv[0].y, iMinSAD, &newMV, center_x, center_y, |
2524 |
min_dx, max_dx, min_dy, max_dy, iEdgedWidth, |
min_dx, max_dx, min_dy, max_dy, iEdgedWidth, |
2525 |
iDiamondSize, iFcode, iQuant, 0); |
iDiamondSize, iFcode, iQuant, 0); |
2526 |
|
|
2533 |
if ((!(MVzero(pmv[0]))) && (!(MVzero(backupMV)))) { |
if ((!(MVzero(pmv[0]))) && (!(MVzero(backupMV)))) { |
2534 |
iSAD = |
iSAD = |
2535 |
(*MainSearchPtr) (pRef, pRefH, pRefV, pRefHV, cur, x, y, 0, 0, |
(*MainSearchPtr) (pRef, pRefH, pRefV, pRefHV, cur, x, y, 0, 0, |
2536 |
iMinSAD, &newMV, pmv, min_dx, max_dx, min_dy, |
iMinSAD, &newMV, center_x, center_y, min_dx, max_dx, min_dy, |
2537 |
max_dy, iEdgedWidth, iDiamondSize, iFcode, |
max_dy, iEdgedWidth, iDiamondSize, iFcode, |
2538 |
iQuant, 0); |
iQuant, 0); |
2539 |
|
|
2550 |
if (MotionFlags & PMV_HALFPELREFINE8) // perform final half-pel step |
if (MotionFlags & PMV_HALFPELREFINE8) // perform final half-pel step |
2551 |
iMinSAD = |
iMinSAD = |
2552 |
Halfpel8_Refine(pRef, pRefH, pRefV, pRefHV, cur, x, y, currMV, |
Halfpel8_Refine(pRef, pRefH, pRefV, pRefHV, cur, x, y, currMV, |
2553 |
iMinSAD, pmv, min_dx, max_dx, min_dy, max_dy, |
iMinSAD, center_x, center_y, min_dx, max_dx, min_dy, max_dy, |
2554 |
iFcode, iQuant, iEdgedWidth); |
iFcode, iQuant, iEdgedWidth); |
2555 |
|
|
2556 |
EPZS8_Terminate_without_Refine: |
EPZS8_Terminate_without_Refine: |
2557 |
|
|
2558 |
currPMV->x = currMV->x - pmv[0].x; |
currPMV->x = currMV->x - center_x; |
2559 |
currPMV->y = currMV->y - pmv[0].y; |
currPMV->y = currMV->y - center_y; |
2560 |
return iMinSAD; |
return iMinSAD; |
2561 |
} |
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* *********************************************************** |
|
|
bvop motion estimation |
|
|
// TODO: need to incorporate prediction here (eg. sad += calc_delta_16) |
|
|
***************************************************************/ |
|
|
|
|
|
|
|
|
void |
|
|
MotionEstimationBVOP(MBParam * const pParam, |
|
|
FRAMEINFO * const frame, |
|
|
// forward (past) reference |
|
|
const MACROBLOCK * const f_mbs, |
|
|
const IMAGE * const f_ref, |
|
|
const IMAGE * const f_refH, |
|
|
const IMAGE * const f_refV, |
|
|
const IMAGE * const f_refHV, |
|
|
// backward (future) reference |
|
|
const MACROBLOCK * const b_mbs, |
|
|
const IMAGE * const b_ref, |
|
|
const IMAGE * const b_refH, |
|
|
const IMAGE * const b_refV, |
|
|
const IMAGE * const b_refHV) |
|
|
{ |
|
|
const uint32_t mb_width = pParam->mb_width; |
|
|
const uint32_t mb_height = pParam->mb_height; |
|
|
const int32_t edged_width = pParam->edged_width; |
|
|
|
|
|
uint32_t i, j; |
|
|
|
|
|
int32_t f_sad16; |
|
|
int32_t b_sad16; |
|
|
int32_t i_sad16; |
|
|
int32_t d_sad16; |
|
|
int32_t best_sad; |
|
|
|
|
|
VECTOR pmv_dontcare; |
|
|
|
|
|
// note: i==horizontal, j==vertical |
|
|
for (j = 0; j < mb_height; j++) { |
|
|
for (i = 0; i < mb_width; i++) { |
|
|
MACROBLOCK *mb = &frame->mbs[i + j * mb_width]; |
|
|
const MACROBLOCK *f_mb = &f_mbs[i + j * mb_width]; |
|
|
const MACROBLOCK *b_mb = &b_mbs[i + j * mb_width]; |
|
|
|
|
|
if (b_mb->mode == MODE_INTER && b_mb->cbp == 0 && |
|
|
b_mb->mvs[0].x == 0 && b_mb->mvs[0].y == 0) { |
|
|
mb->mode = MODE_NOT_CODED; |
|
|
mb->mvs[0].x = 0; |
|
|
mb->mvs[0].y = 0; |
|
|
mb->b_mvs[0].x = 0; |
|
|
mb->b_mvs[0].y = 0; |
|
|
continue; |
|
|
} |
|
|
/* force F_SAD16 |
|
|
f_sad16 = 100; |
|
|
b_sad16 = 65535; |
|
|
|
|
|
mb->mode = MODE_FORWARD; |
|
|
mb->mvs[0].x = 1; |
|
|
mb->mvs[0].y = 1; |
|
|
mb->b_mvs[0].x = 1; |
|
|
mb->b_mvs[0].y = 1; |
|
|
continue; |
|
|
^^ force F_SAD16 */ |
|
|
|
|
|
|
|
|
// forward search |
|
|
f_sad16 = |
|
|
SEARCH16(f_ref->y, f_refH->y, f_refV->y, f_refHV->y, |
|
|
&frame->image, i, j, frame->motion_flags, |
|
|
frame->quant, frame->fcode, pParam, |
|
|
f_mbs, f_mbs, /* todo */ |
|
|
&mb->mvs[0], &pmv_dontcare); // ignore pmv |
|
|
|
|
|
// backward search |
|
|
b_sad16 = SEARCH16(b_ref->y, b_refH->y, b_refV->y, b_refHV->y, |
|
|
&frame->image, i, j, frame->motion_flags, |
|
|
frame->quant, frame->bcode, pParam, |
|
|
b_mbs, b_mbs, /* todo */ |
|
|
&mb->b_mvs[0], &pmv_dontcare); // ignore pmv |
|
|
|
|
|
// interpolate search (simple, but effective) |
|
|
i_sad16 = 65535; |
|
|
|
|
|
/* |
|
|
x/y range somewhat buggy |
|
|
i_sad16 = |
|
|
sad16bi_c(frame->image.y + i * 16 + j * 16 * edged_width, |
|
|
get_ref(f_ref->y, f_refH->y, f_refV->y, f_refHV->y, |
|
|
i, j, 16, mb->mvs[0].x, mb->mvs[0].y, |
|
|
edged_width), get_ref(b_ref->y, b_refH->y, |
|
|
b_refV->y, b_refHV->y, |
|
|
i, j, 16, |
|
|
mb->b_mvs[0].x, |
|
|
mb->b_mvs[0].x, |
|
|
edged_width), |
|
|
edged_width); |
|
|
*/ |
|
|
|
|
|
// TODO: direct search |
|
|
// predictor + range of [-32,32] |
|
|
d_sad16 = 65535; |
|
|
|
|
|
|
|
|
if (f_sad16 < b_sad16) { |
|
|
best_sad = f_sad16; |
|
|
mb->mode = MODE_FORWARD; |
|
|
} else { |
|
|
best_sad = b_sad16; |
|
|
mb->mode = MODE_BACKWARD; |
|
|
} |
|
|
|
|
|
if (i_sad16 < best_sad) { |
|
|
best_sad = i_sad16; |
|
|
mb->mode = MODE_INTERPOLATE; |
|
|
} |
|
|
|
|
|
if (d_sad16 < best_sad) { |
|
|
best_sad = d_sad16; |
|
|
mb->mode = MODE_DIRECT; |
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|