21 |
* along with this program ; if not, write to the Free Software |
* along with this program ; if not, write to the Free Software |
22 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 |
* |
* |
24 |
* $Id: estimation_bvop.c,v 1.2 2004-03-22 22:36:24 edgomez Exp $ |
* $Id: estimation_bvop.c,v 1.5 2004-05-26 09:15:02 edgomez Exp $ |
25 |
* |
* |
26 |
****************************************************************************/ |
****************************************************************************/ |
27 |
|
|
46 |
int sad; |
int sad; |
47 |
const uint32_t stride = data->iEdgedWidth/2; |
const uint32_t stride = data->iEdgedWidth/2; |
48 |
uint8_t *f_refu, *f_refv, *b_refu, *b_refv; |
uint8_t *f_refu, *f_refv, *b_refu, *b_refv; |
49 |
|
int offset, filter; |
50 |
|
|
51 |
const INTERPOLATE8X8_PTR interpolate8x8_halfpel[] = { |
const INTERPOLATE8X8_PTR interpolate8x8_halfpel[] = { |
52 |
NULL, |
NULL, |
55 |
interpolate8x8_halfpel_hv |
interpolate8x8_halfpel_hv |
56 |
}; |
}; |
57 |
|
|
58 |
int offset = (fx>>1) + (fy>>1)*stride; |
if (data->chromaX == fx && data->chromaY == fy && |
59 |
int filter = ((fx & 1) << 1) | (fy & 1); |
data->b_chromaX == bx && data->b_chromaY == by) |
60 |
|
return data->chromaSAD; |
61 |
|
|
62 |
|
offset = (fx>>1) + (fy>>1)*stride; |
63 |
|
filter = ((fx & 1) << 1) | (fy & 1); |
64 |
|
|
65 |
if (filter != 0) { |
if (filter != 0) { |
66 |
f_refu = data->RefQ; |
f_refu = data->RefQ; |
67 |
f_refv = data->RefQ + 8; |
f_refv = data->RefQ + 8; |
68 |
|
if (data->chromaX != fx || data->chromaY != fy) { |
69 |
interpolate8x8_halfpel[filter](f_refu, data->RefP[4] + offset, stride, data->rounding); |
interpolate8x8_halfpel[filter](f_refu, data->RefP[4] + offset, stride, data->rounding); |
70 |
interpolate8x8_halfpel[filter](f_refv, data->RefP[5] + offset, stride, data->rounding); |
interpolate8x8_halfpel[filter](f_refv, data->RefP[5] + offset, stride, data->rounding); |
71 |
|
} |
72 |
} else { |
} else { |
73 |
f_refu = (uint8_t*)data->RefP[4] + offset; |
f_refu = (uint8_t*)data->RefP[4] + offset; |
74 |
f_refv = (uint8_t*)data->RefP[5] + offset; |
f_refv = (uint8_t*)data->RefP[5] + offset; |
75 |
} |
} |
76 |
|
data->chromaX = fx; data->chromaY = fy; |
77 |
|
|
78 |
offset = (bx>>1) + (by>>1)*stride; |
offset = (bx>>1) + (by>>1)*stride; |
79 |
filter = ((bx & 1) << 1) | (by & 1); |
filter = ((bx & 1) << 1) | (by & 1); |
81 |
if (filter != 0) { |
if (filter != 0) { |
82 |
b_refu = data->RefQ + 16; |
b_refu = data->RefQ + 16; |
83 |
b_refv = data->RefQ + 24; |
b_refv = data->RefQ + 24; |
84 |
|
if (data->b_chromaX != bx || data->b_chromaY != by) { |
85 |
interpolate8x8_halfpel[filter](b_refu, data->b_RefP[4] + offset, stride, data->rounding); |
interpolate8x8_halfpel[filter](b_refu, data->b_RefP[4] + offset, stride, data->rounding); |
86 |
interpolate8x8_halfpel[filter](b_refv, data->b_RefP[5] + offset, stride, data->rounding); |
interpolate8x8_halfpel[filter](b_refv, data->b_RefP[5] + offset, stride, data->rounding); |
87 |
|
} |
88 |
} else { |
} else { |
89 |
b_refu = (uint8_t*)data->b_RefP[4] + offset; |
b_refu = (uint8_t*)data->b_RefP[4] + offset; |
90 |
b_refv = (uint8_t*)data->b_RefP[5] + offset; |
b_refv = (uint8_t*)data->b_RefP[5] + offset; |
91 |
} |
} |
92 |
|
data->b_chromaX = bx; data->b_chromaY = by; |
93 |
|
|
94 |
sad = sad8bi(data->CurU, b_refu, f_refu, stride); |
sad = sad8bi(data->CurU, b_refu, f_refu, stride); |
95 |
sad += sad8bi(data->CurV, b_refv, f_refv, stride); |
sad += sad8bi(data->CurV, b_refv, f_refv, stride); |
96 |
|
|
97 |
|
data->chromaSAD = sad; |
98 |
return sad; |
return sad; |
99 |
} |
} |
100 |
|
|
157 |
} |
} |
158 |
|
|
159 |
static void |
static void |
|
CheckCandidateInt_qpel(const int x, const int y, SearchData * const data, const unsigned int Direction) |
|
|
{ |
|
|
int32_t sad, xf, yf, xb, yb, xcf, ycf, xcb, ycb; |
|
|
uint32_t t; |
|
|
|
|
|
const uint8_t *ReferenceF, *ReferenceB; |
|
|
VECTOR *current; |
|
|
|
|
|
if ((x > data->max_dx) || (x < data->min_dx) || |
|
|
(y > data->max_dy) || (y < data->min_dy)) |
|
|
return; |
|
|
|
|
|
if (Direction == 1) { /* x and y mean forward vector */ |
|
|
VECTOR backward = data->qpel_precision ? data->currentQMV[1] : data->currentMV[1]; |
|
|
xb = backward.x; |
|
|
yb = backward.y; |
|
|
xf = x; yf = y; |
|
|
} else { /* x and y mean backward vector */ |
|
|
VECTOR forward = data->qpel_precision ? data->currentQMV[0] : data->currentMV[0]; |
|
|
xf = forward.x; |
|
|
yf = forward.y; |
|
|
xb = x; yb = y; |
|
|
} |
|
|
|
|
|
ReferenceF = xvid_me_interpolate16x16qpel(xf, yf, 0, data); |
|
|
current = data->currentQMV + Direction - 1; |
|
|
ReferenceB = xvid_me_interpolate16x16qpel(xb, yb, 1, data); |
|
|
xcf = xf/2; ycf = yf/2; |
|
|
xcb = xb/2; ycb = yb/2; |
|
|
|
|
|
t = d_mv_bits(xf, yf, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0) |
|
|
+ d_mv_bits(xb, yb, data->bpredMV, data->iFcode, data->qpel^data->qpel_precision, 0); |
|
|
|
|
|
sad = sad16bi(data->Cur, ReferenceF, ReferenceB, data->iEdgedWidth); |
|
|
sad += (data->lambda16 * t * sad)>>10; |
|
|
|
|
|
if (data->chroma && sad < *data->iMinSAD) |
|
|
sad += ChromaSAD2((xcf >> 1) + roundtab_79[xcf & 0x3], |
|
|
(ycf >> 1) + roundtab_79[ycf & 0x3], |
|
|
(xcb >> 1) + roundtab_79[xcb & 0x3], |
|
|
(ycb >> 1) + roundtab_79[ycb & 0x3], data); |
|
|
|
|
|
if (sad < *(data->iMinSAD)) { |
|
|
*data->iMinSAD = sad; |
|
|
current->x = x; current->y = y; |
|
|
data->dir = Direction; |
|
|
} |
|
|
|
|
|
if (sad < *(data->iMinSAD)) { |
|
|
data->iMinSAD2 = *(data->iMinSAD); |
|
|
data->currentQMV2.x = current->x; |
|
|
data->currentQMV2.y = current->y; |
|
|
|
|
|
*data->iMinSAD = sad; |
|
|
current->x = x; current->y = y; |
|
|
} else if (sad < data->iMinSAD2) { |
|
|
data->iMinSAD2 = sad; |
|
|
data->currentQMV2.x = x; data->currentQMV2.y = y; |
|
|
} |
|
|
} |
|
|
|
|
|
static void |
|
160 |
CheckCandidateDirect(const int x, const int y, SearchData * const data, const unsigned int Direction) |
CheckCandidateDirect(const int x, const int y, SearchData * const data, const unsigned int Direction) |
161 |
{ |
{ |
162 |
int32_t sad = 0, xcf = 0, ycf = 0, xcb = 0, ycb = 0; |
int32_t sad = 0, xcf = 0, ycf = 0, xcb = 0, ycb = 0; |
197 |
ReferenceF = xvid_me_interpolate8x8qpel(mvs.x, mvs.y, k, 0, data); |
ReferenceF = xvid_me_interpolate8x8qpel(mvs.x, mvs.y, k, 0, data); |
198 |
ReferenceB = xvid_me_interpolate8x8qpel(b_mvs.x, b_mvs.y, k, 1, data); |
ReferenceB = xvid_me_interpolate8x8qpel(b_mvs.x, b_mvs.y, k, 1, data); |
199 |
|
|
200 |
sad += sad8bi(data->Cur + 8*(k&1) + 8*(k>>1)*(data->iEdgedWidth), |
sad += data->iMinSAD[k+1] = |
201 |
|
sad8bi(data->Cur + 8*(k&1) + 8*(k>>1)*(data->iEdgedWidth), |
202 |
ReferenceF, ReferenceB, data->iEdgedWidth); |
ReferenceF, ReferenceB, data->iEdgedWidth); |
203 |
if (sad > *(data->iMinSAD)) return; |
if (sad > *(data->iMinSAD)) return; |
204 |
} |
} |
310 |
} |
} |
311 |
} |
} |
312 |
|
|
|
void |
|
|
CheckCandidate16no4v_qpel(const int x, const int y, SearchData * const data, const unsigned int Direction) |
|
|
{ |
|
|
int32_t sad, xc, yc; |
|
|
const uint8_t * Reference; |
|
|
uint32_t t; |
|
|
|
|
|
if ( (x > data->max_dx) || ( x < data->min_dx) |
|
|
|| (y > data->max_dy) || (y < data->min_dy) ) return; |
|
|
|
|
|
if (data->rrv && (!(x&1) && x !=0) | (!(y&1) && y !=0) ) return; /* non-zero even value */ |
|
|
|
|
|
Reference = xvid_me_interpolate16x16qpel(x, y, 0, data); |
|
|
|
|
|
xc = x/2; yc = y/2; |
|
|
t = d_mv_bits(x, y, data->predMV, data->iFcode, |
|
|
data->qpel^data->qpel_precision, data->rrv); |
|
|
|
|
|
sad = sad16(data->Cur, Reference, data->iEdgedWidth, 256*4096); |
|
|
sad += (data->lambda16 * t * sad)>>10; |
|
|
|
|
|
if (data->chroma && sad < *data->iMinSAD) |
|
|
sad += xvid_me_ChromaSAD((xc >> 1) + roundtab_79[xc & 0x3], |
|
|
(yc >> 1) + roundtab_79[yc & 0x3], data); |
|
|
|
|
|
if (sad < *(data->iMinSAD)) { |
|
|
data->iMinSAD2 = *(data->iMinSAD); |
|
|
data->currentQMV2.x = data->currentQMV->x; |
|
|
data->currentQMV2.y = data->currentQMV->y; |
|
|
|
|
|
data->iMinSAD[0] = sad; |
|
|
data->currentQMV[0].x = x; data->currentQMV[0].y = y; |
|
|
} else if (sad < data->iMinSAD2) { |
|
|
data->iMinSAD2 = sad; |
|
|
data->currentQMV2.x = x; data->currentQMV2.y = y; |
|
|
} |
|
|
} |
|
|
|
|
313 |
static __inline VECTOR |
static __inline VECTOR |
314 |
ChoosePred(const MACROBLOCK * const pMB, const uint32_t mode) |
ChoosePred(const MACROBLOCK * const pMB, const uint32_t mode) |
315 |
{ |
{ |
414 |
MainSearchPtr(Data->currentMV->x, Data->currentMV->y, Data, mask, CheckCandidate16no4v); |
MainSearchPtr(Data->currentMV->x, Data->currentMV->y, Data, mask, CheckCandidate16no4v); |
415 |
} |
} |
416 |
|
|
|
xvid_me_SubpelRefine(Data, CheckCandidate16no4v); |
|
417 |
|
|
418 |
if (Data->qpel && (*Data->iMinSAD < *best_sad + threshA)) { |
|
419 |
|
|
420 |
|
if(!Data->qpel) { |
421 |
|
/* halfpel mode */ |
422 |
|
if (MotionFlags & XVID_ME_HALFPELREFINE16) |
423 |
|
xvid_me_SubpelRefine(Data, CheckCandidate16no4v, 0); |
424 |
|
} else { |
425 |
|
/* qpel mode */ |
426 |
|
if(MotionFlags & XVID_ME_FASTREFINE16) { |
427 |
|
/* fast */ |
428 |
|
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 4, |
429 |
|
pParam->width, pParam->height, Data->iFcode, 2, 0); |
430 |
|
if (*Data->iMinSAD < *best_sad + 2*threshA) |
431 |
|
FullRefine_Fast(Data, CheckCandidate16no4v, 0); |
432 |
|
} else { |
433 |
Data->currentQMV->x = 2*Data->currentMV->x; |
Data->currentQMV->x = 2*Data->currentMV->x; |
434 |
Data->currentQMV->y = 2*Data->currentMV->y; |
Data->currentQMV->y = 2*Data->currentMV->y; |
|
Data->qpel_precision = 1; |
|
|
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 4, |
|
|
pParam->width, pParam->height, iFcode, 2, 0); |
|
|
|
|
435 |
if (MotionFlags & XVID_ME_QUARTERPELREFINE16) { |
if (MotionFlags & XVID_ME_QUARTERPELREFINE16) { |
436 |
if (MotionFlags & XVID_ME_FASTREFINE16) |
/* full */ |
437 |
SubpelRefine_Fast(Data, CheckCandidate16no4v_qpel); |
if (MotionFlags & XVID_ME_HALFPELREFINE16) { |
438 |
else |
xvid_me_SubpelRefine(Data, CheckCandidate16no4v, 0); /* hpel part */ |
439 |
xvid_me_SubpelRefine(Data, CheckCandidate16no4v); |
Data->currentQMV->x = 2*Data->currentMV->x; |
440 |
|
Data->currentQMV->y = 2*Data->currentMV->y; |
441 |
|
} |
442 |
|
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 4, |
443 |
|
pParam->width, pParam->height, Data->iFcode, 2, 0); |
444 |
|
Data->qpel_precision = 1; |
445 |
|
if (*Data->iMinSAD < *best_sad + threshA) |
446 |
|
xvid_me_SubpelRefine(Data, CheckCandidate16no4v, 0); /* qpel part */ |
447 |
|
} |
448 |
} |
} |
449 |
} |
} |
450 |
|
|
570 |
Data->max_dy = k * (pParam->height - y * 16); |
Data->max_dy = k * (pParam->height - y * 16); |
571 |
Data->min_dx = -k * (16 + x * 16); |
Data->min_dx = -k * (16 + x * 16); |
572 |
Data->min_dy = -k * (16 + y * 16); |
Data->min_dy = -k * (16 + y * 16); |
573 |
|
Data->chromaX = Data->chromaY = Data->b_chromaX = Data->b_chromaY = 256*4096; |
574 |
|
|
575 |
Data->referencemv = Data->qpel ? b_mb->qmvs : b_mb->mvs; |
Data->referencemv = Data->qpel ? b_mb->qmvs : b_mb->mvs; |
576 |
Data->qpel_precision = 0; |
Data->qpel_precision = 0; |
598 |
} |
} |
599 |
} |
} |
600 |
|
|
601 |
CheckCandidate = b_mb->mode == MODE_INTER4V ? CheckCandidateDirect : CheckCandidateDirectno4v; |
CheckCandidateDirect(0, 0, Data, 255); /* will also fill iMinSAD[1..4] with 8x8 SADs */ |
|
|
|
|
CheckCandidate(0, 0, Data, 255); |
|
602 |
|
|
603 |
/* initial (fast) skip decision */ |
/* initial (fast) skip decision */ |
604 |
if (*Data->iMinSAD < (int)Data->iQuant * INITIAL_SKIP_THRESH) { |
if (Data->iMinSAD[1] < (int)Data->iQuant * INITIAL_SKIP_THRESH |
605 |
|
&& Data->iMinSAD[2] < (int)Data->iQuant * INITIAL_SKIP_THRESH |
606 |
|
&& Data->iMinSAD[3] < (int)Data->iQuant * INITIAL_SKIP_THRESH |
607 |
|
&& Data->iMinSAD[4] < (int)Data->iQuant * INITIAL_SKIP_THRESH) { |
608 |
/* possible skip */ |
/* possible skip */ |
609 |
SkipDecisionB(pCur, f_Ref, b_Ref, pMB, x, y, Data); |
SkipDecisionB(pCur, f_Ref, b_Ref, pMB, x, y, Data); |
610 |
if (pMB->mode == MODE_DIRECT_NONE_MV) return *Data->iMinSAD; /* skipped */ |
if (pMB->mode == MODE_DIRECT_NONE_MV) |
611 |
|
return *Data->iMinSAD; /* skipped */ |
612 |
} |
} |
613 |
|
|
614 |
*Data->iMinSAD += Data->lambda16; |
skip_sad = 4*MAX(MAX(Data->iMinSAD[1],Data->iMinSAD[2]), MAX(Data->iMinSAD[3],Data->iMinSAD[4])); |
615 |
skip_sad = *Data->iMinSAD; |
if (Data->chroma) skip_sad += Data->chromaSAD; |
616 |
|
|
617 |
|
CheckCandidate = b_mb->mode == MODE_INTER4V ? CheckCandidateDirect : CheckCandidateDirectno4v; |
618 |
|
|
619 |
if (!(MotionFlags & XVID_ME_SKIP_DELTASEARCH)) { |
if (!(MotionFlags & XVID_ME_SKIP_DELTASEARCH)) { |
620 |
if (MotionFlags & XVID_ME_USESQUARES16) MainSearchPtr = xvid_me_SquareSearch; |
if (MotionFlags & XVID_ME_USESQUARES16) MainSearchPtr = xvid_me_SquareSearch; |
623 |
|
|
624 |
MainSearchPtr(0, 0, Data, 255, CheckCandidate); |
MainSearchPtr(0, 0, Data, 255, CheckCandidate); |
625 |
|
|
626 |
xvid_me_SubpelRefine(Data, CheckCandidate); |
xvid_me_SubpelRefine(Data, CheckCandidate, 0); |
627 |
} |
} |
628 |
|
|
629 |
|
*Data->iMinSAD += Data->lambda16; |
630 |
*best_sad = *Data->iMinSAD; |
*best_sad = *Data->iMinSAD; |
631 |
|
|
632 |
if (Data->qpel || b_mb->mode == MODE_INTER4V) pMB->mode = MODE_DIRECT; |
if (Data->qpel || b_mb->mode == MODE_INTER4V) pMB->mode = MODE_DIRECT; |
671 |
} |
} |
672 |
|
|
673 |
static void |
static void |
|
SubpelRefine_dir(SearchData * const data, CheckFunc * const CheckCandidate, const int dir) |
|
|
{ |
|
|
/* Do a half-pel or q-pel refinement */ |
|
|
const VECTOR centerMV = data->qpel_precision ? |
|
|
data->currentQMV[dir-1] : data->currentMV[dir-1]; |
|
|
|
|
|
CHECK_CANDIDATE(centerMV.x, centerMV.y - 1, dir); |
|
|
CHECK_CANDIDATE(centerMV.x + 1, centerMV.y - 1, dir); |
|
|
CHECK_CANDIDATE(centerMV.x + 1, centerMV.y, dir); |
|
|
CHECK_CANDIDATE(centerMV.x + 1, centerMV.y + 1, dir); |
|
|
CHECK_CANDIDATE(centerMV.x, centerMV.y + 1, dir); |
|
|
CHECK_CANDIDATE(centerMV.x - 1, centerMV.y + 1, dir); |
|
|
CHECK_CANDIDATE(centerMV.x - 1, centerMV.y, dir); |
|
|
CHECK_CANDIDATE(centerMV.x - 1, centerMV.y - 1, dir); |
|
|
} |
|
|
|
|
|
/* Pretty much redundant code, just as SubpelRefine_dir above too |
|
|
* |
|
|
* TODO: Get rid off all the redundancy (SubpelRefine_Fast_dir, |
|
|
* CheckCandidate16no4v_qpel etc.) */ |
|
|
|
|
|
void |
|
|
SubpelRefine_Fast_dir(SearchData * data, CheckFunc * CheckCandidate, const int dir) |
|
|
{ |
|
|
/* Do a fast q-pel refinement */ |
|
|
VECTOR centerMV; |
|
|
VECTOR second_best; |
|
|
int best_sad = *data->iMinSAD; |
|
|
int xo, yo, xo2, yo2; |
|
|
int size = 2; |
|
|
data->iMinSAD2 = 0; |
|
|
|
|
|
/* check all halfpixel positions near our best halfpel position */ |
|
|
centerMV = data->currentQMV[dir-1]; |
|
|
*data->iMinSAD = 256 * 4096; |
|
|
|
|
|
CHECK_CANDIDATE(centerMV.x, centerMV.y - size, dir); |
|
|
CHECK_CANDIDATE(centerMV.x + size, centerMV.y - size, dir); |
|
|
CHECK_CANDIDATE(centerMV.x + size, centerMV.y, dir); |
|
|
CHECK_CANDIDATE(centerMV.x + size, centerMV.y + size, dir); |
|
|
|
|
|
CHECK_CANDIDATE(centerMV.x, centerMV.y + size, dir); |
|
|
CHECK_CANDIDATE(centerMV.x - size, centerMV.y + size, dir); |
|
|
CHECK_CANDIDATE(centerMV.x - size, centerMV.y, dir); |
|
|
CHECK_CANDIDATE(centerMV.x - size, centerMV.y - size, dir); |
|
|
|
|
|
second_best = data->currentQMV[dir-1]; |
|
|
|
|
|
/* after second_best has been found, go back to the vector we began with */ |
|
|
|
|
|
data->currentQMV[dir-1] = centerMV; |
|
|
*data->iMinSAD = best_sad; |
|
|
|
|
|
xo = centerMV.x; |
|
|
yo = centerMV.y; |
|
|
xo2 = second_best.x; |
|
|
yo2 = second_best.y; |
|
|
|
|
|
data->iMinSAD2 = 256 * 4096; |
|
|
|
|
|
if (yo == yo2) { |
|
|
CHECK_CANDIDATE((xo+xo2)>>1, yo, dir); |
|
|
CHECK_CANDIDATE(xo, yo-1, dir); |
|
|
CHECK_CANDIDATE(xo, yo+1, dir); |
|
|
|
|
|
if(best_sad <= data->iMinSAD2) return; |
|
|
|
|
|
if(data->currentQMV[dir-1].x == data->currentQMV2.x) { |
|
|
CHECK_CANDIDATE((xo+xo2)>>1, yo-1, dir); |
|
|
CHECK_CANDIDATE((xo+xo2)>>1, yo+1, dir); |
|
|
} else { |
|
|
CHECK_CANDIDATE((xo+xo2)>>1, |
|
|
(data->currentQMV[dir-1].x == xo) ? data->currentQMV[dir-1].y : data->currentQMV2.y, dir); |
|
|
} |
|
|
return; |
|
|
} |
|
|
|
|
|
if (xo == xo2) { |
|
|
CHECK_CANDIDATE(xo, (yo+yo2)>>1, dir); |
|
|
CHECK_CANDIDATE(xo-1, yo, dir); |
|
|
CHECK_CANDIDATE(xo+1, yo, dir); |
|
|
|
|
|
if(best_sad < data->iMinSAD2) return; |
|
|
|
|
|
if(data->currentQMV[dir-1].y == data->currentQMV2.y) { |
|
|
CHECK_CANDIDATE(xo-1, (yo+yo2)>>1, dir); |
|
|
CHECK_CANDIDATE(xo+1, (yo+yo2)>>1, dir); |
|
|
} else { |
|
|
CHECK_CANDIDATE((data->currentQMV[dir-1].y == yo) ? data->currentQMV[dir-1].x : data->currentQMV2.x, (yo+yo2)>>1, dir); |
|
|
} |
|
|
return; |
|
|
} |
|
|
|
|
|
CHECK_CANDIDATE(xo, (yo+yo2)>>1, dir); |
|
|
CHECK_CANDIDATE((xo+xo2)>>1, yo, dir); |
|
|
|
|
|
if(best_sad <= data->iMinSAD2) return; |
|
|
|
|
|
CHECK_CANDIDATE((xo+xo2)>>1, (yo+yo2)>>1, dir); |
|
|
} |
|
|
|
|
|
static void |
|
674 |
SearchInterpolate(const IMAGE * const f_Ref, |
SearchInterpolate(const IMAGE * const f_Ref, |
675 |
const uint8_t * const f_RefH, |
const uint8_t * const f_RefH, |
676 |
const uint8_t * const f_RefV, |
const uint8_t * const f_RefV, |
715 |
Data->b_RefP[4] = b_Ref->u + (x + (Data->iEdgedWidth/2) * y) * 8; |
Data->b_RefP[4] = b_Ref->u + (x + (Data->iEdgedWidth/2) * y) * 8; |
716 |
Data->b_RefP[5] = b_Ref->v + (x + (Data->iEdgedWidth/2) * y) * 8; |
Data->b_RefP[5] = b_Ref->v + (x + (Data->iEdgedWidth/2) * y) * 8; |
717 |
|
|
718 |
|
Data->chromaX = Data->chromaY = 256*4096; |
719 |
|
|
720 |
Data->predMV = *f_predMV; |
Data->predMV = *f_predMV; |
721 |
Data->bpredMV = *b_predMV; |
Data->bpredMV = *b_predMV; |
722 |
|
|
774 |
Data->currentQMV[1].x = 2 * Data->currentMV[1].x; |
Data->currentQMV[1].x = 2 * Data->currentMV[1].x; |
775 |
Data->currentQMV[1].y = 2 * Data->currentMV[1].y; |
Data->currentQMV[1].y = 2 * Data->currentMV[1].y; |
776 |
|
|
777 |
if (MotionFlags & XVID_ME_QUARTERPELREFINE16) { |
if (MotionFlags & XVID_ME_QUARTERPELREFINE16) |
778 |
if (MotionFlags & XVID_ME_FASTREFINE16) |
xvid_me_SubpelRefine(Data, CheckCandidateInt, 1); |
|
SubpelRefine_Fast_dir(Data, CheckCandidateInt_qpel, 1); |
|
|
else |
|
|
SubpelRefine_dir(Data, CheckCandidateInt, 1); |
|
|
} |
|
779 |
|
|
780 |
if (*Data->iMinSAD > *best_sad + threshB) return; |
if (*Data->iMinSAD > *best_sad + threshB) return; |
781 |
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 4, pParam->width, pParam->height, bcode, 2, 0); |
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 4, pParam->width, pParam->height, bcode, 2, 0); |
782 |
|
|
783 |
if (MotionFlags & XVID_ME_QUARTERPELREFINE16) { |
if (MotionFlags & XVID_ME_QUARTERPELREFINE16) |
784 |
if (MotionFlags & XVID_ME_FASTREFINE16) |
xvid_me_SubpelRefine(Data, CheckCandidateInt, 2); |
|
SubpelRefine_Fast_dir(Data, CheckCandidateInt_qpel, 2); |
|
|
else |
|
|
SubpelRefine_dir(Data, CheckCandidateInt, 2); |
|
|
} |
|
785 |
} |
} |
786 |
|
|
787 |
*Data->iMinSAD += 2 * Data->lambda16; /* two bits are needed to code interpolate mode. */ |
*Data->iMinSAD += 2 * Data->lambda16; /* two bits are needed to code interpolate mode. */ |
872 |
} |
} |
873 |
|
|
874 |
Data.lambda16 = xvid_me_lambda_vec16[b_mb->quant]; |
Data.lambda16 = xvid_me_lambda_vec16[b_mb->quant]; |
|
|
|
875 |
Data.Cur = frame->image.y + (j * Data.iEdgedWidth + i) * 16; |
Data.Cur = frame->image.y + (j * Data.iEdgedWidth + i) * 16; |
876 |
Data.CurU = frame->image.u + (j * Data.iEdgedWidth/2 + i) * 8; |
Data.CurU = frame->image.u + (j * Data.iEdgedWidth/2 + i) * 8; |
877 |
Data.CurV = frame->image.v + (j * Data.iEdgedWidth/2 + i) * 8; |
Data.CurV = frame->image.v + (j * Data.iEdgedWidth/2 + i) * 8; |
968 |
} |
} |
969 |
|
|
970 |
/* final skip decision */ |
/* final skip decision */ |
971 |
if ( (skip_sad < Data.iQuant * MAX_SAD00_FOR_SKIP * (Data.chroma ? 3:2) ) |
if ( (skip_sad < Data.iQuant * MAX_SAD00_FOR_SKIP ) |
972 |
&& ((100*best_sad)/(skip_sad+1) > FINAL_SKIP_THRESH) ) |
&& ((100*best_sad)/(skip_sad+1) > FINAL_SKIP_THRESH) ) |
973 |
|
|
974 |
SkipDecisionB(&frame->image, f_ref, b_ref, pMB, i, j, &Data); |
SkipDecisionB(&frame->image, f_ref, b_ref, pMB, i, j, &Data); |