Differential D9642 Diff 31337 extern/draco/draco/src/draco/compression/attributes/attributes_decoder.cc
Changeset View
Changeset View
Standalone View
Standalone View
extern/draco/draco/src/draco/compression/attributes/attributes_decoder.cc
- This file was moved from extern/draco/dracoenc/src/draco/compression/attributes/attributes_decoder.cc.
| Show All 27 Lines | |||||
| } | } | ||||
| bool AttributesDecoder::DecodeAttributesDecoderData(DecoderBuffer *in_buffer) { | bool AttributesDecoder::DecodeAttributesDecoderData(DecoderBuffer *in_buffer) { | ||||
| // Decode and create attributes. | // Decode and create attributes. | ||||
| uint32_t num_attributes; | uint32_t num_attributes; | ||||
| #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED | #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED | ||||
| if (point_cloud_decoder_->bitstream_version() < | if (point_cloud_decoder_->bitstream_version() < | ||||
| DRACO_BITSTREAM_VERSION(2, 0)) { | DRACO_BITSTREAM_VERSION(2, 0)) { | ||||
| if (!in_buffer->Decode(&num_attributes)) | if (!in_buffer->Decode(&num_attributes)) { | ||||
| return false; | return false; | ||||
| } | |||||
| } else | } else | ||||
| #endif | #endif | ||||
| { | { | ||||
| if (!DecodeVarint(&num_attributes, in_buffer)) | if (!DecodeVarint(&num_attributes, in_buffer)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| if (num_attributes == 0) | } | ||||
| if (num_attributes == 0) { | |||||
| return false; | return false; | ||||
| } | |||||
| point_attribute_ids_.resize(num_attributes); | point_attribute_ids_.resize(num_attributes); | ||||
| PointCloud *pc = point_cloud_; | PointCloud *pc = point_cloud_; | ||||
| for (uint32_t i = 0; i < num_attributes; ++i) { | for (uint32_t i = 0; i < num_attributes; ++i) { | ||||
| // Decode attribute descriptor data. | // Decode attribute descriptor data. | ||||
| uint8_t att_type, data_type, num_components, normalized; | uint8_t att_type, data_type, num_components, normalized; | ||||
| if (!in_buffer->Decode(&att_type)) | if (!in_buffer->Decode(&att_type)) { | ||||
| return false; | return false; | ||||
| if (!in_buffer->Decode(&data_type)) | } | ||||
| if (!in_buffer->Decode(&data_type)) { | |||||
| return false; | |||||
| } | |||||
| if (!in_buffer->Decode(&num_components)) { | |||||
| return false; | return false; | ||||
| if (!in_buffer->Decode(&num_components)) | } | ||||
| if (!in_buffer->Decode(&normalized)) { | |||||
| return false; | return false; | ||||
| if (!in_buffer->Decode(&normalized)) | } | ||||
| if (att_type >= GeometryAttribute::NAMED_ATTRIBUTES_COUNT) { | |||||
| return false; | return false; | ||||
| if (data_type <= DT_INVALID || data_type >= DT_TYPES_COUNT) | } | ||||
| if (data_type == DT_INVALID || data_type >= DT_TYPES_COUNT) { | |||||
| return false; | return false; | ||||
| } | |||||
| const DataType draco_dt = static_cast<DataType>(data_type); | const DataType draco_dt = static_cast<DataType>(data_type); | ||||
| // Add the attribute to the point cloud | // Add the attribute to the point cloud | ||||
| GeometryAttribute ga; | GeometryAttribute ga; | ||||
| ga.Init(static_cast<GeometryAttribute::Type>(att_type), nullptr, | ga.Init(static_cast<GeometryAttribute::Type>(att_type), nullptr, | ||||
| num_components, draco_dt, normalized > 0, | num_components, draco_dt, normalized > 0, | ||||
| DataTypeLength(draco_dt) * num_components, 0); | DataTypeLength(draco_dt) * num_components, 0); | ||||
| uint32_t unique_id; | uint32_t unique_id; | ||||
| #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED | #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED | ||||
| if (point_cloud_decoder_->bitstream_version() < | if (point_cloud_decoder_->bitstream_version() < | ||||
| DRACO_BITSTREAM_VERSION(1, 3)) { | DRACO_BITSTREAM_VERSION(1, 3)) { | ||||
| uint16_t custom_id; | uint16_t custom_id; | ||||
| if (!in_buffer->Decode(&custom_id)) | if (!in_buffer->Decode(&custom_id)) { | ||||
| return false; | return false; | ||||
| } | |||||
| // TODO(draco-eng): Add "custom_id" to attribute metadata. | // TODO(draco-eng): Add "custom_id" to attribute metadata. | ||||
| unique_id = static_cast<uint32_t>(custom_id); | unique_id = static_cast<uint32_t>(custom_id); | ||||
| ga.set_unique_id(unique_id); | ga.set_unique_id(unique_id); | ||||
| } else | } else | ||||
| #endif | #endif | ||||
| { | { | ||||
| DecodeVarint(&unique_id, in_buffer); | DecodeVarint(&unique_id, in_buffer); | ||||
| ga.set_unique_id(unique_id); | ga.set_unique_id(unique_id); | ||||
| } | } | ||||
| const int att_id = pc->AddAttribute( | const int att_id = pc->AddAttribute( | ||||
| std::unique_ptr<PointAttribute>(new PointAttribute(ga))); | std::unique_ptr<PointAttribute>(new PointAttribute(ga))); | ||||
| pc->attribute(att_id)->set_unique_id(unique_id); | pc->attribute(att_id)->set_unique_id(unique_id); | ||||
| point_attribute_ids_[i] = att_id; | point_attribute_ids_[i] = att_id; | ||||
| // Update the inverse map. | // Update the inverse map. | ||||
| if (att_id >= static_cast<int32_t>(point_attribute_to_local_id_map_.size())) | if (att_id >= | ||||
| static_cast<int32_t>(point_attribute_to_local_id_map_.size())) { | |||||
| point_attribute_to_local_id_map_.resize(att_id + 1, -1); | point_attribute_to_local_id_map_.resize(att_id + 1, -1); | ||||
| } | |||||
| point_attribute_to_local_id_map_[att_id] = i; | point_attribute_to_local_id_map_[att_id] = i; | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| } // namespace draco | } // namespace draco | ||||