Revision 36672bac
libavcodec/elbg.c  

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  118 
/** 
118  119 
* Implementation of the simple LBG algorithm for just two codebooks 
119  120 
*/ 
120 
static int simple_lbg(int dim, 

121 
static int simple_lbg(elbg_data *elbg, 

122 
int dim, 

121  123 
int *centroid[3], 
122  124 
int newutility[3], 
123  125 
int *points, 
...  ...  
125  127 
{ 
126  128 
int i, idx; 
127  129 
int numpoints[2] = {0,0}; 
128 
int newcentroid[2][dim]; 

130 
int *newcentroid[2] = { 

131 
elbg>scratchbuf + 3*dim, 

132 
elbg>scratchbuf + 4*dim 

133 
}; 

129  134 
cell *tempcell; 
130  135  
131 
memset(newcentroid, 0, sizeof(newcentroid));


136 
memset(newcentroid[0], 0, 2 * dim * sizeof(*newcentroid[0]));


132  137  
133  138 
newutility[0] = 
134  139 
newutility[1] = 0; 
...  ...  
158  163 
int *newcentroid_p) 
159  164 
{ 
160  165 
cell *tempcell; 
161 
int min[elbg>dim];


162 
int max[elbg>dim];


166 
int *min = newcentroid_i;


167 
int *max = newcentroid_p;


163  168 
int i; 
164  169  
165  170 
for (i=0; i< elbg>dim; i++) { 
...  ...  
174  179 
} 
175  180  
176  181 
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; 

182 
int ni = min[i] + (max[i]  min[i])/3; 

183 
int np = min[i] + (2*(max[i]  min[i]))/3; 

184 
newcentroid_i[i] = ni; 

185 
newcentroid_p[i] = np; 

179  186 
} 
180  187 
} 
181  188  
...  ...  
248  255 
{ 
249  256 
int j, k, olderror=0, newerror, cont=0; 
250  257 
int newutility[3]; 
251 
int newcentroid[3][elbg>dim]; 

252 
int *newcentroid_ptrs[3]; 

258 
int *newcentroid[3] = { 

259 
elbg>scratchbuf, 

260 
elbg>scratchbuf + elbg>dim, 

261 
elbg>scratchbuf + 2*elbg>dim 

262 
}; 

253  263 
cell *tempcell; 
254  264  
255 
newcentroid_ptrs[0] = newcentroid[0]; 

256 
newcentroid_ptrs[1] = newcentroid[1]; 

257 
newcentroid_ptrs[2] = newcentroid[2]; 

258  
259  265 
for (j=0; j<3; j++) 
260  266 
olderror += elbg>utility[idx[j]]; 
261  267  
...  ...  
277  283  
278  284 
newerror = newutility[2]; 
279  285  
280 
newerror += simple_lbg(elbg>dim, newcentroid_ptrs, newutility, elbg>points,


286 
newerror += simple_lbg(elbg, elbg>dim, newcentroid, newutility, elbg>points,


281  287 
elbg>cells[idx[1]]); 
282  288  
283  289 
if (olderror > newerror) { 
284 
shift_codebook(elbg, idx, newcentroid_ptrs);


290 
shift_codebook(elbg, idx, newcentroid); 

285  291  
286  292 
elbg>error += newerror  olderror; 
287  293  
...  ...  
366  372 
elbg>nearest_cb = closest_cb; 
367  373 
elbg>points = points; 
368  374 
elbg>utility_inc = av_malloc(numCB*sizeof(int)); 
375 
elbg>scratchbuf = av_malloc(5*dim*sizeof(int)); 

369  376  
370  377 
elbg>rand_state = rand_state; 
371  378  
...  ...  
425  432 
av_free(list_buffer); 
426  433 
av_free(elbg>cells); 
427  434 
av_free(elbg>utility_inc); 
435 
av_free(elbg>scratchbuf); 

428  436 
} 
Also available in: Unified diff