Changeset View
Changeset View
Standalone View
Standalone View
extern/draco/draco/src/draco/compression/entropy/symbol_decoding.cc
- This file was moved from extern/draco/dracoenc/src/draco/compression/entropy/symbol_decoding.cc.
| Show All 25 Lines | bool DecodeTaggedSymbols(uint32_t num_values, int num_components, | ||||
| DecoderBuffer *src_buffer, uint32_t *out_values); | DecoderBuffer *src_buffer, uint32_t *out_values); | ||||
| template <template <int> class SymbolDecoderT> | template <template <int> class SymbolDecoderT> | ||||
| bool DecodeRawSymbols(uint32_t num_values, DecoderBuffer *src_buffer, | bool DecodeRawSymbols(uint32_t num_values, DecoderBuffer *src_buffer, | ||||
| uint32_t *out_values); | uint32_t *out_values); | ||||
| bool DecodeSymbols(uint32_t num_values, int num_components, | bool DecodeSymbols(uint32_t num_values, int num_components, | ||||
| DecoderBuffer *src_buffer, uint32_t *out_values) { | DecoderBuffer *src_buffer, uint32_t *out_values) { | ||||
| if (num_values == 0) | if (num_values == 0) { | ||||
| return true; | return true; | ||||
| } | |||||
| // Decode which scheme to use. | // Decode which scheme to use. | ||||
| uint8_t scheme; | uint8_t scheme; | ||||
| if (!src_buffer->Decode(&scheme)) | if (!src_buffer->Decode(&scheme)) { | ||||
| return false; | return false; | ||||
| } | |||||
| if (scheme == SYMBOL_CODING_TAGGED) { | if (scheme == SYMBOL_CODING_TAGGED) { | ||||
| return DecodeTaggedSymbols<RAnsSymbolDecoder>(num_values, num_components, | return DecodeTaggedSymbols<RAnsSymbolDecoder>(num_values, num_components, | ||||
| src_buffer, out_values); | src_buffer, out_values); | ||||
| } else if (scheme == SYMBOL_CODING_RAW) { | } else if (scheme == SYMBOL_CODING_RAW) { | ||||
| return DecodeRawSymbols<RAnsSymbolDecoder>(num_values, src_buffer, | return DecodeRawSymbols<RAnsSymbolDecoder>(num_values, src_buffer, | ||||
| out_values); | out_values); | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| template <template <int> class SymbolDecoderT> | template <template <int> class SymbolDecoderT> | ||||
| bool DecodeTaggedSymbols(uint32_t num_values, int num_components, | bool DecodeTaggedSymbols(uint32_t num_values, int num_components, | ||||
| DecoderBuffer *src_buffer, uint32_t *out_values) { | DecoderBuffer *src_buffer, uint32_t *out_values) { | ||||
| // Decode the encoded data. | // Decode the encoded data. | ||||
| SymbolDecoderT<5> tag_decoder; | SymbolDecoderT<5> tag_decoder; | ||||
| if (!tag_decoder.Create(src_buffer)) | if (!tag_decoder.Create(src_buffer)) { | ||||
| return false; | return false; | ||||
| } | |||||
| if (!tag_decoder.StartDecoding(src_buffer)) | if (!tag_decoder.StartDecoding(src_buffer)) { | ||||
| return false; | return false; | ||||
| } | |||||
| if (num_values > 0 && tag_decoder.num_symbols() == 0) | if (num_values > 0 && tag_decoder.num_symbols() == 0) { | ||||
| return false; // Wrong number of symbols. | return false; // Wrong number of symbols. | ||||
| } | |||||
| // src_buffer now points behind the encoded tag data (to the place where the | // src_buffer now points behind the encoded tag data (to the place where the | ||||
| // values are encoded). | // values are encoded). | ||||
| src_buffer->StartBitDecoding(false, nullptr); | src_buffer->StartBitDecoding(false, nullptr); | ||||
| int value_id = 0; | int value_id = 0; | ||||
| for (uint32_t i = 0; i < num_values; i += num_components) { | for (uint32_t i = 0; i < num_values; i += num_components) { | ||||
| // Decode the tag. | // Decode the tag. | ||||
| const int bit_length = tag_decoder.DecodeSymbol(); | const int bit_length = tag_decoder.DecodeSymbol(); | ||||
| // Decode the actual value. | // Decode the actual value. | ||||
| for (int j = 0; j < num_components; ++j) { | for (int j = 0; j < num_components; ++j) { | ||||
| uint32_t val; | uint32_t val; | ||||
| if (!src_buffer->DecodeLeastSignificantBits32(bit_length, &val)) | if (!src_buffer->DecodeLeastSignificantBits32(bit_length, &val)) { | ||||
| return false; | return false; | ||||
| } | |||||
| out_values[value_id++] = val; | out_values[value_id++] = val; | ||||
| } | } | ||||
| } | } | ||||
| tag_decoder.EndDecoding(); | tag_decoder.EndDecoding(); | ||||
| src_buffer->EndBitDecoding(); | src_buffer->EndBitDecoding(); | ||||
| return true; | return true; | ||||
| } | } | ||||
| template <class SymbolDecoderT> | template <class SymbolDecoderT> | ||||
| bool DecodeRawSymbolsInternal(uint32_t num_values, DecoderBuffer *src_buffer, | bool DecodeRawSymbolsInternal(uint32_t num_values, DecoderBuffer *src_buffer, | ||||
| uint32_t *out_values) { | uint32_t *out_values) { | ||||
| SymbolDecoderT decoder; | SymbolDecoderT decoder; | ||||
| if (!decoder.Create(src_buffer)) | if (!decoder.Create(src_buffer)) { | ||||
| return false; | return false; | ||||
| } | |||||
| if (num_values > 0 && decoder.num_symbols() == 0) | if (num_values > 0 && decoder.num_symbols() == 0) { | ||||
| return false; // Wrong number of symbols. | return false; // Wrong number of symbols. | ||||
| } | |||||
| if (!decoder.StartDecoding(src_buffer)) | if (!decoder.StartDecoding(src_buffer)) { | ||||
| return false; | return false; | ||||
| } | |||||
| for (uint32_t i = 0; i < num_values; ++i) { | for (uint32_t i = 0; i < num_values; ++i) { | ||||
| // Decode a symbol into the value. | // Decode a symbol into the value. | ||||
| const uint32_t value = decoder.DecodeSymbol(); | const uint32_t value = decoder.DecodeSymbol(); | ||||
| out_values[i] = value; | out_values[i] = value; | ||||
| } | } | ||||
| decoder.EndDecoding(); | decoder.EndDecoding(); | ||||
| return true; | return true; | ||||
| } | } | ||||
| template <template <int> class SymbolDecoderT> | template <template <int> class SymbolDecoderT> | ||||
| bool DecodeRawSymbols(uint32_t num_values, DecoderBuffer *src_buffer, | bool DecodeRawSymbols(uint32_t num_values, DecoderBuffer *src_buffer, | ||||
| uint32_t *out_values) { | uint32_t *out_values) { | ||||
| uint8_t max_bit_length; | uint8_t max_bit_length; | ||||
| if (!src_buffer->Decode(&max_bit_length)) | if (!src_buffer->Decode(&max_bit_length)) { | ||||
| return false; | return false; | ||||
| } | |||||
| switch (max_bit_length) { | switch (max_bit_length) { | ||||
| case 1: | case 1: | ||||
| return DecodeRawSymbolsInternal<SymbolDecoderT<1>>(num_values, src_buffer, | return DecodeRawSymbolsInternal<SymbolDecoderT<1>>(num_values, src_buffer, | ||||
| out_values); | out_values); | ||||
| case 2: | case 2: | ||||
| return DecodeRawSymbolsInternal<SymbolDecoderT<2>>(num_values, src_buffer, | return DecodeRawSymbolsInternal<SymbolDecoderT<2>>(num_values, src_buffer, | ||||
| out_values); | out_values); | ||||
| case 3: | case 3: | ||||
| ▲ Show 20 Lines • Show All 53 Lines • Show Last 20 Lines | |||||