static int unpack_modes(Vp3DecodeContext *s, GetBitContext *gb)

{

    int i, j, k, sb_x, sb_y;

    int scheme;

    int current_macroblock;

    int current_fragment;

    int coding_mode;

    int custom_mode_alphabet[CODING_MODE_COUNT];



    if (s->keyframe) {

        for (i = 0; i < s->fragment_count; i++)

            s->all_fragments[i].coding_method = MODE_INTRA;



    } else {



        /* fetch the mode coding scheme for this frame */

        scheme = get_bits(gb, 3);



        /* is it a custom coding scheme? */

        if (scheme == 0) {

            for (i = 0; i < 8; i++)

                custom_mode_alphabet[i] = MODE_INTER_NO_MV;

            for (i = 0; i < 8; i++)

                custom_mode_alphabet[get_bits(gb, 3)] = i;

        }



        /* iterate through all of the macroblocks that contain 1 or more

         * coded fragments */

        for (sb_y = 0; sb_y < s->y_superblock_height; sb_y++) {

            for (sb_x = 0; sb_x < s->y_superblock_width; sb_x++) {



            for (j = 0; j < 4; j++) {

                int mb_x = 2*sb_x +   (j>>1);

                int mb_y = 2*sb_y + (((j>>1)+j)&1);

                int frags_coded = 0;

                current_macroblock = mb_y * s->macroblock_width + mb_x;



                if (mb_x >= s->macroblock_width || mb_y >= s->macroblock_height)

                    continue;



#define BLOCK_X (2*mb_x + (k&1))

#define BLOCK_Y (2*mb_y + (k>>1))

                /* coding modes are only stored if the macroblock has at least one

                 * luma block coded, otherwise it must be INTER_NO_MV */

                for (k = 0; k < 4; k++) {

                    current_fragment = BLOCK_Y*s->fragment_width + BLOCK_X;

                    if (s->all_fragments[current_fragment].coding_method != MODE_COPY)

                        break;

                }

                if (k == 4) {

                    s->macroblock_coding[current_macroblock] = MODE_INTER_NO_MV;

                    continue;

                }



                /* mode 7 means get 3 bits for each coding mode */

                if (scheme == 7)

                    coding_mode = get_bits(gb, 3);

                else if(scheme == 0)

                    coding_mode = custom_mode_alphabet

                        [get_vlc2(gb, s->mode_code_vlc.table, 3, 3)];

                else

                    coding_mode = ModeAlphabet[scheme-1]

                        [get_vlc2(gb, s->mode_code_vlc.table, 3, 3)];



                s->macroblock_coding[current_macroblock] = coding_mode;

                for (k = 0; k < 4; k++) {

                    current_fragment =

                        BLOCK_Y*s->fragment_width + BLOCK_X;

                    if (s->all_fragments[current_fragment].coding_method !=

                        MODE_COPY)

                        s->all_fragments[current_fragment].coding_method =

                            coding_mode;

                }

                for (k = 0; k < 2; k++) {

                    current_fragment = s->fragment_start[k+1] +

                        mb_y*(s->fragment_width>>1) + mb_x;

                    if (s->all_fragments[current_fragment].coding_method !=

                        MODE_COPY)

                        s->all_fragments[current_fragment].coding_method =

                            coding_mode;

                }

            }

            }

        }

    }



    return 0;

}

static int unpack_modes(Vp3DecodeContext *s, GetBitContext *gb)

