Changeset View
Changeset View
Standalone View
Standalone View
extern/draco/draco/src/draco/compression/entropy/symbol_encoding.cc
- This file was moved from extern/draco/dracoenc/src/draco/compression/entropy/symbol_encoding.cc.
| Show All 30 Lines | |||||
| typedef uint64_t TaggedBitLengthFrequencies[kMaxTagSymbolBitLength]; | typedef uint64_t TaggedBitLengthFrequencies[kMaxTagSymbolBitLength]; | ||||
| void SetSymbolEncodingMethod(Options *options, SymbolCodingMethod method) { | void SetSymbolEncodingMethod(Options *options, SymbolCodingMethod method) { | ||||
| options->SetInt("symbol_encoding_method", method); | options->SetInt("symbol_encoding_method", method); | ||||
| } | } | ||||
| bool SetSymbolEncodingCompressionLevel(Options *options, | bool SetSymbolEncodingCompressionLevel(Options *options, | ||||
| int compression_level) { | int compression_level) { | ||||
| if (compression_level < 0 || compression_level > 10) | if (compression_level < 0 || compression_level > 10) { | ||||
| return false; | return false; | ||||
| } | |||||
| options->SetInt("symbol_encoding_compression_level", compression_level); | options->SetInt("symbol_encoding_compression_level", compression_level); | ||||
| return true; | return true; | ||||
| } | } | ||||
| // Computes bit lengths of the input values. If num_components > 1, the values | // Computes bit lengths of the input values. If num_components > 1, the values | ||||
| // are processed in "num_components" sized chunks and the bit length is always | // are processed in "num_components" sized chunks and the bit length is always | ||||
| // computed for the largest value from the chunk. | // computed for the largest value from the chunk. | ||||
| static void ComputeBitLengths(const uint32_t *symbols, int num_values, | static void ComputeBitLengths(const uint32_t *symbols, int num_values, | ||||
| int num_components, | int num_components, | ||||
| std::vector<uint32_t> *out_bit_lengths, | std::vector<uint32_t> *out_bit_lengths, | ||||
| uint32_t *out_max_value) { | uint32_t *out_max_value) { | ||||
| out_bit_lengths->reserve(num_values); | out_bit_lengths->reserve(num_values); | ||||
| *out_max_value = 0; | *out_max_value = 0; | ||||
| // Maximum integer value across all components. | // Maximum integer value across all components. | ||||
| for (int i = 0; i < num_values; i += num_components) { | for (int i = 0; i < num_values; i += num_components) { | ||||
| // Get the maximum value for a given entry across all attribute components. | // Get the maximum value for a given entry across all attribute components. | ||||
| uint32_t max_component_value = symbols[i]; | uint32_t max_component_value = symbols[i]; | ||||
| for (int j = 1; j < num_components; ++j) { | for (int j = 1; j < num_components; ++j) { | ||||
| if (max_component_value < symbols[i + j]) | if (max_component_value < symbols[i + j]) { | ||||
| max_component_value = symbols[i + j]; | max_component_value = symbols[i + j]; | ||||
| } | } | ||||
| } | |||||
| int value_msb_pos = 0; | int value_msb_pos = 0; | ||||
| if (max_component_value > 0) { | if (max_component_value > 0) { | ||||
| value_msb_pos = MostSignificantBit(max_component_value); | value_msb_pos = MostSignificantBit(max_component_value); | ||||
| } | } | ||||
| if (max_component_value > *out_max_value) { | if (max_component_value > *out_max_value) { | ||||
| *out_max_value = max_component_value; | *out_max_value = max_component_value; | ||||
| } | } | ||||
| out_bit_lengths->push_back(value_msb_pos + 1); | out_bit_lengths->push_back(value_msb_pos + 1); | ||||
| Show All 38 Lines | |||||
| template <template <int> class SymbolEncoderT> | template <template <int> class SymbolEncoderT> | ||||
| bool EncodeRawSymbols(const uint32_t *symbols, int num_values, | bool EncodeRawSymbols(const uint32_t *symbols, int num_values, | ||||
| uint32_t max_entry_value, int32_t num_unique_symbols, | uint32_t max_entry_value, int32_t num_unique_symbols, | ||||
| const Options *options, EncoderBuffer *target_buffer); | const Options *options, EncoderBuffer *target_buffer); | ||||
| bool EncodeSymbols(const uint32_t *symbols, int num_values, int num_components, | bool EncodeSymbols(const uint32_t *symbols, int num_values, int num_components, | ||||
| const Options *options, EncoderBuffer *target_buffer) { | const Options *options, EncoderBuffer *target_buffer) { | ||||
| if (num_values < 0) | if (num_values < 0) { | ||||
| return false; | return false; | ||||
| if (num_values == 0) | } | ||||
| if (num_values == 0) { | |||||
| return true; | return true; | ||||
| if (num_components <= 0) | } | ||||
| if (num_components <= 0) { | |||||
| num_components = 1; | num_components = 1; | ||||
| } | |||||
| std::vector<uint32_t> bit_lengths; | std::vector<uint32_t> bit_lengths; | ||||
| uint32_t max_value; | uint32_t max_value; | ||||
| ComputeBitLengths(symbols, num_values, num_components, &bit_lengths, | ComputeBitLengths(symbols, num_values, num_components, &bit_lengths, | ||||
| &max_value); | &max_value); | ||||
| // Approximate number of bits needed for storing the symbols using the tagged | // Approximate number of bits needed for storing the symbols using the tagged | ||||
| // scheme. | // scheme. | ||||
| const int64_t tagged_scheme_total_bits = | const int64_t tagged_scheme_total_bits = | ||||
| ▲ Show 20 Lines • Show All 140 Lines • ▼ Show 20 Lines | bool EncodeRawSymbols(const uint32_t *symbols, int num_values, | ||||
| uint32_t max_entry_value, int32_t num_unique_symbols, | uint32_t max_entry_value, int32_t num_unique_symbols, | ||||
| const Options *options, EncoderBuffer *target_buffer) { | const Options *options, EncoderBuffer *target_buffer) { | ||||
| int symbol_bits = 0; | int symbol_bits = 0; | ||||
| if (num_unique_symbols > 0) { | if (num_unique_symbols > 0) { | ||||
| symbol_bits = MostSignificantBit(num_unique_symbols); | symbol_bits = MostSignificantBit(num_unique_symbols); | ||||
| } | } | ||||
| int unique_symbols_bit_length = symbol_bits + 1; | int unique_symbols_bit_length = symbol_bits + 1; | ||||
| // Currently, we don't support encoding of more than 2^18 unique symbols. | // Currently, we don't support encoding of more than 2^18 unique symbols. | ||||
| if (unique_symbols_bit_length > kMaxRawEncodingBitLength) | if (unique_symbols_bit_length > kMaxRawEncodingBitLength) { | ||||
| return false; | return false; | ||||
| } | |||||
| int compression_level = kDefaultSymbolCodingCompressionLevel; | int compression_level = kDefaultSymbolCodingCompressionLevel; | ||||
| if (options != nullptr && | if (options != nullptr && | ||||
| options->IsOptionSet("symbol_encoding_compression_level")) { | options->IsOptionSet("symbol_encoding_compression_level")) { | ||||
| compression_level = options->GetInt("symbol_encoding_compression_level"); | compression_level = options->GetInt("symbol_encoding_compression_level"); | ||||
| } | } | ||||
| // Adjust the bit_length based on compression level. Lower compression levels | // Adjust the bit_length based on compression level. Lower compression levels | ||||
| // will use fewer bits while higher compression levels use more bits. Note | // will use fewer bits while higher compression levels use more bits. Note | ||||
| ▲ Show 20 Lines • Show All 83 Lines • Show Last 20 Lines | |||||