aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVitor Sessak <vitor1001@gmail.com>2010-01-02 12:15:09 +0000
committerVitor Sessak <vitor1001@gmail.com>2010-01-02 12:15:09 +0000
commit4e2c08c5516adc8d31c67fbb1192b1fcaa472ee6 (patch)
tree83b5ce7568b3f9ed9b488cee0f1b8f54c5f9ad1e
parentaa13b573b462e4ce88814f28fd9d2659ddc04eb7 (diff)
downloadffmpeg-4e2c08c5516adc8d31c67fbb1192b1fcaa472ee6.tar.gz
Small ELBG optimization: use last pixel as a initial guess for the codebook
entry. Originally committed as revision 21001 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r--libavcodec/elbg.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/libavcodec/elbg.c b/libavcodec/elbg.c
index 85319db78e..2f9d15300e 100644
--- a/libavcodec/elbg.c
+++ b/libavcodec/elbg.c
@@ -355,6 +355,7 @@ void ff_do_elbg(int *points, int dim, int numpoints, int *codebook,
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 @@ void ff_do_elbg(int *points, int dim, int numpoints, int *codebook,
/* 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;