Changeset View
Changeset View
Standalone View
Standalone View
extern/draco/draco/src/draco/core/encoder_buffer.cc
- This file was moved from extern/draco/dracoenc/src/draco/core/encoder_buffer.cc.
| Show All 25 Lines | |||||
| void EncoderBuffer::Clear() { | void EncoderBuffer::Clear() { | ||||
| buffer_.clear(); | buffer_.clear(); | ||||
| bit_encoder_reserved_bytes_ = 0; | bit_encoder_reserved_bytes_ = 0; | ||||
| } | } | ||||
| void EncoderBuffer::Resize(int64_t nbytes) { buffer_.resize(nbytes); } | void EncoderBuffer::Resize(int64_t nbytes) { buffer_.resize(nbytes); } | ||||
| bool EncoderBuffer::StartBitEncoding(int64_t required_bits, bool encode_size) { | bool EncoderBuffer::StartBitEncoding(int64_t required_bits, bool encode_size) { | ||||
| if (bit_encoder_active()) | if (bit_encoder_active()) { | ||||
| return false; // Bit encoding mode already active. | return false; // Bit encoding mode already active. | ||||
| if (required_bits <= 0) | } | ||||
| if (required_bits <= 0) { | |||||
| return false; // Invalid size. | return false; // Invalid size. | ||||
| } | |||||
| encode_bit_sequence_size_ = encode_size; | encode_bit_sequence_size_ = encode_size; | ||||
| const int64_t required_bytes = (required_bits + 7) / 8; | const int64_t required_bytes = (required_bits + 7) / 8; | ||||
| bit_encoder_reserved_bytes_ = required_bytes; | bit_encoder_reserved_bytes_ = required_bytes; | ||||
| uint64_t buffer_start_size = buffer_.size(); | uint64_t buffer_start_size = buffer_.size(); | ||||
| if (encode_size) { | if (encode_size) { | ||||
| // Reserve memory for storing the encoded bit sequence size. It will be | // Reserve memory for storing the encoded bit sequence size. It will be | ||||
| // filled once the bit encoding ends. | // filled once the bit encoding ends. | ||||
| buffer_start_size += sizeof(uint64_t); | buffer_start_size += sizeof(uint64_t); | ||||
| } | } | ||||
| // Resize buffer to fit the maximum size of encoded bit data. | // Resize buffer to fit the maximum size of encoded bit data. | ||||
| buffer_.resize(buffer_start_size + required_bytes); | buffer_.resize(buffer_start_size + required_bytes); | ||||
| // Get the buffer data pointer for the bit encoder. | // Get the buffer data pointer for the bit encoder. | ||||
| const char *const data = buffer_.data() + buffer_start_size; | const char *const data = buffer_.data() + buffer_start_size; | ||||
| bit_encoder_ = | bit_encoder_ = | ||||
| std::unique_ptr<BitEncoder>(new BitEncoder(const_cast<char *>(data))); | std::unique_ptr<BitEncoder>(new BitEncoder(const_cast<char *>(data))); | ||||
| return true; | return true; | ||||
| } | } | ||||
| void EncoderBuffer::EndBitEncoding() { | void EncoderBuffer::EndBitEncoding() { | ||||
| if (!bit_encoder_active()) | if (!bit_encoder_active()) { | ||||
| return; | return; | ||||
| } | |||||
| // Get the number of encoded bits and bytes (rounded up). | // Get the number of encoded bits and bytes (rounded up). | ||||
| const uint64_t encoded_bits = bit_encoder_->Bits(); | const uint64_t encoded_bits = bit_encoder_->Bits(); | ||||
| const uint64_t encoded_bytes = (encoded_bits + 7) / 8; | const uint64_t encoded_bytes = (encoded_bits + 7) / 8; | ||||
| // Flush all cached bits that are not in the bit encoder's main buffer. | // Flush all cached bits that are not in the bit encoder's main buffer. | ||||
| bit_encoder_->Flush(0); | bit_encoder_->Flush(0); | ||||
| // Encode size if needed. | // Encode size if needed. | ||||
| if (encode_bit_sequence_size_) { | if (encode_bit_sequence_size_) { | ||||
| char *out_mem = const_cast<char *>(data() + size()); | char *out_mem = const_cast<char *>(data() + size()); | ||||
| Show All 24 Lines | |||||