int ff_vc1_parse_frame_header(VC1Context *v, GetBitContext* gb)

{

    int pqindex, lowquant, status;





    if (v->finterpflag)

        v->interpfrm = get_bits1(gb);

    if (!v->s.avctx->codec)

        return -1;

    if (v->s.avctx->codec_id == AV_CODEC_ID_MSS2)

        v->respic   =

        v->rangered =

        v->multires = get_bits(gb, 2) == 1;

    else

        skip_bits(gb, 2); //framecnt unused

    v->rangeredfrm = 0;

    if (v->rangered)

        v->rangeredfrm = get_bits1(gb);

    v->s.pict_type = get_bits1(gb);

    if (v->s.avctx->max_b_frames) {

        if (!v->s.pict_type) {

            if (get_bits1(gb))

                v->s.pict_type = AV_PICTURE_TYPE_I;

            else

                v->s.pict_type = AV_PICTURE_TYPE_B;

        } else

            v->s.pict_type = AV_PICTURE_TYPE_P;

    } else

        v->s.pict_type = v->s.pict_type ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I;



    v->bi_type = 0;

    if (v->s.pict_type == AV_PICTURE_TYPE_B) {

        if (read_bfraction(v, gb) < 0)

            return AVERROR_INVALIDDATA;

        if (v->bfraction == 0) {

            v->s.pict_type = AV_PICTURE_TYPE_BI;

        }

    }

    if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI)

        skip_bits(gb, 7); // skip buffer fullness



    if (v->parse_only)

        return 0;



    /* calculate RND */

    if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI)

        v->rnd = 1;

    if (v->s.pict_type == AV_PICTURE_TYPE_P)

        v->rnd ^= 1;



    /* Quantizer stuff */

    pqindex = get_bits(gb, 5);

    if (!pqindex)

        return -1;

    if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)

        v->pq = ff_vc1_pquant_table[0][pqindex];

    else

        v->pq = ff_vc1_pquant_table[1][pqindex];



    v->pquantizer = 1;

    if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)

        v->pquantizer = pqindex < 9;

    if (v->quantizer_mode == QUANT_NON_UNIFORM)

        v->pquantizer = 0;

    v->pqindex = pqindex;

    if (pqindex < 9)

        v->halfpq = get_bits1(gb);

    else

        v->halfpq = 0;

    if (v->quantizer_mode == QUANT_FRAME_EXPLICIT)

        v->pquantizer = get_bits1(gb);

    v->dquantfrm = 0;

    if (v->extended_mv == 1)

        v->mvrange = get_unary(gb, 0, 3);

    v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13

    v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11

    v->range_x = 1 << (v->k_x - 1);

    v->range_y = 1 << (v->k_y - 1);

    if (v->multires && v->s.pict_type != AV_PICTURE_TYPE_B)

        v->respic = get_bits(gb, 2);



    if (v->res_x8 && (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI)) {

        v->x8_type = get_bits1(gb);

    } else

        v->x8_type = 0;

    av_dlog(v->s.avctx, "%c Frame: QP=[%i]%i (+%i/2) %i\n",

            (v->s.pict_type == AV_PICTURE_TYPE_P) ? 'P' : ((v->s.pict_type == AV_PICTURE_TYPE_I) ? 'I' : 'B'),

            pqindex, v->pq, v->halfpq, v->rangeredfrm);



    if (v->first_pic_header_flag)

        rotate_luts(v);



    switch (v->s.pict_type) {

    case AV_PICTURE_TYPE_P:

        if (v->pq < 5)       v->tt_index = 0;

        else if (v->pq < 13) v->tt_index = 1;

        else                 v->tt_index = 2;



        lowquant = (v->pq > 12) ? 0 : 1;

        v->mv_mode = ff_vc1_mv_pmode_table[lowquant][get_unary(gb, 1, 4)];

        if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {

            v->mv_mode2 = ff_vc1_mv_pmode_table2[lowquant][get_unary(gb, 1, 3)];

            v->lumscale = get_bits(gb, 6);

            v->lumshift = get_bits(gb, 6);

            v->last_use_ic = 1;

            /* fill lookup tables for intensity compensation */

            INIT_LUT(v->lumscale, v->lumshift, v->last_luty[0], v->last_lutuv[0], 1);

            INIT_LUT(v->lumscale, v->lumshift, v->last_luty[1], v->last_lutuv[1], 1);

        }

        v->qs_last = v->s.quarter_sample;

        if (v->mv_mode == MV_PMODE_1MV_HPEL || v->mv_mode == MV_PMODE_1MV_HPEL_BILIN)

            v->s.quarter_sample = 0;

        else if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {

            if (v->mv_mode2 == MV_PMODE_1MV_HPEL || v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN)

                v->s.quarter_sample = 0;

            else

                v->s.quarter_sample = 1;

        } else

            v->s.quarter_sample = 1;

        v->s.mspel = !(v->mv_mode == MV_PMODE_1MV_HPEL_BILIN || (v->mv_mode == MV_PMODE_INTENSITY_COMP && v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN));



        if ((v->mv_mode  == MV_PMODE_INTENSITY_COMP &&

             v->mv_mode2 == MV_PMODE_MIXED_MV)      ||

            v->mv_mode   == MV_PMODE_MIXED_MV) {

            status = bitplane_decoding(v->mv_type_mb_plane, &v->mv_type_is_raw, v);

            if (status < 0)

                return -1;

            av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: "

                   "Imode: %i, Invert: %i\n", status>>1, status&1);

        } else {

            v->mv_type_is_raw = 0;

            memset(v->mv_type_mb_plane, 0, v->s.mb_stride * v->s.mb_height);

        }

        status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);

        if (status < 0)

            return -1;

        av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "

               "Imode: %i, Invert: %i\n", status>>1, status&1);



        /* Hopefully this is correct for P frames */

        v->s.mv_table_index = get_bits(gb, 2); //but using ff_vc1_ tables

        v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)];



        if (v->dquant) {

            av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");

            vop_dquant_decoding(v);

        }



        v->ttfrm = 0; //FIXME Is that so ?

        if (v->vstransform) {

            v->ttmbf = get_bits1(gb);

            if (v->ttmbf) {

                v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];

            }

        } else {

            v->ttmbf = 1;

            v->ttfrm = TT_8X8;

        }

        break;

    case AV_PICTURE_TYPE_B:

        if (v->pq < 5)       v->tt_index = 0;

        else if (v->pq < 13) v->tt_index = 1;

        else                 v->tt_index = 2;



        v->mv_mode          = get_bits1(gb) ? MV_PMODE_1MV : MV_PMODE_1MV_HPEL_BILIN;

        v->qs_last          = v->s.quarter_sample;

        v->s.quarter_sample = (v->mv_mode == MV_PMODE_1MV);

        v->s.mspel          = v->s.quarter_sample;



        status = bitplane_decoding(v->direct_mb_plane, &v->dmb_is_raw, v);

        if (status < 0)

            return -1;

        av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct Type plane encoding: "

               "Imode: %i, Invert: %i\n", status>>1, status&1);

        status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);

        if (status < 0)

            return -1;

        av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "

               "Imode: %i, Invert: %i\n", status>>1, status&1);



        v->s.mv_table_index = get_bits(gb, 2);

        v->cbpcy_vlc        = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)];



        if (v->dquant) {

            av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");

            vop_dquant_decoding(v);

        }



        v->ttfrm = 0;

        if (v->vstransform) {

            v->ttmbf = get_bits1(gb);

            if (v->ttmbf) {

                v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];

            }

        } else {

            v->ttmbf = 1;

            v->ttfrm = TT_8X8;

        }

        break;

    }



    if (!v->x8_type) {

        /* AC Syntax */

        v->c_ac_table_index = decode012(gb);

        if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI) {

            v->y_ac_table_index = decode012(gb);

        }

        /* DC Syntax */

        v->s.dc_table_index = get_bits1(gb);

    }



    if (v->s.pict_type == AV_PICTURE_TYPE_BI) {

        v->s.pict_type = AV_PICTURE_TYPE_B;

        v->bi_type     = 1;

    }

    return 0;

}
int ff_vc1_parse_frame_header(VC1Context *v, GetBitContext* gb)

{

    int pqindex, lowquant, status;





    if (v->finterpflag)

        v->interpfrm = get_bits1(gb);

    if (!v->s.avctx->codec)

        return -1;

    if (v->s.avctx->codec_id == AV_CODEC_ID_MSS2)

        v->respic   =

        v->rangered =

        v->multires = get_bits(gb, 2) == 1;

    else

        skip_bits(gb, 2); 

    v->rangeredfrm = 0;

    if (v->rangered)

        v->rangeredfrm = get_bits1(gb);

    v->s.pict_type = get_bits1(gb);

    if (v->s.avctx->max_b_frames) {

        if (!v->s.pict_type) {

            if (get_bits1(gb))

                v->s.pict_type = AV_PICTURE_TYPE_I;

            else

                v->s.pict_type = AV_PICTURE_TYPE_B;

        } else

            v->s.pict_type = AV_PICTURE_TYPE_P;

    } else

        v->s.pict_type = v->s.pict_type ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I;



    v->bi_type = 0;

    if (v->s.pict_type == AV_PICTURE_TYPE_B) {

        if (read_bfraction(v, gb) < 0)

            return AVERROR_INVALIDDATA;

        if (v->bfraction == 0) {

            v->s.pict_type = AV_PICTURE_TYPE_BI;

        }

    }

    if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI)

        skip_bits(gb, 7); 



    if (v->parse_only)

        return 0;



    

    if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI)

        v->rnd = 1;

    if (v->s.pict_type == AV_PICTURE_TYPE_P)

        v->rnd ^= 1;



    

    pqindex = get_bits(gb, 5);

    if (!pqindex)

        return -1;

    if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)

        v->pq = ff_vc1_pquant_table[0][pqindex];

    else

        v->pq = ff_vc1_pquant_table[1][pqindex];



    v->pquantizer = 1;

    if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)

        v->pquantizer = pqindex < 9;

    if (v->quantizer_mode == QUANT_NON_UNIFORM)

        v->pquantizer = 0;

    v->pqindex = pqindex;

    if (pqindex < 9)

        v->halfpq = get_bits1(gb);

    else

        v->halfpq = 0;

    if (v->quantizer_mode == QUANT_FRAME_EXPLICIT)

        v->pquantizer = get_bits1(gb);

    v->dquantfrm = 0;

    if (v->extended_mv == 1)

        v->mvrange = get_unary(gb, 0, 3);

    v->k_x = v->mvrange + 9 + (v->mvrange >> 1); 

    v->k_y = v->mvrange + 8; 

    v->range_x = 1 << (v->k_x - 1);

    v->range_y = 1 << (v->k_y - 1);

    if (v->multires && v->s.pict_type != AV_PICTURE_TYPE_B)

        v->respic = get_bits(gb, 2);



    if (v->res_x8 && (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI)) {

        v->x8_type = get_bits1(gb);

    } else

        v->x8_type = 0;

    av_dlog(v->s.avctx, "%c Frame: QP=[%i]%i (+%i/2) %i\n",

            (v->s.pict_type == AV_PICTURE_TYPE_P) ? 'P' : ((v->s.pict_type == AV_PICTURE_TYPE_I) ? 'I' : 'B'),

            pqindex, v->pq, v->halfpq, v->rangeredfrm);



    if (v->first_pic_header_flag)

        rotate_luts(v);



    switch (v->s.pict_type) {

    case AV_PICTURE_TYPE_P:

        if (v->pq < 5)       v->tt_index = 0;

        else if (v->pq < 13) v->tt_index = 1;

        else                 v->tt_index = 2;



        lowquant = (v->pq > 12) ? 0 : 1;

        v->mv_mode = ff_vc1_mv_pmode_table[lowquant][get_unary(gb, 1, 4)];

        if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {

            v->mv_mode2 = ff_vc1_mv_pmode_table2[lowquant][get_unary(gb, 1, 3)];

            v->lumscale = get_bits(gb, 6);

            v->lumshift = get_bits(gb, 6);

            v->last_use_ic = 1;

            

            INIT_LUT(v->lumscale, v->lumshift, v->last_luty[0], v->last_lutuv[0], 1);

            INIT_LUT(v->lumscale, v->lumshift, v->last_luty[1], v->last_lutuv[1], 1);

        }

        v->qs_last = v->s.quarter_sample;

        if (v->mv_mode == MV_PMODE_1MV_HPEL || v->mv_mode == MV_PMODE_1MV_HPEL_BILIN)

            v->s.quarter_sample = 0;

        else if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {

            if (v->mv_mode2 == MV_PMODE_1MV_HPEL || v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN)

                v->s.quarter_sample = 0;

            else

                v->s.quarter_sample = 1;

        } else

            v->s.quarter_sample = 1;

        v->s.mspel = !(v->mv_mode == MV_PMODE_1MV_HPEL_BILIN || (v->mv_mode == MV_PMODE_INTENSITY_COMP && v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN));



        if ((v->mv_mode  == MV_PMODE_INTENSITY_COMP &&

             v->mv_mode2 == MV_PMODE_MIXED_MV)      ||

            v->mv_mode   == MV_PMODE_MIXED_MV) {

            status = bitplane_decoding(v->mv_type_mb_plane, &v->mv_type_is_raw, v);

            if (status < 0)

                return -1;

            av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: "

                   "Imode: %i, Invert: %i\n", status>>1, status&1);

        } else {

            v->mv_type_is_raw = 0;

            memset(v->mv_type_mb_plane, 0, v->s.mb_stride * v->s.mb_height);

        }

        status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);

        if (status < 0)

            return -1;

        av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "

               "Imode: %i, Invert: %i\n", status>>1, status&1);



        

        v->s.mv_table_index = get_bits(gb, 2); 

        v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)];



        if (v->dquant) {

            av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");

            vop_dquant_decoding(v);

        }



        v->ttfrm = 0; 

        if (v->vstransform) {

            v->ttmbf = get_bits1(gb);

            if (v->ttmbf) {

                v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];

            }

        } else {

            v->ttmbf = 1;

            v->ttfrm = TT_8X8;

        }

        break;

    case AV_PICTURE_TYPE_B:

        if (v->pq < 5)       v->tt_index = 0;

        else if (v->pq < 13) v->tt_index = 1;

        else                 v->tt_index = 2;



        v->mv_mode          = get_bits1(gb) ? MV_PMODE_1MV : MV_PMODE_1MV_HPEL_BILIN;

        v->qs_last          = v->s.quarter_sample;

        v->s.quarter_sample = (v->mv_mode == MV_PMODE_1MV);

        v->s.mspel          = v->s.quarter_sample;



        status = bitplane_decoding(v->direct_mb_plane, &v->dmb_is_raw, v);

        if (status < 0)

            return -1;

        av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct Type plane encoding: "

               "Imode: %i, Invert: %i\n", status>>1, status&1);

        status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);

        if (status < 0)

            return -1;

        av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "

               "Imode: %i, Invert: %i\n", status>>1, status&1);



        v->s.mv_table_index = get_bits(gb, 2);

        v->cbpcy_vlc        = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)];



        if (v->dquant) {

            av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");

            vop_dquant_decoding(v);

        }



        v->ttfrm = 0;

        if (v->vstransform) {

            v->ttmbf = get_bits1(gb);

            if (v->ttmbf) {

                v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];

            }

        } else {

            v->ttmbf = 1;

            v->ttfrm = TT_8X8;

        }

        break;

    }



    if (!v->x8_type) {

        

        v->c_ac_table_index = decode012(gb);

        if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI) {

            v->y_ac_table_index = decode012(gb);

        }

        

        v->s.dc_table_index = get_bits1(gb);

    }



    if (v->s.pict_type == AV_PICTURE_TYPE_BI) {

        v->s.pict_type = AV_PICTURE_TYPE_B;

        v->bi_type     = 1;

    }

    return 0;

}
int FUNC_0(VC1Context *VAR_0, GetBitContext* VAR_1)

