Coverage Report

Created: 2024-09-08 06:46

/src/draco/src/draco/compression/entropy/rans_symbol_decoder.h
Line
Count
Source (jump to first uncovered line)
1
// Copyright 2016 The Draco Authors.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//      http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
//
15
#ifndef DRACO_COMPRESSION_ENTROPY_RANS_SYMBOL_DECODER_H_
16
#define DRACO_COMPRESSION_ENTROPY_RANS_SYMBOL_DECODER_H_
17
18
#include "draco/compression/config/compression_shared.h"
19
#include "draco/compression/entropy/rans_symbol_coding.h"
20
#include "draco/core/decoder_buffer.h"
21
#include "draco/core/varint_decoding.h"
22
#include "draco/draco_features.h"
23
24
namespace draco {
25
26
// A helper class for decoding symbols using the rANS algorithm (see ans.h).
27
// The class can be used to decode the probability table and the data encoded
28
// by the RAnsSymbolEncoder. |unique_symbols_bit_length_t| must be the same as
29
// the one used for the corresponding RAnsSymbolEncoder.
30
template <int unique_symbols_bit_length_t>
31
class RAnsSymbolDecoder {
32
 public:
33
4.75k
  RAnsSymbolDecoder() : num_symbols_(0) {}
draco::RAnsSymbolDecoder<5>::RAnsSymbolDecoder()
Line
Count
Source
33
1.11k
  RAnsSymbolDecoder() : num_symbols_(0) {}
draco::RAnsSymbolDecoder<1>::RAnsSymbolDecoder()
Line
Count
Source
33
432
  RAnsSymbolDecoder() : num_symbols_(0) {}
draco::RAnsSymbolDecoder<2>::RAnsSymbolDecoder()
Line
Count
Source
33
256
  RAnsSymbolDecoder() : num_symbols_(0) {}
draco::RAnsSymbolDecoder<3>::RAnsSymbolDecoder()
Line
Count
Source
33
254
  RAnsSymbolDecoder() : num_symbols_(0) {}
draco::RAnsSymbolDecoder<4>::RAnsSymbolDecoder()
Line
Count
Source
33
201
  RAnsSymbolDecoder() : num_symbols_(0) {}
draco::RAnsSymbolDecoder<6>::RAnsSymbolDecoder()
Line
Count
Source
33
224
  RAnsSymbolDecoder() : num_symbols_(0) {}
draco::RAnsSymbolDecoder<7>::RAnsSymbolDecoder()
Line
Count
Source
33
292
  RAnsSymbolDecoder() : num_symbols_(0) {}
draco::RAnsSymbolDecoder<8>::RAnsSymbolDecoder()
Line
Count
Source
33
203
  RAnsSymbolDecoder() : num_symbols_(0) {}
draco::RAnsSymbolDecoder<9>::RAnsSymbolDecoder()
Line
Count
Source
33
124
  RAnsSymbolDecoder() : num_symbols_(0) {}
draco::RAnsSymbolDecoder<10>::RAnsSymbolDecoder()
Line
Count
Source
33
170
  RAnsSymbolDecoder() : num_symbols_(0) {}
draco::RAnsSymbolDecoder<11>::RAnsSymbolDecoder()
Line
Count
Source
33
179
  RAnsSymbolDecoder() : num_symbols_(0) {}
draco::RAnsSymbolDecoder<12>::RAnsSymbolDecoder()
Line
Count
Source
33
200
  RAnsSymbolDecoder() : num_symbols_(0) {}
draco::RAnsSymbolDecoder<13>::RAnsSymbolDecoder()
Line
Count
Source
33
198
  RAnsSymbolDecoder() : num_symbols_(0) {}
draco::RAnsSymbolDecoder<14>::RAnsSymbolDecoder()
Line
Count
Source
33
139
  RAnsSymbolDecoder() : num_symbols_(0) {}
draco::RAnsSymbolDecoder<15>::RAnsSymbolDecoder()
Line
Count
Source
33
241
  RAnsSymbolDecoder() : num_symbols_(0) {}
draco::RAnsSymbolDecoder<16>::RAnsSymbolDecoder()
Line
Count
Source
33
206
  RAnsSymbolDecoder() : num_symbols_(0) {}
draco::RAnsSymbolDecoder<17>::RAnsSymbolDecoder()
Line
Count
Source
33
170
  RAnsSymbolDecoder() : num_symbols_(0) {}
draco::RAnsSymbolDecoder<18>::RAnsSymbolDecoder()
Line
Count
Source
33
151
  RAnsSymbolDecoder() : num_symbols_(0) {}
34
35
  // Initialize the decoder and decode the probability table.
36
  bool Create(DecoderBuffer *buffer);
37
38
2.48k
  uint32_t num_symbols() const { return num_symbols_; }
draco::RAnsSymbolDecoder<5>::num_symbols() const
Line
Count
Source
38
504
  uint32_t num_symbols() const { return num_symbols_; }
draco::RAnsSymbolDecoder<1>::num_symbols() const
Line
Count
Source
38
114
  uint32_t num_symbols() const { return num_symbols_; }
draco::RAnsSymbolDecoder<2>::num_symbols() const
Line
Count
Source
38
153
  uint32_t num_symbols() const { return num_symbols_; }
draco::RAnsSymbolDecoder<3>::num_symbols() const
Line
Count
Source
38
164
  uint32_t num_symbols() const { return num_symbols_; }
draco::RAnsSymbolDecoder<4>::num_symbols() const
Line
Count
Source
38
116
  uint32_t num_symbols() const { return num_symbols_; }
draco::RAnsSymbolDecoder<6>::num_symbols() const
Line
Count
Source
38
163
  uint32_t num_symbols() const { return num_symbols_; }
draco::RAnsSymbolDecoder<7>::num_symbols() const
Line
Count
Source
38
173
  uint32_t num_symbols() const { return num_symbols_; }
draco::RAnsSymbolDecoder<8>::num_symbols() const
Line
Count
Source
38
119
  uint32_t num_symbols() const { return num_symbols_; }
draco::RAnsSymbolDecoder<9>::num_symbols() const
Line
Count
Source
38
44
  uint32_t num_symbols() const { return num_symbols_; }
draco::RAnsSymbolDecoder<10>::num_symbols() const
Line
Count
Source
38
88
  uint32_t num_symbols() const { return num_symbols_; }
draco::RAnsSymbolDecoder<11>::num_symbols() const
Line
Count
Source
38
101
  uint32_t num_symbols() const { return num_symbols_; }
draco::RAnsSymbolDecoder<12>::num_symbols() const
Line
Count
Source
38
115
  uint32_t num_symbols() const { return num_symbols_; }
draco::RAnsSymbolDecoder<13>::num_symbols() const
Line
Count
Source
38
103
  uint32_t num_symbols() const { return num_symbols_; }
draco::RAnsSymbolDecoder<14>::num_symbols() const
Line
Count
Source
38
87
  uint32_t num_symbols() const { return num_symbols_; }
draco::RAnsSymbolDecoder<15>::num_symbols() const
Line
Count
Source
38
126
  uint32_t num_symbols() const { return num_symbols_; }
draco::RAnsSymbolDecoder<16>::num_symbols() const
Line
Count
Source
38
102
  uint32_t num_symbols() const { return num_symbols_; }
draco::RAnsSymbolDecoder<17>::num_symbols() const
Line
Count
Source
38
109
  uint32_t num_symbols() const { return num_symbols_; }
draco::RAnsSymbolDecoder<18>::num_symbols() const
Line
Count
Source
38
108
  uint32_t num_symbols() const { return num_symbols_; }
39
40
  // Starts decoding from the buffer. The buffer will be advanced past the
41
  // encoded data after this call.
42
  bool StartDecoding(DecoderBuffer *buffer);
43
159M
  uint32_t DecodeSymbol() { return ans_.rans_read(); }
draco::RAnsSymbolDecoder<5>::DecodeSymbol()
Line
Count
Source
43
10.8M
  uint32_t DecodeSymbol() { return ans_.rans_read(); }
draco::RAnsSymbolDecoder<1>::DecodeSymbol()
Line
Count
Source
43
4.06M
  uint32_t DecodeSymbol() { return ans_.rans_read(); }
draco::RAnsSymbolDecoder<2>::DecodeSymbol()
Line
Count
Source
43
2.21M
  uint32_t DecodeSymbol() { return ans_.rans_read(); }
draco::RAnsSymbolDecoder<3>::DecodeSymbol()
Line
Count
Source
43
10.9M
  uint32_t DecodeSymbol() { return ans_.rans_read(); }
draco::RAnsSymbolDecoder<4>::DecodeSymbol()
Line
Count
Source
43
14.8M
  uint32_t DecodeSymbol() { return ans_.rans_read(); }
draco::RAnsSymbolDecoder<6>::DecodeSymbol()
Line
Count
Source
43
26.2M
  uint32_t DecodeSymbol() { return ans_.rans_read(); }
draco::RAnsSymbolDecoder<7>::DecodeSymbol()
Line
Count
Source
43
24.4M
  uint32_t DecodeSymbol() { return ans_.rans_read(); }
draco::RAnsSymbolDecoder<8>::DecodeSymbol()
Line
Count
Source
43
12.5M
  uint32_t DecodeSymbol() { return ans_.rans_read(); }
draco::RAnsSymbolDecoder<9>::DecodeSymbol()
Line
Count
Source
43
343k
  uint32_t DecodeSymbol() { return ans_.rans_read(); }
draco::RAnsSymbolDecoder<10>::DecodeSymbol()
Line
Count
Source
43
328k
  uint32_t DecodeSymbol() { return ans_.rans_read(); }
draco::RAnsSymbolDecoder<11>::DecodeSymbol()
Line
Count
Source
43
166k
  uint32_t DecodeSymbol() { return ans_.rans_read(); }
draco::RAnsSymbolDecoder<12>::DecodeSymbol()
Line
Count
Source
43
274k
  uint32_t DecodeSymbol() { return ans_.rans_read(); }
draco::RAnsSymbolDecoder<13>::DecodeSymbol()
Line
Count
Source
43
433k
  uint32_t DecodeSymbol() { return ans_.rans_read(); }
draco::RAnsSymbolDecoder<14>::DecodeSymbol()
Line
Count
Source
43
6.57M
  uint32_t DecodeSymbol() { return ans_.rans_read(); }
draco::RAnsSymbolDecoder<15>::DecodeSymbol()
Line
Count
Source
43
7.97M
  uint32_t DecodeSymbol() { return ans_.rans_read(); }
draco::RAnsSymbolDecoder<16>::DecodeSymbol()
Line
Count
Source
43
11.5M
  uint32_t DecodeSymbol() { return ans_.rans_read(); }
draco::RAnsSymbolDecoder<17>::DecodeSymbol()
Line
Count
Source
43
3.49M
  uint32_t DecodeSymbol() { return ans_.rans_read(); }
draco::RAnsSymbolDecoder<18>::DecodeSymbol()
Line
Count
Source
43
22.1M
  uint32_t DecodeSymbol() { return ans_.rans_read(); }
44
  void EndDecoding();
45
46
 private:
47
  static constexpr int rans_precision_bits_ =
48
      ComputeRAnsPrecisionFromUniqueSymbolsBitLength(
49
          unique_symbols_bit_length_t);
50
  static constexpr int rans_precision_ = 1 << rans_precision_bits_;
51
52
  std::vector<uint32_t> probability_table_;
53
  uint32_t num_symbols_;
54
  RAnsDecoder<rans_precision_bits_> ans_;
55
};
56
57
template <int unique_symbols_bit_length_t>
58
bool RAnsSymbolDecoder<unique_symbols_bit_length_t>::Create(
59
4.75k
    DecoderBuffer *buffer) {
60
  // Check that the DecoderBuffer version is set.
61
4.75k
  if (buffer->bitstream_version() == 0) {
62
0
    return false;
63
0
  }
64
  // Decode the number of alphabet symbols.
65
4.75k
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
66
4.75k
  if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
67
771
    if (!buffer->Decode(&num_symbols_)) {
68
5
      return false;
69
5
    }
70
71
771
  } else
72
3.98k
#endif
73
3.98k
  {
74
3.98k
    if (!DecodeVarint(&num_symbols_, buffer)) {
75
31
      return false;
76
31
    }
77
3.98k
  }
78
  // Check that decoded number of symbols is not unreasonably high. Remaining
79
  // buffer size must be at least |num_symbols| / 64 bytes to contain the
80
  // probability table. The |prob_data| below is one byte but it can be
81
  // theoretically stored for each 64th symbol.
82
4.71k
  if (num_symbols_ / 64 > buffer->remaining_size()) {
83
315
    return false;
84
315
  }
85
4.40k
  probability_table_.resize(num_symbols_);
86
4.40k
  if (num_symbols_ == 0) {
87
303
    return true;
88
303
  }
89
  // Decode the table.
90
8.84M
  for (uint32_t i = 0; i < num_symbols_; ++i) {
91
8.83M
    uint8_t prob_data = 0;
92
    // Decode the first byte and extract the number of extra bytes we need to
93
    // get, or the offset to the next symbol with non-zero probability.
94
8.83M
    if (!buffer->Decode(&prob_data)) {
95
371
      return false;
96
371
    }
97
    // Token is stored in the first two bits of the first byte. Values 0-2 are
98
    // used to indicate the number of extra bytes, and value 3 is a special
99
    // symbol used to denote run-length coding of zero probability entries.
100
    // See rans_symbol_encoder.h for more details.
101
8.83M
    const int token = prob_data & 3;
102
8.83M
    if (token == 3) {
103
4.60M
      const uint32_t offset = prob_data >> 2;
104
4.60M
      if (i + offset >= num_symbols_) {
105
518
        return false;
106
518
      }
107
      // Set zero probability for all symbols in the specified range.
108
171M
      for (uint32_t j = 0; j < offset + 1; ++j) {
109
166M
        probability_table_[i + j] = 0;
110
166M
      }
111
4.60M
      i += offset;
112
4.60M
    } else {
113
4.23M
      const int extra_bytes = token;
114
4.23M
      uint32_t prob = prob_data >> 2;
115
7.18M
      for (int b = 0; b < extra_bytes; ++b) {
116
2.95M
        uint8_t eb;
117
2.95M
        if (!buffer->Decode(&eb)) {
118
181
          return false;
119
181
        }
120
        // Shift 8 bits for each extra byte and subtract 2 for the two first
121
        // bits.
122
2.95M
        prob |= static_cast<uint32_t>(eb) << (8 * (b + 1) - 2);
123
2.95M
      }
124
4.23M
      probability_table_[i] = prob;
125
4.23M
    }
126
8.83M
  }
127
3.02k
  if (!ans_.rans_build_look_up_table(&probability_table_[0], num_symbols_)) {
128
656
    return false;
129
656
  }
130
2.37k
  return true;
131
3.02k
}
draco::RAnsSymbolDecoder<5>::Create(draco::DecoderBuffer*)
Line
Count
Source
59
1.11k
    DecoderBuffer *buffer) {
60
  // Check that the DecoderBuffer version is set.
61
1.11k
  if (buffer->bitstream_version() == 0) {
62
0
    return false;
63
0
  }
64
  // Decode the number of alphabet symbols.
65
1.11k
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
66
1.11k
  if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
67
168
    if (!buffer->Decode(&num_symbols_)) {
68
3
      return false;
69
3
    }
70
71
168
  } else
