Differential D9642 Diff 31697 extern/draco/draco/src/draco/compression/attributes/sequential_integer_attribute_decoder.cc
Changeset View
Changeset View
Standalone View
Standalone View
extern/draco/draco/src/draco/compression/attributes/sequential_integer_attribute_decoder.cc
- This file was moved from extern/draco/dracoenc/src/draco/compression/attributes/sequential_integer_attribute_decoder.cc.
| Show All 18 Lines | |||||
| #include "draco/compression/entropy/symbol_decoding.h" | #include "draco/compression/entropy/symbol_decoding.h" | ||||
| namespace draco { | namespace draco { | ||||
| SequentialIntegerAttributeDecoder::SequentialIntegerAttributeDecoder() {} | SequentialIntegerAttributeDecoder::SequentialIntegerAttributeDecoder() {} | ||||
| bool SequentialIntegerAttributeDecoder::Init(PointCloudDecoder *decoder, | bool SequentialIntegerAttributeDecoder::Init(PointCloudDecoder *decoder, | ||||
| int attribute_id) { | int attribute_id) { | ||||
| if (!SequentialAttributeDecoder::Init(decoder, attribute_id)) | if (!SequentialAttributeDecoder::Init(decoder, attribute_id)) { | ||||
| return false; | return false; | ||||
| } | |||||
| return true; | return true; | ||||
| } | } | ||||
| bool SequentialIntegerAttributeDecoder::TransformAttributeToOriginalFormat( | bool SequentialIntegerAttributeDecoder::TransformAttributeToOriginalFormat( | ||||
| const std::vector<PointIndex> &point_ids) { | const std::vector<PointIndex> &point_ids) { | ||||
| #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED | #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED | ||||
| if (decoder() && | if (decoder() && | ||||
| decoder()->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) | decoder()->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) { | ||||
| return true; // Don't revert the transform here for older files. | return true; // Don't revert the transform here for older files. | ||||
| } | |||||
| #endif | #endif | ||||
| return StoreValues(static_cast<uint32_t>(point_ids.size())); | return StoreValues(static_cast<uint32_t>(point_ids.size())); | ||||
| } | } | ||||
| bool SequentialIntegerAttributeDecoder::DecodeValues( | bool SequentialIntegerAttributeDecoder::DecodeValues( | ||||
| const std::vector<PointIndex> &point_ids, DecoderBuffer *in_buffer) { | const std::vector<PointIndex> &point_ids, DecoderBuffer *in_buffer) { | ||||
| // Decode prediction scheme. | // Decode prediction scheme. | ||||
| int8_t prediction_scheme_method; | int8_t prediction_scheme_method; | ||||
| in_buffer->Decode(&prediction_scheme_method); | if (!in_buffer->Decode(&prediction_scheme_method)) { | ||||
| return false; | |||||
| } | |||||
| if (prediction_scheme_method != PREDICTION_NONE) { | if (prediction_scheme_method != PREDICTION_NONE) { | ||||
| int8_t prediction_transform_type; | int8_t prediction_transform_type; | ||||
| in_buffer->Decode(&prediction_transform_type); | if (!in_buffer->Decode(&prediction_transform_type)) { | ||||
| return false; | |||||
| } | |||||
| prediction_scheme_ = CreateIntPredictionScheme( | prediction_scheme_ = CreateIntPredictionScheme( | ||||
| static_cast<PredictionSchemeMethod>(prediction_scheme_method), | static_cast<PredictionSchemeMethod>(prediction_scheme_method), | ||||
| static_cast<PredictionSchemeTransformType>(prediction_transform_type)); | static_cast<PredictionSchemeTransformType>(prediction_transform_type)); | ||||
| } | } | ||||
| if (prediction_scheme_) { | if (prediction_scheme_) { | ||||
| if (!InitPredictionScheme(prediction_scheme_.get())) | if (!InitPredictionScheme(prediction_scheme_.get())) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | |||||
| if (!DecodeIntegerValues(point_ids, in_buffer)) | if (!DecodeIntegerValues(point_ids, in_buffer)) { | ||||
| return false; | return false; | ||||
| } | |||||
| #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED | #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED | ||||
| const int32_t num_values = static_cast<uint32_t>(point_ids.size()); | const int32_t num_values = static_cast<uint32_t>(point_ids.size()); | ||||
| if (decoder() && | if (decoder() && | ||||
| decoder()->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) { | decoder()->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) { | ||||
| // For older files, revert the transform right after we decode the data. | // For older files, revert the transform right after we decode the data. | ||||
| if (!StoreValues(num_values)) | if (!StoreValues(num_values)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | |||||
| #endif | #endif | ||||
| return true; | return true; | ||||
| } | } | ||||
| std::unique_ptr<PredictionSchemeTypedDecoderInterface<int32_t>> | std::unique_ptr<PredictionSchemeTypedDecoderInterface<int32_t>> | ||||
| SequentialIntegerAttributeDecoder::CreateIntPredictionScheme( | SequentialIntegerAttributeDecoder::CreateIntPredictionScheme( | ||||
| PredictionSchemeMethod method, | PredictionSchemeMethod method, | ||||
| PredictionSchemeTransformType transform_type) { | PredictionSchemeTransformType transform_type) { | ||||
| if (transform_type != PREDICTION_TRANSFORM_WRAP) | if (transform_type != PREDICTION_TRANSFORM_WRAP) { | ||||
| return nullptr; // For now we support only wrap transform. | return nullptr; // For now we support only wrap transform. | ||||
| } | |||||
| return CreatePredictionSchemeForDecoder< | return CreatePredictionSchemeForDecoder< | ||||
| int32_t, PredictionSchemeWrapDecodingTransform<int32_t>>( | int32_t, PredictionSchemeWrapDecodingTransform<int32_t>>( | ||||
| method, attribute_id(), decoder()); | method, attribute_id(), decoder()); | ||||
| } | } | ||||
| bool SequentialIntegerAttributeDecoder::DecodeIntegerValues( | bool SequentialIntegerAttributeDecoder::DecodeIntegerValues( | ||||
| const std::vector<PointIndex> &point_ids, DecoderBuffer *in_buffer) { | const std::vector<PointIndex> &point_ids, DecoderBuffer *in_buffer) { | ||||
| const int num_components = GetNumValueComponents(); | const int num_components = GetNumValueComponents(); | ||||
| if (num_components <= 0) | if (num_components <= 0) { | ||||
| return false; | return false; | ||||
| } | |||||
| const size_t num_entries = point_ids.size(); | const size_t num_entries = point_ids.size(); | ||||
| const size_t num_values = num_entries * num_components; | const size_t num_values = num_entries * num_components; | ||||
| PreparePortableAttribute(static_cast<int>(num_entries), num_components); | PreparePortableAttribute(static_cast<int>(num_entries), num_components); | ||||
| int32_t *const portable_attribute_data = GetPortableAttributeData(); | int32_t *const portable_attribute_data = GetPortableAttributeData(); | ||||
| if (portable_attribute_data == nullptr) | if (portable_attribute_data == nullptr) { | ||||
| return false; | return false; | ||||
| } | |||||
| uint8_t compressed; | uint8_t compressed; | ||||
| if (!in_buffer->Decode(&compressed)) | if (!in_buffer->Decode(&compressed)) { | ||||
| return false; | return false; | ||||
| } | |||||
| if (compressed > 0) { | if (compressed > 0) { | ||||
| // Decode compressed values. | // Decode compressed values. | ||||
| if (!DecodeSymbols(static_cast<uint32_t>(num_values), num_components, | if (!DecodeSymbols(static_cast<uint32_t>(num_values), num_components, | ||||
| in_buffer, | in_buffer, | ||||
| reinterpret_cast<uint32_t *>(portable_attribute_data))) | reinterpret_cast<uint32_t *>(portable_attribute_data))) { | ||||
| return false; | return false; | ||||
| } | |||||
| } else { | } else { | ||||
| // Decode the integer data directly. | // Decode the integer data directly. | ||||
| // Get the number of bytes for a given entry. | // Get the number of bytes for a given entry. | ||||
| uint8_t num_bytes; | uint8_t num_bytes; | ||||
| if (!in_buffer->Decode(&num_bytes)) | if (!in_buffer->Decode(&num_bytes)) { | ||||
| return false; | return false; | ||||
| } | |||||
| if (num_bytes == DataTypeLength(DT_INT32)) { | if (num_bytes == DataTypeLength(DT_INT32)) { | ||||
| if (portable_attribute()->buffer()->data_size() < | if (portable_attribute()->buffer()->data_size() < | ||||
| sizeof(int32_t) * num_values) | sizeof(int32_t) * num_values) { | ||||
| return false; | return false; | ||||
| } | |||||
| if (!in_buffer->Decode(portable_attribute_data, | if (!in_buffer->Decode(portable_attribute_data, | ||||
| sizeof(int32_t) * num_values)) | sizeof(int32_t) * num_values)) { | ||||
| return false; | return false; | ||||
| } | |||||
| } else { | } else { | ||||
| if (portable_attribute()->buffer()->data_size() < num_bytes * num_values) | if (portable_attribute()->buffer()->data_size() < | ||||
| num_bytes * num_values) { | |||||
| return false; | return false; | ||||
| } | |||||
| if (in_buffer->remaining_size() < | if (in_buffer->remaining_size() < | ||||
| static_cast<int64_t>(num_bytes) * static_cast<int64_t>(num_values)) | static_cast<int64_t>(num_bytes) * static_cast<int64_t>(num_values)) { | ||||
| return false; | return false; | ||||
| } | |||||
| for (size_t i = 0; i < num_values; ++i) { | for (size_t i = 0; i < num_values; ++i) { | ||||
| in_buffer->Decode(portable_attribute_data + i, num_bytes); | if (!in_buffer->Decode(portable_attribute_data + i, num_bytes)) | ||||
| return false; | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| if (num_values > 0 && (prediction_scheme_ == nullptr || | if (num_values > 0 && (prediction_scheme_ == nullptr || | ||||
| !prediction_scheme_->AreCorrectionsPositive())) { | !prediction_scheme_->AreCorrectionsPositive())) { | ||||
| // Convert the values back to the original signed format. | // Convert the values back to the original signed format. | ||||
| ConvertSymbolsToSignedInts( | ConvertSymbolsToSignedInts( | ||||
| reinterpret_cast<const uint32_t *>(portable_attribute_data), | reinterpret_cast<const uint32_t *>(portable_attribute_data), | ||||
| static_cast<int>(num_values), portable_attribute_data); | static_cast<int>(num_values), portable_attribute_data); | ||||
| } | } | ||||
| // If the data was encoded with a prediction scheme, we must revert it. | // If the data was encoded with a prediction scheme, we must revert it. | ||||
| if (prediction_scheme_) { | if (prediction_scheme_) { | ||||
| if (!prediction_scheme_->DecodePredictionData(in_buffer)) | if (!prediction_scheme_->DecodePredictionData(in_buffer)) { | ||||
| return false; | return false; | ||||
| } | |||||
| if (num_values > 0) { | if (num_values > 0) { | ||||
| if (!prediction_scheme_->ComputeOriginalValues( | if (!prediction_scheme_->ComputeOriginalValues( | ||||
| portable_attribute_data, portable_attribute_data, | portable_attribute_data, portable_attribute_data, | ||||
| static_cast<int>(num_values), num_components, point_ids.data())) { | static_cast<int>(num_values), num_components, point_ids.data())) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 63 Lines • Show Last 20 Lines | |||||