void CountBitsCoeff(int *qcoeff, int Mode, int CBP, Bits *bits, int ncoeffs) { int i; if (Mode == MODE_INTRA) { for (i = 0; i < 4; i++) { bits->Y += CodeCoeff(Mode, qcoeff,i,ncoeffs); } for (i = 4; i < 6; i++) { bits->C += CodeCoeff(Mode, qcoeff,i,ncoeffs); } } else { for (i = 0; i < 4; i++) { if ((i==0 && CBP&32) || (i==1 && CBP&16) || (i==2 && CBP&8) || (i==3 && CBP&4) || (i==4 && CBP&2) || (i==5 && CBP&1)) { bits->Y += CodeCoeff(Mode, qcoeff, i, ncoeffs); } } for (i = 4; i < 6; i++) { if ((i==0 && CBP&32) || (i==1 && CBP&16) || (i==2 && CBP&8) || (i==3 && CBP&4) || (i==4 && CBP&2) || (i==5 && CBP&1)) { bits->C += CodeCoeff(Mode, qcoeff, i, ncoeffs); } } } return; }
/***********************************************************CommentBegin****** * * -- MB_CodeCoeff -- Codes coefficients, does DC/AC prediction * * Purpose : * Codes coefficients, does DC/AC prediction * * Arguments in : * Int *qcoeff : quantized dct-coefficients * Int Mode : encoding mode * Int CBP : coded block pattern * Int ncoeffs : number of coefficients per block * Int x_pos : the horizontal position of the macroblock in the vop * Int intra_dcpred_disable : disable the intradc prediction * Int transp_pattern[]: Describes which blocks are transparent * * Arguments out : * Bits *bits : struct to count the number of texture bits * Image *bitstream : output bitstream * * Description : * The intradc prediction can be switched off by setting the variable * intradc_pred_disable to '1'. * ***********************************************************CommentEnd********/ Void MB_CodeCoeff(Bits* bits, Int *qcoeff, Int Mode, Int CBP, Int ncoeffs, Int intra_dcpred_disable, Image *DCbitstream, Image *bitstream, Int transp_pattern[], Int direction[], Int error_res_disable, Int reverse_vlc, Int switched, Int alternate_scan) { Int i, m, coeff[64]; Int *zz = alternate_scan ? zigzag_v : zigzag; if (Mode == MODE_INTRA || Mode == MODE_INTRA_Q) { if (intra_dcpred_disable == 0) { for (i = 0; i < 6; i++) { // if (i>3 || transp_pattern[i]!=1) /* Not transparent */ { if (!alternate_scan) { switch (direction[i]) { case 1: zz = zigzag_v; break; case 2: zz = zigzag_h; break; case 0: break; default: fprintf(stderr, "MB_CodeCoeff(): Error in zigzag direction\n"); exit(-1); } } /* Do the zigzag scanning of coefficients */ for (m = 0; m < 64; m++) { *(coeff + zz[m]) = qcoeff[i*ncoeffs+m]; } if (switched==0) { if (error_res_disable) { if (i < 4) bits->Y += IntraDC_dpcm(coeff[0],1,bitstream); else bits->C += IntraDC_dpcm(coeff[0],0,bitstream); } else { if (i < 4) bits->Y += IntraDC_dpcm(coeff[0],1,DCbitstream); else bits->C += IntraDC_dpcm(coeff[0],0,DCbitstream); } } /* Code AC coeffs. dep. on block pattern MW 15-NOV-1996 */ if ((i==0 && CBP&32) || (i==1 && CBP&16) || (i==2 && CBP&8) || (i==3 && CBP&4) || (i==4 && CBP&2) || (i==5 && CBP&1)) { if (error_res_disable || ((!error_res_disable) && (!reverse_vlc))) { if (i < 4) bits->Y += CodeCoeff(1-switched,Mode, coeff,i,ncoeffs,bitstream); else bits->C += CodeCoeff(1-switched,Mode, coeff,i,ncoeffs, bitstream); } else { if (i < 4) bits->Y += CodeCoeff_RVLC(1-switched,Mode, coeff, i, ncoeffs, bitstream); else bits->C += CodeCoeff_RVLC(1-switched,Mode, coeff, i, ncoeffs, bitstream); } } } } } else /* Without ACDC prediction */ { for (i = 0; i < 6; i++) { // if (i>3 || transp_pattern[i]!=1) /* Not transparent */ { /* Do the zigzag scanning of coefficients */ for (m = 0; m < 64; m++) *(coeff + zz[m]) = qcoeff[i*ncoeffs+m]; if (switched==0) { if (error_res_disable) { if (coeff[0] != 128) BitstreamPutBits(bitstream,(long)(coeff[0]),8L); else BitstreamPutBits(bitstream, 255L, 8L); } else { if (coeff[0] != 128) BitstreamPutBits(DCbitstream,(long)(coeff[0]),8L); else BitstreamPutBits(DCbitstream,255L, 8L); } if (i < 4) bits->Y += 8; else bits->C += 8; } if ((i==0 && CBP&32) || (i==1 && CBP&16) || (i==2 && CBP&8) || (i==3 && CBP&4) || (i==4 && CBP&2) || (i==5 && CBP&1)) { /* send coeff, not qcoeff !!! MW 07-11-96 */ if (error_res_disable || ((!error_res_disable) && (!reverse_vlc))) { if (i < 4) bits->Y += CodeCoeff(1-switched,Mode, coeff,i,ncoeffs, bitstream); else bits->C += CodeCoeff(1-switched,Mode, coeff,i,ncoeffs, bitstream); } else { if (i < 4) bits->Y += CodeCoeff_RVLC(1-switched,Mode, coeff, i, ncoeffs, bitstream); else bits->C += CodeCoeff_RVLC(1-switched,Mode, coeff, i, ncoeffs, bitstream); } } } } } } else /* inter block encoding */ { for (i = 0; i < 6; i++) { /* Do the zigzag scanning of coefficients */ for (m = 0; m < 64; m++) *(coeff + zz[m]) = qcoeff[i*ncoeffs+m]; if ((i==0 && CBP&32) || (i==1 && CBP&16) || (i==2 && CBP&8) || (i==3 && CBP&4) || (i==4 && CBP&2) || (i==5 && CBP&1)) { if (error_res_disable || ((!error_res_disable) && (!reverse_vlc))) { if (i < 4) bits->Y += CodeCoeff(0,Mode, coeff, i, ncoeffs, bitstream); else bits->C += CodeCoeff(0,Mode, coeff, i, ncoeffs, bitstream); } else { if (i < 4) bits->Y += CodeCoeff_RVLC(0,Mode, coeff, i, ncoeffs, bitstream); else bits->C += CodeCoeff_RVLC(0,Mode, coeff, i, ncoeffs, bitstream); } } } } }