static void encode_mb(MpegEncContext *s, int motion_x, int motion_y)

{

    const int mb_x= s->mb_x;

    const int mb_y= s->mb_y;

    int i;

#if 0

        if (s->interlaced_dct) {

            dct_linesize = s->linesize * 2;

            dct_offset = s->linesize;

        } else {

            dct_linesize = s->linesize;

            dct_offset = s->linesize * 8;

        }

#endif



    if (s->mb_intra) {

        UINT8 *ptr;

        int wrap;



        wrap = s->linesize;

        ptr = s->new_picture[0] + (mb_y * 16 * wrap) + mb_x * 16;

        get_pixels(s->block[0], ptr               , wrap);

        get_pixels(s->block[1], ptr            + 8, wrap);

        get_pixels(s->block[2], ptr + 8 * wrap    , wrap);

        get_pixels(s->block[3], ptr + 8 * wrap + 8, wrap);



        wrap >>=1;

        ptr = s->new_picture[1] + (mb_y * 8 * wrap) + mb_x * 8;

        get_pixels(s->block[4], ptr, wrap);



        ptr = s->new_picture[2] + (mb_y * 8 * wrap) + mb_x * 8;

        get_pixels(s->block[5], ptr, wrap);

    }else{

        op_pixels_func *op_pix;

        qpel_mc_func *op_qpix;

        UINT8 *dest_y, *dest_cb, *dest_cr;

        UINT8 *ptr;

        int wrap;



        dest_y  = s->current_picture[0] + (mb_y * 16 * s->linesize       ) + mb_x * 16;

        dest_cb = s->current_picture[1] + (mb_y * 8  * (s->linesize >> 1)) + mb_x * 8;

        dest_cr = s->current_picture[2] + (mb_y * 8  * (s->linesize >> 1)) + mb_x * 8;



        if ((!s->no_rounding) || s->pict_type==B_TYPE){

            op_pix = put_pixels_tab;

            op_qpix= qpel_mc_rnd_tab;

        }else{

            op_pix = put_no_rnd_pixels_tab;

            op_qpix= qpel_mc_no_rnd_tab;

        }



        if (s->mv_dir & MV_DIR_FORWARD) {

            MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture, op_pix, op_qpix);

           if ((!s->no_rounding) || s->pict_type==B_TYPE)

                op_pix = avg_pixels_tab;

            else

                op_pix = avg_no_rnd_pixels_tab;

        }

        if (s->mv_dir & MV_DIR_BACKWARD) {

            MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture, op_pix, op_qpix);

        }

        wrap = s->linesize;

        ptr = s->new_picture[0] + (mb_y * 16 * wrap) + mb_x * 16;

        diff_pixels(s->block[0], ptr               , dest_y               , wrap);

        diff_pixels(s->block[1], ptr            + 8, dest_y            + 8, wrap);

        diff_pixels(s->block[2], ptr + 8 * wrap    , dest_y + 8 * wrap    , wrap);

        diff_pixels(s->block[3], ptr + 8 * wrap + 8, dest_y + 8 * wrap + 8, wrap);



        wrap >>=1;

        ptr = s->new_picture[1] + (mb_y * 8 * wrap) + mb_x * 8;

        diff_pixels(s->block[4], ptr, dest_cb, wrap);



        ptr = s->new_picture[2] + (mb_y * 8 * wrap) + mb_x * 8;

        diff_pixels(s->block[5], ptr, dest_cr, wrap);

    }

            

#if 0

            {

                float adap_parm;

                

                adap_parm = ((s->avg_mb_var << 1) + s->mb_var[s->mb_width*mb_y+mb_x] + 1.0) /

                            ((s->mb_var[s->mb_width*mb_y+mb_x] << 1) + s->avg_mb_var + 1.0);

            

                printf("\ntype=%c qscale=%2d adap=%0.2f dquant=%4.2f var=%4d avgvar=%4d", 

                        (s->mb_type[s->mb_width*mb_y+mb_x] > 0) ? 'I' : 'P', 

                        s->qscale, adap_parm, s->qscale*adap_parm,

                        s->mb_var[s->mb_width*mb_y+mb_x], s->avg_mb_var);

            }

