667 |
for(i = 0; i < 4; i++) { |
for(i = 0; i < 4; i++) { |
668 |
int s = 8*((i&1) + (i>>1)*data->iEdgedWidth); |
int s = 8*((i&1) + (i>>1)*data->iEdgedWidth); |
669 |
transfer_8to16subro(in, data->Cur + s, ptr + s, data->iEdgedWidth); |
transfer_8to16subro(in, data->Cur + s, ptr + s, data->iEdgedWidth); |
670 |
bits += data->temp[i] = Block_CalcBits(coeff, in, data->iQuant, data->quant_type, &cbp, i, 0); |
bits += data->temp[i] = Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, i); |
671 |
} |
} |
672 |
|
|
673 |
bits += t = d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0); |
bits += t = BITS_MULT*d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0); |
674 |
|
|
675 |
bits += xvid_cbpy_tab[15-(cbp>>2)].len; |
//8x8 blocks for inter4v mode |
676 |
|
if (data->temp[0] + t < data->iMinSAD[1]) { |
677 |
|
data->iMinSAD[1] = data->temp[0] + t; current[1].x = x; current[1].y = y; } |
678 |
|
if (data->temp[1] < data->iMinSAD[2]) { |
679 |
|
data->iMinSAD[2] = data->temp[1]; current[2].x = x; current[2].y = y; } |
680 |
|
if (data->temp[2] < data->iMinSAD[3]) { |
681 |
|
data->iMinSAD[3] = data->temp[2]; current[3].x = x; current[3].y = y; } |
682 |
|
if (data->temp[3] < data->iMinSAD[4]) { |
683 |
|
data->iMinSAD[4] = data->temp[3]; current[4].x = x; current[4].y = y; } |
684 |
|
|
685 |
|
bits += BITS_MULT*xvid_cbpy_tab[15-(cbp>>2)].len; |
686 |
|
|
687 |
if (bits >= data->iMinSAD[0]) return; |
if (bits >= data->iMinSAD[0]) return; |
688 |
|
|
693 |
//chroma U |
//chroma U |
694 |
ptr = interpolate8x8_switch2(data->RefQ + 64, data->RefP[4], 0, 0, xc, yc, data->iEdgedWidth/2, data->rounding); |
ptr = interpolate8x8_switch2(data->RefQ + 64, data->RefP[4], 0, 0, xc, yc, data->iEdgedWidth/2, data->rounding); |
695 |
transfer_8to16subro(in, ptr, data->CurU, data->iEdgedWidth/2); |
transfer_8to16subro(in, ptr, data->CurU, data->iEdgedWidth/2); |
696 |
bits += Block_CalcBits(coeff, in, data->iQuant, data->quant_type, &cbp, 4, 0); |
bits += Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, 4); |
697 |
if (bits >= data->iMinSAD[0]) return; |
if (bits >= data->iMinSAD[0]) return; |
698 |
|
|
699 |
//chroma V |
//chroma V |
700 |
ptr = interpolate8x8_switch2(data->RefQ + 64, data->RefP[5], 0, 0, xc, yc, data->iEdgedWidth/2, data->rounding); |
ptr = interpolate8x8_switch2(data->RefQ + 64, data->RefP[5], 0, 0, xc, yc, data->iEdgedWidth/2, data->rounding); |
701 |
transfer_8to16subro(in, ptr, data->CurV, data->iEdgedWidth/2); |
transfer_8to16subro(in, ptr, data->CurV, data->iEdgedWidth/2); |
702 |
bits += Block_CalcBits(coeff, in, data->iQuant, data->quant_type, &cbp, 5, 0); |
bits += Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, 5); |
703 |
|
|
704 |
bits += mcbpc_inter_tab[(MODE_INTER & 7) | ((cbp & 3) << 3)].len; |
bits += BITS_MULT*mcbpc_inter_tab[(MODE_INTER & 7) | ((cbp & 3) << 3)].len; |
705 |
|
|
706 |
if (bits < data->iMinSAD[0]) { |
if (bits < data->iMinSAD[0]) { |
707 |
data->iMinSAD[0] = bits; |
data->iMinSAD[0] = bits; |
708 |
current[0].x = x; current[0].y = y; |
current[0].x = x; current[0].y = y; |
709 |
*dir = Direction; |
*dir = Direction; |
710 |
} |
} |
|
|
|
|
if (data->temp[0] + t < data->iMinSAD[1]) { |
|
|
data->iMinSAD[1] = data->temp[0] + t; current[1].x = x; current[1].y = y; } |
|
|
if (data->temp[1] < data->iMinSAD[2]) { |
|
|
data->iMinSAD[2] = data->temp[1]; current[2].x = x; current[2].y = y; } |
|
|
if (data->temp[2] < data->iMinSAD[3]) { |
|
|
data->iMinSAD[3] = data->temp[2]; current[3].x = x; current[3].y = y; } |
|
|
if (data->temp[3] < data->iMinSAD[4]) { |
|
|
data->iMinSAD[4] = data->temp[3]; current[4].x = x; current[4].y = y; } |
|
|
|
|
711 |
} |
} |
712 |
static void |
static void |
713 |
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) |
731 |
} |
} |
732 |
|
|
733 |
transfer_8to16subro(in, data->Cur, ptr, data->iEdgedWidth); |
transfer_8to16subro(in, data->Cur, ptr, data->iEdgedWidth); |
734 |
bits = Block_CalcBits(coeff, in, data->iQuant, data->quant_type, &cbp, 5, 0); |
bits = Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, 5); |
735 |
bits += d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0); |
bits += BITS_MULT*d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0); |
736 |
|
|
737 |
if (bits < data->iMinSAD[0]) { |
if (bits < data->iMinSAD[0]) { |
738 |
data->temp[0] = cbp; |
data->temp[0] = cbp; |
973 |
Data->iMinSAD[0] = sad; |
Data->iMinSAD[0] = sad; |
974 |
} |
} |
975 |
|
|
976 |
/* 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?" |
977 |
if (skip_possible && (pMB->sad16 < (int)iQuant * MAX_SAD00_FOR_SKIP)) |
if (skip_possible && (pMB->sad16 < (int)iQuant * MAX_SAD00_FOR_SKIP)) |
978 |
if ( (100*sad)/(pMB->sad16+1) > FINAL_SKIP_THRESH) |
if ( (100*sad)/(pMB->sad16+1) > FINAL_SKIP_THRESH) |
979 |
if (Data->chroma || SkipDecisionP(pCurrent, pRef, x, y, Data->iEdgedWidth/2, iQuant, Data->rrv)) { |
if (Data->chroma || SkipDecisionP(pCurrent, pRef, x, y, Data->iEdgedWidth/2, iQuant, Data->rrv)) { |
981 |
sad = 0; |
sad = 0; |
982 |
} |
} |
983 |
|
|
984 |
/* intra decision */ |
// intra decision |
985 |
|
|
986 |
if (iQuant > 8) InterBias += 100 * (iQuant - 8); // to make high quants work |
if (iQuant > 8) InterBias += 100 * (iQuant - 8); // to make high quants work |
987 |
if (y != 0) |
if (y != 0) |
1087 |
VECTOR currentMV[5]; |
VECTOR currentMV[5]; |
1088 |
VECTOR currentQMV[5]; |
VECTOR currentQMV[5]; |
1089 |
int32_t iMinSAD[5]; |
int32_t iMinSAD[5]; |
1090 |
DECLARE_ALIGNED_MATRIX(dct_space, 2, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(dct_space, 3, 64, int16_t, CACHE_LINE); |
1091 |
SearchData Data; |
SearchData Data; |
1092 |
memset(&Data, 0, sizeof(SearchData)); |
memset(&Data, 0, sizeof(SearchData)); |
1093 |
Data.iEdgedWidth = iEdgedWidth; |
Data.iEdgedWidth = iEdgedWidth; |
1150 |
//initial skip decision |
//initial skip decision |
1151 |
/* no early skip for GMC (global vector = skip vector is unknown!) */ |
/* no early skip for GMC (global vector = skip vector is unknown!) */ |
1152 |
if (!(current->global_flags & XVID_GMC)) { /* no fast SKIP for S(GMC)-VOPs */ |
if (!(current->global_flags & XVID_GMC)) { /* no fast SKIP for S(GMC)-VOPs */ |
1153 |
if (pMB->dquant == NO_CHANGE && sad00 < pMB->quant * skip_thresh) |
if (pMB->dquant == NO_CHANGE && sad00 < quant * skip_thresh) |
1154 |
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)) { |
1155 |
SkipMacroblockP(pMB, sad00); |
SkipMacroblockP(pMB, sad00); |
1156 |
continue; |
continue; |
1292 |
Data->iMinSAD[3] = pMB->sad8[2]; |
Data->iMinSAD[3] = pMB->sad8[2]; |
1293 |
Data->iMinSAD[4] = pMB->sad8[3]; |
Data->iMinSAD[4] = pMB->sad8[3]; |
1294 |
|
|
1295 |
if ((!(GlobalFlags & XVID_MODEDECISION_BITS)) || (x | y)) { |
if ((!(GlobalFlags & XVID_MODEDECISION_BITS)) && (x | y)) { |
1296 |
threshA = Data->temp[0]; // that's where we keep this SAD atm |
threshA = Data->temp[0]; // that's where we keep this SAD atm |
1297 |
if (threshA < 512) threshA = 512; |
if (threshA < 512) threshA = 512; |
1298 |
else if (threshA > 1024) threshA = 1024; |
else if (threshA > 1024) threshA = 1024; |
1371 |
Data->currentQMV[i].y = 2 * Data->currentMV[i].y; |
Data->currentQMV[i].y = 2 * Data->currentMV[i].y; |
1372 |
} |
} |
1373 |
|
|
1374 |
if (MotionFlags & PMV_QUARTERPELREFINE16) { |
if (Data->qpel) { |
|
|
|
1375 |
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, |
1376 |
pParam->width, pParam->height, Data->iFcode, 1, 0); |
pParam->width, pParam->height, Data->iFcode, 1, 0); |
1377 |
Data->qpel_precision = 1; |
Data->qpel_precision = 1; |
1378 |
|
if (MotionFlags & PMV_QUARTERPELREFINE16) |
1379 |
SubpelRefine(Data); |
SubpelRefine(Data); |
1380 |
} |
} |
1381 |
|
|
1382 |
if ((!(GlobalFlags & XVID_MODEDECISION_BITS)) && (Data->iMinSAD[0] < (int32_t)pMB->quant * 30)) |
if (Data->iMinSAD[0] < (int32_t)pMB->quant * 30) |
1383 |
inter4v = 0; |
inter4v = 0; |
1384 |
|
|
1385 |
if (inter4v) { |
if (inter4v) { |
1775 |
CheckCandidate(0, 0, 255, &k, Data); |
CheckCandidate(0, 0, 255, &k, Data); |
1776 |
|
|
1777 |
// initial (fast) skip decision |
// initial (fast) skip decision |
1778 |
if (*Data->iMinSAD < pMB->quant * INITIAL_SKIP_THRESH * (2 + Data->chroma?1:0)) { |
if (*Data->iMinSAD < pMB->quant * INITIAL_SKIP_THRESH * (Data->chroma?3:2)) { |
1779 |
//possible skip |
//possible skip |
1780 |
if (Data->chroma) { |
if (Data->chroma) { |
1781 |
pMB->mode = MODE_DIRECT_NONE_MV; |
pMB->mode = MODE_DIRECT_NONE_MV; |
2159 |
} |
} |
2160 |
} |
} |
2161 |
|
|
2162 |
#define INTRA_THRESH 1800 |
#define INTRA_THRESH 2200 |
2163 |
#define INTER_THRESH 1200 |
#define INTER_THRESH 50 |
2164 |
|
#define INTRA_THRESH2 95 |
2165 |
|
|
2166 |
int |
int |
2167 |
MEanalysis( const IMAGE * const pRef, |
MEanalysis( const IMAGE * const pRef, |
2176 |
int sSAD = 0; |
int sSAD = 0; |
2177 |
MACROBLOCK * const pMBs = Current->mbs; |
MACROBLOCK * const pMBs = Current->mbs; |
2178 |
const IMAGE * const pCurrent = &Current->image; |
const IMAGE * const pCurrent = &Current->image; |
2179 |
int IntraThresh = INTRA_THRESH, InterThresh = INTER_THRESH + 10*b_thresh; |
int IntraThresh = INTRA_THRESH, InterThresh = INTER_THRESH + b_thresh; |
2180 |
int s = 0, blocks = 0; |
int s = 0, blocks = 0; |
2181 |
|
int complexity = 0; |
2182 |
|
|
2183 |
int32_t iMinSAD[5], temp[5]; |
int32_t iMinSAD[5], temp[5]; |
2184 |
VECTOR currentMV[5]; |
VECTOR currentMV[5]; |
2190 |
Data.temp = temp; |
Data.temp = temp; |
2191 |
CheckCandidate = CheckCandidate32I; |
CheckCandidate = CheckCandidate32I; |
2192 |
|
|
2193 |
if (intraCount != 0 && intraCount < 10) // we're right after an I frame |
|
2194 |
|
if (intraCount != 0) { |
2195 |
|
if (intraCount < 10) // we're right after an I frame |
2196 |
IntraThresh += 15 * (intraCount - 10) * (intraCount - 10); |
IntraThresh += 15 * (intraCount - 10) * (intraCount - 10); |
2197 |
else |
else |
2198 |
if ( 5*(maxIntra - intraCount) < maxIntra) // we're close to maximum. 2 sec when max is 10 sec |
if ( 5*(maxIntra - intraCount) < maxIntra) // we're close to maximum. 2 sec when max is 10 sec |
2199 |
IntraThresh -= (IntraThresh * (maxIntra - 8*(maxIntra - intraCount)))/maxIntra; |
IntraThresh -= (IntraThresh * (maxIntra - 8*(maxIntra - intraCount)))/maxIntra; |
2200 |
|
} |
2201 |
|
|
2202 |
InterThresh -= (350 - 8*b_thresh) * bCount; |
InterThresh -= 12 * bCount; |
2203 |
if (InterThresh < 300 + 5*b_thresh) InterThresh = 300 + 5*b_thresh; |
if (InterThresh < 15 + b_thresh) InterThresh = 15 + b_thresh; |
2204 |
|
|
2205 |
if (sadInit) (*sadInit) (); |
if (sadInit) (*sadInit) (); |
2206 |
|
|
2207 |
for (y = 1; y < pParam->mb_height-1; y += 2) { |
for (y = 1; y < pParam->mb_height-1; y += 2) { |
2208 |
for (x = 1; x < pParam->mb_width-1; x += 2) { |
for (x = 1; x < pParam->mb_width-1; x += 2) { |
2209 |
int i; |
int i; |
2210 |
blocks += 4; |
blocks += 10; |
2211 |
|
|
2212 |
if (bCount == 0) pMBs[x + y * pParam->mb_width].mvs[0] = zeroMV; |
if (bCount == 0) pMBs[x + y * pParam->mb_width].mvs[0] = zeroMV; |
2213 |
else { //extrapolation of the vector found for last frame |
else { //extrapolation of the vector found for last frame |
2222 |
for (i = 0; i < 4; i++) { |
for (i = 0; i < 4; i++) { |
2223 |
int dev; |
int dev; |
2224 |
MACROBLOCK *pMB = &pMBs[x+(i&1) + (y+(i>>1)) * pParam->mb_width]; |
MACROBLOCK *pMB = &pMBs[x+(i&1) + (y+(i>>1)) * pParam->mb_width]; |
|
if (pMB->sad16 > IntraThresh) { |
|
2225 |
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, |
2226 |
pParam->edged_width); |
pParam->edged_width); |
2227 |
|
|
2228 |
|
complexity += dev; |
2229 |
if (dev + IntraThresh < pMB->sad16) { |
if (dev + IntraThresh < pMB->sad16) { |
2230 |
pMB->mode = MODE_INTRA; |
pMB->mode = MODE_INTRA; |
2231 |
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; |
2232 |
} |
} |
2233 |
} |
|
2234 |
if (pMB->mvs[0].x == 0 && pMB->mvs[0].y == 0) s++; |
if (pMB->mvs[0].x == 0 && pMB->mvs[0].y == 0) |
2235 |
|
if (dev > 500 && pMB->sad16 < 1000) |
2236 |
|
sSAD += 1000; |
2237 |
|
|
2238 |
sSAD += pMB->sad16; |
sSAD += pMB->sad16; |
2239 |
} |
} |
2240 |
} |
} |
2241 |
} |
} |
2242 |
|
complexity >>= 7; |
2243 |
|
|
2244 |
sSAD /= blocks; |
sSAD /= complexity + 4*blocks; |
|
s = (10*s) / blocks; |
|
|
|
|
|
if (s > 4) sSAD += (s - 2) * (60 - 2*b_thresh); //static block - looks bad when in bframe... |
|
2245 |
|
|
2246 |
|
if (intraCount > 12 && sSAD > INTRA_THRESH2 ) return I_VOP; |
2247 |
if (sSAD > InterThresh ) return P_VOP; |
if (sSAD > InterThresh ) return P_VOP; |
2248 |
emms(); |
emms(); |
2249 |
return B_VOP; |
return B_VOP; |
2453 |
Data->qpel_precision = 1; |
Data->qpel_precision = 1; |
2454 |
CheckCandidateBits16(Data->currentQMV[0].x, Data->currentQMV[0].y, 255, &iDirection, Data); |
CheckCandidateBits16(Data->currentQMV[0].x, Data->currentQMV[0].y, 255, &iDirection, Data); |
2455 |
|
|
|
//checking if this vector is perfect. if it is, we stop. |
|
|
if (Data->temp[0] == 0 && Data->temp[1] == 0 && Data->temp[2] == 0 && Data->temp[3] == 0) |
|
|
return 0; //quick stop |
|
|
|
|
2456 |
if (MotionFlags & (HALFPELREFINE16_BITS | EXTSEARCH_BITS)) { //we have to prepare for halfpixel-precision search |
if (MotionFlags & (HALFPELREFINE16_BITS | EXTSEARCH_BITS)) { //we have to prepare for halfpixel-precision search |
2457 |
for(i = 0; i < 5; i++) bsad[i] = Data->iMinSAD[i]; |
for(i = 0; i < 5; i++) bsad[i] = Data->iMinSAD[i]; |
2458 |
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, |
2465 |
} else { // not qpel |
} else { // not qpel |
2466 |
|
|
2467 |
CheckCandidateBits16(Data->currentMV[0].x, Data->currentMV[0].y, 255, &iDirection, Data); |
CheckCandidateBits16(Data->currentMV[0].x, Data->currentMV[0].y, 255, &iDirection, Data); |
|
//checking if this vector is perfect. if it is, we stop. |
|
|
if (Data->temp[0] == 0 && Data->temp[1] == 0 && Data->temp[2] == 0 && Data->temp[3] == 0) { |
|
|
return 0; //inter |
|
|
} |
|
2468 |
} |
} |
2469 |
|
|
2470 |
if (MotionFlags&EXTSEARCH_BITS) SquareSearch(Data->currentMV->x, Data->currentMV->y, Data, iDirection); |
if (MotionFlags&EXTSEARCH_BITS) SquareSearch(Data->currentMV->x, Data->currentMV->y, Data, iDirection); |
2494 |
return Data->iMinSAD[0]; |
return Data->iMinSAD[0]; |
2495 |
} |
} |
2496 |
|
|
|
|
|
2497 |
static int |
static int |
2498 |
CountMBBitsInter4v(const SearchData * const Data, |
CountMBBitsInter4v(const SearchData * const Data, |
2499 |
MACROBLOCK * const pMB, const MACROBLOCK * const pMBs, |
MACROBLOCK * const pMB, const MACROBLOCK * const pMBs, |
2535 |
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), 8, |
2536 |
pParam->width, pParam->height, Data8->iFcode, Data8->qpel, 0); |
pParam->width, pParam->height, Data8->iFcode, Data8->qpel, 0); |
2537 |
|
|
2538 |
*Data8->iMinSAD += t; |
*Data8->iMinSAD += BITS_MULT*t; |
2539 |
|
|
2540 |
Data8->qpel_precision = Data8->qpel; |
Data8->qpel_precision = Data8->qpel; |
2541 |
// checking the vector which has been found by SAD-based 8x8 search (if it's different than the one found so far) |
// checking the vector which has been found by SAD-based 8x8 search (if it's different than the one found so far) |
2613 |
|
|
2614 |
} // /for all luma blocks |
} // /for all luma blocks |
2615 |
|
|
2616 |
bits += xvid_cbpy_tab[15-(cbp>>2)].len; |
bits += BITS_MULT*xvid_cbpy_tab[15-(cbp>>2)].len; |
2617 |
|
|
2618 |
// let's check chroma |
// let's check chroma |
2619 |
sumx = (sumx >> 3) + roundtab_76[sumx & 0xf]; |
sumx = (sumx >> 3) + roundtab_76[sumx & 0xf]; |
2622 |
//chroma U |
//chroma U |
2623 |
ptr = interpolate8x8_switch2(Data->RefQ + 64, Data->RefP[4], 0, 0, sumx, sumy, Data->iEdgedWidth/2, Data->rounding); |
ptr = interpolate8x8_switch2(Data->RefQ + 64, Data->RefP[4], 0, 0, sumx, sumy, Data->iEdgedWidth/2, Data->rounding); |
2624 |
transfer_8to16subro(in, Data->CurU, ptr, Data->iEdgedWidth/2); |
transfer_8to16subro(in, Data->CurU, ptr, Data->iEdgedWidth/2); |
2625 |
bits += Block_CalcBits(coeff, in, Data->iQuant, Data->quant_type, &cbp, 4, 0); |
bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 4); |
2626 |
|
|
2627 |
if (bits >= *Data->iMinSAD) return bits; |
if (bits >= *Data->iMinSAD) return bits; |
2628 |
|
|
2629 |
//chroma V |
//chroma V |
2630 |
ptr = interpolate8x8_switch2(Data->RefQ + 64, Data->RefP[5], 0, 0, sumx, sumy, Data->iEdgedWidth/2, Data->rounding); |
ptr = interpolate8x8_switch2(Data->RefQ + 64, Data->RefP[5], 0, 0, sumx, sumy, Data->iEdgedWidth/2, Data->rounding); |
2631 |
transfer_8to16subro(in, Data->CurV, ptr, Data->iEdgedWidth/2); |
transfer_8to16subro(in, Data->CurV, ptr, Data->iEdgedWidth/2); |
2632 |
bits += Block_CalcBits(coeff, in, Data->iQuant, Data->quant_type, &cbp, 5, 0); |
bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 5); |
2633 |
|
|
2634 |
bits += mcbpc_inter_tab[(MODE_INTER4V & 7) | ((cbp & 3) << 3)].len; |
bits += BITS_MULT*mcbpc_inter_tab[(MODE_INTER4V & 7) | ((cbp & 3) << 3)].len; |
2635 |
|
|
2636 |
return bits; |
return bits; |
2637 |
} |
} |
2638 |
|
|
|
|
|
2639 |
static int |
static int |
2640 |
CountMBBitsIntra(const SearchData * const Data) |
CountMBBitsIntra(const SearchData * const Data) |
2641 |
{ |
{ |
2642 |
int bits = 1; //this one is ac/dc prediction flag. always 1. |
int bits = BITS_MULT*1; //this one is ac/dc prediction flag bit |
2643 |
int cbp = 0, i, t, dc = 1024, b_dc; |
int cbp = 0, i, dc = 0; |
2644 |
int16_t *in = Data->dctSpace, * coeff = Data->dctSpace + 64; |
int16_t *in = Data->dctSpace, * coeff = Data->dctSpace + 64; |
|
uint32_t iDcScaler = get_dc_scaler(Data->iQuant, 1); |
|
2645 |
|
|
2646 |
for(i = 0; i < 4; i++) { |
for(i = 0; i < 4; i++) { |
2647 |
int s = 8*((i&1) + (i>>1)*Data->iEdgedWidth); |
int s = 8*((i&1) + (i>>1)*Data->iEdgedWidth); |
2648 |
transfer_8to16copy(in, Data->Cur + s, Data->iEdgedWidth); |
transfer_8to16copy(in, Data->Cur + s, Data->iEdgedWidth); |
2649 |
fdct(in); |
bits += Block_CalcBitsIntra(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, i, &dc); |
2650 |
b_dc = in[0]; |
|
|
in[0] -= dc; |
|
|
dc = b_dc; |
|
|
if (Data->quant_type == 0) quant_intra(coeff, in, Data->iQuant, iDcScaler); |
|
|
else quant4_intra(coeff, in, Data->iQuant, iDcScaler); |
|
|
|
|
|
bits += t = CodeCoeffIntra_CalcBits(coeff, scan_tables[0]) + dcy_tab[coeff[0] + 255].len; |
|
|
Data->temp[i] = t; |
|
|
if (t != 0) cbp |= 1 << (5 - i); |
|
2651 |
if (bits >= Data->iMinSAD[0]) return bits; |
if (bits >= Data->iMinSAD[0]) return bits; |
2652 |
} |
} |
2653 |
|
|
2654 |
bits += xvid_cbpy_tab[cbp>>2].len; |
bits += BITS_MULT*xvid_cbpy_tab[cbp>>2].len; |
|
|
|
|
iDcScaler = get_dc_scaler(Data->iQuant, 0); |
|
2655 |
|
|
2656 |
//chroma U |
//chroma U |
2657 |
transfer_8to16copy(in, Data->CurU, Data->iEdgedWidth/2); |
transfer_8to16copy(in, Data->CurU, Data->iEdgedWidth/2); |
2658 |
fdct(in); |
bits += Block_CalcBitsIntra(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 4, &dc); |
|
in[0] -= 1024; |
|
|
if (Data->quant_type == 0) quant_intra(coeff, in, Data->iQuant, iDcScaler); |
|
|
else quant4_intra(coeff, in, Data->iQuant, iDcScaler); |
|
|
|
|
|
bits += t = CodeCoeffIntra_CalcBits(coeff, scan_tables[0]) + dcc_tab[coeff[0] + 255].len; |
|
|
if (t != 0) cbp |= 1 << (5 - 4); |
|
2659 |
|
|
2660 |
if (bits >= Data->iMinSAD[0]) return bits; |
if (bits >= Data->iMinSAD[0]) return bits; |
2661 |
|
|
2662 |
//chroma V |
//chroma V |
2663 |
transfer_8to16copy(in, Data->CurV, Data->iEdgedWidth/2); |
transfer_8to16copy(in, Data->CurV, Data->iEdgedWidth/2); |
2664 |
fdct(in); |
bits += Block_CalcBitsIntra(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 5, &dc); |
|
in[0] -= 1024; |
|
|
if (Data->quant_type == 0) quant_intra(coeff, in, Data->iQuant, iDcScaler); |
|
|
else quant4_intra(coeff, in, Data->iQuant, iDcScaler); |
|
|
|
|
|
bits += t = CodeCoeffIntra_CalcBits(coeff, scan_tables[0]) + dcc_tab[coeff[0] + 255].len; |
|
|
if (t != 0) cbp |= 1 << (5 - 5); |
|
2665 |
|
|
2666 |
bits += mcbpc_inter_tab[(MODE_INTRA & 7) | ((cbp & 3) << 3)].len; |
bits += BITS_MULT*mcbpc_inter_tab[(MODE_INTRA & 7) | ((cbp & 3) << 3)].len; |
2667 |
|
|
2668 |
return bits; |
return bits; |
2669 |
} |
} |