int log2_threshold, level, orientation, plane_index;
int level, orientation, plane_index;
static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size){    SnowContext *s = avctx->priv_data;    CABACContext * const c= &s->c;    const int width= s->avctx->width;    const int height= s->avctx->height;    int bytes_read;    AVFrame *picture = data;    int log2_threshold, level, orientation, plane_index;        /* no supplementary picture */    if (buf_size == 0)        return 0;    ff_init_cabac_decoder(c, buf, buf_size);    ff_init_cabac_states(c, ff_h264_lps_range, ff_h264_mps_state, ff_h264_lps_state, 64);    memset(s->header_state, 0, sizeof(s->header_state));    s->current_picture.pict_type= FF_I_TYPE; //FIXME I vs. P    decode_header(s);    if(!s->block) alloc_blocks(s);    frame_start(s);    //keyframe flag dupliaction mess FIXME    if(avctx->debug&FF_DEBUG_PICT_INFO)        av_log(avctx, AV_LOG_ERROR, "keyframe:%d qlog:%d\n", s->keyframe, s->qlog);        decode_blocks(s);    for(plane_index=0; plane_index<3; plane_index++){        Plane *p= &s->plane[plane_index];        int w= p->width;        int h= p->height;        int x, y;        if(s->avctx->debug&2048){        memset(s->spatial_dwt_buffer, 0, sizeof(DWTELEM)*w*h);        predict_plane(s, s->spatial_dwt_buffer, plane_index, 1);        for(y=0; y<h; y++){            for(x=0; x<w; x++){                int v= (s->spatial_dwt_buffer[y*w + x]+128)>>8;                if(v&(~255)) v= ~(v>>31);                s->mconly_picture.data[plane_index][y*s->mconly_picture.linesize[plane_index] + x]= v;            }        }}        for(level=0; level<s->spatial_decomposition_count; level++){            for(orientation=level ? 1 : 0; orientation<4; orientation++){                SubBand *b= &p->band[level][orientation];                decode_subband(s, b, b->buf, b->parent ? b->parent->buf : NULL, b->stride, orientation);                if(orientation==0){                    correlate(s, b, b->buf, b->stride, 1, 0);                    dequantize(s, b, b->buf, b->stride);                    assert(b->buf == s->spatial_dwt_buffer);                }            }        }        ff_spatial_idwt(s->spatial_dwt_buffer, w, h, w, s->spatial_decomposition_type, s->spatial_decomposition_count);        if(s->qlog == LOSSLESS_QLOG){            for(y=0; y<h; y++){                for(x=0; x<w; x++){                    s->spatial_dwt_buffer[y*w + x]<<=8;                }            }        }        predict_plane(s, s->spatial_dwt_buffer, plane_index, 1);        //FIXME optimize        for(y=0; y<h; y++){            for(x=0; x<w; x++){                int v= (s->spatial_dwt_buffer[y*w + x]+128)>>8;                if(v&(~255)) v= ~(v>>31);                s->current_picture.data[plane_index][y*s->current_picture.linesize[plane_index] + x]= v;            }        }    }                emms_c();    if(s->last_picture.data[0])        avctx->release_buffer(avctx, &s->last_picture);if(!(s->avctx->debug&2048))            *picture= s->current_picture;else    *picture= s->mconly_picture;        *data_size = sizeof(AVFrame);        bytes_read= get_cabac_terminate(c);    if(bytes_read ==0) av_log(s->avctx, AV_LOG_ERROR, "error at end of frame\n");    return bytes_read;}