249 |
ref1 = GetReferenceB(halfpel_x, halfpel_y, dir, data); |
ref1 = GetReferenceB(halfpel_x, halfpel_y, dir, data); |
250 |
ref1 += 8 * (block&1) + 8 * (block>>1) * iEdgedWidth; |
ref1 += 8 * (block&1) + 8 * (block>>1) * iEdgedWidth; |
251 |
switch( ((x&1)<<1) + (y&1) ) { |
switch( ((x&1)<<1) + (y&1) ) { |
252 |
case 0: // pure halfpel position |
case 3: // x and y in qpel resolution - the "corners" (top left/right and |
253 |
return (uint8_t *) ref1; |
// bottom left/right) during qpel refinement |
254 |
|
ref2 = GetReferenceB(halfpel_x, y - halfpel_y, dir, data); |
255 |
|
ref3 = GetReferenceB(x - halfpel_x, halfpel_y, dir, data); |
256 |
|
ref4 = GetReferenceB(x - halfpel_x, y - halfpel_y, dir, data); |
257 |
|
ref2 += 8 * (block&1) + 8 * (block>>1) * iEdgedWidth; |
258 |
|
ref3 += 8 * (block&1) + 8 * (block>>1) * iEdgedWidth; |
259 |
|
ref4 += 8 * (block&1) + 8 * (block>>1) * iEdgedWidth; |
260 |
|
interpolate8x8_avg4(Reference, ref1, ref2, ref3, ref4, iEdgedWidth, rounding); |
261 |
break; |
break; |
262 |
|
|
263 |
case 1: // x halfpel, y qpel - top or bottom during qpel refinement |
case 1: // x halfpel, y qpel - top or bottom during qpel refinement |
272 |
interpolate8x8_avg2(Reference, ref1, ref2, iEdgedWidth, rounding, 8); |
interpolate8x8_avg2(Reference, ref1, ref2, iEdgedWidth, rounding, 8); |
273 |
break; |
break; |
274 |
|
|
275 |
default: // x and y in qpel resolution - the "corners" (top left/right and |
default: // pure halfpel position |
276 |
// bottom left/right) during qpel refinement |
return (uint8_t *) ref1; |
277 |
ref2 = GetReferenceB(halfpel_x, y - halfpel_y, dir, data); |
|
|
ref3 = GetReferenceB(x - halfpel_x, halfpel_y, dir, data); |
|
|
ref4 = GetReferenceB(x - halfpel_x, y - halfpel_y, dir, data); |
|
|
ref2 += 8 * (block&1) + 8 * (block>>1) * iEdgedWidth; |
|
|
ref3 += 8 * (block&1) + 8 * (block>>1) * iEdgedWidth; |
|
|
ref4 += 8 * (block&1) + 8 * (block>>1) * iEdgedWidth; |
|
|
interpolate8x8_avg4(Reference, ref1, ref2, ref3, ref4, iEdgedWidth, rounding); |
|
|
break; |
|
278 |
} |
} |
279 |
return Reference; |
return Reference; |
280 |
} |
} |
319 |
interpolate8x8_avg2(Reference+8*iEdgedWidth+8, ref1+8*iEdgedWidth+8, ref2+8*iEdgedWidth+8, iEdgedWidth, rounding, 8); |
interpolate8x8_avg2(Reference+8*iEdgedWidth+8, ref1+8*iEdgedWidth+8, ref2+8*iEdgedWidth+8, iEdgedWidth, rounding, 8); |
320 |
break; |
break; |
321 |
|
|
322 |
case 0: // pure halfpel position |
default: // pure halfpel position |
323 |
return (uint8_t *) ref1; |
return (uint8_t *) ref1; |
324 |
} |
} |
325 |
return Reference; |
return Reference; |
405 |
uint32_t t; |
uint32_t t; |
406 |
const uint8_t * Reference; |
const uint8_t * Reference; |
407 |
|
|
408 |
if ( (!(x&1) && x !=0) || (!(y&1) && y !=0) || //non-zero integer value |
if ( (!(x&1) && x !=0) || (!(y&1) && y !=0) || //non-zero even value |
409 |
(x > data->max_dx) || (x < data->min_dx) |
(x > data->max_dx) || (x < data->min_dx) |
410 |
|| (y > data->max_dy) || (y < data->min_dy) ) return; |
|| (y > data->max_dy) || (y < data->min_dy) ) return; |
411 |
|
|
440 |
uint32_t t; |
uint32_t t; |
441 |
VECTOR * current; |
VECTOR * current; |
442 |
|
|
443 |
if ( (x > data->max_dx) | ( x < data->min_dx) |
if ( (x > data->max_dx) || ( x < data->min_dx) |
444 |
| (y > data->max_dy) | (y < data->min_dy) ) return; |
|| (y > data->max_dy) || (y < data->min_dy) ) return; |
445 |
|
|
446 |
if (data->rrv && (!(x&1) && x !=0) | (!(y&1) && y !=0) ) return; //non-zero even value |
if (data->rrv && (!(x&1) && x !=0) | (!(y&1) && y !=0) ) return; //non-zero even value |
447 |
|
|
612 |
const uint8_t *ReferenceB; |
const uint8_t *ReferenceB; |
613 |
VECTOR mvs, b_mvs; |
VECTOR mvs, b_mvs; |
614 |
|
|
615 |
if (( x > 31) | ( x < -32) | ( y > 31) | (y < -32)) return; |
if (( x > 31) || ( x < -32) || ( y > 31) || (y < -32)) return; |
616 |
|
|
617 |
mvs.x = data->directmvF[0].x + x; |
mvs.x = data->directmvF[0].x + x; |
618 |
b_mvs.x = ((x == 0) ? |
b_mvs.x = ((x == 0) ? |
624 |
data->directmvB[0].y |
data->directmvB[0].y |
625 |
: mvs.y - data->referencemv[0].y); |
: mvs.y - data->referencemv[0].y); |
626 |
|
|
627 |
if ( (mvs.x > data->max_dx) | (mvs.x < data->min_dx) |
if ( (mvs.x > data->max_dx) || (mvs.x < data->min_dx) |
628 |
| (mvs.y > data->max_dy) | (mvs.y < data->min_dy) |
|| (mvs.y > data->max_dy) || (mvs.y < data->min_dy) |
629 |
| (b_mvs.x > data->max_dx) | (b_mvs.x < data->min_dx) |
|| (b_mvs.x > data->max_dx) || (b_mvs.x < data->min_dx) |
630 |
| (b_mvs.y > data->max_dy) | (b_mvs.y < data->min_dy) ) return; |
|| (b_mvs.y > data->max_dy) || (b_mvs.y < data->min_dy) ) return; |
631 |
|
|
632 |
if (data->qpel) { |
if (data->qpel) { |
633 |
xcf = 4*(mvs.x/2); ycf = 4*(mvs.y/2); |
xcf = 4*(mvs.x/2); ycf = 4*(mvs.y/2); |
661 |
CheckCandidateBits16(const int x, const int y, const int Direction, int * const dir, const SearchData * const data) |
CheckCandidateBits16(const int x, const int y, const int Direction, int * const dir, const SearchData * const data) |
662 |
{ |
{ |
663 |
|
|
664 |
static int16_t in[64], coeff[64]; |
int16_t *in = data->dctSpace, *coeff = data->dctSpace + 64; |
665 |
int32_t bits = 0, sum; |
int32_t bits = 0, sum; |
666 |
VECTOR * current; |
VECTOR * current; |
667 |
const uint8_t * ptr; |
const uint8_t * ptr; |
723 |
} |
} |
724 |
} |
} |
725 |
|
|
726 |
bits += cbpy_tab[15-(cbp>>2)].len; |
bits += xvid_cbpy_tab[15-(cbp>>2)].len; |
727 |
bits += mcbpc_inter_tab[(MODE_INTER & 7) | ((cbp & 3) << 3)].len; |
bits += mcbpc_inter_tab[(MODE_INTER & 7) | ((cbp & 3) << 3)].len; |
728 |
|
|
729 |
if (bits < data->iMinSAD[0]) { |
if (bits < data->iMinSAD[0]) { |
746 |
CheckCandidateBits8(const int x, const int y, const int Direction, int * const dir, const SearchData * const data) |
CheckCandidateBits8(const int x, const int y, const int Direction, int * const dir, const SearchData * const data) |
747 |
{ |
{ |
748 |
|
|
749 |
static int16_t in[64], coeff[64]; |
int16_t *in = data->dctSpace, *coeff = data->dctSpace + 64; |
750 |
int32_t sum, bits; |
int32_t sum, bits; |
751 |
VECTOR * current; |
VECTOR * current; |
752 |
const uint8_t * ptr; |
const uint8_t * ptr; |
952 |
const uint32_t stride, const uint32_t iQuant, int rrv) |
const uint32_t stride, const uint32_t iQuant, int rrv) |
953 |
|
|
954 |
{ |
{ |
955 |
|
int offset = (x + y*stride)*8; |
956 |
if(!rrv) { |
if(!rrv) { |
957 |
uint32_t sadC = sad8(current->u + x*8 + y*stride*8, |
uint32_t sadC = sad8(current->u + offset, |
958 |
reference->u + x*8 + y*stride*8, stride); |
reference->u + offset, stride); |
959 |
if (sadC > iQuant * MAX_CHROMA_SAD_FOR_SKIP) return 0; |
if (sadC > iQuant * MAX_CHROMA_SAD_FOR_SKIP) return 0; |
960 |
sadC += sad8(current->v + (x + y*stride)*8, |
sadC += sad8(current->v + offset, |
961 |
reference->v + (x + y*stride)*8, stride); |
reference->v + offset, stride); |
962 |
if (sadC > iQuant * MAX_CHROMA_SAD_FOR_SKIP) return 0; |
if (sadC > iQuant * MAX_CHROMA_SAD_FOR_SKIP) return 0; |
963 |
return 1; |
return 1; |
964 |
|
|
965 |
} else { |
} else { |
966 |
uint32_t sadC = sad16(current->u + x*16 + y*stride*16, |
uint32_t sadC = sad16(current->u + 2*offset, |
967 |
reference->u + x*16 + y*stride*16, stride, 256*4096); |
reference->u + 2*offset, stride, 256*4096); |
968 |
if (sadC > iQuant * MAX_CHROMA_SAD_FOR_SKIP*4) return 0; |
if (sadC > iQuant * MAX_CHROMA_SAD_FOR_SKIP*4) return 0; |
969 |
sadC += sad16(current->v + (x + y*stride)*16, |
sadC += sad16(current->v + 2*offset, |
970 |
reference->v + (x + y*stride)*16, stride, 256*4096); |
reference->v + 2*offset, stride, 256*4096); |
971 |
if (sadC > iQuant * MAX_CHROMA_SAD_FOR_SKIP*4) return 0; |
if (sadC > iQuant * MAX_CHROMA_SAD_FOR_SKIP*4) return 0; |
972 |
return 1; |
return 1; |
973 |
} |
} |
998 |
uint32_t mb_width = pParam->mb_width; |
uint32_t mb_width = pParam->mb_width; |
999 |
uint32_t mb_height = pParam->mb_height; |
uint32_t mb_height = pParam->mb_height; |
1000 |
const uint32_t iEdgedWidth = pParam->edged_width; |
const uint32_t iEdgedWidth = pParam->edged_width; |
1001 |
const uint32_t MotionFlags = MakeGoodMotionFlags(current->motion_flags, current->vop_flags, current->vol_flags); |
const uint32_t MotionFlags = MakeGoodMotionFlags(current->motion_flags, current->global_flags); |
1002 |
|
|
1003 |
uint32_t x, y; |
uint32_t x, y; |
1004 |
uint32_t iIntra = 0; |
uint32_t iIntra = 0; |
1005 |
int32_t quant = current->quant, sad00; |
int32_t quant = current->quant, sad00; |
1006 |
int skip_thresh = \ |
int skip_thresh = INITIAL_SKIP_THRESH * |
1007 |
INITIAL_SKIP_THRESH * \ |
(current->global_flags & XVID_REDUCED ? 4:1) * |
1008 |
(current->vop_flags & XVID_VOP_REDUCED ? 4:1) * \ |
(current->global_flags & XVID_MODEDECISION_BITS ? 2:1); |
|
(current->vop_flags & XVID_VOP_MODEDECISION_BITS ? 2:1); |
|
1009 |
|
|
1010 |
// some pre-initialized thingies for SearchP |
// some pre-initialized thingies for SearchP |
1011 |
int32_t temp[8]; |
int32_t temp[8]; |
1012 |
VECTOR currentMV[5]; |
VECTOR currentMV[5]; |
1013 |
VECTOR currentQMV[5]; |
VECTOR currentQMV[5]; |
1014 |
int32_t iMinSAD[5]; |
int32_t iMinSAD[5]; |
1015 |
|
DECLARE_ALIGNED_MATRIX(dct_space, 2, 64, int16_t, CACHE_LINE); |
1016 |
SearchData Data; |
SearchData Data; |
1017 |
memset(&Data, 0, sizeof(SearchData)); |
memset(&Data, 0, sizeof(SearchData)); |
1018 |
Data.iEdgedWidth = iEdgedWidth; |
Data.iEdgedWidth = iEdgedWidth; |
1022 |
Data.temp = temp; |
Data.temp = temp; |
1023 |
Data.iFcode = current->fcode; |
Data.iFcode = current->fcode; |
1024 |
Data.rounding = pParam->m_rounding_type; |
Data.rounding = pParam->m_rounding_type; |
1025 |
Data.qpel = current->vol_flags & XVID_VOL_QUARTERPEL; |
Data.qpel = pParam->m_quarterpel; |
1026 |
Data.chroma = MotionFlags & XVID_ME_CHROMA16; |
Data.chroma = MotionFlags & PMV_CHROMA16; |
1027 |
Data.rrv = current->vop_flags & XVID_VOP_REDUCED; |
Data.rrv = current->global_flags & XVID_REDUCED; |
1028 |
|
Data.dctSpace = dct_space; |
1029 |
|
|
1030 |
if ((current->vop_flags & XVID_VOP_REDUCED)) { |
if ((current->global_flags & XVID_REDUCED)) { |
1031 |
mb_width = (pParam->width + 31) / 32; |
mb_width = (pParam->width + 31) / 32; |
1032 |
mb_height = (pParam->height + 31) / 32; |
mb_height = (pParam->height + 31) / 32; |
1033 |
Data.qpel = 0; |
Data.qpel = 0; |
1060 |
|
|
1061 |
sad00 = pMB->sad16; |
sad00 = pMB->sad16; |
1062 |
|
|
1063 |
if (pMB->dquant != 0) { |
if (!(current->global_flags & XVID_LUMIMASKING)) { |
1064 |
|
pMB->dquant = NO_CHANGE; |
1065 |
|
} else { |
1066 |
|
if (pMB->dquant != NO_CHANGE) { |
1067 |
quant += DQtab[pMB->dquant]; |
quant += DQtab[pMB->dquant]; |
1068 |
if (quant > 31) quant = 31; |
if (quant > 31) quant = 31; |
1069 |
else if (quant < 1) quant = 1; |
else if (quant < 1) quant = 1; |
1070 |
} |
} |
1071 |
|
} |
1072 |
pMB->quant = current->quant; |
pMB->quant = current->quant; |
1073 |
|
|
1074 |
//initial skip decision |
//initial skip decision |
1075 |
/* no early skip for GMC (global vector = skip vector is unknown!) */ |
/* no early skip for GMC (global vector = skip vector is unknown!) */ |
1076 |
if (!(current->vol_flags & XVID_VOL_GMC)) { /* no fast SKIP for S(GMC)-VOPs */ |
if (!(current->global_flags & XVID_GMC)) { /* no fast SKIP for S(GMC)-VOPs */ |
1077 |
if (pMB->dquant == 0 && sad00 < pMB->quant * skip_thresh) |
if (pMB->dquant == NO_CHANGE && sad00 < pMB->quant * skip_thresh) |
1078 |
if (Data.chroma || SkipDecisionP(pCurrent, pRef, x, y, iEdgedWidth/2, pMB->quant, Data.rrv)) { |
if (Data.chroma || SkipDecisionP(pCurrent, pRef, x, y, iEdgedWidth/2, pMB->quant, Data.rrv)) { |
1079 |
SkipMacroblockP(pMB, sad00); |
SkipMacroblockP(pMB, sad00); |
1080 |
continue; |
continue; |
1082 |
} |
} |
1083 |
|
|
1084 |
SearchP(pRef, pRefH->y, pRefV->y, pRefHV->y, pCurrent, x, |
SearchP(pRef, pRefH->y, pRefV->y, pRefHV->y, pCurrent, x, |
1085 |
y, MotionFlags, current->vol_flags, pMB->quant, |
y, MotionFlags, current->global_flags, pMB->quant, |
1086 |
&Data, pParam, pMBs, reference->mbs, |
&Data, pParam, pMBs, reference->mbs, |
1087 |
current->vop_flags & XVID_VOP_INTER4V, pMB); |
current->global_flags & XVID_INTER4V, pMB); |
1088 |
|
|
1089 |
/* final skip decision, a.k.a. "the vector you found, really that good?" */ |
/* final skip decision, a.k.a. "the vector you found, really that good?" */ |
1090 |
if (!(current->vol_flags & XVID_VOL_GMC || current->vop_flags & XVID_VOP_MODEDECISION_BITS)) { |
if (!(current->global_flags & XVID_GMC || current->global_flags & XVID_MODEDECISION_BITS)) { |
1091 |
if ( pMB->dquant == 0 && sad00 < pMB->quant * MAX_SAD00_FOR_SKIP) { |
if ( pMB->dquant == NO_CHANGE && sad00 < pMB->quant * MAX_SAD00_FOR_SKIP) { |
1092 |
if ( (100*pMB->sad16)/(sad00+1) > FINAL_SKIP_THRESH * (Data.rrv ? 4:1) ) |
if ( (100*pMB->sad16)/(sad00+1) > FINAL_SKIP_THRESH * (Data.rrv ? 4:1) ) |
1093 |
if (Data.chroma || SkipDecisionP(pCurrent, pRef, x, y, iEdgedWidth/2, pMB->quant, Data.rrv)) |
if (Data.chroma || SkipDecisionP(pCurrent, pRef, x, y, iEdgedWidth/2, pMB->quant, Data.rrv)) |
1094 |
SkipMacroblockP(pMB, sad00); |
SkipMacroblockP(pMB, sad00); |
1099 |
} |
} |
1100 |
} |
} |
1101 |
|
|
1102 |
if (current->vol_flags & XVID_VOL_GMC ) /* GMC only for S(GMC)-VOPs */ |
if (current->global_flags & XVID_GMC ) /* GMC only for S(GMC)-VOPs */ |
1103 |
{ |
{ |
1104 |
current->warp = GlobalMotionEst( pMBs, pParam, current, reference, pRefH, pRefV, pRefHV); |
current->warp = GlobalMotionEst( pMBs, pParam, current, reference, pRefH, pRefV, pRefHV); |
1105 |
} |
} |
1174 |
const int x, const int y, |
const int x, const int y, |
1175 |
const MBParam * const pParam, |
const MBParam * const pParam, |
1176 |
const uint32_t MotionFlags, |
const uint32_t MotionFlags, |
1177 |
const uint32_t VopFlags) |
const uint32_t GlobalFlags) |
1178 |
{ |
{ |
1179 |
|
|
1180 |
int mode = MODE_INTER; |
int mode = MODE_INTER; |
1181 |
|
|
1182 |
if (!(VopFlags & XVID_VOP_MODEDECISION_BITS)) { //normal, fast, SAD-based mode decision |
if (!(GlobalFlags & XVID_MODEDECISION_BITS)) { //normal, fast, SAD-based mode decision |
|
// int intra = 0; |
|
1183 |
int sad; |
int sad; |
1184 |
int InterBias = MV16_INTER_BIAS; |
int InterBias = MV16_INTER_BIAS; |
1185 |
if (inter4v == 0 || Data->iMinSAD[0] < Data->iMinSAD[1] + Data->iMinSAD[2] + |
if (inter4v == 0 || Data->iMinSAD[0] < Data->iMinSAD[1] + Data->iMinSAD[2] + |
1186 |
Data->iMinSAD[3] + Data->iMinSAD[4] + IMV16X16 * (int32_t)iQuant) { |
Data->iMinSAD[3] + Data->iMinSAD[4] + IMV16X16 * (int32_t)iQuant) { |
1187 |
mode = 0; //inter |
mode = MODE_INTER; |
1188 |
sad = Data->iMinSAD[0]; |
sad = Data->iMinSAD[0]; |
1189 |
} else { |
} else { |
1190 |
mode = MODE_INTER4V; |
mode = MODE_INTER4V; |
1212 |
dev16(Data->Cur + 8*Data->iEdgedWidth, Data->iEdgedWidth) + |
dev16(Data->Cur + 8*Data->iEdgedWidth, Data->iEdgedWidth) + |
1213 |
dev16(Data->Cur+8+8*Data->iEdgedWidth, Data->iEdgedWidth); |
dev16(Data->Cur+8+8*Data->iEdgedWidth, Data->iEdgedWidth); |
1214 |
|
|
1215 |
if (deviation < (sad - InterBias)) return MODE_INTRA;// intra |
if (deviation < (sad - InterBias)) return MODE_INTRA; |
1216 |
} |
} |
1217 |
return mode; |
return mode; |
1218 |
|
|
1221 |
int bits, intra, i; |
int bits, intra, i; |
1222 |
VECTOR backup[5], *v; |
VECTOR backup[5], *v; |
1223 |
Data->lambda16 = iQuant; |
Data->lambda16 = iQuant; |
1224 |
Data->lambda8 = (pParam->vol_flags & XVID_VOL_MPEGQUANT)?1:0; |
Data->lambda8 = pParam->m_quant_type; |
1225 |
|
|
1226 |
v = Data->qpel ? Data->currentQMV : Data->currentMV; |
v = Data->qpel ? Data->currentQMV : Data->currentMV; |
1227 |
for (i = 0; i < 5; i++) { |
for (i = 0; i < 5; i++) { |
1233 |
if (bits == 0) return MODE_INTER; // quick stop |
if (bits == 0) return MODE_INTER; // quick stop |
1234 |
|
|
1235 |
if (inter4v) { |
if (inter4v) { |
1236 |
int inter4v = CountMBBitsInter4v(Data, pMB, pMBs, x, y, pParam, MotionFlags, backup); |
int bits_inter4v = CountMBBitsInter4v(Data, pMB, pMBs, x, y, pParam, MotionFlags, backup); |
1237 |
if (inter4v < bits) { Data->iMinSAD[0] = bits = inter4v; mode = MODE_INTER4V; } |
if (bits_inter4v < bits) { Data->iMinSAD[0] = bits = bits_inter4v; mode = MODE_INTER4V; } |
1238 |
} |
} |
1239 |
|
|
1240 |
|
|
1255 |
const int x, |
const int x, |
1256 |
const int y, |
const int y, |
1257 |
const uint32_t MotionFlags, |
const uint32_t MotionFlags, |
1258 |
const uint32_t VopFlags, |
const uint32_t GlobalFlags, |
1259 |
const uint32_t iQuant, |
const uint32_t iQuant, |
1260 |
SearchData * const Data, |
SearchData * const Data, |
1261 |
const MBParam * const pParam, |
const MBParam * const pParam, |
1290 |
Data->lambda8 = lambda_vec8[iQuant]; |
Data->lambda8 = lambda_vec8[iQuant]; |
1291 |
Data->qpel_precision = 0; |
Data->qpel_precision = 0; |
1292 |
|
|
1293 |
if (pMB->dquant != 0) inter4v = 0; |
if (pMB->dquant != NO_CHANGE) inter4v = 0; |
1294 |
|
|
1295 |
for(i = 0; i < 5; i++) |
memset(Data->currentMV, 0, 5*sizeof(VECTOR)); |
|
Data->currentMV[i].x = Data->currentMV[i].y = 0; |
|
1296 |
|
|
1297 |
if (Data->qpel) Data->predMV = get_qpmv2(pMBs, pParam->mb_width, 0, x, y, 0); |
if (Data->qpel) Data->predMV = get_qpmv2(pMBs, pParam->mb_width, 0, x, y, 0); |
1298 |
else Data->predMV = pmv[0]; |
else Data->predMV = pmv[0]; |
1304 |
Data->iMinSAD[3] = pMB->sad8[2]; |
Data->iMinSAD[3] = pMB->sad8[2]; |
1305 |
Data->iMinSAD[4] = pMB->sad8[3]; |
Data->iMinSAD[4] = pMB->sad8[3]; |
1306 |
|
|
1307 |
if ((!(VopFlags & XVID_VOP_MODEDECISION_BITS)) || (x | y)) { |
if ((!(GlobalFlags & XVID_MODEDECISION_BITS)) || (x | y)) { |
1308 |
threshA = Data->temp[0]; // that's where we keep this SAD atm |
threshA = Data->temp[0]; // that's where we keep this SAD atm |
1309 |
if (threshA < 512) threshA = 512; |
if (threshA < 512) threshA = 512; |
1310 |
else if (threshA > 1024) threshA = 1024; |
else if (threshA > 1024) threshA = 1024; |
1330 |
if ((Data->iMinSAD[0] <= threshA) || |
if ((Data->iMinSAD[0] <= threshA) || |
1331 |
(MVequal(Data->currentMV[0], (prevMBs+x+y*pParam->mb_width)->mvs[0]) && |
(MVequal(Data->currentMV[0], (prevMBs+x+y*pParam->mb_width)->mvs[0]) && |
1332 |
(Data->iMinSAD[0] < (prevMBs+x+y*pParam->mb_width)->sad16))) { |
(Data->iMinSAD[0] < (prevMBs+x+y*pParam->mb_width)->sad16))) { |
1333 |
if (!(VopFlags & XVID_VOP_MODEDECISION_BITS)) inter4v = 0; } |
if (!(GlobalFlags & XVID_MODEDECISION_BITS)) inter4v = 0; } |
1334 |
else { |
else { |
1335 |
|
|
1336 |
MainSearchFunc * MainSearchPtr; |
MainSearchFunc * MainSearchPtr; |
1337 |
if (MotionFlags & XVID_ME_USESQUARES16) MainSearchPtr = SquareSearch; |
if (MotionFlags & PMV_USESQUARES16) MainSearchPtr = SquareSearch; |
1338 |
else if (MotionFlags & XVID_ME_ADVANCEDDIAMOND16) MainSearchPtr = AdvDiamondSearch; |
else if (MotionFlags & PMV_ADVANCEDDIAMOND16) MainSearchPtr = AdvDiamondSearch; |
1339 |
else MainSearchPtr = DiamondSearch; |
else MainSearchPtr = DiamondSearch; |
1340 |
|
|
1341 |
MainSearchPtr(Data->currentMV->x, Data->currentMV->y, Data, iDirection); |
MainSearchPtr(Data->currentMV->x, Data->currentMV->y, Data, iDirection); |
1344 |
note that this search is/might be done in halfpel positions, |
note that this search is/might be done in halfpel positions, |
1345 |
which makes it more different than the diamond above */ |
which makes it more different than the diamond above */ |
1346 |
|
|
1347 |
if (MotionFlags & XVID_ME_EXTSEARCH16) { |
if (MotionFlags & PMV_EXTSEARCH16) { |
1348 |
int32_t bSAD; |
int32_t bSAD; |
1349 |
VECTOR startMV = Data->predMV, backupMV = Data->currentMV[0]; |
VECTOR startMV = Data->predMV, backupMV = Data->currentMV[0]; |
1350 |
if (Data->rrv) { |
if (Data->rrv) { |
1375 |
} |
} |
1376 |
} |
} |
1377 |
|
|
1378 |
if (MotionFlags & XVID_ME_HALFPELREFINE16) |
if (MotionFlags & PMV_HALFPELREFINE16) |
1379 |
if ((!(MotionFlags & XVID_ME_HALFPELREFINE16_BITS)) || Data->iMinSAD[0] < 200*(int)iQuant) |
if ((!(MotionFlags & HALFPELREFINE16_BITS)) || Data->iMinSAD[0] < 200*(int)iQuant) |
1380 |
SubpelRefine(Data); |
SubpelRefine(Data); |
1381 |
|
|
1382 |
for(i = 0; i < 5; i++) { |
for(i = 0; i < 5; i++) { |
1384 |
Data->currentQMV[i].y = 2 * Data->currentMV[i].y; |
Data->currentQMV[i].y = 2 * Data->currentMV[i].y; |
1385 |
} |
} |
1386 |
|
|
1387 |
if (MotionFlags & XVID_ME_QUARTERPELREFINE16) { |
if (MotionFlags & PMV_QUARTERPELREFINE16) { |
1388 |
|
|
1389 |
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 16, |
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 16, |
1390 |
pParam->width, pParam->height, Data->iFcode, 1, 0); |
pParam->width, pParam->height, Data->iFcode, 1, 0); |
1391 |
|
|
1392 |
if ((!(MotionFlags & XVID_ME_QUARTERPELREFINE16_BITS)) || (Data->iMinSAD[0] < 200*(int)iQuant)) { |
if ((!(MotionFlags & QUARTERPELREFINE16_BITS)) || (Data->iMinSAD[0] < 200*(int)iQuant)) { |
1393 |
Data->qpel_precision = 1; |
Data->qpel_precision = 1; |
1394 |
SubpelRefine(Data); |
SubpelRefine(Data); |
1395 |
} |
} |
1396 |
} |
} |
1397 |
|
|
1398 |
if ((!(VopFlags & XVID_VOP_MODEDECISION_BITS)) && (Data->iMinSAD[0] < (int32_t)iQuant * 30)) inter4v = 0; |
if ((!(GlobalFlags & XVID_MODEDECISION_BITS)) && (Data->iMinSAD[0] < (int32_t)iQuant * 30)) inter4v = 0; |
1399 |
|
|
1400 |
if (inter4v && (!(VopFlags & XVID_VOP_MODEDECISION_BITS) || |
if (inter4v && (!(GlobalFlags & XVID_MODEDECISION_BITS) || |
1401 |
(!(MotionFlags & XVID_ME_QUARTERPELREFINE8_BITS)) || (!(MotionFlags & XVID_ME_HALFPELREFINE8_BITS)) || |
(!(MotionFlags & QUARTERPELREFINE8_BITS)) || (!(MotionFlags & HALFPELREFINE8_BITS)) || |
1402 |
((!(MotionFlags & XVID_ME_EXTSEARCH_BITS)) && (!(MotionFlags&XVID_ME_EXTSEARCH8)) ))) { |
((!(MotionFlags & EXTSEARCH_BITS)) && (!(MotionFlags&PMV_EXTSEARCH8)) ))) { |
1403 |
// if decision is BITS-based and all refinement steps will be done in BITS domain, there is no reason to call this loop |
// if decision is BITS-based and all refinement steps will be done in BITS domain, there is no reason to call this loop |
1404 |
|
|
1405 |
SearchData Data8; |
SearchData Data8; |
1410 |
Search8(Data, 2*x, 2*y + 1, MotionFlags, pParam, pMB, pMBs, 2, &Data8); |
Search8(Data, 2*x, 2*y + 1, MotionFlags, pParam, pMB, pMBs, 2, &Data8); |
1411 |
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); |
1412 |
|
|
1413 |
if ((Data->chroma) && (!(VopFlags & XVID_VOP_MODEDECISION_BITS))) { |
if ((Data->chroma) && (!(GlobalFlags & XVID_MODEDECISION_BITS))) { |
1414 |
// chroma is only used for comparsion to INTER. if the comparsion will be done in BITS domain, there is no reason to compute it |
// chroma is only used for comparsion to INTER. if the comparsion will be done in BITS domain, there is no reason to compute it |
1415 |
int sumx = 0, sumy = 0; |
int sumx = 0, sumy = 0; |
1416 |
const int div = 1 + Data->qpel; |
const int div = 1 + Data->qpel; |
1426 |
} |
} |
1427 |
} |
} |
1428 |
|
|
1429 |
inter4v = ModeDecision(iQuant, Data, inter4v, pMB, pMBs, x, y, pParam, MotionFlags, VopFlags); |
inter4v = ModeDecision(iQuant, Data, inter4v, pMB, pMBs, x, y, pParam, MotionFlags, GlobalFlags); |
1430 |
|
|
1431 |
if (Data->rrv) { |
if (Data->rrv) { |
1432 |
Data->currentMV[0].x = RRV_MV_SCALEDOWN(Data->currentMV[0].x); |
Data->currentMV[0].x = RRV_MV_SCALEDOWN(Data->currentMV[0].x); |
1485 |
|
|
1486 |
*(Data->iMinSAD) += (Data->lambda8 * i * (*Data->iMinSAD + NEIGH_8X8_BIAS))>>10; |
*(Data->iMinSAD) += (Data->lambda8 * i * (*Data->iMinSAD + NEIGH_8X8_BIAS))>>10; |
1487 |
|
|
1488 |
if (MotionFlags & (XVID_ME_EXTSEARCH8|XVID_ME_HALFPELREFINE8|XVID_ME_QUARTERPELREFINE8)) { |
if (MotionFlags & (PMV_EXTSEARCH8|PMV_HALFPELREFINE8|PMV_QUARTERPELREFINE8)) { |
1489 |
if (Data->rrv) i = 2; else i = 1; |
if (Data->rrv) i = 2; else i = 1; |
1490 |
|
|
1491 |
Data->Ref = OldData->Ref + i * 8 * ((block&1) + Data->iEdgedWidth*(block>>1)); |
Data->Ref = OldData->Ref + i * 8 * ((block&1) + Data->iEdgedWidth*(block>>1)); |
1502 |
if (!Data->rrv) CheckCandidate = CheckCandidate8; |
if (!Data->rrv) CheckCandidate = CheckCandidate8; |
1503 |
else CheckCandidate = CheckCandidate16no4v; |
else CheckCandidate = CheckCandidate16no4v; |
1504 |
|
|
1505 |
if (MotionFlags & XVID_ME_EXTSEARCH8 && (!(MotionFlags & XVID_ME_EXTSEARCH_BITS))) { |
if (MotionFlags & PMV_EXTSEARCH8 && (!(MotionFlags & EXTSEARCH_BITS))) { |
1506 |
int32_t temp_sad = *(Data->iMinSAD); // store current MinSAD |
int32_t temp_sad = *(Data->iMinSAD); // store current MinSAD |
1507 |
|
|
1508 |
MainSearchFunc *MainSearchPtr; |
MainSearchFunc *MainSearchPtr; |
1509 |
if (MotionFlags & XVID_ME_USESQUARES8) MainSearchPtr = SquareSearch; |
if (MotionFlags & PMV_USESQUARES8) MainSearchPtr = SquareSearch; |
1510 |
else if (MotionFlags & XVID_ME_ADVANCEDDIAMOND8) MainSearchPtr = AdvDiamondSearch; |
else if (MotionFlags & PMV_ADVANCEDDIAMOND8) MainSearchPtr = AdvDiamondSearch; |
1511 |
else MainSearchPtr = DiamondSearch; |
else MainSearchPtr = DiamondSearch; |
1512 |
|
|
1513 |
MainSearchPtr(Data->currentMV->x, Data->currentMV->y, Data, 255); |
MainSearchPtr(Data->currentMV->x, Data->currentMV->y, Data, 255); |
1518 |
} |
} |
1519 |
} |
} |
1520 |
|
|
1521 |
if (MotionFlags & XVID_ME_HALFPELREFINE8) { |
if (MotionFlags & PMV_HALFPELREFINE8) { |
1522 |
int32_t temp_sad = *(Data->iMinSAD); // store current MinSAD |
int32_t temp_sad = *(Data->iMinSAD); // store current MinSAD |
1523 |
|
|
1524 |
SubpelRefine(Data); // perform halfpel refine of current best vector |
SubpelRefine(Data); // perform halfpel refine of current best vector |
1529 |
} |
} |
1530 |
} |
} |
1531 |
|
|
1532 |
if (Data->qpel && MotionFlags & XVID_ME_QUARTERPELREFINE8) { |
if (Data->qpel && MotionFlags & PMV_QUARTERPELREFINE8) { |
1533 |
Data->qpel_precision = 1; |
Data->qpel_precision = 1; |
1534 |
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 8, |
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 8, |
1535 |
pParam->width, pParam->height, Data->iFcode, 1, 0); |
pParam->width, pParam->height, Data->iFcode, 1, 0); |
1653 |
CheckCandidate16no4v(pmv[i].x, pmv[i].y, mask, &iDirection, Data); |
CheckCandidate16no4v(pmv[i].x, pmv[i].y, mask, &iDirection, Data); |
1654 |
} |
} |
1655 |
|
|
1656 |
if (MotionFlags & XVID_ME_USESQUARES16) MainSearchPtr = SquareSearch; |
if (MotionFlags & PMV_USESQUARES16) MainSearchPtr = SquareSearch; |
1657 |
else if (MotionFlags & XVID_ME_ADVANCEDDIAMOND16) MainSearchPtr = AdvDiamondSearch; |
else if (MotionFlags & PMV_ADVANCEDDIAMOND16) MainSearchPtr = AdvDiamondSearch; |
1658 |
else MainSearchPtr = DiamondSearch; |
else MainSearchPtr = DiamondSearch; |
1659 |
|
|
1660 |
MainSearchPtr(Data->currentMV->x, Data->currentMV->y, Data, iDirection); |
MainSearchPtr(Data->currentMV->x, Data->currentMV->y, Data, iDirection); |
1714 |
|
|
1715 |
for (k = 0; k < 4; k++) { |
for (k = 0; k < 4; k++) { |
1716 |
dy += Data->directmvF[k].y / div; |
dy += Data->directmvF[k].y / div; |
1717 |
dx += Data->directmvF[0].x / div; |
dx += Data->directmvF[k].x / div; |
1718 |
b_dy += Data->directmvB[0].y / div; |
b_dy += Data->directmvB[k].y / div; |
1719 |
b_dx += Data->directmvB[0].x / div; |
b_dx += Data->directmvB[k].x / div; |
1720 |
} |
} |
1721 |
|
|
1722 |
dy = (dy >> 3) + roundtab_76[dy & 0xf]; |
dy = (dy >> 3) + roundtab_76[dy & 0xf]; |
1736 |
b_Ref->v + (y*8 + b_dy/2) * stride + x*8 + b_dx/2, |
b_Ref->v + (y*8 + b_dy/2) * stride + x*8 + b_dx/2, |
1737 |
stride); |
stride); |
1738 |
|
|
1739 |
if (sum < 2 * MAX_CHROMA_SAD_FOR_SKIP * pMB->quant) pMB->mode = MODE_DIRECT_NONE_MV; //skipped |
if (sum < 2 * MAX_CHROMA_SAD_FOR_SKIP * pMB->quant) { |
1740 |
|
pMB->mode = MODE_DIRECT_NONE_MV; //skipped |
1741 |
|
for (k = 0; k < 4; k++) { |
1742 |
|
pMB->qmvs[k] = pMB->mvs[k]; |
1743 |
|
pMB->b_qmvs[k] = pMB->b_mvs[k]; |
1744 |
|
} |
1745 |
|
} |
1746 |
} |
} |
1747 |
|
|
1748 |
static __inline uint32_t |
static __inline uint32_t |
1837 |
// DIRECT MODE DELTA VECTOR SEARCH. |
// DIRECT MODE DELTA VECTOR SEARCH. |
1838 |
// This has to be made more effective, but at the moment I'm happy it's running at all |
// This has to be made more effective, but at the moment I'm happy it's running at all |
1839 |
|
|
1840 |
if (MotionFlags & XVID_ME_USESQUARES16) MainSearchPtr = SquareSearch; |
if (MotionFlags & PMV_USESQUARES16) MainSearchPtr = SquareSearch; |
1841 |
else if (MotionFlags & XVID_ME_ADVANCEDDIAMOND16) MainSearchPtr = AdvDiamondSearch; |
else if (MotionFlags & PMV_ADVANCEDDIAMOND16) MainSearchPtr = AdvDiamondSearch; |
1842 |
else MainSearchPtr = DiamondSearch; |
else MainSearchPtr = DiamondSearch; |
1843 |
|
|
1844 |
MainSearchPtr(0, 0, Data, 255); |
MainSearchPtr(0, 0, Data, 255); |
2047 |
Data.currentMV = currentMV; Data.currentQMV = currentQMV; |
Data.currentMV = currentMV; Data.currentQMV = currentQMV; |
2048 |
Data.iMinSAD = &iMinSAD; |
Data.iMinSAD = &iMinSAD; |
2049 |
Data.lambda16 = lambda_vec16[frame->quant]; |
Data.lambda16 = lambda_vec16[frame->quant]; |
2050 |
Data.qpel = pParam->vol_flags & XVID_VOL_QUARTERPEL; |
Data.qpel = pParam->m_quarterpel; |
2051 |
Data.rounding = 0; |
Data.rounding = 0; |
2052 |
Data.chroma = frame->motion_flags & XVID_ME_CHROMA8; |
Data.chroma = frame->motion_flags & PMV_CHROMA8; |
2053 |
Data.temp = temp; |
Data.temp = temp; |
2054 |
|
|
2055 |
Data.RefQ = f_refV->u; // a good place, also used in MC (for similar purpose) |
Data.RefQ = f_refV->u; // a good place, also used in MC (for similar purpose) |
2157 |
{ |
{ |
2158 |
|
|
2159 |
int i, mask; |
int i, mask; |
|
int quarterpel = (pParam->vol_flags & XVID_VOL_QUARTERPEL)? 1: 0; |
|
2160 |
VECTOR pmv[3]; |
VECTOR pmv[3]; |
2161 |
MACROBLOCK * const pMB = &pMBs[x + y * pParam->mb_width]; |
MACROBLOCK * const pMB = &pMBs[x + y * pParam->mb_width]; |
2162 |
|
|
2172 |
else Data->predMV = get_pmv2(pMBs, pParam->mb_width, 0, x, y, 0); //else median |
else Data->predMV = get_pmv2(pMBs, pParam->mb_width, 0, x, y, 0); //else median |
2173 |
|
|
2174 |
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 16, |
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 16, |
2175 |
pParam->width, pParam->height, Data->iFcode - quarterpel, 0, 0); |
pParam->width, pParam->height, Data->iFcode - pParam->m_quarterpel, 0, 0); |
2176 |
|
|
2177 |
Data->Cur = pCur + (x + y * pParam->edged_width) * 16; |
Data->Cur = pCur + (x + y * pParam->edged_width) * 16; |
2178 |
Data->Ref = pRef + (x + y * pParam->edged_width) * 16; |
Data->Ref = pRef + (x + y * pParam->edged_width) * 16; |
2499 |
if (Data->temp[0] == 0 && Data->temp[1] == 0 && Data->temp[2] == 0 && Data->temp[3] == 0) |
if (Data->temp[0] == 0 && Data->temp[1] == 0 && Data->temp[2] == 0 && Data->temp[3] == 0) |
2500 |
return 0; //quick stop |
return 0; //quick stop |
2501 |
|
|
2502 |
if (MotionFlags & (XVID_ME_HALFPELREFINE16_BITS | XVID_ME_EXTSEARCH_BITS)) { //we have to prepare for halfpixel-precision search |
if (MotionFlags & (HALFPELREFINE16_BITS | EXTSEARCH_BITS)) { //we have to prepare for halfpixel-precision search |
2503 |
for(i = 0; i < 5; i++) bsad[i] = Data->iMinSAD[i]; |
for(i = 0; i < 5; i++) bsad[i] = Data->iMinSAD[i]; |
2504 |
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 16, |
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 16, |
2505 |
pParam->width, pParam->height, Data->iFcode - Data->qpel, 0, Data->rrv); |
pParam->width, pParam->height, Data->iFcode - Data->qpel, 0, Data->rrv); |
2517 |
} |
} |
2518 |
} |
} |
2519 |
|
|
2520 |
if (MotionFlags&XVID_ME_EXTSEARCH_BITS) SquareSearch(Data->currentMV->x, Data->currentMV->y, Data, iDirection); |
if (MotionFlags&EXTSEARCH_BITS) SquareSearch(Data->currentMV->x, Data->currentMV->y, Data, iDirection); |
2521 |
|
|
2522 |
if (MotionFlags&XVID_ME_HALFPELREFINE16_BITS) SubpelRefine(Data); |
if (MotionFlags&HALFPELREFINE16_BITS) SubpelRefine(Data); |
2523 |
|
|
2524 |
if (Data->qpel) { |
if (Data->qpel) { |
2525 |
if (MotionFlags&(XVID_ME_EXTSEARCH_BITS | XVID_ME_HALFPELREFINE16_BITS)) { // there was halfpel-precision search |
if (MotionFlags&(EXTSEARCH_BITS | HALFPELREFINE16_BITS)) { // there was halfpel-precision search |
2526 |
for(i = 0; i < 5; i++) if (bsad[i] > Data->iMinSAD[i]) { |
for(i = 0; i < 5; i++) if (bsad[i] > Data->iMinSAD[i]) { |
2527 |
Data->currentQMV[i].x = 2 * Data->currentMV[i].x; // we have found a better match |
Data->currentQMV[i].x = 2 * Data->currentMV[i].x; // we have found a better match |
2528 |
Data->currentQMV[i].y = 2 * Data->currentMV[i].y; |
Data->currentQMV[i].y = 2 * Data->currentMV[i].y; |
2533 |
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 16, |
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 16, |
2534 |
pParam->width, pParam->height, Data->iFcode, 1, 0); |
pParam->width, pParam->height, Data->iFcode, 1, 0); |
2535 |
} |
} |
2536 |
if (MotionFlags&XVID_ME_QUARTERPELREFINE16_BITS) SubpelRefine(Data); |
if (MotionFlags&QUARTERPELREFINE16_BITS) SubpelRefine(Data); |
2537 |
} |
} |
2538 |
|
|
2539 |
if (MotionFlags&XVID_ME_CHECKPREDICTION_BITS) { //let's check vector equal to prediction |
if (MotionFlags&CHECKPREDICTION_BITS) { //let's check vector equal to prediction |
2540 |
VECTOR * v = Data->qpel ? Data->currentQMV : Data->currentMV; |
VECTOR * v = Data->qpel ? Data->currentQMV : Data->currentMV; |
2541 |
if (!(Data->predMV.x == v->x && Data->predMV.y == v->y)) |
if (!(Data->predMV.x == v->x && Data->predMV.y == v->y)) |
2542 |
CheckCandidateBits16(Data->predMV.x, Data->predMV.y, 255, &iDirection, Data); |
CheckCandidateBits16(Data->predMV.x, Data->predMV.y, 255, &iDirection, Data); |
2556 |
int cbp = 0, bits = 0, t = 0, i, iDirection; |
int cbp = 0, bits = 0, t = 0, i, iDirection; |
2557 |
SearchData Data2, *Data8 = &Data2; |
SearchData Data2, *Data8 = &Data2; |
2558 |
int sumx = 0, sumy = 0; |
int sumx = 0, sumy = 0; |
2559 |
int16_t in[64], coeff[64]; |
int16_t *in = Data->dctSpace, *coeff = Data->dctSpace + 64; |
2560 |
|
|
2561 |
memcpy(Data8, Data, sizeof(SearchData)); |
memcpy(Data8, Data, sizeof(SearchData)); |
2562 |
CheckCandidate = CheckCandidateBits8; |
CheckCandidate = CheckCandidateBits8; |
2597 |
} |
} |
2598 |
|
|
2599 |
if (Data8->qpel) { |
if (Data8->qpel) { |
2600 |
if (MotionFlags&XVID_ME_HALFPELREFINE8_BITS || (MotionFlags&XVID_ME_EXTSEARCH8 && MotionFlags&XVID_ME_EXTSEARCH_BITS)) { // halfpixel motion search follows |
if (MotionFlags&HALFPELREFINE8_BITS || (MotionFlags&PMV_EXTSEARCH8 && MotionFlags&EXTSEARCH_BITS)) { // halfpixel motion search follows |
2601 |
int32_t s = *Data8->iMinSAD; |
int32_t s = *Data8->iMinSAD; |
2602 |
Data8->currentMV->x = Data8->currentQMV->x/2; |
Data8->currentMV->x = Data8->currentQMV->x/2; |
2603 |
Data8->currentMV->y = Data8->currentQMV->y/2; |
Data8->currentMV->y = Data8->currentQMV->y/2; |
2608 |
if (Data8->currentQMV->x & 1 || Data8->currentQMV->y & 1) |
if (Data8->currentQMV->x & 1 || Data8->currentQMV->y & 1) |
2609 |
CheckCandidateBits8(Data8->currentMV->x, Data8->currentMV->y, 255, &iDirection, Data8); |
CheckCandidateBits8(Data8->currentMV->x, Data8->currentMV->y, 255, &iDirection, Data8); |
2610 |
|
|
2611 |
if (MotionFlags & XVID_ME_EXTSEARCH8 && MotionFlags & XVID_ME_EXTSEARCH_BITS) |
if (MotionFlags & PMV_EXTSEARCH8 && MotionFlags & EXTSEARCH_BITS) |
2612 |
SquareSearch(Data8->currentMV->x, Data8->currentMV->x, Data8, 255); |
SquareSearch(Data8->currentMV->x, Data8->currentMV->x, Data8, 255); |
2613 |
|
|
2614 |
if (MotionFlags & XVID_ME_HALFPELREFINE8_BITS) SubpelRefine(Data8); |
if (MotionFlags & HALFPELREFINE8_BITS) SubpelRefine(Data8); |
2615 |
|
|
2616 |
if(s > *Data8->iMinSAD) { //we have found a better match |
if(s > *Data8->iMinSAD) { //we have found a better match |
2617 |
Data8->currentQMV->x = 2*Data8->currentMV->x; |
Data8->currentQMV->x = 2*Data8->currentMV->x; |
2623 |
pParam->width, pParam->height, Data8->iFcode, 1, 0); |
pParam->width, pParam->height, Data8->iFcode, 1, 0); |
2624 |
|
|
2625 |
} |
} |
2626 |
if (MotionFlags & XVID_ME_QUARTERPELREFINE8_BITS) SubpelRefine(Data8); |
if (MotionFlags & QUARTERPELREFINE8_BITS) SubpelRefine(Data8); |
2627 |
|
|
2628 |
} else // not qpel |
} else // not qpel |
2629 |
if (MotionFlags & XVID_ME_HALFPELREFINE8_BITS) SubpelRefine(Data8); //halfpel mode, halfpel refinement |
if (MotionFlags & HALFPELREFINE8_BITS) SubpelRefine(Data8); //halfpel mode, halfpel refinement |
2630 |
|
|
2631 |
//checking vector equal to predicion |
//checking vector equal to predicion |
2632 |
if (i != 0 && MotionFlags & XVID_ME_CHECKPREDICTION_BITS) { |
if (i != 0 && MotionFlags & CHECKPREDICTION_BITS) { |
2633 |
const VECTOR * v = Data->qpel ? Data8->currentQMV : Data8->currentMV; |
const VECTOR * v = Data->qpel ? Data8->currentQMV : Data8->currentMV; |
2634 |
if (!(Data8->predMV.x == v->x && Data8->predMV.y == v->y)) |
if (!(Data8->predMV.x == v->x && Data8->predMV.y == v->y)) |
2635 |
CheckCandidateBits8(Data8->predMV.x, Data8->predMV.y, 255, &iDirection, Data8); |
CheckCandidateBits8(Data8->predMV.x, Data8->predMV.y, 255, &iDirection, Data8); |
2683 |
bits += CodeCoeffInter_CalcBits(coeff, scan_tables[0]); |
bits += CodeCoeffInter_CalcBits(coeff, scan_tables[0]); |
2684 |
cbp |= 1 << (5 - 5); |
cbp |= 1 << (5 - 5); |
2685 |
} |
} |
2686 |
bits += cbpy_tab[15-(cbp>>2)].len; |
bits += xvid_cbpy_tab[15-(cbp>>2)].len; |
2687 |
bits += mcbpc_inter_tab[(MODE_INTER4V & 7) | ((cbp & 3) << 3)].len; |
bits += mcbpc_inter_tab[(MODE_INTER4V & 7) | ((cbp & 3) << 3)].len; |
2688 |
} |
} |
2689 |
} |
} |
2698 |
int bits = 1; //this one is ac/dc prediction flag. always 1. |
int bits = 1; //this one is ac/dc prediction flag. always 1. |
2699 |
int cbp = 0, i, t, dc = 0, b_dc = 1024; |
int cbp = 0, i, t, dc = 0, b_dc = 1024; |
2700 |
const uint32_t iQuant = Data->lambda16; |
const uint32_t iQuant = Data->lambda16; |
2701 |
int16_t in[64], coeff[64]; |
int16_t *in = Data->dctSpace, * coeff = Data->dctSpace + 64; |
2702 |
|
|
2703 |
for(i = 0; i < 4; i++) { |
for(i = 0; i < 4; i++) { |
2704 |
uint32_t iDcScaler = get_dc_scaler(iQuant, 1); |
uint32_t iDcScaler = get_dc_scaler(iQuant, 1); |
2746 |
bits += t = CodeCoeffIntra_CalcBits(coeff, scan_tables[0]) + dcc_tab[coeff[0] + 255].len; |
bits += t = CodeCoeffIntra_CalcBits(coeff, scan_tables[0]) + dcc_tab[coeff[0] + 255].len; |
2747 |
if (t != 0) cbp |= 1 << (5 - 5); |
if (t != 0) cbp |= 1 << (5 - 5); |
2748 |
|
|
2749 |
bits += cbpy_tab[cbp>>2].len; |
bits += xvid_cbpy_tab[cbp>>2].len; |
2750 |
bits += mcbpc_inter_tab[(MODE_INTRA & 7) | ((cbp & 3) << 3)].len; |
bits += mcbpc_inter_tab[(MODE_INTRA & 7) | ((cbp & 3) << 3)].len; |
2751 |
} |
} |
2752 |
} |
} |