Mercurial > libavcodec.hg
comparison snow.c @ 5633:873ea64637d9 libavcodec
code to do halfpel interpolation per frame (unfinished and under ifdef but it
should be faster when its finished)
author | michael |
---|---|
date | Wed, 05 Sep 2007 00:06:34 +0000 |
parents | a920d9b58f19 |
children | 9960732c7d7b |
comparison
equal
deleted
inserted
replaced
5632:cdc40afde7b8 | 5633:873ea64637d9 |
---|---|
430 DSPContext dsp; | 430 DSPContext dsp; |
431 AVFrame new_picture; | 431 AVFrame new_picture; |
432 AVFrame input_picture; ///< new_picture with the internal linesizes | 432 AVFrame input_picture; ///< new_picture with the internal linesizes |
433 AVFrame current_picture; | 433 AVFrame current_picture; |
434 AVFrame last_picture[MAX_REF_FRAMES]; | 434 AVFrame last_picture[MAX_REF_FRAMES]; |
435 uint8_t *halfpel_plane[MAX_REF_FRAMES][4][4]; | |
435 AVFrame mconly_picture; | 436 AVFrame mconly_picture; |
436 // uint8_t q_context[16]; | 437 // uint8_t q_context[16]; |
437 uint8_t header_state[32]; | 438 uint8_t header_state[32]; |
438 uint8_t block_state[128 + 32*128]; | 439 uint8_t block_state[128 + 32*128]; |
439 int keyframe; | 440 int keyframe; |
3813 } | 3814 } |
3814 | 3815 |
3815 return 0; | 3816 return 0; |
3816 } | 3817 } |
3817 | 3818 |
3819 static void halfpel_interpol(SnowContext *s, uint8_t *halfpel[4][4], AVFrame *frame){ | |
3820 int p,x,y; | |
3821 | |
3822 assert(!(s->avctx->flags & CODEC_FLAG_EMU_EDGE)); | |
3823 | |
3824 for(p=0; p<3; p++){ | |
3825 int is_chroma= !!p; | |
3826 int w= s->avctx->width >>is_chroma; | |
3827 int h= s->avctx->height >>is_chroma; | |
3828 int ls= frame->linesize[p]; | |
3829 uint8_t *src= frame->data[p]; | |
3830 | |
3831 halfpel[1][p]= (uint8_t*)av_malloc(ls * (h+2*EDGE_WIDTH)) + EDGE_WIDTH*(1+ls); | |
3832 halfpel[2][p]= (uint8_t*)av_malloc(ls * (h+2*EDGE_WIDTH)) + EDGE_WIDTH*(1+ls); | |
3833 halfpel[3][p]= (uint8_t*)av_malloc(ls * (h+2*EDGE_WIDTH)) + EDGE_WIDTH*(1+ls); | |
3834 | |
3835 halfpel[0][p]= src; | |
3836 for(y=0; y<h; y++){ | |
3837 for(x=0; x<w; x++){ | |
3838 int i= y*ls + x; | |
3839 | |
3840 halfpel[1][p][i]= (20*(src[i] + src[i+1]) - 5*(src[i-1] + src[i+2]) + (src[i-2] + src[i+3]) + 16 )>>5; | |
3841 } | |
3842 } | |
3843 for(y=0; y<h; y++){ | |
3844 for(x=0; x<w; x++){ | |
3845 int i= y*ls + x; | |
3846 | |
3847 halfpel[2][p][i]= (20*(src[i] + src[i+ls]) - 5*(src[i-ls] + src[i+2*ls]) + (src[i-2*ls] + src[i+3*ls]) + 16 )>>5; | |
3848 } | |
3849 } | |
3850 src= halfpel[1][p]; | |
3851 for(y=0; y<h; y++){ | |
3852 for(x=0; x<w; x++){ | |
3853 int i= y*ls + x; | |
3854 | |
3855 halfpel[3][p][i]= (20*(src[i] + src[i+ls]) - 5*(src[i-ls] + src[i+2*ls]) + (src[i-2*ls] + src[i+3*ls]) + 16 )>>5; | |
3856 } | |
3857 } | |
3858 | |
3859 //FIXME border! | |
3860 } | |
3861 } | |
3862 | |
3818 static int frame_start(SnowContext *s){ | 3863 static int frame_start(SnowContext *s){ |
3819 AVFrame tmp; | 3864 AVFrame tmp; |
3820 int w= s->avctx->width; //FIXME round up to x16 ? | 3865 int w= s->avctx->width; //FIXME round up to x16 ? |
3821 int h= s->avctx->height; | 3866 int h= s->avctx->height; |
3822 | 3867 |
3826 draw_edges(s->current_picture.data[2], s->current_picture.linesize[2], w>>1, h>>1, EDGE_WIDTH/2); | 3871 draw_edges(s->current_picture.data[2], s->current_picture.linesize[2], w>>1, h>>1, EDGE_WIDTH/2); |
3827 } | 3872 } |
3828 | 3873 |
3829 tmp= s->last_picture[s->max_ref_frames-1]; | 3874 tmp= s->last_picture[s->max_ref_frames-1]; |
3830 memmove(s->last_picture+1, s->last_picture, (s->max_ref_frames-1)*sizeof(AVFrame)); | 3875 memmove(s->last_picture+1, s->last_picture, (s->max_ref_frames-1)*sizeof(AVFrame)); |
3876 memmove(s->halfpel_plane+1, s->halfpel_plane, (s->max_ref_frames-1)*sizeof(void*)*4*4); | |
3877 #ifdef USE_HALFPEL_PLANE | |
3878 if(s->current_picture.data[0]) | |
3879 halfpel_interpol(s, s->halfpel_plane[0], &s->current_picture); | |
3880 #endif | |
3831 s->last_picture[0]= s->current_picture; | 3881 s->last_picture[0]= s->current_picture; |
3832 s->current_picture= tmp; | 3882 s->current_picture= tmp; |
3833 | 3883 |
3834 if(s->keyframe){ | 3884 if(s->keyframe){ |
3835 s->ref_frames= 0; | 3885 s->ref_frames= 0; |
4081 s->avctx->error[plane_index] += error; | 4131 s->avctx->error[plane_index] += error; |
4082 s->current_picture.error[plane_index] = error; | 4132 s->current_picture.error[plane_index] = error; |
4083 } | 4133 } |
4084 } | 4134 } |
4085 | 4135 |
4086 if(s->last_picture[s->max_ref_frames-1].data[0]) | 4136 if(s->last_picture[s->max_ref_frames-1].data[0]){ |
4087 avctx->release_buffer(avctx, &s->last_picture[s->max_ref_frames-1]); | 4137 avctx->release_buffer(avctx, &s->last_picture[s->max_ref_frames-1]); |
4138 for(i=0; i<9; i++) | |
4139 if(s->halfpel_plane[s->max_ref_frames-1][1+i/3][i%3]) | |
4140 av_free(s->halfpel_plane[s->max_ref_frames-1][1+i/3][i%3] - EDGE_WIDTH*(1+s->current_picture.linesize[i%3])); | |
4141 } | |
4088 | 4142 |
4089 s->current_picture.coded_picture_number = avctx->frame_number; | 4143 s->current_picture.coded_picture_number = avctx->frame_number; |
4090 s->current_picture.pict_type = pict->pict_type; | 4144 s->current_picture.pict_type = pict->pict_type; |
4091 s->current_picture.quality = pict->quality; | 4145 s->current_picture.quality = pict->quality; |
4092 s->m.frame_bits = 8*(s->c.bytestream - s->c.bytestream_start); | 4146 s->m.frame_bits = 8*(s->c.bytestream - s->c.bytestream_start); |
4170 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size){ | 4224 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size){ |
4171 SnowContext *s = avctx->priv_data; | 4225 SnowContext *s = avctx->priv_data; |
4172 RangeCoder * const c= &s->c; | 4226 RangeCoder * const c= &s->c; |
4173 int bytes_read; | 4227 int bytes_read; |
4174 AVFrame *picture = data; | 4228 AVFrame *picture = data; |
4175 int level, orientation, plane_index; | 4229 int level, orientation, plane_index, i; |
4176 | 4230 |
4177 ff_init_range_decoder(c, buf, buf_size); | 4231 ff_init_range_decoder(c, buf, buf_size); |
4178 ff_build_rac_states(c, 0.05*(1LL<<32), 256-8); | 4232 ff_build_rac_states(c, 0.05*(1LL<<32), 256-8); |
4179 | 4233 |
4180 s->current_picture.pict_type= FF_I_TYPE; //FIXME I vs. P | 4234 s->current_picture.pict_type= FF_I_TYPE; //FIXME I vs. P |
4302 STOP_TIMER("idwt + predict_slices")} | 4356 STOP_TIMER("idwt + predict_slices")} |
4303 } | 4357 } |
4304 | 4358 |
4305 emms_c(); | 4359 emms_c(); |
4306 | 4360 |
4307 if(s->last_picture[s->max_ref_frames-1].data[0]) | 4361 if(s->last_picture[s->max_ref_frames-1].data[0]){ |
4308 avctx->release_buffer(avctx, &s->last_picture[s->max_ref_frames-1]); | 4362 avctx->release_buffer(avctx, &s->last_picture[s->max_ref_frames-1]); |
4363 for(i=0; i<9; i++) | |
4364 if(s->halfpel_plane[s->max_ref_frames-1][1+i/3][i%3]) | |
4365 av_free(s->halfpel_plane[s->max_ref_frames-1][1+i/3][i%3] - EDGE_WIDTH*(1+s->current_picture.linesize[i%3])); | |
4366 } | |
4309 | 4367 |
4310 if(!(s->avctx->debug&2048)) | 4368 if(!(s->avctx->debug&2048)) |
4311 *picture= s->current_picture; | 4369 *picture= s->current_picture; |
4312 else | 4370 else |
4313 *picture= s->mconly_picture; | 4371 *picture= s->mconly_picture; |