Mercurial > libavcodec.hg
comparison snow.c @ 5665:834f359e7257 libavcodec
perform init after reading the values needed for init
fixes decoding of files with spatial_decomposition_count!=5
author | michael |
---|---|
date | Sun, 09 Sep 2007 13:47:25 +0000 |
parents | 1f9e8321c2fb |
children | b5c137f3f53a |
comparison
equal
deleted
inserted
replaced
5664:1f9e8321c2fb | 5665:834f359e7257 |
---|---|
1654 | 1654 |
1655 static void reset_contexts(SnowContext *s){ //FIXME better initial contexts | 1655 static void reset_contexts(SnowContext *s){ //FIXME better initial contexts |
1656 int plane_index, level, orientation; | 1656 int plane_index, level, orientation; |
1657 | 1657 |
1658 for(plane_index=0; plane_index<3; plane_index++){ | 1658 for(plane_index=0; plane_index<3; plane_index++){ |
1659 for(level=0; level<s->spatial_decomposition_count; level++){ | 1659 for(level=0; level<MAX_DECOMPOSITIONS; level++){ |
1660 for(orientation=level ? 1:0; orientation<4; orientation++){ | 1660 for(orientation=level ? 1:0; orientation<4; orientation++){ |
1661 memset(s->plane[plane_index].band[level][orientation].state, MID_STATE, sizeof(s->plane[plane_index].band[level][orientation].state)); | 1661 memset(s->plane[plane_index].band[level][orientation].state, MID_STATE, sizeof(s->plane[plane_index].band[level][orientation].state)); |
1662 } | 1662 } |
1663 } | 1663 } |
1664 } | 1664 } |
3695 } | 3695 } |
3696 | 3696 |
3697 static int common_init(AVCodecContext *avctx){ | 3697 static int common_init(AVCodecContext *avctx){ |
3698 SnowContext *s = avctx->priv_data; | 3698 SnowContext *s = avctx->priv_data; |
3699 int width, height; | 3699 int width, height; |
3700 int level, orientation, plane_index; | |
3701 int i, j; | 3700 int i, j; |
3702 | 3701 |
3703 s->avctx= avctx; | 3702 s->avctx= avctx; |
3704 | 3703 |
3705 dsputil_init(&s->dsp, avctx); | 3704 dsputil_init(&s->dsp, avctx); |
3743 mcfh(8, 8) | 3742 mcfh(8, 8) |
3744 | 3743 |
3745 if(!qexp[0]) | 3744 if(!qexp[0]) |
3746 init_qexp(); | 3745 init_qexp(); |
3747 | 3746 |
3748 s->spatial_decomposition_count= 5; | |
3749 s->spatial_decomposition_type= avctx->prediction_method; //FIXME add decorrelator type r transform_type | |
3750 | |
3751 s->chroma_h_shift= 1; //FIXME XXX | |
3752 s->chroma_v_shift= 1; | |
3753 | |
3754 // dec += FFMAX(s->chroma_h_shift, s->chroma_v_shift); | 3747 // dec += FFMAX(s->chroma_h_shift, s->chroma_v_shift); |
3755 | 3748 |
3756 width= s->avctx->width; | 3749 width= s->avctx->width; |
3757 height= s->avctx->height; | 3750 height= s->avctx->height; |
3758 | 3751 |
3759 s->spatial_idwt_buffer= av_mallocz(width*height*sizeof(IDWTELEM)); | 3752 s->spatial_idwt_buffer= av_mallocz(width*height*sizeof(IDWTELEM)); |
3760 s->spatial_dwt_buffer= av_mallocz(width*height*sizeof(DWTELEM)); //FIXME this doesnt belong here | 3753 s->spatial_dwt_buffer= av_mallocz(width*height*sizeof(DWTELEM)); //FIXME this doesnt belong here |
3761 | 3754 |
3762 s->mv_scale= (s->avctx->flags & CODEC_FLAG_QPEL) ? 2 : 4; | 3755 for(i=0; i<MAX_REF_FRAMES; i++) |
3763 s->block_max_depth= (s->avctx->flags & CODEC_FLAG_4MV) ? 1 : 0; | 3756 for(j=0; j<MAX_REF_FRAMES; j++) |
3757 scale_mv_ref[i][j] = 256*(i+1)/(j+1); | |
3758 | |
3759 s->avctx->get_buffer(s->avctx, &s->mconly_picture); | |
3760 | |
3761 return 0; | |
3762 } | |
3763 | |
3764 static int common_init_after_header(AVCodecContext *avctx){ | |
3765 SnowContext *s = avctx->priv_data; | |
3766 int plane_index, level, orientation; | |
3764 | 3767 |
3765 for(plane_index=0; plane_index<3; plane_index++){ | 3768 for(plane_index=0; plane_index<3; plane_index++){ |
3766 int w= s->avctx->width; | 3769 int w= s->avctx->width; |
3767 int h= s->avctx->height; | 3770 int h= s->avctx->height; |
3768 | 3771 |
3770 w>>= s->chroma_h_shift; | 3773 w>>= s->chroma_h_shift; |
3771 h>>= s->chroma_v_shift; | 3774 h>>= s->chroma_v_shift; |
3772 } | 3775 } |
3773 s->plane[plane_index].width = w; | 3776 s->plane[plane_index].width = w; |
3774 s->plane[plane_index].height= h; | 3777 s->plane[plane_index].height= h; |
3775 | |
3776 s->plane[plane_index].diag_mc= 1; | |
3777 s->plane[plane_index].htaps= 6; | |
3778 s->plane[plane_index].hcoeff[0]= 40; | |
3779 s->plane[plane_index].hcoeff[1]= -10; | |
3780 s->plane[plane_index].hcoeff[2]= 2; | |
3781 s->plane[plane_index].fast_mc= 1; | |
3782 | 3778 |
3783 //av_log(NULL, AV_LOG_DEBUG, "%d %d\n", w, h); | 3779 //av_log(NULL, AV_LOG_DEBUG, "%d %d\n", w, h); |
3784 for(level=s->spatial_decomposition_count-1; level>=0; level--){ | 3780 for(level=s->spatial_decomposition_count-1; level>=0; level--){ |
3785 for(orientation=level ? 1 : 0; orientation<4; orientation++){ | 3781 for(orientation=level ? 1 : 0; orientation<4; orientation++){ |
3786 SubBand *b= &s->plane[plane_index].band[level][orientation]; | 3782 SubBand *b= &s->plane[plane_index].band[level][orientation]; |
3805 } | 3801 } |
3806 b->ibuf= s->spatial_idwt_buffer + (b->buf - s->spatial_dwt_buffer); | 3802 b->ibuf= s->spatial_idwt_buffer + (b->buf - s->spatial_dwt_buffer); |
3807 | 3803 |
3808 if(level) | 3804 if(level) |
3809 b->parent= &s->plane[plane_index].band[level-1][orientation]; | 3805 b->parent= &s->plane[plane_index].band[level-1][orientation]; |
3806 //FIXME avoid this realloc | |
3807 av_freep(&b->x_coeff); | |
3810 b->x_coeff=av_mallocz(((b->width+1) * b->height+1)*sizeof(x_and_coeff)); | 3808 b->x_coeff=av_mallocz(((b->width+1) * b->height+1)*sizeof(x_and_coeff)); |
3811 } | 3809 } |
3812 w= (w+1)>>1; | 3810 w= (w+1)>>1; |
3813 h= (h+1)>>1; | 3811 h= (h+1)>>1; |
3814 } | 3812 } |
3815 } | 3813 } |
3816 | |
3817 for(i=0; i<MAX_REF_FRAMES; i++) | |
3818 for(j=0; j<MAX_REF_FRAMES; j++) | |
3819 scale_mv_ref[i][j] = 256*(i+1)/(j+1); | |
3820 | |
3821 /* | |
3822 width= s->width= avctx->width; | |
3823 height= s->height= avctx->height; | |
3824 | |
3825 assert(width && height); | |
3826 */ | |
3827 s->avctx->get_buffer(s->avctx, &s->mconly_picture); | |
3828 | 3814 |
3829 return 0; | 3815 return 0; |
3830 } | 3816 } |
3831 | 3817 |
3832 static int qscale2qlog(int qscale){ | 3818 static int qscale2qlog(int qscale){ |
3929 && avctx->global_quality == 0){ | 3915 && avctx->global_quality == 0){ |
3930 av_log(avctx, AV_LOG_ERROR, "the 9/7 wavelet is incompatible with lossless mode\n"); | 3916 av_log(avctx, AV_LOG_ERROR, "the 9/7 wavelet is incompatible with lossless mode\n"); |
3931 return -1; | 3917 return -1; |
3932 } | 3918 } |
3933 | 3919 |
3920 s->spatial_decomposition_count= 5; | |
3921 s->spatial_decomposition_type= avctx->prediction_method; //FIXME add decorrelator type r transform_type | |
3922 | |
3923 s->chroma_h_shift= 1; //FIXME XXX | |
3924 s->chroma_v_shift= 1; | |
3925 | |
3926 s->mv_scale = (avctx->flags & CODEC_FLAG_QPEL) ? 2 : 4; | |
3927 s->block_max_depth= (avctx->flags & CODEC_FLAG_4MV ) ? 1 : 0; | |
3928 | |
3929 for(plane_index=0; plane_index<3; plane_index++){ | |
3930 s->plane[plane_index].diag_mc= 1; | |
3931 s->plane[plane_index].htaps= 6; | |
3932 s->plane[plane_index].hcoeff[0]= 40; | |
3933 s->plane[plane_index].hcoeff[1]= -10; | |
3934 s->plane[plane_index].hcoeff[2]= 2; | |
3935 s->plane[plane_index].fast_mc= 1; | |
3936 } | |
3937 | |
3934 common_init(avctx); | 3938 common_init(avctx); |
3939 common_init_after_header(avctx); | |
3935 alloc_blocks(s); | 3940 alloc_blocks(s); |
3936 | 3941 |
3937 s->version=0; | 3942 s->version=0; |
3938 | 3943 |
3939 s->m.avctx = avctx; | 3944 s->m.avctx = avctx; |
4412 ff_init_range_decoder(c, buf, buf_size); | 4417 ff_init_range_decoder(c, buf, buf_size); |
4413 ff_build_rac_states(c, 0.05*(1LL<<32), 256-8); | 4418 ff_build_rac_states(c, 0.05*(1LL<<32), 256-8); |
4414 | 4419 |
4415 s->current_picture.pict_type= FF_I_TYPE; //FIXME I vs. P | 4420 s->current_picture.pict_type= FF_I_TYPE; //FIXME I vs. P |
4416 decode_header(s); | 4421 decode_header(s); |
4422 common_init_after_header(avctx); | |
4417 | 4423 |
4418 // realloc slice buffer for the case that spatial_decomposition_count changed | 4424 // realloc slice buffer for the case that spatial_decomposition_count changed |
4419 slice_buffer_destroy(&s->sb); | 4425 slice_buffer_destroy(&s->sb); |
4420 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); | 4426 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); |
4421 | 4427 |