/src/brunsli/c/dec/ans_decode.cc
Line | Count | Source |
1 | | // Copyright (c) Google LLC 2019 |
2 | | // |
3 | | // Use of this source code is governed by an MIT-style |
4 | | // license that can be found in the LICENSE file or at |
5 | | // https://opensource.org/licenses/MIT. |
6 | | |
7 | | #include "./ans_decode.h" |
8 | | |
9 | | #include <vector> |
10 | | |
11 | | #include <brunsli/types.h> |
12 | | |
13 | | namespace brunsli { |
14 | | |
15 | 11.5k | bool ANSDecodingData::Init(const std::vector<uint32_t>& counts) { |
16 | 11.5k | size_t pos = 0; |
17 | 219k | for (size_t i = 0; i < counts.size(); ++i) { |
18 | 12.0M | for (size_t j = 0; j < counts[i]; ++j, ++pos) { |
19 | 11.8M | map_[pos].symbol_ = static_cast<uint8_t>(i); |
20 | 11.8M | map_[pos].freq_ = static_cast<uint16_t>(counts[i]); |
21 | 11.8M | map_[pos].offset_ = static_cast<uint16_t>(j); |
22 | 11.8M | } |
23 | 207k | } |
24 | 11.5k | return (pos == BRUNSLI_ANS_TAB_SIZE); |
25 | 11.5k | } |
26 | | |
27 | | } // namespace brunsli |