54 |
#define MV16_THRESHOLD 192 |
#define MV16_THRESHOLD 192 |
55 |
#define MV8_THRESHOLD 56 |
#define MV8_THRESHOLD 56 |
56 |
|
|
57 |
|
#define NEIGH_MOVE_THRESH 0 |
58 |
|
// how much a block's MV must differ from his neighbour |
59 |
|
// to be search for INTER4V. The more, the faster... |
60 |
|
|
61 |
/* sad16(0,0) bias; mpeg4 spec suggests nb/2+1 */ |
/* sad16(0,0) bias; mpeg4 spec suggests nb/2+1 */ |
62 |
/* nb = vop pixels * 2^(bpp-8) */ |
/* nb = vop pixels * 2^(bpp-8) */ |
63 |
#define MV16_00_BIAS (128+1) |
#define MV16_00_BIAS (128+1) |
299 |
pMB->sad16 = SEARCH16(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent, |
pMB->sad16 = SEARCH16(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent, |
300 |
x, y, current->motion_flags, current->quant, current->fcode, |
x, y, current->motion_flags, current->quant, current->fcode, |
301 |
pParam, pMBs, prevMBs, &pMB->mv16, &pMB->pmvs[0]); |
pParam, pMBs, prevMBs, &pMB->mv16, &pMB->pmvs[0]); |
|
} |
|
302 |
|
|
|
for (y = 0; y < iHcount; y++) |
|
|
for (x = 0; x < iWcount; x++) |
|
|
{ |
|
|
MACROBLOCK* const pMB = &pMBs[x + y * iWcount]; |
|
303 |
|
|
304 |
if (0 < (pMB->sad16 - MV16_INTER_BIAS)) |
if (0 < (pMB->sad16 - MV16_INTER_BIAS)) |
305 |
{ |
{ |
322 |
continue; |
continue; |
323 |
} |
} |
324 |
} |
} |
325 |
|
pMB->mode = MODE_INTER; |
326 |
|
pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->mv16; |
327 |
|
pMB->sad8[0] = pMB->sad8[1] = pMB->sad8[2] = pMB->sad8[3] = pMB->sad16; |
328 |
|
} |
329 |
|
|
330 |
if ( (current->global_flags & XVID_INTER4V) |
// we try to do as few INTER4V-searches as possible. So we split ME in two parts, normal |
331 |
&& (!(current->global_flags & XVID_LUMIMASKING) |
// SEARCH16 and only for special blocks SEARCH8. May this should be modified for quality |
332 |
|| pMB->dquant == NO_CHANGE) ) |
// levels. |
333 |
|
|
334 |
|
|
335 |
|
|
336 |
|
if (current->global_flags & XVID_INTER4V) |
337 |
|
for (y = 0; y < iHcount; y++) |
338 |
|
for (x = 0; x < iWcount; x++) |
339 |
{ |
{ |
340 |
int32_t sad8 = 129; //IMV16X16 * current->quant; |
MACROBLOCK* const pMB = &pMBs[x + y * iWcount]; |
341 |
|
|
342 |
|
if (pMB->mode == MODE_INTRA) |
343 |
|
continue; |
344 |
|
|
345 |
|
|
346 |
|
if ( (!(current->global_flags & XVID_LUMIMASKING) || pMB->dquant == NO_CHANGE) ) |
347 |
|
{ |
348 |
|
int32_t neigh=0; |
349 |
|
|
350 |
|
if (x>0) |
351 |
|
{ neigh += abs((pMB->mv16.x)-((pMB-1)->mv16.x)); |
352 |
|
neigh += abs((pMB->mv16.y)-((pMB-1)->mv16.y)); |
353 |
|
} |
354 |
|
if (y>0) |
355 |
|
{ neigh += abs((pMB->mv16.x)-((pMB-iWcount)->mv16.x)); |
356 |
|
neigh += abs((pMB->mv16.y)-((pMB-iWcount)->mv16.y)); |
357 |
|
} |
358 |
|
if (x<(iWcount-1)) |
359 |
|
{ neigh += abs((pMB->mv16.x)-((pMB+1)->mv16.x)); |
360 |
|
neigh += abs((pMB->mv16.y)-((pMB+1)->mv16.y)); |
361 |
|
} |
362 |
|
if (y<(iHcount-1)) |
363 |
|
{ neigh += abs((pMB->mv16.x)-((pMB+iHcount)->mv16.x)); |
364 |
|
neigh += abs((pMB->mv16.y)-((pMB+iHcount)->mv16.y)); |
365 |
|
} |
366 |
|
|
367 |
|
if (neigh > NEIGH_MOVE_THRESH) |
368 |
|
{ |
369 |
|
int32_t sad8 = IMV16X16 * current->quant; |
370 |
|
|
371 |
if (sad8 < pMB->sad16) |
if (sad8 < pMB->sad16) |
372 |
sad8 += pMB->sad8[0] |
sad8 += pMB->sad8[0] |
409 |
pMB->sad8[3] *= 4; |
pMB->sad8[3] *= 4; |
410 |
continue; |
continue; |
411 |
} |
} |
|
} |
|
412 |
|
|
|
pMB->mode = MODE_INTER; |
|
413 |
pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->mv16; |
pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->mv16; |
414 |
pMB->sad8[0] = pMB->sad8[1] = pMB->sad8[2] = pMB->sad8[3] = pMB->sad16; |
} |
415 |
|
|
416 |
if (current->global_flags & XVID_INTER4V) |
} |
|
{ pmv = get_pmv(pMBs, x, y, pParam->mb_width, 0); |
|
|
// get_pmv has to be called again. inter4v changes predictors |
|
417 |
|
|
418 |
pMB->pmvs[0].x = pMB->mv16.x - pmv.x; |
// get_pmv has to be called again, because inter4v changes predictors |
419 |
|
|
420 |
|
pmv = get_pmv(pMBs, x, y, pParam->mb_width, 0); |
421 |
|
pMB->pmvs[0].x = pMB->mv16.x - pmv.x; /* the other pmvs are only needed in INTER4V-mode */ |
422 |
pMB->pmvs[0].y = pMB->mv16.y - pmv.y; |
pMB->pmvs[0].y = pMB->mv16.y - pmv.y; |
423 |
|
|
424 |
} |
} |
425 |
} |
|
426 |
return 0; |
return 0; |
427 |
} |
} |
428 |
|
|