72
945
#endif
73
945
  {
74
945
    if (!DecodeVarint(&num_symbols_, buffer)) {
75
5
      return false;
76
5
    }
77
945
  }
78
  // Check that decoded number of symbols is not unreasonably high. Remaining
79
  // buffer size must be at least |num_symbols| / 64 bytes to contain the
80
  // probability table. The |prob_data| below is one byte but it can be
81
  // theoretically stored for each 64th symbol.
82
1.10k
  if (num_symbols_ / 64 > buffer->remaining_size()) {
83
126
    return false;
84
126
  }
85
979
  probability_table_.resize(num_symbols_);
86
979
  if (num_symbols_ == 0) {
87
245
    return true;
88
245
  }
89
  // Decode the table.
90
1.98M
  for (uint32_t i = 0; i < num_symbols_; ++i) {
91
1.98M
    uint8_t prob_data = 0;
92
    // Decode the first byte and extract the number of extra bytes we need to
93
    // get, or the offset to the next symbol with non-zero probability.
94
1.98M
    if (!buffer->Decode(&prob_data)) {
95
37
      return false;
96
37
    }
97
    // Token is stored in the first two bits of the first byte. Values 0-2 are
98
    // used to indicate the number of extra bytes, and value 3 is a special
99
    // symbol used to denote run-length coding of zero probability entries.
100
    // See rans_symbol_encoder.h for more details.
101
1.98M
    const int token = prob_data & 3;
102
1.98M
    if (token == 3) {
103
1.55M
      const uint32_t offset = prob_data >> 2;
104
1.55M
      if (i + offset >= num_symbols_) {
105
104
        return false;
106
104
      }
107
      // Set zero probability for all symbols in the specified range.
108
63.7M
      for (uint32_t j = 0; j < offset + 1; ++j) {
109
62.2M
        probability_table_[i + j] = 0;
110
62.2M
      }
111
1.55M
      i += offset;
112
1.55M
    } else {
113
437k
      const int extra_bytes = token;
114
437k
      uint32_t prob = prob_data >> 2;
115
665k
      for (int b = 0; b < extra_bytes; ++b) {
116
227k
        uint8_t eb;
117
227k
        if (!buffer->Decode(&eb)) {
118
25
          return false;
119
25
        }
120
        // Shift 8 bits for each extra byte and subtract 2 for the two first
121
        // bits.
122
227k
        prob |= static_cast<uint32_t>(eb) << (8 * (b + 1) - 2);
123
227k
      }
124
437k
      probability_table_[i] = prob;
125
437k
    }
126
1.98M
  }
127
568
  if (!ans_.rans_build_look_up_table(&probability_table_[0], num_symbols_)) {
128
122
    return false;
129
122
  }
130
446
  return true;
131
568
}
draco::RAnsSymbolDecoder<1>::Create(draco::DecoderBuffer*)
Line
Count
Source
59
432
    DecoderBuffer *buffer) {
60
  // Check that the DecoderBuffer version is set.
61
432
  if (buffer->bitstream_version() == 0) {
62
0
    return false;
63
0
  }
64
  // Decode the number of alphabet symbols.
65
432
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
66
432
  if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
67
38
    if (!buffer->Decode(&num_symbols_)) {
68
2
      return false;
69
2
    }
70
71
38
  } else
72
394
#endif
73
394
  {
74
394
    if (!DecodeVarint(&num_symbols_, buffer)) {
75
7
      return false;
76
7
    }
77
394
  }
78
  // Check that decoded number of symbols is not unreasonably high. Remaining
79
  // buffer size must be at least |num_symbols| / 64 bytes to contain the
80
  // probability table. The |prob_data| below is one byte but it can be
81
  // theoretically stored for each 64th symbol.
82
423
  if (num_symbols_ / 64 > buffer->remaining_size()) {
83
30
    return false;
84
30
  }
85
393
  probability_table_.resize(num_symbols_);
86
393
  if (num_symbols_ == 0) {
87
28
    return true;
88
28
  }
89
  // Decode the table.
90
1.89M
  for (uint32_t i = 0; i < num_symbols_; ++i) {
91
1.89M
    uint8_t prob_data = 0;
92
    // Decode the first byte and extract the number of extra bytes we need to
93
    // get, or the offset to the next symbol with non-zero probability.
94
1.89M
    if (!buffer->Decode(&prob_data)) {
95
29
      return false;
96
29
    }
97
    // Token is stored in the first two bits of the first byte. Values 0-2 are
98
    // used to indicate the number of extra bytes, and value 3 is a special
99
    // symbol used to denote run-length coding of zero probability entries.
100
    // See rans_symbol_encoder.h for more details.
101
1.89M
    const int token = prob_data & 3;
102
1.89M
    if (token == 3) {
103
659k
      const uint32_t offset = prob_data >> 2;
104
659k
      if (i + offset >= num_symbols_) {
105
58
        return false;
106
58
      }
107
      // Set zero probability for all symbols in the specified range.
108
16.3M
      for (uint32_t j = 0; j < offset + 1; ++j) {
109
15.6M
        probability_table_[i + j] = 0;
110
15.6M
      }
111
659k
      i += offset;
112
1.23M
    } else {
113
1.23M
      const int extra_bytes = token;
114
1.23M
      uint32_t prob = prob_data >> 2;
115
2.36M
      for (int b = 0; b < extra_bytes; ++b) {
116
1.12M
        uint8_t eb;
117
1.12M
        if (!buffer->Decode(&eb)) {
118
16
          return false;
119
16
        }
120
        // Shift 8 bits for each extra byte and subtract 2 for the two first
121
        // bits.
122
1.12M
        prob |= static_cast<uint32_t>(eb) << (8 * (b + 1) - 2);
123
1.12M
      }
124
1.23M
      probability_table_[i] = prob;
125
1.23M
    }
126
1.89M
  }
127
262
  if (!ans_.rans_build_look_up_table(&probability_table_[0], num_symbols_)) {
128
176
    return false;
129
176
  }
130
86
  return true;
131
262
}
draco::RAnsSymbolDecoder<2>::Create(draco::DecoderBuffer*)
Line
Count
Source
59
256
    DecoderBuffer *buffer) {
60
  // Check that the DecoderBuffer version is set.
61
256
  if (buffer->bitstream_version() == 0) {
62
0
    return false;
63
0
  }
64
  // Decode the number of alphabet symbols.
65
256
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
66
256
  if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
67
51
    if (!buffer->Decode(&num_symbols_)) {
68
0
      return false;
69
0
    }
70
71
51
  } else
72
205
#endif
73
205
  {
74
205
    if (!DecodeVarint(&num_symbols_, buffer)) {
75
3
      return false;
76
3
    }
77
205
  }
78
  // Check that decoded number of symbols is not unreasonably high. Remaining
79
  // buffer size must be at least |num_symbols| / 64 bytes to contain the
80
  // probability table. The |prob_data| below is one byte but it can be
81
  // theoretically stored for each 64th symbol.
82
253
  if (num_symbols_ / 64 > buffer->remaining_size()) {
83
10
    return false;
84
10
  }
85
243
  probability_table_.resize(num_symbols_);
86
243
  if (num_symbols_ == 0) {
87
4
    return true;
88
4
  }
89
  // Decode the table.
90
248k
  for (uint32_t i = 0; i < num_symbols_; ++i) {
91
247k
    uint8_t prob_data = 0;
92
    // Decode the first byte and extract the number of extra bytes we need to
93
    // get, or the offset to the next symbol with non-zero probability.
94
247k
    if (!buffer->Decode(&prob_data)) {
95
16
      return false;
96
16
    }
97
    // Token is stored in the first two bits of the first byte. Values 0-2 are
98
    // used to indicate the number of extra bytes, and value 3 is a special
99
    // symbol used to denote run-length coding of zero probability entries.
100
    // See rans_symbol_encoder.h for more details.
101
247k
    const int token = prob_data & 3;
102
247k
    if (token == 3) {
103
22.5k
      const uint32_t offset = prob_data >> 2;
104
22.5k
      if (i + offset >= num_symbols_) {
105
27
        return false;
106
27
      }
107
      // Set zero probability for all symbols in the specified range.
108
603k
      for (uint32_t j = 0; j < offset + 1; ++j) {
109
581k
        probability_table_[i + j] = 0;
110
581k
      }
111
22.5k
      i += offset;
112
225k
    } else {
113
225k
      const int extra_bytes = token;
114
225k
      uint32_t prob = prob_data >> 2;
115
441k
      for (int b = 0; b < extra_bytes; ++b) {
116
216k
        uint8_t eb;
117
216k
        if (!buffer->Decode(&eb)) {
118
11
          return false;
119
11
        }
120
        // Shift 8 bits for each extra byte and subtract 2 for the two first
121
        // bits.
122
216k
        prob |= static_cast<uint32_t>(eb) << (8 * (b + 1) - 2);
123
216k
      }
124
225k
      probability_table_[i] = prob;
125
225k
    }
126
247k
  }
127
185
  if (!ans_.rans_build_look_up_table(&probability_table_[0], num_symbols_)) {
128
36
    return false;
129
36
  }
130
149
  return true;
131
185
}
draco::RAnsSymbolDecoder<3>::Create(draco::DecoderBuffer*)
Line
Count
Source
59
254
    DecoderBuffer *buffer) {
60
  // Check that the DecoderBuffer version is set.
61
254
  if (buffer->bitstream_version() == 0) {
62
0
    return false;
63
0
  }
64
  // Decode the number of alphabet symbols.
65
254
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
66
254
  if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
67
59
    if (!buffer->Decode(&num_symbols_)) {
68
0
      return false;
69
0
    }
70
71
59
  } else
