mirror of
https://git.mirrors.martin98.com/https://github.com/google/draco
synced 2025-07-25 19:04:25 +08:00

- Improved compression for triangular meshes (~10%) - Added WebAssembly decoder - Code cleanup + robustness fixes
48 lines
1.1 KiB
C++
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
|