draco/core/symbol_bit_decoder.cc
Ondrej Stava 73bb3c8530 Version 0.10.0 snapshot
- Improved compression for triangular meshes (~10%)
- Added WebAssembly decoder
- Code cleanup + robustness fixes
2017-04-12 12:09:14 -07:00

48 lines
1.1 KiB
C++

#include "core/symbol_bit_decoder.h"
#include "core/symbol_decoding.h"
namespace draco {
bool SymbolBitDecoder::StartDecoding(DecoderBuffer *source_buffer) {
uint32_t size;
if (!source_buffer->Decode(&size))
return false;
symbols_.resize(size);
if (!DecodeSymbols(size, 1, source_buffer, symbols_.data()))
return false;
std::reverse(symbols_.begin(), symbols_.end());
return true;
}
bool SymbolBitDecoder::DecodeNextBit() {
uint32_t symbol;
DecodeLeastSignificantBits32(1, &symbol);
DCHECK(symbol == 0 || symbol == 1);
return symbol == 1;
}
void SymbolBitDecoder::DecodeLeastSignificantBits32(int nbits,
uint32_t *value) {
DCHECK_LE(1, nbits);
DCHECK_LE(nbits, 32);
DCHECK_NE(value, nullptr);
// Testing: check to make sure there is something to decode.
DCHECK_GT(symbols_.size(), 0);
(*value) = symbols_.back();
symbols_.pop_back();
const int discarded_bits = 32 - nbits;
(*value) <<= discarded_bits;
(*value) >>= discarded_bits;
}
void SymbolBitDecoder::Clear() {
symbols_.clear();
symbols_.shrink_to_fit();
}
} // namespace draco