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: motion_est.c,v 1.58.2.32 2003-08-29 13:47:21 syskin Exp $ |
* $Id: motion_est.c,v 1.58.2.33 2003-09-04 18:40:02 Isibaar Exp $ |
25 |
* |
* |
26 |
****************************************************************************/ |
****************************************************************************/ |
27 |
|
|
347 |
} |
} |
348 |
|
|
349 |
static void |
static void |
350 |
|
CheckCandidate16_subpel(const int x, const int y, const SearchData * const data, const int Direction) |
351 |
|
{ |
352 |
|
int xc, yc; |
353 |
|
const uint8_t *Reference; |
354 |
|
VECTOR *current, *current2; |
355 |
|
int32_t sad; uint32_t t; |
356 |
|
|
357 |
|
if ( (x > data->max_dx) || (x < data->min_dx) |
358 |
|
|| (y > data->max_dy) || (y < data->min_dy) ) return; |
359 |
|
|
360 |
|
if (!data->qpel_precision) { |
361 |
|
Reference = GetReference(x, y, data); |
362 |
|
current = data->currentMV; |
363 |
|
current2 = data->currentMV2; |
364 |
|
xc = x; yc = y; |
365 |
|
} else { /* x and y are in 1/4 precision */ |
366 |
|
Reference = Interpolate16x16qpel(x, y, 0, data); |
367 |
|
xc = x/2; yc = y/2; /* for chroma sad */ |
368 |
|
current = data->currentQMV; |
369 |
|
current2 = data->currentQMV2; |
370 |
|
} |
371 |
|
|
372 |
|
sad = sad16v(data->Cur, Reference, data->iEdgedWidth, data->temp); |
373 |
|
t = d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0); |
374 |
|
|
375 |
|
sad += (data->lambda16 * t * sad)>>10; |
376 |
|
data->temp[0] += (data->lambda8 * t * (data->temp[0] + NEIGH_8X8_BIAS))>>10; |
377 |
|
|
378 |
|
if (data->chroma && sad < data->iMinSAD[0]) |
379 |
|
sad += ChromaSAD((xc >> 1) + roundtab_79[xc & 0x3], |
380 |
|
(yc >> 1) + roundtab_79[yc & 0x3], data); |
381 |
|
|
382 |
|
if (data->temp[0] < data->iMinSAD[1]) { |
383 |
|
data->iMinSAD[1] = data->temp[0]; current[1].x = x; current[1].y = y; } |
384 |
|
if (data->temp[1] < data->iMinSAD[2]) { |
385 |
|
data->iMinSAD[2] = data->temp[1]; current[2].x = x; current[2].y = y; } |
386 |
|
if (data->temp[2] < data->iMinSAD[3]) { |
387 |
|
data->iMinSAD[3] = data->temp[2]; current[3].x = x; current[3].y = y; } |
388 |
|
if (data->temp[3] < data->iMinSAD[4]) { |
389 |
|
data->iMinSAD[4] = data->temp[3]; current[4].x = x; current[4].y = y; } |
390 |
|
|
391 |
|
if (sad < data->iMinSAD[0]) { |
392 |
|
*(data->iMinSAD2) = *(data->iMinSAD); |
393 |
|
current2->x = current->x; current2->y = current->y; |
394 |
|
|
395 |
|
data->iMinSAD[0] = sad; |
396 |
|
current[0].x = x; current[0].y = y; |
397 |
|
*data->dir = Direction; |
398 |
|
return; |
399 |
|
} |
400 |
|
|
401 |
|
if (sad < *(data->iMinSAD2)) { |
402 |
|
*(data->iMinSAD2) = sad; |
403 |
|
current2->x = x; current2->y = y; |
404 |
|
*data->dir = Direction; |
405 |
|
} |
406 |
|
} |
407 |
|
|
408 |
|
static void |
409 |
CheckCandidate8(const int x, const int y, const SearchData * const data, const int Direction) |
CheckCandidate8(const int x, const int y, const SearchData * const data, const int Direction) |
410 |
{ |
{ |
411 |
int32_t sad; uint32_t t; |
int32_t sad; uint32_t t; |
977 |
/* MAINSEARCH FUNCTIONS END */ |
/* MAINSEARCH FUNCTIONS END */ |
978 |
|
|
979 |
static void |
static void |
980 |
|
SubpelRefine_Fast(SearchData * data, CheckFunc * CheckCandidate) |
981 |
|
{ |
982 |
|
/* Do a half-pel or q-pel refinement */ |
983 |
|
VECTOR centerMV; |
984 |
|
VECTOR second_best; |
985 |
|
int best_sad = *data->iMinSAD; |
986 |
|
int xo, yo, xo2, yo2; |
987 |
|
int size = 2; |
988 |
|
CheckFunc *backupFunc = CheckCandidate; |
989 |
|
|
990 |
|
if(data->qpel_precision) |
991 |
|
size = 1; |
992 |
|
|
993 |
|
centerMV = *data->currentMV; |
994 |
|
*data->iMinSAD = 256 * 4096; |
995 |
|
|
996 |
|
CHECK_CANDIDATE(centerMV.x, centerMV.y - size, 0); |
997 |
|
CHECK_CANDIDATE(centerMV.x + size, centerMV.y - size, 0); |
998 |
|
CHECK_CANDIDATE(centerMV.x + size, centerMV.y, 0); |
999 |
|
CHECK_CANDIDATE(centerMV.x + size, centerMV.y + size, 0); |
1000 |
|
|
1001 |
|
CHECK_CANDIDATE(centerMV.x, centerMV.y + size, 0); |
1002 |
|
CHECK_CANDIDATE(centerMV.x - size, centerMV.y + size, 0); |
1003 |
|
CHECK_CANDIDATE(centerMV.x - size, centerMV.y, 0); |
1004 |
|
CHECK_CANDIDATE(centerMV.x - size, centerMV.y - size, 0); |
1005 |
|
|
1006 |
|
second_best = *data->currentMV; |
1007 |
|
|
1008 |
|
if(data->qpel_precision) |
1009 |
|
second_best.x *= 2; second_best.y *= 2; |
1010 |
|
|
1011 |
|
data->currentMV[0] = centerMV; |
1012 |
|
*data->iMinSAD = best_sad; |
1013 |
|
|
1014 |
|
centerMV = data->qpel_precision ? *data->currentQMV : *data->currentMV; |
1015 |
|
|
1016 |
|
xo = centerMV.x; |
1017 |
|
yo = centerMV.y; |
1018 |
|
xo2 = second_best.x; |
1019 |
|
yo2 = second_best.y; |
1020 |
|
|
1021 |
|
CheckCandidate = CheckCandidate16_subpel; |
1022 |
|
*data->iMinSAD2 = 256 * 4096; |
1023 |
|
|
1024 |
|
if (yo == yo2) |
1025 |
|
{ |
1026 |
|
CHECK_CANDIDATE((xo+xo2)>>1, yo, 0); |
1027 |
|
CHECK_CANDIDATE(xo, yo-1, 0); |
1028 |
|
CHECK_CANDIDATE(xo, yo+1, 0); |
1029 |
|
|
1030 |
|
if(best_sad <= *data->iMinSAD2) |
1031 |
|
goto ende; |
1032 |
|
|
1033 |
|
if(data->currentQMV[0].x == data->currentQMV2[0].x) { |
1034 |
|
CHECK_CANDIDATE((xo+xo2)>>1, yo-1, 0); |
1035 |
|
CHECK_CANDIDATE((xo+xo2)>>1, yo+1, 0); |
1036 |
|
goto ende; |
1037 |
|
} |
1038 |
|
else { |
1039 |
|
CHECK_CANDIDATE((xo+xo2)>>1, |
1040 |
|
(data->currentQMV[0].x == xo) ? data->currentQMV[0].y : data->currentQMV2[0].y, |
1041 |
|
0); |
1042 |
|
goto ende; |
1043 |
|
} |
1044 |
|
} |
1045 |
|
|
1046 |
|
if (xo == xo2) |
1047 |
|
{ |
1048 |
|
CHECK_CANDIDATE(xo, (yo+yo2)>>1, 0); |
1049 |
|
CHECK_CANDIDATE(xo-1, yo, 0); |
1050 |
|
CHECK_CANDIDATE(xo+1, yo, 0); |
1051 |
|
|
1052 |
|
if(best_sad < *data->iMinSAD2) |
1053 |
|
goto ende; |
1054 |
|
|
1055 |
|
if(data->currentQMV[0].y == data->currentQMV2[0].y) { |
1056 |
|
CHECK_CANDIDATE(xo-1, (yo+yo2)>>1, 0); |
1057 |
|
CHECK_CANDIDATE(xo+1, (yo+yo2)>>1, 0); |
1058 |
|
goto ende; |
1059 |
|
} |
1060 |
|
else { |
1061 |
|
CHECK_CANDIDATE((data->currentQMV[0].y == yo) ? data->currentQMV[0].x : data->currentQMV2[0].x, (yo+yo2)>>1, 0); |
1062 |
|
goto ende; |
1063 |
|
} |
1064 |
|
} |
1065 |
|
|
1066 |
|
CHECK_CANDIDATE(xo, (yo+yo2)>>1, 0); |
1067 |
|
CHECK_CANDIDATE((xo+xo2)>>1, yo, 0); |
1068 |
|
|
1069 |
|
if(best_sad <= *data->iMinSAD2) |
1070 |
|
goto ende; |
1071 |
|
|
1072 |
|
CHECK_CANDIDATE((xo+xo2)>>1, (yo+yo2)>>1, 0); |
1073 |
|
|
1074 |
|
ende: |
1075 |
|
CheckCandidate = backupFunc; |
1076 |
|
} |
1077 |
|
|
1078 |
|
static void |
1079 |
SubpelRefine(const SearchData * const data, CheckFunc * const CheckCandidate) |
SubpelRefine(const SearchData * const data, CheckFunc * const CheckCandidate) |
1080 |
{ |
{ |
1081 |
/* Do a half-pel or q-pel refinement */ |
/* Do a half-pel or q-pel refinement */ |
1128 |
} |
} |
1129 |
|
|
1130 |
static __inline void |
static __inline void |
1131 |
|
ModeDecision_Fast(SearchData * const Data, |
1132 |
|
MACROBLOCK * const pMB, |
1133 |
|
const MACROBLOCK * const pMBs, |
1134 |
|
const int x, const int y, |
1135 |
|
const MBParam * const pParam, |
1136 |
|
const uint32_t MotionFlags, |
1137 |
|
const uint32_t VopFlags, |
1138 |
|
const uint32_t VolFlags, |
1139 |
|
const IMAGE * const pCurrent, |
1140 |
|
const IMAGE * const pRef, |
1141 |
|
const IMAGE * const vGMC, |
1142 |
|
const int coding_type) |
1143 |
|
{ |
1144 |
|
int mode = MODE_INTER; |
1145 |
|
int mcsel = 0; |
1146 |
|
int inter4v = (VopFlags & XVID_VOP_INTER4V) && (pMB->dquant == 0); |
1147 |
|
const uint32_t iQuant = pMB->quant; |
1148 |
|
const int skip_possible = (coding_type == P_VOP) && (pMB->dquant == 0); |
1149 |
|
int sad; |
1150 |
|
int min_rd = -1, intra_rd, i, cbp, c[2] = {0, 0}; |
1151 |
|
VECTOR backup[5], *v; |
1152 |
|
int sad_backup[5]; |
1153 |
|
int InterBias = MV16_INTER_BIAS; |
1154 |
|
int thresh = 0; |
1155 |
|
int count = 0; |
1156 |
|
int top = 0, top_right = 0, left = 0; |
1157 |
|
|
1158 |
|
pMB->mcsel = 0; |
1159 |
|
|
1160 |
|
/* INTER <-> INTER4V decision */ |
1161 |
|
if ((Data->iMinSAD[0] + 125 < Data->iMinSAD[1] + |
1162 |
|
Data->iMinSAD[2] + Data->iMinSAD[3] + Data->iMinSAD[4])) { /* normal, fast, SAD-based mode decision */ |
1163 |
|
if (inter4v == 0 || Data->iMinSAD[0] < Data->iMinSAD[1] + Data->iMinSAD[2] + |
1164 |
|
Data->iMinSAD[3] + Data->iMinSAD[4] + IMV16X16 * (int32_t)iQuant) { |
1165 |
|
mode = MODE_INTER; |
1166 |
|
sad = Data->iMinSAD[0]; |
1167 |
|
} else { |
1168 |
|
mode = MODE_INTER4V; |
1169 |
|
sad = Data->iMinSAD[1] + Data->iMinSAD[2] + |
1170 |
|
Data->iMinSAD[3] + Data->iMinSAD[4] + IMV16X16 * (int32_t)iQuant; |
1171 |
|
Data->iMinSAD[0] = sad; |
1172 |
|
} |
1173 |
|
|
1174 |
|
/* final skip decision, a.k.a. "the vector you found, really that good?" */ |
1175 |
|
if (skip_possible && (pMB->sad16 < (int)iQuant * MAX_SAD00_FOR_SKIP)) |
1176 |
|
if ( (100*sad)/(pMB->sad16+1) > FINAL_SKIP_THRESH) |
1177 |
|
if (Data->chroma || SkipDecisionP(pCurrent, pRef, x, y, Data->iEdgedWidth/2, iQuant, Data->rrv)) { |
1178 |
|
mode = MODE_NOT_CODED; |
1179 |
|
goto early_out; |
1180 |
|
} |
1181 |
|
|
1182 |
|
/* mcsel */ |
1183 |
|
if (coding_type == S_VOP) { |
1184 |
|
|
1185 |
|
int32_t iSAD = sad16(Data->Cur, |
1186 |
|
vGMC->y + 16*y*Data->iEdgedWidth + 16*x, Data->iEdgedWidth, 65536); |
1187 |
|
|
1188 |
|
if (Data->chroma) { |
1189 |
|
iSAD += sad8(Data->CurU, vGMC->u + 8*y*(Data->iEdgedWidth/2) + 8*x, Data->iEdgedWidth/2); |
1190 |
|
iSAD += sad8(Data->CurV, vGMC->v + 8*y*(Data->iEdgedWidth/2) + 8*x, Data->iEdgedWidth/2); |
1191 |
|
} |
1192 |
|
|
1193 |
|
if (iSAD <= sad) { /* mode decision GMC */ |
1194 |
|
mode = MODE_INTER; |
1195 |
|
mcsel = 1; |
1196 |
|
sad = iSAD; |
1197 |
|
} |
1198 |
|
|
1199 |
|
} |
1200 |
|
} else { /* Rate-Distortion INTER<->INTER4V */ |
1201 |
|
Data->iQuant = iQuant; |
1202 |
|
Data->cbp = c; |
1203 |
|
v = Data->qpel ? Data->currentQMV : Data->currentMV; |
1204 |
|
|
1205 |
|
/* final skip decision, a.k.a. "the vector you found, really that good?" */ |
1206 |
|
if (skip_possible && (pMB->sad16 < (int)iQuant * MAX_SAD00_FOR_SKIP)) |
1207 |
|
if ( (100*Data->iMinSAD[0])/(pMB->sad16+1) > FINAL_SKIP_THRESH) |
1208 |
|
if (Data->chroma || SkipDecisionP(pCurrent, pRef, x, y, Data->iEdgedWidth/2, iQuant, Data->rrv)) { |
1209 |
|
mode = MODE_NOT_CODED; |
1210 |
|
goto early_out; |
1211 |
|
} |
1212 |
|
|
1213 |
|
for (i = 0; i < 5; i++) { |
1214 |
|
sad_backup[i] = Data->iMinSAD[i]; |
1215 |
|
Data->iMinSAD[i] = 256*4096; |
1216 |
|
backup[i] = v[i]; |
1217 |
|
} |
1218 |
|
|
1219 |
|
min_rd = findRDinter(Data, pMBs, x, y, pParam, MotionFlags); |
1220 |
|
cbp = *Data->cbp; |
1221 |
|
sad = sad_backup[0]; |
1222 |
|
|
1223 |
|
if (coding_type == S_VOP) { |
1224 |
|
int gmc_rd; |
1225 |
|
int32_t iSAD = sad16(Data->Cur, |
1226 |
|
vGMC->y + 16*y*Data->iEdgedWidth + 16*x, Data->iEdgedWidth, 65536); |
1227 |
|
|
1228 |
|
if (Data->chroma) { |
1229 |
|
iSAD += sad8(Data->CurU, vGMC->u + 8*y*(Data->iEdgedWidth/2) + 8*x, Data->iEdgedWidth/2); |
1230 |
|
iSAD += sad8(Data->CurV, vGMC->v + 8*y*(Data->iEdgedWidth/2) + 8*x, Data->iEdgedWidth/2); |
1231 |
|
} |
1232 |
|
|
1233 |
|
*Data->iMinSAD = min_rd += BITS_MULT*1; /* mcsel */ |
1234 |
|
gmc_rd = findRDgmc(Data, vGMC, x, y); |
1235 |
|
if (gmc_rd < min_rd) { |
1236 |
|
mcsel = 1; |
1237 |
|
*Data->iMinSAD = min_rd = gmc_rd; |
1238 |
|
mode = MODE_INTER; |
1239 |
|
cbp = *Data->cbp; |
1240 |
|
sad = iSAD; |
1241 |
|
} |
1242 |
|
} |
1243 |
|
|
1244 |
|
if (inter4v) { |
1245 |
|
int v4_rd; |
1246 |
|
v4_rd = findRDinter4v(Data, pMB, pMBs, x, y, pParam, MotionFlags, backup); |
1247 |
|
if (v4_rd < min_rd) { |
1248 |
|
Data->iMinSAD[0] = min_rd = v4_rd; |
1249 |
|
mode = MODE_INTER4V; |
1250 |
|
cbp = *Data->cbp; |
1251 |
|
sad = sad_backup[1] + sad_backup[2] + |
1252 |
|
sad_backup[3] + sad_backup[4] + IMV16X16 * (int32_t)iQuant; |
1253 |
|
} |
1254 |
|
} |
1255 |
|
} |
1256 |
|
|
1257 |
|
left = top = top_right = -1; |
1258 |
|
thresh = 0; |
1259 |
|
|
1260 |
|
if(x > 0 && y > 0 && x < pParam->mb_width) { |
1261 |
|
left = (&pMBs[(x-1) + y * pParam->mb_width])->sad16; // left |
1262 |
|
top = (&pMBs[x + (y-1) * pParam->mb_width])->sad16; // top |
1263 |
|
top_right = (&pMBs[(x+1) + (y-1) * pParam->mb_width])->sad16; // top right |
1264 |
|
|
1265 |
|
if(((&pMBs[(x-1) + y * pParam->mb_width])->mode != MODE_INTRA) && |
1266 |
|
((&pMBs[x + (y-1) * pParam->mb_width])->mode != MODE_INTRA) && |
1267 |
|
((&pMBs[(x+1) + (y-1) * pParam->mb_width])->mode != MODE_INTRA)) |
1268 |
|
thresh = MAX(MAX(top, left), top_right); |
1269 |
|
else |
1270 |
|
thresh = MIN(MIN(top, left), top_right); |
1271 |
|
} |
1272 |
|
|
1273 |
|
/* INTRA <-> INTER decision */ |
1274 |
|
if (sad < thresh) { /* normal, fast, SAD-based mode decision */ |
1275 |
|
/* intra decision */ |
1276 |
|
|
1277 |
|
if (iQuant > 8) InterBias += 100 * (iQuant - 8); /* to make high quants work */ |
1278 |
|
if (y != 0) |
1279 |
|
if ((pMB - pParam->mb_width)->mode == MODE_INTRA ) InterBias -= 80; |
1280 |
|
if (x != 0) |
1281 |
|
if ((pMB - 1)->mode == MODE_INTRA ) InterBias -= 80; |
1282 |
|
|
1283 |
|
if (Data->chroma) InterBias += 50; /* dev8(chroma) ??? <-- yes, we need dev8 (no big difference though) */ |
1284 |
|
if (Data->rrv) InterBias *= 4; |
1285 |
|
|
1286 |
|
if (InterBias < sad) { |
1287 |
|
int32_t deviation; |
1288 |
|
if (!Data->rrv) |
1289 |
|
deviation = dev16(Data->Cur, Data->iEdgedWidth); |
1290 |
|
else |
1291 |
|
deviation = dev16(Data->Cur, Data->iEdgedWidth) + /* dev32() */ |
1292 |
|
dev16(Data->Cur+16, Data->iEdgedWidth) + |
1293 |
|
dev16(Data->Cur + 16*Data->iEdgedWidth, Data->iEdgedWidth) + |
1294 |
|
dev16(Data->Cur+16+16*Data->iEdgedWidth, Data->iEdgedWidth); |
1295 |
|
|
1296 |
|
if (deviation < (sad - InterBias)) mode = MODE_INTRA; |
1297 |
|
} |
1298 |
|
|
1299 |
|
pMB->cbp = 63; |
1300 |
|
} else { /* Rate-Distortion INTRA<->INTER */ |
1301 |
|
if(min_rd < 0) { |
1302 |
|
Data->iQuant = iQuant; |
1303 |
|
Data->cbp = c; |
1304 |
|
v = Data->qpel ? Data->currentQMV : Data->currentMV; |
1305 |
|
|
1306 |
|
for (i = 0; i < 5; i++) { |
1307 |
|
Data->iMinSAD[i] = 256*4096; |
1308 |
|
backup[i] = v[i]; |
1309 |
|
} |
1310 |
|
|
1311 |
|
if(mode == MODE_INTER) { |
1312 |
|
min_rd = findRDinter(Data, pMBs, x, y, pParam, MotionFlags); |
1313 |
|
cbp = *Data->cbp; |
1314 |
|
|
1315 |
|
if (coding_type == S_VOP) { |
1316 |
|
int gmc_rd; |
1317 |
|
|
1318 |
|
*Data->iMinSAD = min_rd += BITS_MULT*1; /* mcsel */ |
1319 |
|
gmc_rd = findRDgmc(Data, vGMC, x, y); |
1320 |
|
if (gmc_rd < min_rd) { |
1321 |
|
mcsel = 1; |
1322 |
|
*Data->iMinSAD = min_rd = gmc_rd; |
1323 |
|
mode = MODE_INTER; |
1324 |
|
cbp = *Data->cbp; |
1325 |
|
} |
1326 |
|
} |
1327 |
|
} |
1328 |
|
|
1329 |
|
if(mode == MODE_INTER4V) { |
1330 |
|
int v4_rd; |
1331 |
|
v4_rd = findRDinter4v(Data, pMB, pMBs, x, y, pParam, MotionFlags, backup); |
1332 |
|
if (v4_rd < min_rd) { |
1333 |
|
Data->iMinSAD[0] = min_rd = v4_rd; |
1334 |
|
mode = MODE_INTER4V; |
1335 |
|
cbp = *Data->cbp; |
1336 |
|
} |
1337 |
|
} |
1338 |
|
} |
1339 |
|
|
1340 |
|
intra_rd = findRDintra(Data); |
1341 |
|
if (intra_rd < min_rd) { |
1342 |
|
*Data->iMinSAD = min_rd = intra_rd; |
1343 |
|
mode = MODE_INTRA; |
1344 |
|
} |
1345 |
|
|
1346 |
|
pMB->cbp = cbp; |
1347 |
|
} |
1348 |
|
|
1349 |
|
early_out: |
1350 |
|
pMB->sad16 = pMB->sad8[0] = pMB->sad8[1] = pMB->sad8[2] = pMB->sad8[3] = sad; |
1351 |
|
|
1352 |
|
if (Data->rrv) { |
1353 |
|
Data->currentMV[0].x = RRV_MV_SCALEDOWN(Data->currentMV[0].x); |
1354 |
|
Data->currentMV[0].y = RRV_MV_SCALEDOWN(Data->currentMV[0].y); |
1355 |
|
} |
1356 |
|
|
1357 |
|
if (mode == MODE_INTER && mcsel == 0) { |
1358 |
|
pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = Data->currentMV[0]; |
1359 |
|
|
1360 |
|
if(Data->qpel) { |
1361 |
|
pMB->qmvs[0] = pMB->qmvs[1] |
1362 |
|
= pMB->qmvs[2] = pMB->qmvs[3] = Data->currentQMV[0]; |
1363 |
|
pMB->pmvs[0].x = Data->currentQMV[0].x - Data->predMV.x; |
1364 |
|
pMB->pmvs[0].y = Data->currentQMV[0].y - Data->predMV.y; |
1365 |
|
} else { |
1366 |
|
pMB->pmvs[0].x = Data->currentMV[0].x - Data->predMV.x; |
1367 |
|
pMB->pmvs[0].y = Data->currentMV[0].y - Data->predMV.y; |
1368 |
|
} |
1369 |
|
|
1370 |
|
} else if (mode == MODE_INTER ) { // but mcsel == 1 |
1371 |
|
|
1372 |
|
pMB->mcsel = 1; |
1373 |
|
if (Data->qpel) { |
1374 |
|
pMB->qmvs[0] = pMB->qmvs[1] = pMB->qmvs[2] = pMB->qmvs[3] = pMB->amv; |
1375 |
|
pMB->mvs[0].x = pMB->mvs[1].x = pMB->mvs[2].x = pMB->mvs[3].x = pMB->amv.x/2; |
1376 |
|
pMB->mvs[0].y = pMB->mvs[1].y = pMB->mvs[2].y = pMB->mvs[3].y = pMB->amv.y/2; |
1377 |
|
} else |
1378 |
|
pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv; |
1379 |
|
|
1380 |
|
} else |
1381 |
|
if (mode == MODE_INTER4V) ; /* anything here? */ |
1382 |
|
else /* INTRA, NOT_CODED */ |
1383 |
|
ZeroMacroblockP(pMB, 0); |
1384 |
|
|
1385 |
|
pMB->mode = mode; |
1386 |
|
} |
1387 |
|
|
1388 |
|
static __inline void |
1389 |
ModeDecision(SearchData * const Data, |
ModeDecision(SearchData * const Data, |
1390 |
MACROBLOCK * const pMB, |
MACROBLOCK * const pMB, |
1391 |
const MACROBLOCK * const pMBs, |
const MACROBLOCK * const pMBs, |
1578 |
uint32_t mb_height = pParam->mb_height; |
uint32_t mb_height = pParam->mb_height; |
1579 |
const uint32_t iEdgedWidth = pParam->edged_width; |
const uint32_t iEdgedWidth = pParam->edged_width; |
1580 |
const uint32_t MotionFlags = MakeGoodMotionFlags(current->motion_flags, current->vop_flags, current->vol_flags); |
const uint32_t MotionFlags = MakeGoodMotionFlags(current->motion_flags, current->vop_flags, current->vol_flags); |
1581 |
|
int stat_thresh = 0; |
1582 |
|
|
1583 |
uint32_t x, y; |
uint32_t x, y; |
1584 |
uint32_t iIntra = 0; |
uint32_t iIntra = 0; |
1591 |
int32_t temp[8]; uint32_t dir; |
int32_t temp[8]; uint32_t dir; |
1592 |
VECTOR currentMV[5]; |
VECTOR currentMV[5]; |
1593 |
VECTOR currentQMV[5]; |
VECTOR currentQMV[5]; |
1594 |
|
VECTOR currentMV2[5]; |
1595 |
|
VECTOR currentQMV2[5]; |
1596 |
int32_t iMinSAD[5]; |
int32_t iMinSAD[5]; |
1597 |
|
int32_t iMinSAD2[5]; |
1598 |
DECLARE_ALIGNED_MATRIX(dct_space, 3, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(dct_space, 3, 64, int16_t, CACHE_LINE); |
1599 |
SearchData Data; |
SearchData Data; |
1600 |
memset(&Data, 0, sizeof(SearchData)); |
memset(&Data, 0, sizeof(SearchData)); |
1601 |
Data.iEdgedWidth = iEdgedWidth; |
Data.iEdgedWidth = iEdgedWidth; |
1602 |
Data.currentMV = currentMV; |
Data.currentMV = currentMV; |
1603 |
Data.currentQMV = currentQMV; |
Data.currentQMV = currentQMV; |
1604 |
|
Data.currentMV2 = currentMV2; |
1605 |
|
Data.currentQMV2 = currentQMV2; |
1606 |
Data.iMinSAD = iMinSAD; |
Data.iMinSAD = iMinSAD; |
1607 |
|
Data.iMinSAD2 = iMinSAD2; |
1608 |
Data.temp = temp; |
Data.temp = temp; |
1609 |
Data.dir = &dir; |
Data.dir = &dir; |
1610 |
Data.iFcode = current->fcode; |
Data.iFcode = current->fcode; |
1627 |
for (y = 0; y < mb_height; y++) { |
for (y = 0; y < mb_height; y++) { |
1628 |
for (x = 0; x < mb_width; x++) { |
for (x = 0; x < mb_width; x++) { |
1629 |
MACROBLOCK *pMB = &pMBs[x + y * pParam->mb_width]; |
MACROBLOCK *pMB = &pMBs[x + y * pParam->mb_width]; |
1630 |
|
MACROBLOCK *prevMB = &reference->mbs[x + y * pParam->mb_width]; |
1631 |
|
|
1632 |
if (!Data.rrv) pMB->sad16 = |
if (!Data.rrv) pMB->sad16 = |
1633 |
sad16v(pCurrent->y + (x + y * iEdgedWidth) * 16, |
sad16v(pCurrent->y + (x + y * iEdgedWidth) * 16, |
1660 |
} |
} |
1661 |
} |
} |
1662 |
|
|
1663 |
|
if(MotionFlags & XVID_ME_DETECT_STATIC_MOTION) { |
1664 |
|
if(x > 0 && y > 0 && x < pParam->mb_width) |
1665 |
|
if(MVequal((&pMBs[(x-1) + y * pParam->mb_width])->mvs[0], zeroMV) && |
1666 |
|
MVequal((&pMBs[x + (y-1) * pParam->mb_width])->mvs[0], zeroMV) && |
1667 |
|
MVequal((&pMBs[(x+1) + (y-1) * pParam->mb_width])->mvs[0], zeroMV) && |
1668 |
|
MVequal(prevMB->mvs[0], zeroMV)) { |
1669 |
|
stat_thresh = MAX((&pMBs[(x-1) + y * pParam->mb_width])->sad16, |
1670 |
|
MAX((&pMBs[x + (y-1) * pParam->mb_width])->sad16, |
1671 |
|
MAX((&pMBs[(x+1) + (y-1) * pParam->mb_width])->sad16, |
1672 |
|
prevMB->sad16))); |
1673 |
|
} |
1674 |
|
else |
1675 |
|
stat_thresh = MIN((&pMBs[(x-1) + y * pParam->mb_width])->sad16, |
1676 |
|
MIN((&pMBs[x + (y-1) * pParam->mb_width])->sad16, |
1677 |
|
MIN((&pMBs[(x+1) + (y-1) * pParam->mb_width])->sad16, |
1678 |
|
prevMB->sad16))); |
1679 |
|
} |
1680 |
|
|
1681 |
if ((current->vop_flags & XVID_VOP_CARTOON) && |
if ((current->vop_flags & XVID_VOP_CARTOON) && |
1682 |
(sad00 < pMB->quant * 4 * skip_thresh)) { /* favorize (0,0) vector for cartoons */ |
(sad00 < pMB->quant * 4 * skip_thresh) || (sad00 < stat_thresh)) { /* favorize (0,0) vector for cartoons */ |
1683 |
ZeroMacroblockP(pMB, sad00); |
ZeroMacroblockP(pMB, sad00); |
1684 |
continue; |
continue; |
1685 |
} |
} |
1688 |
y, MotionFlags, current->vop_flags, current->vol_flags, |
y, MotionFlags, current->vop_flags, current->vol_flags, |
1689 |
&Data, pParam, pMBs, reference->mbs, pMB); |
&Data, pParam, pMBs, reference->mbs, pMB); |
1690 |
|
|
1691 |
|
if(current->vop_flags & XVID_VOP_FAST_MODEDECISION_RD) { |
1692 |
|
ModeDecision_Fast(&Data, pMB, pMBs, x, y, pParam, |
1693 |
|
MotionFlags, current->vop_flags, current->vol_flags, |
1694 |
|
pCurrent, pRef, pGMC, current->coding_type); |
1695 |
|
} |
1696 |
|
else { |
1697 |
ModeDecision(&Data, pMB, pMBs, x, y, pParam, |
ModeDecision(&Data, pMB, pMBs, x, y, pParam, |
1698 |
MotionFlags, current->vop_flags, current->vol_flags, |
MotionFlags, current->vop_flags, current->vol_flags, |
1699 |
pCurrent, pRef, pGMC, current->coding_type); |
pCurrent, pRef, pGMC, current->coding_type); |
1700 |
|
} |
1701 |
|
|
1702 |
if (pMB->mode == MODE_INTRA) |
if (pMB->mode == MODE_INTRA) |
1703 |
if (++iIntra > iLimit) return 1; |
if (++iIntra > iLimit) return 1; |
1921 |
pParam->width, pParam->height, Data->iFcode, 2, 0); |
pParam->width, pParam->height, Data->iFcode, 2, 0); |
1922 |
Data->qpel_precision = 1; |
Data->qpel_precision = 1; |
1923 |
if (MotionFlags & XVID_ME_QUARTERPELREFINE16) |
if (MotionFlags & XVID_ME_QUARTERPELREFINE16) |
1924 |
|
if(MotionFlags & XVID_ME_FASTREFINE16) |
1925 |
|
SubpelRefine_Fast(Data, CheckCandidate); |
1926 |
|
else |
1927 |
SubpelRefine(Data, CheckCandidate); |
SubpelRefine(Data, CheckCandidate); |
1928 |
} |
} |
1929 |
|
|