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.10 2003-12-03 11:51:28 syskin 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]) { |
210 |
static void |
static void |
211 |
SubpelRefine_Fast(SearchData * data, CheckFunc * CheckCandidate) |
SubpelRefine_Fast(SearchData * data, CheckFunc * CheckCandidate) |
212 |
{ |
{ |
213 |
/* Do a half-pel or q-pel refinement */ |
/* Do a fast q-pel refinement */ |
214 |
VECTOR centerMV; |
VECTOR centerMV; |
215 |
VECTOR second_best; |
VECTOR second_best; |
216 |
int best_sad = *data->iMinSAD; |
int best_sad = *data->iMinSAD; |
217 |
int xo, yo, xo2, yo2; |
int xo, yo, xo2, yo2; |
218 |
int size = 2; |
int size = 2; |
219 |
CheckFunc *backupFunc = CheckCandidate; |
data->iMinSAD2 = 0; |
|
|
|
|
if(data->qpel_precision) |
|
|
size = 1; |
|
220 |
|
|
221 |
centerMV = *data->currentMV; |
/* check all halfpixel positions near our best halfpel position */ |
222 |
|
centerMV = *data->currentQMV; |
223 |
*data->iMinSAD = 256 * 4096; |
*data->iMinSAD = 256 * 4096; |
224 |
|
|
225 |
CHECK_CANDIDATE(centerMV.x, centerMV.y - size, 0); |
CHECK_CANDIDATE(centerMV.x, centerMV.y - size, 0); |
232 |
CHECK_CANDIDATE(centerMV.x - size, centerMV.y, 0); |
CHECK_CANDIDATE(centerMV.x - size, centerMV.y, 0); |
233 |
CHECK_CANDIDATE(centerMV.x - size, centerMV.y - size, 0); |
CHECK_CANDIDATE(centerMV.x - size, centerMV.y - size, 0); |
234 |
|
|
235 |
second_best = *data->currentMV; |
second_best = *data->currentQMV; |
236 |
|
|
237 |
if(data->qpel_precision) { |
/* after second_best has been found, go back to the vector we began with */ |
|
second_best.x *= 2; second_best.y *= 2; |
|
|
} |
|
238 |
|
|
239 |
data->currentMV[0] = centerMV; |
data->currentQMV[0] = centerMV; |
240 |
*data->iMinSAD = best_sad; |
*data->iMinSAD = best_sad; |
241 |
|
|
|
centerMV = data->qpel_precision ? *data->currentQMV : *data->currentMV; |
|
|
|
|
242 |
xo = centerMV.x; |
xo = centerMV.x; |
243 |
yo = centerMV.y; |
yo = centerMV.y; |
244 |
xo2 = second_best.x; |
xo2 = second_best.x; |
245 |
yo2 = second_best.y; |
yo2 = second_best.y; |
246 |
|
|
247 |
CheckCandidate = CheckCandidate16_subpel; |
data->iMinSAD2 = 256 * 4096; |
|
*data->iMinSAD2 = 256 * 4096; |
|
248 |
|
|
249 |
if (yo == yo2) |
if (yo == yo2) { |
|
{ |
|
250 |
CHECK_CANDIDATE((xo+xo2)>>1, yo, 0); |
CHECK_CANDIDATE((xo+xo2)>>1, yo, 0); |
251 |
CHECK_CANDIDATE(xo, yo-1, 0); |
CHECK_CANDIDATE(xo, yo-1, 0); |
252 |
CHECK_CANDIDATE(xo, yo+1, 0); |
CHECK_CANDIDATE(xo, yo+1, 0); |
253 |
|
|
254 |
if(best_sad <= *data->iMinSAD2) |
if(best_sad <= data->iMinSAD2) return; |
|
goto ende; |
|
255 |
|
|
256 |
if(data->currentQMV[0].x == data->currentQMV2[0].x) { |
if(data->currentQMV[0].x == data->currentQMV2.x) { |
257 |
CHECK_CANDIDATE((xo+xo2)>>1, yo-1, 0); |
CHECK_CANDIDATE((xo+xo2)>>1, yo-1, 0); |
258 |
CHECK_CANDIDATE((xo+xo2)>>1, yo+1, 0); |
CHECK_CANDIDATE((xo+xo2)>>1, yo+1, 0); |
259 |
goto ende; |
} else { |
|
} |
|
|
else { |
|
260 |
CHECK_CANDIDATE((xo+xo2)>>1, |
CHECK_CANDIDATE((xo+xo2)>>1, |
261 |
(data->currentQMV[0].x == xo) ? data->currentQMV[0].y : data->currentQMV2[0].y, |
(data->currentQMV[0].x == xo) ? data->currentQMV[0].y : data->currentQMV2.y, 0); |
|
0); |
|
|
goto ende; |
|
262 |
} |
} |
263 |
|
return; |
264 |
} |
} |
265 |
|
|
266 |
if (xo == xo2) |
if (xo == xo2) { |
|
{ |
|
267 |
CHECK_CANDIDATE(xo, (yo+yo2)>>1, 0); |
CHECK_CANDIDATE(xo, (yo+yo2)>>1, 0); |
268 |
CHECK_CANDIDATE(xo-1, yo, 0); |
CHECK_CANDIDATE(xo-1, yo, 0); |
269 |
CHECK_CANDIDATE(xo+1, yo, 0); |
CHECK_CANDIDATE(xo+1, yo, 0); |
270 |
|
|
271 |
if(best_sad < *data->iMinSAD2) |
if(best_sad < data->iMinSAD2) return; |
|
goto ende; |
|
272 |
|
|
273 |
if(data->currentQMV[0].y == data->currentQMV2[0].y) { |
if(data->currentQMV[0].y == data->currentQMV2.y) { |
274 |
CHECK_CANDIDATE(xo-1, (yo+yo2)>>1, 0); |
CHECK_CANDIDATE(xo-1, (yo+yo2)>>1, 0); |
275 |
CHECK_CANDIDATE(xo+1, (yo+yo2)>>1, 0); |
CHECK_CANDIDATE(xo+1, (yo+yo2)>>1, 0); |
276 |
goto ende; |
} else { |
277 |
} |
CHECK_CANDIDATE((data->currentQMV[0].y == yo) ? data->currentQMV[0].x : data->currentQMV2.x, (yo+yo2)>>1, 0); |
|
else { |
|
|
CHECK_CANDIDATE((data->currentQMV[0].y == yo) ? data->currentQMV[0].x : data->currentQMV2[0].x, (yo+yo2)>>1, 0); |
|
|
goto ende; |
|
278 |
} |
} |
279 |
|
return; |
280 |
} |
} |
281 |
|
|
282 |
CHECK_CANDIDATE(xo, (yo+yo2)>>1, 0); |
CHECK_CANDIDATE(xo, (yo+yo2)>>1, 0); |
283 |
CHECK_CANDIDATE((xo+xo2)>>1, yo, 0); |
CHECK_CANDIDATE((xo+xo2)>>1, yo, 0); |
284 |
|
|
285 |
if(best_sad <= *data->iMinSAD2) |
if(best_sad <= data->iMinSAD2) return; |
|
goto ende; |
|
286 |
|
|
287 |
CHECK_CANDIDATE((xo+xo2)>>1, (yo+yo2)>>1, 0); |
CHECK_CANDIDATE((xo+xo2)>>1, (yo+yo2)>>1, 0); |
|
|
|
|
ende: |
|
|
CheckCandidate = backupFunc; |
|
288 |
} |
} |
289 |
|
|
290 |
int |
int |
326 |
* [3]: topright neighbour's SAD |
* [3]: topright neighbour's SAD |
327 |
*/ |
*/ |
328 |
|
|
329 |
static __inline int |
static __inline void |
330 |
get_pmvdata2(const MACROBLOCK * const mbs, |
get_pmvdata2(const MACROBLOCK * const mbs, |
331 |
const int mb_width, |
const int mb_width, |
332 |
const int bound, |
const int bound, |
333 |
const int x, |
const int x, |
334 |
const int y, |
const int y, |
|
const int block, |
|
335 |
VECTOR * const pmv, |
VECTOR * const pmv, |
336 |
int32_t * const psad) |
int32_t * const psad) |
337 |
{ |
{ |
341 |
int lpos, tpos, rpos; |
int lpos, tpos, rpos; |
342 |
int num_cand = 0, last_cand = 1; |
int num_cand = 0, last_cand = 1; |
343 |
|
|
|
switch (block) { |
|
|
case 0: |
|
344 |
lx = x - 1; ly = y; lz = 1; |
lx = x - 1; ly = y; lz = 1; |
345 |
tx = x; ty = y - 1; tz = 2; |
tx = x; ty = y - 1; tz = 2; |
346 |
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; |
|
|
} |
|
347 |
|
|
348 |
lpos = lx + ly * mb_width; |
lpos = lx + ly * mb_width; |
349 |
rpos = rx + ry * mb_width; |
rpos = rx + ry * mb_width; |
380 |
} |
} |
381 |
|
|
382 |
/* original pmvdata() compatibility hack */ |
/* original pmvdata() compatibility hack */ |
383 |
if (x == 0 && y == 0 && block == 0) { |
if (x == 0 && y == 0) { |
384 |
pmv[0] = pmv[1] = pmv[2] = pmv[3] = zeroMV; |
pmv[0] = pmv[1] = pmv[2] = pmv[3] = zeroMV; |
385 |
psad[0] = 0; |
psad[0] = 0; |
386 |
psad[1] = psad[2] = psad[3] = MV_MAX_ERROR; |
psad[1] = psad[2] = psad[3] = MV_MAX_ERROR; |
387 |
return 0; |
return; |
388 |
} |
} |
389 |
|
|
390 |
/* 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 */ |
391 |
if (num_cand == 1) { |
if (num_cand == 1) { |
392 |
pmv[0] = pmv[last_cand]; |
pmv[0] = pmv[last_cand]; |
393 |
psad[0] = psad[last_cand]; |
psad[0] = psad[last_cand]; |
394 |
#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); |
|
395 |
} |
} |
396 |
|
|
397 |
if ((MVequal(pmv[1], pmv[2])) && (MVequal(pmv[1], pmv[3]))) { |
if ((MVequal(pmv[1], pmv[2])) && (MVequal(pmv[1], pmv[3]))) { |
398 |
pmv[0] = pmv[1]; |
pmv[0] = pmv[1]; |
399 |
psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]); |
psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]); |
400 |
return 1; |
return; |
401 |
} |
} |
402 |
|
|
403 |
/* set median, minimum */ |
/* set median, minimum */ |
411 |
|
|
412 |
psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]); |
psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]); |
413 |
|
|
|
return 0; |
|
414 |
} |
} |
415 |
|
|
416 |
|
|
479 |
|
|
480 |
/* intra decision */ |
/* intra decision */ |
481 |
|
|
482 |
if (iQuant > 8) InterBias += 100 * (iQuant - 8); /* to make high quants work */ |
if (iQuant > 10) InterBias += 60 * (iQuant - 10); /* to make high quants work */ |
483 |
if (y != 0) |
if (y != 0) |
484 |
if ((pMB - pParam->mb_width)->mode == MODE_INTRA ) InterBias -= 80; |
if ((pMB - pParam->mb_width)->mode == MODE_INTRA ) InterBias -= 80; |
485 |
if (x != 0) |
if (x != 0) |
581 |
} |
} |
582 |
|
|
583 |
static void |
static void |
584 |
Search8(const SearchData * const OldData, |
Search8(SearchData * const OldData, |
585 |
const int x, const int y, |
const int x, const int y, |
586 |
const uint32_t MotionFlags, |
const uint32_t MotionFlags, |
587 |
const MBParam * const pParam, |
const MBParam * const pParam, |
592 |
{ |
{ |
593 |
int i = 0; |
int i = 0; |
594 |
CheckFunc * CheckCandidate; |
CheckFunc * CheckCandidate; |
595 |
Data->iMinSAD = OldData->iMinSAD + 1 + block; |
*Data->iMinSAD = *(OldData->iMinSAD + 1 + block); |
596 |
Data->currentMV = OldData->currentMV + 1 + block; |
*Data->currentMV = *(OldData->currentMV + 1 + block); |
597 |
Data->currentQMV = OldData->currentQMV + 1 + block; |
*Data->currentQMV = *(OldData->currentQMV + 1 + block); |
598 |
|
|
599 |
if(Data->qpel) { |
if(Data->qpel) { |
600 |
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); |
675 |
pMB->pmvs[block].y = Data->currentMV->y - Data->predMV.y; |
pMB->pmvs[block].y = Data->currentMV->y - Data->predMV.y; |
676 |
} |
} |
677 |
|
|
678 |
|
*(OldData->iMinSAD + 1 + block) = *Data->iMinSAD; |
679 |
|
*(OldData->currentMV + 1 + block) = *Data->currentMV; |
680 |
|
*(OldData->currentQMV + 1 + block) = *Data->currentQMV; |
681 |
|
|
682 |
pMB->mvs[block] = *Data->currentMV; |
pMB->mvs[block] = *Data->currentMV; |
683 |
pMB->sad8[block] = 4 * *Data->iMinSAD; |
pMB->sad8[block] = 4 * *Data->iMinSAD; |
684 |
} |
} |
710 |
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, |
711 |
pParam->width, pParam->height, Data->iFcode - Data->qpel, 1, Data->rrv); |
pParam->width, pParam->height, Data->iFcode - Data->qpel, 1, Data->rrv); |
712 |
|
|
713 |
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); |
714 |
|
|
715 |
Data->temp[5] = Data->temp[6] = 0; /* chroma-sad cache */ |
Data->chromaX = Data->chromaY = 0; /* chroma-sad cache */ |
716 |
i = Data->rrv ? 2 : 1; |
i = Data->rrv ? 2 : 1; |
717 |
Data->Cur = pCur->y + (x + y * Data->iEdgedWidth) * 16*i; |
Data->Cur = pCur->y + (x + y * Data->iEdgedWidth) * 16*i; |
718 |
Data->CurV = pCur->v + (x + y * (Data->iEdgedWidth/2)) * 8*i; |
Data->CurV = pCur->v + (x + y * (Data->iEdgedWidth/2)) * 8*i; |
728 |
Data->lambda16 = xvid_me_lambda_vec16[pMB->quant]; |
Data->lambda16 = xvid_me_lambda_vec16[pMB->quant]; |
729 |
Data->lambda8 = xvid_me_lambda_vec8[pMB->quant]; |
Data->lambda8 = xvid_me_lambda_vec8[pMB->quant]; |
730 |
Data->qpel_precision = 0; |
Data->qpel_precision = 0; |
731 |
*Data->dir = 0; |
Data->dir = 0; |
732 |
|
|
733 |
memset(Data->currentMV, 0, 5*sizeof(VECTOR)); |
memset(Data->currentMV, 0, 5*sizeof(VECTOR)); |
734 |
|
|
772 |
else { |
else { |
773 |
|
|
774 |
MainSearchFunc * MainSearchPtr; |
MainSearchFunc * MainSearchPtr; |
775 |
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 */ |
776 |
|
|
777 |
if (MotionFlags & XVID_ME_USESQUARES16) MainSearchPtr = xvid_me_SquareSearch; |
if (MotionFlags & XVID_ME_USESQUARES16) MainSearchPtr = xvid_me_SquareSearch; |
778 |
else if (MotionFlags & XVID_ME_ADVANCEDDIAMOND16) MainSearchPtr = xvid_me_AdvDiamondSearch; |
else if (MotionFlags & XVID_ME_ADVANCEDDIAMOND16) MainSearchPtr = xvid_me_AdvDiamondSearch; |
787 |
if (MotionFlags & XVID_ME_EXTSEARCH16) { |
if (MotionFlags & XVID_ME_EXTSEARCH16) { |
788 |
int32_t bSAD; |
int32_t bSAD; |
789 |
VECTOR startMV = Data->predMV, backupMV = Data->currentMV[0]; |
VECTOR startMV = Data->predMV, backupMV = Data->currentMV[0]; |
790 |
if (Data->rrv) { |
if (Data->qpel) { |
791 |
|
startMV.x /= 2; |
792 |
|
startMV.y /= 2; |
793 |
|
} else if (Data->rrv) { |
794 |
startMV.x = RRV_MV_SCALEUP(startMV.x); |
startMV.x = RRV_MV_SCALEUP(startMV.x); |
795 |
startMV.y = RRV_MV_SCALEUP(startMV.y); |
startMV.y = RRV_MV_SCALEUP(startMV.y); |
796 |
} |
} |
798 |
bSAD = Data->iMinSAD[0]; Data->iMinSAD[0] = MV_MAX_ERROR; |
bSAD = Data->iMinSAD[0]; Data->iMinSAD[0] = MV_MAX_ERROR; |
799 |
|
|
800 |
CheckCandidate(startMV.x, startMV.y, Data, 255); |
CheckCandidate(startMV.x, startMV.y, Data, 255); |
801 |
MainSearchPtr(startMV.x, startMV.y, Data, 255, CheckCandidate); |
xvid_me_DiamondSearch(startMV.x, startMV.y, Data, 255, CheckCandidate); |
802 |
if (bSAD < Data->iMinSAD[0]) { |
if (bSAD < Data->iMinSAD[0]) { |
803 |
Data->currentMV[0] = backupMV; |
Data->currentMV[0] = backupMV; |
804 |
Data->iMinSAD[0] = bSAD; } |
Data->iMinSAD[0] = bSAD; } |
810 |
bSAD = Data->iMinSAD[0]; Data->iMinSAD[0] = MV_MAX_ERROR; |
bSAD = Data->iMinSAD[0]; Data->iMinSAD[0] = MV_MAX_ERROR; |
811 |
|
|
812 |
CheckCandidate(startMV.x, startMV.y, Data, 255); |
CheckCandidate(startMV.x, startMV.y, Data, 255); |
813 |
MainSearchPtr(startMV.x, startMV.y, Data, 255, CheckCandidate); |
xvid_me_DiamondSearch(startMV.x, startMV.y, Data, 255, CheckCandidate); |
814 |
if (bSAD < Data->iMinSAD[0]) { |
if (bSAD < Data->iMinSAD[0]) { |
815 |
Data->currentMV[0] = backupMV; |
Data->currentMV[0] = backupMV; |
816 |
Data->iMinSAD[0] = bSAD; |
Data->iMinSAD[0] = bSAD; |
833 |
Data->qpel_precision = 1; |
Data->qpel_precision = 1; |
834 |
if (MotionFlags & XVID_ME_QUARTERPELREFINE16) { |
if (MotionFlags & XVID_ME_QUARTERPELREFINE16) { |
835 |
if(MotionFlags & XVID_ME_FASTREFINE16) |
if(MotionFlags & XVID_ME_FASTREFINE16) |
836 |
SubpelRefine_Fast(Data, CheckCandidate); |
SubpelRefine_Fast(Data, CheckCandidate16_qpel); |
837 |
else |
else |
838 |
xvid_me_SubpelRefine(Data, CheckCandidate); |
xvid_me_SubpelRefine(Data, CheckCandidate16_qpel); |
839 |
} |
} |
840 |
} |
} |
841 |
|
|
937 |
(current->vop_flags & XVID_VOP_MODEDECISION_RD ? 2:1); |
(current->vop_flags & XVID_VOP_MODEDECISION_RD ? 2:1); |
938 |
|
|
939 |
/* 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]; |
|
940 |
DECLARE_ALIGNED_MATRIX(dct_space, 3, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(dct_space, 3, 64, int16_t, CACHE_LINE); |
941 |
SearchData Data; |
SearchData Data; |
942 |
memset(&Data, 0, sizeof(SearchData)); |
memset(&Data, 0, sizeof(SearchData)); |
943 |
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; |
|
944 |
Data.iFcode = current->fcode; |
Data.iFcode = current->fcode; |
945 |
Data.rounding = pParam->m_rounding_type; |
Data.rounding = pParam->m_rounding_type; |
946 |
Data.qpel = (current->vol_flags & XVID_VOL_QUARTERPEL ? 1:0); |
Data.qpel = (current->vol_flags & XVID_VOL_QUARTERPEL ? 1:0); |
948 |
Data.rrv = (current->vop_flags & XVID_VOP_REDUCED) ? 1:0; |
Data.rrv = (current->vop_flags & XVID_VOP_REDUCED) ? 1:0; |
949 |
Data.dctSpace = dct_space; |
Data.dctSpace = dct_space; |
950 |
Data.quant_type = !(pParam->vol_flags & XVID_VOL_MPEGQUANT); |
Data.quant_type = !(pParam->vol_flags & XVID_VOL_MPEGQUANT); |
951 |
|
Data.mpeg_quant_matrices = pParam->mpeg_quant_matrices; |
952 |
|
Data.iMinSAD2 = 0; |
953 |
|
|
954 |
if ((current->vop_flags & XVID_VOP_REDUCED)) { |
if ((current->vop_flags & XVID_VOP_REDUCED)) { |
955 |
mb_width = (pParam->width + 31) / 32; |
mb_width = (pParam->width + 31) / 32; |
976 |
pParam->edged_width, pMB->sad8 ); |
pParam->edged_width, pMB->sad8 ); |
977 |
|
|
978 |
if (Data.chroma) { |
if (Data.chroma) { |
979 |
Data.temp[7] = sad8(pCurrent->u + x*8 + y*(iEdgedWidth/2)*8, |
Data.chromaSAD = sad8(pCurrent->u + x*8 + y*(iEdgedWidth/2)*8, |
980 |
pRef->u + x*8 + y*(iEdgedWidth/2)*8, iEdgedWidth/2) |
pRef->u + x*8 + y*(iEdgedWidth/2)*8, iEdgedWidth/2) |
981 |
+ sad8(pCurrent->v + (x + y*(iEdgedWidth/2))*8, |
+ sad8(pCurrent->v + (x + y*(iEdgedWidth/2))*8, |
982 |
pRef->v + (x + y*(iEdgedWidth/2))*8, iEdgedWidth/2); |
pRef->v + (x + y*(iEdgedWidth/2))*8, iEdgedWidth/2); |
983 |
pMB->sad16 += Data.temp[7]; |
pMB->sad16 += Data.chromaSAD; |
984 |
} |
} |
985 |
|
|
986 |
sad00 = pMB->sad16; |
sad00 = pMB->sad16; |
1006 |
MAX((&pMBs[x + (y-1) * pParam->mb_width])->sad16, |
MAX((&pMBs[x + (y-1) * pParam->mb_width])->sad16, |
1007 |
MAX((&pMBs[(x+1) + (y-1) * pParam->mb_width])->sad16, |
MAX((&pMBs[(x+1) + (y-1) * pParam->mb_width])->sad16, |
1008 |
prevMB->sad16))); |
prevMB->sad16))); |
|
} |
|
1009 |
} else { |
} else { |
1010 |
stat_thresh = MIN((&pMBs[(x-1) + y * pParam->mb_width])->sad16, |
stat_thresh = MIN((&pMBs[(x-1) + y * pParam->mb_width])->sad16, |
1011 |
MIN((&pMBs[x + (y-1) * pParam->mb_width])->sad16, |
MIN((&pMBs[x + (y-1) * pParam->mb_width])->sad16, |
1013 |
prevMB->sad16))); |
prevMB->sad16))); |
1014 |
} |
} |
1015 |
} |
} |
1016 |
|
} |
1017 |
|
|
1018 |
/* favorize (0,0) vector for cartoons */ |
/* favorize (0,0) vector for cartoons */ |
1019 |
if ((current->vop_flags & XVID_VOP_CARTOON) && |
if ((current->vop_flags & XVID_VOP_CARTOON) && |