diff options
author | Alex Converse <aconverse@google.com> | 2015-10-26 17:05:00 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2015-10-26 17:05:00 +0000 |
commit | e34c7e3f59ad7bf398c457865ca06af958c89f87 (patch) | |
tree | 2b20b619ac7cb0e8f2e7f7be8c758bb4037513bb /vp10/encoder | |
parent | e1a056e163dfb8217dc55ce77c5ba66087f1a822 (diff) | |
parent | 171fd8999fe8fdf04b5e836ff4eb0106ac6d7501 (diff) | |
download | libvpx-e34c7e3f59ad7bf398c457865ca06af958c89f87.tar libvpx-e34c7e3f59ad7bf398c457865ca06af958c89f87.tar.gz libvpx-e34c7e3f59ad7bf398c457865ca06af958c89f87.tar.bz2 libvpx-e34c7e3f59ad7bf398c457865ca06af958c89f87.zip |
Merge "palette: Replace rand() call with custom LCG."
Diffstat (limited to 'vp10/encoder')
-rw-r--r-- | vp10/encoder/palette.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/vp10/encoder/palette.c b/vp10/encoder/palette.c index b6fd6533e..fd5f402d8 100644 --- a/vp10/encoder/palette.c +++ b/vp10/encoder/palette.c @@ -39,12 +39,20 @@ void vp10_calc_indices(const double *data, const double *centroids, } } +// Generate a random number in the range [0, 32768). +static unsigned int lcg_rand16(unsigned int *state) { + *state = *state * 1103515245 + 12345; + return *state / 65536 % 32768; +} + static void calc_centroids(const double *data, double *centroids, const uint8_t *indices, int n, int k, int dim) { int i, j, index; int count[PALETTE_MAX_SIZE]; + unsigned int rand_state = data[0]; + + assert(n <= 32768); - srand((unsigned int) data[0]); memset(count, 0, sizeof(count[0]) * k); memset(centroids, 0, sizeof(centroids[0]) * k * dim); @@ -59,8 +67,7 @@ static void calc_centroids(const double *data, double *centroids, for (i = 0; i < k; ++i) { if (count[i] == 0) { - // TODO(huisu): replace rand() with something else. - memcpy(centroids + i * dim, data + (rand() % n) * dim, + memcpy(centroids + i * dim, data + (lcg_rand16(&rand_state) % n) * dim, sizeof(centroids[0]) * dim); } else { const double norm = 1.0 / count[i]; |