dracox 0.0.1__cp39-cp39-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bin/draco_decoder.exe +0 -0
- bin/draco_encoder.exe +0 -0
- dracox/__init__.py +252 -0
- dracox/dracox_ext.cp39-win_amd64.pyd +0 -0
- dracox-0.0.1.dist-info/METADATA +14 -0
- dracox-0.0.1.dist-info/RECORD +214 -0
- dracox-0.0.1.dist-info/WHEEL +5 -0
- include/draco/animation/keyframe_animation.h +107 -0
- include/draco/animation/keyframe_animation_decoder.h +34 -0
- include/draco/animation/keyframe_animation_encoder.h +39 -0
- include/draco/attributes/attribute_octahedron_transform.h +81 -0
- include/draco/attributes/attribute_quantization_transform.h +102 -0
- include/draco/attributes/attribute_transform.h +76 -0
- include/draco/attributes/attribute_transform_data.h +71 -0
- include/draco/attributes/attribute_transform_type.h +30 -0
- include/draco/attributes/geometry_attribute.h +541 -0
- include/draco/attributes/geometry_indices.h +54 -0
- include/draco/attributes/point_attribute.h +196 -0
- include/draco/compression/attributes/attributes_decoder.h +97 -0
- include/draco/compression/attributes/attributes_decoder_interface.h +62 -0
- include/draco/compression/attributes/attributes_encoder.h +154 -0
- include/draco/compression/attributes/kd_tree_attributes_decoder.h +50 -0
- include/draco/compression/attributes/kd_tree_attributes_encoder.h +51 -0
- include/draco/compression/attributes/kd_tree_attributes_shared.h +28 -0
- include/draco/compression/attributes/linear_sequencer.h +51 -0
- include/draco/compression/attributes/mesh_attribute_indices_encoding_data.h +58 -0
- include/draco/compression/attributes/normal_compression_utils.h +372 -0
- include/draco/compression/attributes/point_d_vector.h +288 -0
- include/draco/compression/attributes/points_sequencer.h +63 -0
- include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_constrained_multi_parallelogram_decoder.h +236 -0
- include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_constrained_multi_parallelogram_encoder.h +413 -0
- include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_constrained_multi_parallelogram_shared.h +34 -0
- include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_data.h +72 -0
- include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_decoder.h +46 -0
- include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_encoder.h +46 -0
- include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_decoder.h +176 -0
- include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_encoder.h +180 -0
- include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_predictor_area.h +117 -0
- include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_predictor_base.h +96 -0
- include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_multi_parallelogram_decoder.h +128 -0
- include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_multi_parallelogram_encoder.h +133 -0
- include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_parallelogram_encoder.h +111 -0
- include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_parallelogram_shared.h +78 -0
- include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_decoder.h +372 -0
- include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_encoder.h +318 -0
- include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_decoder.h +143 -0
- include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_encoder.h +136 -0
- include/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_predictor.h +282 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_decoder.h +90 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_decoder_factory.h +194 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_decoder_interface.h +53 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_decoding_transform.h +65 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_delta_decoder.h +65 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_delta_encoder.h +69 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_encoder.h +90 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_encoder_factory.h +134 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_encoder_interface.h +55 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_encoding_transform.h +77 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_factory.h +85 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_interface.h +60 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_canonicalized_decoding_transform.h +118 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_canonicalized_encoding_transform.h +116 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_canonicalized_transform_base.h +102 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_decoding_transform.h +115 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_encoding_transform.h +105 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_transform_base.h +90 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_wrap_decoding_transform.h +88 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_wrap_encoding_transform.h +81 -0
- include/draco/compression/attributes/prediction_schemes/prediction_scheme_wrap_transform_base.h +120 -0
- include/draco/compression/attributes/sequential_attribute_decoder.h +86 -0
- include/draco/compression/attributes/sequential_attribute_decoders_controller.h +61 -0
- include/draco/compression/attributes/sequential_attribute_encoder.h +134 -0
- include/draco/compression/attributes/sequential_attribute_encoders_controller.h +115 -0
- include/draco/compression/attributes/sequential_integer_attribute_decoder.h +76 -0
- include/draco/compression/attributes/sequential_integer_attribute_encoder.h +67 -0
- include/draco/compression/attributes/sequential_normal_attribute_decoder.h +83 -0
- include/draco/compression/attributes/sequential_normal_attribute_encoder.h +82 -0
- include/draco/compression/attributes/sequential_quantization_attribute_decoder.h +52 -0
- include/draco/compression/attributes/sequential_quantization_attribute_encoder.h +52 -0
- include/draco/compression/bit_coders/adaptive_rans_bit_coding_shared.h +43 -0
- include/draco/compression/bit_coders/adaptive_rans_bit_decoder.h +54 -0
- include/draco/compression/bit_coders/adaptive_rans_bit_encoder.h +61 -0
- include/draco/compression/bit_coders/direct_bit_decoder.h +89 -0
- include/draco/compression/bit_coders/direct_bit_encoder.h +89 -0
- include/draco/compression/bit_coders/folded_integer_bit_decoder.h +77 -0
- include/draco/compression/bit_coders/folded_integer_bit_encoder.h +82 -0
- include/draco/compression/bit_coders/rans_bit_decoder.h +55 -0
- include/draco/compression/bit_coders/rans_bit_encoder.h +57 -0
- include/draco/compression/bit_coders/symbol_bit_decoder.h +36 -0
- include/draco/compression/bit_coders/symbol_bit_encoder.h +36 -0
- include/draco/compression/config/compression_shared.h +155 -0
- include/draco/compression/config/decoder_options.h +34 -0
- include/draco/compression/config/draco_options.h +249 -0
- include/draco/compression/config/encoder_options.h +101 -0
- include/draco/compression/config/encoding_features.h +39 -0
- include/draco/compression/decode.h +80 -0
- include/draco/compression/draco_compression_options.h +141 -0
- include/draco/compression/encode.h +139 -0
- include/draco/compression/encode_base.h +131 -0
- include/draco/compression/entropy/ans.h +526 -0
- include/draco/compression/entropy/rans_symbol_coding.h +53 -0
- include/draco/compression/entropy/rans_symbol_decoder.h +171 -0
- include/draco/compression/entropy/rans_symbol_encoder.h +290 -0
- include/draco/compression/entropy/shannon_entropy.h +110 -0
- include/draco/compression/entropy/symbol_decoding.h +29 -0
- include/draco/compression/entropy/symbol_encoding.h +47 -0
- include/draco/compression/expert_encode.h +160 -0
- include/draco/compression/mesh/mesh_decoder.h +68 -0
- include/draco/compression/mesh/mesh_edgebreaker_decoder.h +54 -0
- include/draco/compression/mesh/mesh_edgebreaker_decoder_impl.h +228 -0
- include/draco/compression/mesh/mesh_edgebreaker_decoder_impl_interface.h +47 -0
- include/draco/compression/mesh/mesh_edgebreaker_encoder.h +73 -0
- include/draco/compression/mesh/mesh_edgebreaker_encoder_impl.h +209 -0
- include/draco/compression/mesh/mesh_edgebreaker_encoder_impl_interface.h +57 -0
- include/draco/compression/mesh/mesh_edgebreaker_shared.h +129 -0
- include/draco/compression/mesh/mesh_edgebreaker_traversal_decoder.h +201 -0
- include/draco/compression/mesh/mesh_edgebreaker_traversal_encoder.h +139 -0
- include/draco/compression/mesh/mesh_edgebreaker_traversal_predictive_decoder.h +134 -0
- include/draco/compression/mesh/mesh_edgebreaker_traversal_predictive_encoder.h +172 -0
- include/draco/compression/mesh/mesh_edgebreaker_traversal_valence_decoder.h +219 -0
- include/draco/compression/mesh/mesh_edgebreaker_traversal_valence_encoder.h +226 -0
- include/draco/compression/mesh/mesh_encoder.h +84 -0
- include/draco/compression/mesh/mesh_sequential_decoder.h +39 -0
- include/draco/compression/mesh/mesh_sequential_encoder.h +56 -0
- include/draco/compression/mesh/traverser/depth_first_traverser.h +172 -0
- include/draco/compression/mesh/traverser/max_prediction_degree_traverser.h +226 -0
- include/draco/compression/mesh/traverser/mesh_attribute_indices_encoding_observer.h +76 -0
- include/draco/compression/mesh/traverser/mesh_traversal_sequencer.h +113 -0
- include/draco/compression/mesh/traverser/traverser_base.h +87 -0
- include/draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_decoder.h +369 -0
- include/draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_encoder.h +372 -0
- include/draco/compression/point_cloud/algorithms/float_points_tree_decoder.h +141 -0
- include/draco/compression/point_cloud/algorithms/float_points_tree_encoder.h +126 -0
- include/draco/compression/point_cloud/algorithms/point_cloud_compression_method.h +34 -0
- include/draco/compression/point_cloud/algorithms/point_cloud_types.h +76 -0
- include/draco/compression/point_cloud/algorithms/quantize_points_3.h +84 -0
- include/draco/compression/point_cloud/algorithms/queuing_policy.h +75 -0
- include/draco/compression/point_cloud/point_cloud_decoder.h +118 -0
- include/draco/compression/point_cloud/point_cloud_encoder.h +158 -0
- include/draco/compression/point_cloud/point_cloud_kd_tree_decoder.h +31 -0
- include/draco/compression/point_cloud/point_cloud_kd_tree_encoder.h +45 -0
- include/draco/compression/point_cloud/point_cloud_sequential_decoder.h +33 -0
- include/draco/compression/point_cloud/point_cloud_sequential_encoder.h +43 -0
- include/draco/core/bit_utils.h +127 -0
- include/draco/core/bounding_box.h +77 -0
- include/draco/core/constants.h +6 -0
- include/draco/core/cycle_timer.h +51 -0
- include/draco/core/data_buffer.h +82 -0
- include/draco/core/decoder_buffer.h +216 -0
- include/draco/core/divide.h +42 -0
- include/draco/core/draco_index_type.h +184 -0
- include/draco/core/draco_index_type_vector.h +90 -0
- include/draco/core/draco_types.h +52 -0
- include/draco/core/draco_version.h +25 -0
- include/draco/core/encoder_buffer.h +152 -0
- include/draco/core/hash_utils.h +64 -0
- include/draco/core/macros.h +124 -0
- include/draco/core/math_utils.h +79 -0
- include/draco/core/options.h +151 -0
- include/draco/core/quantization_utils.h +82 -0
- include/draco/core/status.h +83 -0
- include/draco/core/status_or.h +81 -0
- include/draco/core/varint_decoding.h +81 -0
- include/draco/core/varint_encoding.h +61 -0
- include/draco/core/vector_d.h +355 -0
- include/draco/draco_features.h +25 -0
- include/draco/io/file_reader_factory.h +34 -0
- include/draco/io/file_reader_interface.h +32 -0
- include/draco/io/file_utils.h +86 -0
- include/draco/io/file_writer_factory.h +34 -0
- include/draco/io/file_writer_interface.h +26 -0
- include/draco/io/file_writer_utils.h +38 -0
- include/draco/io/mesh_io.h +107 -0
- include/draco/io/obj_decoder.h +147 -0
- include/draco/io/obj_encoder.h +107 -0
- include/draco/io/parser_utils.h +66 -0
- include/draco/io/ply_decoder.h +69 -0
- include/draco/io/ply_encoder.h +54 -0
- include/draco/io/ply_property_reader.h +96 -0
- include/draco/io/ply_property_writer.h +94 -0
- include/draco/io/ply_reader.h +155 -0
- include/draco/io/point_cloud_io.h +89 -0
- include/draco/io/stdio_file_reader.h +48 -0
- include/draco/io/stdio_file_writer.h +42 -0
- include/draco/io/stl_decoder.h +38 -0
- include/draco/io/stl_encoder.h +52 -0
- include/draco/mesh/corner_table.h +397 -0
- include/draco/mesh/corner_table_iterators.h +309 -0
- include/draco/mesh/mesh.h +378 -0
- include/draco/mesh/mesh_are_equivalent.h +71 -0
- include/draco/mesh/mesh_attribute_corner_table.h +202 -0
- include/draco/mesh/mesh_cleanup.h +61 -0
- include/draco/mesh/mesh_features.h +93 -0
- include/draco/mesh/mesh_indices.h +37 -0
- include/draco/mesh/mesh_misc_functions.h +105 -0
- include/draco/mesh/mesh_stripifier.h +258 -0
- include/draco/mesh/triangle_soup_mesh_builder.h +134 -0
- include/draco/mesh/valence_cache.h +142 -0
- include/draco/metadata/geometry_metadata.h +142 -0
- include/draco/metadata/metadata.h +209 -0
- include/draco/metadata/metadata_decoder.h +42 -0
- include/draco/metadata/metadata_encoder.h +41 -0
- include/draco/metadata/property_attribute.h +107 -0
- include/draco/metadata/property_table.h +222 -0
- include/draco/metadata/structural_metadata.h +78 -0
- include/draco/metadata/structural_metadata_schema.h +118 -0
- include/draco/point_cloud/point_cloud.h +289 -0
- include/draco/point_cloud/point_cloud_builder.h +101 -0
- lib/draco.lib +0 -0
- lib/pkgconfig/draco.pc +6 -0
- share/cmake/draco/draco-config-version.cmake +43 -0
- share/cmake/draco/draco-config.cmake +27 -0
- share/cmake/draco/draco-targets-release.cmake +19 -0
- share/cmake/draco/draco-targets.cmake +107 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// Copyright 2016 The Draco Authors.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
//
|
|
15
|
+
#ifndef DRACO_COMPRESSION_ATTRIBUTES_SEQUENTIAL_NORMAL_ATTRIBUTE_DECODER_H_
|
|
16
|
+
#define DRACO_COMPRESSION_ATTRIBUTES_SEQUENTIAL_NORMAL_ATTRIBUTE_DECODER_H_
|
|
17
|
+
|
|
18
|
+
#include "draco/attributes/attribute_octahedron_transform.h"
|
|
19
|
+
#include "draco/compression/attributes/prediction_schemes/prediction_scheme_decoder_factory.h"
|
|
20
|
+
#include "draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_canonicalized_decoding_transform.h"
|
|
21
|
+
#include "draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_decoding_transform.h"
|
|
22
|
+
#include "draco/compression/attributes/sequential_integer_attribute_decoder.h"
|
|
23
|
+
#include "draco/draco_features.h"
|
|
24
|
+
|
|
25
|
+
namespace draco {
|
|
26
|
+
|
|
27
|
+
// Decoder for attributes encoded with SequentialNormalAttributeEncoder.
|
|
28
|
+
class SequentialNormalAttributeDecoder
|
|
29
|
+
: public SequentialIntegerAttributeDecoder {
|
|
30
|
+
public:
|
|
31
|
+
SequentialNormalAttributeDecoder();
|
|
32
|
+
bool Init(PointCloudDecoder *decoder, int attribute_id) override;
|
|
33
|
+
|
|
34
|
+
protected:
|
|
35
|
+
int32_t GetNumValueComponents() const override {
|
|
36
|
+
return 2; // We quantize everything into two components.
|
|
37
|
+
}
|
|
38
|
+
bool DecodeIntegerValues(const std::vector<PointIndex> &point_ids,
|
|
39
|
+
DecoderBuffer *in_buffer) override;
|
|
40
|
+
bool DecodeDataNeededByPortableTransform(
|
|
41
|
+
const std::vector<PointIndex> &point_ids,
|
|
42
|
+
DecoderBuffer *in_buffer) override;
|
|
43
|
+
bool StoreValues(uint32_t num_points) override;
|
|
44
|
+
|
|
45
|
+
private:
|
|
46
|
+
AttributeOctahedronTransform octahedral_transform_;
|
|
47
|
+
|
|
48
|
+
std::unique_ptr<PredictionSchemeTypedDecoderInterface<int32_t>>
|
|
49
|
+
CreateIntPredictionScheme(
|
|
50
|
+
PredictionSchemeMethod method,
|
|
51
|
+
PredictionSchemeTransformType transform_type) override {
|
|
52
|
+
switch (transform_type) {
|
|
53
|
+
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
|
|
54
|
+
case PREDICTION_TRANSFORM_NORMAL_OCTAHEDRON: {
|
|
55
|
+
typedef PredictionSchemeNormalOctahedronDecodingTransform<int32_t>
|
|
56
|
+
Transform;
|
|
57
|
+
// At this point the decoder has not read the quantization bits,
|
|
58
|
+
// which is why we must construct the transform by default.
|
|
59
|
+
// See Transform.DecodeTransformData for more details.
|
|
60
|
+
return CreatePredictionSchemeForDecoder<int32_t, Transform>(
|
|
61
|
+
method, attribute_id(), decoder());
|
|
62
|
+
}
|
|
63
|
+
#endif
|
|
64
|
+
case PREDICTION_TRANSFORM_NORMAL_OCTAHEDRON_CANONICALIZED: {
|
|
65
|
+
typedef PredictionSchemeNormalOctahedronCanonicalizedDecodingTransform<
|
|
66
|
+
int32_t>
|
|
67
|
+
Transform;
|
|
68
|
+
// At this point the decoder has not read the quantization bits,
|
|
69
|
+
// which is why we must construct the transform by default.
|
|
70
|
+
// See Transform.DecodeTransformData for more details.
|
|
71
|
+
return CreatePredictionSchemeForDecoder<int32_t, Transform>(
|
|
72
|
+
method, attribute_id(), decoder());
|
|
73
|
+
}
|
|
74
|
+
default:
|
|
75
|
+
return nullptr; // Currently, we support only octahedron transform and
|
|
76
|
+
// octahedron transform canonicalized.
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
} // namespace draco
|
|
82
|
+
|
|
83
|
+
#endif // DRACO_COMPRESSION_ATTRIBUTES_SEQUENTIAL_NORMAL_ATTRIBUTE_DECODER_H_
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// Copyright 2016 The Draco Authors.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
//
|
|
15
|
+
#ifndef DRACO_COMPRESSION_ATTRIBUTES_SEQUENTIAL_NORMAL_ATTRIBUTE_ENCODER_H_
|
|
16
|
+
#define DRACO_COMPRESSION_ATTRIBUTES_SEQUENTIAL_NORMAL_ATTRIBUTE_ENCODER_H_
|
|
17
|
+
|
|
18
|
+
#include "draco/attributes/attribute_octahedron_transform.h"
|
|
19
|
+
#include "draco/compression/attributes/prediction_schemes/prediction_scheme_encoder_factory.h"
|
|
20
|
+
#include "draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_canonicalized_encoding_transform.h"
|
|
21
|
+
#include "draco/compression/attributes/sequential_integer_attribute_encoder.h"
|
|
22
|
+
#include "draco/compression/config/compression_shared.h"
|
|
23
|
+
|
|
24
|
+
namespace draco {
|
|
25
|
+
|
|
26
|
+
// Class for encoding normal vectors using an octahedral encoding, see Cigolle
|
|
27
|
+
// et al.'14 “A Survey of Efficient Representations for Independent Unit
|
|
28
|
+
// Vectors”. Compared to the basic quantization encoder, this encoder results
|
|
29
|
+
// in a better compression rate under the same accuracy settings. Note that this
|
|
30
|
+
// encoder doesn't preserve the lengths of input vectors, therefore it will not
|
|
31
|
+
// work correctly when the input values are not normalized.
|
|
32
|
+
class SequentialNormalAttributeEncoder
|
|
33
|
+
: public SequentialIntegerAttributeEncoder {
|
|
34
|
+
public:
|
|
35
|
+
uint8_t GetUniqueId() const override {
|
|
36
|
+
return SEQUENTIAL_ATTRIBUTE_ENCODER_NORMALS;
|
|
37
|
+
}
|
|
38
|
+
bool IsLossyEncoder() const override { return true; }
|
|
39
|
+
|
|
40
|
+
bool EncodeDataNeededByPortableTransform(EncoderBuffer *out_buffer) override;
|
|
41
|
+
|
|
42
|
+
protected:
|
|
43
|
+
bool Init(PointCloudEncoder *encoder, int attribute_id) override;
|
|
44
|
+
|
|
45
|
+
// Put quantized values in portable attribute for sequential encoding.
|
|
46
|
+
bool PrepareValues(const std::vector<PointIndex> &point_ids,
|
|
47
|
+
int num_points) override;
|
|
48
|
+
|
|
49
|
+
std::unique_ptr<PredictionSchemeTypedEncoderInterface<int32_t>>
|
|
50
|
+
CreateIntPredictionScheme(PredictionSchemeMethod /* method */) override {
|
|
51
|
+
typedef PredictionSchemeNormalOctahedronCanonicalizedEncodingTransform<
|
|
52
|
+
int32_t>
|
|
53
|
+
Transform;
|
|
54
|
+
const int32_t quantization_bits = encoder()->options()->GetAttributeInt(
|
|
55
|
+
attribute_id(), "quantization_bits", -1);
|
|
56
|
+
const int32_t max_value = (1 << quantization_bits) - 1;
|
|
57
|
+
const Transform transform(max_value);
|
|
58
|
+
const PredictionSchemeMethod default_prediction_method =
|
|
59
|
+
SelectPredictionMethod(attribute_id(), encoder());
|
|
60
|
+
const int32_t prediction_method = encoder()->options()->GetAttributeInt(
|
|
61
|
+
attribute_id(), "prediction_scheme", default_prediction_method);
|
|
62
|
+
|
|
63
|
+
if (prediction_method == MESH_PREDICTION_GEOMETRIC_NORMAL) {
|
|
64
|
+
return CreatePredictionSchemeForEncoder<int32_t, Transform>(
|
|
65
|
+
MESH_PREDICTION_GEOMETRIC_NORMAL, attribute_id(), encoder(),
|
|
66
|
+
transform);
|
|
67
|
+
}
|
|
68
|
+
if (prediction_method == PREDICTION_DIFFERENCE) {
|
|
69
|
+
return CreatePredictionSchemeForEncoder<int32_t, Transform>(
|
|
70
|
+
PREDICTION_DIFFERENCE, attribute_id(), encoder(), transform);
|
|
71
|
+
}
|
|
72
|
+
DRACO_DCHECK(false); // Should never be reached.
|
|
73
|
+
return nullptr;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Used for the conversion to quantized normals in octahedral format.
|
|
77
|
+
AttributeOctahedronTransform attribute_octahedron_transform_;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
} // namespace draco
|
|
81
|
+
|
|
82
|
+
#endif // DRACO_COMPRESSION_ATTRIBUTES_SEQUENTIAL_NORMAL_ATTRIBUTE_ENCODER_H_
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// Copyright 2016 The Draco Authors.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
//
|
|
15
|
+
#ifndef DRACO_COMPRESSION_ATTRIBUTES_SEQUENTIAL_QUANTIZATION_ATTRIBUTE_DECODER_H_
|
|
16
|
+
#define DRACO_COMPRESSION_ATTRIBUTES_SEQUENTIAL_QUANTIZATION_ATTRIBUTE_DECODER_H_
|
|
17
|
+
|
|
18
|
+
#include "draco/attributes/attribute_quantization_transform.h"
|
|
19
|
+
#include "draco/compression/attributes/sequential_integer_attribute_decoder.h"
|
|
20
|
+
#include "draco/draco_features.h"
|
|
21
|
+
|
|
22
|
+
namespace draco {
|
|
23
|
+
|
|
24
|
+
// Decoder for attribute values encoded with the
|
|
25
|
+
// SequentialQuantizationAttributeEncoder.
|
|
26
|
+
class SequentialQuantizationAttributeDecoder
|
|
27
|
+
: public SequentialIntegerAttributeDecoder {
|
|
28
|
+
public:
|
|
29
|
+
SequentialQuantizationAttributeDecoder();
|
|
30
|
+
bool Init(PointCloudDecoder *decoder, int attribute_id) override;
|
|
31
|
+
|
|
32
|
+
protected:
|
|
33
|
+
bool DecodeIntegerValues(const std::vector<PointIndex> &point_ids,
|
|
34
|
+
DecoderBuffer *in_buffer) override;
|
|
35
|
+
bool DecodeDataNeededByPortableTransform(
|
|
36
|
+
const std::vector<PointIndex> &point_ids,
|
|
37
|
+
DecoderBuffer *in_buffer) override;
|
|
38
|
+
bool StoreValues(uint32_t num_points) override;
|
|
39
|
+
|
|
40
|
+
// Decodes data necessary for dequantizing the encoded values.
|
|
41
|
+
virtual bool DecodeQuantizedDataInfo();
|
|
42
|
+
|
|
43
|
+
// Dequantizes all values and stores them into the output attribute.
|
|
44
|
+
virtual bool DequantizeValues(uint32_t num_values);
|
|
45
|
+
|
|
46
|
+
private:
|
|
47
|
+
AttributeQuantizationTransform quantization_transform_;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
} // namespace draco
|
|
51
|
+
|
|
52
|
+
#endif // DRACO_COMPRESSION_ATTRIBUTES_SEQUENTIAL_QUANTIZATION_ATTRIBUTE_DECODER_H_
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// Copyright 2016 The Draco Authors.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
//
|
|
15
|
+
#ifndef DRACO_COMPRESSION_ATTRIBUTES_SEQUENTIAL_QUANTIZATION_ATTRIBUTE_ENCODER_H_
|
|
16
|
+
#define DRACO_COMPRESSION_ATTRIBUTES_SEQUENTIAL_QUANTIZATION_ATTRIBUTE_ENCODER_H_
|
|
17
|
+
|
|
18
|
+
#include "draco/attributes/attribute_quantization_transform.h"
|
|
19
|
+
#include "draco/compression/attributes/sequential_integer_attribute_encoder.h"
|
|
20
|
+
|
|
21
|
+
namespace draco {
|
|
22
|
+
|
|
23
|
+
class MeshEncoder;
|
|
24
|
+
|
|
25
|
+
// Attribute encoder that quantizes floating point attribute values. The
|
|
26
|
+
// quantized values can be optionally compressed using an entropy coding.
|
|
27
|
+
class SequentialQuantizationAttributeEncoder
|
|
28
|
+
: public SequentialIntegerAttributeEncoder {
|
|
29
|
+
public:
|
|
30
|
+
SequentialQuantizationAttributeEncoder();
|
|
31
|
+
uint8_t GetUniqueId() const override {
|
|
32
|
+
return SEQUENTIAL_ATTRIBUTE_ENCODER_QUANTIZATION;
|
|
33
|
+
}
|
|
34
|
+
bool Init(PointCloudEncoder *encoder, int attribute_id) override;
|
|
35
|
+
|
|
36
|
+
bool IsLossyEncoder() const override { return true; }
|
|
37
|
+
|
|
38
|
+
bool EncodeDataNeededByPortableTransform(EncoderBuffer *out_buffer) override;
|
|
39
|
+
|
|
40
|
+
protected:
|
|
41
|
+
// Put quantized values in portable attribute for sequential encoding.
|
|
42
|
+
bool PrepareValues(const std::vector<PointIndex> &point_ids,
|
|
43
|
+
int num_points) override;
|
|
44
|
+
|
|
45
|
+
private:
|
|
46
|
+
// Used for the quantization.
|
|
47
|
+
AttributeQuantizationTransform attribute_quantization_transform_;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
} // namespace draco
|
|
51
|
+
|
|
52
|
+
#endif // DRACO_COMPRESSION_ATTRIBUTES_SEQUENTIAL_QUANTIZATION_ATTRIBUTE_ENCODER_H_
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Copyright 2016 The Draco Authors.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
//
|
|
15
|
+
// File provides shared functions for adaptive rANS bit coding.
|
|
16
|
+
#ifndef DRACO_COMPRESSION_BIT_CODERS_ADAPTIVE_RANS_BIT_CODING_SHARED_H_
|
|
17
|
+
#define DRACO_COMPRESSION_BIT_CODERS_ADAPTIVE_RANS_BIT_CODING_SHARED_H_
|
|
18
|
+
|
|
19
|
+
#include "draco/core/macros.h"
|
|
20
|
+
|
|
21
|
+
namespace draco {
|
|
22
|
+
|
|
23
|
+
// Clamp the probability p to a uint8_t in the range [1,255].
|
|
24
|
+
inline uint8_t clamp_probability(double p) {
|
|
25
|
+
DRACO_DCHECK_LE(p, 1.0);
|
|
26
|
+
DRACO_DCHECK_LE(0.0, p);
|
|
27
|
+
uint32_t p_int = static_cast<uint32_t>((p * 256) + 0.5);
|
|
28
|
+
p_int -= (p_int == 256);
|
|
29
|
+
p_int += (p_int == 0);
|
|
30
|
+
return static_cast<uint8_t>(p_int);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Update the probability according to new incoming bit.
|
|
34
|
+
inline double update_probability(double old_p, bool bit) {
|
|
35
|
+
static constexpr double w = 128.0;
|
|
36
|
+
static constexpr double w0 = (w - 1.0) / w;
|
|
37
|
+
static constexpr double w1 = 1.0 / w;
|
|
38
|
+
return old_p * w0 + (!bit) * w1;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
} // namespace draco
|
|
42
|
+
|
|
43
|
+
#endif // DRACO_COMPRESSION_BIT_CODERS_ADAPTIVE_RANS_BIT_CODING_SHARED_H_
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Copyright 2016 The Draco Authors.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
//
|
|
15
|
+
// File provides basic classes and functions for rANS bit decoding.
|
|
16
|
+
#ifndef DRACO_COMPRESSION_BIT_CODERS_ADAPTIVE_RANS_BIT_DECODER_H_
|
|
17
|
+
#define DRACO_COMPRESSION_BIT_CODERS_ADAPTIVE_RANS_BIT_DECODER_H_
|
|
18
|
+
|
|
19
|
+
#include <vector>
|
|
20
|
+
|
|
21
|
+
#include "draco/compression/entropy/ans.h"
|
|
22
|
+
#include "draco/core/decoder_buffer.h"
|
|
23
|
+
|
|
24
|
+
namespace draco {
|
|
25
|
+
|
|
26
|
+
// Class for decoding a sequence of bits that were encoded with
|
|
27
|
+
// AdaptiveRAnsBitEncoder.
|
|
28
|
+
class AdaptiveRAnsBitDecoder {
|
|
29
|
+
public:
|
|
30
|
+
AdaptiveRAnsBitDecoder();
|
|
31
|
+
~AdaptiveRAnsBitDecoder();
|
|
32
|
+
|
|
33
|
+
// Sets |source_buffer| as the buffer to decode bits from.
|
|
34
|
+
bool StartDecoding(DecoderBuffer *source_buffer);
|
|
35
|
+
|
|
36
|
+
// Decode one bit. Returns true if the bit is a 1, otherwise false.
|
|
37
|
+
bool DecodeNextBit();
|
|
38
|
+
|
|
39
|
+
// Decode the next |nbits| and return the sequence in |value|. |nbits| must be
|
|
40
|
+
// > 0 and <= 32.
|
|
41
|
+
void DecodeLeastSignificantBits32(int nbits, uint32_t *value);
|
|
42
|
+
|
|
43
|
+
void EndDecoding() {}
|
|
44
|
+
|
|
45
|
+
private:
|
|
46
|
+
void Clear();
|
|
47
|
+
|
|
48
|
+
AnsDecoder ans_decoder_;
|
|
49
|
+
double p0_f_;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
} // namespace draco
|
|
53
|
+
|
|
54
|
+
#endif // DRACO_COMPRESSION_BIT_CODERS_ADAPTIVE_RANS_BIT_DECODER_H_
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// Copyright 2016 The Draco Authors.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
//
|
|
15
|
+
// File provides basic classes and functions for rANS bit encoding.
|
|
16
|
+
#ifndef DRACO_COMPRESSION_BIT_CODERS_ADAPTIVE_RANS_BIT_ENCODER_H_
|
|
17
|
+
#define DRACO_COMPRESSION_BIT_CODERS_ADAPTIVE_RANS_BIT_ENCODER_H_
|
|
18
|
+
|
|
19
|
+
#include <vector>
|
|
20
|
+
|
|
21
|
+
#include "draco/compression/entropy/ans.h"
|
|
22
|
+
#include "draco/core/encoder_buffer.h"
|
|
23
|
+
|
|
24
|
+
namespace draco {
|
|
25
|
+
|
|
26
|
+
// Class for adaptive encoding a sequence of bits using rANS.
|
|
27
|
+
class AdaptiveRAnsBitEncoder {
|
|
28
|
+
public:
|
|
29
|
+
AdaptiveRAnsBitEncoder();
|
|
30
|
+
~AdaptiveRAnsBitEncoder();
|
|
31
|
+
|
|
32
|
+
// Must be called before any Encode* function is called.
|
|
33
|
+
void StartEncoding();
|
|
34
|
+
|
|
35
|
+
// Encode one bit. If |bit| is true encode a 1, otherwise encode a 0.
|
|
36
|
+
void EncodeBit(bool bit) { bits_.push_back(bit); }
|
|
37
|
+
|
|
38
|
+
// Encode |nbits| of |value|, starting from the least significant bit.
|
|
39
|
+
// |nbits| must be > 0 and <= 32.
|
|
40
|
+
void EncodeLeastSignificantBits32(int nbits, uint32_t value) {
|
|
41
|
+
DRACO_DCHECK_EQ(true, nbits <= 32);
|
|
42
|
+
DRACO_DCHECK_EQ(true, nbits > 0);
|
|
43
|
+
uint32_t selector = (1 << (nbits - 1));
|
|
44
|
+
while (selector) {
|
|
45
|
+
EncodeBit(value & selector);
|
|
46
|
+
selector = selector >> 1;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Ends the bit encoding and stores the result into the target_buffer.
|
|
51
|
+
void EndEncoding(EncoderBuffer *target_buffer);
|
|
52
|
+
|
|
53
|
+
private:
|
|
54
|
+
void Clear();
|
|
55
|
+
|
|
56
|
+
std::vector<bool> bits_;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
} // namespace draco
|
|
60
|
+
|
|
61
|
+
#endif // DRACO_COMPRESSION_BIT_CODERS_ADAPTIVE_RANS_BIT_ENCODER_H_
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// Copyright 2016 The Draco Authors.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
//
|
|
15
|
+
// File provides direct encoding of bits with arithmetic encoder interface.
|
|
16
|
+
#ifndef DRACO_COMPRESSION_BIT_CODERS_DIRECT_BIT_DECODER_H_
|
|
17
|
+
#define DRACO_COMPRESSION_BIT_CODERS_DIRECT_BIT_DECODER_H_
|
|
18
|
+
|
|
19
|
+
#include <vector>
|
|
20
|
+
|
|
21
|
+
#include "draco/core/decoder_buffer.h"
|
|
22
|
+
|
|
23
|
+
namespace draco {
|
|
24
|
+
|
|
25
|
+
class DirectBitDecoder {
|
|
26
|
+
public:
|
|
27
|
+
DirectBitDecoder();
|
|
28
|
+
~DirectBitDecoder();
|
|
29
|
+
|
|
30
|
+
// Sets |source_buffer| as the buffer to decode bits from.
|
|
31
|
+
bool StartDecoding(DecoderBuffer *source_buffer);
|
|
32
|
+
|
|
33
|
+
// Decode one bit. Returns true if the bit is a 1, otherwise false.
|
|
34
|
+
bool DecodeNextBit() {
|
|
35
|
+
const uint32_t selector = 1 << (31 - num_used_bits_);
|
|
36
|
+
if (pos_ == bits_.end()) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
const bool bit = *pos_ & selector;
|
|
40
|
+
++num_used_bits_;
|
|
41
|
+
if (num_used_bits_ == 32) {
|
|
42
|
+
++pos_;
|
|
43
|
+
num_used_bits_ = 0;
|
|
44
|
+
}
|
|
45
|
+
return bit;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Decode the next |nbits| and return the sequence in |value|. |nbits| must be
|
|
49
|
+
// > 0 and <= 32.
|
|
50
|
+
bool DecodeLeastSignificantBits32(int nbits, uint32_t *value) {
|
|
51
|
+
DRACO_DCHECK_EQ(true, nbits <= 32);
|
|
52
|
+
DRACO_DCHECK_EQ(true, nbits > 0);
|
|
53
|
+
const int remaining = 32 - num_used_bits_;
|
|
54
|
+
if (nbits <= remaining) {
|
|
55
|
+
if (pos_ == bits_.end()) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
*value = (*pos_ << num_used_bits_) >> (32 - nbits);
|
|
59
|
+
num_used_bits_ += nbits;
|
|
60
|
+
if (num_used_bits_ == 32) {
|
|
61
|
+
++pos_;
|
|
62
|
+
num_used_bits_ = 0;
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
if (pos_ + 1 == bits_.end()) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
const uint32_t value_l = ((*pos_) << num_used_bits_);
|
|
69
|
+
num_used_bits_ = nbits - remaining;
|
|
70
|
+
++pos_;
|
|
71
|
+
const uint32_t value_r = (*pos_) >> (32 - num_used_bits_);
|
|
72
|
+
*value = (value_l >> (32 - num_used_bits_ - remaining)) | value_r;
|
|
73
|
+
}
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
void EndDecoding() {}
|
|
78
|
+
|
|
79
|
+
private:
|
|
80
|
+
void Clear();
|
|
81
|
+
|
|
82
|
+
std::vector<uint32_t> bits_;
|
|
83
|
+
std::vector<uint32_t>::const_iterator pos_;
|
|
84
|
+
uint32_t num_used_bits_;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
} // namespace draco
|
|
88
|
+
|
|
89
|
+
#endif // DRACO_COMPRESSION_BIT_CODERS_DIRECT_BIT_DECODER_H_
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// Copyright 2016 The Draco Authors.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
//
|
|
15
|
+
// File provides direct encoding of bits with arithmetic encoder interface.
|
|
16
|
+
#ifndef DRACO_COMPRESSION_BIT_CODERS_DIRECT_BIT_ENCODER_H_
|
|
17
|
+
#define DRACO_COMPRESSION_BIT_CODERS_DIRECT_BIT_ENCODER_H_
|
|
18
|
+
|
|
19
|
+
#include <vector>
|
|
20
|
+
|
|
21
|
+
#include "draco/core/encoder_buffer.h"
|
|
22
|
+
|
|
23
|
+
namespace draco {
|
|
24
|
+
|
|
25
|
+
class DirectBitEncoder {
|
|
26
|
+
public:
|
|
27
|
+
DirectBitEncoder();
|
|
28
|
+
~DirectBitEncoder();
|
|
29
|
+
|
|
30
|
+
// Must be called before any Encode* function is called.
|
|
31
|
+
void StartEncoding();
|
|
32
|
+
|
|
33
|
+
// Encode one bit. If |bit| is true encode a 1, otherwise encode a 0.
|
|
34
|
+
void EncodeBit(bool bit) {
|
|
35
|
+
if (bit) {
|
|
36
|
+
local_bits_ |= 1 << (31 - num_local_bits_);
|
|
37
|
+
}
|
|
38
|
+
num_local_bits_++;
|
|
39
|
+
if (num_local_bits_ == 32) {
|
|
40
|
+
bits_.push_back(local_bits_);
|
|
41
|
+
num_local_bits_ = 0;
|
|
42
|
+
local_bits_ = 0;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Encode |nbits| of |value|, starting from the least significant bit.
|
|
47
|
+
// |nbits| must be > 0 and <= 32.
|
|
48
|
+
void EncodeLeastSignificantBits32(int nbits, uint32_t value) {
|
|
49
|
+
DRACO_DCHECK_EQ(true, nbits <= 32);
|
|
50
|
+
DRACO_DCHECK_EQ(true, nbits > 0);
|
|
51
|
+
|
|
52
|
+
const int remaining = 32 - num_local_bits_;
|
|
53
|
+
|
|
54
|
+
// Make sure there are no leading bits that should not be encoded and
|
|
55
|
+
// start from here.
|
|
56
|
+
value = value << (32 - nbits);
|
|
57
|
+
if (nbits <= remaining) {
|
|
58
|
+
value = value >> num_local_bits_;
|
|
59
|
+
local_bits_ = local_bits_ | value;
|
|
60
|
+
num_local_bits_ += nbits;
|
|
61
|
+
if (num_local_bits_ == 32) {
|
|
62
|
+
bits_.push_back(local_bits_);
|
|
63
|
+
local_bits_ = 0;
|
|
64
|
+
num_local_bits_ = 0;
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
value = value >> (32 - nbits);
|
|
68
|
+
num_local_bits_ = nbits - remaining;
|
|
69
|
+
const uint32_t value_l = value >> num_local_bits_;
|
|
70
|
+
local_bits_ = local_bits_ | value_l;
|
|
71
|
+
bits_.push_back(local_bits_);
|
|
72
|
+
local_bits_ = value << (32 - num_local_bits_);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Ends the bit encoding and stores the result into the target_buffer.
|
|
77
|
+
void EndEncoding(EncoderBuffer *target_buffer);
|
|
78
|
+
|
|
79
|
+
private:
|
|
80
|
+
void Clear();
|
|
81
|
+
|
|
82
|
+
std::vector<uint32_t> bits_;
|
|
83
|
+
uint32_t local_bits_;
|
|
84
|
+
uint32_t num_local_bits_;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
} // namespace draco
|
|
88
|
+
|
|
89
|
+
#endif // DRACO_COMPRESSION_BIT_CODERS_DIRECT_BIT_ENCODER_H_
|