static int read_header(FFV1Context *f){

    uint8_t state[CONTEXT_SIZE];

    int i, j, context_count;

    RangeCoder * const c= &f->slice_context[0]->c;



    memset(state, 128, sizeof(state));



    if(f->version < 2){

        f->version= get_symbol(c, state, 0);

        f->ac= f->avctx->coder_type= get_symbol(c, state, 0);

        if(f->ac>1){

            for(i=1; i<256; i++){

                f->state_transition[i]= get_symbol(c, state, 1) + c->one_state[i];

            }

        }

        f->colorspace= get_symbol(c, state, 0); //YUV cs type

        if(f->version>0)

            f->avctx->bits_per_raw_sample= get_symbol(c, state, 0);

        f->chroma_planes= get_rac(c, state);

        f->chroma_h_shift= get_symbol(c, state, 0);

        f->chroma_v_shift= get_symbol(c, state, 0);

        f->transparency= get_rac(c, state);

        f->plane_count= 2 + f->transparency;

    }



    if(f->colorspace==0){

        if(!f->transparency && !f->chroma_planes){

            if (f->avctx->bits_per_raw_sample<=8)

                f->avctx->pix_fmt= PIX_FMT_GRAY8;

            else

                f->avctx->pix_fmt= PIX_FMT_GRAY16;

        }else if(f->avctx->bits_per_raw_sample<=8 && !f->transparency){

            switch(16*f->chroma_h_shift + f->chroma_v_shift){

            case 0x00: f->avctx->pix_fmt= PIX_FMT_YUV444P; break;

            case 0x01: f->avctx->pix_fmt= PIX_FMT_YUV440P; break;

            case 0x10: f->avctx->pix_fmt= PIX_FMT_YUV422P; break;

            case 0x11: f->avctx->pix_fmt= PIX_FMT_YUV420P; break;

            case 0x20: f->avctx->pix_fmt= PIX_FMT_YUV411P; break;

            case 0x22: f->avctx->pix_fmt= PIX_FMT_YUV410P; break;

            default:

                av_log(f->avctx, AV_LOG_ERROR, "format not supported\n");

                return -1;

            }

        }else if(f->avctx->bits_per_raw_sample<=8 && f->transparency){

            switch(16*f->chroma_h_shift + f->chroma_v_shift){

            case 0x00: f->avctx->pix_fmt= PIX_FMT_YUVA444P; break;

            case 0x11: f->avctx->pix_fmt= PIX_FMT_YUVA420P; break;

            default:

                av_log(f->avctx, AV_LOG_ERROR, "format not supported\n");

                return -1;

            }

        }else if(f->avctx->bits_per_raw_sample==9) {

            f->packed_at_lsb=1;

            switch(16*f->chroma_h_shift + f->chroma_v_shift){

            case 0x00: f->avctx->pix_fmt= PIX_FMT_YUV444P9; break;

            case 0x10: f->avctx->pix_fmt= PIX_FMT_YUV422P9; break;

            case 0x11: f->avctx->pix_fmt= PIX_FMT_YUV420P9; break;

            default:

                av_log(f->avctx, AV_LOG_ERROR, "format not supported\n");

                return -1;

            }

        }else if(f->avctx->bits_per_raw_sample==10) {

            f->packed_at_lsb=1;

            switch(16*f->chroma_h_shift + f->chroma_v_shift){

            case 0x00: f->avctx->pix_fmt= PIX_FMT_YUV444P10; break;

            case 0x10: f->avctx->pix_fmt= PIX_FMT_YUV422P10; break;

            case 0x11: f->avctx->pix_fmt= PIX_FMT_YUV420P10; break;

            default:

                av_log(f->avctx, AV_LOG_ERROR, "format not supported\n");

                return -1;

            }

        }else {

            switch(16*f->chroma_h_shift + f->chroma_v_shift){

            case 0x00: f->avctx->pix_fmt= PIX_FMT_YUV444P16; break;

            case 0x10: f->avctx->pix_fmt= PIX_FMT_YUV422P16; break;

            case 0x11: f->avctx->pix_fmt= PIX_FMT_YUV420P16; break;

            default:

                av_log(f->avctx, AV_LOG_ERROR, "format not supported\n");

                return -1;

            }

        }

    }else if(f->colorspace==1){

        if(f->chroma_h_shift || f->chroma_v_shift){

            av_log(f->avctx, AV_LOG_ERROR, "chroma subsampling not supported in this colorspace\n");

            return -1;

        }

        if(f->transparency) f->avctx->pix_fmt= PIX_FMT_RGB32;

        else                f->avctx->pix_fmt= PIX_FMT_0RGB32;

    }else{

        av_log(f->avctx, AV_LOG_ERROR, "colorspace not supported\n");

        return -1;

    }



//printf("%d %d %d\n", f->chroma_h_shift, f->chroma_v_shift,f->avctx->pix_fmt);

    if(f->version < 2){

        context_count= read_quant_tables(c, f->quant_table);

        if(context_count < 0){

                av_log(f->avctx, AV_LOG_ERROR, "read_quant_table error\n");

                return -1;

        }

    }else{

        f->slice_count= get_symbol(c, state, 0);

        if(f->slice_count > (unsigned)MAX_SLICES)

            return -1;

    }



    for(j=0; j<f->slice_count; j++){

        FFV1Context *fs= f->slice_context[j];

        fs->ac= f->ac;

        fs->packed_at_lsb= f->packed_at_lsb;



        if(f->version >= 2){

            fs->slice_x     = get_symbol(c, state, 0)   *f->width ;

            fs->slice_y     = get_symbol(c, state, 0)   *f->height;

            fs->slice_width =(get_symbol(c, state, 0)+1)*f->width  + fs->slice_x;

            fs->slice_height=(get_symbol(c, state, 0)+1)*f->height + fs->slice_y;



            fs->slice_x /= f->num_h_slices;

            fs->slice_y /= f->num_v_slices;

            fs->slice_width  = fs->slice_width /f->num_h_slices - fs->slice_x;

            fs->slice_height = fs->slice_height/f->num_v_slices - fs->slice_y;

            if((unsigned)fs->slice_width > f->width || (unsigned)fs->slice_height > f->height)

                return -1;

            if(    (unsigned)fs->slice_x + (uint64_t)fs->slice_width  > f->width

                || (unsigned)fs->slice_y + (uint64_t)fs->slice_height > f->height)

                return -1;

        }



        for(i=0; i<f->plane_count; i++){

            PlaneContext * const p= &fs->plane[i];



            if(f->version >= 2){

                int idx=get_symbol(c, state, 0);

                if(idx > (unsigned)f->quant_table_count){

                    av_log(f->avctx, AV_LOG_ERROR, "quant_table_index out of range\n");

                    return -1;

                }

                p->quant_table_index= idx;

                memcpy(p->quant_table, f->quant_tables[idx], sizeof(p->quant_table));

                context_count= f->context_count[idx];

            }else{

                memcpy(p->quant_table, f->quant_table, sizeof(p->quant_table));

            }



            if(p->context_count < context_count){

                av_freep(&p->state);

                av_freep(&p->vlc_state);

            }

            p->context_count= context_count;

        }

    }



    return 0;

}

