Browse code

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

Vitor Sessak authored on 2010/01/02 21:15:09
Showing 1 changed files
... ...
@@ -355,6 +355,7 @@ void ff_do_elbg(int *points, int dim, int numpoints, int *codebook,
355 355
     int *size_part = av_malloc(numCB*sizeof(int));
356 356
     cell *list_buffer = av_malloc(numpoints*sizeof(cell));
357 357
     cell *free_cells;
358
+    int best_dist, best_idx = 0;
358 359
 
359 360
     elbg->error = INT_MAX;
360 361
     elbg->dim = dim;
... ...
@@ -380,14 +381,16 @@ void ff_do_elbg(int *points, int dim, int numpoints, int *codebook,
380 380
         /* This loop evaluate the actual Voronoi partition. It is the most
381 381
            costly part of the algorithm. */
382 382
         for (i=0; i < numpoints; i++) {
383
-            dist_cb[i] = INT_MAX;
383
+            best_dist = distance_limited(elbg->points + i*elbg->dim, elbg->codebook + best_idx*elbg->dim, dim, INT_MAX);
384 384
             for (k=0; k < elbg->numCB; k++) {
385
-                dist = distance_limited(elbg->points + i*elbg->dim, elbg->codebook + k*elbg->dim, dim, dist_cb[i]);
386
-                if (dist < dist_cb[i]) {
387
-                    dist_cb[i] = dist;
388
-                    elbg->nearest_cb[i] = k;
385
+                dist = distance_limited(elbg->points + i*elbg->dim, elbg->codebook + k*elbg->dim, dim, best_dist);
386
+                if (dist < best_dist) {
387
+                    best_dist = dist;
388
+                    best_idx = k;
389 389
                 }
390 390
             }
391
+            elbg->nearest_cb[i] = best_idx;
392
+            dist_cb[i] = best_dist;
391 393
             elbg->error += dist_cb[i];
392 394
             elbg->utility[elbg->nearest_cb[i]] += dist_cb[i];
393 395
             free_cells->index = i;