elbg: remove VLAs
Originally committed as revision 23787 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
@@ -53,6 +53,7 @@ typedef struct{
|
|||||||
int *nearest_cb;
|
int *nearest_cb;
|
||||||
int *points;
|
int *points;
|
||||||
AVLFG *rand_state;
|
AVLFG *rand_state;
|
||||||
|
int *scratchbuf;
|
||||||
} elbg_data;
|
} elbg_data;
|
||||||
|
|
||||||
static inline int distance_limited(int *a, int *b, int dim, int limit)
|
static inline int distance_limited(int *a, int *b, int dim, int limit)
|
||||||
@@ -117,7 +118,8 @@ static int get_high_utility_cell(elbg_data *elbg)
|
|||||||
/**
|
/**
|
||||||
* Implementation of the simple LBG algorithm for just two codebooks
|
* Implementation of the simple LBG algorithm for just two codebooks
|
||||||
*/
|
*/
|
||||||
static int simple_lbg(int dim,
|
static int simple_lbg(elbg_data *elbg,
|
||||||
|
int dim,
|
||||||
int *centroid[3],
|
int *centroid[3],
|
||||||
int newutility[3],
|
int newutility[3],
|
||||||
int *points,
|
int *points,
|
||||||
@@ -125,10 +127,13 @@ static int simple_lbg(int dim,
|
|||||||
{
|
{
|
||||||
int i, idx;
|
int i, idx;
|
||||||
int numpoints[2] = {0,0};
|
int numpoints[2] = {0,0};
|
||||||
int newcentroid[2][dim];
|
int *newcentroid[2] = {
|
||||||
|
elbg->scratchbuf + 3*dim,
|
||||||
|
elbg->scratchbuf + 4*dim
|
||||||
|
};
|
||||||
cell *tempcell;
|
cell *tempcell;
|
||||||
|
|
||||||
memset(newcentroid, 0, sizeof(newcentroid));
|
memset(newcentroid[0], 0, 2 * dim * sizeof(*newcentroid[0]));
|
||||||
|
|
||||||
newutility[0] =
|
newutility[0] =
|
||||||
newutility[1] = 0;
|
newutility[1] = 0;
|
||||||
@@ -158,8 +163,8 @@ static void get_new_centroids(elbg_data *elbg, int huc, int *newcentroid_i,
|
|||||||
int *newcentroid_p)
|
int *newcentroid_p)
|
||||||
{
|
{
|
||||||
cell *tempcell;
|
cell *tempcell;
|
||||||
int min[elbg->dim];
|
int *min = newcentroid_i;
|
||||||
int max[elbg->dim];
|
int *max = newcentroid_p;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i=0; i< elbg->dim; i++) {
|
for (i=0; i< elbg->dim; i++) {
|
||||||
@@ -174,8 +179,10 @@ static void get_new_centroids(elbg_data *elbg, int huc, int *newcentroid_i,
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (i=0; i<elbg->dim; i++) {
|
for (i=0; i<elbg->dim; i++) {
|
||||||
newcentroid_i[i] = min[i] + (max[i] - min[i])/3;
|
int ni = min[i] + (max[i] - min[i])/3;
|
||||||
newcentroid_p[i] = min[i] + (2*(max[i] - min[i]))/3;
|
int np = min[i] + (2*(max[i] - min[i]))/3;
|
||||||
|
newcentroid_i[i] = ni;
|
||||||
|
newcentroid_p[i] = np;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,14 +255,13 @@ static void try_shift_candidate(elbg_data *elbg, int idx[3])
|
|||||||
{
|
{
|
||||||
int j, k, olderror=0, newerror, cont=0;
|
int j, k, olderror=0, newerror, cont=0;
|
||||||
int newutility[3];
|
int newutility[3];
|
||||||
int newcentroid[3][elbg->dim];
|
int *newcentroid[3] = {
|
||||||
int *newcentroid_ptrs[3];
|
elbg->scratchbuf,
|
||||||
|
elbg->scratchbuf + elbg->dim,
|
||||||
|
elbg->scratchbuf + 2*elbg->dim
|
||||||
|
};
|
||||||
cell *tempcell;
|
cell *tempcell;
|
||||||
|
|
||||||
newcentroid_ptrs[0] = newcentroid[0];
|
|
||||||
newcentroid_ptrs[1] = newcentroid[1];
|
|
||||||
newcentroid_ptrs[2] = newcentroid[2];
|
|
||||||
|
|
||||||
for (j=0; j<3; j++)
|
for (j=0; j<3; j++)
|
||||||
olderror += elbg->utility[idx[j]];
|
olderror += elbg->utility[idx[j]];
|
||||||
|
|
||||||
@@ -277,11 +283,11 @@ static void try_shift_candidate(elbg_data *elbg, int idx[3])
|
|||||||
|
|
||||||
newerror = newutility[2];
|
newerror = newutility[2];
|
||||||
|
|
||||||
newerror += simple_lbg(elbg->dim, newcentroid_ptrs, newutility, elbg->points,
|
newerror += simple_lbg(elbg, elbg->dim, newcentroid, newutility, elbg->points,
|
||||||
elbg->cells[idx[1]]);
|
elbg->cells[idx[1]]);
|
||||||
|
|
||||||
if (olderror > newerror) {
|
if (olderror > newerror) {
|
||||||
shift_codebook(elbg, idx, newcentroid_ptrs);
|
shift_codebook(elbg, idx, newcentroid);
|
||||||
|
|
||||||
elbg->error += newerror - olderror;
|
elbg->error += newerror - olderror;
|
||||||
|
|
||||||
@@ -366,6 +372,7 @@ void ff_do_elbg(int *points, int dim, int numpoints, int *codebook,
|
|||||||
elbg->nearest_cb = closest_cb;
|
elbg->nearest_cb = closest_cb;
|
||||||
elbg->points = points;
|
elbg->points = points;
|
||||||
elbg->utility_inc = av_malloc(numCB*sizeof(int));
|
elbg->utility_inc = av_malloc(numCB*sizeof(int));
|
||||||
|
elbg->scratchbuf = av_malloc(5*dim*sizeof(int));
|
||||||
|
|
||||||
elbg->rand_state = rand_state;
|
elbg->rand_state = rand_state;
|
||||||
|
|
||||||
@@ -425,4 +432,5 @@ void ff_do_elbg(int *points, int dim, int numpoints, int *codebook,
|
|||||||
av_free(list_buffer);
|
av_free(list_buffer);
|
||||||
av_free(elbg->cells);
|
av_free(elbg->cells);
|
||||||
av_free(elbg->utility_inc);
|
av_free(elbg->utility_inc);
|
||||||
|
av_free(elbg->scratchbuf);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user