From e6a2ac3474986280dda041521229683f00f04759 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Mon, 7 Jun 2004 03:23:31 +0000 Subject: [PATCH] noise preserving sum of squares comparission function Originally committed as revision 3204 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavcodec/avcodec.h | 5 ++-- libavcodec/dsputil.c | 53 +++++++++++++++++++++++++++++++++++++++++ libavcodec/dsputil.h | 1 + libavcodec/motion_est.c | 1 + 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; ynsse[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)