# HG changeset patch # User kostya # Date 1210323761 0 # Node ID a57835341650a5248bbd6b301061ea2363171173 # Parent 7cd794be03ae5c52ee9552880e0f55602004be15 Improve motion estimation metric. Patch by Michael Niedermayer diff -r 7cd794be03ae -r a57835341650 zmbvenc.c --- a/zmbvenc.c Thu May 08 23:15:39 2008 +0000 +++ b/zmbvenc.c Fri May 09 09:02:41 2008 +0000 @@ -54,6 +54,8 @@ z_stream zstream; } ZmbvEncContext; +static int score_tab[256]; + /** Block comparing function * XXX should be optimized and moved to DSPContext * TODO handle out of edge ME @@ -62,13 +64,18 @@ { int sum = 0; int i, j; + uint8_t histogram[256]={0}; for(j = 0; j < bh; j++){ for(i = 0; i < bw; i++) - sum += src[i] ^ src2[i]; + histogram[src[i] ^ src2[i]]++; src += stride; src2 += stride2; } + + for(i=1; i<256; i++) + sum+= score_tab[histogram[i]]; + return sum; } @@ -235,8 +242,12 @@ { ZmbvEncContext * const c = avctx->priv_data; int zret; // Zlib return code + int i; int lvl = 9; + for(i=1; i<256; i++) + score_tab[i]= -i * log2(i/256.0) * 256; + c->avctx = avctx; c->pic.data[0] = NULL;