--- mbprediction.c 2003/09/10 22:19:00 1.13.2.8 +++ mbprediction.c 2004/06/12 13:02:12 1.16 @@ -20,7 +20,7 @@ * along with this program ; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: mbprediction.c,v 1.13.2.8 2003/09/10 22:19:00 edgomez Exp $ + * $Id: mbprediction.c,v 1.16 2004/06/12 13:02:12 edgomez Exp $ * ****************************************************************************/ @@ -67,7 +67,7 @@ uint32_t current_quant, int32_t iDcScaler, int16_t predictors[8], - const int bound) + const int bound) { const int mbpos = (y * mb_width) + x; @@ -184,11 +184,8 @@ break; } - /* - * determine ac prediction direction & ac/dc predictor place rescaled ac/dc - * predictions into predictors[] for later use - */ - + /* determine ac prediction direction & ac/dc predictor place rescaled ac/dc + * predictions into predictors[] for later use */ if (abs(pLeft[0] - pDiag[0]) < abs(pDiag[0] - pTop[0])) { *acpred_direction = 1; /* vertical */ predictors[0] = DIV_DIV(pTop[0], iDcScaler); @@ -206,16 +203,20 @@ /* decoder: add predictors to dct_codes[] and - store current coeffs to pred_values[] for future prediction + store current coeffs to pred_values[] for future prediction */ +/* Up to this version, no DC clipping was performed, so we try to be backward + * compatible to avoid artifacts */ +#define BS_VERSION_BUGGY_DC_CLIPPING 34 void add_acdc(MACROBLOCK * pMB, uint32_t block, int16_t dct_codes[64], uint32_t iDcScaler, - int16_t predictors[8]) + int16_t predictors[8], + const int bsversion) { uint8_t acpred_direction = pMB->acpred_directions[block]; int16_t *pCurrent = pMB->pred_values[block]; @@ -224,7 +225,10 @@ DPRINTF(XVID_DEBUG_COEFF,"predictor[0] %i\n", predictors[0]); dct_codes[0] += predictors[0]; /* dc prediction */ - pCurrent[0] = dct_codes[0] * iDcScaler; + pCurrent[0] = dct_codes[0]*iDcScaler; + if (!bsversion || bsversion > BS_VERSION_BUGGY_DC_CLIPPING) { + pCurrent[0] = CLIP(pCurrent[0], -2048, 2047); + } if (acpred_direction == 1) { for (i = 1; i < 8; i++) { @@ -281,6 +285,7 @@ /* store current coeffs to pred_values[] for future prediction */ pCurrent[0] = qcoeff[0] * iDcScaler; + pCurrent[0] = CLIP(pCurrent[0], -2048, 2047); for (i = 1; i < 8; i++) { pCurrent[i] = qcoeff[i]; pCurrent[i + 7] = qcoeff[i * 8]; @@ -337,6 +342,7 @@ /* store current coeffs to pred_values[] for future prediction */ pCurrent[0] = qcoeff[0] * iDcScaler; + pCurrent[0] = CLIP(pCurrent[0], -2048, 2047); for (i = 1; i < 8; i++) { pCurrent[i] = qcoeff[i]; pCurrent[i + 7] = qcoeff[i * 8]; @@ -347,11 +353,7 @@ qcoeff[0] = qcoeff[0] - predictors[0]; /* calc cost before ac prediction */ -#ifdef BIGLUT - Z2 = CodeCoeff_CalcBits(qcoeff, intra_table, scan_tables[0], 1); -#else Z2 = CodeCoeffIntra_CalcBits(qcoeff, scan_tables[0]); -#endif /* apply ac prediction & calc cost*/ if (direction == 1) { @@ -368,18 +370,14 @@ } } -#ifdef BIGLUT - Z1 = CodeCoeff_CalcBits(qcoeff, intra_table, scan_tables[direction], 1); -#else Z1 = CodeCoeffIntra_CalcBits(qcoeff, scan_tables[direction]); -#endif /* undo prediction */ if (direction == 1) { - for (i = 1; i < 8; i++) + for (i = 1; i < 8; i++) qcoeff[i] = tmp[i]; }else{ /* acpred_direction == 2 */ - for (i = 1; i < 8; i++) + for (i = 1; i < 8; i++) qcoeff[i*8] = tmp[i]; } @@ -397,10 +395,10 @@ unsigned int i; if (pMB->acpred_directions[block] == 1) { - for (i = 1; i < 8; i++) + for (i = 1; i < 8; i++) qcoeff[i] = predictors[i]; } else { - for (i = 1; i < 8; i++) + for (i = 1; i < 8; i++) qcoeff[i * 8] = predictors[i]; } } @@ -441,10 +439,10 @@ for (j = 0; j < 6; j++) pMB->acpred_directions[j] = 0; }else{ - for (j = 0; j < 6; j++) + for (j = 0; j < 6; j++) apply_acdc(pMB, j, &qcoeff[j * 64], predictors[j]); } - + pMB->cbp = calc_cbp(qcoeff); } }