void mpeg1_encode_init(MpegEncContext *s)

{

    static int done=0;

    if(!done){

        int f_code;

        int mv;



        done=1;

        for(f_code=1; f_code<=MAX_FCODE; f_code++){

            for(mv=-MAX_MV; mv<=MAX_MV; mv++){

                int len;



                if(mv==0) len= mbMotionVectorTable[0][1];

                else{

                    int val, bit_size, range, code;



                    bit_size = s->f_code - 1;

                    range = 1 << bit_size;



                    val=mv;

                    if (val < 0) 

                        val = -val;

                    val--;

                    code = (val >> bit_size) + 1;

                    if(code<17){

                        len= mbMotionVectorTable[code][1] + 1 + bit_size;

                    }else{

                        len= mbMotionVectorTable[16][1] + 2 + bit_size;

                    }

                }



                mv_penalty[f_code][mv+MAX_MV]= len;

            }

        }

        



        for(f_code=MAX_FCODE; f_code>0; f_code--){

            for(mv=-(8<<f_code); mv<(8<<f_code); mv++){

                fcode_tab[mv+MAX_MV]= f_code;

            }

        }

    }

    s->mv_penalty= mv_penalty;

    

    s->fcode_tab= fcode_tab;

}

void mpeg1_encode_init(MpegEncContext *s)

{

    static int done=0;

    if(!done){

        int f_code;

        int mv;



        done=1;

        for(f_code=1; f_code<=MAX_FCODE; f_code++){

            for(mv=-MAX_MV; mv<=MAX_MV; mv++){

                int len;



                if(mv==0) len= mbMotionVectorTable[0][1];

                else{

                    int val, bit_size, range, code;



                    bit_size = s->f_code - 1;

                    range = 1 << bit_size;



                    val=mv;

                    if (val < 0) 

                        val = -val;

                    val--;

                    code = (val >> bit_size) + 1;

                    if(code<17){

                        len= mbMotionVectorTable[code][1] + 1 + bit_size;

                    }else{

                        len= mbMotionVectorTable[16][1] + 2 + bit_size;

                    }

                }



                mv_penalty[f_code][mv+MAX_MV]= len;

            }

        }

        



        for(f_code=MAX_FCODE; f_code>0; f_code--){

            for(mv=-(8<<f_code); mv<(8<<f_code); mv++){

                fcode_tab[mv+MAX_MV]= f_code;

            }

        }

    }

    s->mv_penalty= mv_penalty;

    

    s->fcode_tab= fcode_tab;

}

void FUNC_0(MpegEncContext *VAR_0)

{

    static int VAR_1=0;

    if(!VAR_1){

        int VAR_2;

        int VAR_3;



        VAR_1=1;

        for(VAR_2=1; VAR_2<=MAX_FCODE; VAR_2++){

            for(VAR_3=-MAX_MV; VAR_3<=MAX_MV; VAR_3++){

                int len;



                if(VAR_3==0) len= mbMotionVectorTable[0][1];

                else{

                    int val, bit_size, range, code;



                    bit_size = VAR_0->VAR_2 - 1;

                    range = 1 << bit_size;



                    val=VAR_3;

                    if (val < 0) 

                        val = -val;

                    val--;

                    code = (val >> bit_size) + 1;

                    if(code<17){

                        len= mbMotionVectorTable[code][1] + 1 + bit_size;

                    }else{

                        len= mbMotionVectorTable[16][1] + 2 + bit_size;

                    }

                }



                mv_penalty[VAR_2][VAR_3+MAX_MV]= len;

            }

        }

        



        for(VAR_2=MAX_FCODE; VAR_2>0; VAR_2--){

            for(VAR_3=-(8<<VAR_2); VAR_3<(8<<VAR_2); VAR_3++){

                fcode_tab[VAR_3+MAX_MV]= VAR_2;

            }

        }

    }

    VAR_0->mv_penalty= mv_penalty;

    

    VAR_0->fcode_tab= fcode_tab;

}

void FUNC_0(MpegEncContext *VAR_0)
{ static int VAR_1=0; if(!VAR_1){ int VAR_2; int VAR_3; VAR_1=1; for(VAR_2=1; VAR_2<=MAX_FCODE; VAR_2++){ for(VAR_3=-MAX_MV; VAR_3<=MAX_MV; VAR_3++){ int len; if(VAR_3==0) len= mbMotionVectorTable[0][1]; else{ int val, bit_size, range, code; bit_size = VAR_0->VAR_2 - 1; range = 1 << bit_size; val=VAR_3; if (val < 0)
val = -val; val--; code = (val >> bit_size) + 1; if(code<17){ len= mbMotionVectorTable[code][1] + 1 + bit_size; }else{ len= mbMotionVectorTable[16][1] + 2 + bit_size; } } mv_penalty[VAR_2][VAR_3+MAX_MV]= len; } } for(VAR_2=MAX_FCODE; VAR_2>0; VAR_2--){ for(VAR_3=-(8<<VAR_2); VAR_3<(8<<VAR_2); VAR_3++){ fcode_tab[VAR_3+MAX_MV]= VAR_2; } } } VAR_0->mv_penalty= mv_penalty; VAR_0->fcode_tab= fcode_tab; }