#endif

    /* DCT & quantize */

    if (s->h263_msmpeg4) {

        msmpeg4_dc_scale(s);

    } else if (s->h263_pred) {

        h263_dc_scale(s);

    } else {

        /* default quantization values */

        s->y_dc_scale = 8;

        s->c_dc_scale = 8;

    }

    for(i=0;i<6;i++) {

        s->block_last_index[i] = dct_quantize(s, s->block[i], i, s->qscale);

    }



    /* huffman encode */

    switch(s->out_format) {

    case FMT_MPEG1:

        mpeg1_encode_mb(s, s->block, motion_x, motion_y);

        break;

    case FMT_H263:

        if (s->h263_msmpeg4)

            msmpeg4_encode_mb(s, s->block, motion_x, motion_y);

        else if(s->h263_pred)

            mpeg4_encode_mb(s, s->block, motion_x, motion_y);

        else

            h263_encode_mb(s, s->block, motion_x, motion_y);

        break;

    case FMT_MJPEG:

        mjpeg_encode_mb(s, s->block);

        break;

    }

}

static void encode_mb(MpegEncContext *s, int motion_x, int motion_y)

{

    const int mb_x= s->mb_x;

    const int mb_y= s->mb_y;

    int i;

#if 0

        if (s->interlaced_dct) {

            dct_linesize = s->linesize * 2;

            dct_offset = s->linesize;

        } else {

            dct_linesize = s->linesize;

            dct_offset = s->linesize * 8;

        }

#endif



    if (s->mb_intra) {

        UINT8 *ptr;

        int wrap;



        wrap = s->linesize;

        ptr = s->new_picture[0] + (mb_y * 16 * wrap) + mb_x * 16;

        get_pixels(s->block[0], ptr               , wrap);

        get_pixels(s->block[1], ptr            + 8, wrap);

        get_pixels(s->block[2], ptr + 8 * wrap    , wrap);

        get_pixels(s->block[3], ptr + 8 * wrap + 8, wrap);



        wrap >>=1;

        ptr = s->new_picture[1] + (mb_y * 8 * wrap) + mb_x * 8;

        get_pixels(s->block[4], ptr, wrap);



        ptr = s->new_picture[2] + (mb_y * 8 * wrap) + mb_x * 8;

        get_pixels(s->block[5], ptr, wrap);

    }else{

        op_pixels_func *op_pix;

        qpel_mc_func *op_qpix;

        UINT8 *dest_y, *dest_cb, *dest_cr;

        UINT8 *ptr;

        int wrap;



        dest_y  = s->current_picture[0] + (mb_y * 16 * s->linesize       ) + mb_x * 16;

        dest_cb = s->current_picture[1] + (mb_y * 8  * (s->linesize >> 1)) + mb_x * 8;

        dest_cr = s->current_picture[2] + (mb_y * 8  * (s->linesize >> 1)) + mb_x * 8;



        if ((!s->no_rounding) || s->pict_type==B_TYPE){

            op_pix = put_pixels_tab;

            op_qpix= qpel_mc_rnd_tab;

        }else{

            op_pix = put_no_rnd_pixels_tab;

            op_qpix= qpel_mc_no_rnd_tab;

        }



        if (s->mv_dir & MV_DIR_FORWARD) {

            MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture, op_pix, op_qpix);

           if ((!s->no_rounding) || s->pict_type==B_TYPE)

                op_pix = avg_pixels_tab;

            else

                op_pix = avg_no_rnd_pixels_tab;

        }

        if (s->mv_dir & MV_DIR_BACKWARD) {

            MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture, op_pix, op_qpix);

        }

        wrap = s->linesize;

        ptr = s->new_picture[0] + (mb_y * 16 * wrap) + mb_x * 16;

        diff_pixels(s->block[0], ptr               , dest_y               , wrap);

        diff_pixels(s->block[1], ptr            + 8, dest_y            + 8, wrap);

        diff_pixels(s->block[2], ptr + 8 * wrap    , dest_y + 8 * wrap    , wrap);

        diff_pixels(s->block[3], ptr + 8 * wrap + 8, dest_y + 8 * wrap + 8, wrap);



        wrap >>=1;

        ptr = s->new_picture[1] + (mb_y * 8 * wrap) + mb_x * 8;

        diff_pixels(s->block[4], ptr, dest_cb, wrap);



        ptr = s->new_picture[2] + (mb_y * 8 * wrap) + mb_x * 8;

        diff_pixels(s->block[5], ptr, dest_cr, wrap);

    }

            

