57 |
d_mv_bits(int x, int y, const VECTOR pred, const uint32_t iFcode, const int qpel, const int rrv) |
d_mv_bits(int x, int y, const VECTOR pred, const uint32_t iFcode, const int qpel, const int rrv) |
58 |
{ |
{ |
59 |
int xb, yb; |
int xb, yb; |
60 |
x += x * qpel; y += y * qpel; |
x = qpel ? x<<1 : x; |
61 |
|
y = qpel ? y<<1 : y; |
62 |
if (rrv) { x = RRV_MV_SCALEDOWN(x); y = RRV_MV_SCALEDOWN(y); } |
if (rrv) { x = RRV_MV_SCALEDOWN(x); y = RRV_MV_SCALEDOWN(y); } |
63 |
|
|
64 |
x -= pred.x; |
x -= pred.x; |
65 |
y -= pred.y; |
y -= pred.y; |
66 |
|
|
204 |
{ |
{ |
205 |
switch ( ((x&1)<<1) | (y&1) ) { |
switch ( ((x&1)<<1) | (y&1) ) { |
206 |
case 0 : return data->Ref + x/2 + (y/2)*(data->iEdgedWidth); |
case 0 : return data->Ref + x/2 + (y/2)*(data->iEdgedWidth); |
207 |
|
case 3 : return data->RefHV + (x-1)/2 + ((y-1)/2)*(data->iEdgedWidth); |
208 |
case 1 : return data->RefV + x/2 + ((y-1)/2)*(data->iEdgedWidth); |
case 1 : return data->RefV + x/2 + ((y-1)/2)*(data->iEdgedWidth); |
209 |
case 2 : return data->RefH + (x-1)/2 + (y/2)*(data->iEdgedWidth); |
default : return data->RefH + (x-1)/2 + (y/2)*(data->iEdgedWidth); //case 2 |
|
default : return data->RefHV + (x-1)/2 + ((y-1)/2)*(data->iEdgedWidth); |
|
210 |
} |
} |
211 |
} |
} |
212 |
|
|
267 |
|
|
268 |
ref1 = GetReferenceB(halfpel_x, halfpel_y, dir, data); |
ref1 = GetReferenceB(halfpel_x, halfpel_y, dir, data); |
269 |
switch( ((x&1)<<1) + (y&1) ) { |
switch( ((x&1)<<1) + (y&1) ) { |
270 |
case 0: // pure halfpel position |
case 3: // x and y in qpel resolution - the "corners" (top left/right and |
271 |
return (uint8_t *) ref1; |
// bottom left/right) during qpel refinement |
272 |
|
ref2 = GetReferenceB(halfpel_x, y - halfpel_y, dir, data); |
273 |
|
ref3 = GetReferenceB(x - halfpel_x, halfpel_y, dir, data); |
274 |
|
ref4 = GetReferenceB(x - halfpel_x, y - halfpel_y, dir, data); |
275 |
|
interpolate8x8_avg4(Reference, ref1, ref2, ref3, ref4, iEdgedWidth, rounding); |
276 |
|
interpolate8x8_avg4(Reference+8, ref1+8, ref2+8, ref3+8, ref4+8, iEdgedWidth, rounding); |
277 |
|
interpolate8x8_avg4(Reference+8*iEdgedWidth, ref1+8*iEdgedWidth, ref2+8*iEdgedWidth, ref3+8*iEdgedWidth, ref4+8*iEdgedWidth, iEdgedWidth, rounding); |
278 |
|
interpolate8x8_avg4(Reference+8*iEdgedWidth+8, ref1+8*iEdgedWidth+8, ref2+8*iEdgedWidth+8, ref3+8*iEdgedWidth+8, ref4+8*iEdgedWidth+8, iEdgedWidth, rounding); |
279 |
|
break; |
280 |
|
|
281 |
case 1: // x halfpel, y qpel - top or bottom during qpel refinement |
case 1: // x halfpel, y qpel - top or bottom during qpel refinement |
282 |
ref2 = GetReferenceB(halfpel_x, y - halfpel_y, dir, data); |
ref2 = GetReferenceB(halfpel_x, y - halfpel_y, dir, data); |
283 |
interpolate8x8_avg2(Reference, ref1, ref2, iEdgedWidth, rounding, 8); |
interpolate8x8_avg2(Reference, ref1, ref2, iEdgedWidth, rounding, 8); |
294 |
interpolate8x8_avg2(Reference+8*iEdgedWidth+8, ref1+8*iEdgedWidth+8, ref2+8*iEdgedWidth+8, iEdgedWidth, rounding, 8); |
interpolate8x8_avg2(Reference+8*iEdgedWidth+8, ref1+8*iEdgedWidth+8, ref2+8*iEdgedWidth+8, iEdgedWidth, rounding, 8); |
295 |
break; |
break; |
296 |
|
|
297 |
default: // x and y in qpel resolution - the "corners" (top left/right and |
case 0: // pure halfpel position |
298 |
// bottom left/right) during qpel refinement |
return (uint8_t *) ref1; |
|
ref2 = GetReferenceB(halfpel_x, y - halfpel_y, dir, data); |
|
|
ref3 = GetReferenceB(x - halfpel_x, halfpel_y, dir, data); |
|
|
ref4 = GetReferenceB(x - halfpel_x, y - halfpel_y, dir, data); |
|
|
interpolate8x8_avg4(Reference, ref1, ref2, ref3, ref4, iEdgedWidth, rounding); |
|
|
interpolate8x8_avg4(Reference+8, ref1+8, ref2+8, ref3+8, ref4+8, iEdgedWidth, rounding); |
|
|
interpolate8x8_avg4(Reference+8*iEdgedWidth, ref1+8*iEdgedWidth, ref2+8*iEdgedWidth, ref3+8*iEdgedWidth, ref4+8*iEdgedWidth, iEdgedWidth, rounding); |
|
|
interpolate8x8_avg4(Reference+8*iEdgedWidth+8, ref1+8*iEdgedWidth+8, ref2+8*iEdgedWidth+8, ref3+8*iEdgedWidth+8, ref4+8*iEdgedWidth+8, iEdgedWidth, rounding); |
|
|
break; |
|
299 |
} |
} |
300 |
return Reference; |
return Reference; |
301 |
} |
} |
305 |
static void |
static void |
306 |
CheckCandidate16(const int x, const int y, const int Direction, int * const dir, const SearchData * const data) |
CheckCandidate16(const int x, const int y, const int Direction, int * const dir, const SearchData * const data) |
307 |
{ |
{ |
308 |
int t, xc, yc; |
int xc, yc; |
309 |
const uint8_t * Reference; |
const uint8_t * Reference; |
310 |
VECTOR * current; |
VECTOR * current; |
311 |
|
int32_t sad; uint32_t t; |
312 |
|
|
313 |
if ( (x > data->max_dx) | (x < data->min_dx) |
if ( (x > data->max_dx) || (x < data->min_dx) |
314 |
| (y > data->max_dy) | (y < data->min_dy) ) return; |
|| (y > data->max_dy) || (y < data->min_dy) ) return; |
315 |
|
|
316 |
if (data->qpel_precision) { // x and y are in 1/4 precision |
if (!data->qpel_precision) { |
|
Reference = Interpolate16x16qpel(x, y, 0, data); |
|
|
xc = x/2; yc = y/2; //for chroma sad |
|
|
current = data->currentQMV; |
|
|
} else { |
|
317 |
Reference = GetReference(x, y, data); |
Reference = GetReference(x, y, data); |
318 |
current = data->currentMV; |
current = data->currentMV; |
319 |
xc = x; yc = y; |
xc = x; yc = y; |
320 |
|
} else { // x and y are in 1/4 precision |
321 |
|
Reference = Interpolate16x16qpel(x, y, 0, data); |
322 |
|
xc = x/2; yc = y/2; //for chroma sad |
323 |
|
current = data->currentQMV; |
324 |
} |
} |
|
t = d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0); |
|
325 |
|
|
326 |
data->temp[0] = sad16v(data->Cur, Reference, data->iEdgedWidth, data->temp + 1); |
sad = sad16v(data->Cur, Reference, data->iEdgedWidth, data->temp + 1); |
327 |
|
t = d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0); |
328 |
|
|
329 |
data->temp[0] += (data->lambda16 * t * data->temp[0])>>10; |
sad += (data->lambda16 * t * sad)>>10; |
330 |
data->temp[1] += (data->lambda8 * t * (data->temp[1] + NEIGH_8X8_BIAS))>>10; |
data->temp[1] += (data->lambda8 * t * (data->temp[1] + NEIGH_8X8_BIAS))>>10; |
331 |
|
|
332 |
if (data->chroma) data->temp[0] += ChromaSAD((xc >> 1) + roundtab_79[xc & 0x3], |
if (data->chroma) sad += ChromaSAD((xc >> 1) + roundtab_79[xc & 0x3], |
333 |
(yc >> 1) + roundtab_79[yc & 0x3], data); |
(yc >> 1) + roundtab_79[yc & 0x3], data); |
334 |
|
|
335 |
if (data->temp[0] < data->iMinSAD[0]) { |
if (sad < data->iMinSAD[0]) { |
336 |
data->iMinSAD[0] = data->temp[0]; |
data->iMinSAD[0] = sad; |
337 |
current[0].x = x; current[0].y = y; |
current[0].x = x; current[0].y = y; |
338 |
*dir = Direction; } |
*dir = Direction; |
339 |
|
} |
340 |
|
|
341 |
if (data->temp[1] < data->iMinSAD[1]) { |
if (data->temp[1] < data->iMinSAD[1]) { |
342 |
data->iMinSAD[1] = data->temp[1]; current[1].x = x; current[1].y= y; } |
data->iMinSAD[1] = data->temp[1]; current[1].x = x; current[1].y= y; } |
350 |
} |
} |
351 |
|
|
352 |
static void |
static void |
353 |
|
CheckCandidate8(const int x, const int y, const int Direction, int * const dir, const SearchData * const data) |
354 |
|
{ |
355 |
|
int32_t sad; uint32_t t; |
356 |
|
const uint8_t * Reference; |
357 |
|
|
358 |
|
if ( (x > data->max_dx) || (x < data->min_dx) |
359 |
|
|| (y > data->max_dy) || (y < data->min_dy) ) return; |
360 |
|
|
361 |
|
if (!data->qpel_precision) Reference = GetReference(x, y, data); |
362 |
|
else Reference = Interpolate16x16qpel(x, y, 0, data); |
363 |
|
|
364 |
|
sad = sad8(data->Cur, Reference, data->iEdgedWidth); |
365 |
|
t = d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0); |
366 |
|
|
367 |
|
sad += (data->lambda8 * t * (sad+NEIGH_8X8_BIAS))>>10; |
368 |
|
|
369 |
|
if (sad < *(data->iMinSAD)) { |
370 |
|
*(data->iMinSAD) = sad; |
371 |
|
data->currentMV->x = x; data->currentMV->y = y; |
372 |
|
*dir = Direction; |
373 |
|
} |
374 |
|
} |
375 |
|
|
376 |
|
|
377 |
|
static void |
378 |
CheckCandidate32(const int x, const int y, const int Direction, int * const dir, const SearchData * const data) |
CheckCandidate32(const int x, const int y, const int Direction, int * const dir, const SearchData * const data) |
379 |
{ |
{ |
380 |
uint32_t t; |
uint32_t t; |
381 |
const uint8_t * Reference; |
const uint8_t * Reference; |
382 |
|
|
383 |
if ( (!(x&1) && x !=0) | (!(y&1) && y !=0) || //non-zero integer value |
if ( (!(x&1) && x !=0) || (!(y&1) && y !=0) || //non-zero integer value |
384 |
(x > data->max_dx) | (x < data->min_dx) |
(x > data->max_dx) || (x < data->min_dx) |
385 |
| (y > data->max_dy) | (y < data->min_dy) ) return; |
|| (y > data->max_dy) || (y < data->min_dy) ) return; |
386 |
|
|
387 |
Reference = GetReference(x, y, data); |
Reference = GetReference(x, y, data); |
388 |
t = d_mv_bits(x, y, data->predMV, data->iFcode, 0, 1); |
t = d_mv_bits(x, y, data->predMV, data->iFcode, 0, 1); |
450 |
CheckCandidate32I(const int x, const int y, const int Direction, int * const dir, const SearchData * const data) |
CheckCandidate32I(const int x, const int y, const int Direction, int * const dir, const SearchData * const data) |
451 |
{ |
{ |
452 |
// maximum speed - for P/B/I decision |
// maximum speed - for P/B/I decision |
453 |
|
int32_t sad; |
454 |
|
|
455 |
if ( (x > data->max_dx) | (x < data->min_dx) |
if ( (x > data->max_dx) || (x < data->min_dx) |
456 |
| (y > data->max_dy) | (y < data->min_dy) ) return; |
|| (y > data->max_dy) || (y < data->min_dy) ) return; |
457 |
|
|
458 |
data->temp[0] = sad32v_c(data->Cur, data->Ref + x/2 + (y/2)*(data->iEdgedWidth), |
sad = sad32v_c(data->Cur, data->Ref + x/2 + (y/2)*(data->iEdgedWidth), |
459 |
data->iEdgedWidth, data->temp+1); |
data->iEdgedWidth, data->temp+1); |
460 |
|
|
461 |
if (data->temp[0] < *(data->iMinSAD)) { |
if (sad < *(data->iMinSAD)) { |
462 |
*(data->iMinSAD) = data->temp[0]; |
*(data->iMinSAD) = sad; |
463 |
data->currentMV[0].x = x; data->currentMV[0].y = y; |
data->currentMV[0].x = x; data->currentMV[0].y = y; |
464 |
*dir = Direction; } |
*dir = Direction; |
465 |
|
} |
466 |
if (data->temp[1] < data->iMinSAD[1]) { |
if (data->temp[1] < data->iMinSAD[1]) { |
467 |
data->iMinSAD[1] = data->temp[1]; data->currentMV[1].x = x; data->currentMV[1].y = y; } |
data->iMinSAD[1] = data->temp[1]; data->currentMV[1].x = x; data->currentMV[1].y = y; } |
468 |
if (data->temp[2] < data->iMinSAD[2]) { |
if (data->temp[2] < data->iMinSAD[2]) { |
630 |
} |
} |
631 |
} |
} |
632 |
|
|
|
static void |
|
|
CheckCandidate8(const int x, const int y, const int Direction, int * const dir, const SearchData * const data) |
|
|
{ |
|
|
int32_t sad; uint32_t t; |
|
|
const uint8_t * Reference; |
|
|
|
|
|
if ( (x > data->max_dx) | (x < data->min_dx) |
|
|
| (y > data->max_dy) | (y < data->min_dy) ) return; |
|
|
|
|
|
if (data->qpel) Reference = Interpolate16x16qpel(x, y, 0, data); |
|
|
else Reference = GetReference(x, y, data); |
|
|
|
|
|
sad = sad8(data->Cur, Reference, data->iEdgedWidth); |
|
|
t = d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0); |
|
|
|
|
|
sad += (data->lambda8 * t * (sad+NEIGH_8X8_BIAS))>>10; |
|
|
|
|
|
if (sad < *(data->iMinSAD)) { |
|
|
*(data->iMinSAD) = sad; |
|
|
data->currentMV->x = x; data->currentMV->y = y; |
|
|
*dir = Direction; } |
|
|
} |
|
|
|
|
633 |
/* CHECK_CANDIATE FUNCTIONS END */ |
/* CHECK_CANDIATE FUNCTIONS END */ |
634 |
|
|
635 |
/* MAINSEARCH FUNCTIONS START */ |
/* MAINSEARCH FUNCTIONS START */ |