// Copyright 2016 The Draco Authors. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #include "core/symbol_encoding.h" #include #include #include "core/bit_utils.h" #include "core/rans_symbol_encoder.h" namespace draco { constexpr int32_t kMaxTagSymbolBitLength = 32; constexpr int kMaxRawEncodingBitLength = 18; typedef uint64_t TaggedBitLengthFrequencies[kMaxTagSymbolBitLength]; void ConvertSignedIntsToSymbols(const int32_t *in, int in_values, uint32_t *out) { // Convert the quantized values into a format more suitable for entropy // encoding. // Put the sign bit into LSB pos and shift the rest one bit left. for (int i = 0; i < in_values; ++i) { int32_t val = in[i]; const bool is_negative = (val < 0); if (is_negative) val = -val - 1; // Map -1 to 0, -2 to -1, etc.. val <<= 1; if (is_negative) val |= 1; out[i] = static_cast(val); } } // 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 // computed for the largest value from the chunk. static void ComputeBitLengths(const uint32_t *symbols, int num_values, int num_components, std::vector *out_bit_lengths, uint32_t *out_max_value) { out_bit_lengths->reserve(num_values); *out_max_value = 0; // Maximum integer value across all components. for (int i = 0; i < num_values; i += num_components) { // Get the maximum value for a given entry across all attribute components. uint32_t max_component_value = symbols[i]; for (int j = 1; j < num_components; ++j) { if (max_component_value < symbols[i + j]) max_component_value = symbols[i + j]; } int value_msb_pos = 0; if (max_component_value > 0) { value_msb_pos = bits::MostSignificantBit(max_component_value); } if (max_component_value > *out_max_value) { *out_max_value = max_component_value; } out_bit_lengths->push_back(value_msb_pos + 1); } } template