#if 0

            {

                float adap_parm;

                

                adap_parm = ((s->avg_mb_var << 1) + s->mb_var[s->mb_width*mb_y+mb_x] + 1.0) /

                            ((s->mb_var[s->mb_width*mb_y+mb_x] << 1) + s->avg_mb_var + 1.0);

            

                printf("\ntype=%c qscale=%2d adap=%0.2f dquant=%4.2f var=%4d avgvar=%4d", 

                        (s->mb_type[s->mb_width*mb_y+mb_x] > 0) ? 'I' : 'P', 

                        s->qscale, adap_parm, s->qscale*adap_parm,

                        s->mb_var[s->mb_width*mb_y+mb_x], s->avg_mb_var);

            }

#endif

    

    if (s->h263_msmpeg4) {

        msmpeg4_dc_scale(s);

    } else if (s->h263_pred) {

        h263_dc_scale(s);

    } else {

        

        s->y_dc_scale = 8;

        s->c_dc_scale = 8;

    }

    for(i=0;i<6;i++) {

        s->block_last_index[i] = dct_quantize(s, s->block[i], i, s->qscale);

    }



    

    switch(s->out_format) {

    case FMT_MPEG1:

        mpeg1_encode_mb(s, s->block, motion_x, motion_y);

        break;

    case FMT_H263:

        if (s->h263_msmpeg4)

            msmpeg4_encode_mb(s, s->block, motion_x, motion_y);

        else if(s->h263_pred)

            mpeg4_encode_mb(s, s->block, motion_x, motion_y);

        else

            h263_encode_mb(s, s->block, motion_x, motion_y);

        break;

    case FMT_MJPEG:

        mjpeg_encode_mb(s, s->block);

        break;

    }

}

    }else{         } else { #endif #endif #endif     int i;     } else {     for(i=0;i<6;i++) {         s->block_last_index[i] = dct_quantize(s, s->block[i], i, s->qscale);     } else {     }else{         } else { #endif         } else {
static void FUNC_0(MpegEncContext *VAR_0, int VAR_1, int VAR_2)

{

    const int VAR_3= VAR_0->VAR_3;

    const int VAR_4= VAR_0->VAR_4;

    int VAR_5;

#if 0

        if (VAR_0->interlaced_dct) {

            dct_linesize = VAR_0->linesize * 2;

            dct_offset = VAR_0->linesize;

        } else {

            dct_linesize = VAR_0->linesize;

            dct_offset = VAR_0->linesize * 8;

        }

#endif



    if (VAR_0->mb_intra) {

        UINT8 *ptr;

        int VAR_7;



        VAR_7 = VAR_0->linesize;

        ptr = VAR_0->new_picture[0] + (VAR_4 * 16 * VAR_7) + VAR_3 * 16;

        get_pixels(VAR_0->block[0], ptr               , VAR_7);

        get_pixels(VAR_0->block[1], ptr            + 8, VAR_7);

        get_pixels(VAR_0->block[2], ptr + 8 * VAR_7    , VAR_7);

        get_pixels(VAR_0->block[3], ptr + 8 * VAR_7 + 8, VAR_7);



        VAR_7 >>=1;

        ptr = VAR_0->new_picture[1] + (VAR_4 * 8 * VAR_7) + VAR_3 * 8;

        get_pixels(VAR_0->block[4], ptr, VAR_7);



        ptr = VAR_0->new_picture[2] + (VAR_4 * 8 * VAR_7) + VAR_3 * 8;

        get_pixels(VAR_0->block[5], ptr, VAR_7);

    }else{

        op_pixels_func *op_pix;

        qpel_mc_func *op_qpix;

        UINT8 *dest_y, *dest_cb, *dest_cr;

        UINT8 *ptr;

        int VAR_7;



        dest_y  = VAR_0->current_picture[0] + (VAR_4 * 16 * VAR_0->linesize       ) + VAR_3 * 16;

        dest_cb = VAR_0->current_picture[1] + (VAR_4 * 8  * (VAR_0->linesize >> 1)) + VAR_3 * 8;

        dest_cr = VAR_0->current_picture[2] + (VAR_4 * 8  * (VAR_0->linesize >> 1)) + VAR_3 * 8;



        if ((!VAR_0->no_rounding) || VAR_0->pict_type==B_TYPE){

            op_pix = put_pixels_tab;

            op_qpix= qpel_mc_rnd_tab;

        }else{

            op_pix = put_no_rnd_pixels_tab;

            op_qpix= qpel_mc_no_rnd_tab;

        }



        if (VAR_0->mv_dir & MV_DIR_FORWARD) {

            MPV_motion(VAR_0, dest_y, dest_cb, dest_cr, 0, VAR_0->last_picture, op_pix, op_qpix);

           if ((!VAR_0->no_rounding) || VAR_0->pict_type==B_TYPE)

                op_pix = avg_pixels_tab;

            else

                op_pix = avg_no_rnd_pixels_tab;

        }

        if (VAR_0->mv_dir & MV_DIR_BACKWARD) {

            MPV_motion(VAR_0, dest_y, dest_cb, dest_cr, 1, VAR_0->next_picture, op_pix, op_qpix);

        }

        VAR_7 = VAR_0->linesize;

        ptr = VAR_0->new_picture[0] + (VAR_4 * 16 * VAR_7) + VAR_3 * 16;

        diff_pixels(VAR_0->block[0], ptr               , dest_y               , VAR_7);

        diff_pixels(VAR_0->block[1], ptr            + 8, dest_y            + 8, VAR_7);

        diff_pixels(VAR_0->block[2], ptr + 8 * VAR_7    , dest_y + 8 * VAR_7    , VAR_7);

        diff_pixels(VAR_0->block[3], ptr + 8 * VAR_7 + 8, dest_y + 8 * VAR_7 + 8, VAR_7);



        VAR_7 >>=1;

        ptr = VAR_0->new_picture[1] + (VAR_4 * 8 * VAR_7) + VAR_3 * 8;

        diff_pixels(VAR_0->block[4], ptr, dest_cb, VAR_7);



        ptr = VAR_0->new_picture[2] + (VAR_4 * 8 * VAR_7) + VAR_3 * 8;

        diff_pixels(VAR_0->block[5], ptr, dest_cr, VAR_7);

    }

            

#if 0

            {

                float adap_parm;

                

                adap_parm = ((VAR_0->avg_mb_var << 1) + VAR_0->mb_var[VAR_0->mb_width*VAR_4+VAR_3] + 1.0) /

                            ((VAR_0->mb_var[VAR_0->mb_width*VAR_4+VAR_3] << 1) + VAR_0->avg_mb_var + 1.0);

            

                printf("\ntype=%c qscale=%2d adap=%0.2f dquant=%4.2f var=%4d avgvar=%4d", 

                        (VAR_0->mb_type[VAR_0->mb_width*VAR_4+VAR_3] > 0) ? 'I' : 'P', 

                        VAR_0->qscale, adap_parm, VAR_0->qscale*adap_parm,

                        VAR_0->mb_var[VAR_0->mb_width*VAR_4+VAR_3], VAR_0->avg_mb_var);

            }

#endif

    

    if (VAR_0->h263_msmpeg4) {

        msmpeg4_dc_scale(VAR_0);

    } else if (VAR_0->h263_pred) {

        h263_dc_scale(VAR_0);

    } else {

        

        VAR_0->y_dc_scale = 8;

        VAR_0->c_dc_scale = 8;

    }

    for(VAR_5=0;VAR_5<6;VAR_5++) {

        VAR_0->block_last_index[VAR_5] = dct_quantize(VAR_0, VAR_0->block[VAR_5], VAR_5, VAR_0->qscale);

    }



    

    switch(VAR_0->out_format) {

    case FMT_MPEG1:

        mpeg1_encode_mb(VAR_0, VAR_0->block, VAR_1, VAR_2);

        break;

    case FMT_H263:

        if (VAR_0->h263_msmpeg4)

            msmpeg4_encode_mb(VAR_0, VAR_0->block, VAR_1, VAR_2);

        else if(VAR_0->h263_pred)

            mpeg4_encode_mb(VAR_0, VAR_0->block, VAR_1, VAR_2);

        else

            h263_encode_mb(VAR_0, VAR_0->block, VAR_1, VAR_2);

        break;

    case FMT_MJPEG:

        mjpeg_encode_mb(VAR_0, VAR_0->block);

        break;

    }

}

static void FUNC_0(MpegEncContext *VAR_0, int VAR_1, int VAR_2)
{ const int VAR_3= VAR_0->VAR_3; const int VAR_4= VAR_0->VAR_4; int VAR_5; #if 0
if (VAR_0->interlaced_dct) { dct_linesize = VAR_0->linesize * 2; dct_offset = VAR_0->linesize; } else { dct_linesize = VAR_0->linesize; dct_offset = VAR_0->linesize * 8; } #endif
if (VAR_0->mb_intra) { UINT8 *ptr; int VAR_7; VAR_7 = VAR_0->linesize; ptr = VAR_0->new_picture[0] + (VAR_4 * 16 * VAR_7) + VAR_3 * 16; get_pixels(VAR_0->block[0], ptr               , VAR_7); get_pixels(VAR_0->block[1], ptr            + 8, VAR_7); get_pixels(VAR_0->block[2], ptr + 8 * VAR_7    , VAR_7); get_pixels(VAR_0->block[3], ptr + 8 * VAR_7 + 8, VAR_7); VAR_7 >>=1; ptr = VAR_0->new_picture[1] + (VAR_4 * 8 * VAR_7) + VAR_3 * 8; get_pixels(VAR_0->block[4], ptr, VAR_7); ptr = VAR_0->new_picture[2] + (VAR_4 * 8 * VAR_7) + VAR_3 * 8; get_pixels(VAR_0->block[5], ptr, VAR_7); }else{ op_pixels_func *op_pix; qpel_mc_func *op_qpix; UINT8 *dest_y, *dest_cb, *dest_cr; UINT8 *ptr; int VAR_7; dest_y  = VAR_0->current_picture[0] + (VAR_4 * 16 * VAR_0->linesize       ) + VAR_3 * 16; dest_cb = VAR_0->current_picture[1] + (VAR_4 * 8  * (VAR_0->linesize >> 1)) + VAR_3 * 8; dest_cr = VAR_0->current_picture[2] + (VAR_4 * 8  * (VAR_0->linesize >> 1)) + VAR_3 * 8; if ((!VAR_0->no_rounding) || VAR_0->pict_type==B_TYPE){ op_pix = put_pixels_tab; op_qpix= qpel_mc_rnd_tab; }else{ op_pix = put_no_rnd_pixels_tab; op_qpix= qpel_mc_no_rnd_tab; } if (VAR_0->mv_dir & MV_DIR_FORWARD) { MPV_motion(VAR_0, dest_y, dest_cb, dest_cr, 0, VAR_0->last_picture, op_pix, op_qpix); if ((!VAR_0->no_rounding) || VAR_0->pict_type==B_TYPE)
op_pix = avg_pixels_tab; else
op_pix = avg_no_rnd_pixels_tab; } if (VAR_0->mv_dir & MV_DIR_BACKWARD) { MPV_motion(VAR_0, dest_y, dest_cb, dest_cr, 1, VAR_0->next_picture, op_pix, op_qpix); } VAR_7 = VAR_0->linesize; ptr = VAR_0->new_picture[0] + (VAR_4 * 16 * VAR_7) + VAR_3 * 16; diff_pixels(VAR_0->block[0], ptr               , dest_y               , VAR_7); diff_pixels(VAR_0->block[1], ptr            + 8, dest_y            + 8, VAR_7); diff_pixels(VAR_0->block[2], ptr + 8 * VAR_7    , dest_y + 8 * VAR_7    , VAR_7); diff_pixels(VAR_0->block[3], ptr + 8 * VAR_7 + 8, dest_y + 8 * VAR_7 + 8, VAR_7); VAR_7 >>=1; ptr = VAR_0->new_picture[1] + (VAR_4 * 8 * VAR_7) + VAR_3 * 8; diff_pixels(VAR_0->block[4], ptr, dest_cb, VAR_7); ptr = VAR_0->new_picture[2] + (VAR_4 * 8 * VAR_7) + VAR_3 * 8; diff_pixels(VAR_0->block[5], ptr, dest_cr, VAR_7); } #if 0
{ float adap_parm; adap_parm = ((VAR_0->avg_mb_var << 1) + VAR_0->mb_var[VAR_0->mb_width*VAR_4+VAR_3] + 1.0) /
((VAR_0->mb_var[VAR_0->mb_width*VAR_4+VAR_3] << 1) + VAR_0->avg_mb_var + 1.0); printf("\ntype=%c qscale=%2d adap=%0.2f dquant=%4.2f var=%4d avgvar=%4d",
(VAR_0->mb_type[VAR_0->mb_width*VAR_4+VAR_3] > 0) ? 'I' : 'P',
VAR_0->qscale, adap_parm, VAR_0->qscale*adap_parm,
VAR_0->mb_var[VAR_0->mb_width*VAR_4+VAR_3], VAR_0->avg_mb_var); } #endif
if (VAR_0->h263_msmpeg4) { msmpeg4_dc_scale(VAR_0); } else if (VAR_0->h263_pred) { h263_dc_scale(VAR_0); } else { VAR_0->y_dc_scale = 8; VAR_0->c_dc_scale = 8; } for(VAR_5=0;VAR_5<6;VAR_5++) { VAR_0->block_last_index[VAR_5] = dct_quantize(VAR_0, VAR_0->block[VAR_5], VAR_5, VAR_0->qscale); } switch(VAR_0->out_format) { case FMT_MPEG1:
mpeg1_encode_mb(VAR_0, VAR_0->block, VAR_1, VAR_2); break; case FMT_H263:
if (VAR_0->h263_msmpeg4)
msmpeg4_encode_mb(VAR_0, VAR_0->block, VAR_1, VAR_2); else if(VAR_0->h263_pred)
mpeg4_encode_mb(VAR_0, VAR_0->block, VAR_1, VAR_2); else
h263_encode_mb(VAR_0, VAR_0->block, VAR_1, VAR_2); break; case FMT_MJPEG:
mjpeg_encode_mb(VAR_0, VAR_0->block); break; } }