/* DeQuantize all blocks -- Intra mode */
static __inline void
MBDeQuantIntra(const MBParam * pParam,
			   const int iQuant,
			   int16_t qcoeff[6 * 64],
			   int16_t data[6*64])
{
	int mpeg;
	int scaler_lum, scaler_chr;

	quant_intraFuncPtr const dequant[2] =
		{
			dequant_h263_intra,
			dequant_mpeg_intra
		};

	mpeg = !!(pParam->vol_flags & XVID_VOL_MPEGQUANT);
	scaler_lum = get_dc_scaler(iQuant, 1);
	scaler_chr = get_dc_scaler(iQuant, 0);

	start_timer();
	dequant[mpeg](&qcoeff[0 * 64], &data[0 * 64], iQuant, scaler_lum, pParam->mpeg_quant_matrices);
	dequant[mpeg](&qcoeff[1 * 64], &data[1 * 64], iQuant, scaler_lum, pParam->mpeg_quant_matrices);
	dequant[mpeg](&qcoeff[2 * 64], &data[2 * 64], iQuant, scaler_lum, pParam->mpeg_quant_matrices);
	dequant[mpeg](&qcoeff[3 * 64], &data[3 * 64], iQuant, scaler_lum, pParam->mpeg_quant_matrices);
	dequant[mpeg](&qcoeff[4 * 64], &data[4 * 64], iQuant, scaler_chr, pParam->mpeg_quant_matrices);
	dequant[mpeg](&qcoeff[5 * 64], &data[5 * 64], iQuant, scaler_chr, pParam->mpeg_quant_matrices);
	stop_iquant_timer();
}
/* Quantize all blocks -- Intra mode */
static __inline void
MBQuantIntra(const MBParam * pParam,
			 const FRAMEINFO * const frame,
			 const MACROBLOCK * pMB,
			 int16_t qcoeff[6 * 64],
			 int16_t data[6*64])
{
	int scaler_lum, scaler_chr;
	quant_intraFuncPtr quant;

	/* check if quant matrices need to be re-initialized with new quant */
	if (pParam->vol_flags & XVID_VOL_MPEGQUANT) {
		if (pParam->last_quant_initialized_intra != pMB->quant) {
			init_intra_matrix(pParam->mpeg_quant_matrices, pMB->quant);
		}
		quant = quant_mpeg_intra;
	} else {
		quant = quant_h263_intra;
	}

	scaler_lum = get_dc_scaler(pMB->quant, 1);
	scaler_chr = get_dc_scaler(pMB->quant, 0);

	/* Quantize the block */
	start_timer();
	quant(&data[0 * 64], &qcoeff[0 * 64], pMB->quant, scaler_lum, pParam->mpeg_quant_matrices);
	quant(&data[1 * 64], &qcoeff[1 * 64], pMB->quant, scaler_lum, pParam->mpeg_quant_matrices);
	quant(&data[2 * 64], &qcoeff[2 * 64], pMB->quant, scaler_lum, pParam->mpeg_quant_matrices);
	quant(&data[3 * 64], &qcoeff[3 * 64], pMB->quant, scaler_lum, pParam->mpeg_quant_matrices);
	quant(&data[4 * 64], &qcoeff[4 * 64], pMB->quant, scaler_chr, pParam->mpeg_quant_matrices);
	quant(&data[5 * 64], &qcoeff[5 * 64], pMB->quant, scaler_chr, pParam->mpeg_quant_matrices);
	stop_quant_timer();
}
Exemplo n.º 3
0
void
MBPrediction(FRAMEINFO * frame,
			 uint32_t x,
			 uint32_t y,
			 uint32_t mb_width,
			 int16_t qcoeff[6 * 64],
			 const int bound)
{

	int32_t j;
	int32_t iDcScaler, iQuant;
	int S = 0;
	int16_t predictors[6][8];

	MACROBLOCK *pMB = &frame->mbs[x + y * mb_width];
    iQuant = pMB->quant;

	if ((pMB->mode == MODE_INTRA) || (pMB->mode == MODE_INTRA_Q)) {

		for (j = 0; j < 6; j++) {
			iDcScaler = get_dc_scaler(iQuant, j<4);

			predict_acdc(frame->mbs, x, y, mb_width, j, &qcoeff[j * 64],
						 iQuant, iDcScaler, predictors[j], bound);

			if ((frame->vop_flags & XVID_VOP_HQACPRED))
				S += calc_acdc_bits(pMB, j, &qcoeff[j * 64], iDcScaler, predictors[j]);
			else
				S += calc_acdc_coeff(pMB, j, &qcoeff[j * 64], iDcScaler, predictors[j]);

		}

		if (S<=0) {				/* dont predict */
			for (j = 0; j < 6; j++)
				pMB->acpred_directions[j] = 0;
		}else{
			for (j = 0; j < 6; j++)
				apply_acdc(pMB, j, &qcoeff[j * 64], predictors[j]);
		}

		pMB->cbp = calc_cbp(qcoeff);
	}
}
Exemplo n.º 4
0
void
MBPrediction(FRAMEINFO * frame,
			 uint32_t x,
			 uint32_t y,
			 uint32_t mb_width,
			 int16_t qcoeff[6 * 64])
{

	int32_t j;
	int32_t iDcScaler, iQuant = frame->quant;
	int32_t S = 0;
	int16_t predictors[6][8];

	MACROBLOCK *pMB = &frame->mbs[x + y * mb_width];

	if ((pMB->mode == MODE_INTRA) || (pMB->mode == MODE_INTRA_Q)) {

		for (j = 0; j < 6; j++) {
			iDcScaler = get_dc_scaler(iQuant, (j < 4) ? 1 : 0);

			predict_acdc(frame->mbs, x, y, mb_width, j, &qcoeff[j * 64],
						 iQuant, iDcScaler, predictors[j], 0);

			S += calc_acdc(pMB, j, &qcoeff[j * 64], iDcScaler, predictors[j]);

		}

		if (S < 0)				/* dont predict */
		{
			for (j = 0; j < 6; j++) {
				pMB->acpred_directions[j] = 0;
			}
		} else {
			for (j = 0; j < 6; j++) {
				apply_acdc(pMB, j, &qcoeff[j * 64], predictors[j]);
			}
		}
		pMB->cbp = calc_cbp(qcoeff);
	}

}
Exemplo n.º 5
0
void
decoder_mbintra(DECODER * dec,
                MACROBLOCK * pMB,
                const uint32 x_pos,
                const uint32 y_pos,
                const uint32 acpred_flag,
                const uint32 cbp,
                Bitstream * bs,
                const uint32 quant, const uint32 intra_dc_threshold)
{
    uint32  stride = dec->edged_width;
    uint32  stride2 = stride / 2;
    uint32  next_block = stride * 8;
    uint32  i,j;
    uint32  iQuant = pMB->quant;
    uint8  *pY_Cur, *pU_Cur, *pV_Cur;

    pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);
    pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);
    pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);

    memset(block, 0, 6 * 64 * sizeof(int16));
	int16* tmpBlock = NULL;
    for (i = 0; i < 6; i++)
    {
        uint32  iDcScaler = get_dc_scaler(iQuant, (i < 4) ? 1 : 0);
        int16   predictors[8];
        int     start_coeff;

        start_timer();
        predict_acdc(dec->mbs, x_pos, y_pos, dec->mb_width, i,
                     &block[i * 64], iQuant, iDcScaler, predictors,
                     dec->slice);
        if (!acpred_flag)
        {
            pMB->acpred_directions[i] = 0;
        }
        stop_prediction_timer();

        if (quant < intra_dc_threshold)
        {
            int     dc_size;
            int     dc_dif;

            dc_size =
                i < 4 ? get_dc_size_lum(bs) : get_dc_size_chrom(bs);
            dc_dif = dc_size ? get_dc_dif(bs, dc_size) : 0;

            if (dc_size > 8)
            {
                BitstreamSkip(bs, 1);   // marker
            }

            block[i * 64] = dc_dif;
            start_coeff = 1;
        }
        else
        {
            start_coeff = 0;
        }

        start_timer();
        if (cbp & (1 << (5 - i)))       // coded
        {
            get_intra_block(bs, &block[i * 64],
                            pMB->acpred_directions[i], start_coeff);
        }
        stop_coding_timer();

        start_timer();
        add_acdc(pMB, i, &block[i * 64], iDcScaler, predictors);
        stop_prediction_timer();

        start_timer();
        dequant_intra(&data[i * 64], &block[i * 64], iQuant, iDcScaler);
        stop_iquant_timer();

        /*start_timer();
		idct(&data[i * 64]);
        stop_idct_timer();*/
		
		if(tmpBlock!=NULL)
		{
			start_timer();
			idct_dual(tmpBlock, &data[i * 64]);
			stop_idct_timer();
			tmpBlock = NULL;
		}
		else
		{
			tmpBlock = &data[i * 64];
		}
    }

    start_timer();
    transfer_16to8copy(pY_Cur, &data[0 * 64], stride);
    transfer_16to8copy(pY_Cur + 8, &data[1 * 64], stride);
    transfer_16to8copy(pY_Cur + next_block, &data[2 * 64], stride);
    transfer_16to8copy(pY_Cur + 8 + next_block, &data[3 * 64], stride);
    transfer_16to8copy(pU_Cur, &data[4 * 64], stride2);
    transfer_16to8copy(pV_Cur, &data[5 * 64], stride2);
    stop_transfer_timer();

#if 0
	printf("(%d,%d)\n",x_pos,y_pos);
	printf("pY_Cur = [\n");
	for (j = 0; j < 8; j++)
        for (i = 0; i < 8; i++)
			printf(((i+1)%8)? "%5d " : "%5d\n", pY_Cur[j * stride + i]);
	printf("\n");
	printf("pY_Cur + 8 = [\n");
	for (j = 0; j < 8; j++)
        for (i = 0; i < 8; i++)
			printf(((i+1)%8)? "%5d " : "%5d\n", (pY_Cur+8)[j * stride + i]);
	printf("\n");
	printf("pY_Cur+ next_block = [\n");
	for (j = 0; j < 8; j++)
        for (i = 0; i < 8; i++)
			printf(((i+1)%8)? "%5d " : "%5d\n", (pY_Cur+ next_block)[j * stride + i]);
	printf("\n");
	printf("pY_Cur+ next_block +8= [\n");
	for (j = 0; j < 8; j++)
        for (i = 0; i < 8; i++)
			printf(((i+1)%8)? "%5d " : "%5d\n", (pY_Cur+ next_block+8)[j * stride + i]);
	printf("\n");
#endif
}