{

    int i, j, k, sb_x, sb_y;

    int scheme;

    int current_macroblock;

    int current_fragment;

    int coding_mode;

    int custom_mode_alphabet[CODING_MODE_COUNT];



    if (s->keyframe) {

        for (i = 0; i < s->fragment_count; i++)

            s->all_fragments[i].coding_method = MODE_INTRA;



    } else {



        

        scheme = get_bits(gb, 3);



        

        if (scheme == 0) {

            for (i = 0; i < 8; i++)

                custom_mode_alphabet[i] = MODE_INTER_NO_MV;

            for (i = 0; i < 8; i++)

                custom_mode_alphabet[get_bits(gb, 3)] = i;

        }



        



        for (sb_y = 0; sb_y < s->y_superblock_height; sb_y++) {

            for (sb_x = 0; sb_x < s->y_superblock_width; sb_x++) {



            for (j = 0; j < 4; j++) {

                int mb_x = 2*sb_x +   (j>>1);

                int mb_y = 2*sb_y + (((j>>1)+j)&1);

                int frags_coded = 0;

                current_macroblock = mb_y * s->macroblock_width + mb_x;



                if (mb_x >= s->macroblock_width || mb_y >= s->macroblock_height)

                    continue;



#define BLOCK_X (2*mb_x + (k&1))

#define BLOCK_Y (2*mb_y + (k>>1))

                



                for (k = 0; k < 4; k++) {

                    current_fragment = BLOCK_Y*s->fragment_width + BLOCK_X;

                    if (s->all_fragments[current_fragment].coding_method != MODE_COPY)

                        break;

                }

                if (k == 4) {

                    s->macroblock_coding[current_macroblock] = MODE_INTER_NO_MV;

                    continue;

                }



                

                if (scheme == 7)

                    coding_mode = get_bits(gb, 3);

                else if(scheme == 0)

                    coding_mode = custom_mode_alphabet

                        [get_vlc2(gb, s->mode_code_vlc.table, 3, 3)];

                else

                    coding_mode = ModeAlphabet[scheme-1]

                        [get_vlc2(gb, s->mode_code_vlc.table, 3, 3)];



                s->macroblock_coding[current_macroblock] = coding_mode;

                for (k = 0; k < 4; k++) {

                    current_fragment =

                        BLOCK_Y*s->fragment_width + BLOCK_X;

                    if (s->all_fragments[current_fragment].coding_method !=

                        MODE_COPY)

                        s->all_fragments[current_fragment].coding_method =

                            coding_mode;

                }

                for (k = 0; k < 2; k++) {

                    current_fragment = s->fragment_start[k+1] +

                        mb_y*(s->fragment_width>>1) + mb_x;

                    if (s->all_fragments[current_fragment].coding_method !=

                        MODE_COPY)

                        s->all_fragments[current_fragment].coding_method =

                            coding_mode;

                }

            }

            }

        }

    }



    return 0;

}

static int FUNC_0(Vp3DecodeContext *VAR_0, GetBitContext *VAR_1)

{

    int VAR_2, VAR_3, VAR_4, VAR_5, VAR_6;

    int VAR_7;

    int VAR_8;

    int VAR_9;

    int VAR_10;

    int VAR_11[CODING_MODE_COUNT];



    if (VAR_0->keyframe) {

        for (VAR_2 = 0; VAR_2 < VAR_0->fragment_count; VAR_2++)

            VAR_0->all_fragments[VAR_2].coding_method = MODE_INTRA;



    } else {



        

        VAR_7 = get_bits(VAR_1, 3);



        

        if (VAR_7 == 0) {

            for (VAR_2 = 0; VAR_2 < 8; VAR_2++)

                VAR_11[VAR_2] = MODE_INTER_NO_MV;

            for (VAR_2 = 0; VAR_2 < 8; VAR_2++)

                VAR_11[get_bits(VAR_1, 3)] = VAR_2;

        }



        



        for (VAR_6 = 0; VAR_6 < VAR_0->y_superblock_height; VAR_6++) {

            for (VAR_5 = 0; VAR_5 < VAR_0->y_superblock_width; VAR_5++) {



            for (VAR_3 = 0; VAR_3 < 4; VAR_3++) {

                int mb_x = 2*VAR_5 +   (VAR_3>>1);

                int mb_y = 2*VAR_6 + (((VAR_3>>1)+VAR_3)&1);

                int frags_coded = 0;

                VAR_8 = mb_y * VAR_0->macroblock_width + mb_x;



                if (mb_x >= VAR_0->macroblock_width || mb_y >= VAR_0->macroblock_height)

                    continue;



#define BLOCK_X (2*mb_x + (VAR_4&1))

#define BLOCK_Y (2*mb_y + (VAR_4>>1))

                



                for (VAR_4 = 0; VAR_4 < 4; VAR_4++) {

                    VAR_9 = BLOCK_Y*VAR_0->fragment_width + BLOCK_X;

                    if (VAR_0->all_fragments[VAR_9].coding_method != MODE_COPY)

                        break;

                }

                if (VAR_4 == 4) {

                    VAR_0->macroblock_coding[VAR_8] = MODE_INTER_NO_MV;

                    continue;

                }



                

                if (VAR_7 == 7)

                    VAR_10 = get_bits(VAR_1, 3);

                else if(VAR_7 == 0)

                    VAR_10 = VAR_11

                        [get_vlc2(VAR_1, VAR_0->mode_code_vlc.table, 3, 3)];

                else

                    VAR_10 = ModeAlphabet[VAR_7-1]

                        [get_vlc2(VAR_1, VAR_0->mode_code_vlc.table, 3, 3)];



                VAR_0->macroblock_coding[VAR_8] = VAR_10;

                for (VAR_4 = 0; VAR_4 < 4; VAR_4++) {

                    VAR_9 =

                        BLOCK_Y*VAR_0->fragment_width + BLOCK_X;

                    if (VAR_0->all_fragments[VAR_9].coding_method !=

                        MODE_COPY)

                        VAR_0->all_fragments[VAR_9].coding_method =

                            VAR_10;

                }

                for (VAR_4 = 0; VAR_4 < 2; VAR_4++) {

                    VAR_9 = VAR_0->fragment_start[VAR_4+1] +

                        mb_y*(VAR_0->fragment_width>>1) + mb_x;

                    if (VAR_0->all_fragments[VAR_9].coding_method !=

                        MODE_COPY)

                        VAR_0->all_fragments[VAR_9].coding_method =

                            VAR_10;

                }

            }

            }

        }

    }



    return 0;

}

