diff options
| author | Carl Hetherington <cth@carlh.net> | 2021-02-01 17:46:22 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2021-02-01 23:44:36 +0100 |
| commit | 49b655d3e1937018c46ed7f6a62e1157b247e426 (patch) | |
| tree | 45b4b6562e2575a458da5fef8a38af1437458ab6 /src/lib/rng.cc | |
| parent | e50967fb2b67b76e139f11206994bc0505cab76c (diff) | |
Use a predictable RNG when adding noise to low-bitrate images.
The recovery code assumes that encoding a given frame from the
same data will always give the same output; it always encodes frame 0
again to set things up properly and if that frame is a different size
to the previous run everything breaks.
Diffstat (limited to 'src/lib/rng.cc')
| -rw-r--r-- | src/lib/rng.cc | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/lib/rng.cc b/src/lib/rng.cc new file mode 100644 index 000000000..3fc41725d --- /dev/null +++ b/src/lib/rng.cc @@ -0,0 +1,42 @@ +/* + Copyright (C) 2020 Carl Hetherington <cth@carlh.net> + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>. + +*/ + + +#include "rng.h" +#include <stdint.h> + + +using namespace dcpomatic; + + +RNG::RNG (int32_t seed) + : _state (static_cast<uint32_t>(seed)) +{ + +} + + +int32_t RNG::get () +{ + uint32_t const b = ((_state >> 0) ^ (_state >> 1) ^ (_state >> 2) ^ (_state >> 7)); + _state = (_state >> 1) | (b << 23); + return static_cast<int32_t>(_state); +} + |