72
195
#endif
73
195
  {
74
195
    if (!DecodeVarint(&num_symbols_, buffer)) {
75
9
      return false;
76
9
    }
77
195
  }
78
  // Check that decoded number of symbols is not unreasonably high. Remaining
79
  // buffer size must be at least |num_symbols| / 64 bytes to contain the
80
  // probability table. The |prob_data| below is one byte but it can be
81
  // theoretically stored for each 64th symbol.
82
245
  if (num_symbols_ / 64 > buffer->remaining_size()) {
83
12
    return false;
84
12
  }
85
233
  probability_table_.resize(num_symbols_);
86
233
  if (num_symbols_ == 0) {
87
1
    return true;
88
1
  }
89
  // Decode the table.
90
301k
  for (uint32_t i = 0; i < num_symbols_; ++i) {
91
301k
    uint8_t prob_data = 0;
92
    // Decode the first byte and extract the number of extra bytes we need to
93
    // get, or the offset to the next symbol with non-zero probability.
94
301k
    if (!buffer->Decode(&prob_data)) {
95
22
      return false;
96
22
    }
97
    // Token is stored in the first two bits of the first byte. Values 0-2 are
98
    // used to indicate the number of extra bytes, and value 3 is a special
99
    // symbol used to denote run-length coding of zero probability entries.
100
    // See rans_symbol_encoder.h for more details.
101
301k
    const int token = prob_data & 3;
102
301k
    if (token == 3) {
103
96.8k
      const uint32_t offset = prob_data >> 2;
104
96.8k
      if (i + offset >= num_symbols_) {
105
27
        return false;
106
27
      }
107
      // Set zero probability for all symbols in the specified range.
108
4.10M
      for (uint32_t j = 0; j < offset + 1; ++j) {
109
4.00M
        probability_table_[i + j] = 0;
110
4.00M
      }
111
96.8k
      i += offset;
112
204k
    } else {
113
204k
      const int extra_bytes = token;
114
204k
      uint32_t prob = prob_data >> 2;
115
323k
      for (int b = 0; b < extra_bytes; ++b) {
116
118k
        uint8_t eb;
117
118k
        if (!buffer->Decode(&eb)) {
118
7
          return false;
119
7
        }
120
        // Shift 8 bits for each extra byte and subtract 2 for the two first
121
        // bits.
122
118k
        prob |= static_cast<uint32_t>(eb) << (8 * (b + 1) - 2);
123
118k
      }
124
204k
      probability_table_[i] = prob;
125
204k
    }
126
301k
  }
127
176
  if (!ans_.rans_build_look_up_table(&probability_table_[0], num_symbols_)) {
128
13
    return false;
129
13
  }
130
163
  return true;
131
176
}
draco::RAnsSymbolDecoder<4>::Create(draco::DecoderBuffer*)
Line
Count
Source
59
201
    DecoderBuffer *buffer) {
60
  // Check that the DecoderBuffer version is set.
61
201
  if (buffer->bitstream_version() == 0) {
62
0
    return false;
63
0
  }
64
  // Decode the number of alphabet symbols.
65
201
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
66
201
  if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
67
56
    if (!buffer->Decode(&num_symbols_)) {
68
0
      return false;
69
0
    }
70
71
56
  } else
72
145
#endif
73
145
  {
74
145
    if (!DecodeVarint(&num_symbols_, buffer)) {
75
0
      return false;
76
0
    }
77
145
  }
78
  // Check that decoded number of symbols is not unreasonably high. Remaining
79
  // buffer size must be at least |num_symbols| / 64 bytes to contain the
80
  // probability table. The |prob_data| below is one byte but it can be
81
  // theoretically stored for each 64th symbol.
82
201
  if (num_symbols_ / 64 > buffer->remaining_size()) {
83
15
    return false;
84
15
  }
85
186
  probability_table_.resize(num_symbols_);
86
186
  if (num_symbols_ == 0) {
87
3
    return true;
88
3
  }
89
  // Decode the table.
90
156k
  for (uint32_t i = 0; i < num_symbols_; ++i) {
91
155k
    uint8_t prob_data = 0;
92
    // Decode the first byte and extract the number of extra bytes we need to
93
    // get, or the offset to the next symbol with non-zero probability.
94
155k
    if (!buffer->Decode(&prob_data)) {
95
15
      return false;
96
15
    }
97
    // Token is stored in the first two bits of the first byte. Values 0-2 are
98
    // used to indicate the number of extra bytes, and value 3 is a special
99
    // symbol used to denote run-length coding of zero probability entries.
100
    // See rans_symbol_encoder.h for more details.
101
155k
    const int token = prob_data & 3;
102
155k
    if (token == 3) {
103
54.3k
      const uint32_t offset = prob_data >> 2;
104
54.3k
      if (i + offset >= num_symbols_) {
105
36
        return false;
106
36
      }
107
      // Set zero probability for all symbols in the specified range.
108
1.42M
      for (uint32_t j = 0; j < offset + 1; ++j) {
109
1.36M
        probability_table_[i + j] = 0;
110
1.36M
      }
111
54.3k
      i += offset;
112
101k
    } else {
113
101k
      const int extra_bytes = token;
114
101k
      uint32_t prob = prob_data >> 2;
115
183k
      for (int b = 0; b < extra_bytes; ++b) {
116
81.9k
        uint8_t eb;
117
81.9k
        if (!buffer->Decode(&eb)) {
118
8
          return false;
119
8
        }
120
        // Shift 8 bits for each extra byte and subtract 2 for the two first
121
        // bits.
122
81.9k
        prob |= static_cast<uint32_t>(eb) << (8 * (b + 1) - 2);
123
81.9k
      }
124
101k
      probability_table_[i] = prob;
125
101k
    }
126
155k
  }
127
124
  if (!ans_.rans_build_look_up_table(&probability_table_[0], num_symbols_)) {
128
11
    return false;
129
11
  }
130
113
  return true;
131
124
}
draco::RAnsSymbolDecoder<6>::Create(draco::DecoderBuffer*)
Line
Count
Source
59
224
    DecoderBuffer *buffer) {
60
  // Check that the DecoderBuffer version is set.
61
224
  if (buffer->bitstream_version() == 0) {
62
0
    return false;
63
0
  }
64
  // Decode the number of alphabet symbols.
65
224
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
66
224
  if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
67
17
    if (!buffer->Decode(&num_symbols_)) {
68
0
      return false;
69
0
    }
70
71
17
  } else
72
207
#endif
73
207
  {
74
207
    if (!DecodeVarint(&num_symbols_, buffer)) {
75
0
      return false;
76
0
    }
77
207
  }
78
  // Check that decoded number of symbols is not unreasonably high. Remaining
79
  // buffer size must be at least |num_symbols| / 64 bytes to contain the
80
  // probability table. The |prob_data| below is one byte but it can be
81
  // theoretically stored for each 64th symbol.
82
224
  if (num_symbols_ / 64 > buffer->remaining_size()) {
83
8
    return false;
84
8
  }
85
216
  probability_table_.resize(num_symbols_);
86
216
  if (num_symbols_ == 0) {
87
1
    return true;
88
1
  }
89
  // Decode the table.
90
79.4k
  for (uint32_t i = 0; i < num_symbols_; ++i) {
91
79.2k
    uint8_t prob_data = 0;
92
    // Decode the first byte and extract the number of extra bytes we need to
93
    // get, or the offset to the next symbol with non-zero probability.
94
79.2k
    if (!buffer->Decode(&prob_data)) {
95
14
      return false;
96
14
    }
97
    // Token is stored in the first two bits of the first byte. Values 0-2 are
98
    // used to indicate the number of extra bytes, and value 3 is a special
99
    // symbol used to denote run-length coding of zero probability entries.
100
    // See rans_symbol_encoder.h for more details.
101
79.2k
    const int token = prob_data & 3;
102
79.2k
    if (token == 3) {
103
9.91k
      const uint32_t offset = prob_data >> 2;
104
9.91k
      if (i + offset >= num_symbols_) {
105
15
        return false;
106
15
      }
107
      // Set zero probability for all symbols in the specified range.
108
332k
      for (uint32_t j = 0; j < offset + 1; ++j) {
109
322k
        probability_table_[i + j] = 0;
110
322k
      }
111
9.90k
      i += offset;
112
69.3k
    } else {
113
69.3k
      const int extra_bytes = token;
114
69.3k
      uint32_t prob = prob_data >> 2;
115
94.9k
      for (int b = 0; b < extra_bytes; ++b) {
116
25.6k
        uint8_t eb;
117
25.6k
        if (!buffer->Decode(&eb)) {
118
9
          return false;
119
9
        }
120
        // Shift 8 bits for each extra byte and subtract 2 for the two first
121
        // bits.
122
25.6k
        prob |= static_cast<uint32_t>(eb) << (8 * (b + 1) - 2);
123
25.6k
      }
124
69.3k
      probability_table_[i] = prob;
125
69.3k
    }
126
79.2k
  }
127
177
  if (!ans_.rans_build_look_up_table(&probability_table_[0], num_symbols_)) {
128
15
    return false;
129
15
  }
130
162
  return true;
131
177
}
draco::RAnsSymbolDecoder<7>::Create(draco::DecoderBuffer*)
Line
Count
Source
59
292
    DecoderBuffer *buffer) {
60
  // Check that the DecoderBuffer version is set.
61
292
  if (buffer->bitstream_version() == 0) {
62
0
    return false;
63
0
  }
64
  // Decode the number of alphabet symbols.
65
292
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
66
292
  if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
67
56
    if (!buffer->Decode(&num_symbols_)) {
68
0
      return false;
69
0
    }
70
71
56
  } else
72
236
#endif
73
236
  {
74
236
    if (!DecodeVarint(&num_symbols_, buffer)) {
75
1
      return false;
76
1
    }
77
236
  }
78
  // Check that decoded number of symbols is not unreasonably high. Remaining
79
  // buffer size must be at least |num_symbols| / 64 bytes to contain the
80
  // probability table. The |prob_data| below is one byte but it can be
81
  // theoretically stored for each 64th symbol.
82
291
  if (num_symbols_ / 64 > buffer->remaining_size()) {
83
10
    return false;
84
10
  }
85
281
  probability_table_.resize(num_symbols_);
86
281
  if (num_symbols_ == 0) {
87
7
    return true;
88
7
  }
89
  // Decode the table.
90
995k
  for (uint32_t i = 0; i < num_symbols_; ++i) {
91
994k
    uint8_t prob_data = 0;
92
    // Decode the first byte and extract the number of extra bytes we need to
93
    // get, or the offset to the next symbol with non-zero probability.
94
994k
    if (!buffer->Decode(&prob_data)) {
95
41
      return false;
96
41
    }
97
    // Token is stored in the first two bits of the first byte. Values 0-2 are
98
    // used to indicate the number of extra bytes, and value 3 is a special
99
    // symbol used to denote run-length coding of zero probability entries.
100
    // See rans_symbol_encoder.h for more details.
101
994k
    const int token = prob_data & 3;
102
994k
    if (token == 3) {
103
257k
      const uint32_t offset = prob_data >> 2;
104
257k
      if (i + offset >= num_symbols_) {
105
33
        return false;
106
33
      }
107
      // Set zero probability for all symbols in the specified range.
108
9.05M
      for (uint32_t j = 0; j < offset + 1; ++j) {
109
8.79M
        probability_table_[i + j] = 0;
110
8.79M
      }
111
257k
      i += offset;
112
737k
    } else {
113
737k
      const int extra_bytes = token;
114
737k
      uint32_t prob = prob_data >> 2;
115
1.25M
      for (int b = 0; b < extra_bytes; ++b) {
116
521k
        uint8_t eb;
117
521k
        if (!buffer->Decode(&eb)) {
118
11
          return false;
119
11
        }
120
        // Shift 8 bits for each extra byte and subtract 2 for the two first
121
        // bits.
122
521k
        prob |= static_cast<uint32_t>(eb) << (8 * (b + 1) - 2);
123
521k
      }
124
737k
      probability_table_[i] = prob;
125
737k
    }
126
994k
  }
127
189
  if (!ans_.rans_build_look_up_table(&probability_table_[0], num_symbols_)) {
128
23
    return false;
129
23
  }
130
166
  return true;
