X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Felbg.c;h=59ae4b97a064ced1041e404394f837ac219a4d7a;hb=e1f7cb7fa0aec465ec0c172d1b922aebced04cc2;hp=cd5b5ed4fecadc5b0301ec093025a3fd0f5e4fee;hpb=3a66812fc859b0fa374a9a72e36d8cef27838b08;p=ffmpeg diff --git a/libavcodec/elbg.c b/libavcodec/elbg.c index cd5b5ed4fec..59ae4b97a06 100644 --- a/libavcodec/elbg.c +++ b/libavcodec/elbg.c @@ -19,15 +19,15 @@ */ /** - * @file cbook_gen.c + * @file elbg.c * Codebook Generator using the ELBG algorithm */ #include +#include "libavutil/random.h" #include "elbg.h" #include "avcodec.h" -#include "random.h" #define DELTA_ERR_MAX 0.1 ///< Precision of the ELBG algorithm (as percentual error) @@ -105,9 +105,12 @@ static int get_high_utility_cell(elbg_data *elbg) { int i=0; /* Using linear search, do binary if it ever turns to be speed critical */ - int r = av_random(elbg->rand_state)%elbg->utility_inc[elbg->numCB-1]; + int r = av_random(elbg->rand_state)%(elbg->utility_inc[elbg->numCB-1]-1) + 1; while (elbg->utility_inc[i] < r) i++; + + assert(!elbg->cells[i]); + return i; } @@ -246,9 +249,13 @@ static void try_shift_candidate(elbg_data *elbg, int idx[3]) int j, k, olderror=0, newerror, cont=0; int newutility[3]; int newcentroid[3][elbg->dim]; - int *newcentroid_ptrs[3] = { newcentroid[0], newcentroid[1], newcentroid[2] }; + int *newcentroid_ptrs[3]; cell *tempcell; + newcentroid_ptrs[0] = newcentroid[0]; + newcentroid_ptrs[1] = newcentroid[1]; + newcentroid_ptrs[2] = newcentroid[2]; + for (j=0; j<3; j++) olderror += elbg->utility[idx[j]]; @@ -302,7 +309,8 @@ static void do_shiftings(elbg_data *elbg) idx[1] = get_high_utility_cell(elbg); idx[2] = get_closest_codebook(elbg, idx[0]); - try_shift_candidate(elbg, idx); + if (idx[1] != idx[0] && idx[1] != idx[2]) + try_shift_candidate(elbg, idx); } }