1+ use rand:: rngs:: SmallRng ;
12use rand:: SeedableRng ;
23use rand_distr:: { Distribution , Normal , Triangular , Uniform } ;
34use std:: fmt;
@@ -41,29 +42,12 @@ impl fmt::Display for dyn Ditherer {
4142 }
4243}
4344
44- // `SmallRng` is 33% faster than `ThreadRng`, but we can do even better.
45- // `SmallRng` defaults to `Xoshiro256PlusPlus` on 64-bit platforms and
46- // `Xoshiro128PlusPlus` on 32-bit platforms. These are excellent for the
47- // general case. In our case of just 64-bit floating points, we can make
48- // some optimizations. Compared to `SmallRng`, these hand-picked generators
49- // improve performance by another 9% on 64-bit platforms and 2% on 32-bit
50- // platforms.
51- //
52- // For reference, see https://prng.di.unimi.it. Note that we do not use
53- // `Xoroshiro128Plus` or `Xoshiro128Plus` because they display low linear
54- // complexity in the lower four bits, which is not what we want:
55- // linearization is the very point of dithering.
56- #[ cfg( target_pointer_width = "64" ) ]
57- type Rng = rand_xoshiro:: Xoshiro256Plus ;
58- #[ cfg( not( target_pointer_width = "64" ) ) ]
59- type Rng = rand_xoshiro:: Xoshiro128StarStar ;
60-
61- fn create_rng ( ) -> Rng {
62- Rng :: from_entropy ( )
45+ fn create_rng ( ) -> SmallRng {
46+ SmallRng :: from_entropy ( )
6347}
6448
6549pub struct TriangularDitherer {
66- cached_rng : Rng ,
50+ cached_rng : SmallRng ,
6751 distribution : Triangular < f64 > ,
6852}
6953
@@ -90,7 +74,7 @@ impl TriangularDitherer {
9074}
9175
9276pub struct GaussianDitherer {
93- cached_rng : Rng ,
77+ cached_rng : SmallRng ,
9478 distribution : Normal < f64 > ,
9579}
9680
@@ -119,7 +103,7 @@ impl GaussianDitherer {
119103pub struct HighPassDitherer {
120104 active_channel : usize ,
121105 previous_noises : [ f64 ; NUM_CHANNELS ] ,
122- cached_rng : Rng ,
106+ cached_rng : SmallRng ,
123107 distribution : Uniform < f64 > ,
124108}
125109
0 commit comments