static int read_header(FFV1Context *f){

    uint8_t state[CONTEXT_SIZE];

    int i, j, context_count;

    RangeCoder * const c= &f->slice_context[0]->c;



    memset(state, 128, sizeof(state));



    if(f->version < 2){

        f->version= get_symbol(c, state, 0);

        f->ac= f->avctx->coder_type= get_symbol(c, state, 0);

        if(f->ac>1){

            for(i=1; i<256; i++){

                f->state_transition[i]= get_symbol(c, state, 1) + c->one_state[i];

            }

        }

        f->colorspace= get_symbol(c, state, 0); 

        if(f->version>0)

            f->avctx->bits_per_raw_sample= get_symbol(c, state, 0);

        f->chroma_planes= get_rac(c, state);

        f->chroma_h_shift= get_symbol(c, state, 0);

        f->chroma_v_shift= get_symbol(c, state, 0);

        f->transparency= get_rac(c, state);

        f->plane_count= 2 + f->transparency;

    }



    if(f->colorspace==0){

        if(!f->transparency && !f->chroma_planes){

            if (f->avctx->bits_per_raw_sample<=8)

                f->avctx->pix_fmt= PIX_FMT_GRAY8;

            else

                f->avctx->pix_fmt= PIX_FMT_GRAY16;

        }else if(f->avctx->bits_per_raw_sample<=8 && !f->transparency){

            switch(16*f->chroma_h_shift + f->chroma_v_shift){

            case 0x00: f->avctx->pix_fmt= PIX_FMT_YUV444P; break;

            case 0x01: f->avctx->pix_fmt= PIX_FMT_YUV440P; break;

            case 0x10: f->avctx->pix_fmt= PIX_FMT_YUV422P; break;

            case 0x11: f->avctx->pix_fmt= PIX_FMT_YUV420P; break;

            case 0x20: f->avctx->pix_fmt= PIX_FMT_YUV411P; break;

            case 0x22: f->avctx->pix_fmt= PIX_FMT_YUV410P; break;

            default:

                av_log(f->avctx, AV_LOG_ERROR, "format not supported\n");

                return -1;

            }

        }else if(f->avctx->bits_per_raw_sample<=8 && f->transparency){

            switch(16*f->chroma_h_shift + f->chroma_v_shift){

            case 0x00: f->avctx->pix_fmt= PIX_FMT_YUVA444P; break;

            case 0x11: f->avctx->pix_fmt= PIX_FMT_YUVA420P; break;

            default:

                av_log(f->avctx, AV_LOG_ERROR, "format not supported\n");

                return -1;

            }

        }else if(f->avctx->bits_per_raw_sample==9) {

            f->packed_at_lsb=1;

            switch(16*f->chroma_h_shift + f->chroma_v_shift){

            case 0x00: f->avctx->pix_fmt= PIX_FMT_YUV444P9; break;

            case 0x10: f->avctx->pix_fmt= PIX_FMT_YUV422P9; break;

            case 0x11: f->avctx->pix_fmt= PIX_FMT_YUV420P9; break;

            default:

                av_log(f->avctx, AV_LOG_ERROR, "format not supported\n");

                return -1;

            }

        }else if(f->avctx->bits_per_raw_sample==10) {

            f->packed_at_lsb=1;

            switch(16*f->chroma_h_shift + f->chroma_v_shift){

            case 0x00: f->avctx->pix_fmt= PIX_FMT_YUV444P10; break;

            case 0x10: f->avctx->pix_fmt= PIX_FMT_YUV422P10; break;

            case 0x11: f->avctx->pix_fmt= PIX_FMT_YUV420P10; break;

            default:

                av_log(f->avctx, AV_LOG_ERROR, "format not supported\n");

                return -1;

            }

        }else {

            switch(16*f->chroma_h_shift + f->chroma_v_shift){

            case 0x00: f->avctx->pix_fmt= PIX_FMT_YUV444P16; break;

            case 0x10: f->avctx->pix_fmt= PIX_FMT_YUV422P16; break;

            case 0x11: f->avctx->pix_fmt= PIX_FMT_YUV420P16; break;

            default:

                av_log(f->avctx, AV_LOG_ERROR, "format not supported\n");

                return -1;

            }

        }

    }else if(f->colorspace==1){

        if(f->chroma_h_shift || f->chroma_v_shift){

            av_log(f->avctx, AV_LOG_ERROR, "chroma subsampling not supported in this colorspace\n");

            return -1;

        }

        if(f->transparency) f->avctx->pix_fmt= PIX_FMT_RGB32;

        else                f->avctx->pix_fmt= PIX_FMT_0RGB32;

    }else{

        av_log(f->avctx, AV_LOG_ERROR, "colorspace not supported\n");

        return -1;

    }





    if(f->version < 2){

        context_count= read_quant_tables(c, f->quant_table);

        if(context_count < 0){

                av_log(f->avctx, AV_LOG_ERROR, "read_quant_table error\n");

                return -1;

        }

    }else{

        f->slice_count= get_symbol(c, state, 0);

        if(f->slice_count > (unsigned)MAX_SLICES)

            return -1;

    }



    for(j=0; j<f->slice_count; j++){

        FFV1Context *fs= f->slice_context[j];

        fs->ac= f->ac;

        fs->packed_at_lsb= f->packed_at_lsb;



        if(f->version >= 2){

            fs->slice_x     = get_symbol(c, state, 0)   *f->width ;

            fs->slice_y     = get_symbol(c, state, 0)   *f->height;

            fs->slice_width =(get_symbol(c, state, 0)+1)*f->width  + fs->slice_x;

            fs->slice_height=(get_symbol(c, state, 0)+1)*f->height + fs->slice_y;



            fs->slice_x /= f->num_h_slices;

            fs->slice_y /= f->num_v_slices;

            fs->slice_width  = fs->slice_width /f->num_h_slices - fs->slice_x;

            fs->slice_height = fs->slice_height/f->num_v_slices - fs->slice_y;

            if((unsigned)fs->slice_width > f->width || (unsigned)fs->slice_height > f->height)

                return -1;

            if(    (unsigned)fs->slice_x + (uint64_t)fs->slice_width  > f->width

                || (unsigned)fs->slice_y + (uint64_t)fs->slice_height > f->height)

                return -1;

        }



        for(i=0; i<f->plane_count; i++){

            PlaneContext * const p= &fs->plane[i];



            if(f->version >= 2){

                int idx=get_symbol(c, state, 0);

                if(idx > (unsigned)f->quant_table_count){

                    av_log(f->avctx, AV_LOG_ERROR, "quant_table_index out of range\n");

                    return -1;

                }

                p->quant_table_index= idx;

                memcpy(p->quant_table, f->quant_tables[idx], sizeof(p->quant_table));

                context_count= f->context_count[idx];

            }else{

                memcpy(p->quant_table, f->quant_table, sizeof(p->quant_table));

            }



            if(p->context_count < context_count){

                av_freep(&p->state);

                av_freep(&p->vlc_state);

            }

            p->context_count= context_count;

        }

    }



    return 0;

}