131
189
}
draco::RAnsSymbolDecoder<8>::Create(draco::DecoderBuffer*)
Line
Count
Source
59
203
    DecoderBuffer *buffer) {
60
  // Check that the DecoderBuffer version is set.
61
203
  if (buffer->bitstream_version() == 0) {
62
0
    return false;
63
0
  }
64
  // Decode the number of alphabet symbols.
65
203
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
66
203
  if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
67
29
    if (!buffer->Decode(&num_symbols_)) {
68
0
      return false;
69
0
    }
70
71
29
  } else
72
174
#endif
73
174
  {
74
174
    if (!DecodeVarint(&num_symbols_, buffer)) {
75
2
      return false;
76
2
    }
77
174
  }
78
  // Check that decoded number of symbols is not unreasonably high. Remaining
79
  // buffer size must be at least |num_symbols| / 64 bytes to contain the
80
  // probability table. The |prob_data| below is one byte but it can be
81
  // theoretically stored for each 64th symbol.
82
201
  if (num_symbols_ / 64 > buffer->remaining_size()) {
83
6
    return false;
84
6
  }
85
195
  probability_table_.resize(num_symbols_);
86
195
  if (num_symbols_ == 0) {
87
0
    return true;
88
0
  }
89
  // Decode the table.
90
655k
  for (uint32_t i = 0; i < num_symbols_; ++i) {
91
655k
    uint8_t prob_data = 0;
92
    // Decode the first byte and extract the number of extra bytes we need to
93
    // get, or the offset to the next symbol with non-zero probability.
94
655k
    if (!buffer->Decode(&prob_data)) {
95
27
      return false;
96
27
    }
97
    // Token is stored in the first two bits of the first byte. Values 0-2 are
98
    // used to indicate the number of extra bytes, and value 3 is a special
99
    // symbol used to denote run-length coding of zero probability entries.
100
    // See rans_symbol_encoder.h for more details.
101
655k
    const int token = prob_data & 3;
102
655k
    if (token == 3) {
103
162k
      const uint32_t offset = prob_data >> 2;
104
162k
      if (i + offset >= num_symbols_) {
105
22
        return false;
106
22
      }
107
      // Set zero probability for all symbols in the specified range.
108
5.12M
      for (uint32_t j = 0; j < offset + 1; ++j) {
109
4.96M
        probability_table_[i + j] = 0;
110
4.96M
      }
111
162k
      i += offset;
112
492k
    } else {
113
492k
      const int extra_bytes = token;
114
492k
      uint32_t prob = prob_data >> 2;
115
730k
      for (int b = 0; b < extra_bytes; ++b) {
116
237k
        uint8_t eb;
117
237k
        if (!buffer->Decode(&eb)) {
118
9
          return false;
119
9
        }
120
        // Shift 8 bits for each extra byte and subtract 2 for the two first
121
        // bits.
122
237k
        prob |= static_cast<uint32_t>(eb) << (8 * (b + 1) - 2);
123
237k
      }
124
492k
      probability_table_[i] = prob;
125
492k
    }
126
655k
  }
127
137
  if (!ans_.rans_build_look_up_table(&probability_table_[0], num_symbols_)) {
128
18
    return false;
129
18
  }
130
119
  return true;
131
137
}
draco::RAnsSymbolDecoder<9>::Create(draco::DecoderBuffer*)
Line
Count
Source
59
124
    DecoderBuffer *buffer) {
60
  // Check that the DecoderBuffer version is set.
61
124
  if (buffer->bitstream_version() == 0) {
62
0
    return false;
63
0
  }
64
  // Decode the number of alphabet symbols.
65
124
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
66
124
  if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
67
6
    if (!buffer->Decode(&num_symbols_)) {
68
0
      return false;
69
0
    }
70
71
6
  } else
72
118
#endif
73
118
  {
74
118
    if (!DecodeVarint(&num_symbols_, buffer)) {
75
0
      return false;
76
0
    }
77
118
  }
78
  // Check that decoded number of symbols is not unreasonably high. Remaining
79
  // buffer size must be at least |num_symbols| / 64 bytes to contain the
80
  // probability table. The |prob_data| below is one byte but it can be
81
  // theoretically stored for each 64th symbol.
82
124
  if (num_symbols_ / 64 > buffer->remaining_size()) {
83
7
    return false;
84
7
  }
85
117
  probability_table_.resize(num_symbols_);
86
117
  if (num_symbols_ == 0) {
87
0
    return true;
88
0
  }
89
  // Decode the table.
90
9.23k
  for (uint32_t i = 0; i < num_symbols_; ++i) {
91
9.16k
    uint8_t prob_data = 0;
92
    // Decode the first byte and extract the number of extra bytes we need to
93
    // get, or the offset to the next symbol with non-zero probability.
94
9.16k
    if (!buffer->Decode(&prob_data)) {
95
20
      return false;
96
20
    }
97
    // Token is stored in the first two bits of the first byte. Values 0-2 are
98
    // used to indicate the number of extra bytes, and value 3 is a special
99
    // symbol used to denote run-length coding of zero probability entries.
100
    // See rans_symbol_encoder.h for more details.
101
9.14k
    const int token = prob_data & 3;
102
9.14k
    if (token == 3) {
103
2.73k
      const uint32_t offset = prob_data >> 2;
104
2.73k
      if (i + offset >= num_symbols_) {
105
18
        return false;
106
18
      }
107
      // Set zero probability for all symbols in the specified range.
108
88.0k
      for (uint32_t j = 0; j < offset + 1; ++j) {
109
85.3k
        probability_table_[i + j] = 0;
110
85.3k
      }
111
2.72k
      i += offset;
112
6.40k
    } else {
113
6.40k
      const int extra_bytes = token;
114
6.40k
      uint32_t prob = prob_data >> 2;
115
10.9k
      for (int b = 0; b < extra_bytes; ++b) {
116
4.54k
        uint8_t eb;
117
4.54k
        if (!buffer->Decode(&eb)) {
118
8
          return false;
119
8
        }
120
        // Shift 8 bits for each extra byte and subtract 2 for the two first
121
        // bits.
122
4.53k
        prob |= static_cast<uint32_t>(eb) << (8 * (b + 1) - 2);
123
4.53k
      }
124
6.39k
      probability_table_[i] = prob;
125
6.39k
    }
126
9.14k
  }
127
71
  if (!ans_.rans_build_look_up_table(&probability_table_[0], num_symbols_)) {
128
27
    return false;
129
27
  }
130
44
  return true;
131
71
}
draco::RAnsSymbolDecoder<10>::Create(draco::DecoderBuffer*)
Line
Count
Source
59
170
    DecoderBuffer *buffer) {
60
  // Check that the DecoderBuffer version is set.
61
170
  if (buffer->bitstream_version() == 0) {
62
0
    return false;
63
0
  }
64
  // Decode the number of alphabet symbols.
65
170
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
66
170
  if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
67
17
    if (!buffer->Decode(&num_symbols_)) {
68
0
      return false;
69
0
    }
70
71
17
  } else
72
153
#endif
73
153
  {
74
153
    if (!DecodeVarint(&num_symbols_, buffer)) {
75
0
      return false;
76
0
    }
77
153
  }
78
  // Check that decoded number of symbols is not unreasonably high. Remaining
79
  // buffer size must be at least |num_symbols| / 64 bytes to contain the
80
  // probability table. The |prob_data| below is one byte but it can be
81
  // theoretically stored for each 64th symbol.
82
170
  if (num_symbols_ / 64 > buffer->remaining_size()) {
83
16
    return false;
84
16
  }
85
154
  probability_table_.resize(num_symbols_);
86
154
  if (num_symbols_ == 0) {
87
1
    return true;
88
1
  }
89
  // Decode the table.
90
24.3k
  for (uint32_t i = 0; i < num_symbols_; ++i) {
91
24.2k
    uint8_t prob_data = 0;
92
    // Decode the first byte and extract the number of extra bytes we need to
93
    // get, or the offset to the next symbol with non-zero probability.
94
24.2k
    if (!buffer->Decode(&prob_data)) {
95
11
      return false;
96
11
    }
97
    // Token is stored in the first two bits of the first byte. Values 0-2 are
98
    // used to indicate the number of extra bytes, and value 3 is a special
99
    // symbol used to denote run-length coding of zero probability entries.
100
    // See rans_symbol_encoder.h for more details.
101
24.2k
    const int token = prob_data & 3;
102
24.2k
    if (token == 3) {
103
6.28k
      const uint32_t offset = prob_data >> 2;
104
6.28k
      if (i + offset >= num_symbols_) {
105
16
        return false;
106
16
      }
107
      // Set zero probability for all symbols in the specified range.
108
226k
      for (uint32_t j = 0; j < offset + 1; ++j) {
109
220k
        probability_table_[i + j] = 0;
110
220k
      }
111
6.27k
      i += offset;
112
17.9k
    } else {
113
17.9k
      const int extra_bytes = token;
114
17.9k
      uint32_t prob = prob_data >> 2;
115
28.9k
      for (int b = 0; b < extra_bytes; ++b) {
116
10.9k
        uint8_t eb;
117
10.9k
        if (!buffer->Decode(&eb)) {
118
11
          return false;
119
11
        }
120
        // Shift 8 bits for each extra byte and subtract 2 for the two first
121
        // bits.
122
10.9k
        prob |= static_cast<uint32_t>(eb) << (8 * (b + 1) - 2);
123
10.9k
      }
124
17.9k
      probability_table_[i] = prob;
125
17.9k
    }
126
24.2k
  }
127
115
  if (!ans_.rans_build_look_up_table(&probability_table_[0], num_symbols_)) {
128
28
    return false;
129
28
  }
130
87
  return true;
131
115
}
draco::RAnsSymbolDecoder<11>::Create(draco::DecoderBuffer*)
Line
Count
Source
59
179
    DecoderBuffer *buffer) {
60
  // Check that the DecoderBuffer version is set.
61
179
  if (buffer->bitstream_version() == 0) {
62
0
    return false;
63
0
  }
64
  // Decode the number of alphabet symbols.
65
179
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
66
179
  if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
67
15
    if (!buffer->Decode(&num_symbols_)) {
68
0
      return false;
69
0
    }
70
71
15
  } else
72
164
#endif
73
164
  {
74
164
    if (!DecodeVarint(&num_symbols_, buffer)) {
75
0
      return false;
76
0
    }
77
164
  }
78
  // Check that decoded number of symbols is not unreasonably high. Remaining
79
  // buffer size must be at least |num_symbols| / 64 bytes to contain the
80
  // probability table. The |prob_data| below is one byte but it can be
81
  // theoretically stored for each 64th symbol.
82
179
  if (num_symbols_ / 64 > buffer->remaining_size()) {
83
2
    return false;
84
2
  }
85
177
  probability_table_.resize(num_symbols_);
86
177
  if (num_symbols_ == 0) {
87
1
    return true;
88
1
  }
89
  // Decode the table.
90
60.6k
  for (uint32_t i = 0; i < num_symbols_; ++i) {
91
60.5k
    uint8_t prob_data = 0;
92
    // Decode the first byte and extract the number of extra bytes we need to
93
    // get, or the offset to the next symbol with non-zero probability.
94
60.5k
    if (!buffer->Decode(&prob_data)) {
95
17
      return false;
96
17
    }
97
    // Token is stored in the first two bits of the first byte. Values 0-2 are
98
    // used to indicate the number of extra bytes, and value 3 is a special
99
    // symbol used to denote run-length coding of zero probability entries.
100
    // See rans_symbol_encoder.h for more details.
101
60.5k
    const int token = prob_data & 3;
102
60.5k
    if (token == 3) {
103
11.9k
      const uint32_t offset = prob_data >> 2;
104
11.9k
      if (i + offset >= num_symbols_) {
105
20
        return false;
106
20
      }
107
      // Set zero probability for all symbols in the specified range.
108
376k
      for (uint32_t j = 0; j < offset + 1; ++j) {
109
364k
        probability_table_[i + j] = 0;
110
364k
      }
111
11.8k
      i += offset;
112
48.6k
    } else {
113
48.6k
      const int extra_bytes = token;
114
48.6k
      uint32_t prob = prob_data >> 2;
115
78.7k
      for (int b = 0; b < extra_bytes; ++b) {
116
30.1k
        uint8_t eb;
117
30.1k
        if (!buffer->Decode(&eb)) {
118
7
          return false;
119
7
        }
120
        // Shift 8 bits for each extra byte and subtract 2 for the two first
121
        // bits.
122
30.1k
        prob |= static_cast<uint32_t>(eb) << (8 * (b + 1) - 2);
123
30.1k
      }
124
48.6k
      probability_table_[i] = prob;
125
48.6k
    }
126
60.5k
  }
