Differential D9642 Diff 31337 extern/draco/draco/src/draco/compression/attributes/kd_tree_attributes_decoder.cc
Changeset View
Changeset View
Standalone View
Standalone View
extern/draco/draco/src/draco/compression/attributes/kd_tree_attributes_decoder.cc
- This file was moved from extern/draco/dracoenc/src/draco/compression/attributes/kd_tree_attributes_decoder.cc.
| // Copyright 2016 The Draco Authors. | // Copyright 2016 The Draco Authors. | ||||
| // | // | ||||
| // Licensed under the Apache License, Version 2.0 (the "License"); | // Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| // you may not use this file except in compliance with the License. | // you may not use this file except in compliance with the License. | ||||
| // You may obtain a copy of the License at | // You may obtain a copy of the License at | ||||
| // | // | ||||
| // http://www.apache.org/licenses/LICENSE-2.0 | // http://www.apache.org/licenses/LICENSE-2.0 | ||||
| // | // | ||||
| // Unless required by applicable law or agreed to in writing, software | // Unless required by applicable law or agreed to in writing, software | ||||
| // distributed under the License is distributed on an "AS IS" BASIS, | // distributed under the License is distributed on an "AS IS" BASIS, | ||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| // See the License for the specific language governing permissions and | // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | // limitations under the License. | ||||
| // | // | ||||
| #include "draco/compression/attributes/kd_tree_attributes_decoder.h" | #include "draco/compression/attributes/kd_tree_attributes_decoder.h" | ||||
| #include "draco/compression/attributes/kd_tree_attributes_shared.h" | #include "draco/compression/attributes/kd_tree_attributes_shared.h" | ||||
| #include "draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_decoder.h" | #include "draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_decoder.h" | ||||
| #include "draco/compression/point_cloud/algorithms/float_points_tree_decoder.h" | #include "draco/compression/point_cloud/algorithms/float_points_tree_decoder.h" | ||||
| #include "draco/compression/point_cloud/point_cloud_decoder.h" | #include "draco/compression/point_cloud/point_cloud_decoder.h" | ||||
| #include "draco/core/draco_types.h" | #include "draco/core/draco_types.h" | ||||
| #include "draco/core/varint_decoding.h" | #include "draco/core/varint_decoding.h" | ||||
| namespace draco { | namespace draco { | ||||
| ▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | public: | ||||
| const Self &operator=(const std::vector<CoeffT> &val) { | const Self &operator=(const std::vector<CoeffT> &val) { | ||||
| for (auto index = 0; index < attributes_.size(); index++) { | for (auto index = 0; index < attributes_.size(); index++) { | ||||
| AttributeTuple &att = attributes_[index]; | AttributeTuple &att = attributes_[index]; | ||||
| PointAttribute *attribute = std::get<0>(att); | PointAttribute *attribute = std::get<0>(att); | ||||
| const uint32_t &offset = std::get<1>(att); | const uint32_t &offset = std::get<1>(att); | ||||
| const uint32_t &data_size = std::get<3>(att); | const uint32_t &data_size = std::get<3>(att); | ||||
| const uint32_t &num_components = std::get<4>(att); | const uint32_t &num_components = std::get<4>(att); | ||||
| const uint32_t *data_source = val.data() + offset; | const uint32_t *data_source = val.data() + offset; | ||||
| if (data_size != 4) { // handle uint16_t, uint8_t | if (data_size < 4) { // handle uint16_t, uint8_t | ||||
| // selectively copy data bytes | // selectively copy data bytes | ||||
| uint8_t *data_counter = data_; | uint8_t *data_counter = data_; | ||||
| for (uint32_t index = 0; index < num_components; | for (uint32_t index = 0; index < num_components; | ||||
| index += 1, data_counter += data_size) { | index += 1, data_counter += data_size) { | ||||
| std::memcpy(data_counter, data_source + index, data_size); | std::memcpy(data_counter, data_source + index, data_size); | ||||
| } | } | ||||
| // redirect to copied data | // redirect to copied data | ||||
| data_source = reinterpret_cast<uint32_t *>(data_); | data_source = reinterpret_cast<uint32_t *>(data_); | ||||
| } | } | ||||
| const AttributeValueIndex avi = attribute->mapped_index(point_id_); | const AttributeValueIndex avi = attribute->mapped_index(point_id_); | ||||
| if (avi >= static_cast<uint32_t>(attribute->size())) | if (avi >= static_cast<uint32_t>(attribute->size())) { | ||||
| return *this; | return *this; | ||||
| } | |||||
| attribute->SetAttributeValue(avi, data_source); | attribute->SetAttributeValue(avi, data_source); | ||||
| } | } | ||||
| return *this; | return *this; | ||||
| } | } | ||||
| private: | private: | ||||
| // preallocated memory for buffering different data sizes. Never reallocated. | // preallocated memory for buffering different data sizes. Never reallocated. | ||||
| std::vector<uint8_t> memory_; | std::vector<uint8_t> memory_; | ||||
| Show All 13 Lines | |||||
| bool KdTreeAttributesDecoder::DecodePortableAttributes( | bool KdTreeAttributesDecoder::DecodePortableAttributes( | ||||
| DecoderBuffer *in_buffer) { | DecoderBuffer *in_buffer) { | ||||
| if (in_buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 3)) { | if (in_buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 3)) { | ||||
| // Old bitstream does everything in the | // Old bitstream does everything in the | ||||
| // DecodeDataNeededByPortableTransforms() method. | // DecodeDataNeededByPortableTransforms() method. | ||||
| return true; | return true; | ||||
| } | } | ||||
| uint8_t compression_level = 0; | uint8_t compression_level = 0; | ||||
| if (!in_buffer->Decode(&compression_level)) | if (!in_buffer->Decode(&compression_level)) { | ||||
| return false; | return false; | ||||
| } | |||||
| const int32_t num_points = GetDecoder()->point_cloud()->num_points(); | const int32_t num_points = GetDecoder()->point_cloud()->num_points(); | ||||
| // Decode data using the kd tree decoding into integer (portable) attributes. | // Decode data using the kd tree decoding into integer (portable) attributes. | ||||
| // We first need to go over all attributes and create a new portable storage | // We first need to go over all attributes and create a new portable storage | ||||
| // for those attributes that need it (floating point attributes that have to | // for those attributes that need it (floating point attributes that have to | ||||
| // be dequantized after decoding). | // be dequantized after decoding). | ||||
| const int num_attributes = GetNumAttributes(); | const int num_attributes = GetNumAttributes(); | ||||
| ▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | atts[i] = std::make_tuple(target_att, total_dimensionality, data_type, | ||||
| data_size, num_components); | data_size, num_components); | ||||
| total_dimensionality += num_components; | total_dimensionality += num_components; | ||||
| } | } | ||||
| PointAttributeVectorOutputIterator<uint32_t> out_it(atts); | PointAttributeVectorOutputIterator<uint32_t> out_it(atts); | ||||
| switch (compression_level) { | switch (compression_level) { | ||||
| case 0: { | case 0: { | ||||
| DynamicIntegerPointsKdTreeDecoder<0> decoder(total_dimensionality); | DynamicIntegerPointsKdTreeDecoder<0> decoder(total_dimensionality); | ||||
| if (!decoder.DecodePoints(in_buffer, out_it)) | if (!decoder.DecodePoints(in_buffer, out_it)) { | ||||
| return false; | return false; | ||||
| } | |||||
| break; | break; | ||||
| } | } | ||||
| case 1: { | case 1: { | ||||
| DynamicIntegerPointsKdTreeDecoder<1> decoder(total_dimensionality); | DynamicIntegerPointsKdTreeDecoder<1> decoder(total_dimensionality); | ||||
| if (!decoder.DecodePoints(in_buffer, out_it)) | if (!decoder.DecodePoints(in_buffer, out_it)) { | ||||
| return false; | return false; | ||||
| } | |||||
| break; | break; | ||||
| } | } | ||||
| case 2: { | case 2: { | ||||
| DynamicIntegerPointsKdTreeDecoder<2> decoder(total_dimensionality); | DynamicIntegerPointsKdTreeDecoder<2> decoder(total_dimensionality); | ||||
| if (!decoder.DecodePoints(in_buffer, out_it)) | if (!decoder.DecodePoints(in_buffer, out_it)) { | ||||
| return false; | return false; | ||||
| } | |||||
| break; | break; | ||||
| } | } | ||||
| case 3: { | case 3: { | ||||
| DynamicIntegerPointsKdTreeDecoder<3> decoder(total_dimensionality); | DynamicIntegerPointsKdTreeDecoder<3> decoder(total_dimensionality); | ||||
| if (!decoder.DecodePoints(in_buffer, out_it)) | if (!decoder.DecodePoints(in_buffer, out_it)) { | ||||
| return false; | return false; | ||||
| } | |||||
| break; | break; | ||||
| } | } | ||||
| case 4: { | case 4: { | ||||
| DynamicIntegerPointsKdTreeDecoder<4> decoder(total_dimensionality); | DynamicIntegerPointsKdTreeDecoder<4> decoder(total_dimensionality); | ||||
| if (!decoder.DecodePoints(in_buffer, out_it)) | if (!decoder.DecodePoints(in_buffer, out_it)) { | ||||
| return false; | return false; | ||||
| } | |||||
| break; | break; | ||||
| } | } | ||||
| case 5: { | case 5: { | ||||
| DynamicIntegerPointsKdTreeDecoder<5> decoder(total_dimensionality); | DynamicIntegerPointsKdTreeDecoder<5> decoder(total_dimensionality); | ||||
| if (!decoder.DecodePoints(in_buffer, out_it)) | if (!decoder.DecodePoints(in_buffer, out_it)) { | ||||
| return false; | return false; | ||||
| } | |||||
| break; | break; | ||||
| } | } | ||||
| case 6: { | case 6: { | ||||
| DynamicIntegerPointsKdTreeDecoder<6> decoder(total_dimensionality); | DynamicIntegerPointsKdTreeDecoder<6> decoder(total_dimensionality); | ||||
| if (!decoder.DecodePoints(in_buffer, out_it)) | if (!decoder.DecodePoints(in_buffer, out_it)) { | ||||
| return false; | return false; | ||||
| } | |||||
| break; | break; | ||||
| } | } | ||||
| default: | default: | ||||
| return false; | return false; | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| bool KdTreeAttributesDecoder::DecodeDataNeededByPortableTransforms( | bool KdTreeAttributesDecoder::DecodeDataNeededByPortableTransforms( | ||||
| DecoderBuffer *in_buffer) { | DecoderBuffer *in_buffer) { | ||||
| if (in_buffer->bitstream_version() >= DRACO_BITSTREAM_VERSION(2, 3)) { | if (in_buffer->bitstream_version() >= DRACO_BITSTREAM_VERSION(2, 3)) { | ||||
| // Decode quantization data for each attribute that need it. | // Decode quantization data for each attribute that need it. | ||||
| // TODO(ostava): This should be moved to AttributeQuantizationTransform. | // TODO(ostava): This should be moved to AttributeQuantizationTransform. | ||||
| std::vector<float> min_value; | std::vector<float> min_value; | ||||
| for (int i = 0; i < GetNumAttributes(); ++i) { | for (int i = 0; i < GetNumAttributes(); ++i) { | ||||
| const int att_id = GetAttributeId(i); | const int att_id = GetAttributeId(i); | ||||
| const PointAttribute *const att = | const PointAttribute *const att = | ||||
| GetDecoder()->point_cloud()->attribute(att_id); | GetDecoder()->point_cloud()->attribute(att_id); | ||||
| if (att->data_type() == DT_FLOAT32) { | if (att->data_type() == DT_FLOAT32) { | ||||
| const int num_components = att->num_components(); | const int num_components = att->num_components(); | ||||
| min_value.resize(num_components); | min_value.resize(num_components); | ||||
| if (!in_buffer->Decode(&min_value[0], sizeof(float) * num_components)) | if (!in_buffer->Decode(&min_value[0], sizeof(float) * num_components)) { | ||||
| return false; | return false; | ||||
| } | |||||
| float max_value_dif; | float max_value_dif; | ||||
| if (!in_buffer->Decode(&max_value_dif)) | if (!in_buffer->Decode(&max_value_dif)) { | ||||
| return false; | return false; | ||||
| } | |||||
| uint8_t quantization_bits; | uint8_t quantization_bits; | ||||
| if (!in_buffer->Decode(&quantization_bits) || quantization_bits > 31) | if (!in_buffer->Decode(&quantization_bits) || quantization_bits > 31) { | ||||
| return false; | return false; | ||||
| } | |||||
| AttributeQuantizationTransform transform; | AttributeQuantizationTransform transform; | ||||
| transform.SetParameters(quantization_bits, min_value.data(), | transform.SetParameters(quantization_bits, min_value.data(), | ||||
| num_components, max_value_dif); | num_components, max_value_dif); | ||||
| const int num_transforms = | const int num_transforms = | ||||
| static_cast<int>(attribute_quantization_transforms_.size()); | static_cast<int>(attribute_quantization_transforms_.size()); | ||||
| if (!transform.TransferToAttribute( | if (!transform.TransferToAttribute( | ||||
| quantized_portable_attributes_[num_transforms].get())) | quantized_portable_attributes_[num_transforms].get())) { | ||||
| return false; | return false; | ||||
| } | |||||
| attribute_quantization_transforms_.push_back(transform); | attribute_quantization_transforms_.push_back(transform); | ||||
| } | } | ||||
| } | } | ||||
| // Decode transform data for signed integer attributes. | // Decode transform data for signed integer attributes. | ||||
| for (int i = 0; i < min_signed_values_.size(); ++i) { | for (int i = 0; i < min_signed_values_.size(); ++i) { | ||||
| int32_t val; | int32_t val; | ||||
| DecodeVarint(&val, in_buffer); | DecodeVarint(&val, in_buffer); | ||||
| Show All 11 Lines | for (auto attribute_index = 0; | ||||
| static_cast<uint32_t>(attribute_index) < attribute_count; | static_cast<uint32_t>(attribute_index) < attribute_count; | ||||
| attribute_index += 1) // increment the dimensionality as needed... | attribute_index += 1) // increment the dimensionality as needed... | ||||
| { | { | ||||
| const int att_id = GetAttributeId(attribute_index); | const int att_id = GetAttributeId(attribute_index); | ||||
| PointAttribute *const att = GetDecoder()->point_cloud()->attribute(att_id); | PointAttribute *const att = GetDecoder()->point_cloud()->attribute(att_id); | ||||
| const DataType data_type = att->data_type(); | const DataType data_type = att->data_type(); | ||||
| const uint32_t data_size = (std::max)(0, DataTypeLength(data_type)); | const uint32_t data_size = (std::max)(0, DataTypeLength(data_type)); | ||||
| const uint32_t num_components = att->num_components(); | const uint32_t num_components = att->num_components(); | ||||
| if (data_size > 4) { | |||||
| return false; | |||||
| } | |||||
| atts[attribute_index] = std::make_tuple( | atts[attribute_index] = std::make_tuple( | ||||
| att, total_dimensionality, data_type, data_size, num_components); | att, total_dimensionality, data_type, data_size, num_components); | ||||
| // everything is treated as 32bit in the encoder. | // everything is treated as 32bit in the encoder. | ||||
| total_dimensionality += num_components; | total_dimensionality += num_components; | ||||
| } | } | ||||
| const int att_id = GetAttributeId(0); | const int att_id = GetAttributeId(0); | ||||
| PointAttribute *const att = GetDecoder()->point_cloud()->attribute(att_id); | PointAttribute *const att = GetDecoder()->point_cloud()->attribute(att_id); | ||||
| att->SetIdentityMapping(); | att->SetIdentityMapping(); | ||||
| // Decode method | // Decode method | ||||
| uint8_t method; | uint8_t method; | ||||
| if (!in_buffer->Decode(&method)) | if (!in_buffer->Decode(&method)) { | ||||
| return false; | return false; | ||||
| } | |||||
| if (method == KdTreeAttributesEncodingMethod::kKdTreeQuantizationEncoding) { | if (method == KdTreeAttributesEncodingMethod::kKdTreeQuantizationEncoding) { | ||||
| uint8_t compression_level = 0; | uint8_t compression_level = 0; | ||||
| if (!in_buffer->Decode(&compression_level)) | if (!in_buffer->Decode(&compression_level)) { | ||||
| return false; | return false; | ||||
| } | |||||
| uint32_t num_points = 0; | uint32_t num_points = 0; | ||||
| if (!in_buffer->Decode(&num_points)) | if (!in_buffer->Decode(&num_points)) { | ||||
| return false; | return false; | ||||
| } | |||||
| att->Reset(num_points); | att->Reset(num_points); | ||||
| FloatPointsTreeDecoder decoder; | FloatPointsTreeDecoder decoder; | ||||
| decoder.set_num_points_from_header(num_points); | |||||
| PointAttributeVectorOutputIterator<float> out_it(atts); | PointAttributeVectorOutputIterator<float> out_it(atts); | ||||
| if (!decoder.DecodePointCloud(in_buffer, out_it)) | if (!decoder.DecodePointCloud(in_buffer, out_it)) { | ||||
| return false; | return false; | ||||
| } | |||||
| } else if (method == KdTreeAttributesEncodingMethod::kKdTreeIntegerEncoding) { | } else if (method == KdTreeAttributesEncodingMethod::kKdTreeIntegerEncoding) { | ||||
| uint8_t compression_level = 0; | uint8_t compression_level = 0; | ||||
| if (!in_buffer->Decode(&compression_level)) | if (!in_buffer->Decode(&compression_level)) { | ||||
| return false; | return false; | ||||
| } | |||||
| if (6 < compression_level) { | if (6 < compression_level) { | ||||
| LOGE("KdTreeAttributesDecoder: compression level %i not supported.\n", | LOGE("KdTreeAttributesDecoder: compression level %i not supported.\n", | ||||
| compression_level); | compression_level); | ||||
| return false; | return false; | ||||
| } | } | ||||
| uint32_t num_points; | uint32_t num_points; | ||||
| if (!in_buffer->Decode(&num_points)) | if (!in_buffer->Decode(&num_points)) { | ||||
| return false; | return false; | ||||
| } | |||||
| for (auto attribute_index = 0; | for (auto attribute_index = 0; | ||||
| static_cast<uint32_t>(attribute_index) < attribute_count; | static_cast<uint32_t>(attribute_index) < attribute_count; | ||||
| attribute_index += 1) { | attribute_index += 1) { | ||||
| const int att_id = GetAttributeId(attribute_index); | const int att_id = GetAttributeId(attribute_index); | ||||
| PointAttribute *const attr = | PointAttribute *const attr = | ||||
| GetDecoder()->point_cloud()->attribute(att_id); | GetDecoder()->point_cloud()->attribute(att_id); | ||||
| attr->Reset(num_points); | attr->Reset(num_points); | ||||
| attr->SetIdentityMapping(); | attr->SetIdentityMapping(); | ||||
| }; | }; | ||||
| PointAttributeVectorOutputIterator<uint32_t> out_it(atts); | PointAttributeVectorOutputIterator<uint32_t> out_it(atts); | ||||
| switch (compression_level) { | switch (compression_level) { | ||||
| case 0: { | case 0: { | ||||
| DynamicIntegerPointsKdTreeDecoder<0> decoder(total_dimensionality); | DynamicIntegerPointsKdTreeDecoder<0> decoder(total_dimensionality); | ||||
| if (!decoder.DecodePoints(in_buffer, out_it)) | if (!decoder.DecodePoints(in_buffer, out_it)) { | ||||
| return false; | return false; | ||||
| } | |||||
| break; | break; | ||||
| } | } | ||||
| case 1: { | case 1: { | ||||
| DynamicIntegerPointsKdTreeDecoder<1> decoder(total_dimensionality); | DynamicIntegerPointsKdTreeDecoder<1> decoder(total_dimensionality); | ||||
| if (!decoder.DecodePoints(in_buffer, out_it)) | if (!decoder.DecodePoints(in_buffer, out_it)) { | ||||
| return false; | return false; | ||||
| } | |||||
| break; | break; | ||||
| } | } | ||||
| case 2: { | case 2: { | ||||
| DynamicIntegerPointsKdTreeDecoder<2> decoder(total_dimensionality); | DynamicIntegerPointsKdTreeDecoder<2> decoder(total_dimensionality); | ||||
| if (!decoder.DecodePoints(in_buffer, out_it)) | if (!decoder.DecodePoints(in_buffer, out_it)) { | ||||
| return false; | return false; | ||||
| } | |||||
| break; | break; | ||||
| } | } | ||||
| case 3: { | case 3: { | ||||
| DynamicIntegerPointsKdTreeDecoder<3> decoder(total_dimensionality); | DynamicIntegerPointsKdTreeDecoder<3> decoder(total_dimensionality); | ||||
| if (!decoder.DecodePoints(in_buffer, out_it)) | if (!decoder.DecodePoints(in_buffer, out_it)) { | ||||
| return false; | return false; | ||||
| } | |||||
| break; | break; | ||||
| } | } | ||||
| case 4: { | case 4: { | ||||
| DynamicIntegerPointsKdTreeDecoder<4> decoder(total_dimensionality); | DynamicIntegerPointsKdTreeDecoder<4> decoder(total_dimensionality); | ||||
| if (!decoder.DecodePoints(in_buffer, out_it)) | if (!decoder.DecodePoints(in_buffer, out_it)) { | ||||
| return false; | return false; | ||||
| } | |||||
| break; | break; | ||||
| } | } | ||||
| case 5: { | case 5: { | ||||
| DynamicIntegerPointsKdTreeDecoder<5> decoder(total_dimensionality); | DynamicIntegerPointsKdTreeDecoder<5> decoder(total_dimensionality); | ||||
| if (!decoder.DecodePoints(in_buffer, out_it)) | if (!decoder.DecodePoints(in_buffer, out_it)) { | ||||
| return false; | return false; | ||||
| } | |||||
| break; | break; | ||||
| } | } | ||||
| case 6: { | case 6: { | ||||
| DynamicIntegerPointsKdTreeDecoder<6> decoder(total_dimensionality); | DynamicIntegerPointsKdTreeDecoder<6> decoder(total_dimensionality); | ||||
| if (!decoder.DecodePoints(in_buffer, out_it)) | if (!decoder.DecodePoints(in_buffer, out_it)) { | ||||
| return false; | return false; | ||||
| } | |||||
| break; | break; | ||||
| } | } | ||||
| default: | default: | ||||
| return false; | return false; | ||||
| } | } | ||||
| } else { | } else { | ||||
| // Invalid method. | // Invalid method. | ||||
| return false; | return false; | ||||
| Show All 38 Lines | for (int i = 0; i < GetNumAttributes(); ++i) { | ||||
| PointAttribute *const att = GetDecoder()->point_cloud()->attribute(att_id); | PointAttribute *const att = GetDecoder()->point_cloud()->attribute(att_id); | ||||
| if (att->data_type() == DT_INT32 || att->data_type() == DT_INT16 || | if (att->data_type() == DT_INT32 || att->data_type() == DT_INT16 || | ||||
| att->data_type() == DT_INT8) { | att->data_type() == DT_INT8) { | ||||
| std::vector<uint32_t> unsigned_val(att->num_components()); | std::vector<uint32_t> unsigned_val(att->num_components()); | ||||
| std::vector<int32_t> signed_val(att->num_components()); | std::vector<int32_t> signed_val(att->num_components()); | ||||
| // Values are stored as unsigned in the attribute, make them signed again. | // Values are stored as unsigned in the attribute, make them signed again. | ||||
| if (att->data_type() == DT_INT32) { | if (att->data_type() == DT_INT32) { | ||||
| if (!TransformAttributeBackToSignedType<int32_t>( | if (!TransformAttributeBackToSignedType<int32_t>( | ||||
| att, num_processed_signed_components)) | att, num_processed_signed_components)) { | ||||
| return false; | return false; | ||||
| } | |||||
| } else if (att->data_type() == DT_INT16) { | } else if (att->data_type() == DT_INT16) { | ||||
| if (!TransformAttributeBackToSignedType<int16_t>( | if (!TransformAttributeBackToSignedType<int16_t>( | ||||
| att, num_processed_signed_components)) | att, num_processed_signed_components)) { | ||||
| return false; | return false; | ||||
| } | |||||
| } else if (att->data_type() == DT_INT8) { | } else if (att->data_type() == DT_INT8) { | ||||
| if (!TransformAttributeBackToSignedType<int8_t>( | if (!TransformAttributeBackToSignedType<int8_t>( | ||||
| att, num_processed_signed_components)) | att, num_processed_signed_components)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | |||||
| num_processed_signed_components += att->num_components(); | num_processed_signed_components += att->num_components(); | ||||
| } else if (att->data_type() == DT_FLOAT32) { | } else if (att->data_type() == DT_FLOAT32) { | ||||
| // TODO(ostava): This code should be probably moved out to attribute | // TODO(ostava): This code should be probably moved out to attribute | ||||
| // transform and shared with the SequentialQuantizationAttributeDecoder. | // transform and shared with the SequentialQuantizationAttributeDecoder. | ||||
| const PointAttribute *const src_att = | const PointAttribute *const src_att = | ||||
| quantized_portable_attributes_[num_processed_quantized_attributes] | quantized_portable_attributes_[num_processed_quantized_attributes] | ||||
| .get(); | .get(); | ||||
| Show All 19 Lines | if (att->data_type() == DT_INT32 || att->data_type() == DT_INT16 || | ||||
| const int32_t max_quantized_value = | const int32_t max_quantized_value = | ||||
| (1u << static_cast<uint32_t>(transform.quantization_bits())) - 1; | (1u << static_cast<uint32_t>(transform.quantization_bits())) - 1; | ||||
| const int num_components = att->num_components(); | const int num_components = att->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(transform.range(), max_quantized_value)) | if (!dequantizer.Init(transform.range(), max_quantized_value)) { | ||||
| return false; | return false; | ||||
| } | |||||
| const uint32_t *const portable_attribute_data = | const uint32_t *const portable_attribute_data = | ||||
| reinterpret_cast<const uint32_t *>( | reinterpret_cast<const uint32_t *>( | ||||
| src_att->GetAddress(AttributeValueIndex(0))); | src_att->GetAddress(AttributeValueIndex(0))); | ||||
| for (uint32_t i = 0; i < src_att->size(); ++i) { | for (uint32_t i = 0; i < src_att->size(); ++i) { | ||||
| for (int c = 0; c < num_components; ++c) { | for (int c = 0; c < num_components; ++c) { | ||||
| float value = dequantizer.DequantizeFloat( | float value = dequantizer.DequantizeFloat( | ||||
| portable_attribute_data[quant_val_id++]); | portable_attribute_data[quant_val_id++]); | ||||
| value = value + transform.min_value(c); | value = value + transform.min_value(c); | ||||
| Show All 12 Lines | |||||