static int FUNC_0(FFV1Context *VAR_0){

    uint8_t state[CONTEXT_SIZE];

    int VAR_1, VAR_2, VAR_3;

    RangeCoder * const c= &VAR_0->slice_context[0]->c;



    memset(state, 128, sizeof(state));



    if(VAR_0->version < 2){

        VAR_0->version= get_symbol(c, state, 0);

        VAR_0->ac= VAR_0->avctx->coder_type= get_symbol(c, state, 0);

        if(VAR_0->ac>1){

            for(VAR_1=1; VAR_1<256; VAR_1++){

                VAR_0->state_transition[VAR_1]= get_symbol(c, state, 1) + c->one_state[VAR_1];

            }

        }

        VAR_0->colorspace= get_symbol(c, state, 0); 

        if(VAR_0->version>0)

            VAR_0->avctx->bits_per_raw_sample= get_symbol(c, state, 0);

        VAR_0->chroma_planes= get_rac(c, state);

        VAR_0->chroma_h_shift= get_symbol(c, state, 0);

        VAR_0->chroma_v_shift= get_symbol(c, state, 0);

        VAR_0->transparency= get_rac(c, state);

        VAR_0->plane_count= 2 + VAR_0->transparency;

    }



    if(VAR_0->colorspace==0){

        if(!VAR_0->transparency && !VAR_0->chroma_planes){

            if (VAR_0->avctx->bits_per_raw_sample<=8)

                VAR_0->avctx->pix_fmt= PIX_FMT_GRAY8;

            else

                VAR_0->avctx->pix_fmt= PIX_FMT_GRAY16;

        }else if(VAR_0->avctx->bits_per_raw_sample<=8 && !VAR_0->transparency){

            switch(16*VAR_0->chroma_h_shift + VAR_0->chroma_v_shift){

            case 0x00: VAR_0->avctx->pix_fmt= PIX_FMT_YUV444P; break;

            case 0x01: VAR_0->avctx->pix_fmt= PIX_FMT_YUV440P; break;

            case 0x10: VAR_0->avctx->pix_fmt= PIX_FMT_YUV422P; break;

            case 0x11: VAR_0->avctx->pix_fmt= PIX_FMT_YUV420P; break;

            case 0x20: VAR_0->avctx->pix_fmt= PIX_FMT_YUV411P; break;

            case 0x22: VAR_0->avctx->pix_fmt= PIX_FMT_YUV410P; break;

            default:

                av_log(VAR_0->avctx, AV_LOG_ERROR, "format not supported\n");

                return -1;

            }

        }else if(VAR_0->avctx->bits_per_raw_sample<=8 && VAR_0->transparency){

            switch(16*VAR_0->chroma_h_shift + VAR_0->chroma_v_shift){

            case 0x00: VAR_0->avctx->pix_fmt= PIX_FMT_YUVA444P; break;

            case 0x11: VAR_0->avctx->pix_fmt= PIX_FMT_YUVA420P; break;

            default:

                av_log(VAR_0->avctx, AV_LOG_ERROR, "format not supported\n");

                return -1;

            }

        }else if(VAR_0->avctx->bits_per_raw_sample==9) {

            VAR_0->packed_at_lsb=1;

            switch(16*VAR_0->chroma_h_shift + VAR_0->chroma_v_shift){

            case 0x00: VAR_0->avctx->pix_fmt= PIX_FMT_YUV444P9; break;

            case 0x10: VAR_0->avctx->pix_fmt= PIX_FMT_YUV422P9; break;

            case 0x11: VAR_0->avctx->pix_fmt= PIX_FMT_YUV420P9; break;

            default:

                av_log(VAR_0->avctx, AV_LOG_ERROR, "format not supported\n");

                return -1;

            }

        }else if(VAR_0->avctx->bits_per_raw_sample==10) {

            VAR_0->packed_at_lsb=1;

            switch(16*VAR_0->chroma_h_shift + VAR_0->chroma_v_shift){

            case 0x00: VAR_0->avctx->pix_fmt= PIX_FMT_YUV444P10; break;

            case 0x10: VAR_0->avctx->pix_fmt= PIX_FMT_YUV422P10; break;

            case 0x11: VAR_0->avctx->pix_fmt= PIX_FMT_YUV420P10; break;

            default:

                av_log(VAR_0->avctx, AV_LOG_ERROR, "format not supported\n");

                return -1;

            }

        }else {

            switch(16*VAR_0->chroma_h_shift + VAR_0->chroma_v_shift){

            case 0x00: VAR_0->avctx->pix_fmt= PIX_FMT_YUV444P16; break;

            case 0x10: VAR_0->avctx->pix_fmt= PIX_FMT_YUV422P16; break;

            case 0x11: VAR_0->avctx->pix_fmt= PIX_FMT_YUV420P16; break;

            default:

                av_log(VAR_0->avctx, AV_LOG_ERROR, "format not supported\n");

                return -1;

            }

        }

    }else if(VAR_0->colorspace==1){

        if(VAR_0->chroma_h_shift || VAR_0->chroma_v_shift){

            av_log(VAR_0->avctx, AV_LOG_ERROR, "chroma subsampling not supported in this colorspace\n");

            return -1;

        }

        if(VAR_0->transparency) VAR_0->avctx->pix_fmt= PIX_FMT_RGB32;

        else                VAR_0->avctx->pix_fmt= PIX_FMT_0RGB32;

    }else{

        av_log(VAR_0->avctx, AV_LOG_ERROR, "colorspace not supported\n");

        return -1;

    }





    if(VAR_0->version < 2){

        VAR_3= read_quant_tables(c, VAR_0->quant_table);

        if(VAR_3 < 0){

                av_log(VAR_0->avctx, AV_LOG_ERROR, "read_quant_table error\n");

                return -1;

        }

    }else{

        VAR_0->slice_count= get_symbol(c, state, 0);

        if(VAR_0->slice_count > (unsigned)MAX_SLICES)

            return -1;

    }



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

        FFV1Context *fs= VAR_0->slice_context[VAR_2];

        fs->ac= VAR_0->ac;

        fs->packed_at_lsb= VAR_0->packed_at_lsb;



        if(VAR_0->version >= 2){

            fs->slice_x     = get_symbol(c, state, 0)   *VAR_0->width ;

            fs->slice_y     = get_symbol(c, state, 0)   *VAR_0->height;

            fs->slice_width =(get_symbol(c, state, 0)+1)*VAR_0->width  + fs->slice_x;

            fs->slice_height=(get_symbol(c, state, 0)+1)*VAR_0->height + fs->slice_y;



            fs->slice_x /= VAR_0->num_h_slices;

            fs->slice_y /= VAR_0->num_v_slices;

            fs->slice_width  = fs->slice_width /VAR_0->num_h_slices - fs->slice_x;

            fs->slice_height = fs->slice_height/VAR_0->num_v_slices - fs->slice_y;

            if((unsigned)fs->slice_width > VAR_0->width || (unsigned)fs->slice_height > VAR_0->height)

                return -1;

            if(    (unsigned)fs->slice_x + (uint64_t)fs->slice_width  > VAR_0->width

                || (unsigned)fs->slice_y + (uint64_t)fs->slice_height > VAR_0->height)

                return -1;

        }



        for(VAR_1=0; VAR_1<VAR_0->plane_count; VAR_1++){

            PlaneContext * const p= &fs->plane[VAR_1];



            if(VAR_0->version >= 2){

                int idx=get_symbol(c, state, 0);

                if(idx > (unsigned)VAR_0->quant_table_count){

                    av_log(VAR_0->avctx, AV_LOG_ERROR, "quant_table_index out of range\n");

                    return -1;

                }

                p->quant_table_index= idx;

                memcpy(p->quant_table, VAR_0->quant_tables[idx], sizeof(p->quant_table));

                VAR_3= VAR_0->VAR_3[idx];

            }else{

                memcpy(p->quant_table, VAR_0->quant_table, sizeof(p->quant_table));

            }



            if(p->VAR_3 < VAR_3){

                av_freep(&p->state);

                av_freep(&p->vlc_state);

            }

            p->VAR_3= VAR_3;

        }

    }



    return 0;

}