127
132
  if (!ans_.rans_build_look_up_table(&probability_table_[0], num_symbols_)) {
128
32
    return false;
129
32
  }
130
100
  return true;
131
132
}
draco::RAnsSymbolDecoder<12>::Create(draco::DecoderBuffer*)
Line
Count
Source
59
200
    DecoderBuffer *buffer) {
60
  // Check that the DecoderBuffer version is set.
61
200
  if (buffer->bitstream_version() == 0) {
62
0
    return false;
63
0
  }
64
  // Decode the number of alphabet symbols.
65
200
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
66
200
  if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
67
54
    if (!buffer->Decode(&num_symbols_)) {
68
0
      return false;
69
0
    }
70
71
54
  } else
72
146
#endif
73
146
  {
74
146
    if (!DecodeVarint(&num_symbols_, buffer)) {
75
0
      return false;
76
0
    }
77
146
  }
78
  // Check that decoded number of symbols is not unreasonably high. Remaining
79
  // buffer size must be at least |num_symbols| / 64 bytes to contain the
80
  // probability table. The |prob_data| below is one byte but it can be
81
  // theoretically stored for each 64th symbol.
82
200
  if (num_symbols_ / 64 > buffer->remaining_size()) {
83
9
    return false;
84
9
  }
85
191
  probability_table_.resize(num_symbols_);
86
191
  if (num_symbols_ == 0) {
87
1
    return true;
88
1
  }
89
  // Decode the table.
90
1.33M
  for (uint32_t i = 0; i < num_symbols_; ++i) {
91
1.33M
    uint8_t prob_data = 0;
92
    // Decode the first byte and extract the number of extra bytes we need to
93
    // get, or the offset to the next symbol with non-zero probability.
94
1.33M
    if (!buffer->Decode(&prob_data)) {
95
14
      return false;
96
14
    }
97
    // Token is stored in the first two bits of the first byte. Values 0-2 are
98
    // used to indicate the number of extra bytes, and value 3 is a special
99
    // symbol used to denote run-length coding of zero probability entries.
100
    // See rans_symbol_encoder.h for more details.
101
1.33M
    const int token = prob_data & 3;
102
1.33M
    if (token == 3) {
103
1.30M
      const uint32_t offset = prob_data >> 2;
104
1.30M
      if (i + offset >= num_symbols_) {
105
18
        return false;
106
18
      }
107
      // Set zero probability for all symbols in the specified range.
108
44.9M
      for (uint32_t j = 0; j < offset + 1; ++j) {
109
43.6M
        probability_table_[i + j] = 0;
110
43.6M
      }
111
1.30M
      i += offset;
112
1.30M
    } else {
113
29.9k
      const int extra_bytes = token;
114
29.9k
      uint32_t prob = prob_data >> 2;
115
50.2k
      for (int b = 0; b < extra_bytes; ++b) {
116
20.2k
        uint8_t eb;
117
20.2k
        if (!buffer->Decode(&eb)) {
118
14
          return false;
119
14
        }
120
        // Shift 8 bits for each extra byte and subtract 2 for the two first
121
        // bits.
122
20.2k
        prob |= static_cast<uint32_t>(eb) << (8 * (b + 1) - 2);
123
20.2k
      }
124
29.9k
      probability_table_[i] = prob;
125
29.9k
    }
126
1.33M
  }
127
144
  if (!ans_.rans_build_look_up_table(&probability_table_[0], num_symbols_)) {
128
30
    return false;
129
30
  }
130
114
  return true;
131
144
}
draco::RAnsSymbolDecoder<13>::Create(draco::DecoderBuffer*)
Line
Count
Source
59
198
    DecoderBuffer *buffer) {
60
  // Check that the DecoderBuffer version is set.
61
198
  if (buffer->bitstream_version() == 0) {
62
0
    return false;
63
0
  }
64
  // Decode the number of alphabet symbols.
65
198
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
66
198
  if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
67
11
    if (!buffer->Decode(&num_symbols_)) {
68
0
      return false;
69
0
    }
70
71
11
  } else
72
187
#endif
73
187
  {
74
187
    if (!DecodeVarint(&num_symbols_, buffer)) {
75
4
      return false;
76
4
    }
77
187
  }
78
  // Check that decoded number of symbols is not unreasonably high. Remaining
79
  // buffer size must be at least |num_symbols| / 64 bytes to contain the
80
  // probability table. The |prob_data| below is one byte but it can be
81
  // theoretically stored for each 64th symbol.
82
194
  if (num_symbols_ / 64 > buffer->remaining_size()) {
83
12
    return false;
84
12
  }
85
182
  probability_table_.resize(num_symbols_);
86
182
  if (num_symbols_ == 0) {
87
9
    return true;
88
9
  }
89
  // Decode the table.
90
33.9k
  for (uint32_t i = 0; i < num_symbols_; ++i) {
91
33.8k
    uint8_t prob_data = 0;
92
    // Decode the first byte and extract the number of extra bytes we need to
93
    // get, or the offset to the next symbol with non-zero probability.
94
33.8k
    if (!buffer->Decode(&prob_data)) {
95
20
      return false;
96
20
    }
97
    // Token is stored in the first two bits of the first byte. Values 0-2 are
98
    // used to indicate the number of extra bytes, and value 3 is a special
99
    // symbol used to denote run-length coding of zero probability entries.
100
    // See rans_symbol_encoder.h for more details.
101
33.8k
    const int token = prob_data & 3;
102
33.8k
    if (token == 3) {
103
4.65k
      const uint32_t offset = prob_data >> 2;
104
4.65k
      if (i + offset >= num_symbols_) {
105
8
        return false;
106
8
      }
107
      // Set zero probability for all symbols in the specified range.
108
107k
      for (uint32_t j = 0; j < offset + 1; ++j) {
109
102k
        probability_table_[i + j] = 0;
110
102k
      }
111
4.64k
      i += offset;
112
29.1k
    } else {
113
29.1k
      const int extra_bytes = token;
114
29.1k
      uint32_t prob = prob_data >> 2;
115
56.1k
      for (int b = 0; b < extra_bytes; ++b) {
116
27.0k
        uint8_t eb;
117
27.0k
        if (!buffer->Decode(&eb)) {
118
8
          return false;
119
8
        }
120
        // Shift 8 bits for each extra byte and subtract 2 for the two first
121
        // bits.
122
27.0k
        prob |= static_cast<uint32_t>(eb) << (8 * (b + 1) - 2);
123
27.0k
      }
124
29.1k
      probability_table_[i] = prob;
125
29.1k
    }
126
33.8k
  }
127
137
  if (!ans_.rans_build_look_up_table(&probability_table_[0], num_symbols_)) {
128
43
    return false;
129
43
  }
130
94
  return true;
131
137
}
draco::RAnsSymbolDecoder<14>::Create(draco::DecoderBuffer*)
Line
Count
Source
59
139
    DecoderBuffer *buffer) {
60
  // Check that the DecoderBuffer version is set.
61
139
  if (buffer->bitstream_version() == 0) {
62
0
    return false;
63
0
  }
64
  // Decode the number of alphabet symbols.
65
139
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
66
139
  if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
67
8
    if (!buffer->Decode(&num_symbols_)) {
68
0
      return false;
69
0
    }
70
71
8
  } else
72
131
#endif
73
131
  {
74
131
    if (!DecodeVarint(&num_symbols_, buffer)) {
75
0
      return false;
76
0
    }
77
131
  }
78
  // Check that decoded number of symbols is not unreasonably high. Remaining
79
  // buffer size must be at least |num_symbols| / 64 bytes to contain the
80
  // probability table. The |prob_data| below is one byte but it can be
81
  // theoretically stored for each 64th symbol.
82
139
  if (num_symbols_ / 64 > buffer->remaining_size()) {
83
7
    return false;
84
7
  }
85
132
  probability_table_.resize(num_symbols_);
86
132
  if (num_symbols_ == 0) {
87
0
    return true;
88
0
  }
89
  // Decode the table.
90
894k
  for (uint32_t i = 0; i < num_symbols_; ++i) {
91
894k
    uint8_t prob_data = 0;
92
    // Decode the first byte and extract the number of extra bytes we need to
93
    // get, or the offset to the next symbol with non-zero probability.
94
894k
    if (!buffer->Decode(&prob_data)) {
95
12
      return false;
96
12
    }
97
    // Token is stored in the first two bits of the first byte. Values 0-2 are
98
    // used to indicate the number of extra bytes, and value 3 is a special
99
    // symbol used to denote run-length coding of zero probability entries.
100
    // See rans_symbol_encoder.h for more details.
101
894k
    const int token = prob_data & 3;
102
894k
    if (token == 3) {
103
371k
      const uint32_t offset = prob_data >> 2;
104
371k
      if (i + offset >= num_symbols_) {
105
11
        return false;
106
11
      }
107
      // Set zero probability for all symbols in the specified range.
108
21.6M
      for (uint32_t j = 0; j < offset + 1; ++j) {
109
21.2M
        probability_table_[i + j] = 0;
110
21.2M
      }
111
371k
      i += offset;
112
522k
    } else {
113
522k
      const int extra_bytes = token;
114
522k
      uint32_t prob = prob_data >> 2;
115
773k
      for (int b = 0; b < extra_bytes; ++b) {
116
250k
        uint8_t eb;
117
250k
        if (!buffer->Decode(&eb)) {
118
10
          return false;
119
10
        }
120
        // Shift 8 bits for each extra byte and subtract 2 for the two first
121
        // bits.
122
250k
        prob |= static_cast<uint32_t>(eb) << (8 * (b + 1) - 2);
123
250k
      }
124
522k
      probability_table_[i] = prob;
125
522k
    }
126
894k
  }
127
99
  if (!ans_.rans_build_look_up_table(&probability_table_[0], num_symbols_)) {
128
12
    return false;
129
12
  }
130
87
  return true;
131
99
}
draco::RAnsSymbolDecoder<15>::Create(draco::DecoderBuffer*)
Line
Count
Source
59
241
    DecoderBuffer *buffer) {
60
  // Check that the DecoderBuffer version is set.
61
241
  if (buffer->bitstream_version() == 0) {
62
0
    return false;
63
0
  }
64
  // Decode the number of alphabet symbols.
65
241
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
66
241
  if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
67
99
    if (!buffer->Decode(&num_symbols_)) {
68
0
      return false;
69
0
    }
70
71
99
  } else
72
142
#endif
73
142
  {
74
142
    if (!DecodeVarint(&num_symbols_, buffer)) {
75
0
      return false;
76
0
    }
77
142
  }
78
  // Check that decoded number of symbols is not unreasonably high. Remaining
79
  // buffer size must be at least |num_symbols| / 64 bytes to contain the
80
  // probability table. The |prob_data| below is one byte but it can be
81
  // theoretically stored for each 64th symbol.
82
241
  if (num_symbols_ / 64 > buffer->remaining_size()) {
83
26
    return false;
84
26
  }
85
215
  probability_table_.resize(num_symbols_);
86
215
  if (num_symbols_ == 0) {
87
2
    return true;
88
2
  }
89
  // Decode the table.
90
60.1k
  for (uint32_t i = 0; i < num_symbols_; ++i) {
91
60.0k
    uint8_t prob_data = 0;
92
    // Decode the first byte and extract the number of extra bytes we need to
93
    // get, or the offset to the next symbol with non-zero probability.
94
60.0k
    if (!buffer->Decode(&prob_data)) {
95
22
      return false;
96
22
    }
97
    // Token is stored in the first two bits of the first byte. Values 0-2 are
98
    // used to indicate the number of extra bytes, and value 3 is a special
99
    // symbol used to denote run-length coding of zero probability entries.
100
    // See rans_symbol_encoder.h for more details.
101
60.0k
    const int token = prob_data & 3;
102
60.0k
    if (token == 3) {
103
25.4k
      const uint32_t offset = prob_data >> 2;
104
25.4k
      if (i + offset >= num_symbols_) {
105
32
        return false;
106
32
      }
107
      // Set zero probability for all symbols in the specified range.
108
761k
      for (uint32_t j = 0; j < offset + 1; ++j) {
109
736k
        probability_table_[i + j] = 0;
110
736k
      }
111
25.3k
      i += offset;
112
34.5k
    } else {
113
34.5k
      const int extra_bytes = token;
114
34.5k
      uint32_t prob = prob_data >> 2;
115
64.5k
      for (int b = 0; b < extra_bytes; ++b) {
116
29.9k
        uint8_t eb;
117
29.9k
        if (!buffer->Decode(&eb)) {
118
7
          return false;
119
7
        }
120
        // Shift 8 bits for each extra byte and subtract 2 for the two first
121
        // bits.
122
29.9k
        prob |= static_cast<uint32_t>(eb) << (8 * (b + 1) - 2);
123
29.9k
      }
124
34.5k
      probability_table_[i] = prob;
125
34.5k
    }
126
60.0k
  }
