Differential D9642 Diff 31697 extern/draco/draco/src/draco/compression/attributes/sequential_quantization_attribute_decoder.cc
Changeset View
Changeset View
Standalone View
Standalone View
extern/draco/draco/src/draco/compression/attributes/sequential_quantization_attribute_decoder.cc
- This file was moved from extern/draco/dracoenc/src/draco/compression/attributes/sequential_quantization_attribute_decoder.cc.
| Show All 18 Lines | |||||
| namespace draco { | namespace draco { | ||||
| SequentialQuantizationAttributeDecoder::SequentialQuantizationAttributeDecoder() | SequentialQuantizationAttributeDecoder::SequentialQuantizationAttributeDecoder() | ||||
| : quantization_bits_(-1), max_value_dif_(0.f) {} | : quantization_bits_(-1), max_value_dif_(0.f) {} | ||||
| bool SequentialQuantizationAttributeDecoder::Init(PointCloudDecoder *decoder, | bool SequentialQuantizationAttributeDecoder::Init(PointCloudDecoder *decoder, | ||||
| int attribute_id) { | int attribute_id) { | ||||
| if (!SequentialIntegerAttributeDecoder::Init(decoder, attribute_id)) | if (!SequentialIntegerAttributeDecoder::Init(decoder, attribute_id)) { | ||||
| return false; | return false; | ||||
| } | |||||
| const PointAttribute *const attribute = | const PointAttribute *const attribute = | ||||
| decoder->point_cloud()->attribute(attribute_id); | decoder->point_cloud()->attribute(attribute_id); | ||||
| // Currently we can quantize only floating point arguments. | // Currently we can quantize only floating point arguments. | ||||
| if (attribute->data_type() != DT_FLOAT32) | if (attribute->data_type() != DT_FLOAT32) { | ||||
| return false; | return false; | ||||
| } | |||||
| return true; | return true; | ||||
| } | } | ||||
| bool SequentialQuantizationAttributeDecoder::DecodeIntegerValues( | bool SequentialQuantizationAttributeDecoder::DecodeIntegerValues( | ||||
| const std::vector<PointIndex> &point_ids, DecoderBuffer *in_buffer) { | const std::vector<PointIndex> &point_ids, DecoderBuffer *in_buffer) { | ||||
| #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED | #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED | ||||
| if (decoder()->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0) && | if (decoder()->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0) && | ||||
| !DecodeQuantizedDataInfo()) | !DecodeQuantizedDataInfo()) { | ||||
| return false; | return false; | ||||
| } | |||||
| #endif | #endif | ||||
| return SequentialIntegerAttributeDecoder::DecodeIntegerValues(point_ids, | return SequentialIntegerAttributeDecoder::DecodeIntegerValues(point_ids, | ||||
| in_buffer); | in_buffer); | ||||
| } | } | ||||
| bool SequentialQuantizationAttributeDecoder:: | bool SequentialQuantizationAttributeDecoder:: | ||||
| DecodeDataNeededByPortableTransform( | DecodeDataNeededByPortableTransform( | ||||
| const std::vector<PointIndex> &point_ids, DecoderBuffer *in_buffer) { | const std::vector<PointIndex> &point_ids, DecoderBuffer *in_buffer) { | ||||
| if (decoder()->bitstream_version() >= DRACO_BITSTREAM_VERSION(2, 0)) { | if (decoder()->bitstream_version() >= DRACO_BITSTREAM_VERSION(2, 0)) { | ||||
| // Decode quantization data here only for files with bitstream version 2.0+ | // Decode quantization data here only for files with bitstream version 2.0+ | ||||
| if (!DecodeQuantizedDataInfo()) | if (!DecodeQuantizedDataInfo()) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | |||||
| // Store the decoded transform data in portable attribute; | // Store the decoded transform data in portable attribute; | ||||
| AttributeQuantizationTransform transform; | AttributeQuantizationTransform transform; | ||||
| transform.SetParameters(quantization_bits_, min_value_.get(), | transform.SetParameters(quantization_bits_, min_value_.get(), | ||||
| attribute()->num_components(), max_value_dif_); | attribute()->num_components(), max_value_dif_); | ||||
| return transform.TransferToAttribute(portable_attribute()); | return transform.TransferToAttribute(portable_attribute()); | ||||
| } | } | ||||
| bool SequentialQuantizationAttributeDecoder::StoreValues(uint32_t num_values) { | bool SequentialQuantizationAttributeDecoder::StoreValues(uint32_t num_values) { | ||||
| return DequantizeValues(num_values); | return DequantizeValues(num_values); | ||||
| } | } | ||||
| bool SequentialQuantizationAttributeDecoder::DecodeQuantizedDataInfo() { | bool SequentialQuantizationAttributeDecoder::DecodeQuantizedDataInfo() { | ||||
| const int num_components = attribute()->num_components(); | const int num_components = attribute()->num_components(); | ||||
| min_value_ = std::unique_ptr<float[]>(new float[num_components]); | min_value_ = std::unique_ptr<float[]>(new float[num_components]); | ||||
| if (!decoder()->buffer()->Decode(min_value_.get(), | if (!decoder()->buffer()->Decode(min_value_.get(), | ||||
| sizeof(float) * num_components)) | sizeof(float) * num_components)) { | ||||
| return false; | return false; | ||||
| if (!decoder()->buffer()->Decode(&max_value_dif_)) | } | ||||
| if (!decoder()->buffer()->Decode(&max_value_dif_)) { | |||||
| return false; | return false; | ||||
| } | |||||
| uint8_t quantization_bits; | uint8_t quantization_bits; | ||||
| if (!decoder()->buffer()->Decode(&quantization_bits) || | if (!decoder()->buffer()->Decode(&quantization_bits) || | ||||
| quantization_bits > 31) | quantization_bits > 31) { | ||||
| return false; | return false; | ||||
| } | |||||
| quantization_bits_ = quantization_bits; | quantization_bits_ = quantization_bits; | ||||
| return true; | return true; | ||||
| } | } | ||||
| bool SequentialQuantizationAttributeDecoder::DequantizeValues( | bool SequentialQuantizationAttributeDecoder::DequantizeValues( | ||||
| uint32_t num_values) { | uint32_t num_values) { | ||||
| // Convert all quantized values back to floats. | // Convert all quantized values back to floats. | ||||
| const int32_t max_quantized_value = | const int32_t max_quantized_value = | ||||
| (1u << static_cast<uint32_t>(quantization_bits_)) - 1; | (1u << static_cast<uint32_t>(quantization_bits_)) - 1; | ||||
| const int num_components = attribute()->num_components(); | const int num_components = attribute()->num_components(); | ||||
| const int entry_size = sizeof(float) * num_components; | const int entry_size = sizeof(float) * num_components; | ||||
| const std::unique_ptr<float[]> att_val(new float[num_components]); | const std::unique_ptr<float[]> att_val(new float[num_components]); | ||||
| int quant_val_id = 0; | int quant_val_id = 0; | ||||
| int out_byte_pos = 0; | int out_byte_pos = 0; | ||||
| Dequantizer dequantizer; | Dequantizer dequantizer; | ||||
| if (!dequantizer.Init(max_value_dif_, max_quantized_value)) | if (!dequantizer.Init(max_value_dif_, max_quantized_value)) { | ||||
| return false; | return false; | ||||
| } | |||||
| const int32_t *const portable_attribute_data = GetPortableAttributeData(); | const int32_t *const portable_attribute_data = GetPortableAttributeData(); | ||||
| for (uint32_t i = 0; i < num_values; ++i) { | for (uint32_t i = 0; i < num_values; ++i) { | ||||
| for (int c = 0; c < num_components; ++c) { | for (int c = 0; c < num_components; ++c) { | ||||
| float value = | float value = | ||||
| dequantizer.DequantizeFloat(portable_attribute_data[quant_val_id++]); | dequantizer.DequantizeFloat(portable_attribute_data[quant_val_id++]); | ||||
| value = value + min_value_[c]; | value = value + min_value_[c]; | ||||
| att_val[c] = value; | att_val[c] = value; | ||||
| } | } | ||||
| // Store the floating point value into the attribute buffer. | // Store the floating point value into the attribute buffer. | ||||
| attribute()->buffer()->Write(out_byte_pos, att_val.get(), entry_size); | attribute()->buffer()->Write(out_byte_pos, att_val.get(), entry_size); | ||||
| out_byte_pos += entry_size; | out_byte_pos += entry_size; | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| } // namespace draco | } // namespace draco | ||||