diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2004-06-07 03:23:31 +0000 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2004-06-07 03:23:31 +0000 |
commit | e6a2ac3474986280dda041521229683f00f04759 (patch) | |
tree | 902e92e533171eda1ab3b6a433c3b6d3fd37cb79 | |
parent | 2b647ac8c91c95e7f2a94f52e3561f09e6a99d48 (diff) | |
download | ffmpeg-e6a2ac3474986280dda041521229683f00f04759.tar.gz |
noise preserving sum of squares comparission function
Originally committed as revision 3204 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r-- | libavcodec/avcodec.h | 5 | ||||
-rw-r--r-- | libavcodec/dsputil.c | 53 | ||||
-rw-r--r-- | libavcodec/dsputil.h | 1 | ||||
-rw-r--r-- | libavcodec/motion_est.c | 1 | ||||
-rw-r--r-- | libavcodec/mpegvideo.c | 6 |
5 files changed, 64 insertions, 2 deletions
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 0a263cbb08..70df542500 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -915,8 +915,8 @@ typedef struct AVCodecContext { void (*release_buffer)(struct AVCodecContext *c, AVFrame *pic); /** - * is 1 if the decoded stream contains b frames, 0 otherwise. - * - encoding: unused + * if 1 the stream has a 1 frame delay during decoding. + * - encoding: set by lavc * - decoding: set by lavc */ int has_b_frames; @@ -1251,6 +1251,7 @@ typedef struct AVCodecContext { #define FF_CMP_ZERO 7 #define FF_CMP_VSAD 8 #define FF_CMP_VSSE 9 +#define FF_CMP_NSSE 10 #define FF_CMP_CHROMA 256 /** diff --git a/libavcodec/dsputil.c b/libavcodec/dsputil.c index 3e3e550b11..5c84a139be 100644 --- a/libavcodec/dsputil.c +++ b/libavcodec/dsputil.c @@ -2587,6 +2587,54 @@ static int pix_abs8_xy2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, return s; } +static int nsse16_c(/*MpegEncContext*/ void *c, uint8_t *s1, uint8_t *s2, int stride, int h){ + int score1=0; + int score2=0; + int x,y; + + for(y=0; y<h; y++){ + for(x=0; x<16; x++){ + score1+= (s1[x ] - s2[x ])*(s1[x ] - s2[x ]); + } + if(y+1<h){ + for(x=0; x<15; x++){ + score2+= ABS( s1[x ] - s1[x +stride] + - s1[x+1] + s1[x+1+stride]) + -ABS( s2[x ] - s2[x +stride] + - s2[x+1] + s2[x+1+stride]); + } + } + s1+= stride; + s2+= stride; + } + + return score1 + ABS(score2)*8; +} + +static int nsse8_c(/*MpegEncContext*/ void *c, uint8_t *s1, uint8_t *s2, int stride, int h){ + int score1=0; + int score2=0; + int x,y; + + for(y=0; y<h; y++){ + for(x=0; x<8; x++){ + score1+= (s1[x ] - s2[x ])*(s1[x ] - s2[x ]); + } + if(y+1<h){ + for(x=0; x<7; x++){ + score2+= ABS( s1[x ] - s1[x +stride] + - s1[x+1] + s1[x+1+stride]) + -ABS( s2[x ] - s2[x +stride] + - s2[x+1] + s2[x+1+stride]); + } + } + s1+= stride; + s2+= stride; + } + + return score1 + ABS(score2)*8; +} + static int try_8x8basis_c(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale){ int i; unsigned int sum=0; @@ -2680,6 +2728,9 @@ void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type){ case FF_CMP_ZERO: cmp[i]= zero_cmp; break; + case FF_CMP_NSSE: + cmp[i]= c->nsse[i]; + break; default: av_log(NULL, AV_LOG_ERROR,"internal error in cmp function selection\n"); } @@ -3313,6 +3364,8 @@ void dsputil_init(DSPContext* c, AVCodecContext *avctx) c->vsad[4]= vsad_intra16_c; c->vsse[0]= vsse16_c; c->vsse[4]= vsse_intra16_c; + c->nsse[0]= nsse16_c; + c->nsse[1]= nsse8_c; c->add_bytes= add_bytes_c; c->diff_bytes= diff_bytes_c; diff --git a/libavcodec/dsputil.h b/libavcodec/dsputil.h index cdc5a3b859..be53279797 100644 --- a/libavcodec/dsputil.h +++ b/libavcodec/dsputil.h @@ -162,6 +162,7 @@ typedef struct DSPContext { me_cmp_func rd[5]; me_cmp_func vsad[5]; me_cmp_func vsse[5]; + me_cmp_func nsse[5]; me_cmp_func me_pre_cmp[5]; me_cmp_func me_cmp[5]; diff --git a/libavcodec/motion_est.c b/libavcodec/motion_est.c index b92b6dfad8..bee1e07f00 100644 --- a/libavcodec/motion_est.c +++ b/libavcodec/motion_est.c @@ -223,6 +223,7 @@ static inline int get_penalty_factor(MpegEncContext *s, int type){ switch(type&0xFF){ default: case FF_CMP_SAD: + case FF_CMP_NSSE: return s->lambda>>FF_LAMBDA_SHIFT; case FF_CMP_DCT: return (3*s->lambda)>>(FF_LAMBDA_SHIFT+1); diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index bd2de7cd0f..f402a81269 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -3916,9 +3916,15 @@ static int sse_mb(MpegEncContext *s){ if(s->mb_y*16 + 16 > s->height) h= s->height- s->mb_y*16; if(w==16 && h==16) + if(s->avctx->mb_cmp == FF_CMP_NSSE){ + return s->dsp.nsse[0](NULL, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, s->dest[0], s->linesize, 16) + +s->dsp.nsse[1](NULL, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[1], s->uvlinesize, 8) + +s->dsp.nsse[1](NULL, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[2], s->uvlinesize, 8); + }else{ return s->dsp.sse[0](NULL, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, s->dest[0], s->linesize, 16) +s->dsp.sse[1](NULL, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[1], s->uvlinesize, 8) +s->dsp.sse[1](NULL, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[2], s->uvlinesize, 8); + } else return sse(s, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, s->dest[0], w, h, s->linesize) +sse(s, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[1], w>>1, h>>1, s->uvlinesize) |