static int read_quant_table(RangeCoder *c, int16_t *quant_table, int scale){
    int v;
    int i=0;
    uint8_t state[CONTEXT_SIZE];
    memset(state, 128, sizeof(state));
    for(v=0; i<128 ; v++){
        int len= get_symbol(c, state, 0) + 1;
        if(len + i > 128) return -1;
        while(len--){
            quant_table[i] = scale*v;
            i++;
        }
    }
    for(i=1; i<128; i++){
        quant_table[256-i]= -quant_table[i];
    }
    quant_table[128]= -quant_table[127];
    return 2*v - 1;
}
['static int read_header(FFV1Context *f){\n    uint8_t state[CONTEXT_SIZE];\n    int i, context_count;\n    RangeCoder * const c= &f->c;\n    memset(state, 128, sizeof(state));\n    f->version= get_symbol(c, state, 0);\n    f->ac= f->avctx->coder_type= get_symbol(c, state, 0);\n    f->colorspace= get_symbol(c, state, 0);\n    get_rac(c, state);\n    f->chroma_h_shift= get_symbol(c, state, 0);\n    f->chroma_v_shift= get_symbol(c, state, 0);\n    get_rac(c, state);\n    f->plane_count= 2;\n    if(f->colorspace==0){\n        switch(16*f->chroma_h_shift + f->chroma_v_shift){\n        case 0x00: f->avctx->pix_fmt= PIX_FMT_YUV444P; break;\n        case 0x10: f->avctx->pix_fmt= PIX_FMT_YUV422P; break;\n        case 0x11: f->avctx->pix_fmt= PIX_FMT_YUV420P; break;\n        case 0x20: f->avctx->pix_fmt= PIX_FMT_YUV411P; break;\n        case 0x22: f->avctx->pix_fmt= PIX_FMT_YUV410P; break;\n        default:\n            av_log(f->avctx, AV_LOG_ERROR, "format not supported\\n");\n            return -1;\n        }\n    }else if(f->colorspace==1){\n        if(f->chroma_h_shift || f->chroma_v_shift){\n            av_log(f->avctx, AV_LOG_ERROR, "chroma subsampling not supported in this colorspace\\n");\n            return -1;\n        }\n        f->avctx->pix_fmt= PIX_FMT_RGB32;\n    }else{\n        av_log(f->avctx, AV_LOG_ERROR, "colorspace not supported\\n");\n        return -1;\n    }\n    context_count=1;\n    for(i=0; i<5; i++){\n        context_count*= read_quant_table(c, f->quant_table[i], context_count);\n        if(context_count < 0 || context_count > 32768){\n            av_log(f->avctx, AV_LOG_ERROR, "read_quant_table error\\n");\n            return -1;\n        }\n    }\n    context_count= (context_count+1)/2;\n    for(i=0; i<f->plane_count; i++){\n        PlaneContext * const p= &f->plane[i];\n        p->context_count= context_count;\n        if(f->ac){\n            if(!p->state) p->state= av_malloc(CONTEXT_SIZE*p->context_count*sizeof(uint8_t));\n        }else{\n            if(!p->vlc_state) p->vlc_state= av_malloc(p->context_count*sizeof(VlcState));\n        }\n    }\n    return 0;\n}', 'static int read_quant_table(RangeCoder *c, int16_t *quant_table, int scale){\n    int v;\n    int i=0;\n    uint8_t state[CONTEXT_SIZE];\n    memset(state, 128, sizeof(state));\n    for(v=0; i<128 ; v++){\n        int len= get_symbol(c, state, 0) + 1;\n        if(len + i > 128) return -1;\n        while(len--){\n            quant_table[i] = scale*v;\n            i++;\n        }\n    }\n    for(i=1; i<128; i++){\n        quant_table[256-i]= -quant_table[i];\n    }\n    quant_table[128]= -quant_table[127];\n    return 2*v - 1;\n}']