comparison elbg.c @ 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 678152bdb3a1
children 7dd2a45249a9
comparison
equal deleted inserted replaced
10761:1d22da3122b9 10762:a4842fc20ac8
353 int i, j, k, last_error, steps=0; 353 int i, j, k, last_error, steps=0;
354 int *dist_cb = av_malloc(numpoints*sizeof(int)); 354 int *dist_cb = av_malloc(numpoints*sizeof(int));
355 int *size_part = av_malloc(numCB*sizeof(int)); 355 int *size_part = av_malloc(numCB*sizeof(int));
356 cell *list_buffer = av_malloc(numpoints*sizeof(cell)); 356 cell *list_buffer = av_malloc(numpoints*sizeof(cell));
357 cell *free_cells; 357 cell *free_cells;
358 int best_dist, best_idx = 0;
358 359
359 elbg->error = INT_MAX; 360 elbg->error = INT_MAX;
360 elbg->dim = dim; 361 elbg->dim = dim;
361 elbg->numCB = numCB; 362 elbg->numCB = numCB;
362 elbg->codebook = codebook; 363 elbg->codebook = codebook;
378 elbg->error = 0; 379 elbg->error = 0;
379 380
380 /* This loop evaluate the actual Voronoi partition. It is the most 381 /* This loop evaluate the actual Voronoi partition. It is the most
381 costly part of the algorithm. */ 382 costly part of the algorithm. */
382 for (i=0; i < numpoints; i++) { 383 for (i=0; i < numpoints; i++) {
383 dist_cb[i] = INT_MAX; 384 best_dist = distance_limited(elbg->points + i*elbg->dim, elbg->codebook + best_idx*elbg->dim, dim, INT_MAX);
384 for (k=0; k < elbg->numCB; k++) { 385 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 dist = distance_limited(elbg->points + i*elbg->dim, elbg->codebook + k*elbg->dim, dim, best_dist);
386 if (dist < dist_cb[i]) { 387 if (dist < best_dist) {
387 dist_cb[i] = dist; 388 best_dist = dist;
388 elbg->nearest_cb[i] = k; 389 best_idx = k;
389 } 390 }
390 } 391 }
392 elbg->nearest_cb[i] = best_idx;
393 dist_cb[i] = best_dist;
391 elbg->error += dist_cb[i]; 394 elbg->error += dist_cb[i];
392 elbg->utility[elbg->nearest_cb[i]] += dist_cb[i]; 395 elbg->utility[elbg->nearest_cb[i]] += dist_cb[i];
393 free_cells->index = i; 396 free_cells->index = i;
394 free_cells->next = elbg->cells[elbg->nearest_cb[i]]; 397 free_cells->next = elbg->cells[elbg->nearest_cb[i]];
395 elbg->cells[elbg->nearest_cb[i]] = free_cells; 398 elbg->cells[elbg->nearest_cb[i]] = free_cells;