Mercurial > libavcodec.hg
comparison zmbvenc.c @ 6758:a57835341650 libavcodec
Improve motion estimation metric.
Patch by Michael Niedermayer
author | kostya |
---|---|
date | Fri, 09 May 2008 09:02:41 +0000 |
parents | f282270c589f |
children | 99966715fe75 |
comparison
equal
deleted
inserted
replaced
6757:7cd794be03ae | 6758:a57835341650 |
---|---|
52 int comp_size; | 52 int comp_size; |
53 int keyint, curfrm; | 53 int keyint, curfrm; |
54 z_stream zstream; | 54 z_stream zstream; |
55 } ZmbvEncContext; | 55 } ZmbvEncContext; |
56 | 56 |
57 static int score_tab[256]; | |
58 | |
57 /** Block comparing function | 59 /** Block comparing function |
58 * XXX should be optimized and moved to DSPContext | 60 * XXX should be optimized and moved to DSPContext |
59 * TODO handle out of edge ME | 61 * TODO handle out of edge ME |
60 */ | 62 */ |
61 static inline int block_cmp(uint8_t *src, int stride, uint8_t *src2, int stride2, int bw, int bh) | 63 static inline int block_cmp(uint8_t *src, int stride, uint8_t *src2, int stride2, int bw, int bh) |
62 { | 64 { |
63 int sum = 0; | 65 int sum = 0; |
64 int i, j; | 66 int i, j; |
67 uint8_t histogram[256]={0}; | |
65 | 68 |
66 for(j = 0; j < bh; j++){ | 69 for(j = 0; j < bh; j++){ |
67 for(i = 0; i < bw; i++) | 70 for(i = 0; i < bw; i++) |
68 sum += src[i] ^ src2[i]; | 71 histogram[src[i] ^ src2[i]]++; |
69 src += stride; | 72 src += stride; |
70 src2 += stride2; | 73 src2 += stride2; |
71 } | 74 } |
75 | |
76 for(i=1; i<256; i++) | |
77 sum+= score_tab[histogram[i]]; | |
78 | |
72 return sum; | 79 return sum; |
73 } | 80 } |
74 | 81 |
75 /** Motion estimation function | 82 /** Motion estimation function |
76 * TODO make better ME decisions | 83 * TODO make better ME decisions |
233 */ | 240 */ |
234 static av_cold int encode_init(AVCodecContext *avctx) | 241 static av_cold int encode_init(AVCodecContext *avctx) |
235 { | 242 { |
236 ZmbvEncContext * const c = avctx->priv_data; | 243 ZmbvEncContext * const c = avctx->priv_data; |
237 int zret; // Zlib return code | 244 int zret; // Zlib return code |
245 int i; | |
238 int lvl = 9; | 246 int lvl = 9; |
247 | |
248 for(i=1; i<256; i++) | |
249 score_tab[i]= -i * log2(i/256.0) * 256; | |
239 | 250 |
240 c->avctx = avctx; | 251 c->avctx = avctx; |
241 | 252 |
242 c->pic.data[0] = NULL; | 253 c->pic.data[0] = NULL; |
243 c->curfrm = 0; | 254 c->curfrm = 0; |