comparison elbg.c @ 9154:aa459306ee59 libavcodec

Use FLG pseudo-random number generator in RoQ and ELBG
author vitor
date Sun, 08 Mar 2009 17:43:12 +0000
parents e9d9d946f213
children 678152bdb3a1
comparison
equal deleted inserted replaced
9153:4e91d96dd045 9154:aa459306ee59
23 * Codebook Generator using the ELBG algorithm 23 * Codebook Generator using the ELBG algorithm
24 */ 24 */
25 25
26 #include <string.h> 26 #include <string.h>
27 27
28 #include "libavutil/random.h" 28 #include "libavutil/lfg.h"
29 #include "elbg.h" 29 #include "elbg.h"
30 #include "avcodec.h" 30 #include "avcodec.h"
31 31
32 #define DELTA_ERR_MAX 0.1 ///< Precision of the ELBG algorithm (as percentual error) 32 #define DELTA_ERR_MAX 0.1 ///< Precision of the ELBG algorithm (as percentual error)
33 33
50 cell **cells; 50 cell **cells;
51 int *utility; 51 int *utility;
52 int *utility_inc; 52 int *utility_inc;
53 int *nearest_cb; 53 int *nearest_cb;
54 int *points; 54 int *points;
55 AVRandomState *rand_state; 55 AVLFG *rand_state;
56 } elbg_data; 56 } elbg_data;
57 57
58 static inline int distance_limited(int *a, int *b, int dim, int limit) 58 static inline int distance_limited(int *a, int *b, int dim, int limit)
59 { 59 {
60 int i, dist=0; 60 int i, dist=0;
103 103
104 static int get_high_utility_cell(elbg_data *elbg) 104 static int get_high_utility_cell(elbg_data *elbg)
105 { 105 {
106 int i=0; 106 int i=0;
107 /* Using linear search, do binary if it ever turns to be speed critical */ 107 /* Using linear search, do binary if it ever turns to be speed critical */
108 int r = av_random(elbg->rand_state)%(elbg->utility_inc[elbg->numCB-1]-1) + 1; 108 int r = av_lfg_get(elbg->rand_state)%(elbg->utility_inc[elbg->numCB-1]-1) + 1;
109 while (elbg->utility_inc[i] < r) 109 while (elbg->utility_inc[i] < r)
110 i++; 110 i++;
111 111
112 assert(!elbg->cells[i]); 112 assert(!elbg->cells[i]);
113 113
316 316
317 #define BIG_PRIME 433494437LL 317 #define BIG_PRIME 433494437LL
318 318
319 void ff_init_elbg(int *points, int dim, int numpoints, int *codebook, 319 void ff_init_elbg(int *points, int dim, int numpoints, int *codebook,
320 int numCB, int max_steps, int *closest_cb, 320 int numCB, int max_steps, int *closest_cb,
321 AVRandomState *rand_state) 321 AVLFG *rand_state)
322 { 322 {
323 int i, k; 323 int i, k;
324 324
325 if (numpoints > 24*numCB) { 325 if (numpoints > 24*numCB) {
326 /* ELBG is very costly for a big number of points. So if we have a lot 326 /* ELBG is very costly for a big number of points. So if we have a lot
343 343
344 } 344 }
345 345
346 void ff_do_elbg(int *points, int dim, int numpoints, int *codebook, 346 void ff_do_elbg(int *points, int dim, int numpoints, int *codebook,
347 int numCB, int max_steps, int *closest_cb, 347 int numCB, int max_steps, int *closest_cb,
348 AVRandomState *rand_state) 348 AVLFG *rand_state)
349 { 349 {
350 int dist; 350 int dist;
351 elbg_data elbg_d; 351 elbg_data elbg_d;
352 elbg_data *elbg = &elbg_d; 352 elbg_data *elbg = &elbg_d;
353 int i, j, k, last_error, steps=0; 353 int i, j, k, last_error, steps=0;