127
152
  if (!ans_.rans_build_look_up_table(&probability_table_[0], num_symbols_)) {
128
28
    return false;
129
28
  }
130
124
  return true;
131
152
}
draco::RAnsSymbolDecoder<16>::Create(draco::DecoderBuffer*)
Line
Count
Source
59
206
    DecoderBuffer *buffer) {
60
  // Check that the DecoderBuffer version is set.
61
206
  if (buffer->bitstream_version() == 0) {
62
0
    return false;
63
0
  }
64
  // Decode the number of alphabet symbols.
65
206
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
66
206
  if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
67
49
    if (!buffer->Decode(&num_symbols_)) {
68
0
      return false;
69
0
    }
70
71
49
  } else
72
157
#endif
73
157
  {
74
157
    if (!DecodeVarint(&num_symbols_, buffer)) {
75
0
      return false;
76
0
    }
77
157
  }
78
  // Check that decoded number of symbols is not unreasonably high. Remaining
79
  // buffer size must be at least |num_symbols| / 64 bytes to contain the
80
  // probability table. The |prob_data| below is one byte but it can be
81
  // theoretically stored for each 64th symbol.
82
206
  if (num_symbols_ / 64 > buffer->remaining_size()) {
83
3
    return false;
84
3
  }
85
203
  probability_table_.resize(num_symbols_);
86
203
  if (num_symbols_ == 0) {
87
0
    return true;
88
0
  }
89
  // Decode the table.
90
34.9k
  for (uint32_t i = 0; i < num_symbols_; ++i) {
91
34.7k
    uint8_t prob_data = 0;
92
    // Decode the first byte and extract the number of extra bytes we need to
93
    // get, or the offset to the next symbol with non-zero probability.
94
34.7k
    if (!buffer->Decode(&prob_data)) {
95
17
      return false;
96
17
    }
97
    // Token is stored in the first two bits of the first byte. Values 0-2 are
98
    // used to indicate the number of extra bytes, and value 3 is a special
99
    // symbol used to denote run-length coding of zero probability entries.
100
    // See rans_symbol_encoder.h for more details.
101
34.7k
    const int token = prob_data & 3;
102
34.7k
    if (token == 3) {
103
10.8k
      const uint32_t offset = prob_data >> 2;
104
10.8k
      if (i + offset >= num_symbols_) {
105
53
        return false;
106
53
      }
107
      // Set zero probability for all symbols in the specified range.
108
481k
      for (uint32_t j = 0; j < offset + 1; ++j) {
109
470k
        probability_table_[i + j] = 0;
110
470k
      }
111
10.8k
      i += offset;
112
23.8k
    } else {
113
23.8k
      const int extra_bytes = token;
114
23.8k
      uint32_t prob = prob_data >> 2;
115
37.3k
      for (int b = 0; b < extra_bytes; ++b) {
116
13.4k
        uint8_t eb;
117
13.4k
        if (!buffer->Decode(&eb)) {
118
7
          return false;
119
7
        }
120
        // Shift 8 bits for each extra byte and subtract 2 for the two first
121
        // bits.
122
13.4k
        prob |= static_cast<uint32_t>(eb) << (8 * (b + 1) - 2);
123
13.4k
      }
124
23.8k
      probability_table_[i] = prob;
125
23.8k
    }
126
34.7k
  }
127
126
  if (!ans_.rans_build_look_up_table(&probability_table_[0], num_symbols_)) {
128
24
    return false;
129
24
  }
130
102
  return true;
131
126
}
draco::RAnsSymbolDecoder<17>::Create(draco::DecoderBuffer*)
Line
Count
Source
59
170
    DecoderBuffer *buffer) {
60
  // Check that the DecoderBuffer version is set.
61
170
  if (buffer->bitstream_version() == 0) {
62
0
    return false;
63
0
  }
64
  // Decode the number of alphabet symbols.
65
170
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
66
170
  if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
67
33
    if (!buffer->Decode(&num_symbols_)) {
68
0
      return false;
69
0
    }
70
71
33
  } else
72
137
#endif
73
137
  {
74
137
    if (!DecodeVarint(&num_symbols_, buffer)) {
75
0
      return false;
76
0
    }
77
137
  }
78
  // Check that decoded number of symbols is not unreasonably high. Remaining
79
  // buffer size must be at least |num_symbols| / 64 bytes to contain the
80
  // probability table. The |prob_data| below is one byte but it can be
81
  // theoretically stored for each 64th symbol.
82
170
  if (num_symbols_ / 64 > buffer->remaining_size()) {
83
12
    return false;
84
12
  }
85
158
  probability_table_.resize(num_symbols_);
86
158
  if (num_symbols_ == 0) {
87
0
    return true;
88
0
  }
89
  // Decode the table.
90
15.6k
  for (uint32_t i = 0; i < num_symbols_; ++i) {
91
15.5k
    uint8_t prob_data = 0;
92
    // Decode the first byte and extract the number of extra bytes we need to
93
    // get, or the offset to the next symbol with non-zero probability.
94
15.5k
    if (!buffer->Decode(&prob_data)) {
95
18
      return false;
96
18
    }
97
    // Token is stored in the first two bits of the first byte. Values 0-2 are
98
    // used to indicate the number of extra bytes, and value 3 is a special
99
    // symbol used to denote run-length coding of zero probability entries.
100
    // See rans_symbol_encoder.h for more details.
101
15.5k
    const int token = prob_data & 3;
102
15.5k
    if (token == 3) {
103
7.24k
      const uint32_t offset = prob_data >> 2;
104
7.24k
      if (i + offset >= num_symbols_) {
105
15
        return false;
106
15
      }
107
      // Set zero probability for all symbols in the specified range.
108
207k
      for (uint32_t j = 0; j < offset + 1; ++j) {
109
200k
        probability_table_[i + j] = 0;
110
200k
      }
111
7.22k
      i += offset;
112
8.26k
    } else {
113
8.26k
      const int extra_bytes = token;
114
8.26k
      uint32_t prob = prob_data >> 2;
115
12.5k
      for (int b = 0; b < extra_bytes; ++b) {
116
4.26k
        uint8_t eb;
117
4.26k
        if (!buffer->Decode(&eb)) {
118
6
          return false;
119
6
        }
120
        // Shift 8 bits for each extra byte and subtract 2 for the two first
121
        // bits.
122
4.26k
        prob |= static_cast<uint32_t>(eb) << (8 * (b + 1) - 2);
123
4.26k
      }
124
8.25k
      probability_table_[i] = prob;
125
8.25k
    }
126
15.5k
  }
127
119
  if (!ans_.rans_build_look_up_table(&probability_table_[0], num_symbols_)) {
128
10
    return false;
129
10
  }
130
109
  return true;
131
119
}
draco::RAnsSymbolDecoder<18>::Create(draco::DecoderBuffer*)
Line
Count
Source
59
151
    DecoderBuffer *buffer) {
60
  // Check that the DecoderBuffer version is set.
61
151
  if (buffer->bitstream_version() == 0) {
62
0
    return false;
63
0
  }
64
  // Decode the number of alphabet symbols.
65
151
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
66
151
  if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
67
5
    if (!buffer->Decode(&num_symbols_)) {
68
0
      return false;
69
0
    }
70
71
5
  } else
72
146
#endif
73
146
  {
74
146
    if (!DecodeVarint(&num_symbols_, buffer)) {
75
0
      return false;
76
0
    }
77
146
  }
78
  // Check that decoded number of symbols is not unreasonably high. Remaining
79
  // buffer size must be at least |num_symbols| / 64 bytes to contain the
80
  // probability table. The |prob_data| below is one byte but it can be
81
  // theoretically stored for each 64th symbol.
82
151
  if (num_symbols_ / 64 > buffer->remaining_size()) {
83
4
    return false;
84
4
  }
85
147
  probability_table_.resize(num_symbols_);
86
147
  if (num_symbols_ == 0) {
87
0
    return true;
88
0
  }
89
  // Decode the table.
90
52.1k
  for (uint32_t i = 0; i < num_symbols_; ++i) {
91
52.0k
    uint8_t prob_data = 0;
92
    // Decode the first byte and extract the number of extra bytes we need to
93
    // get, or the offset to the next symbol with non-zero probability.
94
52.0k
    if (!buffer->Decode(&prob_data)) {
95
19
      return false;
96
19
    }
97
    // Token is stored in the first two bits of the first byte. Values 0-2 are
98
    // used to indicate the number of extra bytes, and value 3 is a special
99
    // symbol used to denote run-length coding of zero probability entries.
100
    // See rans_symbol_encoder.h for more details.
101
51.9k
    const int token = prob_data & 3;
102
51.9k
    if (token == 3) {
103
44.0k
      const uint32_t offset = prob_data >> 2;
104
44.0k
      if (i + offset >= num_symbols_) {
105
5
        return false;
106
5
      }
107
      // Set zero probability for all symbols in the specified range.
108
1.54M
      for (uint32_t j = 0; j < offset + 1; ++j) {
109
1.49M
        probability_table_[i + j] = 0;
110
1.49M
      }
111
44.0k
      i += offset;
112
44.0k
    } else {
113
7.95k
      const int extra_bytes = token;
114
7.95k
      uint32_t prob = prob_data >> 2;
115
13.4k
      for (int b = 0; b < extra_bytes; ++b) {
116
5.50k
        uint8_t eb;
117
5.50k
        if (!buffer->Decode(&eb)) {
118
7
          return false;
119
7
        }
120
        // Shift 8 bits for each extra byte and subtract 2 for the two first
121
        // bits.
122
5.50k
        prob |= static_cast<uint32_t>(eb) << (8 * (b + 1) - 2);
123
5.50k
      }
124
7.94k
      probability_table_[i] = prob;
125
7.94k
    }
126
51.9k
  }
127
116
  if (!ans_.rans_build_look_up_table(&probability_table_[0], num_symbols_)) {
128
8
    return false;
129
8
  }
130
108
  return true;
131
116
}
132
133
template <int unique_symbols_bit_length_t>
134
bool RAnsSymbolDecoder<unique_symbols_bit_length_t>::StartDecoding(
135
2.58k
    DecoderBuffer *buffer) {
136
2.58k
  uint64_t bytes_encoded;
137
  // Decode the number of bytes encoded by the encoder.
138
2.58k
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
139
2.58k
  if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
140
292
    if (!buffer->Decode(&bytes_encoded)) {
141
5
      return false;
142
5
    }
143
144
292
  } else
145
2.29k
#endif
146
2.29k
  {
147
2.29k
    if (!DecodeVarint<uint64_t>(&bytes_encoded, buffer)) {
148
77
      return false;
149
77
    }
150
2.29k
  }
151
2.50k
  if (bytes_encoded > static_cast<uint64_t>(buffer->remaining_size())) {
152
620
    return false;
153
620
  }
154
1.88k
  const uint8_t *const data_head =
155
1.88k
      reinterpret_cast<const uint8_t *>(buffer->data_head());
156
  // Advance the buffer past the rANS data.
157
1.88k
  buffer->Advance(bytes_encoded);
158
1.88k
  if (ans_.read_init(data_head, static_cast<int>(bytes_encoded)) != 0) {
159
315
    return false;
160
315
  }
161
1.57k
  return true;
162
1.88k
}
draco::RAnsSymbolDecoder<5>::StartDecoding(draco::DecoderBuffer*)
Line
Count
Source
135
660
    DecoderBuffer *buffer) {
136
660
  uint64_t bytes_encoded;
137
  // Decode the number of bytes encoded by the encoder.
138
660
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
139
660
  if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
140
67
    if (!buffer->Decode(&bytes_encoded)) {
141
1
      return false;
142
1
    }
143
144
67
  } else
145
593
#endif
146
593
  {
147
593
    if (!DecodeVarint<uint64_t>(&bytes_encoded, buffer)) {
148
7
      return false;
149
7
    }
150
593
  }
151
652
  if (bytes_encoded > static_cast<uint64_t>(buffer->remaining_size())) {
152
95
    return false;
153
95
  }
154
557
  const uint8_t *const data_head =
