changeset 2065:9e4bebc39ade libavcodec

noise preserving sum of squares comparission function
author michael
date Mon, 07 Jun 2004 03:23:31 +0000
parents b77fe059dd09
children 4bfb146e701b
files avcodec.h dsputil.c dsputil.h motion_est.c mpegvideo.c
diffstat 5 files changed, 64 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/avcodec.h	Sun Jun 06 20:15:53 2004 +0000
+++ b/avcodec.h	Mon Jun 07 03:23:31 2004 +0000
@@ -915,8 +915,8 @@
     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 @@
 #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
     
     /**
--- a/dsputil.c	Sun Jun 06 20:15:53 2004 +0000
+++ b/dsputil.c	Mon Jun 07 03:23:31 2004 +0000
@@ -2587,6 +2587,54 @@
     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 @@
         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 @@
     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;
--- a/dsputil.h	Sun Jun 06 20:15:53 2004 +0000
+++ b/dsputil.h	Mon Jun 07 03:23:31 2004 +0000
@@ -162,6 +162,7 @@
     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];
--- a/motion_est.c	Sun Jun 06 20:15:53 2004 +0000
+++ b/motion_est.c	Mon Jun 07 03:23:31 2004 +0000
@@ -223,6 +223,7 @@
     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);
--- a/mpegvideo.c	Sun Jun 06 20:15:53 2004 +0000
+++ b/mpegvideo.c	Mon Jun 07 03:23:31 2004 +0000
@@ -3916,9 +3916,15 @@
     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)