Originally committed as revision 23787 to svn://svn.ffmpeg.org/ffmpeg/trunk
| ... | ... |
@@ -53,6 +53,7 @@ typedef struct{
|
| 53 | 53 |
int *nearest_cb; |
| 54 | 54 |
int *points; |
| 55 | 55 |
AVLFG *rand_state; |
| 56 |
+ int *scratchbuf; |
|
| 56 | 57 |
} elbg_data; |
| 57 | 58 |
|
| 58 | 59 |
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) |
| 117 | 117 |
/** |
| 118 | 118 |
* Implementation of the simple LBG algorithm for just two codebooks |
| 119 | 119 |
*/ |
| 120 |
-static int simple_lbg(int dim, |
|
| 120 |
+static int simple_lbg(elbg_data *elbg, |
|
| 121 |
+ int dim, |
|
| 121 | 122 |
int *centroid[3], |
| 122 | 123 |
int newutility[3], |
| 123 | 124 |
int *points, |
| ... | ... |
@@ -125,10 +127,13 @@ static int simple_lbg(int dim, |
| 125 | 125 |
{
|
| 126 | 126 |
int i, idx; |
| 127 | 127 |
int numpoints[2] = {0,0};
|
| 128 |
- int newcentroid[2][dim]; |
|
| 128 |
+ int *newcentroid[2] = {
|
|
| 129 |
+ elbg->scratchbuf + 3*dim, |
|
| 130 |
+ elbg->scratchbuf + 4*dim |
|
| 131 |
+ }; |
|
| 129 | 132 |
cell *tempcell; |
| 130 | 133 |
|
| 131 |
- memset(newcentroid, 0, sizeof(newcentroid)); |
|
| 134 |
+ memset(newcentroid[0], 0, 2 * dim * sizeof(*newcentroid[0])); |
|
| 132 | 135 |
|
| 133 | 136 |
newutility[0] = |
| 134 | 137 |
newutility[1] = 0; |
| ... | ... |
@@ -158,8 +163,8 @@ static void get_new_centroids(elbg_data *elbg, int huc, int *newcentroid_i, |
| 158 | 158 |
int *newcentroid_p) |
| 159 | 159 |
{
|
| 160 | 160 |
cell *tempcell; |
| 161 |
- int min[elbg->dim]; |
|
| 162 |
- int max[elbg->dim]; |
|
| 161 |
+ int *min = newcentroid_i; |
|
| 162 |
+ int *max = newcentroid_p; |
|
| 163 | 163 |
int i; |
| 164 | 164 |
|
| 165 | 165 |
for (i=0; i< elbg->dim; i++) {
|
| ... | ... |
@@ -174,8 +179,10 @@ static void get_new_centroids(elbg_data *elbg, int huc, int *newcentroid_i, |
| 174 | 174 |
} |
| 175 | 175 |
|
| 176 | 176 |
for (i=0; i<elbg->dim; i++) {
|
| 177 |
- newcentroid_i[i] = min[i] + (max[i] - min[i])/3; |
|
| 178 |
- newcentroid_p[i] = min[i] + (2*(max[i] - min[i]))/3; |
|
| 177 |
+ int ni = min[i] + (max[i] - min[i])/3; |
|
| 178 |
+ int np = min[i] + (2*(max[i] - min[i]))/3; |
|
| 179 |
+ newcentroid_i[i] = ni; |
|
| 180 |
+ newcentroid_p[i] = np; |
|
| 179 | 181 |
} |
| 180 | 182 |
} |
| 181 | 183 |
|
| ... | ... |
@@ -248,14 +255,13 @@ static void try_shift_candidate(elbg_data *elbg, int idx[3]) |
| 248 | 248 |
{
|
| 249 | 249 |
int j, k, olderror=0, newerror, cont=0; |
| 250 | 250 |
int newutility[3]; |
| 251 |
- int newcentroid[3][elbg->dim]; |
|
| 252 |
- int *newcentroid_ptrs[3]; |
|
| 251 |
+ int *newcentroid[3] = {
|
|
| 252 |
+ elbg->scratchbuf, |
|
| 253 |
+ elbg->scratchbuf + elbg->dim, |
|
| 254 |
+ elbg->scratchbuf + 2*elbg->dim |
|
| 255 |
+ }; |
|
| 253 | 256 |
cell *tempcell; |
| 254 | 257 |
|
| 255 |
- newcentroid_ptrs[0] = newcentroid[0]; |
|
| 256 |
- newcentroid_ptrs[1] = newcentroid[1]; |
|
| 257 |
- newcentroid_ptrs[2] = newcentroid[2]; |
|
| 258 |
- |
|
| 259 | 258 |
for (j=0; j<3; j++) |
| 260 | 259 |
olderror += elbg->utility[idx[j]]; |
| 261 | 260 |
|
| ... | ... |
@@ -277,11 +283,11 @@ static void try_shift_candidate(elbg_data *elbg, int idx[3]) |
| 277 | 277 |
|
| 278 | 278 |
newerror = newutility[2]; |
| 279 | 279 |
|
| 280 |
- newerror += simple_lbg(elbg->dim, newcentroid_ptrs, newutility, elbg->points, |
|
| 280 |
+ newerror += simple_lbg(elbg, elbg->dim, newcentroid, newutility, elbg->points, |
|
| 281 | 281 |
elbg->cells[idx[1]]); |
| 282 | 282 |
|
| 283 | 283 |
if (olderror > newerror) {
|
| 284 |
- shift_codebook(elbg, idx, newcentroid_ptrs); |
|
| 284 |
+ shift_codebook(elbg, idx, newcentroid); |
|
| 285 | 285 |
|
| 286 | 286 |
elbg->error += newerror - olderror; |
| 287 | 287 |
|
| ... | ... |
@@ -366,6 +372,7 @@ void ff_do_elbg(int *points, int dim, int numpoints, int *codebook, |
| 366 | 366 |
elbg->nearest_cb = closest_cb; |
| 367 | 367 |
elbg->points = points; |
| 368 | 368 |
elbg->utility_inc = av_malloc(numCB*sizeof(int)); |
| 369 |
+ elbg->scratchbuf = av_malloc(5*dim*sizeof(int)); |
|
| 369 | 370 |
|
| 370 | 371 |
elbg->rand_state = rand_state; |
| 371 | 372 |
|
| ... | ... |
@@ -425,4 +432,5 @@ void ff_do_elbg(int *points, int dim, int numpoints, int *codebook, |
| 425 | 425 |
av_free(list_buffer); |
| 426 | 426 |
av_free(elbg->cells); |
| 427 | 427 |
av_free(elbg->utility_inc); |
| 428 |
+ av_free(elbg->scratchbuf); |
|
| 428 | 429 |
} |