static int FUNC_0(FFV1Context *VAR_0){ uint8_t state[CONTEXT_SIZE]; int VAR_1, VAR_2, VAR_3; RangeCoder * const c= &VAR_0->slice_context[0]->c; memset(state, 128, sizeof(state)); if(VAR_0->version < 2){ VAR_0->version= get_symbol(c, state, 0); VAR_0->ac= VAR_0->avctx->coder_type= get_symbol(c, state, 0); if(VAR_0->ac>1){ for(VAR_1=1; VAR_1<256; VAR_1++){ VAR_0->state_transition[VAR_1]= get_symbol(c, state, 1) + c->one_state[VAR_1]; } } VAR_0->colorspace= get_symbol(c, state, 0); if(VAR_0->version>0)
VAR_0->avctx->bits_per_raw_sample= get_symbol(c, state, 0); VAR_0->chroma_planes= get_rac(c, state); VAR_0->chroma_h_shift= get_symbol(c, state, 0); VAR_0->chroma_v_shift= get_symbol(c, state, 0); VAR_0->transparency= get_rac(c, state); VAR_0->plane_count= 2 + VAR_0->transparency; } if(VAR_0->colorspace==0){ if(!VAR_0->transparency && !VAR_0->chroma_planes){ if (VAR_0->avctx->bits_per_raw_sample<=8)
VAR_0->avctx->pix_fmt= PIX_FMT_GRAY8; else
VAR_0->avctx->pix_fmt= PIX_FMT_GRAY16; }else if(VAR_0->avctx->bits_per_raw_sample<=8 && !VAR_0->transparency){ switch(16*VAR_0->chroma_h_shift + VAR_0->chroma_v_shift){ case 0x00: VAR_0->avctx->pix_fmt= PIX_FMT_YUV444P; break; case 0x01: VAR_0->avctx->pix_fmt= PIX_FMT_YUV440P; break; case 0x10: VAR_0->avctx->pix_fmt= PIX_FMT_YUV422P; break; case 0x11: VAR_0->avctx->pix_fmt= PIX_FMT_YUV420P; break; case 0x20: VAR_0->avctx->pix_fmt= PIX_FMT_YUV411P; break; case 0x22: VAR_0->avctx->pix_fmt= PIX_FMT_YUV410P; break; default:
av_log(VAR_0->avctx, AV_LOG_ERROR, "format not supported\n"); return -1; } }else if(VAR_0->avctx->bits_per_raw_sample<=8 && VAR_0->transparency){ switch(16*VAR_0->chroma_h_shift + VAR_0->chroma_v_shift){ case 0x00: VAR_0->avctx->pix_fmt= PIX_FMT_YUVA444P; break; case 0x11: VAR_0->avctx->pix_fmt= PIX_FMT_YUVA420P; break; default:
av_log(VAR_0->avctx, AV_LOG_ERROR, "format not supported\n"); return -1; } }else if(VAR_0->avctx->bits_per_raw_sample==9) { VAR_0->packed_at_lsb=1; switch(16*VAR_0->chroma_h_shift + VAR_0->chroma_v_shift){ case 0x00: VAR_0->avctx->pix_fmt= PIX_FMT_YUV444P9; break; case 0x10: VAR_0->avctx->pix_fmt= PIX_FMT_YUV422P9; break; case 0x11: VAR_0->avctx->pix_fmt= PIX_FMT_YUV420P9; break; default:
av_log(VAR_0->avctx, AV_LOG_ERROR, "format not supported\n"); return -1; } }else if(VAR_0->avctx->bits_per_raw_sample==10) { VAR_0->packed_at_lsb=1; switch(16*VAR_0->chroma_h_shift + VAR_0->chroma_v_shift){ case 0x00: VAR_0->avctx->pix_fmt= PIX_FMT_YUV444P10; break; case 0x10: VAR_0->avctx->pix_fmt= PIX_FMT_YUV422P10; break; case 0x11: VAR_0->avctx->pix_fmt= PIX_FMT_YUV420P10; break; default:
av_log(VAR_0->avctx, AV_LOG_ERROR, "format not supported\n"); return -1; } }else { switch(16*VAR_0->chroma_h_shift + VAR_0->chroma_v_shift){ case 0x00: VAR_0->avctx->pix_fmt= PIX_FMT_YUV444P16; break; case 0x10: VAR_0->avctx->pix_fmt= PIX_FMT_YUV422P16; break; case 0x11: VAR_0->avctx->pix_fmt= PIX_FMT_YUV420P16; break; default:
av_log(VAR_0->avctx, AV_LOG_ERROR, "format not supported\n"); return -1; } } }else if(VAR_0->colorspace==1){ if(VAR_0->chroma_h_shift || VAR_0->chroma_v_shift){ av_log(VAR_0->avctx, AV_LOG_ERROR, "chroma subsampling not supported in this colorspace\n"); return -1; } if(VAR_0->transparency) VAR_0->avctx->pix_fmt= PIX_FMT_RGB32; else                VAR_0->avctx->pix_fmt= PIX_FMT_0RGB32; }else{ av_log(VAR_0->avctx, AV_LOG_ERROR, "colorspace not supported\n"); return -1; } if(VAR_0->version < 2){ VAR_3= read_quant_tables(c, VAR_0->quant_table); if(VAR_3 < 0){ av_log(VAR_0->avctx, AV_LOG_ERROR, "read_quant_table error\n"); return -1; } }else{ VAR_0->slice_count= get_symbol(c, state, 0); if(VAR_0->slice_count > (unsigned)MAX_SLICES)
return -1; } for(VAR_2=0; VAR_2<VAR_0->slice_count; VAR_2++){ FFV1Context *fs= VAR_0->slice_context[VAR_2]; fs->ac= VAR_0->ac; fs->packed_at_lsb= VAR_0->packed_at_lsb; if(VAR_0->version >= 2){ fs->slice_x     = get_symbol(c, state, 0)   *VAR_0->width ; fs->slice_y     = get_symbol(c, state, 0)   *VAR_0->height; fs->slice_width =(get_symbol(c, state, 0)+1)*VAR_0->width  + fs->slice_x; fs->slice_height=(get_symbol(c, state, 0)+1)*VAR_0->height + fs->slice_y; fs->slice_x /= VAR_0->num_h_slices; fs->slice_y /= VAR_0->num_v_slices; fs->slice_width  = fs->slice_width /VAR_0->num_h_slices - fs->slice_x; fs->slice_height = fs->slice_height/VAR_0->num_v_slices - fs->slice_y; if((unsigned)fs->slice_width > VAR_0->width || (unsigned)fs->slice_height > VAR_0->height)
return -1; if(    (unsigned)fs->slice_x + (uint64_t)fs->slice_width  > VAR_0->width
|| (unsigned)fs->slice_y + (uint64_t)fs->slice_height > VAR_0->height)
return -1; } for(VAR_1=0; VAR_1<VAR_0->plane_count; VAR_1++){ PlaneContext * const p= &fs->plane[VAR_1]; if(VAR_0->version >= 2){ int idx=get_symbol(c, state, 0); if(idx > (unsigned)VAR_0->quant_table_count){ av_log(VAR_0->avctx, AV_LOG_ERROR, "quant_table_index out of range\n"); return -1; } p->quant_table_index= idx; memcpy(p->quant_table, VAR_0->quant_tables[idx], sizeof(p->quant_table)); VAR_3= VAR_0->VAR_3[idx]; }else{ memcpy(p->quant_table, VAR_0->quant_table, sizeof(p->quant_table)); } if(p->VAR_3 < VAR_3){ av_freep(&p->state); av_freep(&p->vlc_state); } p->VAR_3= VAR_3; } } return 0; }