diff options
Diffstat (limited to 'extern/draco/draco/src/draco/compression/attributes/sequential_quantization_attribute_decoder.cc')
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/sequential_quantization_attribute_decoder.cc | 64 |
1 files changed, 16 insertions, 48 deletions
diff --git a/extern/draco/draco/src/draco/compression/attributes/sequential_quantization_attribute_decoder.cc b/extern/draco/draco/src/draco/compression/attributes/sequential_quantization_attribute_decoder.cc index bf925c4a595..3d306e7dae6 100644 --- a/extern/draco/draco/src/draco/compression/attributes/sequential_quantization_attribute_decoder.cc +++ b/extern/draco/draco/src/draco/compression/attributes/sequential_quantization_attribute_decoder.cc @@ -14,13 +14,12 @@ // #include "draco/compression/attributes/sequential_quantization_attribute_decoder.h" -#include "draco/attributes/attribute_quantization_transform.h" #include "draco/core/quantization_utils.h" namespace draco { -SequentialQuantizationAttributeDecoder::SequentialQuantizationAttributeDecoder() - : quantization_bits_(-1), max_value_dif_(0.f) {} +SequentialQuantizationAttributeDecoder:: + SequentialQuantizationAttributeDecoder() {} bool SequentialQuantizationAttributeDecoder::Init(PointCloudDecoder *decoder, int attribute_id) { @@ -59,62 +58,31 @@ bool SequentialQuantizationAttributeDecoder:: } // Store the decoded transform data in portable attribute; - AttributeQuantizationTransform transform; - transform.SetParameters(quantization_bits_, min_value_.get(), - attribute()->num_components(), max_value_dif_); - return transform.TransferToAttribute(portable_attribute()); + return quantization_transform_.TransferToAttribute(portable_attribute()); } -bool SequentialQuantizationAttributeDecoder::StoreValues(uint32_t num_values) { - return DequantizeValues(num_values); +bool SequentialQuantizationAttributeDecoder::StoreValues(uint32_t num_points) { + return DequantizeValues(num_points); } bool SequentialQuantizationAttributeDecoder::DecodeQuantizedDataInfo() { - const int num_components = attribute()->num_components(); - min_value_ = std::unique_ptr<float[]>(new float[num_components]); - if (!decoder()->buffer()->Decode(min_value_.get(), - sizeof(float) * num_components)) { - return false; - } - if (!decoder()->buffer()->Decode(&max_value_dif_)) { - return false; + // Get attribute used as source for decoding. + auto att = GetPortableAttribute(); + if (att == nullptr) { + // This should happen only in the backward compatibility mode. It will still + // work fine for this case because the only thing the quantization transform + // cares about is the number of components that is the same for both source + // and target attributes. + att = attribute(); } - uint8_t quantization_bits; - if (!decoder()->buffer()->Decode(&quantization_bits) || - quantization_bits > 31) { - return false; - } - quantization_bits_ = quantization_bits; - return true; + return quantization_transform_.DecodeParameters(*att, decoder()->buffer()); } bool SequentialQuantizationAttributeDecoder::DequantizeValues( uint32_t num_values) { // Convert all quantized values back to floats. - const int32_t max_quantized_value = - (1u << static_cast<uint32_t>(quantization_bits_)) - 1; - const int num_components = attribute()->num_components(); - const int entry_size = sizeof(float) * num_components; - const std::unique_ptr<float[]> att_val(new float[num_components]); - int quant_val_id = 0; - int out_byte_pos = 0; - Dequantizer dequantizer; - if (!dequantizer.Init(max_value_dif_, max_quantized_value)) { - return false; - } - const int32_t *const portable_attribute_data = GetPortableAttributeData(); - for (uint32_t i = 0; i < num_values; ++i) { - for (int c = 0; c < num_components; ++c) { - float value = - dequantizer.DequantizeFloat(portable_attribute_data[quant_val_id++]); - value = value + min_value_[c]; - att_val[c] = value; - } - // Store the floating point value into the attribute buffer. - attribute()->buffer()->Write(out_byte_pos, att_val.get(), entry_size); - out_byte_pos += entry_size; - } - return true; + return quantization_transform_.InverseTransformAttribute( + *GetPortableAttribute(), attribute()); } } // namespace draco |