Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Xiph.Org
aom-rav1e
Commits
e34c7e3f
Commit
e34c7e3f
authored
Oct 26, 2015
by
Alex Converse
Committed by
Gerrit Code Review
Oct 26, 2015
Browse files
Options
Browse Files
Download
Plain Diff
Merge "palette: Replace rand() call with custom LCG."
parents
e1a056e1
171fd899
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
3 deletions
+10
-3
vp10/encoder/palette.c
vp10/encoder/palette.c
+10
-3
No files found.
vp10/encoder/palette.c
View file @
e34c7e3f
...
...
@@ -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
];
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment