static int dct_quantize_c(MpegEncContext *s, 

                        DCTELEM *block, int n,

                        int qscale)

{

    int i, j, level, last_non_zero, q;

    const int *qmat;

    int minLevel, maxLevel;



    if(s->avctx!=NULL && s->avctx->codec->id==CODEC_ID_MPEG4){

	/* mpeg4 */

        minLevel= -2048;

	maxLevel= 2047;

    }else if(s->out_format==FMT_MPEG1){

	/* mpeg1 */

        minLevel= -255;

	maxLevel= 255;

    }else if(s->out_format==FMT_MJPEG){

	/* (m)jpeg */

        minLevel= -1023;

	maxLevel= 1023;

    }else{

	/* h263 / msmpeg4 */

        minLevel= -128;

	maxLevel= 127;

    }



    av_fdct (block);



    /* we need this permutation so that we correct the IDCT

       permutation. will be moved into DCT code */

    block_permute(block);



    if (s->mb_intra) {

        if (n < 4)

            q = s->y_dc_scale;

        else

            q = s->c_dc_scale;

        q = q << 3;

        

        /* note: block[0] is assumed to be positive */

        block[0] = (block[0] + (q >> 1)) / q;

        i = 1;

        last_non_zero = 0;

        if (s->out_format == FMT_H263) {

            qmat = s->q_non_intra_matrix;

        } else {

            qmat = s->q_intra_matrix;

        }

    } else {

        i = 0;

        last_non_zero = -1;

        qmat = s->q_non_intra_matrix;

    }



    for(;i<64;i++) {

        j = zigzag_direct[i];

        level = block[j];

        level = level * qmat[j];

#ifdef PARANOID

        {

            static int count = 0;

            int level1, level2, qmat1;

            double val;

            if (qmat == s->q_non_intra_matrix) {

                qmat1 = default_non_intra_matrix[j] * s->qscale;

            } else {

                qmat1 = default_intra_matrix[j] * s->qscale;

            }

            if (av_fdct != jpeg_fdct_ifast)

                val = ((double)block[j] * 8.0) / (double)qmat1;

            else

                val = ((double)block[j] * 8.0 * 2048.0) / 

                    ((double)qmat1 * aanscales[j]);

            level1 = (int)val;

            level2 = level / (1 << (QMAT_SHIFT - 3));

            if (level1 != level2) {

                fprintf(stderr, "%d: quant error qlevel=%d wanted=%d level=%d qmat1=%d qmat=%d wantedf=%0.6f\n", 

                        count, level2, level1, block[j], qmat1, qmat[j],

                        val);

                count++;

            }



        }

#endif

        /* XXX: slight error for the low range. Test should be equivalent to

           (level <= -(1 << (QMAT_SHIFT - 3)) || level >= (1 <<

           (QMAT_SHIFT - 3)))

        */

        if (((level << (31 - (QMAT_SHIFT - 3))) >> (31 - (QMAT_SHIFT - 3))) != 

            level) {

            level = level / (1 << (QMAT_SHIFT - 3));

            /* XXX: currently, this code is not optimal. the range should be:

               mpeg1: -255..255

               mpeg2: -2048..2047

               h263:  -128..127

               mpeg4: -2048..2047

            */

            if (level > maxLevel)

                level = maxLevel;

            else if (level < minLevel)

                level = minLevel;



            block[j] = level;

            last_non_zero = i;

        } else {

            block[j] = 0;

        }

    }

    return last_non_zero;

}

static int dct_quantize_c(MpegEncContext *s, 

                        DCTELEM *block, int n,

                        int qscale)

