int last_spatial_decomposition_type;
int temporal_decomposition_type;
int spatial_decomposition_count;
+ int last_spatial_decomposition_count;
int temporal_decomposition_count;
int max_ref_frames;
int ref_frames;
for (i = buf->data_count - 1; i >= 0; i--)
{
- assert(buf->data_stack[i]);
av_freep(&buf->data_stack[i]);
}
- assert(buf->data_stack);
av_freep(&buf->data_stack);
- assert(buf->line);
av_freep(&buf->line);
}
int plane_index, level, orientation;
for(plane_index=0; plane_index<3; plane_index++){
- for(level=0; level<s->spatial_decomposition_count; level++){
+ for(level=0; level<MAX_DECOMPOSITIONS; level++){
for(orientation=level ? 1:0; orientation<4; orientation++){
memset(s->plane[plane_index].band[level][orientation].state, MID_STATE, sizeof(s->plane[plane_index].band[level][orientation].state));
}
}
}
+static void encode_qlogs(SnowContext *s){
+ int plane_index, level, orientation;
+
+ for(plane_index=0; plane_index<2; plane_index++){
+ for(level=0; level<s->spatial_decomposition_count; level++){
+ for(orientation=level ? 1:0; orientation<4; orientation++){
+ if(orientation==2) continue;
+ put_symbol(&s->c, s->header_state, s->plane[plane_index].band[level][orientation].qlog, 1);
+ }
+ }
+ }
+}
+
static void encode_header(SnowContext *s){
- int plane_index, level, orientation, i;
+ int plane_index, i;
uint8_t kstate[32];
memset(kstate, MID_STATE, sizeof(kstate));
// put_rac(&s->c, s->header_state, s->rate_scalability);
put_symbol(&s->c, s->header_state, s->max_ref_frames-1, 0);
- for(plane_index=0; plane_index<2; plane_index++){
- for(level=0; level<s->spatial_decomposition_count; level++){
- for(orientation=level ? 1:0; orientation<4; orientation++){
- if(orientation==2) continue;
- put_symbol(&s->c, s->header_state, s->plane[plane_index].band[level][orientation].qlog, 1);
- }
- }
- }
+ encode_qlogs(s);
}
if(!s->keyframe){
update_mc |= p->last_diag_mc != p->diag_mc;
update_mc |= !!memcmp(p->last_hcoeff, p->hcoeff, sizeof(p->hcoeff));
}
- if(!s->always_reset)
- put_rac(&s->c, s->header_state, update_mc);
+ put_rac(&s->c, s->header_state, update_mc);
if(update_mc){
for(plane_index=0; plane_index<2; plane_index++){
Plane *p= &s->plane[plane_index];
memcpy(p->last_hcoeff, p->hcoeff, sizeof(p->hcoeff));
}
}
+ if(s->last_spatial_decomposition_count != s->spatial_decomposition_count){
+ put_rac(&s->c, s->header_state, 1);
+ put_symbol(&s->c, s->header_state, s->spatial_decomposition_count, 0);
+ encode_qlogs(s);
+ }else
+ put_rac(&s->c, s->header_state, 0);
}
put_symbol(&s->c, s->header_state, s->spatial_decomposition_type - s->last_spatial_decomposition_type, 1);
s->last_qbias = s->qbias;
s->last_mv_scale = s->mv_scale;
s->last_block_max_depth = s->block_max_depth;
+ s->last_spatial_decomposition_count= s->spatial_decomposition_count;
}
-static int decode_header(SnowContext *s){
+static void decode_qlogs(SnowContext *s){
int plane_index, level, orientation;
+
+ for(plane_index=0; plane_index<3; plane_index++){
+ for(level=0; level<s->spatial_decomposition_count; level++){
+ for(orientation=level ? 1:0; orientation<4; orientation++){
+ int q;
+ if (plane_index==2) q= s->plane[1].band[level][orientation].qlog;
+ else if(orientation==2) q= s->plane[plane_index].band[level][1].qlog;
+ else q= get_symbol(&s->c, s->header_state, 1);
+ s->plane[plane_index].band[level][orientation].qlog= q;
+ }
+ }
+ }
+}
+
+static int decode_header(SnowContext *s){
+ int plane_index;
uint8_t kstate[32];
memset(kstate, MID_STATE, sizeof(kstate));
// s->rate_scalability= get_rac(&s->c, s->header_state);
s->max_ref_frames= get_symbol(&s->c, s->header_state, 0)+1;
- for(plane_index=0; plane_index<3; plane_index++){
- for(level=0; level<s->spatial_decomposition_count; level++){
- for(orientation=level ? 1:0; orientation<4; orientation++){
- int q;
- if (plane_index==2) q= s->plane[1].band[level][orientation].qlog;
- else if(orientation==2) q= s->plane[plane_index].band[level][1].qlog;
- else q= get_symbol(&s->c, s->header_state, 1);
- s->plane[plane_index].band[level][orientation].qlog= q;
- }
- }
- }
+ decode_qlogs(s);
}
if(!s->keyframe){
- if(s->always_reset || get_rac(&s->c, s->header_state)){
+ if(get_rac(&s->c, s->header_state)){
for(plane_index=0; plane_index<2; plane_index++){
int htaps, i, sum=0, absum=0;
Plane *p= &s->plane[plane_index];
s->plane[2].htaps = s->plane[1].htaps;
memcpy(s->plane[2].hcoeff, s->plane[1].hcoeff, sizeof(s->plane[1].hcoeff));
}
+ if(get_rac(&s->c, s->header_state)){
+ s->spatial_decomposition_count= get_symbol(&s->c, s->header_state, 0);
+ decode_qlogs(s);
+ }
}
s->spatial_decomposition_type+= get_symbol(&s->c, s->header_state, 1);
static int common_init(AVCodecContext *avctx){
SnowContext *s = avctx->priv_data;
int width, height;
- int level, orientation, plane_index, dec;
int i, j;
s->avctx= avctx;
if(!qexp[0])
init_qexp();
- dec= s->spatial_decomposition_count= 5;
- s->spatial_decomposition_type= avctx->prediction_method; //FIXME add decorrelator type r transform_type
-
- s->chroma_h_shift= 1; //FIXME XXX
- s->chroma_v_shift= 1;
-
// dec += FFMAX(s->chroma_h_shift, s->chroma_v_shift);
width= s->avctx->width;
s->spatial_idwt_buffer= av_mallocz(width*height*sizeof(IDWTELEM));
s->spatial_dwt_buffer= av_mallocz(width*height*sizeof(DWTELEM)); //FIXME this doesnt belong here
- s->mv_scale= (s->avctx->flags & CODEC_FLAG_QPEL) ? 2 : 4;
- s->block_max_depth= (s->avctx->flags & CODEC_FLAG_4MV) ? 1 : 0;
+ for(i=0; i<MAX_REF_FRAMES; i++)
+ for(j=0; j<MAX_REF_FRAMES; j++)
+ scale_mv_ref[i][j] = 256*(i+1)/(j+1);
+
+ s->avctx->get_buffer(s->avctx, &s->mconly_picture);
+
+ return 0;
+}
+
+static int common_init_after_header(AVCodecContext *avctx){
+ SnowContext *s = avctx->priv_data;
+ int plane_index, level, orientation;
for(plane_index=0; plane_index<3; plane_index++){
int w= s->avctx->width;
s->plane[plane_index].width = w;
s->plane[plane_index].height= h;
- s->plane[plane_index].diag_mc= 1;
- s->plane[plane_index].htaps= 6;
- s->plane[plane_index].hcoeff[0]= 40;
- s->plane[plane_index].hcoeff[1]= -10;
- s->plane[plane_index].hcoeff[2]= 2;
- s->plane[plane_index].fast_mc= 1;
-
//av_log(NULL, AV_LOG_DEBUG, "%d %d\n", w, h);
for(level=s->spatial_decomposition_count-1; level>=0; level--){
for(orientation=level ? 1 : 0; orientation<4; orientation++){
if(level)
b->parent= &s->plane[plane_index].band[level-1][orientation];
+ //FIXME avoid this realloc
+ av_freep(&b->x_coeff);
b->x_coeff=av_mallocz(((b->width+1) * b->height+1)*sizeof(x_and_coeff));
}
w= (w+1)>>1;
}
}
- for(i=0; i<MAX_REF_FRAMES; i++)
- for(j=0; j<MAX_REF_FRAMES; j++)
- scale_mv_ref[i][j] = 256*(i+1)/(j+1);
-
- reset_contexts(s);
-/*
- width= s->width= avctx->width;
- height= s->height= avctx->height;
-
- assert(width && height);
-*/
- s->avctx->get_buffer(s->avctx, &s->mconly_picture);
-
return 0;
}
return -1;
}
+ s->spatial_decomposition_type= avctx->prediction_method; //FIXME add decorrelator type r transform_type
+
+ s->chroma_h_shift= 1; //FIXME XXX
+ s->chroma_v_shift= 1;
+
+ s->mv_scale = (avctx->flags & CODEC_FLAG_QPEL) ? 2 : 4;
+ s->block_max_depth= (avctx->flags & CODEC_FLAG_4MV ) ? 1 : 0;
+
+ for(plane_index=0; plane_index<3; plane_index++){
+ s->plane[plane_index].diag_mc= 1;
+ s->plane[plane_index].htaps= 6;
+ s->plane[plane_index].hcoeff[0]= 40;
+ s->plane[plane_index].hcoeff[1]= -10;
+ s->plane[plane_index].hcoeff[2]= 2;
+ s->plane[plane_index].fast_mc= 1;
+ }
+
common_init(avctx);
alloc_blocks(s);
}
s->pass1_rc= !(avctx->flags & (CODEC_FLAG_QSCALE|CODEC_FLAG_PASS2));
- for(plane_index=0; plane_index<3; plane_index++){
- calculate_vissual_weight(s, &s->plane[plane_index]);
- }
-
-
avctx->coded_frame= &s->current_picture;
switch(avctx->pix_fmt){
// case PIX_FMT_YUV444P:
redo_frame:
+ if(pict->pict_type == I_TYPE)
+ s->spatial_decomposition_count= 5;
+ else
+ s->spatial_decomposition_count= 5;
+
s->m.pict_type = pict->pict_type;
s->qbias= pict->pict_type == P_TYPE ? 2 : 0;
+ common_init_after_header(avctx);
+
+ if(s->last_spatial_decomposition_count != s->spatial_decomposition_count){
+ for(plane_index=0; plane_index<3; plane_index++){
+ calculate_vissual_weight(s, &s->plane[plane_index]);
+ }
+ }
+
encode_header(s);
s->m.misc_bits = 8*(s->c.bytestream - s->c.bytestream_start);
encode_blocks(s, 1);
static int decode_init(AVCodecContext *avctx)
{
SnowContext *s = avctx->priv_data;
- int block_size;
avctx->pix_fmt= PIX_FMT_YUV420P;
common_init(avctx);
- block_size = MB_SIZE >> s->block_max_depth;
-
- slice_buffer_init(&s->sb, s->plane[0].height, block_size + s->spatial_decomposition_count * 8 + 1, s->plane[0].width, s->spatial_idwt_buffer);
return 0;
}
ff_build_rac_states(c, 0.05*(1LL<<32), 256-8);
s->current_picture.pict_type= FF_I_TYPE; //FIXME I vs. P
- decode_header(s);
+ if(decode_header(s)<0)
+ return -1;
+ common_init_after_header(avctx);
+
+ // realloc slice buffer for the case that spatial_decomposition_count changed
+ slice_buffer_destroy(&s->sb);
+ slice_buffer_init(&s->sb, s->plane[0].height, (MB_SIZE >> s->block_max_depth) + s->spatial_decomposition_count * 8 + 1, s->plane[0].width, s->spatial_idwt_buffer);
for(plane_index=0; plane_index<3; plane_index++){
Plane *p= &s->plane[plane_index];