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.22 2003-07-13 09:58:44 syskin Exp $ |
* $Id: motion_est.c,v 1.58.2.28 2003-08-25 15:10:13 syskin Exp $ |
25 |
* |
* |
26 |
****************************************************************************/ |
****************************************************************************/ |
27 |
|
|
109 |
{ |
{ |
110 |
int sad; |
int sad; |
111 |
const uint32_t stride = data->iEdgedWidth/2; |
const uint32_t stride = data->iEdgedWidth/2; |
112 |
uint8_t * f_refu = data->RefQ, |
uint8_t *f_refu, *f_refv, *b_refu, *b_refv; |
113 |
* f_refv = data->RefQ + 8, |
|
114 |
* b_refu = data->RefQ + 16, |
const INTERPOLATE8X8_PTR interpolate8x8_halfpel[] = { |
115 |
* b_refv = data->RefQ + 24; |
NULL, |
116 |
|
interpolate8x8_halfpel_v, |
117 |
|
interpolate8x8_halfpel_h, |
118 |
|
interpolate8x8_halfpel_hv |
119 |
|
}; |
120 |
|
|
121 |
int offset = (fx>>1) + (fy>>1)*stride; |
int offset = (fx>>1) + (fy>>1)*stride; |
122 |
|
int filter = ((fx & 1) << 1) | (fy & 1); |
123 |
|
|
124 |
switch (((fx & 1) << 1) | (fy & 1)) { |
if (filter != 0) { |
125 |
case 0: |
f_refu = data->RefQ; |
126 |
|
f_refv = data->RefQ + 8; |
127 |
|
interpolate8x8_halfpel[filter](f_refu, data->RefP[4] + offset, stride, data->rounding); |
128 |
|
interpolate8x8_halfpel[filter](f_refv, data->RefP[5] + offset, stride, data->rounding); |
129 |
|
} else { |
130 |
f_refu = (uint8_t*)data->RefP[4] + offset; |
f_refu = (uint8_t*)data->RefP[4] + offset; |
131 |
f_refv = (uint8_t*)data->RefP[5] + offset; |
f_refv = (uint8_t*)data->RefP[5] + offset; |
|
break; |
|
|
case 1: |
|
|
interpolate8x8_halfpel_v(f_refu, data->RefP[4] + offset, stride, data->rounding); |
|
|
interpolate8x8_halfpel_v(f_refv, data->RefP[5] + offset, stride, data->rounding); |
|
|
break; |
|
|
case 2: |
|
|
interpolate8x8_halfpel_h(f_refu, data->RefP[4] + offset, stride, data->rounding); |
|
|
interpolate8x8_halfpel_h(f_refv, data->RefP[5] + offset, stride, data->rounding); |
|
|
break; |
|
|
default: |
|
|
interpolate8x8_halfpel_hv(f_refu, data->RefP[4] + offset, stride, data->rounding); |
|
|
interpolate8x8_halfpel_hv(f_refv, data->RefP[5] + offset, stride, data->rounding); |
|
|
break; |
|
132 |
} |
} |
133 |
|
|
134 |
offset = (bx>>1) + (by>>1)*stride; |
offset = (bx>>1) + (by>>1)*stride; |
135 |
switch (((bx & 1) << 1) | (by & 1)) { |
filter = ((bx & 1) << 1) | (by & 1); |
136 |
case 0: |
|
137 |
|
if (filter != 0) { |
138 |
|
b_refu = data->RefQ + 16; |
139 |
|
b_refv = data->RefQ + 24; |
140 |
|
interpolate8x8_halfpel[filter](b_refu, data->b_RefP[4] + offset, stride, data->rounding); |
141 |
|
interpolate8x8_halfpel[filter](b_refv, data->b_RefP[5] + offset, stride, data->rounding); |
142 |
|
} else { |
143 |
b_refu = (uint8_t*)data->b_RefP[4] + offset; |
b_refu = (uint8_t*)data->b_RefP[4] + offset; |
144 |
b_refv = (uint8_t*)data->b_RefP[5] + offset; |
b_refv = (uint8_t*)data->b_RefP[5] + offset; |
|
break; |
|
|
case 1: |
|
|
interpolate8x8_halfpel_v(b_refu, data->b_RefP[4] + offset, stride, data->rounding); |
|
|
interpolate8x8_halfpel_v(b_refv, data->b_RefP[5] + offset, stride, data->rounding); |
|
|
break; |
|
|
case 2: |
|
|
interpolate8x8_halfpel_h(b_refu, data->b_RefP[4] + offset, stride, data->rounding); |
|
|
interpolate8x8_halfpel_h(b_refv, data->b_RefP[5] + offset, stride, data->rounding); |
|
|
break; |
|
|
default: |
|
|
interpolate8x8_halfpel_hv(b_refu, data->b_RefP[4] + offset, stride, data->rounding); |
|
|
interpolate8x8_halfpel_hv(b_refv, data->b_RefP[5] + offset, stride, data->rounding); |
|
|
break; |
|
145 |
} |
} |
146 |
|
|
147 |
sad = sad8bi(data->CurU, b_refu, f_refu, stride); |
sad = sad8bi(data->CurU, b_refu, f_refu, stride); |
291 |
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); |
292 |
break; |
break; |
293 |
|
|
294 |
|
|
295 |
default: /* pure halfpel position */ |
default: /* pure halfpel position */ |
296 |
return (uint8_t *) ref1; |
return (uint8_t *) ref1; |
297 |
} |
} |
668 |
|
|
669 |
|
|
670 |
static void |
static void |
671 |
CheckCandidateBits16(const int x, const int y, const int Direction, int * const dir, const SearchData * const data) |
CheckCandidateRD16(const int x, const int y, const int Direction, int * const dir, const SearchData * const data) |
672 |
{ |
{ |
673 |
|
|
674 |
int16_t *in = data->dctSpace, *coeff = data->dctSpace + 64; |
int16_t *in = data->dctSpace, *coeff = data->dctSpace + 64; |
675 |
int32_t bits = 0; |
int32_t rd = 0; |
676 |
VECTOR * current; |
VECTOR * current; |
677 |
const uint8_t * ptr; |
const uint8_t * ptr; |
678 |
int i, cbp = 0, t, xc, yc; |
int i, cbp = 0, t, xc, yc; |
693 |
for(i = 0; i < 4; i++) { |
for(i = 0; i < 4; i++) { |
694 |
int s = 8*((i&1) + (i>>1)*data->iEdgedWidth); |
int s = 8*((i&1) + (i>>1)*data->iEdgedWidth); |
695 |
transfer_8to16subro(in, data->Cur + s, ptr + s, data->iEdgedWidth); |
transfer_8to16subro(in, data->Cur + s, ptr + s, data->iEdgedWidth); |
696 |
bits += data->temp[i] = Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, i); |
rd += data->temp[i] = Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, i); |
697 |
} |
} |
698 |
|
|
699 |
bits += t = BITS_MULT*d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0); |
rd += t = BITS_MULT*d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0); |
700 |
|
|
701 |
if (data->temp[0] + t < data->iMinSAD[1]) { |
if (data->temp[0] + t < data->iMinSAD[1]) { |
702 |
data->iMinSAD[1] = data->temp[0] + t; current[1].x = x; current[1].y = y; data->cbp[1] = (data->cbp[1]&~32) | cbp&32; } |
data->iMinSAD[1] = data->temp[0] + t; current[1].x = x; current[1].y = y; data->cbp[1] = (data->cbp[1]&~32) | (cbp&32); } |
703 |
if (data->temp[1] < data->iMinSAD[2]) { |
if (data->temp[1] < data->iMinSAD[2]) { |
704 |
data->iMinSAD[2] = data->temp[1]; current[2].x = x; current[2].y = y; data->cbp[1] = (data->cbp[1]&~16) | cbp&16; } |
data->iMinSAD[2] = data->temp[1]; current[2].x = x; current[2].y = y; data->cbp[1] = (data->cbp[1]&~16) | (cbp&16); } |
705 |
if (data->temp[2] < data->iMinSAD[3]) { |
if (data->temp[2] < data->iMinSAD[3]) { |
706 |
data->iMinSAD[3] = data->temp[2]; current[3].x = x; current[3].y = y; data->cbp[1] = (data->cbp[1]&~8) | cbp&8; } |
data->iMinSAD[3] = data->temp[2]; current[3].x = x; current[3].y = y; data->cbp[1] = (data->cbp[1]&~8) | (cbp&8); } |
707 |
if (data->temp[3] < data->iMinSAD[4]) { |
if (data->temp[3] < data->iMinSAD[4]) { |
708 |
data->iMinSAD[4] = data->temp[3]; current[4].x = x; current[4].y = y; data->cbp[1] = (data->cbp[1]&~4) | cbp&4; } |
data->iMinSAD[4] = data->temp[3]; current[4].x = x; current[4].y = y; data->cbp[1] = (data->cbp[1]&~4) | (cbp&4); } |
709 |
|
|
710 |
bits += BITS_MULT*xvid_cbpy_tab[15-(cbp>>2)].len; |
rd += BITS_MULT*xvid_cbpy_tab[15-(cbp>>2)].len; |
711 |
|
|
712 |
if (bits >= data->iMinSAD[0]) return; |
if (rd >= data->iMinSAD[0]) return; |
713 |
|
|
714 |
/* chroma */ |
/* chroma */ |
715 |
xc = (xc >> 1) + roundtab_79[xc & 0x3]; |
xc = (xc >> 1) + roundtab_79[xc & 0x3]; |
718 |
/* chroma U */ |
/* chroma U */ |
719 |
ptr = interpolate8x8_switch2(data->RefQ, data->RefP[4], 0, 0, xc, yc, data->iEdgedWidth/2, data->rounding); |
ptr = interpolate8x8_switch2(data->RefQ, data->RefP[4], 0, 0, xc, yc, data->iEdgedWidth/2, data->rounding); |
720 |
transfer_8to16subro(in, data->CurU, ptr, data->iEdgedWidth/2); |
transfer_8to16subro(in, data->CurU, ptr, data->iEdgedWidth/2); |
721 |
bits += Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, 4); |
rd += Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, 4); |
722 |
if (bits >= data->iMinSAD[0]) return; |
if (rd >= data->iMinSAD[0]) return; |
723 |
|
|
724 |
/* chroma V */ |
/* chroma V */ |
725 |
ptr = interpolate8x8_switch2(data->RefQ, data->RefP[5], 0, 0, xc, yc, data->iEdgedWidth/2, data->rounding); |
ptr = interpolate8x8_switch2(data->RefQ, data->RefP[5], 0, 0, xc, yc, data->iEdgedWidth/2, data->rounding); |
726 |
transfer_8to16subro(in, data->CurV, ptr, data->iEdgedWidth/2); |
transfer_8to16subro(in, data->CurV, ptr, data->iEdgedWidth/2); |
727 |
bits += Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, 5); |
rd += Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, 5); |
728 |
|
|
729 |
bits += BITS_MULT*mcbpc_inter_tab[(MODE_INTER & 7) | ((cbp & 3) << 3)].len; |
rd += BITS_MULT*mcbpc_inter_tab[(MODE_INTER & 7) | ((cbp & 3) << 3)].len; |
730 |
|
|
731 |
if (bits < data->iMinSAD[0]) { |
if (rd < data->iMinSAD[0]) { |
732 |
data->iMinSAD[0] = bits; |
data->iMinSAD[0] = rd; |
733 |
current[0].x = x; current[0].y = y; |
current[0].x = x; current[0].y = y; |
734 |
*dir = Direction; |
*dir = Direction; |
735 |
*data->cbp = cbp; |
*data->cbp = cbp; |
737 |
} |
} |
738 |
|
|
739 |
static void |
static void |
740 |
CheckCandidateBits8(const int x, const int y, const int Direction, int * const dir, const SearchData * const data) |
CheckCandidateRD8(const int x, const int y, const int Direction, int * const dir, const SearchData * const data) |
741 |
{ |
{ |
742 |
|
|
743 |
int16_t *in = data->dctSpace, *coeff = data->dctSpace + 64; |
int16_t *in = data->dctSpace, *coeff = data->dctSpace + 64; |
744 |
int32_t bits; |
int32_t rd; |
745 |
VECTOR * current; |
VECTOR * current; |
746 |
const uint8_t * ptr; |
const uint8_t * ptr; |
747 |
int cbp = 0; |
int cbp = 0; |
758 |
} |
} |
759 |
|
|
760 |
transfer_8to16subro(in, data->Cur, ptr, data->iEdgedWidth); |
transfer_8to16subro(in, data->Cur, ptr, data->iEdgedWidth); |
761 |
bits = Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, 5); |
rd = Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, 5); |
762 |
bits += BITS_MULT*d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0); |
rd += BITS_MULT*d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0); |
763 |
|
|
764 |
if (bits < data->iMinSAD[0]) { |
if (rd < data->iMinSAD[0]) { |
765 |
*data->cbp = cbp; |
*data->cbp = cbp; |
766 |
data->iMinSAD[0] = bits; |
data->iMinSAD[0] = rd; |
767 |
current[0].x = x; current[0].y = y; |
current[0].x = x; current[0].y = y; |
768 |
*dir = Direction; |
*dir = Direction; |
769 |
} |
} |
961 |
} |
} |
962 |
|
|
963 |
static __inline void |
static __inline void |
964 |
SkipMacroblockP(MACROBLOCK *pMB, const int32_t sad) |
ZeroMacroblockP(MACROBLOCK *pMB, const int32_t sad) |
965 |
{ |
{ |
966 |
pMB->mode = MODE_NOT_CODED; |
pMB->mode = MODE_INTER; |
967 |
pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = zeroMV; |
pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = zeroMV; |
968 |
pMB->qmvs[0] = pMB->qmvs[1] = pMB->qmvs[2] = pMB->qmvs[3] = zeroMV; |
pMB->qmvs[0] = pMB->qmvs[1] = pMB->qmvs[2] = pMB->qmvs[3] = zeroMV; |
969 |
pMB->sad16 = pMB->sad8[0] = pMB->sad8[1] = pMB->sad8[2] = pMB->sad8[3] = sad; |
pMB->sad16 = pMB->sad8[0] = pMB->sad8[1] = pMB->sad8[2] = pMB->sad8[3] = sad; |
992 |
|
|
993 |
pMB->mcsel = 0; |
pMB->mcsel = 0; |
994 |
|
|
995 |
if (!(VopFlags & XVID_VOP_MODEDECISION_BITS)) { /* normal, fast, SAD-based mode decision */ |
if (!(VopFlags & XVID_VOP_MODEDECISION_RD)) { /* normal, fast, SAD-based mode decision */ |
996 |
int sad; |
int sad; |
997 |
int InterBias = MV16_INTER_BIAS; |
int InterBias = MV16_INTER_BIAS; |
998 |
if (inter4v == 0 || Data->iMinSAD[0] < Data->iMinSAD[1] + Data->iMinSAD[2] + |
if (inter4v == 0 || Data->iMinSAD[0] < Data->iMinSAD[1] + Data->iMinSAD[2] + |
1060 |
pMB->cbp = 63; |
pMB->cbp = 63; |
1061 |
pMB->sad16 = pMB->sad8[0] = pMB->sad8[1] = pMB->sad8[2] = pMB->sad8[3] = sad; |
pMB->sad16 = pMB->sad8[0] = pMB->sad8[1] = pMB->sad8[2] = pMB->sad8[3] = sad; |
1062 |
|
|
1063 |
} else { /* BITS */ |
} else { /* Rate-Distortion */ |
1064 |
|
|
1065 |
int bits, intra, i, cbp, c[2] = {0, 0}; |
int min_rd, intra_rd, i, cbp, c[2] = {0, 0}; |
1066 |
VECTOR backup[5], *v; |
VECTOR backup[5], *v; |
1067 |
Data->iQuant = iQuant; |
Data->iQuant = iQuant; |
1068 |
Data->cbp = c; |
Data->cbp = c; |
1073 |
backup[i] = v[i]; |
backup[i] = v[i]; |
1074 |
} |
} |
1075 |
|
|
1076 |
bits = CountMBBitsInter(Data, pMBs, x, y, pParam, MotionFlags); |
min_rd = findRDinter(Data, pMBs, x, y, pParam, MotionFlags); |
1077 |
cbp = *Data->cbp; |
cbp = *Data->cbp; |
1078 |
|
|
1079 |
if (coding_type == S_VOP) { |
if (coding_type == S_VOP) { |
1080 |
int bits_gmc; |
int gmc_rd; |
1081 |
*Data->iMinSAD = bits += BITS_MULT*1; /* mcsel */ |
*Data->iMinSAD = min_rd += BITS_MULT*1; /* mcsel */ |
1082 |
bits_gmc = CountMBBitsGMC(Data, vGMC, x, y); |
gmc_rd = findRDgmc(Data, vGMC, x, y); |
1083 |
if (bits_gmc < bits) { |
if (gmc_rd < min_rd) { |
1084 |
mcsel = 1; |
mcsel = 1; |
1085 |
*Data->iMinSAD = bits = bits_gmc; |
*Data->iMinSAD = min_rd = gmc_rd; |
1086 |
mode = MODE_INTER; |
mode = MODE_INTER; |
1087 |
cbp = *Data->cbp; |
cbp = *Data->cbp; |
1088 |
} |
} |
1089 |
} |
} |
1090 |
|
|
1091 |
if (inter4v) { |
if (inter4v) { |
1092 |
int bits_4v; |
int v4_rd; |
1093 |
bits_4v = CountMBBitsInter4v(Data, pMB, pMBs, x, y, pParam, MotionFlags, backup); |
v4_rd = findRDinter4v(Data, pMB, pMBs, x, y, pParam, MotionFlags, backup); |
1094 |
if (bits_4v < bits) { |
if (v4_rd < min_rd) { |
1095 |
Data->iMinSAD[0] = bits = bits_4v; |
Data->iMinSAD[0] = min_rd = v4_rd; |
1096 |
mode = MODE_INTER4V; |
mode = MODE_INTER4V; |
1097 |
cbp = *Data->cbp; |
cbp = *Data->cbp; |
1098 |
} |
} |
1099 |
} |
} |
1100 |
|
|
1101 |
intra = CountMBBitsIntra(Data); |
intra_rd = findRDintra(Data); |
1102 |
if (intra < bits) { |
if (intra_rd < min_rd) { |
1103 |
*Data->iMinSAD = bits = intra; |
*Data->iMinSAD = min_rd = intra_rd; |
1104 |
mode = MODE_INTRA; |
mode = MODE_INTRA; |
1105 |
} |
} |
1106 |
|
|
1139 |
} else |
} else |
1140 |
if (mode == MODE_INTER4V) ; /* anything here? */ |
if (mode == MODE_INTER4V) ; /* anything here? */ |
1141 |
else /* INTRA, NOT_CODED */ |
else /* INTRA, NOT_CODED */ |
1142 |
SkipMacroblockP(pMB, 0); |
ZeroMacroblockP(pMB, 0); |
1143 |
|
|
1144 |
pMB->mode = mode; |
pMB->mode = mode; |
1145 |
} |
} |
1165 |
|
|
1166 |
uint32_t x, y; |
uint32_t x, y; |
1167 |
uint32_t iIntra = 0; |
uint32_t iIntra = 0; |
1168 |
int32_t quant = current->quant, sad00; |
int32_t sad00; |
1169 |
int skip_thresh = INITIAL_SKIP_THRESH * \ |
int skip_thresh = INITIAL_SKIP_THRESH * \ |
1170 |
(current->vop_flags & XVID_VOP_REDUCED ? 4:1) * \ |
(current->vop_flags & XVID_VOP_REDUCED ? 4:1) * \ |
1171 |
(current->vop_flags & XVID_VOP_MODEDECISION_BITS ? 2:1); |
(current->vop_flags & XVID_VOP_MODEDECISION_RD ? 2:1); |
1172 |
|
|
1173 |
/* some pre-initialized thingies for SearchP */ |
/* some pre-initialized thingies for SearchP */ |
1174 |
int32_t temp[8]; |
int32_t temp[8]; |
1186 |
Data.iFcode = current->fcode; |
Data.iFcode = current->fcode; |
1187 |
Data.rounding = pParam->m_rounding_type; |
Data.rounding = pParam->m_rounding_type; |
1188 |
Data.qpel = (current->vol_flags & XVID_VOL_QUARTERPEL ? 1:0); |
Data.qpel = (current->vol_flags & XVID_VOL_QUARTERPEL ? 1:0); |
1189 |
Data.chroma = MotionFlags & XVID_ME_CHROMA16; |
Data.chroma = MotionFlags & XVID_ME_CHROMA_PVOP; |
1190 |
Data.rrv = (current->vop_flags & XVID_VOP_REDUCED) ? 1:0; |
Data.rrv = (current->vop_flags & XVID_VOP_REDUCED) ? 1:0; |
1191 |
Data.dctSpace = dct_space; |
Data.dctSpace = dct_space; |
1192 |
Data.quant_type = !(pParam->vol_flags & XVID_VOL_MPEGQUANT); |
Data.quant_type = !(pParam->vol_flags & XVID_VOL_MPEGQUANT); |
1224 |
|
|
1225 |
sad00 = pMB->sad16; |
sad00 = pMB->sad16; |
1226 |
|
|
|
if (pMB->dquant != 0) { |
|
|
quant += DQtab[pMB->dquant]; |
|
|
if (quant > 31) quant = 31; |
|
|
else if (quant < 1) quant = 1; |
|
|
} |
|
|
pMB->quant = quant; |
|
|
|
|
1227 |
/* initial skip decision */ |
/* initial skip decision */ |
1228 |
/* no early skip for GMC (global vector = skip vector is unknown!) */ |
/* no early skip for GMC (global vector = skip vector is unknown!) */ |
1229 |
if (current->coding_type != S_VOP) { /* no fast SKIP for S(GMC)-VOPs */ |
if (current->coding_type != S_VOP) { /* no fast SKIP for S(GMC)-VOPs */ |
1230 |
if (pMB->dquant == 0 && sad00 < pMB->quant * skip_thresh) |
if (pMB->dquant == 0 && sad00 < pMB->quant * skip_thresh) |
1231 |
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)) { |
1232 |
SkipMacroblockP(pMB, sad00); |
ZeroMacroblockP(pMB, sad00); |
1233 |
|
pMB->mode = MODE_NOT_CODED; |
1234 |
continue; |
continue; |
1235 |
} |
} |
1236 |
} |
} |
1237 |
|
|
1238 |
|
if ((current->vop_flags & XVID_VOP_CARTOON) && |
1239 |
|
(sad00 < pMB->quant * 4 * skip_thresh)) { /* favorize (0,0) vector for cartoons */ |
1240 |
|
ZeroMacroblockP(pMB, sad00); |
1241 |
|
continue; |
1242 |
|
} |
1243 |
|
|
1244 |
SearchP(pRef, pRefH->y, pRefV->y, pRefHV->y, pCurrent, x, |
SearchP(pRef, pRefH->y, pRefV->y, pRefHV->y, pCurrent, x, |
1245 |
y, MotionFlags, current->vop_flags, current->vol_flags, |
y, MotionFlags, current->vop_flags, current->vol_flags, |
1246 |
&Data, pParam, pMBs, reference->mbs, pMB); |
&Data, pParam, pMBs, reference->mbs, pMB); |
1254 |
} |
} |
1255 |
} |
} |
1256 |
|
|
|
// if (current->vol_flags & XVID_VOL_GMC ) /* GMC only for S(GMC)-VOPs */ |
|
|
// { |
|
|
// current->warp = GlobalMotionEst( pMBs, pParam, current, reference, pRefH, pRefV, pRefHV); |
|
|
// } |
|
1257 |
return 0; |
return 0; |
1258 |
} |
} |
1259 |
|
|
1338 |
VECTOR pmv[7]; |
VECTOR pmv[7]; |
1339 |
int inter4v = (VopFlags & XVID_VOP_INTER4V) && (pMB->dquant == 0); |
int inter4v = (VopFlags & XVID_VOP_INTER4V) && (pMB->dquant == 0); |
1340 |
|
|
1341 |
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, 4, |
1342 |
pParam->width, pParam->height, Data->iFcode - Data->qpel, 0, Data->rrv); |
pParam->width, pParam->height, Data->iFcode - Data->qpel, 1, Data->rrv); |
1343 |
|
|
1344 |
get_pmvdata2(pMBs, pParam->mb_width, 0, x, y, 0, pmv, Data->temp); |
get_pmvdata2(pMBs, pParam->mb_width, 0, x, y, 0, pmv, Data->temp); |
1345 |
|
|
1372 |
Data->iMinSAD[3] = pMB->sad8[2]; |
Data->iMinSAD[3] = pMB->sad8[2]; |
1373 |
Data->iMinSAD[4] = pMB->sad8[3]; |
Data->iMinSAD[4] = pMB->sad8[3]; |
1374 |
|
|
1375 |
if ((!(VopFlags & XVID_VOP_MODEDECISION_BITS)) && (x | y)) { |
if ((!(VopFlags & XVID_VOP_MODEDECISION_RD)) && (x | y)) { |
1376 |
threshA = Data->temp[0]; /* that's where we keep this SAD atm */ |
threshA = Data->temp[0]; /* that's where we keep this SAD atm */ |
1377 |
if (threshA < 512) threshA = 512; |
if (threshA < 512) threshA = 512; |
1378 |
else if (threshA > 1024) threshA = 1024; |
else if (threshA > 1024) threshA = 1024; |
1452 |
} |
} |
1453 |
|
|
1454 |
if (Data->qpel) { |
if (Data->qpel) { |
1455 |
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, 4, |
1456 |
pParam->width, pParam->height, Data->iFcode, 1, 0); |
pParam->width, pParam->height, Data->iFcode, 2, 0); |
1457 |
Data->qpel_precision = 1; |
Data->qpel_precision = 1; |
1458 |
if (MotionFlags & XVID_ME_QUARTERPELREFINE16) |
if (MotionFlags & XVID_ME_QUARTERPELREFINE16) |
1459 |
SubpelRefine(Data); |
SubpelRefine(Data); |
1471 |
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); |
1472 |
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); |
1473 |
|
|
1474 |
if ((Data->chroma) && (!(VopFlags & XVID_VOP_MODEDECISION_BITS))) { |
if ((Data->chroma) && (!(VopFlags & XVID_VOP_MODEDECISION_RD))) { |
1475 |
/* chroma is only used for comparsion to INTER. if the comparsion will be done in BITS domain, it will not be used */ |
/* chroma is only used for comparsion to INTER. if the comparsion will be done in BITS domain, it will not be used */ |
1476 |
int sumx = 0, sumy = 0; |
int sumx = 0, sumy = 0; |
1477 |
|
|
1531 |
Data->Cur = OldData->Cur + i * ((block&1) + Data->iEdgedWidth*(block>>1)); |
Data->Cur = OldData->Cur + i * ((block&1) + Data->iEdgedWidth*(block>>1)); |
1532 |
Data->qpel_precision = 0; |
Data->qpel_precision = 0; |
1533 |
|
|
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, 3, |
1535 |
pParam->width, pParam->height, Data->iFcode - Data->qpel, 0, Data->rrv); |
pParam->width, pParam->height, Data->iFcode - Data->qpel, 1, Data->rrv); |
1536 |
|
|
1537 |
if (!Data->rrv) CheckCandidate = CheckCandidate8; |
if (!Data->rrv) CheckCandidate = CheckCandidate8; |
1538 |
else CheckCandidate = CheckCandidate16no4v; |
else CheckCandidate = CheckCandidate16no4v; |
1539 |
|
|
1540 |
if (MotionFlags & XVID_ME_EXTSEARCH8 && (!(MotionFlags & XVID_ME_EXTSEARCH_BITS))) { |
if (MotionFlags & XVID_ME_EXTSEARCH8 && (!(MotionFlags & XVID_ME_EXTSEARCH_RD))) { |
1541 |
int32_t temp_sad = *(Data->iMinSAD); /* store current MinSAD */ |
int32_t temp_sad = *(Data->iMinSAD); /* store current MinSAD */ |
1542 |
|
|
1543 |
MainSearchFunc *MainSearchPtr; |
MainSearchFunc *MainSearchPtr; |
1566 |
|
|
1567 |
if (Data->qpel && MotionFlags & XVID_ME_QUARTERPELREFINE8) { |
if (Data->qpel && MotionFlags & XVID_ME_QUARTERPELREFINE8) { |
1568 |
Data->qpel_precision = 1; |
Data->qpel_precision = 1; |
1569 |
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, 3, |
1570 |
pParam->width, pParam->height, Data->iFcode, 1, 0); |
pParam->width, pParam->height, Data->iFcode, 2, 0); |
1571 |
SubpelRefine(Data); |
SubpelRefine(Data); |
1572 |
} |
} |
1573 |
} |
} |
1671 |
|
|
1672 |
Data->predMV = *predMV; |
Data->predMV = *predMV; |
1673 |
|
|
1674 |
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, 4, |
1675 |
pParam->width, pParam->height, iFcode - Data->qpel, 0, 0); |
pParam->width, pParam->height, iFcode - Data->qpel, 1, 0); |
1676 |
|
|
1677 |
pmv[0] = Data->predMV; |
pmv[0] = Data->predMV; |
1678 |
if (Data->qpel) { pmv[0].x /= 2; pmv[0].y /= 2; } |
if (Data->qpel) { pmv[0].x /= 2; pmv[0].y /= 2; } |
1700 |
Data->currentQMV->x = 2*Data->currentMV->x; |
Data->currentQMV->x = 2*Data->currentMV->x; |
1701 |
Data->currentQMV->y = 2*Data->currentMV->y; |
Data->currentQMV->y = 2*Data->currentMV->y; |
1702 |
Data->qpel_precision = 1; |
Data->qpel_precision = 1; |
1703 |
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, 4, |
1704 |
pParam->width, pParam->height, iFcode, 1, 0); |
pParam->width, pParam->height, iFcode, 2, 0); |
1705 |
SubpelRefine(Data); |
SubpelRefine(Data); |
1706 |
} |
} |
1707 |
|
|
1764 |
b_Ref->u + (y*8 + b_dy/2) * stride + x*8 + b_dx/2, |
b_Ref->u + (y*8 + b_dy/2) * stride + x*8 + b_dx/2, |
1765 |
stride); |
stride); |
1766 |
|
|
1767 |
if (sum >= 2 * MAX_CHROMA_SAD_FOR_SKIP * pMB->quant) return; /* no skip */ |
if (sum >= MAX_CHROMA_SAD_FOR_SKIP * pMB->quant) return; /* no skip */ |
1768 |
|
|
1769 |
sum += sad8bi(pCur->v + 8*x + 8 * y * stride, |
sum += sad8bi(pCur->v + 8*x + 8 * y * stride, |
1770 |
f_Ref->v + (y*8 + dy/2) * stride + x*8 + dx/2, |
f_Ref->v + (y*8 + dy/2) * stride + x*8 + dx/2, |
1771 |
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, |
1772 |
stride); |
stride); |
1773 |
|
|
1774 |
if (sum < 2 * MAX_CHROMA_SAD_FOR_SKIP * pMB->quant) { |
if (sum < MAX_CHROMA_SAD_FOR_SKIP * pMB->quant) { |
1775 |
pMB->mode = MODE_DIRECT_NONE_MV; /* skipped */ |
pMB->mode = MODE_DIRECT_NONE_MV; /* skipped */ |
1776 |
for (k = 0; k < 4; k++) { |
for (k = 0; k < 4; k++) { |
1777 |
pMB->qmvs[k] = pMB->mvs[k]; |
pMB->qmvs[k] = pMB->mvs[k]; |
1967 |
fData->bpredMV = bData.predMV = *b_predMV; |
fData->bpredMV = bData.predMV = *b_predMV; |
1968 |
fData->currentMV[0] = fData->currentMV[2]; |
fData->currentMV[0] = fData->currentMV[2]; |
1969 |
|
|
1970 |
get_range(&fData->min_dx, &fData->max_dx, &fData->min_dy, &fData->max_dy, x, y, 16, pParam->width, pParam->height, fcode - fData->qpel, 0, 0); |
get_range(&fData->min_dx, &fData->max_dx, &fData->min_dy, &fData->max_dy, x, y, 4, pParam->width, pParam->height, fcode - fData->qpel, 1, 0); |
1971 |
get_range(&bData.min_dx, &bData.max_dx, &bData.min_dy, &bData.max_dy, x, y, 16, pParam->width, pParam->height, bcode - fData->qpel, 0, 0); |
get_range(&bData.min_dx, &bData.max_dx, &bData.min_dy, &bData.max_dy, x, y, 4, pParam->width, pParam->height, bcode - fData->qpel, 1, 0); |
1972 |
|
|
1973 |
if (fData->currentMV[0].x > fData->max_dx) fData->currentMV[0].x = fData->max_dx; |
if (fData->currentMV[0].x > fData->max_dx) fData->currentMV[0].x = fData->max_dx; |
1974 |
if (fData->currentMV[0].x < fData->min_dx) fData->currentMV[0].x = fData->min_dx; |
if (fData->currentMV[0].x < fData->min_dx) fData->currentMV[0].x = fData->min_dx; |
2008 |
if (*fData->iMinSAD > *best_sad + 500) return; |
if (*fData->iMinSAD > *best_sad + 500) return; |
2009 |
CheckCandidate = CheckCandidateInt; |
CheckCandidate = CheckCandidateInt; |
2010 |
fData->qpel_precision = bData.qpel_precision = 1; |
fData->qpel_precision = bData.qpel_precision = 1; |
2011 |
get_range(&fData->min_dx, &fData->max_dx, &fData->min_dy, &fData->max_dy, x, y, 16, pParam->width, pParam->height, fcode, 1, 0); |
get_range(&fData->min_dx, &fData->max_dx, &fData->min_dy, &fData->max_dy, x, y, 4, pParam->width, pParam->height, fcode, 2, 0); |
2012 |
get_range(&bData.min_dx, &bData.max_dx, &bData.min_dy, &bData.max_dy, x, y, 16, pParam->width, pParam->height, bcode, 1, 0); |
get_range(&bData.min_dx, &bData.max_dx, &bData.min_dy, &bData.max_dy, x, y, 4, pParam->width, pParam->height, bcode, 2, 0); |
2013 |
fData->currentQMV[2].x = fData->currentQMV[0].x = 2 * fData->currentMV[0].x; |
fData->currentQMV[2].x = fData->currentQMV[0].x = 2 * fData->currentMV[0].x; |
2014 |
fData->currentQMV[2].y = fData->currentQMV[0].y = 2 * fData->currentMV[0].y; |
fData->currentQMV[2].y = fData->currentQMV[0].y = 2 * fData->currentMV[0].y; |
2015 |
fData->currentQMV[1].x = 2 * fData->currentMV[1].x; |
fData->currentQMV[1].x = 2 * fData->currentMV[1].x; |
2084 |
Data.currentMV = currentMV; Data.currentQMV = currentQMV; |
Data.currentMV = currentMV; Data.currentQMV = currentQMV; |
2085 |
Data.iMinSAD = &iMinSAD; |
Data.iMinSAD = &iMinSAD; |
2086 |
Data.lambda16 = lambda_vec16[frame->quant]; |
Data.lambda16 = lambda_vec16[frame->quant]; |
2087 |
Data.qpel = pParam->vol_flags & XVID_VOL_QUARTERPEL; |
Data.qpel = pParam->vol_flags & XVID_VOL_QUARTERPEL ? 1 : 0; |
2088 |
Data.rounding = 0; |
Data.rounding = 0; |
2089 |
Data.chroma = frame->motion_flags & XVID_ME_CHROMA8; |
Data.chroma = frame->motion_flags & XVID_ME_CHROMA_BVOP; |
2090 |
Data.temp = temp; |
Data.temp = temp; |
2091 |
|
|
2092 |
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) */ |
2210 |
Data->predMV = (pMB - 1)->mvs[0]; /* left instead of median */ |
Data->predMV = (pMB - 1)->mvs[0]; /* left instead of median */ |
2211 |
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 */ |
2212 |
|
|
2213 |
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, 4, |
2214 |
pParam->width, pParam->height, Data->iFcode - quarterpel, 0, 0); |
pParam->width, pParam->height, Data->iFcode - quarterpel, 1, 0); |
2215 |
|
|
2216 |
Data->Cur = pCur + (x + y * pParam->edged_width) * 16; |
Data->Cur = pCur + (x + y * pParam->edged_width) * 16; |
2217 |
Data->RefP[0] = pRef + (x + y * pParam->edged_width) * 16; |
Data->RefP[0] = pRef + (x + y * pParam->edged_width) * 16; |
2308 |
dev = dev16(pCurrent->y + (x + (i&1) + (y + (i>>1)) * pParam->edged_width) * 16, |
dev = dev16(pCurrent->y + (x + (i&1) + (y + (i>>1)) * pParam->edged_width) * 16, |
2309 |
pParam->edged_width); |
pParam->edged_width); |
2310 |
|
|
2311 |
complexity += dev; |
complexity += MAX(dev, 300); |
2312 |
if (dev + IntraThresh < pMB->sad16) { |
if (dev + IntraThresh < pMB->sad16) { |
2313 |
pMB->mode = MODE_INTRA; |
pMB->mode = MODE_INTRA; |
2314 |
if (++intra > ((pParam->mb_height-2)*(pParam->mb_width-2))/2) return I_VOP; |
if (++intra > ((pParam->mb_height-2)*(pParam->mb_width-2))/2) return I_VOP; |
2318 |
if (dev > 500 && pMB->sad16 < 1000) |
if (dev > 500 && pMB->sad16 < 1000) |
2319 |
sSAD += 1000; |
sSAD += 1000; |
2320 |
|
|
2321 |
sSAD += pMB->sad16; |
sSAD += (dev < 3000) ? pMB->sad16 : pMB->sad16/2; /* blocks with big contrast differences usually have large SAD - while they look very good in b-frames */ |
2322 |
} |
} |
2323 |
} |
} |
2324 |
} |
} |
2326 |
|
|
2327 |
sSAD /= complexity + 4*blocks; |
sSAD /= complexity + 4*blocks; |
2328 |
|
|
2329 |
if (intraCount > 12 && sSAD > INTRA_THRESH2 ) return I_VOP; |
if (intraCount > 80 && sSAD > INTRA_THRESH2 ) return I_VOP; |
2330 |
if (sSAD > InterThresh ) return P_VOP; |
if (sSAD > InterThresh ) return P_VOP; |
2331 |
emms(); |
emms(); |
2332 |
return B_VOP; |
return B_VOP; |
2336 |
/* functions which perform BITS-based search/bitcount */ |
/* functions which perform BITS-based search/bitcount */ |
2337 |
|
|
2338 |
static int |
static int |
2339 |
CountMBBitsInter(SearchData * const Data, |
findRDinter(SearchData * const Data, |
2340 |
const MACROBLOCK * const pMBs, const int x, const int y, |
const MACROBLOCK * const pMBs, const int x, const int y, |
2341 |
const MBParam * const pParam, |
const MBParam * const pParam, |
2342 |
const uint32_t MotionFlags) |
const uint32_t MotionFlags) |
2344 |
int i, iDirection; |
int i, iDirection; |
2345 |
int32_t bsad[5]; |
int32_t bsad[5]; |
2346 |
|
|
2347 |
CheckCandidate = CheckCandidateBits16; |
CheckCandidate = CheckCandidateRD16; |
2348 |
|
|
2349 |
if (Data->qpel) { |
if (Data->qpel) { |
2350 |
for(i = 0; i < 5; i++) { |
for(i = 0; i < 5; i++) { |
2352 |
Data->currentMV[i].y = Data->currentQMV[i].y/2; |
Data->currentMV[i].y = Data->currentQMV[i].y/2; |
2353 |
} |
} |
2354 |
Data->qpel_precision = 1; |
Data->qpel_precision = 1; |
2355 |
CheckCandidateBits16(Data->currentQMV[0].x, Data->currentQMV[0].y, 255, &iDirection, Data); |
CheckCandidateRD16(Data->currentQMV[0].x, Data->currentQMV[0].y, 255, &iDirection, Data); |
2356 |
|
|
2357 |
if (MotionFlags & (XVID_ME_HALFPELREFINE16_BITS | XVID_ME_EXTSEARCH_BITS)) { /* we have to prepare for halfpixel-precision search */ |
if (MotionFlags & (XVID_ME_HALFPELREFINE16_RD | XVID_ME_EXTSEARCH_RD)) { /* we have to prepare for halfpixel-precision search */ |
2358 |
for(i = 0; i < 5; i++) bsad[i] = Data->iMinSAD[i]; |
for(i = 0; i < 5; i++) bsad[i] = Data->iMinSAD[i]; |
2359 |
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, 4, |
2360 |
pParam->width, pParam->height, Data->iFcode - Data->qpel, 0, Data->rrv); |
pParam->width, pParam->height, Data->iFcode - Data->qpel, 1, Data->rrv); |
2361 |
Data->qpel_precision = 0; |
Data->qpel_precision = 0; |
2362 |
if (Data->currentQMV->x & 1 || Data->currentQMV->y & 1) |
if (Data->currentQMV->x & 1 || Data->currentQMV->y & 1) |
2363 |
CheckCandidateBits16(Data->currentMV[0].x, Data->currentMV[0].y, 255, &iDirection, Data); |
CheckCandidateRD16(Data->currentMV[0].x, Data->currentMV[0].y, 255, &iDirection, Data); |
2364 |
} |
} |
2365 |
|
|
2366 |
} else { /* not qpel */ |
} else { /* not qpel */ |
2367 |
|
|
2368 |
CheckCandidateBits16(Data->currentMV[0].x, Data->currentMV[0].y, 255, &iDirection, Data); |
CheckCandidateRD16(Data->currentMV[0].x, Data->currentMV[0].y, 255, &iDirection, Data); |
2369 |
} |
} |
2370 |
|
|
2371 |
if (MotionFlags&XVID_ME_EXTSEARCH_BITS) SquareSearch(Data->currentMV->x, Data->currentMV->y, Data, iDirection); |
if (MotionFlags&XVID_ME_EXTSEARCH_RD) SquareSearch(Data->currentMV->x, Data->currentMV->y, Data, iDirection); |
2372 |
|
|
2373 |
if (MotionFlags&XVID_ME_HALFPELREFINE16_BITS) SubpelRefine(Data); |
if (MotionFlags&XVID_ME_HALFPELREFINE16_RD) SubpelRefine(Data); |
2374 |
|
|
2375 |
if (Data->qpel) { |
if (Data->qpel) { |
2376 |
if (MotionFlags&(XVID_ME_EXTSEARCH_BITS | XVID_ME_HALFPELREFINE16_BITS)) { /* there was halfpel-precision search */ |
if (MotionFlags&(XVID_ME_EXTSEARCH_RD | XVID_ME_HALFPELREFINE16_RD)) { /* there was halfpel-precision search */ |
2377 |
for(i = 0; i < 5; i++) if (bsad[i] > Data->iMinSAD[i]) { |
for(i = 0; i < 5; i++) if (bsad[i] > Data->iMinSAD[i]) { |
2378 |
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 */ |
2379 |
Data->currentQMV[i].y = 2 * Data->currentMV[i].y; |
Data->currentQMV[i].y = 2 * Data->currentMV[i].y; |
2381 |
|
|
2382 |
/* preparing for qpel-precision search */ |
/* preparing for qpel-precision search */ |
2383 |
Data->qpel_precision = 1; |
Data->qpel_precision = 1; |
2384 |
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, 4, |
2385 |
pParam->width, pParam->height, Data->iFcode, 1, 0); |
pParam->width, pParam->height, Data->iFcode, 2, 0); |
2386 |
} |
} |
2387 |
if (MotionFlags&XVID_ME_QUARTERPELREFINE16_BITS) SubpelRefine(Data); |
if (MotionFlags&XVID_ME_QUARTERPELREFINE16_RD) SubpelRefine(Data); |
2388 |
} |
} |
2389 |
|
|
2390 |
if (MotionFlags&XVID_ME_CHECKPREDICTION_BITS) { /* let's check vector equal to prediction */ |
if (MotionFlags&XVID_ME_CHECKPREDICTION_RD) { /* let's check vector equal to prediction */ |
2391 |
VECTOR * v = Data->qpel ? Data->currentQMV : Data->currentMV; |
VECTOR * v = Data->qpel ? Data->currentQMV : Data->currentMV; |
2392 |
if (!(Data->predMV.x == v->x && Data->predMV.y == v->y)) |
if (!(Data->predMV.x == v->x && Data->predMV.y == v->y)) |
2393 |
CheckCandidateBits16(Data->predMV.x, Data->predMV.y, 255, &iDirection, Data); |
CheckCandidateRD16(Data->predMV.x, Data->predMV.y, 255, &iDirection, Data); |
2394 |
} |
} |
2395 |
return Data->iMinSAD[0]; |
return Data->iMinSAD[0]; |
2396 |
} |
} |
2397 |
|
|
2398 |
static int |
static int |
2399 |
CountMBBitsInter4v(const SearchData * const Data, |
findRDinter4v(const SearchData * const Data, |
2400 |
MACROBLOCK * const pMB, const MACROBLOCK * const pMBs, |
MACROBLOCK * const pMB, const MACROBLOCK * const pMBs, |
2401 |
const int x, const int y, |
const int x, const int y, |
2402 |
const MBParam * const pParam, const uint32_t MotionFlags, |
const MBParam * const pParam, const uint32_t MotionFlags, |
2410 |
uint8_t * ptr; |
uint8_t * ptr; |
2411 |
|
|
2412 |
memcpy(Data8, Data, sizeof(SearchData)); |
memcpy(Data8, Data, sizeof(SearchData)); |
2413 |
CheckCandidate = CheckCandidateBits8; |
CheckCandidate = CheckCandidateRD8; |
2414 |
|
|
2415 |
for (i = 0; i < 4; i++) { /* for all luma blocks */ |
for (i = 0; i < 4; i++) { /* for all luma blocks */ |
2416 |
|
|
2423 |
Data8->RefP[1] = Data->RefP[1] + 8*((i&1) + (i>>1)*Data->iEdgedWidth); |
Data8->RefP[1] = Data->RefP[1] + 8*((i&1) + (i>>1)*Data->iEdgedWidth); |
2424 |
Data8->RefP[3] = Data->RefP[3] + 8*((i&1) + (i>>1)*Data->iEdgedWidth); |
Data8->RefP[3] = Data->RefP[3] + 8*((i&1) + (i>>1)*Data->iEdgedWidth); |
2425 |
*Data8->cbp = (Data->cbp[1] & (1<<(5-i))) ? 1:0; // copy corresponding cbp bit |
*Data8->cbp = (Data->cbp[1] & (1<<(5-i))) ? 1:0; // copy corresponding cbp bit |
|
// *Data8->cbp = 1; |
|
2426 |
|
|
2427 |
if(Data->qpel) { |
if(Data->qpel) { |
2428 |
Data8->predMV = get_qpmv2(pMBs, pParam->mb_width, 0, x, y, i); |
Data8->predMV = get_qpmv2(pMBs, pParam->mb_width, 0, x, y, i); |
2434 |
Data8->predMV, Data8->iFcode, 0, 0); |
Data8->predMV, Data8->iFcode, 0, 0); |
2435 |
} |
} |
2436 |
|
|
2437 |
get_range(&Data8->min_dx, &Data8->max_dx, &Data8->min_dy, &Data8->max_dy, 2*x + (i&1), 2*y + (i>>1), 8, |
get_range(&Data8->min_dx, &Data8->max_dx, &Data8->min_dy, &Data8->max_dy, 2*x + (i&1), 2*y + (i>>1), 3, |
2438 |
pParam->width, pParam->height, Data8->iFcode, Data8->qpel, 0); |
pParam->width, pParam->height, Data8->iFcode, Data8->qpel+1, 0); |
2439 |
|
|
2440 |
*Data8->iMinSAD += BITS_MULT*t; |
*Data8->iMinSAD += BITS_MULT*t; |
2441 |
|
|
2444 |
{ |
{ |
2445 |
VECTOR *v = Data8->qpel ? Data8->currentQMV : Data8->currentMV; |
VECTOR *v = Data8->qpel ? Data8->currentQMV : Data8->currentMV; |
2446 |
if (!MVequal (*v, backup[i+1]) ) |
if (!MVequal (*v, backup[i+1]) ) |
2447 |
CheckCandidateBits8(backup[i+1].x, backup[i+1].y, 255, &iDirection, Data8); |
CheckCandidateRD8(backup[i+1].x, backup[i+1].y, 255, &iDirection, Data8); |
2448 |
} |
} |
2449 |
|
|
2450 |
if (Data8->qpel) { |
if (Data8->qpel) { |
2451 |
if (MotionFlags&XVID_ME_HALFPELREFINE8_BITS || (MotionFlags&XVID_ME_EXTSEARCH8 && MotionFlags&XVID_ME_EXTSEARCH_BITS)) { /* halfpixel motion search follows */ |
if (MotionFlags&XVID_ME_HALFPELREFINE8_RD || (MotionFlags&XVID_ME_EXTSEARCH8 && MotionFlags&XVID_ME_EXTSEARCH_RD)) { /* halfpixel motion search follows */ |
2452 |
int32_t s = *Data8->iMinSAD; |
int32_t s = *Data8->iMinSAD; |
2453 |
Data8->currentMV->x = Data8->currentQMV->x/2; |
Data8->currentMV->x = Data8->currentQMV->x/2; |
2454 |
Data8->currentMV->y = Data8->currentQMV->y/2; |
Data8->currentMV->y = Data8->currentQMV->y/2; |
2455 |
Data8->qpel_precision = 0; |
Data8->qpel_precision = 0; |
2456 |
get_range(&Data8->min_dx, &Data8->max_dx, &Data8->min_dy, &Data8->max_dy, 2*x + (i&1), 2*y + (i>>1), 8, |
get_range(&Data8->min_dx, &Data8->max_dx, &Data8->min_dy, &Data8->max_dy, 2*x + (i&1), 2*y + (i>>1), 3, |
2457 |
pParam->width, pParam->height, Data8->iFcode - 1, 0, 0); |
pParam->width, pParam->height, Data8->iFcode - 1, 1, 0); |
2458 |
|
|
2459 |
if (Data8->currentQMV->x & 1 || Data8->currentQMV->y & 1) |
if (Data8->currentQMV->x & 1 || Data8->currentQMV->y & 1) |
2460 |
CheckCandidateBits8(Data8->currentMV->x, Data8->currentMV->y, 255, &iDirection, Data8); |
CheckCandidateRD8(Data8->currentMV->x, Data8->currentMV->y, 255, &iDirection, Data8); |
2461 |
|
|
2462 |
if (MotionFlags & XVID_ME_EXTSEARCH8 && MotionFlags & XVID_ME_EXTSEARCH_BITS) |
if (MotionFlags & XVID_ME_EXTSEARCH8 && MotionFlags & XVID_ME_EXTSEARCH_RD) |
2463 |
SquareSearch(Data8->currentMV->x, Data8->currentMV->x, Data8, 255); |
SquareSearch(Data8->currentMV->x, Data8->currentMV->x, Data8, 255); |
2464 |
|
|
2465 |
if (MotionFlags & XVID_ME_HALFPELREFINE8_BITS) |
if (MotionFlags & XVID_ME_HALFPELREFINE8_RD) |
2466 |
SubpelRefine(Data8); |
SubpelRefine(Data8); |
2467 |
|
|
2468 |
if(s > *Data8->iMinSAD) { /* we have found a better match */ |
if(s > *Data8->iMinSAD) { /* we have found a better match */ |
2471 |
} |
} |
2472 |
|
|
2473 |
Data8->qpel_precision = 1; |
Data8->qpel_precision = 1; |
2474 |
get_range(&Data8->min_dx, &Data8->max_dx, &Data8->min_dy, &Data8->max_dy, 2*x + (i&1), 2*y + (i>>1), 8, |
get_range(&Data8->min_dx, &Data8->max_dx, &Data8->min_dy, &Data8->max_dy, 2*x + (i&1), 2*y + (i>>1), 3, |
2475 |
pParam->width, pParam->height, Data8->iFcode, 1, 0); |
pParam->width, pParam->height, Data8->iFcode, 2, 0); |
2476 |
|
|
2477 |
} |
} |
2478 |
if (MotionFlags & XVID_ME_QUARTERPELREFINE8_BITS) SubpelRefine(Data8); |
if (MotionFlags & XVID_ME_QUARTERPELREFINE8_RD) SubpelRefine(Data8); |
2479 |
|
|
2480 |
} else { /* not qpel */ |
} else { /* not qpel */ |
2481 |
|
|
2482 |
if (MotionFlags & XVID_ME_EXTSEARCH8 && MotionFlags & XVID_ME_EXTSEARCH_BITS) /* extsearch */ |
if (MotionFlags & XVID_ME_EXTSEARCH8 && MotionFlags & XVID_ME_EXTSEARCH_RD) /* extsearch */ |
2483 |
SquareSearch(Data8->currentMV->x, Data8->currentMV->x, Data8, 255); |
SquareSearch(Data8->currentMV->x, Data8->currentMV->x, Data8, 255); |
2484 |
|
|
2485 |
if (MotionFlags & XVID_ME_HALFPELREFINE8_BITS) |
if (MotionFlags & XVID_ME_HALFPELREFINE8_RD) |
2486 |
SubpelRefine(Data8); /* halfpel refinement */ |
SubpelRefine(Data8); /* halfpel refinement */ |
2487 |
} |
} |
2488 |
|
|
2489 |
/* checking vector equal to predicion */ |
/* checking vector equal to predicion */ |
2490 |
if (i != 0 && MotionFlags & XVID_ME_CHECKPREDICTION_BITS) { |
if (i != 0 && MotionFlags & XVID_ME_CHECKPREDICTION_RD) { |
2491 |
const VECTOR * v = Data->qpel ? Data8->currentQMV : Data8->currentMV; |
const VECTOR * v = Data->qpel ? Data8->currentQMV : Data8->currentMV; |
2492 |
if (!MVequal(*v, Data8->predMV)) |
if (!MVequal(*v, Data8->predMV)) |
2493 |
CheckCandidateBits8(Data8->predMV.x, Data8->predMV.y, 255, &iDirection, Data8); |
CheckCandidateRD8(Data8->predMV.x, Data8->predMV.y, 255, &iDirection, Data8); |
2494 |
} |
} |
2495 |
|
|
2496 |
bits += *Data8->iMinSAD; |
bits += *Data8->iMinSAD; |
2540 |
} |
} |
2541 |
|
|
2542 |
static int |
static int |
2543 |
CountMBBitsIntra(const SearchData * const Data) |
findRDintra(const SearchData * const Data) |
2544 |
{ |
{ |
2545 |
int bits = BITS_MULT*1; /* this one is ac/dc prediction flag bit */ |
int bits = BITS_MULT*1; /* this one is ac/dc prediction flag bit */ |
2546 |
int cbp = 0, i, dc = 0; |
int cbp = 0, i, dc = 0; |
2572 |
} |
} |
2573 |
|
|
2574 |
static int |
static int |
2575 |
CountMBBitsGMC(const SearchData * const Data, const IMAGE * const vGMC, const int x, const int y) |
findRDgmc(const SearchData * const Data, const IMAGE * const vGMC, const int x, const int y) |
2576 |
{ |
{ |
2577 |
int bits = BITS_MULT*1; /* this one is mcsel */ |
int bits = BITS_MULT*1; /* this one is mcsel */ |
2578 |
int cbp = 0, i; |
int cbp = 0, i; |
2627 |
|
|
2628 |
Data->predMV = get_pmv2(pMBs, pParam->mb_width, 0, x, y, 0); |
Data->predMV = get_pmv2(pMBs, pParam->mb_width, 0, x, y, 0); |
2629 |
|
|
2630 |
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, 4, |
2631 |
pParam->width, pParam->height, 16, 0, 0); |
pParam->width, pParam->height, 16, 1, 0); |
2632 |
|
|
2633 |
Data->Cur = pCur + 16*(x + y * pParam->edged_width); |
Data->Cur = pCur + 16*(x + y * pParam->edged_width); |
2634 |
Data->RefP[0] = pRef + 16*(x + y * pParam->edged_width); |
Data->RefP[0] = pRef + 16*(x + y * pParam->edged_width); |
2652 |
Data->currentQMV->x = 2*Data->currentMV->x; |
Data->currentQMV->x = 2*Data->currentMV->x; |
2653 |
Data->currentQMV->y = 2*Data->currentMV->y; |
Data->currentQMV->y = 2*Data->currentMV->y; |
2654 |
Data->qpel_precision = 1; |
Data->qpel_precision = 1; |
2655 |
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, 4, |
2656 |
pParam->width, pParam->height, iFcode, 1, 0); |
pParam->width, pParam->height, iFcode, 2, 0); |
2657 |
SubpelRefine(Data); |
SubpelRefine(Data); |
2658 |
} |
} |
2659 |
*/ |
*/ |
2879 |
*/ |
*/ |
2880 |
gmc.duv[0].x= gmc.duv[0].y= gmc.duv[1].x= gmc.duv[1].y= gmc.duv[2].x= gmc.duv[2].y=0; |
gmc.duv[0].x= gmc.duv[0].y= gmc.duv[1].x= gmc.duv[1].y= gmc.duv[2].x= gmc.duv[2].y=0; |
2881 |
|
|
2882 |
if (!(current->motion_flags & XVID_GME_REFINE)) |
if (!(current->motion_flags & XVID_ME_GME_REFINE)) |
2883 |
return gmc; |
return gmc; |
2884 |
|
|
2885 |
for (my = 1; my < (uint32_t)MBh-1; my++) /* ignore boundary blocks */ |
for (my = 1; my < (uint32_t)MBh-1; my++) /* ignore boundary blocks */ |