static int FUNC_0(Vp3DecodeContext *VAR_0, GetBitContext *VAR_1)
{ int VAR_2, VAR_3, VAR_4, VAR_5, VAR_6; int VAR_7; int VAR_8; int VAR_9; int VAR_10; int VAR_11[CODING_MODE_COUNT]; if (VAR_0->keyframe) { for (VAR_2 = 0; VAR_2 < VAR_0->fragment_count; VAR_2++) VAR_0->all_fragments[VAR_2].coding_method = MODE_INTRA; } else { VAR_7 = get_bits(VAR_1, 3); if (VAR_7 == 0) { for (VAR_2 = 0; VAR_2 < 8; VAR_2++) VAR_11[VAR_2] = MODE_INTER_NO_MV; for (VAR_2 = 0; VAR_2 < 8; VAR_2++) VAR_11[get_bits(VAR_1, 3)] = VAR_2; } for (VAR_6 = 0; VAR_6 < VAR_0->y_superblock_height; VAR_6++) { for (VAR_5 = 0; VAR_5 < VAR_0->y_superblock_width; VAR_5++) { for (VAR_3 = 0; VAR_3 < 4; VAR_3++) { int mb_x = 2*VAR_5 +   (VAR_3>>1); int mb_y = 2*VAR_6 + (((VAR_3>>1)+VAR_3)&1); int frags_coded = 0; VAR_8 = mb_y * VAR_0->macroblock_width + mb_x; if (mb_x >= VAR_0->macroblock_width || mb_y >= VAR_0->macroblock_height)
continue; #define BLOCK_X (2*mb_x + (VAR_4&1))
#define BLOCK_Y (2*mb_y + (VAR_4>>1))
for (VAR_4 = 0; VAR_4 < 4; VAR_4++) { VAR_9 = BLOCK_Y*VAR_0->fragment_width + BLOCK_X; if (VAR_0->all_fragments[VAR_9].coding_method != MODE_COPY)
break; } if (VAR_4 == 4) { VAR_0->macroblock_coding[VAR_8] = MODE_INTER_NO_MV; continue; } if (VAR_7 == 7)
VAR_10 = get_bits(VAR_1, 3); else if(VAR_7 == 0)
VAR_10 = VAR_11
[get_vlc2(VAR_1, VAR_0->mode_code_vlc.table, 3, 3)]; else
VAR_10 = ModeAlphabet[VAR_7-1]
[get_vlc2(VAR_1, VAR_0->mode_code_vlc.table, 3, 3)]; VAR_0->macroblock_coding[VAR_8] = VAR_10; for (VAR_4 = 0; VAR_4 < 4; VAR_4++) { VAR_9 =
BLOCK_Y*VAR_0->fragment_width + BLOCK_X; if (VAR_0->all_fragments[VAR_9].coding_method !=
MODE_COPY)
VAR_0->all_fragments[VAR_9].coding_method =
VAR_10; } for (VAR_4 = 0; VAR_4 < 2; VAR_4++) { VAR_9 = VAR_0->fragment_start[VAR_4+1] +
mb_y*(VAR_0->fragment_width>>1) + mb_x; if (VAR_0->all_fragments[VAR_9].coding_method !=
MODE_COPY)
VAR_0->all_fragments[VAR_9].coding_method =
VAR_10; } } } } } return 0; }