155
557
      reinterpret_cast<const uint8_t *>(buffer->data_head());
156
  // Advance the buffer past the rANS data.
157
557
  buffer->Advance(bytes_encoded);
158
557
  if (ans_.read_init(data_head, static_cast<int>(bytes_encoded)) != 0) {
159
90
    return false;
160
90
  }
161
467
  return true;
162
557
}
draco::RAnsSymbolDecoder<1>::StartDecoding(draco::DecoderBuffer*)
Line
Count
Source
135
86
    DecoderBuffer *buffer) {
136
86
  uint64_t bytes_encoded;
137
  // Decode the number of bytes encoded by the encoder.
138
86
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
139
86
  if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
140
0
    if (!buffer->Decode(&bytes_encoded)) {
141
0
      return false;
142
0
    }
143
144
0
  } else
145
86
#endif
146
86
  {
147
86
    if (!DecodeVarint<uint64_t>(&bytes_encoded, buffer)) {
148
3
      return false;
149
3
    }
150
86
  }
151
83
  if (bytes_encoded > static_cast<uint64_t>(buffer->remaining_size())) {
152
6
    return false;
153
6
  }
154
77
  const uint8_t *const data_head =
155
77
      reinterpret_cast<const uint8_t *>(buffer->data_head());
156
  // Advance the buffer past the rANS data.
157
77
  buffer->Advance(bytes_encoded);
158
77
  if (ans_.read_init(data_head, static_cast<int>(bytes_encoded)) != 0) {
159
10
    return false;
160
10
  }
161
67
  return true;
162
77
}
draco::RAnsSymbolDecoder<2>::StartDecoding(draco::DecoderBuffer*)
Line
Count
Source
135
149
    DecoderBuffer *buffer) {
136
149
  uint64_t bytes_encoded;
137
  // Decode the number of bytes encoded by the encoder.
138
149
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
139
149
  if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
140
31
    if (!buffer->Decode(&bytes_encoded)) {
141
0
      return false;
142
0
    }
143
144
31
  } else
145
118
#endif
146
118
  {
147
118
    if (!DecodeVarint<uint64_t>(&bytes_encoded, buffer)) {
148
11
      return false;
149
11
    }
150
118
  }
151
138
  if (bytes_encoded > static_cast<uint64_t>(buffer->remaining_size())) {
152
54
    return false;
153
54
  }
154
84
  const uint8_t *const data_head =
155
84
      reinterpret_cast<const uint8_t *>(buffer->data_head());
156
  // Advance the buffer past the rANS data.
157
84
  buffer->Advance(bytes_encoded);
158
84
  if (ans_.read_init(data_head, static_cast<int>(bytes_encoded)) != 0) {
159
9
    return false;
160
9
  }
161
75
  return true;
162
84
}
draco::RAnsSymbolDecoder<3>::StartDecoding(draco::DecoderBuffer*)
Line
Count
Source
135
163
    DecoderBuffer *buffer) {
136
163
  uint64_t bytes_encoded;
137
  // Decode the number of bytes encoded by the encoder.
138
163
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
139
163
  if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
140
36
    if (!buffer->Decode(&bytes_encoded)) {
141
1
      return false;
142
1
    }
143
144
36
  } else
145
127
#endif
146
127
  {
147
127
    if (!DecodeVarint<uint64_t>(&bytes_encoded, buffer)) {
148
0
      return false;
149
0
    }
150
127
  }
151
162
  if (bytes_encoded > static_cast<uint64_t>(buffer->remaining_size())) {
152
63
    return false;
153
63
  }
154
99
  const uint8_t *const data_head =
155
99
      reinterpret_cast<const uint8_t *>(buffer->data_head());
156
  // Advance the buffer past the rANS data.
157
99
  buffer->Advance(bytes_encoded);
158
99
  if (ans_.read_init(data_head, static_cast<int>(bytes_encoded)) != 0) {
159
10
    return false;
160
10
  }
161
89
  return true;
162
99
}
draco::RAnsSymbolDecoder<4>::StartDecoding(draco::DecoderBuffer*)
Line
Count
Source
135
113
    DecoderBuffer *buffer) {
136
113
  uint64_t bytes_encoded;
137
  // Decode the number of bytes encoded by the encoder.
138
113
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
139
113
  if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
140
21
    if (!buffer->Decode(&bytes_encoded)) {
141
1
      return false;
142
1
    }
143
144
21
  } else
145
92
#endif
146
92
  {
147
92
    if (!DecodeVarint<uint64_t>(&bytes_encoded, buffer)) {
148
3
      return false;
149
3
    }
150
92
  }
151
109
  if (bytes_encoded > static_cast<uint64_t>(buffer->remaining_size())) {
152
39
    return false;
153
39
  }
154
70
  const uint8_t *const data_head =
155
70
      reinterpret_cast<const uint8_t *>(buffer->data_head());
156
  // Advance the buffer past the rANS data.
157
70
  buffer->Advance(bytes_encoded);
158
70
  if (ans_.read_init(data_head, static_cast<int>(bytes_encoded)) != 0) {
159
6
    return false;
160
6
  }
161
64
  return true;
162
70
}
draco::RAnsSymbolDecoder<6>::StartDecoding(draco::DecoderBuffer*)
Line
Count
Source
135
162
    DecoderBuffer *buffer) {
136
162
  uint64_t bytes_encoded;
137
  // Decode the number of bytes encoded by the encoder.
138
162
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
139
162
  if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
140
7
    if (!buffer->Decode(&bytes_encoded)) {
141
0
      return false;
142
0
    }
143
144
7
  } else
145
155
#endif
146
155
  {
147
155
    if (!DecodeVarint<uint64_t>(&bytes_encoded, buffer)) {
148
7
      return false;
149
7
    }
150
155
  }
151
155
  if (bytes_encoded > static_cast<uint64_t>(buffer->remaining_size())) {
152
18
    return false;
153
18
  }
154
137
  const uint8_t *const data_head =
155
137
      reinterpret_cast<const uint8_t *>(buffer->data_head());
156
  // Advance the buffer past the rANS data.
157
137
  buffer->Advance(bytes_encoded);
158
137
  if (ans_.read_init(data_head, static_cast<int>(bytes_encoded)) != 0) {
159
19
    return false;
160
19
  }
161
118
  return true;
162
137
}
draco::RAnsSymbolDecoder<7>::StartDecoding(draco::DecoderBuffer*)
Line
Count
Source
135
166
    DecoderBuffer *buffer) {
136
166
  uint64_t bytes_encoded;
137
  // Decode the number of bytes encoded by the encoder.
138
166
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
139
166
  if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
140
2
    if (!buffer->Decode(&bytes_encoded)) {
141
1
      return false;
142
1
    }
143
144
2
  } else
145
164
#endif
146
164
  {
147
164
    if (!DecodeVarint<uint64_t>(&bytes_encoded, buffer)) {
148
10
      return false;
149
10
    }
150
164
  }
151
155
  if (bytes_encoded > static_cast<uint64_t>(buffer->remaining_size())) {
152
39
    return false;
153
39
  }
154
116
  const uint8_t *const data_head =
155
116
      reinterpret_cast<const uint8_t *>(buffer->data_head());
156
  // Advance the buffer past the rANS data.
157
116
  buffer->Advance(bytes_encoded);
158
116
  if (ans_.read_init(data_head, static_cast<int>(bytes_encoded)) != 0) {
159
21
    return false;
160
21
  }
161
95
  return true;
162
116
}
draco::RAnsSymbolDecoder<8>::StartDecoding(draco::DecoderBuffer*)
Line
Count
Source
135
119
    DecoderBuffer *buffer) {
136
119
  uint64_t bytes_encoded;
137
  // Decode the number of bytes encoded by the encoder.
138
119
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
139
119
  if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
140
8
    if (!buffer->Decode(&bytes_encoded)) {
141
1
      return false;
142
1
    }
143
144
8
  } else
145
111
#endif
146
111
  {
147
111
    if (!DecodeVarint<uint64_t>(&bytes_encoded, buffer)) {
148
7
      return false;
149
7
    }
150
111
  }
151
111
  if (bytes_encoded > static_cast<uint64_t>(buffer->remaining_size())) {
152
34
    return false;
153
34
  }
154
77
  const uint8_t *const data_head =
155
77
      reinterpret_cast<const uint8_t *>(buffer->data_head());
156
  // Advance the buffer past the rANS data.
157
77
  buffer->Advance(bytes_encoded);
158
77
  if (ans_.read_init(data_head, static_cast<int>(bytes_encoded)) != 0) {
159
12
    return false;
160
12
  }
161
65
  return true;
162
77
}
draco::RAnsSymbolDecoder<9>::StartDecoding(draco::DecoderBuffer*)
Line
Count
Source
135
44
    DecoderBuffer *buffer) {
136
44
  uint64_t bytes_encoded;
137
  // Decode the number of bytes encoded by the encoder.
138
44
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
139
44
  if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
140
0
    if (!buffer->Decode(&bytes_encoded)) {
141
0
      return false;
142
0
    }
143
144
0
  } else
145
44
#endif
146
44
  {
147
44
    if (!DecodeVarint<uint64_t>(&bytes_encoded, buffer)) {
148
0
      return false;
149
0
    }
150
44
  }
151
44
  if (bytes_encoded > static_cast<uint64_t>(buffer->remaining_size())) {
152
7
    return false;
153
7
  }
154
37
  const uint8_t *const data_head =
155
37
      reinterpret_cast<const uint8_t *>(buffer->data_head());
156
  // Advance the buffer past the rANS data.
157
37
  buffer->Advance(bytes_encoded);
158
37
  if (ans_.read_init(data_head, static_cast<int>(bytes_encoded)) != 0) {
159
1
    return false;
160
1
  }
161
36
  return true;
162
37
}
draco::RAnsSymbolDecoder<10>::StartDecoding(draco::DecoderBuffer*)
Line
Count
Source
135
87
    DecoderBuffer *buffer) {
136
87
  uint64_t bytes_encoded;
137
  // Decode the number of bytes encoded by the encoder.
138
87
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
139
87
  if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
140
3
    if (!buffer->Decode(&bytes_encoded)) {
141
0
      return false;
142
0
    }
143
144
3
  } else
145
84
#endif
146
84
  {
147
84
    if (!DecodeVarint<uint64_t>(&bytes_encoded, buffer)) {
148
1
      return false;
149
1
    }
150
84
  }
151
86
  if (bytes_encoded > static_cast<uint64_t>(buffer->remaining_size())) {
152
33
    return false;
153
33
  }
154
53
  const uint8_t *const data_head =
155
53
      reinterpret_cast<const uint8_t *>(buffer->data_head());
156
  // Advance the buffer past the rANS data.
157
53
  buffer->Advance(bytes_encoded);
158
53
  if (ans_.read_init(data_head, static_cast<int>(bytes_encoded)) != 0) {
159
16
    return false;
160
16
  }
161
37
  return true;
162
53
}
draco::RAnsSymbolDecoder<11>::StartDecoding(draco::DecoderBuffer*)
Line
Count
Source
135
100
    DecoderBuffer *buffer) {
136
100
  uint64_t bytes_encoded;
137
  // Decode the number of bytes encoded by the encoder.
138
100
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
139
100
  if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
140
0
    if (!buffer->Decode(&bytes_encoded)) {
141
0
      return false;
142
0
    }
143
144
0
  } else
145
100
#endif
146
100
  {
147
100
    if (!DecodeVarint<uint64_t>(&bytes_encoded, buffer)) {
148
1
      return false;
149
1
    }
150
100
  }
151
99
  if (bytes_encoded > static_cast<uint64_t>(buffer->remaining_size())) {
152
12
    return false;
153
12
  }
154
87
  const uint8_t *const data_head =
155
87
      reinterpret_cast<const uint8_t *>(buffer->data_head());
156
  // Advance the buffer past the rANS data.
157
87
  buffer->Advance(bytes_encoded);
158
87
  if (ans_.read_init(data_head, static_cast<int>(bytes_encoded)) != 0) {
159
32
    return false;
160
32
  }
161
55
  return true;
162
87
}
draco::RAnsSymbolDecoder<12>::StartDecoding(draco::DecoderBuffer*)
Line
Count
Source
135
114
    DecoderBuffer *buffer) {
136
114
  uint64_t bytes_encoded;
137
  // Decode the number of bytes encoded by the encoder.
138
114
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
139
114
  if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
140
39
    if (!buffer->Decode(&bytes_encoded)) {
141
0
      return false;
142
0
    }
143
144
39
  } else