{

    int i, j, level, last_non_zero, q;

    const int *qmat;

    int minLevel, maxLevel;



    if(s->avctx!=NULL && s->avctx->codec->id==CODEC_ID_MPEG4){

	

        minLevel= -2048;

	maxLevel= 2047;

    }else if(s->out_format==FMT_MPEG1){

	

        minLevel= -255;

	maxLevel= 255;

    }else if(s->out_format==FMT_MJPEG){

	

        minLevel= -1023;

	maxLevel= 1023;

    }else{

	

        minLevel= -128;

	maxLevel= 127;

    }



    av_fdct (block);



    



    block_permute(block);



    if (s->mb_intra) {

        if (n < 4)

            q = s->y_dc_scale;

        else

            q = s->c_dc_scale;

        q = q << 3;

        

        

        block[0] = (block[0] + (q >> 1)) / q;

        i = 1;

        last_non_zero = 0;

        if (s->out_format == FMT_H263) {

            qmat = s->q_non_intra_matrix;

        } else {

            qmat = s->q_intra_matrix;

        }

    } else {

        i = 0;

        last_non_zero = -1;

        qmat = s->q_non_intra_matrix;

    }



    for(;i<64;i++) {

        j = zigzag_direct[i];

        level = block[j];

        level = level * qmat[j];

#ifdef PARANOID

        {

            static int count = 0;

            int level1, level2, qmat1;

            double val;

            if (qmat == s->q_non_intra_matrix) {

                qmat1 = default_non_intra_matrix[j] * s->qscale;

            } else {

                qmat1 = default_intra_matrix[j] * s->qscale;

            }

            if (av_fdct != jpeg_fdct_ifast)

                val = ((double)block[j] * 8.0) / (double)qmat1;

            else

                val = ((double)block[j] * 8.0 * 2048.0) / 

                    ((double)qmat1 * aanscales[j]);

            level1 = (int)val;

            level2 = level / (1 << (QMAT_SHIFT - 3));

            if (level1 != level2) {

                fprintf(stderr, "%d: quant error qlevel=%d wanted=%d level=%d qmat1=%d qmat=%d wantedf=%0.6f\n", 

                        count, level2, level1, block[j], qmat1, qmat[j],

                        val);

                count++;

            }



        }

#endif

        







        if (((level << (31 - (QMAT_SHIFT - 3))) >> (31 - (QMAT_SHIFT - 3))) != 

            level) {

            level = level / (1 << (QMAT_SHIFT - 3));

            











            if (level > maxLevel)

                level = maxLevel;

            else if (level < minLevel)

                level = minLevel;



            block[j] = level;

            last_non_zero = i;

        } else {

            block[j] = 0;

        }

    }

    return last_non_zero;

}

    int minLevel, maxLevel;     if(s->avctx!=NULL && s->avctx->codec->id==CODEC_ID_MPEG4){         minLevel= -2048; 	maxLevel= 2047;     }else if(s->out_format==FMT_MPEG1){         minLevel= -255; 	maxLevel= 255;     }else if(s->out_format==FMT_MJPEG){         minLevel= -1023; 	maxLevel= 1023;     }else{         minLevel= -128; 	maxLevel= 127;         i = 1;         if (s->out_format == FMT_H263) {         } else {             if (level > maxLevel)                 level = maxLevel;             else if (level < minLevel)                 level = minLevel;         i = 0; #endif #endif #endif     } else {     } else {                         int qscale)     int minLevel, maxLevel;     if(s->avctx!=NULL && s->avctx->codec->id==CODEC_ID_MPEG4){         minLevel= -2048; 	maxLevel= 2047;     }else if(s->out_format==FMT_MPEG1){         minLevel= -255; 	maxLevel= 255;     }else if(s->out_format==FMT_MJPEG){         minLevel= -1023; 	maxLevel= 1023;     }else{         minLevel= -128; 	maxLevel= 127;         if (s->out_format == FMT_H263) {             qmat = s->q_non_intra_matrix;         } else {             qmat = s->q_intra_matrix;         qmat = s->q_non_intra_matrix; #ifdef PARANOID             static int count = 0;             int level1, level2, qmat1;             double val;             if (qmat == s->q_non_intra_matrix) {                 qmat1 = default_non_intra_matrix[j] * s->qscale;             } else {                 qmat1 = default_intra_matrix[j] * s->qscale;             if (av_fdct != jpeg_fdct_ifast)                 val = ((double)block[j] * 8.0) / (double)qmat1;                 val = ((double)block[j] * 8.0 * 2048.0) /                      ((double)qmat1 * aanscales[j]);             level1 = (int)val;             level2 = level / (1 << (QMAT_SHIFT - 3));             if (level1 != level2) {                 fprintf(stderr, "%d: quant error qlevel=%d wanted=%d level=%d qmat1=%d qmat=%d wantedf=%0.6f\n",                          count, level2, level1, block[j], qmat1, qmat[j],                         val);                 count++; #endif         if (((level << (31 - (QMAT_SHIFT - 3))) >> (31 - (QMAT_SHIFT - 3))) !=              level) {             level = level / (1 << (QMAT_SHIFT - 3));             if (level > maxLevel)                 level = maxLevel;             else if (level < minLevel)                 level = minLevel;             block[j] = level;         } else {             block[j] = 0;
static int FUNC_0(MpegEncContext *VAR_0, 

                        DCTELEM *VAR_1, int VAR_2,

                        int VAR_3)

{

    int VAR_4, VAR_5, VAR_6, VAR_7, VAR_8;

    const int *VAR_9;

    int VAR_10, VAR_11;



    if(VAR_0->avctx!=NULL && VAR_0->avctx->codec->id==CODEC_ID_MPEG4){

	

        VAR_10= -2048;

	VAR_11= 2047;

    }else if(VAR_0->out_format==FMT_MPEG1){

	

        VAR_10= -255;

	VAR_11= 255;

    }else if(VAR_0->out_format==FMT_MJPEG){

	

        VAR_10= -1023;

	VAR_11= 1023;

    }else{

	

        VAR_10= -128;

	VAR_11= 127;

    }



    av_fdct (VAR_1);



    



    block_permute(VAR_1);



    if (VAR_0->mb_intra) {

        if (VAR_2 < 4)

            VAR_8 = VAR_0->y_dc_scale;

        else

            VAR_8 = VAR_0->c_dc_scale;

        VAR_8 = VAR_8 << 3;

        

        

        VAR_1[0] = (VAR_1[0] + (VAR_8 >> 1)) / VAR_8;

        VAR_4 = 1;

        VAR_7 = 0;

        if (VAR_0->out_format == FMT_H263) {

            VAR_9 = VAR_0->q_non_intra_matrix;

        } else {

            VAR_9 = VAR_0->q_intra_matrix;

        }

    } else {

        VAR_4 = 0;

        VAR_7 = -1;

        VAR_9 = VAR_0->q_non_intra_matrix;

    }



    for(;VAR_4<64;VAR_4++) {

        VAR_5 = zigzag_direct[VAR_4];

        VAR_6 = VAR_1[VAR_5];

        VAR_6 = VAR_6 * VAR_9[VAR_5];

#ifdef PARANOID

        {

            static int count = 0;

            int level1, level2, qmat1;

            double val;

            if (VAR_9 == VAR_0->q_non_intra_matrix) {

                qmat1 = default_non_intra_matrix[VAR_5] * VAR_0->VAR_3;

            } else {

                qmat1 = default_intra_matrix[VAR_5] * VAR_0->VAR_3;

            }

            if (av_fdct != jpeg_fdct_ifast)

                val = ((double)VAR_1[VAR_5] * 8.0) / (double)qmat1;

            else

                val = ((double)VAR_1[VAR_5] * 8.0 * 2048.0) / 

                    ((double)qmat1 * aanscales[VAR_5]);

            level1 = (int)val;

            level2 = VAR_6 / (1 << (QMAT_SHIFT - 3));

            if (level1 != level2) {

                fprintf(stderr, "%d: quant error qlevel=%d wanted=%d VAR_6=%d qmat1=%d VAR_9=%d wantedf=%0.6f\VAR_2", 

                        count, level2, level1, VAR_1[VAR_5], qmat1, VAR_9[VAR_5],

                        val);

                count++;

            }



        }

#endif

        







        if (((VAR_6 << (31 - (QMAT_SHIFT - 3))) >> (31 - (QMAT_SHIFT - 3))) != 

            VAR_6) {

            VAR_6 = VAR_6 / (1 << (QMAT_SHIFT - 3));

            











            if (VAR_6 > VAR_11)

                VAR_6 = VAR_11;

            else if (VAR_6 < VAR_10)

                VAR_6 = VAR_10;



            VAR_1[VAR_5] = VAR_6;

            VAR_7 = VAR_4;

        } else {

            VAR_1[VAR_5] = 0;

        }

    }

    return VAR_7;

}

static int FUNC_0(MpegEncContext *VAR_0,
DCTELEM *VAR_1, int VAR_2,
int VAR_3)
{ int VAR_4, VAR_5, VAR_6, VAR_7, VAR_8; const int *VAR_9; int VAR_10, VAR_11; if(VAR_0->avctx!=NULL && VAR_0->avctx->codec->id==CODEC_ID_MPEG4){ VAR_10= -2048; VAR_11= 2047; }else if(VAR_0->out_format==FMT_MPEG1){ VAR_10= -255; VAR_11= 255; }else if(VAR_0->out_format==FMT_MJPEG){ VAR_10= -1023; VAR_11= 1023; }else{ VAR_10= -128; VAR_11= 127; } av_fdct (VAR_1); block_permute(VAR_1); if (VAR_0->mb_intra) { if (VAR_2 < 4)
VAR_8 = VAR_0->y_dc_scale; else
VAR_8 = VAR_0->c_dc_scale; VAR_8 = VAR_8 << 3; VAR_1[0] = (VAR_1[0] + (VAR_8 >> 1)) / VAR_8; VAR_4 = 1; VAR_7 = 0; if (VAR_0->out_format == FMT_H263) { VAR_9 = VAR_0->q_non_intra_matrix; } else { VAR_9 = VAR_0->q_intra_matrix; } } else { VAR_4 = 0; VAR_7 = -1; VAR_9 = VAR_0->q_non_intra_matrix; } for(;VAR_4<64;VAR_4++) { VAR_5 = zigzag_direct[VAR_4]; VAR_6 = VAR_1[VAR_5]; VAR_6 = VAR_6 * VAR_9[VAR_5]; #ifdef PARANOID
{ static int count = 0; int level1, level2, qmat1; double val; if (VAR_9 == VAR_0->q_non_intra_matrix) { qmat1 = default_non_intra_matrix[VAR_5] * VAR_0->VAR_3; } else { qmat1 = default_intra_matrix[VAR_5] * VAR_0->VAR_3; } if (av_fdct != jpeg_fdct_ifast)
val = ((double)VAR_1[VAR_5] * 8.0) / (double)qmat1; else
val = ((double)VAR_1[VAR_5] * 8.0 * 2048.0) /
((double)qmat1 * aanscales[VAR_5]); level1 = (int)val; level2 = VAR_6 / (1 << (QMAT_SHIFT - 3)); if (level1 != level2) { fprintf(stderr, "%d: quant error qlevel=%d wanted=%d VAR_6=%d qmat1=%d VAR_9=%d wantedf=%0.6f\VAR_2",
count, level2, level1, VAR_1[VAR_5], qmat1, VAR_9[VAR_5],
val); count++; } } #endif
if (((VAR_6 << (31 - (QMAT_SHIFT - 3))) >> (31 - (QMAT_SHIFT - 3))) !=
VAR_6) { VAR_6 = VAR_6 / (1 << (QMAT_SHIFT - 3)); if (VAR_6 > VAR_11)
VAR_6 = VAR_11; else if (VAR_6 < VAR_10)
VAR_6 = VAR_10; VAR_1[VAR_5] = VAR_6; VAR_7 = VAR_4; } else { VAR_1[VAR_5] = 0; } } return VAR_7; }