{

    int VAR_2, VAR_3, VAR_4;





    if (VAR_0->finterpflag)

        VAR_0->interpfrm = get_bits1(VAR_1);

    if (!VAR_0->s.avctx->codec)

        return -1;

    if (VAR_0->s.avctx->codec_id == AV_CODEC_ID_MSS2)

        VAR_0->respic   =

        VAR_0->rangered =

        VAR_0->multires = get_bits(VAR_1, 2) == 1;

    else

        skip_bits(VAR_1, 2); 

    VAR_0->rangeredfrm = 0;

    if (VAR_0->rangered)

        VAR_0->rangeredfrm = get_bits1(VAR_1);

    VAR_0->s.pict_type = get_bits1(VAR_1);

    if (VAR_0->s.avctx->max_b_frames) {

        if (!VAR_0->s.pict_type) {

            if (get_bits1(VAR_1))

                VAR_0->s.pict_type = AV_PICTURE_TYPE_I;

            else

                VAR_0->s.pict_type = AV_PICTURE_TYPE_B;

        } else

            VAR_0->s.pict_type = AV_PICTURE_TYPE_P;

    } else

        VAR_0->s.pict_type = VAR_0->s.pict_type ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I;



    VAR_0->bi_type = 0;

    if (VAR_0->s.pict_type == AV_PICTURE_TYPE_B) {

        if (read_bfraction(VAR_0, VAR_1) < 0)

            return AVERROR_INVALIDDATA;

        if (VAR_0->bfraction == 0) {

            VAR_0->s.pict_type = AV_PICTURE_TYPE_BI;

        }

    }

    if (VAR_0->s.pict_type == AV_PICTURE_TYPE_I || VAR_0->s.pict_type == AV_PICTURE_TYPE_BI)

        skip_bits(VAR_1, 7); 



    if (VAR_0->parse_only)

        return 0;



    

    if (VAR_0->s.pict_type == AV_PICTURE_TYPE_I || VAR_0->s.pict_type == AV_PICTURE_TYPE_BI)

        VAR_0->rnd = 1;

    if (VAR_0->s.pict_type == AV_PICTURE_TYPE_P)

        VAR_0->rnd ^= 1;



    

    VAR_2 = get_bits(VAR_1, 5);

    if (!VAR_2)

        return -1;

    if (VAR_0->quantizer_mode == QUANT_FRAME_IMPLICIT)

        VAR_0->pq = ff_vc1_pquant_table[0][VAR_2];

    else

        VAR_0->pq = ff_vc1_pquant_table[1][VAR_2];



    VAR_0->pquantizer = 1;

    if (VAR_0->quantizer_mode == QUANT_FRAME_IMPLICIT)

        VAR_0->pquantizer = VAR_2 < 9;

    if (VAR_0->quantizer_mode == QUANT_NON_UNIFORM)

        VAR_0->pquantizer = 0;

    VAR_0->VAR_2 = VAR_2;

    if (VAR_2 < 9)

        VAR_0->halfpq = get_bits1(VAR_1);

    else

        VAR_0->halfpq = 0;

    if (VAR_0->quantizer_mode == QUANT_FRAME_EXPLICIT)

        VAR_0->pquantizer = get_bits1(VAR_1);

    VAR_0->dquantfrm = 0;

    if (VAR_0->extended_mv == 1)

        VAR_0->mvrange = get_unary(VAR_1, 0, 3);

    VAR_0->k_x = VAR_0->mvrange + 9 + (VAR_0->mvrange >> 1); 

    VAR_0->k_y = VAR_0->mvrange + 8; 

    VAR_0->range_x = 1 << (VAR_0->k_x - 1);

    VAR_0->range_y = 1 << (VAR_0->k_y - 1);

    if (VAR_0->multires && VAR_0->s.pict_type != AV_PICTURE_TYPE_B)

        VAR_0->respic = get_bits(VAR_1, 2);



    if (VAR_0->res_x8 && (VAR_0->s.pict_type == AV_PICTURE_TYPE_I || VAR_0->s.pict_type == AV_PICTURE_TYPE_BI)) {

        VAR_0->x8_type = get_bits1(VAR_1);

    } else

        VAR_0->x8_type = 0;

    av_dlog(VAR_0->s.avctx, "%c Frame: QP=[%i]%i (+%i/2) %i\n",

            (VAR_0->s.pict_type == AV_PICTURE_TYPE_P) ? 'P' : ((VAR_0->s.pict_type == AV_PICTURE_TYPE_I) ? 'I' : 'B'),

            VAR_2, VAR_0->pq, VAR_0->halfpq, VAR_0->rangeredfrm);



    if (VAR_0->first_pic_header_flag)

        rotate_luts(VAR_0);



    switch (VAR_0->s.pict_type) {

    case AV_PICTURE_TYPE_P:

        if (VAR_0->pq < 5)       VAR_0->tt_index = 0;

        else if (VAR_0->pq < 13) VAR_0->tt_index = 1;

        else                 VAR_0->tt_index = 2;



        VAR_3 = (VAR_0->pq > 12) ? 0 : 1;

        VAR_0->mv_mode = ff_vc1_mv_pmode_table[VAR_3][get_unary(VAR_1, 1, 4)];

        if (VAR_0->mv_mode == MV_PMODE_INTENSITY_COMP) {

            VAR_0->mv_mode2 = ff_vc1_mv_pmode_table2[VAR_3][get_unary(VAR_1, 1, 3)];

            VAR_0->lumscale = get_bits(VAR_1, 6);

            VAR_0->lumshift = get_bits(VAR_1, 6);

            VAR_0->last_use_ic = 1;

            

            INIT_LUT(VAR_0->lumscale, VAR_0->lumshift, VAR_0->last_luty[0], VAR_0->last_lutuv[0], 1);

            INIT_LUT(VAR_0->lumscale, VAR_0->lumshift, VAR_0->last_luty[1], VAR_0->last_lutuv[1], 1);

        }

        VAR_0->qs_last = VAR_0->s.quarter_sample;

        if (VAR_0->mv_mode == MV_PMODE_1MV_HPEL || VAR_0->mv_mode == MV_PMODE_1MV_HPEL_BILIN)

            VAR_0->s.quarter_sample = 0;

        else if (VAR_0->mv_mode == MV_PMODE_INTENSITY_COMP) {

            if (VAR_0->mv_mode2 == MV_PMODE_1MV_HPEL || VAR_0->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN)

                VAR_0->s.quarter_sample = 0;

            else

                VAR_0->s.quarter_sample = 1;

        } else

            VAR_0->s.quarter_sample = 1;

        VAR_0->s.mspel = !(VAR_0->mv_mode == MV_PMODE_1MV_HPEL_BILIN || (VAR_0->mv_mode == MV_PMODE_INTENSITY_COMP && VAR_0->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN));



        if ((VAR_0->mv_mode  == MV_PMODE_INTENSITY_COMP &&

             VAR_0->mv_mode2 == MV_PMODE_MIXED_MV)      ||

            VAR_0->mv_mode   == MV_PMODE_MIXED_MV) {

            VAR_4 = bitplane_decoding(VAR_0->mv_type_mb_plane, &VAR_0->mv_type_is_raw, VAR_0);

            if (VAR_4 < 0)

                return -1;

            av_log(VAR_0->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: "

                   "Imode: %i, Invert: %i\n", VAR_4>>1, VAR_4&1);

        } else {

            VAR_0->mv_type_is_raw = 0;

            memset(VAR_0->mv_type_mb_plane, 0, VAR_0->s.mb_stride * VAR_0->s.mb_height);

        }

        VAR_4 = bitplane_decoding(VAR_0->s.mbskip_table, &VAR_0->skip_is_raw, VAR_0);

        if (VAR_4 < 0)

            return -1;

        av_log(VAR_0->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "

               "Imode: %i, Invert: %i\n", VAR_4>>1, VAR_4&1);



        

        VAR_0->s.mv_table_index = get_bits(VAR_1, 2); 

        VAR_0->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(VAR_1, 2)];



        if (VAR_0->dquant) {

            av_log(VAR_0->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");

            vop_dquant_decoding(VAR_0);

        }



        VAR_0->ttfrm = 0; 

        if (VAR_0->vstransform) {

            VAR_0->ttmbf = get_bits1(VAR_1);

            if (VAR_0->ttmbf) {

                VAR_0->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(VAR_1, 2)];

            }

        } else {

            VAR_0->ttmbf = 1;

            VAR_0->ttfrm = TT_8X8;

        }

        break;

    case AV_PICTURE_TYPE_B:

        if (VAR_0->pq < 5)       VAR_0->tt_index = 0;

        else if (VAR_0->pq < 13) VAR_0->tt_index = 1;

        else                 VAR_0->tt_index = 2;



        VAR_0->mv_mode          = get_bits1(VAR_1) ? MV_PMODE_1MV : MV_PMODE_1MV_HPEL_BILIN;

        VAR_0->qs_last          = VAR_0->s.quarter_sample;

        VAR_0->s.quarter_sample = (VAR_0->mv_mode == MV_PMODE_1MV);

        VAR_0->s.mspel          = VAR_0->s.quarter_sample;



        VAR_4 = bitplane_decoding(VAR_0->direct_mb_plane, &VAR_0->dmb_is_raw, VAR_0);

        if (VAR_4 < 0)

            return -1;

        av_log(VAR_0->s.avctx, AV_LOG_DEBUG, "MB Direct Type plane encoding: "

               "Imode: %i, Invert: %i\n", VAR_4>>1, VAR_4&1);

        VAR_4 = bitplane_decoding(VAR_0->s.mbskip_table, &VAR_0->skip_is_raw, VAR_0);

        if (VAR_4 < 0)

            return -1;

        av_log(VAR_0->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "

               "Imode: %i, Invert: %i\n", VAR_4>>1, VAR_4&1);



        VAR_0->s.mv_table_index = get_bits(VAR_1, 2);

        VAR_0->cbpcy_vlc        = &ff_vc1_cbpcy_p_vlc[get_bits(VAR_1, 2)];



        if (VAR_0->dquant) {

            av_log(VAR_0->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");

            vop_dquant_decoding(VAR_0);

        }



        VAR_0->ttfrm = 0;

        if (VAR_0->vstransform) {

            VAR_0->ttmbf = get_bits1(VAR_1);

            if (VAR_0->ttmbf) {

                VAR_0->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(VAR_1, 2)];

            }

        } else {

            VAR_0->ttmbf = 1;

            VAR_0->ttfrm = TT_8X8;

        }

        break;

    }



    if (!VAR_0->x8_type) {

        

        VAR_0->c_ac_table_index = decode012(VAR_1);

        if (VAR_0->s.pict_type == AV_PICTURE_TYPE_I || VAR_0->s.pict_type == AV_PICTURE_TYPE_BI) {

            VAR_0->y_ac_table_index = decode012(VAR_1);

        }

        

        VAR_0->s.dc_table_index = get_bits1(VAR_1);

    }



    if (VAR_0->s.pict_type == AV_PICTURE_TYPE_BI) {

        VAR_0->s.pict_type = AV_PICTURE_TYPE_B;

        VAR_0->bi_type     = 1;

    }

    return 0;

}
int FUNC_0(VC1Context *VAR_0, GetBitContext* VAR_1)
{ int VAR_2, VAR_3, VAR_4; if (VAR_0->finterpflag)
VAR_0->interpfrm = get_bits1(VAR_1); if (!VAR_0->s.avctx->codec)
return -1; if (VAR_0->s.avctx->codec_id == AV_CODEC_ID_MSS2)
VAR_0->respic   =
VAR_0->rangered =
VAR_0->multires = get_bits(VAR_1, 2) == 1; else
skip_bits(VAR_1, 2); VAR_0->rangeredfrm = 0; if (VAR_0->rangered)
VAR_0->rangeredfrm = get_bits1(VAR_1); VAR_0->s.pict_type = get_bits1(VAR_1); if (VAR_0->s.avctx->max_b_frames) { if (!VAR_0->s.pict_type) { if (get_bits1(VAR_1))
VAR_0->s.pict_type = AV_PICTURE_TYPE_I; else
VAR_0->s.pict_type = AV_PICTURE_TYPE_B; } else VAR_0->s.pict_type = AV_PICTURE_TYPE_P; } else VAR_0->s.pict_type = VAR_0->s.pict_type ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I; VAR_0->bi_type = 0; if (VAR_0->s.pict_type == AV_PICTURE_TYPE_B) { if (read_bfraction(VAR_0, VAR_1) < 0)
return AVERROR_INVALIDDATA; if (VAR_0->bfraction == 0) { VAR_0->s.pict_type = AV_PICTURE_TYPE_BI; } } if (VAR_0->s.pict_type == AV_PICTURE_TYPE_I || VAR_0->s.pict_type == AV_PICTURE_TYPE_BI)
skip_bits(VAR_1, 7); if (VAR_0->parse_only)
return 0; if (VAR_0->s.pict_type == AV_PICTURE_TYPE_I || VAR_0->s.pict_type == AV_PICTURE_TYPE_BI)
VAR_0->rnd = 1; if (VAR_0->s.pict_type == AV_PICTURE_TYPE_P)
VAR_0->rnd ^= 1; VAR_2 = get_bits(VAR_1, 5); if (!VAR_2)
return -1; if (VAR_0->quantizer_mode == QUANT_FRAME_IMPLICIT)
VAR_0->pq = ff_vc1_pquant_table[0][VAR_2]; else
VAR_0->pq = ff_vc1_pquant_table[1][VAR_2]; VAR_0->pquantizer = 1; if (VAR_0->quantizer_mode == QUANT_FRAME_IMPLICIT)
VAR_0->pquantizer = VAR_2 < 9; if (VAR_0->quantizer_mode == QUANT_NON_UNIFORM)
VAR_0->pquantizer = 0; VAR_0->VAR_2 = VAR_2; if (VAR_2 < 9)
VAR_0->halfpq = get_bits1(VAR_1); else
VAR_0->halfpq = 0; if (VAR_0->quantizer_mode == QUANT_FRAME_EXPLICIT)
VAR_0->pquantizer = get_bits1(VAR_1); VAR_0->dquantfrm = 0; if (VAR_0->extended_mv == 1)
VAR_0->mvrange = get_unary(VAR_1, 0, 3); VAR_0->k_x = VAR_0->mvrange + 9 + (VAR_0->mvrange >> 1); VAR_0->k_y = VAR_0->mvrange + 8; VAR_0->range_x = 1 << (VAR_0->k_x - 1); VAR_0->range_y = 1 << (VAR_0->k_y - 1); if (VAR_0->multires && VAR_0->s.pict_type != AV_PICTURE_TYPE_B)
VAR_0->respic = get_bits(VAR_1, 2); if (VAR_0->res_x8 && (VAR_0->s.pict_type == AV_PICTURE_TYPE_I || VAR_0->s.pict_type == AV_PICTURE_TYPE_BI)) { VAR_0->x8_type = get_bits1(VAR_1); } else VAR_0->x8_type = 0; av_dlog(VAR_0->s.avctx, "%c Frame: QP=[%i]%i (+%i/2) %i\n",
(VAR_0->s.pict_type == AV_PICTURE_TYPE_P) ? 'P' : ((VAR_0->s.pict_type == AV_PICTURE_TYPE_I) ? 'I' : 'B'),
VAR_2, VAR_0->pq, VAR_0->halfpq, VAR_0->rangeredfrm); if (VAR_0->first_pic_header_flag)
rotate_luts(VAR_0); switch (VAR_0->s.pict_type) { case AV_PICTURE_TYPE_P:
if (VAR_0->pq < 5)       VAR_0->tt_index = 0; else if (VAR_0->pq < 13) VAR_0->tt_index = 1; else                 VAR_0->tt_index = 2; VAR_3 = (VAR_0->pq > 12) ? 0 : 1; VAR_0->mv_mode = ff_vc1_mv_pmode_table[VAR_3][get_unary(VAR_1, 1, 4)]; if (VAR_0->mv_mode == MV_PMODE_INTENSITY_COMP) { VAR_0->mv_mode2 = ff_vc1_mv_pmode_table2[VAR_3][get_unary(VAR_1, 1, 3)]; VAR_0->lumscale = get_bits(VAR_1, 6); VAR_0->lumshift = get_bits(VAR_1, 6); VAR_0->last_use_ic = 1; INIT_LUT(VAR_0->lumscale, VAR_0->lumshift, VAR_0->last_luty[0], VAR_0->last_lutuv[0], 1); INIT_LUT(VAR_0->lumscale, VAR_0->lumshift, VAR_0->last_luty[1], VAR_0->last_lutuv[1], 1); } VAR_0->qs_last = VAR_0->s.quarter_sample; if (VAR_0->mv_mode == MV_PMODE_1MV_HPEL || VAR_0->mv_mode == MV_PMODE_1MV_HPEL_BILIN)
VAR_0->s.quarter_sample = 0; else if (VAR_0->mv_mode == MV_PMODE_INTENSITY_COMP) { if (VAR_0->mv_mode2 == MV_PMODE_1MV_HPEL || VAR_0->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN)
VAR_0->s.quarter_sample = 0; else
VAR_0->s.quarter_sample = 1; } else VAR_0->s.quarter_sample = 1; VAR_0->s.mspel = !(VAR_0->mv_mode == MV_PMODE_1MV_HPEL_BILIN || (VAR_0->mv_mode == MV_PMODE_INTENSITY_COMP && VAR_0->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN)); if ((VAR_0->mv_mode  == MV_PMODE_INTENSITY_COMP &&
VAR_0->mv_mode2 == MV_PMODE_MIXED_MV)      ||
VAR_0->mv_mode   == MV_PMODE_MIXED_MV) { VAR_4 = bitplane_decoding(VAR_0->mv_type_mb_plane, &VAR_0->mv_type_is_raw, VAR_0); if (VAR_4 < 0)
return -1; av_log(VAR_0->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: "
"Imode: %i, Invert: %i\n", VAR_4>>1, VAR_4&1); } else { VAR_0->mv_type_is_raw = 0; memset(VAR_0->mv_type_mb_plane, 0, VAR_0->s.mb_stride * VAR_0->s.mb_height); } VAR_4 = bitplane_decoding(VAR_0->s.mbskip_table, &VAR_0->skip_is_raw, VAR_0); if (VAR_4 < 0)
return -1; av_log(VAR_0->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
"Imode: %i, Invert: %i\n", VAR_4>>1, VAR_4&1); VAR_0->s.mv_table_index = get_bits(VAR_1, 2); VAR_0->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(VAR_1, 2)]; if (VAR_0->dquant) { av_log(VAR_0->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n"); vop_dquant_decoding(VAR_0); } VAR_0->ttfrm = 0; if (VAR_0->vstransform) { VAR_0->ttmbf = get_bits1(VAR_1); if (VAR_0->ttmbf) { VAR_0->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(VAR_1, 2)]; } } else { VAR_0->ttmbf = 1; VAR_0->ttfrm = TT_8X8; } break; case AV_PICTURE_TYPE_B:
if (VAR_0->pq < 5)       VAR_0->tt_index = 0; else if (VAR_0->pq < 13) VAR_0->tt_index = 1; else                 VAR_0->tt_index = 2; VAR_0->mv_mode          = get_bits1(VAR_1) ? MV_PMODE_1MV : MV_PMODE_1MV_HPEL_BILIN; VAR_0->qs_last          = VAR_0->s.quarter_sample; VAR_0->s.quarter_sample = (VAR_0->mv_mode == MV_PMODE_1MV); VAR_0->s.mspel          = VAR_0->s.quarter_sample; VAR_4 = bitplane_decoding(VAR_0->direct_mb_plane, &VAR_0->dmb_is_raw, VAR_0); if (VAR_4 < 0)
return -1; av_log(VAR_0->s.avctx, AV_LOG_DEBUG, "MB Direct Type plane encoding: "
"Imode: %i, Invert: %i\n", VAR_4>>1, VAR_4&1); VAR_4 = bitplane_decoding(VAR_0->s.mbskip_table, &VAR_0->skip_is_raw, VAR_0); if (VAR_4 < 0)
return -1; av_log(VAR_0->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
"Imode: %i, Invert: %i\n", VAR_4>>1, VAR_4&1); VAR_0->s.mv_table_index = get_bits(VAR_1, 2); VAR_0->cbpcy_vlc        = &ff_vc1_cbpcy_p_vlc[get_bits(VAR_1, 2)]; if (VAR_0->dquant) { av_log(VAR_0->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n"); vop_dquant_decoding(VAR_0); } VAR_0->ttfrm = 0; if (VAR_0->vstransform) { VAR_0->ttmbf = get_bits1(VAR_1); if (VAR_0->ttmbf) { VAR_0->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(VAR_1, 2)]; } } else { VAR_0->ttmbf = 1; VAR_0->ttfrm = TT_8X8; } break; } if (!VAR_0->x8_type) { VAR_0->c_ac_table_index = decode012(VAR_1); if (VAR_0->s.pict_type == AV_PICTURE_TYPE_I || VAR_0->s.pict_type == AV_PICTURE_TYPE_BI) { VAR_0->y_ac_table_index = decode012(VAR_1); } VAR_0->s.dc_table_index = get_bits1(VAR_1); } if (VAR_0->s.pict_type == AV_PICTURE_TYPE_BI) { VAR_0->s.pict_type = AV_PICTURE_TYPE_B; VAR_0->bi_type     = 1; } return 0; }