145
75
#endif
146
75
  {
147
75
    if (!DecodeVarint<uint64_t>(&bytes_encoded, buffer)) {
148
4
      return false;
149
4
    }
150
75
  }
151
110
  if (bytes_encoded > static_cast<uint64_t>(buffer->remaining_size())) {
152
41
    return false;
153
41
  }
154
69
  const uint8_t *const data_head =
155
69
      reinterpret_cast<const uint8_t *>(buffer->data_head());
156
  // Advance the buffer past the rANS data.
157
69
  buffer->Advance(bytes_encoded);
158
69
  if (ans_.read_init(data_head, static_cast<int>(bytes_encoded)) != 0) {
159
18
    return false;
160
18
  }
161
51
  return true;
162
69
}
draco::RAnsSymbolDecoder<13>::StartDecoding(draco::DecoderBuffer*)
Line
Count
Source
135
94
    DecoderBuffer *buffer) {
136
94
  uint64_t bytes_encoded;
137
  // Decode the number of bytes encoded by the encoder.
138
94
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
139
94
  if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
140
0
    if (!buffer->Decode(&bytes_encoded)) {
141
0
      return false;
142
0
    }
143
144
0
  } else
145
94
#endif
146
94
  {
147
94
    if (!DecodeVarint<uint64_t>(&bytes_encoded, buffer)) {
148
1
      return false;
149
1
    }
150
94
  }
151
93
  if (bytes_encoded > static_cast<uint64_t>(buffer->remaining_size())) {
152
18
    return false;
153
18
  }
154
75
  const uint8_t *const data_head =
155
75
      reinterpret_cast<const uint8_t *>(buffer->data_head());
156
  // Advance the buffer past the rANS data.
157
75
  buffer->Advance(bytes_encoded);
158
75
  if (ans_.read_init(data_head, static_cast<int>(bytes_encoded)) != 0) {
159
15
    return false;
160
15
  }
161
60
  return true;
162
75
}
draco::RAnsSymbolDecoder<14>::StartDecoding(draco::DecoderBuffer*)
Line
Count
Source
135
87
    DecoderBuffer *buffer) {
136
87
  uint64_t bytes_encoded;
137
  // Decode the number of bytes encoded by the encoder.
138
87
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
139
87
  if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
140
1
    if (!buffer->Decode(&bytes_encoded)) {
141
0
      return false;
142
0
    }
143
144
1
  } else
145
86
#endif
146
86
  {
147
86
    if (!DecodeVarint<uint64_t>(&bytes_encoded, buffer)) {
148
4
      return false;
149
4
    }
150
86
  }
151
83
  if (bytes_encoded > static_cast<uint64_t>(buffer->remaining_size())) {
152
16
    return false;
153
16
  }
154
67
  const uint8_t *const data_head =
155
67
      reinterpret_cast<const uint8_t *>(buffer->data_head());
156
  // Advance the buffer past the rANS data.
157
67
  buffer->Advance(bytes_encoded);
158
67
  if (ans_.read_init(data_head, static_cast<int>(bytes_encoded)) != 0) {
159
9
    return false;
160
9
  }
161
58
  return true;
162
67
}
draco::RAnsSymbolDecoder<15>::StartDecoding(draco::DecoderBuffer*)
Line
Count
Source
135
124
    DecoderBuffer *buffer) {
136
124
  uint64_t bytes_encoded;
137
  // Decode the number of bytes encoded by the encoder.
138
124
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
139
124
  if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
140
50
    if (!buffer->Decode(&bytes_encoded)) {
141
0
      return false;
142
0
    }
143
144
50
  } else
145
74
#endif
146
74
  {
147
74
    if (!DecodeVarint<uint64_t>(&bytes_encoded, buffer)) {
148
0
      return false;
149
0
    }
150
74
  }
151
124
  if (bytes_encoded > static_cast<uint64_t>(buffer->remaining_size())) {
152
55
    return false;
153
55
  }
154
69
  const uint8_t *const data_head =
155
69
      reinterpret_cast<const uint8_t *>(buffer->data_head());
156
  // Advance the buffer past the rANS data.
157
69
  buffer->Advance(bytes_encoded);
158
69
  if (ans_.read_init(data_head, static_cast<int>(bytes_encoded)) != 0) {
159
8
    return false;
160
8
  }
161
61
  return true;
162
69
}
draco::RAnsSymbolDecoder<16>::StartDecoding(draco::DecoderBuffer*)
Line
Count
Source
135
102
    DecoderBuffer *buffer) {
136
102
  uint64_t bytes_encoded;
137
  // Decode the number of bytes encoded by the encoder.
138
102
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
139
102
  if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
140
6
    if (!buffer->Decode(&bytes_encoded)) {
141
0
      return false;
142
0
    }
143
144
6
  } else
145
96
#endif
146
96
  {
147
96
    if (!DecodeVarint<uint64_t>(&bytes_encoded, buffer)) {
148
1
      return false;
149
1
    }
150
96
  }
151
101
  if (bytes_encoded > static_cast<uint64_t>(buffer->remaining_size())) {
152
34
    return false;
153
34
  }
154
67
  const uint8_t *const data_head =
155
67
      reinterpret_cast<const uint8_t *>(buffer->data_head());
156
  // Advance the buffer past the rANS data.
157
67
  buffer->Advance(bytes_encoded);
158
67
  if (ans_.read_init(data_head, static_cast<int>(bytes_encoded)) != 0) {
159
12
    return false;
160
12
  }
161
55
  return true;
162
67
}
draco::RAnsSymbolDecoder<17>::StartDecoding(draco::DecoderBuffer*)
Line
Count
Source
135
109
    DecoderBuffer *buffer) {
136
109
  uint64_t bytes_encoded;
137
  // Decode the number of bytes encoded by the encoder.
138
109
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
139
109
  if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
140
20
    if (!buffer->Decode(&bytes_encoded)) {
141
0
      return false;
142
0
    }
143
144
20
  } else
145
89
#endif
146
89
  {
147
89
    if (!DecodeVarint<uint64_t>(&bytes_encoded, buffer)) {
148
0
      return false;
149
0
    }
150
89
  }
151
109
  if (bytes_encoded > static_cast<uint64_t>(buffer->remaining_size())) {
152
39
    return false;
153
39
  }
154
70
  const uint8_t *const data_head =
155
70
      reinterpret_cast<const uint8_t *>(buffer->data_head());
156
  // Advance the buffer past the rANS data.
157
70
  buffer->Advance(bytes_encoded);
158
70
  if (ans_.read_init(data_head, static_cast<int>(bytes_encoded)) != 0) {
159
11
    return false;
160
11
  }
161
59
  return true;
162
70
}
draco::RAnsSymbolDecoder<18>::StartDecoding(draco::DecoderBuffer*)
Line
Count
Source
135
108
    DecoderBuffer *buffer) {
136
108
  uint64_t bytes_encoded;
137
  // Decode the number of bytes encoded by the encoder.
138
108
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
139
108
  if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
140
1
    if (!buffer->Decode(&bytes_encoded)) {
141
0
      return false;
142
0
    }
143
144
1
  } else
145
107
#endif
146
107
  {
147
107
    if (!DecodeVarint<uint64_t>(&bytes_encoded, buffer)) {
148
17
      return false;
149
17
    }
150
107
  }
151
91
  if (bytes_encoded > static_cast<uint64_t>(buffer->remaining_size())) {
152
17
    return false;
153
17
  }
154
74
  const uint8_t *const data_head =
155
74
      reinterpret_cast<const uint8_t *>(buffer->data_head());
156
  // Advance the buffer past the rANS data.
157
74
  buffer->Advance(bytes_encoded);
158
74
  if (ans_.read_init(data_head, static_cast<int>(bytes_encoded)) != 0) {
159
16
    return false;
160
16
  }
161
58
  return true;
162
74
}
163
164
template <int unique_symbols_bit_length_t>
165
1.53k
void RAnsSymbolDecoder<unique_symbols_bit_length_t>::EndDecoding() {
166
1.53k
  ans_.read_end();
167
1.53k
}
draco::RAnsSymbolDecoder<5>::EndDecoding()
Line
Count
Source
165
431
void RAnsSymbolDecoder<unique_symbols_bit_length_t>::EndDecoding() {
166
431
  ans_.read_end();
167
431
}
draco::RAnsSymbolDecoder<1>::EndDecoding()
Line
Count
Source
165
67
void RAnsSymbolDecoder<unique_symbols_bit_length_t>::EndDecoding() {
166
67
  ans_.read_end();
167
67
}
draco::RAnsSymbolDecoder<2>::EndDecoding()
Line
Count
Source
165
75
void RAnsSymbolDecoder<unique_symbols_bit_length_t>::EndDecoding() {
166
75
  ans_.read_end();
167
75
}
draco::RAnsSymbolDecoder<3>::EndDecoding()
Line
Count
Source
165
89
void RAnsSymbolDecoder<unique_symbols_bit_length_t>::EndDecoding() {
166
89
  ans_.read_end();
167
89
}
draco::RAnsSymbolDecoder<4>::EndDecoding()
Line
Count
Source
165
64
void RAnsSymbolDecoder<unique_symbols_bit_length_t>::EndDecoding() {
166
64
  ans_.read_end();
167
64
}
draco::RAnsSymbolDecoder<6>::EndDecoding()
Line
Count
Source
165
118
void RAnsSymbolDecoder<unique_symbols_bit_length_t>::EndDecoding() {
166
118
  ans_.read_end();
167
118
}
draco::RAnsSymbolDecoder<7>::EndDecoding()
Line
Count
Source
165
95
void RAnsSymbolDecoder<unique_symbols_bit_length_t>::EndDecoding() {
166
95
  ans_.read_end();
167
95
}
draco::RAnsSymbolDecoder<8>::EndDecoding()
Line
Count
Source
165
65
void RAnsSymbolDecoder<unique_symbols_bit_length_t>::EndDecoding() {
166
65
  ans_.read_end();
167
65
}
draco::RAnsSymbolDecoder<9>::EndDecoding()
Line
Count
Source
165
36
void RAnsSymbolDecoder<unique_symbols_bit_length_t>::EndDecoding() {
166
36
  ans_.read_end();
167
36
}
draco::RAnsSymbolDecoder<10>::EndDecoding()
Line
Count
Source
165
37
void RAnsSymbolDecoder<unique_symbols_bit_length_t>::EndDecoding() {
166
37
  ans_.read_end();
167
37
}
draco::RAnsSymbolDecoder<11>::EndDecoding()
Line
Count
Source
165
55
void RAnsSymbolDecoder<unique_symbols_bit_length_t>::EndDecoding() {
166
55
  ans_.read_end();
167
55
}
draco::RAnsSymbolDecoder<12>::EndDecoding()
Line
Count
Source
165
51
void RAnsSymbolDecoder<unique_symbols_bit_length_t>::EndDecoding() {
166
51
  ans_.read_end();
167
51
}
draco::RAnsSymbolDecoder<13>::EndDecoding()
Line
Count
Source
165
60
void RAnsSymbolDecoder<unique_symbols_bit_length_t>::EndDecoding() {
166
60
  ans_.read_end();
167
60
}
draco::RAnsSymbolDecoder<14>::EndDecoding()
Line
Count
Source
165
58
void RAnsSymbolDecoder<unique_symbols_bit_length_t>::EndDecoding() {
166
58
  ans_.read_end();
167
58
}
draco::RAnsSymbolDecoder<15>::EndDecoding()
Line
Count
Source
165
61
void RAnsSymbolDecoder<unique_symbols_bit_length_t>::EndDecoding() {
166
61
  ans_.read_end();
167
61
}
draco::RAnsSymbolDecoder<16>::EndDecoding()
Line
Count
Source
165
55
void RAnsSymbolDecoder<unique_symbols_bit_length_t>::EndDecoding() {
166
55
  ans_.read_end();
167
55
}
draco::RAnsSymbolDecoder<17>::EndDecoding()
Line
Count
Source
165
59
void RAnsSymbolDecoder<unique_symbols_bit_length_t>::EndDecoding() {
166
59
  ans_.read_end();
167
59
}
draco::RAnsSymbolDecoder<18>::EndDecoding()
Line
Count
Source
165
58
void RAnsSymbolDecoder<unique_symbols_bit_length_t>::EndDecoding() {
166
58
  ans_.read_end();
167
58
}
168
169
}  // namespace draco
170
171
#endif  // DRACO_COMPRESSION_ENTROPY_RANS_SYMBOL_DECODER_H_