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_pvop.c,v 1.1.2.2 2003-09-30 18:20:31 edgomez Exp $ |
* $Id: estimation_pvop.c,v 1.1.2.11 2003-12-18 02:02:08 Isibaar Exp $ |
25 |
* |
* |
26 |
****************************************************************************/ |
****************************************************************************/ |
27 |
|
|
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 |
{ |
{ |
|
int xc, yc; |
|
65 |
const uint8_t * Reference; |
const uint8_t * Reference; |
|
VECTOR * current; |
|
66 |
int32_t sad; uint32_t t; |
int32_t sad; uint32_t t; |
67 |
|
|
68 |
if ( (x > data->max_dx) || (x < data->min_dx) |
if ( (x > data->max_dx) || (x < data->min_dx) |
69 |
|| (y > data->max_dy) || (y < data->min_dy) ) return; |
|| (y > data->max_dy) || (y < data->min_dy) ) return; |
70 |
|
|
|
if (!data->qpel_precision) { |
|
71 |
Reference = GetReference(x, y, data); |
Reference = GetReference(x, y, data); |
|
current = data->currentMV; |
|
|
xc = x; yc = y; |
|
|
} else { /* x and y are in 1/4 precision */ |
|
|
Reference = xvid_me_interpolate16x16qpel(x, y, 0, data); |
|
|
xc = x/2; yc = y/2; /* for chroma sad */ |
|
|
current = data->currentQMV; |
|
|
} |
|
72 |
|
|
73 |
sad = sad16v(data->Cur, Reference, data->iEdgedWidth, data->temp); |
sad = sad16v(data->Cur, Reference, data->iEdgedWidth, data->temp); |
74 |
t = d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0); |
t = d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel, 0); |
75 |
|
|
76 |
sad += (data->lambda16 * t * sad)>>10; |
sad += (data->lambda16 * t * sad)>>10; |
77 |
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; |
78 |
|
|
79 |
if (data->chroma && sad < data->iMinSAD[0]) |
if (data->chroma) { |
80 |
sad += xvid_me_ChromaSAD((xc >> 1) + roundtab_79[xc & 0x3], |
if (sad >= data->iMinSAD[0]) goto no16; |
81 |
(yc >> 1) + roundtab_79[yc & 0x3], data); |
sad += xvid_me_ChromaSAD((x >> 1) + roundtab_79[x & 0x3], |
82 |
|
(y >> 1) + roundtab_79[y & 0x3], data); |
83 |
|
} |
84 |
|
|
85 |
if (sad < data->iMinSAD[0]) { |
if (sad < data->iMinSAD[0]) { |
86 |
data->iMinSAD[0] = sad; |
data->iMinSAD[0] = sad; |
87 |
current[0].x = x; current[0].y = y; |
data->currentMV[0].x = x; data->currentMV[0].y = y; |
88 |
*data->dir = Direction; |
data->dir = Direction; |
89 |
} |
} |
90 |
|
|
91 |
|
no16: |
92 |
if (data->temp[0] < data->iMinSAD[1]) { |
if (data->temp[0] < data->iMinSAD[1]) { |
93 |
data->iMinSAD[1] = data->temp[0]; current[1].x = x; current[1].y = y; } |
data->iMinSAD[1] = data->temp[0]; data->currentMV[1].x = x; data->currentMV[1].y = y; } |
94 |
if (data->temp[1] < data->iMinSAD[2]) { |
if (data->temp[1] < data->iMinSAD[2]) { |
95 |
data->iMinSAD[2] = data->temp[1]; current[2].x = x; current[2].y = y; } |
data->iMinSAD[2] = data->temp[1]; data->currentMV[2].x = x; data->currentMV[2].y = y; } |
96 |
if (data->temp[2] < data->iMinSAD[3]) { |
if (data->temp[2] < data->iMinSAD[3]) { |
97 |
data->iMinSAD[3] = data->temp[2]; current[3].x = x; current[3].y = y; } |
data->iMinSAD[3] = data->temp[2]; data->currentMV[3].x = x; data->currentMV[3].y = y; } |
98 |
if (data->temp[3] < data->iMinSAD[4]) { |
if (data->temp[3] < data->iMinSAD[4]) { |
99 |
data->iMinSAD[4] = data->temp[3]; current[4].x = x; current[4].y = y; } |
data->iMinSAD[4] = data->temp[3]; data->currentMV[4].x = x; data->currentMV[4].y = y; } |
100 |
} |
} |
101 |
|
|
102 |
static void |
static void |
103 |
CheckCandidate16_subpel(const int x, const int y, const SearchData * const data, const unsigned int Direction) |
CheckCandidate16_qpel(const int x, const int y, SearchData * const data, const unsigned int Direction) |
104 |
{ |
{ |
|
int xc, yc; |
|
105 |
const uint8_t *Reference; |
const uint8_t *Reference; |
|
VECTOR *current, *current2; |
|
106 |
int32_t sad; uint32_t t; |
int32_t sad; uint32_t t; |
107 |
|
|
108 |
if ( (x > data->max_dx) || (x < data->min_dx) |
if ( (x > data->max_dx) || (x < data->min_dx) |
109 |
|| (y > data->max_dy) || (y < data->min_dy) ) return; |
|| (y > data->max_dy) || (y < data->min_dy) ) return; |
110 |
|
|
|
if (!data->qpel_precision) { |
|
|
Reference = GetReference(x, y, data); |
|
|
current = data->currentMV; |
|
|
current2 = data->currentMV2; |
|
|
xc = x; yc = y; |
|
|
} else { /* x and y are in 1/4 precision */ |
|
111 |
Reference = xvid_me_interpolate16x16qpel(x, y, 0, data); |
Reference = xvid_me_interpolate16x16qpel(x, y, 0, data); |
|
xc = x/2; yc = y/2; /* for chroma sad */ |
|
|
current = data->currentQMV; |
|
|
current2 = data->currentQMV2; |
|
|
} |
|
112 |
|
|
113 |
sad = sad16v(data->Cur, Reference, data->iEdgedWidth, data->temp); |
sad = sad16v(data->Cur, Reference, data->iEdgedWidth, data->temp); |
114 |
t = d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0); |
t = d_mv_bits(x, y, data->predMV, data->iFcode, 0, 0); |
115 |
|
|
116 |
sad += (data->lambda16 * t * sad)>>10; |
sad += (data->lambda16 * t * sad)>>10; |
117 |
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; |
118 |
|
|
119 |
if (data->chroma && sad < data->iMinSAD[0]) |
if (data->chroma && (sad < data->iMinSAD[0] || sad < data->iMinSAD2) ) |
120 |
sad += xvid_me_ChromaSAD((xc >> 1) + roundtab_79[xc & 0x3], |
sad += xvid_me_ChromaSAD(((x/2) >> 1) + roundtab_79[(x/2) & 0x3], |
121 |
(yc >> 1) + roundtab_79[yc & 0x3], data); |
((y/2) >> 1) + roundtab_79[(y/2) & 0x3], data); |
122 |
|
|
123 |
if (data->temp[0] < data->iMinSAD[1]) { |
if (data->temp[0] < data->iMinSAD[1]) { |
124 |
data->iMinSAD[1] = data->temp[0]; current[1].x = x; current[1].y = y; } |
data->iMinSAD[1] = data->temp[0]; data->currentQMV[1].x = x; data->currentQMV[1].y = y; } |
125 |
if (data->temp[1] < data->iMinSAD[2]) { |
if (data->temp[1] < data->iMinSAD[2]) { |
126 |
data->iMinSAD[2] = data->temp[1]; current[2].x = x; current[2].y = y; } |
data->iMinSAD[2] = data->temp[1]; data->currentQMV[2].x = x; data->currentQMV[2].y = y; } |
127 |
if (data->temp[2] < data->iMinSAD[3]) { |
if (data->temp[2] < data->iMinSAD[3]) { |
128 |
data->iMinSAD[3] = data->temp[2]; current[3].x = x; current[3].y = y; } |
data->iMinSAD[3] = data->temp[2]; data->currentQMV[3].x = x; data->currentQMV[3].y = y; } |
129 |
if (data->temp[3] < data->iMinSAD[4]) { |
if (data->temp[3] < data->iMinSAD[4]) { |
130 |
data->iMinSAD[4] = data->temp[3]; current[4].x = x; current[4].y = y; } |
data->iMinSAD[4] = data->temp[3]; data->currentQMV[4].x = x; data->currentQMV[4].y = y; } |
131 |
|
|
132 |
if (sad < data->iMinSAD[0]) { |
if (sad < data->iMinSAD[0]) { |
133 |
*(data->iMinSAD2) = *(data->iMinSAD); |
data->iMinSAD2 = *(data->iMinSAD); |
134 |
current2->x = current->x; current2->y = current->y; |
data->currentQMV2.x = data->currentQMV->x; |
135 |
|
data->currentQMV2.y = data->currentQMV->y; |
136 |
|
|
137 |
data->iMinSAD[0] = sad; |
data->iMinSAD[0] = sad; |
138 |
current[0].x = x; current[0].y = y; |
data->currentQMV[0].x = x; data->currentQMV[0].y = y; |
139 |
*data->dir = Direction; |
} else if (sad < data->iMinSAD2) { |
140 |
return; |
data->iMinSAD2 = sad; |
141 |
} |
data->currentQMV2.x = x; data->currentQMV2.y = y; |
|
|
|
|
if (sad < *(data->iMinSAD2)) { |
|
|
*(data->iMinSAD2) = sad; |
|
|
current2->x = x; current2->y = y; |
|
|
*data->dir = Direction; |
|
142 |
} |
} |
143 |
} |
} |
144 |
|
|
145 |
static void |
static void |
146 |
CheckCandidate8(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) |
147 |
{ |
{ |
148 |
int32_t sad; uint32_t t; |
int32_t sad; uint32_t t; |
149 |
const uint8_t * Reference; |
const uint8_t * Reference; |
168 |
if (sad < *(data->iMinSAD)) { |
if (sad < *(data->iMinSAD)) { |
169 |
*(data->iMinSAD) = sad; |
*(data->iMinSAD) = sad; |
170 |
current->x = x; current->y = y; |
current->x = x; current->y = y; |
171 |
*data->dir = Direction; |
data->dir = Direction; |
172 |
} |
} |
173 |
} |
} |
174 |
|
|
175 |
static void |
static void |
176 |
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) |
177 |
{ |
{ |
178 |
uint32_t t; |
uint32_t t; |
179 |
const uint8_t * Reference; |
const uint8_t * Reference; |
194 |
if (sad < data->iMinSAD[0]) { |
if (sad < data->iMinSAD[0]) { |
195 |
data->iMinSAD[0] = sad; |
data->iMinSAD[0] = sad; |
196 |
data->currentMV[0].x = x; data->currentMV[0].y = y; |
data->currentMV[0].x = x; data->currentMV[0].y = y; |
197 |
*data->dir = Direction; |
data->dir = Direction; |
198 |
} |
} |
199 |
|
|
200 |
if (data->temp[0] < data->iMinSAD[1]) { |
if (data->temp[0] < data->iMinSAD[1]) { |
207 |
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; } |
208 |
} |
} |
209 |
|
|
|
static void |
|
|
SubpelRefine_Fast(SearchData * data, CheckFunc * CheckCandidate) |
|
|
{ |
|
|
/* Do a half-pel or q-pel refinement */ |
|
|
VECTOR centerMV; |
|
|
VECTOR second_best; |
|
|
int best_sad = *data->iMinSAD; |
|
|
int xo, yo, xo2, yo2; |
|
|
int size = 2; |
|
|
CheckFunc *backupFunc = CheckCandidate; |
|
|
|
|
|
if(data->qpel_precision) |
|
|
size = 1; |
|
|
|
|
|
centerMV = *data->currentMV; |
|
|
*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->currentMV; |
|
|
|
|
|
if(data->qpel_precision) { |
|
|
second_best.x *= 2; second_best.y *= 2; |
|
|
} |
|
|
|
|
|
data->currentMV[0] = centerMV; |
|
|
*data->iMinSAD = best_sad; |
|
|
|
|
|
centerMV = data->qpel_precision ? *data->currentQMV : *data->currentMV; |
|
|
|
|
|
xo = centerMV.x; |
|
|
yo = centerMV.y; |
|
|
xo2 = second_best.x; |
|
|
yo2 = second_best.y; |
|
|
|
|
|
CheckCandidate = CheckCandidate16_subpel; |
|
|
*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) |
|
|
goto ende; |
|
|
|
|
|
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); |
|
|
goto ende; |
|
|
} |
|
|
else { |
|
|
CHECK_CANDIDATE((xo+xo2)>>1, |
|
|
(data->currentQMV[0].x == xo) ? data->currentQMV[0].y : data->currentQMV2[0].y, |
|
|
0); |
|
|
goto ende; |
|
|
} |
|
|
} |
|
|
|
|
|
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) |
|
|
goto ende; |
|
|
|
|
|
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); |
|
|
goto ende; |
|
|
} |
|
|
else { |
|
|
CHECK_CANDIDATE((data->currentQMV[0].y == yo) ? data->currentQMV[0].x : data->currentQMV2[0].x, (yo+yo2)>>1, 0); |
|
|
goto ende; |
|
|
} |
|
|
} |
|
|
|
|
|
CHECK_CANDIDATE(xo, (yo+yo2)>>1, 0); |
|
|
CHECK_CANDIDATE((xo+xo2)>>1, yo, 0); |
|
|
|
|
|
if(best_sad <= *data->iMinSAD2) |
|
|
goto ende; |
|
|
|
|
|
CHECK_CANDIDATE((xo+xo2)>>1, (yo+yo2)>>1, 0); |
|
|
|
|
|
ende: |
|
|
CheckCandidate = backupFunc; |
|
|
} |
|
|
|
|
210 |
int |
int |
211 |
xvid_me_SkipDecisionP(const IMAGE * current, const IMAGE * reference, |
xvid_me_SkipDecisionP(const IMAGE * current, const IMAGE * reference, |
212 |
const int x, const int y, |
const int x, const int y, |
246 |
* [3]: topright neighbour's SAD |
* [3]: topright neighbour's SAD |
247 |
*/ |
*/ |
248 |
|
|
249 |
static __inline int |
static __inline void |
250 |
get_pmvdata2(const MACROBLOCK * const mbs, |
get_pmvdata2(const MACROBLOCK * const mbs, |
251 |
const int mb_width, |
const int mb_width, |
252 |
const int bound, |
const int bound, |
253 |
const int x, |
const int x, |
254 |
const int y, |
const int y, |
|
const int block, |
|
255 |
VECTOR * const pmv, |
VECTOR * const pmv, |
256 |
int32_t * const psad) |
int32_t * const psad) |
257 |
{ |
{ |
261 |
int lpos, tpos, rpos; |
int lpos, tpos, rpos; |
262 |
int num_cand = 0, last_cand = 1; |
int num_cand = 0, last_cand = 1; |
263 |
|
|
|
switch (block) { |
|
|
case 0: |
|
264 |
lx = x - 1; ly = y; lz = 1; |
lx = x - 1; ly = y; lz = 1; |
265 |
tx = x; ty = y - 1; tz = 2; |
tx = x; ty = y - 1; tz = 2; |
266 |
rx = x + 1; ry = y - 1; rz = 2; |
rx = x + 1; ry = y - 1; rz = 2; |
|
break; |
|
|
case 1: |
|
|
lx = x; ly = y; lz = 0; |
|
|
tx = x; ty = y - 1; tz = 3; |
|
|
rx = x + 1; ry = y - 1; rz = 2; |
|
|
break; |
|
|
case 2: |
|
|
lx = x - 1; ly = y; lz = 3; |
|
|
tx = x; ty = y; tz = 0; |
|
|
rx = x; ry = y; rz = 1; |
|
|
break; |
|
|
default: |
|
|
lx = x; ly = y; lz = 2; |
|
|
tx = x; ty = y; tz = 0; |
|
|
rx = x; ry = y; rz = 1; |
|
|
} |
|
267 |
|
|
268 |
lpos = lx + ly * mb_width; |
lpos = lx + ly * mb_width; |
269 |
rpos = rx + ry * mb_width; |
rpos = rx + ry * mb_width; |
300 |
} |
} |
301 |
|
|
302 |
/* original pmvdata() compatibility hack */ |
/* original pmvdata() compatibility hack */ |
303 |
if (x == 0 && y == 0 && block == 0) { |
if (x == 0 && y == 0) { |
304 |
pmv[0] = pmv[1] = pmv[2] = pmv[3] = zeroMV; |
pmv[0] = pmv[1] = pmv[2] = pmv[3] = zeroMV; |
305 |
psad[0] = 0; |
psad[0] = 0; |
306 |
psad[1] = psad[2] = psad[3] = MV_MAX_ERROR; |
psad[1] = psad[2] = psad[3] = MV_MAX_ERROR; |
307 |
return 0; |
return; |
308 |
} |
} |
309 |
|
|
310 |
/* 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 */ |
311 |
if (num_cand == 1) { |
if (num_cand == 1) { |
312 |
pmv[0] = pmv[last_cand]; |
pmv[0] = pmv[last_cand]; |
313 |
psad[0] = psad[last_cand]; |
psad[0] = psad[last_cand]; |
314 |
#if 0 |
return; |
|
return MVequal(pmv[0], zeroMV); /* no point calculating median mv and minimum sad */ |
|
|
#endif |
|
|
|
|
|
/* original pmvdata() compatibility hack */ |
|
|
return y==0 && block <= 1 ? 0 : MVequal(pmv[0], zeroMV); |
|
315 |
} |
} |
316 |
|
|
317 |
if ((MVequal(pmv[1], pmv[2])) && (MVequal(pmv[1], pmv[3]))) { |
if ((MVequal(pmv[1], pmv[2])) && (MVequal(pmv[1], pmv[3]))) { |
318 |
pmv[0] = pmv[1]; |
pmv[0] = pmv[1]; |
319 |
psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]); |
psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]); |
320 |
return 1; |
return; |
321 |
} |
} |
322 |
|
|
323 |
/* set median, minimum */ |
/* set median, minimum */ |
331 |
|
|
332 |
psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]); |
psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]); |
333 |
|
|
|
return 0; |
|
334 |
} |
} |
335 |
|
|
336 |
|
|
399 |
|
|
400 |
/* intra decision */ |
/* intra decision */ |
401 |
|
|
402 |
if (iQuant > 8) InterBias += 100 * (iQuant - 8); /* to make high quants work */ |
if (iQuant > 10) InterBias += 60 * (iQuant - 10); /* to make high quants work */ |
403 |
if (y != 0) |
if (y != 0) |
404 |
if ((pMB - pParam->mb_width)->mode == MODE_INTRA ) InterBias -= 80; |
if ((pMB - pParam->mb_width)->mode == MODE_INTRA ) InterBias -= 80; |
405 |
if (x != 0) |
if (x != 0) |
501 |
} |
} |
502 |
|
|
503 |
static void |
static void |
504 |
Search8(const SearchData * const OldData, |
Search8(SearchData * const OldData, |
505 |
const int x, const int y, |
const int x, const int y, |
506 |
const uint32_t MotionFlags, |
const uint32_t MotionFlags, |
507 |
const MBParam * const pParam, |
const MBParam * const pParam, |
512 |
{ |
{ |
513 |
int i = 0; |
int i = 0; |
514 |
CheckFunc * CheckCandidate; |
CheckFunc * CheckCandidate; |
515 |
Data->iMinSAD = OldData->iMinSAD + 1 + block; |
*Data->iMinSAD = *(OldData->iMinSAD + 1 + block); |
516 |
Data->currentMV = OldData->currentMV + 1 + block; |
*Data->currentMV = *(OldData->currentMV + 1 + block); |
517 |
Data->currentQMV = OldData->currentQMV + 1 + block; |
*Data->currentQMV = *(OldData->currentQMV + 1 + block); |
518 |
|
|
519 |
if(Data->qpel) { |
if(Data->qpel) { |
520 |
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); |
595 |
pMB->pmvs[block].y = Data->currentMV->y - Data->predMV.y; |
pMB->pmvs[block].y = Data->currentMV->y - Data->predMV.y; |
596 |
} |
} |
597 |
|
|
598 |
|
*(OldData->iMinSAD + 1 + block) = *Data->iMinSAD; |
599 |
|
*(OldData->currentMV + 1 + block) = *Data->currentMV; |
600 |
|
*(OldData->currentQMV + 1 + block) = *Data->currentQMV; |
601 |
|
|
602 |
pMB->mvs[block] = *Data->currentMV; |
pMB->mvs[block] = *Data->currentMV; |
603 |
pMB->sad8[block] = 4 * *Data->iMinSAD; |
pMB->sad8[block] = 4 * *Data->iMinSAD; |
604 |
} |
} |
630 |
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, |
631 |
pParam->width, pParam->height, Data->iFcode - Data->qpel, 1, Data->rrv); |
pParam->width, pParam->height, Data->iFcode - Data->qpel, 1, Data->rrv); |
632 |
|
|
633 |
get_pmvdata2(pMBs, pParam->mb_width, 0, x, y, 0, pmv, Data->temp); |
get_pmvdata2(pMBs, pParam->mb_width, 0, x, y, pmv, Data->temp); |
634 |
|
|
635 |
Data->temp[5] = Data->temp[6] = 0; /* chroma-sad cache */ |
Data->chromaX = Data->chromaY = 0; /* chroma-sad cache */ |
636 |
i = Data->rrv ? 2 : 1; |
i = Data->rrv ? 2 : 1; |
637 |
Data->Cur = pCur->y + (x + y * Data->iEdgedWidth) * 16*i; |
Data->Cur = pCur->y + (x + y * Data->iEdgedWidth) * 16*i; |
638 |
Data->CurV = pCur->v + (x + y * (Data->iEdgedWidth/2)) * 8*i; |
Data->CurV = pCur->v + (x + y * (Data->iEdgedWidth/2)) * 8*i; |
648 |
Data->lambda16 = xvid_me_lambda_vec16[pMB->quant]; |
Data->lambda16 = xvid_me_lambda_vec16[pMB->quant]; |
649 |
Data->lambda8 = xvid_me_lambda_vec8[pMB->quant]; |
Data->lambda8 = xvid_me_lambda_vec8[pMB->quant]; |
650 |
Data->qpel_precision = 0; |
Data->qpel_precision = 0; |
651 |
*Data->dir = 0; |
Data->dir = 0; |
652 |
|
|
653 |
memset(Data->currentMV, 0, 5*sizeof(VECTOR)); |
memset(Data->currentMV, 0, 5*sizeof(VECTOR)); |
654 |
|
|
692 |
else { |
else { |
693 |
|
|
694 |
MainSearchFunc * MainSearchPtr; |
MainSearchFunc * MainSearchPtr; |
695 |
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 */ |
696 |
|
|
697 |
if (MotionFlags & XVID_ME_USESQUARES16) MainSearchPtr = xvid_me_SquareSearch; |
if (MotionFlags & XVID_ME_USESQUARES16) MainSearchPtr = xvid_me_SquareSearch; |
698 |
else if (MotionFlags & XVID_ME_ADVANCEDDIAMOND16) MainSearchPtr = xvid_me_AdvDiamondSearch; |
else if (MotionFlags & XVID_ME_ADVANCEDDIAMOND16) MainSearchPtr = xvid_me_AdvDiamondSearch; |
707 |
if (MotionFlags & XVID_ME_EXTSEARCH16) { |
if (MotionFlags & XVID_ME_EXTSEARCH16) { |
708 |
int32_t bSAD; |
int32_t bSAD; |
709 |
VECTOR startMV = Data->predMV, backupMV = Data->currentMV[0]; |
VECTOR startMV = Data->predMV, backupMV = Data->currentMV[0]; |
710 |
if (Data->rrv) { |
if (Data->qpel) { |
711 |
|
startMV.x /= 2; |
712 |
|
startMV.y /= 2; |
713 |
|
} else if (Data->rrv) { |
714 |
startMV.x = RRV_MV_SCALEUP(startMV.x); |
startMV.x = RRV_MV_SCALEUP(startMV.x); |
715 |
startMV.y = RRV_MV_SCALEUP(startMV.y); |
startMV.y = RRV_MV_SCALEUP(startMV.y); |
716 |
} |
} |
718 |
bSAD = Data->iMinSAD[0]; Data->iMinSAD[0] = MV_MAX_ERROR; |
bSAD = Data->iMinSAD[0]; Data->iMinSAD[0] = MV_MAX_ERROR; |
719 |
|
|
720 |
CheckCandidate(startMV.x, startMV.y, Data, 255); |
CheckCandidate(startMV.x, startMV.y, Data, 255); |
721 |
MainSearchPtr(startMV.x, startMV.y, Data, 255, CheckCandidate); |
xvid_me_DiamondSearch(startMV.x, startMV.y, Data, 255, CheckCandidate); |
722 |
if (bSAD < Data->iMinSAD[0]) { |
if (bSAD < Data->iMinSAD[0]) { |
723 |
Data->currentMV[0] = backupMV; |
Data->currentMV[0] = backupMV; |
724 |
Data->iMinSAD[0] = bSAD; } |
Data->iMinSAD[0] = bSAD; } |
730 |
bSAD = Data->iMinSAD[0]; Data->iMinSAD[0] = MV_MAX_ERROR; |
bSAD = Data->iMinSAD[0]; Data->iMinSAD[0] = MV_MAX_ERROR; |
731 |
|
|
732 |
CheckCandidate(startMV.x, startMV.y, Data, 255); |
CheckCandidate(startMV.x, startMV.y, Data, 255); |
733 |
MainSearchPtr(startMV.x, startMV.y, Data, 255, CheckCandidate); |
xvid_me_DiamondSearch(startMV.x, startMV.y, Data, 255, CheckCandidate); |
734 |
if (bSAD < Data->iMinSAD[0]) { |
if (bSAD < Data->iMinSAD[0]) { |
735 |
Data->currentMV[0] = backupMV; |
Data->currentMV[0] = backupMV; |
736 |
Data->iMinSAD[0] = bSAD; |
Data->iMinSAD[0] = bSAD; |
753 |
Data->qpel_precision = 1; |
Data->qpel_precision = 1; |
754 |
if (MotionFlags & XVID_ME_QUARTERPELREFINE16) { |
if (MotionFlags & XVID_ME_QUARTERPELREFINE16) { |
755 |
if(MotionFlags & XVID_ME_FASTREFINE16) |
if(MotionFlags & XVID_ME_FASTREFINE16) |
756 |
SubpelRefine_Fast(Data, CheckCandidate); |
SubpelRefine_Fast(Data, CheckCandidate16_qpel); |
757 |
else |
else |
758 |
xvid_me_SubpelRefine(Data, CheckCandidate); |
xvid_me_SubpelRefine(Data, CheckCandidate16_qpel); |
759 |
} |
} |
760 |
} |
} |
761 |
|
|
857 |
(current->vop_flags & XVID_VOP_MODEDECISION_RD ? 2:1); |
(current->vop_flags & XVID_VOP_MODEDECISION_RD ? 2:1); |
858 |
|
|
859 |
/* 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 currentMV2[5]; |
|
|
VECTOR currentQMV2[5]; |
|
|
int32_t iMinSAD[5]; |
|
|
int32_t iMinSAD2[5]; |
|
860 |
DECLARE_ALIGNED_MATRIX(dct_space, 3, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(dct_space, 3, 64, int16_t, CACHE_LINE); |
861 |
SearchData Data; |
SearchData Data; |
862 |
memset(&Data, 0, sizeof(SearchData)); |
memset(&Data, 0, sizeof(SearchData)); |
863 |
Data.iEdgedWidth = iEdgedWidth; |
Data.iEdgedWidth = iEdgedWidth; |
|
Data.currentMV = currentMV; |
|
|
Data.currentQMV = currentQMV; |
|
|
Data.currentMV2 = currentMV2; |
|
|
Data.currentQMV2 = currentQMV2; |
|
|
Data.iMinSAD = iMinSAD; |
|
|
Data.iMinSAD2 = iMinSAD2; |
|
|
Data.temp = temp; |
|
|
Data.dir = &dir; |
|
864 |
Data.iFcode = current->fcode; |
Data.iFcode = current->fcode; |
865 |
Data.rounding = pParam->m_rounding_type; |
Data.rounding = pParam->m_rounding_type; |
866 |
Data.qpel = (current->vol_flags & XVID_VOL_QUARTERPEL ? 1:0); |
Data.qpel = (current->vol_flags & XVID_VOL_QUARTERPEL ? 1:0); |
868 |
Data.rrv = (current->vop_flags & XVID_VOP_REDUCED) ? 1:0; |
Data.rrv = (current->vop_flags & XVID_VOP_REDUCED) ? 1:0; |
869 |
Data.dctSpace = dct_space; |
Data.dctSpace = dct_space; |
870 |
Data.quant_type = !(pParam->vol_flags & XVID_VOL_MPEGQUANT); |
Data.quant_type = !(pParam->vol_flags & XVID_VOL_MPEGQUANT); |
871 |
|
Data.mpeg_quant_matrices = pParam->mpeg_quant_matrices; |
872 |
|
Data.iMinSAD2 = 0; |
873 |
|
|
874 |
if ((current->vop_flags & XVID_VOP_REDUCED)) { |
if ((current->vop_flags & XVID_VOP_REDUCED)) { |
875 |
mb_width = (pParam->width + 31) / 32; |
mb_width = (pParam->width + 31) / 32; |
896 |
pParam->edged_width, pMB->sad8 ); |
pParam->edged_width, pMB->sad8 ); |
897 |
|
|
898 |
if (Data.chroma) { |
if (Data.chroma) { |
899 |
Data.temp[7] = sad8(pCurrent->u + x*8 + y*(iEdgedWidth/2)*8, |
Data.chromaSAD = sad8(pCurrent->u + x*8 + y*(iEdgedWidth/2)*8, |
900 |
pRef->u + x*8 + y*(iEdgedWidth/2)*8, iEdgedWidth/2) |
pRef->u + x*8 + y*(iEdgedWidth/2)*8, iEdgedWidth/2) |
901 |
+ sad8(pCurrent->v + (x + y*(iEdgedWidth/2))*8, |
+ sad8(pCurrent->v + (x + y*(iEdgedWidth/2))*8, |
902 |
pRef->v + (x + y*(iEdgedWidth/2))*8, iEdgedWidth/2); |
pRef->v + (x + y*(iEdgedWidth/2))*8, iEdgedWidth/2); |
903 |
pMB->sad16 += Data.temp[7]; |
pMB->sad16 += Data.chromaSAD; |
904 |
} |
} |
905 |
|
|
906 |
sad00 = pMB->sad16; |
sad00 = pMB->sad16; |
926 |
MAX((&pMBs[x + (y-1) * pParam->mb_width])->sad16, |
MAX((&pMBs[x + (y-1) * pParam->mb_width])->sad16, |
927 |
MAX((&pMBs[(x+1) + (y-1) * pParam->mb_width])->sad16, |
MAX((&pMBs[(x+1) + (y-1) * pParam->mb_width])->sad16, |
928 |
prevMB->sad16))); |
prevMB->sad16))); |
|
} |
|
929 |
} else { |
} else { |
930 |
stat_thresh = MIN((&pMBs[(x-1) + y * pParam->mb_width])->sad16, |
stat_thresh = MIN((&pMBs[(x-1) + y * pParam->mb_width])->sad16, |
931 |
MIN((&pMBs[x + (y-1) * pParam->mb_width])->sad16, |
MIN((&pMBs[x + (y-1) * pParam->mb_width])->sad16, |
933 |
prevMB->sad16))); |
prevMB->sad16))); |
934 |
} |
} |
935 |
} |
} |
936 |
|
} |
937 |
|
|
938 |
/* favorize (0,0) vector for cartoons */ |
/* favorize (0,0) vector for cartoons */ |
939 |
if ((current->vop_flags & XVID_VOP_CARTOON) && |
if ((current->vop_flags & XVID_VOP_CARTOON) && |