Mercurial > libavcodec.hg
changeset 10762:a4842fc20ac8 libavcodec
Small ELBG optimization: use last pixel as a initial guess for the codebook
entry.
author | vitor |
---|---|
date | Sat, 02 Jan 2010 12:15:09 +0000 |
parents | 1d22da3122b9 |
children | 98bf00fa95cd |
files | elbg.c |
diffstat | 1 files changed, 8 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/elbg.c Fri Jan 01 21:32:48 2010 +0000 +++ b/elbg.c Sat Jan 02 12:15:09 2010 +0000 @@ -355,6 +355,7 @@ int *size_part = av_malloc(numCB*sizeof(int)); cell *list_buffer = av_malloc(numpoints*sizeof(cell)); cell *free_cells; + int best_dist, best_idx = 0; elbg->error = INT_MAX; elbg->dim = dim; @@ -380,14 +381,16 @@ /* This loop evaluate the actual Voronoi partition. It is the most costly part of the algorithm. */ for (i=0; i < numpoints; i++) { - dist_cb[i] = INT_MAX; + best_dist = distance_limited(elbg->points + i*elbg->dim, elbg->codebook + best_idx*elbg->dim, dim, INT_MAX); for (k=0; k < elbg->numCB; k++) { - dist = distance_limited(elbg->points + i*elbg->dim, elbg->codebook + k*elbg->dim, dim, dist_cb[i]); - if (dist < dist_cb[i]) { - dist_cb[i] = dist; - elbg->nearest_cb[i] = k; + dist = distance_limited(elbg->points + i*elbg->dim, elbg->codebook + k*elbg->dim, dim, best_dist); + if (dist < best_dist) { + best_dist = dist; + best_idx = k; } } + elbg->nearest_cb[i] = best_idx; + dist_cb[i] = best_dist; elbg->error += dist_cb[i]; elbg->utility[elbg->nearest_cb[i]] += dist_cb[i]; free_cells->index = i;