60 |
}; |
}; |
61 |
|
|
62 |
static void |
static void |
63 |
CheckCandidate16(const int x, const int y, const SearchData * const data, const unsigned int Direction) |
CheckCandidate16(const int x, const int y, SearchData * const data, const unsigned int Direction) |
64 |
{ |
{ |
65 |
const uint8_t * Reference; |
const uint8_t * Reference; |
66 |
int32_t sad; uint32_t t; |
int32_t sad, xc, yc; uint32_t t; |
67 |
|
VECTOR * current; |
68 |
|
|
69 |
if ( (x > data->max_dx) || (x < data->min_dx) |
if ( (x > data->max_dx) || (x < data->min_dx) |
70 |
|| (y > data->max_dy) || (y < data->min_dy) ) return; |
|| (y > data->max_dy) || (y < data->min_dy) ) return; |
71 |
|
|
72 |
|
if (data->qpel_precision) { /* x and y are in 1/4 precision */ |
73 |
|
Reference = xvid_me_interpolate16x16qpel(x, y, 0, data); |
74 |
|
current = data->currentQMV; |
75 |
|
xc = x/2; yc = y/2; |
76 |
|
} else { |
77 |
Reference = GetReference(x, y, data); |
Reference = GetReference(x, y, data); |
78 |
|
current = data->currentMV; |
79 |
|
xc = x; yc = y; |
80 |
|
} |
81 |
|
|
82 |
sad = sad16v(data->Cur, Reference, data->iEdgedWidth, data->temp); |
sad = sad16v(data->Cur, Reference, data->iEdgedWidth, data->temp); |
83 |
t = d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel, 0); |
t = d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0); |
84 |
|
|
85 |
sad += (data->lambda16 * t * sad)>>10; |
sad += (data->lambda16 * t * sad)>>10; |
86 |
data->temp[0] += (data->lambda8 * t * (data->temp[0] + NEIGH_8X8_BIAS))>>10; |
data->temp[0] += (data->lambda8 * t * (data->temp[0] + NEIGH_8X8_BIAS))>>10; |
87 |
|
|
88 |
if (data->chroma) { |
if (data->chroma) { |
89 |
if (sad >= data->iMinSAD[0]) goto no16; |
if (sad >= data->iMinSAD[0]) goto no16; |
90 |
sad += xvid_me_ChromaSAD((x >> 1) + roundtab_79[x & 0x3], |
sad += xvid_me_ChromaSAD((xc >> 1) + roundtab_79[xc & 0x3], |
91 |
(y >> 1) + roundtab_79[y & 0x3], data); |
(yc >> 1) + roundtab_79[yc & 0x3], data); |
92 |
} |
} |
93 |
|
|
94 |
if (sad < data->iMinSAD[0]) { |
if (sad < data->iMinSAD[0]) { |
95 |
data->iMinSAD[0] = sad; |
data->iMinSAD[0] = sad; |
96 |
data->currentMV[0].x = x; data->currentMV[0].y = y; |
current[0].x = x; current[0].y = y; |
97 |
*data->dir = Direction; |
data->dir = Direction; |
98 |
} |
} |
99 |
|
|
100 |
no16: |
no16: |
101 |
if (data->temp[0] < data->iMinSAD[1]) { |
if (data->temp[0] < data->iMinSAD[1]) { |
102 |
data->iMinSAD[1] = data->temp[0]; data->currentMV[1].x = x; data->currentMV[1].y = y; } |
data->iMinSAD[1] = data->temp[0]; current[1].x = x; current[1].y = y; } |
103 |
if (data->temp[1] < data->iMinSAD[2]) { |
if (data->temp[1] < data->iMinSAD[2]) { |
104 |
data->iMinSAD[2] = data->temp[1]; data->currentMV[2].x = x; data->currentMV[2].y = y; } |
data->iMinSAD[2] = data->temp[1]; current[2].x = x; current[2].y = y; } |
105 |
if (data->temp[2] < data->iMinSAD[3]) { |
if (data->temp[2] < data->iMinSAD[3]) { |
106 |
data->iMinSAD[3] = data->temp[2]; data->currentMV[3].x = x; data->currentMV[3].y = y; } |
data->iMinSAD[3] = data->temp[2]; current[3].x = x; current[3].y = y; } |
107 |
if (data->temp[3] < data->iMinSAD[4]) { |
if (data->temp[3] < data->iMinSAD[4]) { |
108 |
data->iMinSAD[4] = data->temp[3]; data->currentMV[4].x = x; data->currentMV[4].y = y; } |
data->iMinSAD[4] = data->temp[3]; current[4].x = x; current[4].y = y; } |
109 |
} |
} |
110 |
|
|
111 |
static void |
static void |
112 |
CheckCandidate16_qpel(const int x, const int y, const SearchData * const data, const unsigned int Direction) |
CheckCandidate8(const int x, const int y, SearchData * const data, const unsigned int Direction) |
|
{ |
|
|
const uint8_t *Reference; |
|
|
int32_t sad; uint32_t t; |
|
|
|
|
|
if ( (x > data->max_dx) || (x < data->min_dx) |
|
|
|| (y > data->max_dy) || (y < data->min_dy) ) return; |
|
|
|
|
|
Reference = xvid_me_interpolate16x16qpel(x, y, 0, data); |
|
|
|
|
|
sad = sad16v(data->Cur, Reference, data->iEdgedWidth, data->temp); |
|
|
t = d_mv_bits(x, y, data->predMV, data->iFcode, 0, 0); |
|
|
|
|
|
sad += (data->lambda16 * t * sad)>>10; |
|
|
data->temp[0] += (data->lambda8 * t * (data->temp[0] + NEIGH_8X8_BIAS))>>10; |
|
|
|
|
|
if (data->chroma && (sad < data->iMinSAD[0] || sad < data->iMinSAD2[0]) ) |
|
|
sad += xvid_me_ChromaSAD(((x/2) >> 1) + roundtab_79[(x/2) & 0x3], |
|
|
((y/2) >> 1) + roundtab_79[(y/2) & 0x3], data); |
|
|
|
|
|
if (data->temp[0] < data->iMinSAD[1]) { |
|
|
data->iMinSAD[1] = data->temp[0]; data->currentQMV[1].x = x; data->currentQMV[1].y = y; } |
|
|
if (data->temp[1] < data->iMinSAD[2]) { |
|
|
data->iMinSAD[2] = data->temp[1]; data->currentQMV[2].x = x; data->currentQMV[2].y = y; } |
|
|
if (data->temp[2] < data->iMinSAD[3]) { |
|
|
data->iMinSAD[3] = data->temp[2]; data->currentQMV[3].x = x; data->currentQMV[3].y = y; } |
|
|
if (data->temp[3] < data->iMinSAD[4]) { |
|
|
data->iMinSAD[4] = data->temp[3]; data->currentQMV[4].x = x; data->currentQMV[4].y = y; } |
|
|
|
|
|
if (sad < data->iMinSAD[0]) { |
|
|
*(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; |
|
|
} |
|
|
} |
|
|
|
|
|
static void |
|
|
CheckCandidate8(const int x, const int y, const SearchData * const data, const unsigned int Direction) |
|
113 |
{ |
{ |
114 |
int32_t sad; uint32_t t; |
int32_t sad; uint32_t t; |
115 |
const uint8_t * Reference; |
const uint8_t * Reference; |
134 |
if (sad < *(data->iMinSAD)) { |
if (sad < *(data->iMinSAD)) { |
135 |
*(data->iMinSAD) = sad; |
*(data->iMinSAD) = sad; |
136 |
current->x = x; current->y = y; |
current->x = x; current->y = y; |
137 |
*data->dir = Direction; |
data->dir = Direction; |
138 |
} |
} |
139 |
} |
} |
140 |
|
|
141 |
static void |
static void |
142 |
CheckCandidate32(const int x, const int y, const SearchData * const data, const unsigned int Direction) |
CheckCandidate32(const int x, const int y, SearchData * const data, const unsigned int Direction) |
143 |
{ |
{ |
144 |
uint32_t t; |
uint32_t t; |
145 |
const uint8_t * Reference; |
const uint8_t * Reference; |
160 |
if (sad < data->iMinSAD[0]) { |
if (sad < data->iMinSAD[0]) { |
161 |
data->iMinSAD[0] = sad; |
data->iMinSAD[0] = sad; |
162 |
data->currentMV[0].x = x; data->currentMV[0].y = y; |
data->currentMV[0].x = x; data->currentMV[0].y = y; |
163 |
*data->dir = Direction; |
data->dir = Direction; |
164 |
} |
} |
165 |
|
|
166 |
if (data->temp[0] < data->iMinSAD[1]) { |
if (data->temp[0] < data->iMinSAD[1]) { |
173 |
data->iMinSAD[4] = data->temp[3]; data->currentMV[4].x = x; data->currentMV[4].y = y; } |
data->iMinSAD[4] = data->temp[3]; data->currentMV[4].x = x; data->currentMV[4].y = y; } |
174 |
} |
} |
175 |
|
|
|
static void |
|
|
SubpelRefine_Fast(SearchData * data, CheckFunc * CheckCandidate) |
|
|
{ |
|
|
/* 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; |
|
|
*data->iMinSAD = 256 * 4096; |
|
|
|
|
|
CHECK_CANDIDATE(centerMV.x, centerMV.y - size, 0); |
|
|
CHECK_CANDIDATE(centerMV.x + size, centerMV.y - size, 0); |
|
|
CHECK_CANDIDATE(centerMV.x + size, centerMV.y, 0); |
|
|
CHECK_CANDIDATE(centerMV.x + size, centerMV.y + size, 0); |
|
|
|
|
|
CHECK_CANDIDATE(centerMV.x, centerMV.y + size, 0); |
|
|
CHECK_CANDIDATE(centerMV.x - size, centerMV.y + size, 0); |
|
|
CHECK_CANDIDATE(centerMV.x - size, centerMV.y, 0); |
|
|
CHECK_CANDIDATE(centerMV.x - size, centerMV.y - size, 0); |
|
|
|
|
|
second_best = *data->currentQMV; |
|
|
|
|
|
/* after second_best has been found, go back to the vector we began with */ |
|
|
|
|
|
data->currentQMV[0] = 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, 0); |
|
|
CHECK_CANDIDATE(xo, yo-1, 0); |
|
|
CHECK_CANDIDATE(xo, yo+1, 0); |
|
|
|
|
|
if(best_sad <= *data->iMinSAD2) return; |
|
|
|
|
|
if(data->currentQMV[0].x == data->currentQMV2[0].x) { |
|
|
CHECK_CANDIDATE((xo+xo2)>>1, yo-1, 0); |
|
|
CHECK_CANDIDATE((xo+xo2)>>1, yo+1, 0); |
|
|
} else { |
|
|
CHECK_CANDIDATE((xo+xo2)>>1, |
|
|
(data->currentQMV[0].x == xo) ? data->currentQMV[0].y : data->currentQMV2[0].y, 0); |
|
|
} |
|
|
return; |
|
|
} |
|
|
|
|
|
if (xo == xo2) { |
|
|
CHECK_CANDIDATE(xo, (yo+yo2)>>1, 0); |
|
|
CHECK_CANDIDATE(xo-1, yo, 0); |
|
|
CHECK_CANDIDATE(xo+1, yo, 0); |
|
|
|
|
|
if(best_sad < *data->iMinSAD2) return; |
|
|
|
|
|
if(data->currentQMV[0].y == data->currentQMV2[0].y) { |
|
|
CHECK_CANDIDATE(xo-1, (yo+yo2)>>1, 0); |
|
|
CHECK_CANDIDATE(xo+1, (yo+yo2)>>1, 0); |
|
|
} else { |
|
|
CHECK_CANDIDATE((data->currentQMV[0].y == yo) ? data->currentQMV[0].x : data->currentQMV2[0].x, (yo+yo2)>>1, 0); |
|
|
} |
|
|
return; |
|
|
} |
|
|
|
|
|
CHECK_CANDIDATE(xo, (yo+yo2)>>1, 0); |
|
|
CHECK_CANDIDATE((xo+xo2)>>1, yo, 0); |
|
|
|
|
|
if(best_sad <= *data->iMinSAD2) return; |
|
|
|
|
|
CHECK_CANDIDATE((xo+xo2)>>1, (yo+yo2)>>1, 0); |
|
|
} |
|
|
|
|
176 |
int |
int |
177 |
xvid_me_SkipDecisionP(const IMAGE * current, const IMAGE * reference, |
xvid_me_SkipDecisionP(const IMAGE * current, const IMAGE * reference, |
178 |
const int x, const int y, |
const int x, const int y, |
270 |
pmv[0] = pmv[1] = pmv[2] = pmv[3] = zeroMV; |
pmv[0] = pmv[1] = pmv[2] = pmv[3] = zeroMV; |
271 |
psad[0] = 0; |
psad[0] = 0; |
272 |
psad[1] = psad[2] = psad[3] = MV_MAX_ERROR; |
psad[1] = psad[2] = psad[3] = MV_MAX_ERROR; |
273 |
|
return; |
274 |
} |
} |
275 |
|
|
276 |
/* if only one valid candidate preictor, the invalid candiates are set to the canidate */ |
/* if only one valid candidate preictor, the invalid candiates are set to the canidate */ |
277 |
if (num_cand == 1) { |
if (num_cand == 1) { |
278 |
pmv[0] = pmv[last_cand]; |
pmv[0] = pmv[last_cand]; |
279 |
psad[0] = psad[last_cand]; |
psad[0] = psad[last_cand]; |
280 |
|
return; |
281 |
} |
} |
282 |
|
|
283 |
if ((MVequal(pmv[1], pmv[2])) && (MVequal(pmv[1], pmv[3]))) { |
if ((MVequal(pmv[1], pmv[2])) && (MVequal(pmv[1], pmv[3]))) { |
284 |
pmv[0] = pmv[1]; |
pmv[0] = pmv[1]; |
285 |
psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]); |
psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]); |
286 |
|
return; |
287 |
} |
} |
288 |
|
|
289 |
/* set median, minimum */ |
/* set median, minimum */ |
365 |
|
|
366 |
/* intra decision */ |
/* intra decision */ |
367 |
|
|
368 |
if (iQuant > 8) InterBias += 100 * (iQuant - 8); /* to make high quants work */ |
if (iQuant > 10) InterBias += 60 * (iQuant - 10); /* to make high quants work */ |
369 |
if (y != 0) |
if (y != 0) |
370 |
if ((pMB - pParam->mb_width)->mode == MODE_INTRA ) InterBias -= 80; |
if ((pMB - pParam->mb_width)->mode == MODE_INTRA ) InterBias -= 80; |
371 |
if (x != 0) |
if (x != 0) |
467 |
} |
} |
468 |
|
|
469 |
static void |
static void |
470 |
Search8(const SearchData * const OldData, |
Search8(SearchData * const OldData, |
471 |
const int x, const int y, |
const int x, const int y, |
472 |
const uint32_t MotionFlags, |
const uint32_t MotionFlags, |
473 |
const MBParam * const pParam, |
const MBParam * const pParam, |
477 |
SearchData * const Data) |
SearchData * const Data) |
478 |
{ |
{ |
479 |
int i = 0; |
int i = 0; |
480 |
|
VECTOR vbest_q; int32_t sbest_q; |
481 |
CheckFunc * CheckCandidate; |
CheckFunc * CheckCandidate; |
482 |
Data->iMinSAD = OldData->iMinSAD + 1 + block; |
*Data->iMinSAD = *(OldData->iMinSAD + 1 + block); |
483 |
Data->currentMV = OldData->currentMV + 1 + block; |
*Data->currentMV = *(OldData->currentMV + 1 + block); |
484 |
Data->currentQMV = OldData->currentQMV + 1 + block; |
*Data->currentQMV = *(OldData->currentQMV + 1 + block); |
485 |
|
|
486 |
if(Data->qpel) { |
if(Data->qpel) { |
487 |
Data->predMV = get_qpmv2(pMBs, pParam->mb_width, 0, x/2, y/2, block); |
Data->predMV = get_qpmv2(pMBs, pParam->mb_width, 0, x/2, y/2, block); |
497 |
|
|
498 |
if (MotionFlags & (XVID_ME_EXTSEARCH8|XVID_ME_HALFPELREFINE8|XVID_ME_QUARTERPELREFINE8)) { |
if (MotionFlags & (XVID_ME_EXTSEARCH8|XVID_ME_HALFPELREFINE8|XVID_ME_QUARTERPELREFINE8)) { |
499 |
|
|
500 |
|
vbest_q = Data->currentQMV[0]; |
501 |
|
sbest_q = Data->iMinSAD[0]; |
502 |
|
|
503 |
if (Data->rrv) i = 16; else i = 8; |
if (Data->rrv) i = 16; else i = 8; |
504 |
|
|
505 |
Data->RefP[0] = OldData->RefP[0] + i * ((block&1) + Data->iEdgedWidth*(block>>1)); |
Data->RefP[0] = OldData->RefP[0] + i * ((block&1) + Data->iEdgedWidth*(block>>1)); |
517 |
else CheckCandidate = CheckCandidate16no4v; |
else CheckCandidate = CheckCandidate16no4v; |
518 |
|
|
519 |
if (MotionFlags & XVID_ME_EXTSEARCH8 && (!(MotionFlags & XVID_ME_EXTSEARCH_RD))) { |
if (MotionFlags & XVID_ME_EXTSEARCH8 && (!(MotionFlags & XVID_ME_EXTSEARCH_RD))) { |
|
int32_t temp_sad = *(Data->iMinSAD); /* store current MinSAD */ |
|
520 |
|
|
521 |
MainSearchFunc *MainSearchPtr; |
MainSearchFunc *MainSearchPtr; |
522 |
if (MotionFlags & XVID_ME_USESQUARES8) MainSearchPtr = xvid_me_SquareSearch; |
if (MotionFlags & XVID_ME_USESQUARES8) MainSearchPtr = xvid_me_SquareSearch; |
524 |
else MainSearchPtr = xvid_me_DiamondSearch; |
else MainSearchPtr = xvid_me_DiamondSearch; |
525 |
|
|
526 |
MainSearchPtr(Data->currentMV->x, Data->currentMV->y, Data, 255, CheckCandidate); |
MainSearchPtr(Data->currentMV->x, Data->currentMV->y, Data, 255, CheckCandidate); |
527 |
|
} |
528 |
|
|
529 |
if(*(Data->iMinSAD) < temp_sad) { |
if(!Data->qpel) { |
530 |
Data->currentQMV->x = 2 * Data->currentMV->x; /* update our qpel vector */ |
/* halfpel mode */ |
531 |
|
if (MotionFlags & XVID_ME_HALFPELREFINE8) |
532 |
|
xvid_me_SubpelRefine(Data, CheckCandidate, 0); /* perform halfpel refine of current best vector */ |
533 |
|
} else { |
534 |
|
/* qpel mode */ |
535 |
|
Data->currentQMV->x = 2*Data->currentMV->x; |
536 |
Data->currentQMV->y = 2 * Data->currentMV->y; |
Data->currentQMV->y = 2 * Data->currentMV->y; |
|
} |
|
|
} |
|
537 |
|
|
538 |
|
if(MotionFlags & XVID_ME_FASTREFINE8) { |
539 |
|
/* fast */ |
540 |
|
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 3, |
541 |
|
pParam->width, pParam->height, Data->iFcode, 2, 0); |
542 |
|
FullRefine_Fast(Data, CheckCandidate8, 0); |
543 |
|
} else if(MotionFlags & XVID_ME_QUARTERPELREFINE8) { |
544 |
|
/* full */ |
545 |
if (MotionFlags & XVID_ME_HALFPELREFINE8) { |
if (MotionFlags & XVID_ME_HALFPELREFINE8) { |
546 |
int32_t temp_sad = *(Data->iMinSAD); /* store current MinSAD */ |
xvid_me_SubpelRefine(Data, CheckCandidate8, 0); /* hpel part */ |
547 |
|
Data->currentQMV->x = 2*Data->currentMV->x; |
|
xvid_me_SubpelRefine(Data, CheckCandidate); /* perform halfpel refine of current best vector */ |
|
|
|
|
|
if(*(Data->iMinSAD) < temp_sad) { /* we have found a better match */ |
|
|
Data->currentQMV->x = 2 * Data->currentMV->x; /* update our qpel vector */ |
|
548 |
Data->currentQMV->y = 2 * Data->currentMV->y; |
Data->currentQMV->y = 2 * Data->currentMV->y; |
549 |
} |
} |
|
} |
|
550 |
|
|
|
if (Data->qpel && MotionFlags & XVID_ME_QUARTERPELREFINE8) { |
|
|
Data->qpel_precision = 1; |
|
551 |
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 3, |
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 3, |
552 |
pParam->width, pParam->height, Data->iFcode, 2, 0); |
pParam->width, pParam->height, Data->iFcode, 2, 0); |
553 |
xvid_me_SubpelRefine(Data, CheckCandidate); |
Data->qpel_precision = 1; |
554 |
|
|
555 |
|
xvid_me_SubpelRefine(Data, CheckCandidate8, 0); /* qpel part */ |
556 |
|
} |
557 |
} |
} |
558 |
|
|
559 |
|
if (sbest_q <= Data->iMinSAD[0]) /* we have not found a better match */ |
560 |
|
Data->currentQMV[0] = vbest_q; |
561 |
|
|
562 |
} |
} |
563 |
|
|
564 |
if (Data->rrv) { |
if (Data->rrv) { |
565 |
Data->currentMV->x = RRV_MV_SCALEDOWN(Data->currentMV->x); |
Data->currentMV->x = RRV_MV_SCALEDOWN(Data->currentMV->x); |
566 |
Data->currentMV->y = RRV_MV_SCALEDOWN(Data->currentMV->y); |
Data->currentMV->y = RRV_MV_SCALEDOWN(Data->currentMV->y); |
567 |
} |
} else if(Data->qpel) { |
|
|
|
|
if(Data->qpel) { |
|
568 |
pMB->pmvs[block].x = Data->currentQMV->x - Data->predMV.x; |
pMB->pmvs[block].x = Data->currentQMV->x - Data->predMV.x; |
569 |
pMB->pmvs[block].y = Data->currentQMV->y - Data->predMV.y; |
pMB->pmvs[block].y = Data->currentQMV->y - Data->predMV.y; |
570 |
pMB->qmvs[block] = *Data->currentQMV; |
pMB->qmvs[block] = *Data->currentQMV; |
573 |
pMB->pmvs[block].y = Data->currentMV->y - Data->predMV.y; |
pMB->pmvs[block].y = Data->currentMV->y - Data->predMV.y; |
574 |
} |
} |
575 |
|
|
576 |
|
*(OldData->iMinSAD + 1 + block) = *Data->iMinSAD; |
577 |
|
*(OldData->currentMV + 1 + block) = *Data->currentMV; |
578 |
|
*(OldData->currentQMV + 1 + block) = *Data->currentQMV; |
579 |
|
|
580 |
pMB->mvs[block] = *Data->currentMV; |
pMB->mvs[block] = *Data->currentMV; |
581 |
pMB->sad8[block] = 4 * *Data->iMinSAD; |
pMB->sad8[block] = 4 * *Data->iMinSAD; |
582 |
} |
} |
610 |
|
|
611 |
get_pmvdata2(pMBs, pParam->mb_width, 0, x, y, pmv, Data->temp); |
get_pmvdata2(pMBs, pParam->mb_width, 0, x, y, pmv, Data->temp); |
612 |
|
|
613 |
Data->temp[5] = Data->temp[6] = 0; /* chroma-sad cache */ |
Data->chromaX = Data->chromaY = 0; /* chroma-sad cache */ |
614 |
i = Data->rrv ? 2 : 1; |
i = Data->rrv ? 2 : 1; |
615 |
Data->Cur = pCur->y + (x + y * Data->iEdgedWidth) * 16*i; |
Data->Cur = pCur->y + (x + y * Data->iEdgedWidth) * 16*i; |
616 |
Data->CurV = pCur->v + (x + y * (Data->iEdgedWidth/2)) * 8*i; |
Data->CurV = pCur->v + (x + y * (Data->iEdgedWidth/2)) * 8*i; |
626 |
Data->lambda16 = xvid_me_lambda_vec16[pMB->quant]; |
Data->lambda16 = xvid_me_lambda_vec16[pMB->quant]; |
627 |
Data->lambda8 = xvid_me_lambda_vec8[pMB->quant]; |
Data->lambda8 = xvid_me_lambda_vec8[pMB->quant]; |
628 |
Data->qpel_precision = 0; |
Data->qpel_precision = 0; |
629 |
*Data->dir = 0; |
Data->dir = 0; |
630 |
|
|
631 |
memset(Data->currentMV, 0, 5*sizeof(VECTOR)); |
memset(Data->currentMV, 0, 5*sizeof(VECTOR)); |
632 |
|
|
670 |
else { |
else { |
671 |
|
|
672 |
MainSearchFunc * MainSearchPtr; |
MainSearchFunc * MainSearchPtr; |
673 |
int mask = make_mask(pmv, i, *Data->dir); /* all vectors pmv[0..i-1] have been checked */ |
int mask = make_mask(pmv, i, Data->dir); /* all vectors pmv[0..i-1] have been checked */ |
674 |
|
|
675 |
if (MotionFlags & XVID_ME_USESQUARES16) MainSearchPtr = xvid_me_SquareSearch; |
if (MotionFlags & XVID_ME_USESQUARES16) MainSearchPtr = xvid_me_SquareSearch; |
676 |
else if (MotionFlags & XVID_ME_ADVANCEDDIAMOND16) MainSearchPtr = xvid_me_AdvDiamondSearch; |
else if (MotionFlags & XVID_ME_ADVANCEDDIAMOND16) MainSearchPtr = xvid_me_AdvDiamondSearch; |
696 |
bSAD = Data->iMinSAD[0]; Data->iMinSAD[0] = MV_MAX_ERROR; |
bSAD = Data->iMinSAD[0]; Data->iMinSAD[0] = MV_MAX_ERROR; |
697 |
|
|
698 |
CheckCandidate(startMV.x, startMV.y, Data, 255); |
CheckCandidate(startMV.x, startMV.y, Data, 255); |
699 |
MainSearchPtr(startMV.x, startMV.y, Data, 255, CheckCandidate); |
xvid_me_DiamondSearch(startMV.x, startMV.y, Data, 255, CheckCandidate); |
700 |
if (bSAD < Data->iMinSAD[0]) { |
if (bSAD < Data->iMinSAD[0]) { |
701 |
Data->currentMV[0] = backupMV; |
Data->currentMV[0] = backupMV; |
702 |
Data->iMinSAD[0] = bSAD; } |
Data->iMinSAD[0] = bSAD; } |
708 |
bSAD = Data->iMinSAD[0]; Data->iMinSAD[0] = MV_MAX_ERROR; |
bSAD = Data->iMinSAD[0]; Data->iMinSAD[0] = MV_MAX_ERROR; |
709 |
|
|
710 |
CheckCandidate(startMV.x, startMV.y, Data, 255); |
CheckCandidate(startMV.x, startMV.y, Data, 255); |
711 |
MainSearchPtr(startMV.x, startMV.y, Data, 255, CheckCandidate); |
xvid_me_DiamondSearch(startMV.x, startMV.y, Data, 255, CheckCandidate); |
712 |
if (bSAD < Data->iMinSAD[0]) { |
if (bSAD < Data->iMinSAD[0]) { |
713 |
Data->currentMV[0] = backupMV; |
Data->currentMV[0] = backupMV; |
714 |
Data->iMinSAD[0] = bSAD; |
Data->iMinSAD[0] = bSAD; |
717 |
} |
} |
718 |
} |
} |
719 |
|
|
720 |
|
|
721 |
|
if(!Data->qpel) { |
722 |
|
/* halfpel mode */ |
723 |
if (MotionFlags & XVID_ME_HALFPELREFINE16) |
if (MotionFlags & XVID_ME_HALFPELREFINE16) |
724 |
xvid_me_SubpelRefine(Data, CheckCandidate); |
xvid_me_SubpelRefine(Data, CheckCandidate, 0); |
725 |
|
} else { |
726 |
|
/* qpel mode */ |
727 |
|
|
728 |
for(i = 0; i < 5; i++) { |
for(i = 0; i < 5; i++) { |
729 |
Data->currentQMV[i].x = 2 * Data->currentMV[i].x; /* initialize qpel vectors */ |
Data->currentQMV[i].x = 2 * Data->currentMV[i].x; /* initialize qpel vectors */ |
730 |
Data->currentQMV[i].y = 2 * Data->currentMV[i].y; |
Data->currentQMV[i].y = 2 * Data->currentMV[i].y; |
731 |
} |
} |
732 |
|
if(MotionFlags & XVID_ME_FASTREFINE16 && MotionFlags & XVID_ME_QUARTERPELREFINE16) { |
733 |
if (Data->qpel) { |
/* fast */ |
734 |
|
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 4, |
735 |
|
pParam->width, pParam->height, Data->iFcode, 2, 0); |
736 |
|
FullRefine_Fast(Data, CheckCandidate, 0); |
737 |
|
} else { |
738 |
|
if(MotionFlags & (XVID_ME_QUARTERPELREFINE16 | XVID_ME_QUARTERPELREFINE16_RD)) { |
739 |
|
/* full */ |
740 |
|
if (MotionFlags & XVID_ME_HALFPELREFINE16) { |
741 |
|
xvid_me_SubpelRefine(Data, CheckCandidate, 0); /* hpel part */ |
742 |
|
for(i = 0; i < 5; i++) { |
743 |
|
Data->currentQMV[i].x = 2 * Data->currentMV[i].x; |
744 |
|
Data->currentQMV[i].y = 2 * Data->currentMV[i].y; |
745 |
|
} |
746 |
|
} |
747 |
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 4, |
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 4, |
748 |
pParam->width, pParam->height, Data->iFcode, 2, 0); |
pParam->width, pParam->height, Data->iFcode, 2, 0); |
749 |
Data->qpel_precision = 1; |
Data->qpel_precision = 1; |
750 |
if (MotionFlags & XVID_ME_QUARTERPELREFINE16) { |
if(MotionFlags & XVID_ME_QUARTERPELREFINE16) |
751 |
if(MotionFlags & XVID_ME_FASTREFINE16) |
xvid_me_SubpelRefine(Data, CheckCandidate, 0); /* qpel part */ |
752 |
SubpelRefine_Fast(Data, CheckCandidate16_qpel); |
} |
|
else |
|
|
xvid_me_SubpelRefine(Data, CheckCandidate16_qpel); |
|
753 |
} |
} |
754 |
} |
} |
755 |
|
|
756 |
if (Data->iMinSAD[0] < (int32_t)pMB->quant * 30) |
if (Data->iMinSAD[0] < (int32_t)pMB->quant * 30* ((MotionFlags & XVID_ME_FASTREFINE16) ? 8 : 1)) |
757 |
inter4v = 0; |
inter4v = 0; |
758 |
|
|
759 |
if (inter4v) { |
if (inter4v) { |
766 |
Search8(Data, 2*x + 1, 2*y + 1, MotionFlags, pParam, pMB, pMBs, 3, &Data8); |
Search8(Data, 2*x + 1, 2*y + 1, MotionFlags, pParam, pMB, pMBs, 3, &Data8); |
767 |
|
|
768 |
if ((Data->chroma) && (!(VopFlags & XVID_VOP_MODEDECISION_RD))) { |
if ((Data->chroma) && (!(VopFlags & XVID_VOP_MODEDECISION_RD))) { |
769 |
/* chroma is only used for comparsion to INTER. if the comparsion will be done in BITS domain, it will not be used */ |
/* chroma is only used for comparison to INTER. if the comparison will be done in RD domain, it will not be used */ |
770 |
int sumx = 0, sumy = 0; |
int sumx = 0, sumy = 0; |
771 |
|
|
772 |
if (Data->qpel) |
if (Data->qpel) |
811 |
if (Flags & XVID_ME_QUARTERPELREFINE8_RD) |
if (Flags & XVID_ME_QUARTERPELREFINE8_RD) |
812 |
Flags &= ~XVID_ME_QUARTERPELREFINE8; |
Flags &= ~XVID_ME_QUARTERPELREFINE8; |
813 |
|
|
814 |
|
if (Flags & XVID_ME_QUARTERPELREFINE16_RD) |
815 |
|
Flags &= ~XVID_ME_QUARTERPELREFINE16; |
816 |
|
|
817 |
if (!(VolFlags & XVID_VOL_QUARTERPEL)) |
if (!(VolFlags & XVID_VOL_QUARTERPEL)) |
818 |
Flags &= ~(XVID_ME_QUARTERPELREFINE16+XVID_ME_QUARTERPELREFINE8+XVID_ME_QUARTERPELREFINE16_RD+XVID_ME_QUARTERPELREFINE8_RD); |
Flags &= ~(XVID_ME_QUARTERPELREFINE16+XVID_ME_QUARTERPELREFINE8+XVID_ME_QUARTERPELREFINE16_RD+XVID_ME_QUARTERPELREFINE8_RD); |
819 |
|
|
823 |
if ((VopFlags & XVID_VOP_GREYSCALE) || (VopFlags & XVID_VOP_REDUCED)) |
if ((VopFlags & XVID_VOP_GREYSCALE) || (VopFlags & XVID_VOP_REDUCED)) |
824 |
Flags &= ~(XVID_ME_CHROMA_PVOP + XVID_ME_CHROMA_BVOP); |
Flags &= ~(XVID_ME_CHROMA_PVOP + XVID_ME_CHROMA_BVOP); |
825 |
|
|
826 |
|
if (Flags & XVID_ME_FASTREFINE8) |
827 |
|
Flags &= ~XVID_ME_HALFPELREFINE8_RD; |
828 |
|
|
829 |
|
if (Flags & XVID_ME_FASTREFINE16) |
830 |
|
Flags &= ~XVID_ME_HALFPELREFINE16_RD; |
831 |
|
|
832 |
return Flags; |
return Flags; |
833 |
} |
} |
834 |
|
|
860 |
(current->vop_flags & XVID_VOP_MODEDECISION_RD ? 2:1); |
(current->vop_flags & XVID_VOP_MODEDECISION_RD ? 2:1); |
861 |
|
|
862 |
/* some pre-initialized thingies for SearchP */ |
/* some pre-initialized thingies for SearchP */ |
|
int32_t temp[8]; uint32_t dir; |
|
|
VECTOR currentMV[5]; |
|
|
VECTOR currentQMV[5]; |
|
|
VECTOR currentQMV2; |
|
|
int32_t iMinSAD[5]; |
|
|
int32_t iMinSAD2; |
|
863 |
DECLARE_ALIGNED_MATRIX(dct_space, 3, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(dct_space, 3, 64, int16_t, CACHE_LINE); |
864 |
SearchData Data; |
SearchData Data; |
865 |
memset(&Data, 0, sizeof(SearchData)); |
memset(&Data, 0, sizeof(SearchData)); |
866 |
Data.iEdgedWidth = iEdgedWidth; |
Data.iEdgedWidth = iEdgedWidth; |
|
Data.currentMV = currentMV; |
|
|
Data.currentQMV = currentQMV; |
|
|
Data.currentQMV2 = ¤tQMV2; |
|
|
Data.iMinSAD = iMinSAD; |
|
|
Data.iMinSAD2 = &iMinSAD2; |
|
|
Data.temp = temp; |
|
|
Data.dir = &dir; |
|
867 |
Data.iFcode = current->fcode; |
Data.iFcode = current->fcode; |
868 |
Data.rounding = pParam->m_rounding_type; |
Data.rounding = pParam->m_rounding_type; |
869 |
Data.qpel = (current->vol_flags & XVID_VOL_QUARTERPEL ? 1:0); |
Data.qpel = (current->vol_flags & XVID_VOL_QUARTERPEL ? 1:0); |
871 |
Data.rrv = (current->vop_flags & XVID_VOP_REDUCED) ? 1:0; |
Data.rrv = (current->vop_flags & XVID_VOP_REDUCED) ? 1:0; |
872 |
Data.dctSpace = dct_space; |
Data.dctSpace = dct_space; |
873 |
Data.quant_type = !(pParam->vol_flags & XVID_VOL_MPEGQUANT); |
Data.quant_type = !(pParam->vol_flags & XVID_VOL_MPEGQUANT); |
874 |
|
Data.mpeg_quant_matrices = pParam->mpeg_quant_matrices; |
875 |
|
|
876 |
if ((current->vop_flags & XVID_VOP_REDUCED)) { |
if ((current->vop_flags & XVID_VOP_REDUCED)) { |
877 |
mb_width = (pParam->width + 31) / 32; |
mb_width = (pParam->width + 31) / 32; |
898 |
pParam->edged_width, pMB->sad8 ); |
pParam->edged_width, pMB->sad8 ); |
899 |
|
|
900 |
if (Data.chroma) { |
if (Data.chroma) { |
901 |
Data.temp[7] = sad8(pCurrent->u + x*8 + y*(iEdgedWidth/2)*8, |
Data.chromaSAD = sad8(pCurrent->u + x*8 + y*(iEdgedWidth/2)*8, |
902 |
pRef->u + x*8 + y*(iEdgedWidth/2)*8, iEdgedWidth/2) |
pRef->u + x*8 + y*(iEdgedWidth/2)*8, iEdgedWidth/2) |
903 |
+ sad8(pCurrent->v + (x + y*(iEdgedWidth/2))*8, |
+ sad8(pCurrent->v + (x + y*(iEdgedWidth/2))*8, |
904 |
pRef->v + (x + y*(iEdgedWidth/2))*8, iEdgedWidth/2); |
pRef->v + (x + y*(iEdgedWidth/2))*8, iEdgedWidth/2); |
905 |
pMB->sad16 += Data.temp[7]; |
pMB->sad16 += Data.chromaSAD; |
906 |
} |
} |
907 |
|
|
908 |
sad00 = pMB->sad16; |
sad00 = pMB->sad16; |
910 |
/* initial skip decision */ |
/* initial skip decision */ |
911 |
/* no early skip for GMC (global vector = skip vector is unknown!) */ |
/* no early skip for GMC (global vector = skip vector is unknown!) */ |
912 |
if (current->coding_type != S_VOP) { /* no fast SKIP for S(GMC)-VOPs */ |
if (current->coding_type != S_VOP) { /* no fast SKIP for S(GMC)-VOPs */ |
913 |
if (pMB->dquant == 0 && sad00 < pMB->quant * skip_thresh) |
if (pMB->dquant == 0 |
914 |
|
&& pMB->sad8[0] < pMB->quant * skip_thresh |
915 |
|
&& pMB->sad8[1] < pMB->quant * skip_thresh |
916 |
|
&& pMB->sad8[2] < pMB->quant * skip_thresh |
917 |
|
&& pMB->sad8[3] < pMB->quant * skip_thresh) |
918 |
|
|
919 |
if (Data.chroma || xvid_me_SkipDecisionP(pCurrent, pRef, x, y, iEdgedWidth/2, pMB->quant, Data.rrv)) { |
if (Data.chroma || xvid_me_SkipDecisionP(pCurrent, pRef, x, y, iEdgedWidth/2, pMB->quant, Data.rrv)) { |
920 |
ZeroMacroblockP(pMB, sad00); |
ZeroMacroblockP(pMB, sad00); |
921 |
pMB->mode = MODE_NOT_CODED; |
pMB->mode = MODE_NOT_CODED; |
933 |
MAX((&pMBs[x + (y-1) * pParam->mb_width])->sad16, |
MAX((&pMBs[x + (y-1) * pParam->mb_width])->sad16, |
934 |
MAX((&pMBs[(x+1) + (y-1) * pParam->mb_width])->sad16, |
MAX((&pMBs[(x+1) + (y-1) * pParam->mb_width])->sad16, |
935 |
prevMB->sad16))); |
prevMB->sad16))); |
|
} |
|
936 |
} else { |
} else { |
937 |
stat_thresh = MIN((&pMBs[(x-1) + y * pParam->mb_width])->sad16, |
stat_thresh = MIN((&pMBs[(x-1) + y * pParam->mb_width])->sad16, |
938 |
MIN((&pMBs[x + (y-1) * pParam->mb_width])->sad16, |
MIN((&pMBs[x + (y-1) * pParam->mb_width])->sad16, |
940 |
prevMB->sad16))); |
prevMB->sad16))); |
941 |
} |
} |
942 |
} |
} |
943 |
|
} |
944 |
|
|
945 |
/* favorize (0,0) vector for cartoons */ |
/* favorize (0,0) vector for cartoons */ |
946 |
if ((current->vop_flags & XVID_VOP_CARTOON) && |
if ((current->vop_flags & XVID_VOP_CARTOON) && |