Commit 2f8e6371 authored by vitor's avatar vitor

Small ELBG optimization: use last pixel as a initial guess for the codebook

entry.


git-svn-id: file:///var/local/repositories/ffmpeg/trunk@21001 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent 1b2d6ecd
...@@ -355,6 +355,7 @@ void ff_do_elbg(int *points, int dim, int numpoints, int *codebook, ...@@ -355,6 +355,7 @@ void ff_do_elbg(int *points, int dim, int numpoints, int *codebook,
int *size_part = av_malloc(numCB*sizeof(int)); int *size_part = av_malloc(numCB*sizeof(int));
cell *list_buffer = av_malloc(numpoints*sizeof(cell)); cell *list_buffer = av_malloc(numpoints*sizeof(cell));
cell *free_cells; cell *free_cells;
int best_dist, best_idx = 0;
elbg->error = INT_MAX; elbg->error = INT_MAX;
elbg->dim = dim; elbg->dim = dim;
...@@ -380,14 +381,16 @@ void ff_do_elbg(int *points, int dim, int numpoints, int *codebook, ...@@ -380,14 +381,16 @@ void ff_do_elbg(int *points, int dim, int numpoints, int *codebook,
/* This loop evaluate the actual Voronoi partition. It is the most /* This loop evaluate the actual Voronoi partition. It is the most
costly part of the algorithm. */ costly part of the algorithm. */
for (i=0; i < numpoints; i++) { 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++) { for (k=0; k < elbg->numCB; k++) {
dist = distance_limited(elbg->points + i*elbg->dim, elbg->codebook + k*elbg->dim, dim, dist_cb[i]); dist = distance_limited(elbg->points + i*elbg->dim, elbg->codebook + k*elbg->dim, dim, best_dist);
if (dist < dist_cb[i]) { if (dist < best_dist) {
dist_cb[i] = dist; best_dist = dist;
elbg->nearest_cb[i] = k; best_idx = k;
} }
} }
elbg->nearest_cb[i] = best_idx;
dist_cb[i] = best_dist;
elbg->error += dist_cb[i]; elbg->error += dist_cb[i];
elbg->utility[elbg->nearest_cb[i]] += dist_cb[i]; elbg->utility[elbg->nearest_cb[i]] += dist_cb[i];
free_cells->index = i; free_cells->index = i;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment