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,171 @@
|
|
|
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_ENTROPY_RANS_SYMBOL_DECODER_H_
|
|
16
|
+
#define DRACO_COMPRESSION_ENTROPY_RANS_SYMBOL_DECODER_H_
|
|
17
|
+
|
|
18
|
+
#include "draco/compression/config/compression_shared.h"
|
|
19
|
+
#include "draco/compression/entropy/rans_symbol_coding.h"
|
|
20
|
+
#include "draco/core/decoder_buffer.h"
|
|
21
|
+
#include "draco/core/varint_decoding.h"
|
|
22
|
+
#include "draco/draco_features.h"
|
|
23
|
+
|
|
24
|
+
namespace draco {
|
|
25
|
+
|
|
26
|
+
// A helper class for decoding symbols using the rANS algorithm (see ans.h).
|
|
27
|
+
// The class can be used to decode the probability table and the data encoded
|
|
28
|
+
// by the RAnsSymbolEncoder. |unique_symbols_bit_length_t| must be the same as
|
|
29
|
+
// the one used for the corresponding RAnsSymbolEncoder.
|
|
30
|
+
template <int unique_symbols_bit_length_t>
|
|
31
|
+
class RAnsSymbolDecoder {
|
|
32
|
+
public:
|
|
33
|
+
RAnsSymbolDecoder() : num_symbols_(0) {}
|
|
34
|
+
|
|
35
|
+
// Initialize the decoder and decode the probability table.
|
|
36
|
+
bool Create(DecoderBuffer *buffer);
|
|
37
|
+
|
|
38
|
+
uint32_t num_symbols() const { return num_symbols_; }
|
|
39
|
+
|
|
40
|
+
// Starts decoding from the buffer. The buffer will be advanced past the
|
|
41
|
+
// encoded data after this call.
|
|
42
|
+
bool StartDecoding(DecoderBuffer *buffer);
|
|
43
|
+
uint32_t DecodeSymbol() { return ans_.rans_read(); }
|
|
44
|
+
void EndDecoding();
|
|
45
|
+
|
|
46
|
+
private:
|
|
47
|
+
static constexpr int rans_precision_bits_ =
|
|
48
|
+
ComputeRAnsPrecisionFromUniqueSymbolsBitLength(
|
|
49
|
+
unique_symbols_bit_length_t);
|
|
50
|
+
static constexpr int rans_precision_ = 1 << rans_precision_bits_;
|
|
51
|
+
|
|
52
|
+
std::vector<uint32_t> probability_table_;
|
|
53
|
+
uint32_t num_symbols_;
|
|
54
|
+
RAnsDecoder<rans_precision_bits_> ans_;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
template <int unique_symbols_bit_length_t>
|
|
58
|
+
bool RAnsSymbolDecoder<unique_symbols_bit_length_t>::Create(
|
|
59
|
+
DecoderBuffer *buffer) {
|
|
60
|
+
// Check that the DecoderBuffer version is set.
|
|
61
|
+
if (buffer->bitstream_version() == 0) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
// Decode the number of alphabet symbols.
|
|
65
|
+
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
|
|
66
|
+
if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
|
|
67
|
+
if (!buffer->Decode(&num_symbols_)) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
} else
|
|
72
|
+
#endif
|
|
73
|
+
{
|
|
74
|
+
if (!DecodeVarint(&num_symbols_, buffer)) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// Check that decoded number of symbols is not unreasonably high. Remaining
|
|
79
|
+
// buffer size must be at least |num_symbols| / 64 bytes to contain the
|
|
80
|
+
// probability table. The |prob_data| below is one byte but it can be
|
|
81
|
+
// theoretically stored for each 64th symbol.
|
|
82
|
+
if (num_symbols_ / 64 > buffer->remaining_size()) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
probability_table_.resize(num_symbols_);
|
|
86
|
+
if (num_symbols_ == 0) {
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
// Decode the table.
|
|
90
|
+
for (uint32_t i = 0; i < num_symbols_; ++i) {
|
|
91
|
+
uint8_t prob_data = 0;
|
|
92
|
+
// Decode the first byte and extract the number of extra bytes we need to
|
|
93
|
+
// get, or the offset to the next symbol with non-zero probability.
|
|
94
|
+
if (!buffer->Decode(&prob_data)) {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
// Token is stored in the first two bits of the first byte. Values 0-2 are
|
|
98
|
+
// used to indicate the number of extra bytes, and value 3 is a special
|
|
99
|
+
// symbol used to denote run-length coding of zero probability entries.
|
|
100
|
+
// See rans_symbol_encoder.h for more details.
|
|
101
|
+
const int token = prob_data & 3;
|
|
102
|
+
if (token == 3) {
|
|
103
|
+
const uint32_t offset = prob_data >> 2;
|
|
104
|
+
if (i + offset >= num_symbols_) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
// Set zero probability for all symbols in the specified range.
|
|
108
|
+
for (uint32_t j = 0; j < offset + 1; ++j) {
|
|
109
|
+
probability_table_[i + j] = 0;
|
|
110
|
+
}
|
|
111
|
+
i += offset;
|
|
112
|
+
} else {
|
|
113
|
+
const int extra_bytes = token;
|
|
114
|
+
uint32_t prob = prob_data >> 2;
|
|
115
|
+
for (int b = 0; b < extra_bytes; ++b) {
|
|
116
|
+
uint8_t eb;
|
|
117
|
+
if (!buffer->Decode(&eb)) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
// Shift 8 bits for each extra byte and subtract 2 for the two first
|
|
121
|
+
// bits.
|
|
122
|
+
prob |= static_cast<uint32_t>(eb) << (8 * (b + 1) - 2);
|
|
123
|
+
}
|
|
124
|
+
probability_table_[i] = prob;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (!ans_.rans_build_look_up_table(&probability_table_[0], num_symbols_)) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
template <int unique_symbols_bit_length_t>
|
|
134
|
+
bool RAnsSymbolDecoder<unique_symbols_bit_length_t>::StartDecoding(
|
|
135
|
+
DecoderBuffer *buffer) {
|
|
136
|
+
uint64_t bytes_encoded;
|
|
137
|
+
// Decode the number of bytes encoded by the encoder.
|
|
138
|
+
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
|
|
139
|
+
if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
|
|
140
|
+
if (!buffer->Decode(&bytes_encoded)) {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
} else
|
|
145
|
+
#endif
|
|
146
|
+
{
|
|
147
|
+
if (!DecodeVarint<uint64_t>(&bytes_encoded, buffer)) {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (bytes_encoded > static_cast<uint64_t>(buffer->remaining_size())) {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
const uint8_t *const data_head =
|
|
155
|
+
reinterpret_cast<const uint8_t *>(buffer->data_head());
|
|
156
|
+
// Advance the buffer past the rANS data.
|
|
157
|
+
buffer->Advance(bytes_encoded);
|
|
158
|
+
if (ans_.read_init(data_head, static_cast<int>(bytes_encoded)) != 0) {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
template <int unique_symbols_bit_length_t>
|
|
165
|
+
void RAnsSymbolDecoder<unique_symbols_bit_length_t>::EndDecoding() {
|
|
166
|
+
ans_.read_end();
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
} // namespace draco
|
|
170
|
+
|
|
171
|
+
#endif // DRACO_COMPRESSION_ENTROPY_RANS_SYMBOL_DECODER_H_
|
|
@@ -0,0 +1,290 @@
|
|
|
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_ENTROPY_RANS_SYMBOL_ENCODER_H_
|
|
16
|
+
#define DRACO_COMPRESSION_ENTROPY_RANS_SYMBOL_ENCODER_H_
|
|
17
|
+
|
|
18
|
+
#include <algorithm>
|
|
19
|
+
#include <cmath>
|
|
20
|
+
#include <cstring>
|
|
21
|
+
|
|
22
|
+
#include "draco/compression/entropy/ans.h"
|
|
23
|
+
#include "draco/compression/entropy/rans_symbol_coding.h"
|
|
24
|
+
#include "draco/core/encoder_buffer.h"
|
|
25
|
+
#include "draco/core/varint_encoding.h"
|
|
26
|
+
|
|
27
|
+
namespace draco {
|
|
28
|
+
|
|
29
|
+
// A helper class for encoding symbols using the rANS algorithm (see ans.h).
|
|
30
|
+
// The class can be used to initialize and encode probability table needed by
|
|
31
|
+
// rANS, and to perform encoding of symbols into the provided EncoderBuffer.
|
|
32
|
+
template <int unique_symbols_bit_length_t>
|
|
33
|
+
class RAnsSymbolEncoder {
|
|
34
|
+
public:
|
|
35
|
+
RAnsSymbolEncoder()
|
|
36
|
+
: num_symbols_(0), num_expected_bits_(0), buffer_offset_(0) {}
|
|
37
|
+
|
|
38
|
+
// Creates a probability table needed by the rANS library and encode it into
|
|
39
|
+
// the provided buffer.
|
|
40
|
+
bool Create(const uint64_t *frequencies, int num_symbols,
|
|
41
|
+
EncoderBuffer *buffer);
|
|
42
|
+
|
|
43
|
+
void StartEncoding(EncoderBuffer *buffer);
|
|
44
|
+
void EncodeSymbol(uint32_t symbol) {
|
|
45
|
+
ans_.rans_write(&probability_table_[symbol]);
|
|
46
|
+
}
|
|
47
|
+
void EndEncoding(EncoderBuffer *buffer);
|
|
48
|
+
|
|
49
|
+
// rANS requires to encode the input symbols in the reverse order.
|
|
50
|
+
static constexpr bool needs_reverse_encoding() { return true; }
|
|
51
|
+
|
|
52
|
+
private:
|
|
53
|
+
// Functor used for sorting symbol ids according to their probabilities.
|
|
54
|
+
// The functor sorts symbol indices that index an underlying map between
|
|
55
|
+
// symbol ids and their probabilities. We don't sort the probability table
|
|
56
|
+
// directly, because that would require an additional indirection during the
|
|
57
|
+
// EncodeSymbol() function.
|
|
58
|
+
struct ProbabilityLess {
|
|
59
|
+
explicit ProbabilityLess(const std::vector<rans_sym> *probs)
|
|
60
|
+
: probabilities(probs) {}
|
|
61
|
+
bool operator()(int i, int j) const {
|
|
62
|
+
return probabilities->at(i).prob < probabilities->at(j).prob;
|
|
63
|
+
}
|
|
64
|
+
const std::vector<rans_sym> *probabilities;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// Encodes the probability table into the output buffer.
|
|
68
|
+
bool EncodeTable(EncoderBuffer *buffer);
|
|
69
|
+
|
|
70
|
+
static constexpr int rans_precision_bits_ =
|
|
71
|
+
ComputeRAnsPrecisionFromUniqueSymbolsBitLength(
|
|
72
|
+
unique_symbols_bit_length_t);
|
|
73
|
+
static constexpr int rans_precision_ = 1 << rans_precision_bits_;
|
|
74
|
+
|
|
75
|
+
std::vector<rans_sym> probability_table_;
|
|
76
|
+
// The number of symbols in the input alphabet.
|
|
77
|
+
uint32_t num_symbols_;
|
|
78
|
+
// Expected number of bits that is needed to encode the input.
|
|
79
|
+
uint64_t num_expected_bits_;
|
|
80
|
+
|
|
81
|
+
RAnsEncoder<rans_precision_bits_> ans_;
|
|
82
|
+
// Initial offset of the encoder buffer before any ans data was encoded.
|
|
83
|
+
uint64_t buffer_offset_;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
template <int unique_symbols_bit_length_t>
|
|
87
|
+
bool RAnsSymbolEncoder<unique_symbols_bit_length_t>::Create(
|
|
88
|
+
const uint64_t *frequencies, int num_symbols, EncoderBuffer *buffer) {
|
|
89
|
+
// Compute the total of the input frequencies.
|
|
90
|
+
uint64_t total_freq = 0;
|
|
91
|
+
int max_valid_symbol = 0;
|
|
92
|
+
for (int i = 0; i < num_symbols; ++i) {
|
|
93
|
+
total_freq += frequencies[i];
|
|
94
|
+
if (frequencies[i] > 0) {
|
|
95
|
+
max_valid_symbol = i;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
num_symbols = max_valid_symbol + 1;
|
|
99
|
+
num_symbols_ = num_symbols;
|
|
100
|
+
probability_table_.resize(num_symbols);
|
|
101
|
+
const double total_freq_d = static_cast<double>(total_freq);
|
|
102
|
+
const double rans_precision_d = static_cast<double>(rans_precision_);
|
|
103
|
+
// Compute probabilities by rescaling the normalized frequencies into interval
|
|
104
|
+
// [1, rans_precision - 1]. The total probability needs to be equal to
|
|
105
|
+
// rans_precision.
|
|
106
|
+
int total_rans_prob = 0;
|
|
107
|
+
for (int i = 0; i < num_symbols; ++i) {
|
|
108
|
+
const uint64_t freq = frequencies[i];
|
|
109
|
+
|
|
110
|
+
// Normalized probability.
|
|
111
|
+
const double prob = static_cast<double>(freq) / total_freq_d;
|
|
112
|
+
|
|
113
|
+
// RAns probability in range of [1, rans_precision - 1].
|
|
114
|
+
uint32_t rans_prob = static_cast<uint32_t>(prob * rans_precision_d + 0.5f);
|
|
115
|
+
if (rans_prob == 0 && freq > 0) {
|
|
116
|
+
rans_prob = 1;
|
|
117
|
+
}
|
|
118
|
+
probability_table_[i].prob = rans_prob;
|
|
119
|
+
total_rans_prob += rans_prob;
|
|
120
|
+
}
|
|
121
|
+
// Because of rounding errors, the total precision may not be exactly accurate
|
|
122
|
+
// and we may need to adjust the entries a little bit.
|
|
123
|
+
if (total_rans_prob != rans_precision_) {
|
|
124
|
+
std::vector<int> sorted_probabilities(num_symbols);
|
|
125
|
+
for (int i = 0; i < num_symbols; ++i) {
|
|
126
|
+
sorted_probabilities[i] = i;
|
|
127
|
+
}
|
|
128
|
+
std::stable_sort(sorted_probabilities.begin(), sorted_probabilities.end(),
|
|
129
|
+
ProbabilityLess(&probability_table_));
|
|
130
|
+
if (total_rans_prob < rans_precision_) {
|
|
131
|
+
// This happens rather infrequently, just add the extra needed precision
|
|
132
|
+
// to the most frequent symbol.
|
|
133
|
+
probability_table_[sorted_probabilities.back()].prob +=
|
|
134
|
+
rans_precision_ - total_rans_prob;
|
|
135
|
+
} else {
|
|
136
|
+
// We have over-allocated the precision, which is quite common.
|
|
137
|
+
// Rescale the probabilities of all symbols.
|
|
138
|
+
int32_t error = total_rans_prob - rans_precision_;
|
|
139
|
+
while (error > 0) {
|
|
140
|
+
const double act_total_prob_d = static_cast<double>(total_rans_prob);
|
|
141
|
+
const double act_rel_error_d = rans_precision_d / act_total_prob_d;
|
|
142
|
+
for (int j = num_symbols - 1; j > 0; --j) {
|
|
143
|
+
int symbol_id = sorted_probabilities[j];
|
|
144
|
+
if (probability_table_[symbol_id].prob <= 1) {
|
|
145
|
+
if (j == num_symbols - 1) {
|
|
146
|
+
return false; // Most frequent symbol would be empty.
|
|
147
|
+
}
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
const int32_t new_prob = static_cast<int32_t>(
|
|
151
|
+
floor(act_rel_error_d *
|
|
152
|
+
static_cast<double>(probability_table_[symbol_id].prob)));
|
|
153
|
+
int32_t fix = probability_table_[symbol_id].prob - new_prob;
|
|
154
|
+
if (fix == 0u) {
|
|
155
|
+
fix = 1;
|
|
156
|
+
}
|
|
157
|
+
if (fix >= static_cast<int32_t>(probability_table_[symbol_id].prob)) {
|
|
158
|
+
fix = probability_table_[symbol_id].prob - 1;
|
|
159
|
+
}
|
|
160
|
+
if (fix > error) {
|
|
161
|
+
fix = error;
|
|
162
|
+
}
|
|
163
|
+
probability_table_[symbol_id].prob -= fix;
|
|
164
|
+
total_rans_prob -= fix;
|
|
165
|
+
error -= fix;
|
|
166
|
+
if (total_rans_prob == rans_precision_) {
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Compute the cumulative probability (cdf).
|
|
175
|
+
uint32_t total_prob = 0;
|
|
176
|
+
for (int i = 0; i < num_symbols; ++i) {
|
|
177
|
+
probability_table_[i].cum_prob = total_prob;
|
|
178
|
+
total_prob += probability_table_[i].prob;
|
|
179
|
+
}
|
|
180
|
+
if (total_prob != rans_precision_) {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Estimate the number of bits needed to encode the input.
|
|
185
|
+
// From Shannon entropy the total number of bits N is:
|
|
186
|
+
// N = -sum{i : all_symbols}(F(i) * log2(P(i)))
|
|
187
|
+
// where P(i) is the normalized probability of symbol i and F(i) is the
|
|
188
|
+
// symbol's frequency in the input data.
|
|
189
|
+
double num_bits = 0;
|
|
190
|
+
for (int i = 0; i < num_symbols; ++i) {
|
|
191
|
+
if (probability_table_[i].prob == 0) {
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
const double norm_prob =
|
|
195
|
+
static_cast<double>(probability_table_[i].prob) / rans_precision_d;
|
|
196
|
+
num_bits += static_cast<double>(frequencies[i]) * log2(norm_prob);
|
|
197
|
+
}
|
|
198
|
+
num_expected_bits_ = static_cast<uint64_t>(ceil(-num_bits));
|
|
199
|
+
if (!EncodeTable(buffer)) {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
template <int unique_symbols_bit_length_t>
|
|
206
|
+
bool RAnsSymbolEncoder<unique_symbols_bit_length_t>::EncodeTable(
|
|
207
|
+
EncoderBuffer *buffer) {
|
|
208
|
+
EncodeVarint(num_symbols_, buffer);
|
|
209
|
+
// Use varint encoding for the probabilities (first two bits represent the
|
|
210
|
+
// number of bytes used - 1).
|
|
211
|
+
for (uint32_t i = 0; i < num_symbols_; ++i) {
|
|
212
|
+
const uint32_t prob = probability_table_[i].prob;
|
|
213
|
+
int num_extra_bytes = 0;
|
|
214
|
+
if (prob >= (1 << 6)) {
|
|
215
|
+
num_extra_bytes++;
|
|
216
|
+
if (prob >= (1 << 14)) {
|
|
217
|
+
num_extra_bytes++;
|
|
218
|
+
if (prob >= (1 << 22)) {
|
|
219
|
+
// The maximum number of precision bits is 20 so we should not really
|
|
220
|
+
// get to this point.
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
if (prob == 0) {
|
|
226
|
+
// When the probability of the symbol is 0, set the first two bits to 1
|
|
227
|
+
// (unique identifier) and use the remaining 6 bits to store the offset
|
|
228
|
+
// to the next symbol with non-zero probability.
|
|
229
|
+
uint32_t offset = 0;
|
|
230
|
+
for (; offset < (1 << 6) - 1; ++offset) {
|
|
231
|
+
// Note: we don't have to check whether the next symbol id is larger
|
|
232
|
+
// than num_symbols_ because we know that the last symbol always has
|
|
233
|
+
// non-zero probability.
|
|
234
|
+
const uint32_t next_prob = probability_table_[i + offset + 1].prob;
|
|
235
|
+
if (next_prob > 0) {
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
buffer->Encode(static_cast<uint8_t>((offset << 2) | 3));
|
|
240
|
+
i += offset;
|
|
241
|
+
} else {
|
|
242
|
+
// Encode the first byte (including the number of extra bytes).
|
|
243
|
+
buffer->Encode(static_cast<uint8_t>((prob << 2) | (num_extra_bytes & 3)));
|
|
244
|
+
// Encode the extra bytes.
|
|
245
|
+
for (int b = 0; b < num_extra_bytes; ++b) {
|
|
246
|
+
buffer->Encode(static_cast<uint8_t>(prob >> (8 * (b + 1) - 2)));
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return true;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
template <int unique_symbols_bit_length_t>
|
|
254
|
+
void RAnsSymbolEncoder<unique_symbols_bit_length_t>::StartEncoding(
|
|
255
|
+
EncoderBuffer *buffer) {
|
|
256
|
+
// Allocate extra storage just in case.
|
|
257
|
+
const uint64_t required_bits = 2 * num_expected_bits_ + 32;
|
|
258
|
+
|
|
259
|
+
buffer_offset_ = buffer->size();
|
|
260
|
+
const int64_t required_bytes = (required_bits + 7) / 8;
|
|
261
|
+
buffer->Resize(buffer_offset_ + required_bytes + sizeof(buffer_offset_));
|
|
262
|
+
uint8_t *const data =
|
|
263
|
+
reinterpret_cast<uint8_t *>(const_cast<char *>(buffer->data()));
|
|
264
|
+
ans_.write_init(data + buffer_offset_);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
template <int unique_symbols_bit_length_t>
|
|
268
|
+
void RAnsSymbolEncoder<unique_symbols_bit_length_t>::EndEncoding(
|
|
269
|
+
EncoderBuffer *buffer) {
|
|
270
|
+
char *const src = const_cast<char *>(buffer->data()) + buffer_offset_;
|
|
271
|
+
|
|
272
|
+
// TODO(fgalligan): Look into changing this to uint32_t as write_end()
|
|
273
|
+
// returns an int.
|
|
274
|
+
const uint64_t bytes_written = static_cast<uint64_t>(ans_.write_end());
|
|
275
|
+
EncoderBuffer var_size_buffer;
|
|
276
|
+
EncodeVarint(bytes_written, &var_size_buffer);
|
|
277
|
+
const uint32_t size_len = static_cast<uint32_t>(var_size_buffer.size());
|
|
278
|
+
char *const dst = src + size_len;
|
|
279
|
+
memmove(dst, src, bytes_written);
|
|
280
|
+
|
|
281
|
+
// Store the size of the encoded data.
|
|
282
|
+
memcpy(src, var_size_buffer.data(), size_len);
|
|
283
|
+
|
|
284
|
+
// Resize the buffer to match the number of encoded bytes.
|
|
285
|
+
buffer->Resize(buffer_offset_ + bytes_written + size_len);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
} // namespace draco
|
|
289
|
+
|
|
290
|
+
#endif // DRACO_COMPRESSION_ENTROPY_RANS_SYMBOL_ENCODER_H_
|
|
@@ -0,0 +1,110 @@
|
|
|
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_ENTROPY_SHANNON_ENTROPY_H_
|
|
16
|
+
#define DRACO_COMPRESSION_ENTROPY_SHANNON_ENTROPY_H_
|
|
17
|
+
|
|
18
|
+
#include <stdint.h>
|
|
19
|
+
|
|
20
|
+
#include <vector>
|
|
21
|
+
|
|
22
|
+
namespace draco {
|
|
23
|
+
|
|
24
|
+
// Computes an approximate Shannon entropy of symbols stored in the provided
|
|
25
|
+
// input array |symbols|. The entropy corresponds to the number of bits that is
|
|
26
|
+
// required to represent/store all the symbols using an optimal entropy coding
|
|
27
|
+
// algorithm. See for example "A mathematical theory of communication" by
|
|
28
|
+
// Shannon'48 (http://ieeexplore.ieee.org/document/6773024/).
|
|
29
|
+
//
|
|
30
|
+
// |max_value| is a required input that define the maximum value in the input
|
|
31
|
+
// |symbols| array.
|
|
32
|
+
//
|
|
33
|
+
// |out_num_unique_symbols| is an optional output argument that stores the
|
|
34
|
+
// number of unique symbols contained within the |symbols| array.
|
|
35
|
+
// TODO(ostava): This should be renamed or the return value should be changed to
|
|
36
|
+
// return the actual entropy and not the number of bits needed to represent the
|
|
37
|
+
// input symbols.
|
|
38
|
+
int64_t ComputeShannonEntropy(const uint32_t *symbols, int num_symbols,
|
|
39
|
+
int max_value, int *out_num_unique_symbols);
|
|
40
|
+
|
|
41
|
+
// Computes the Shannon entropy of |num_values| Boolean entries, where
|
|
42
|
+
// |num_true_values| are set to true.
|
|
43
|
+
// Returns entropy between 0-1.
|
|
44
|
+
double ComputeBinaryShannonEntropy(uint32_t num_values,
|
|
45
|
+
uint32_t num_true_values);
|
|
46
|
+
|
|
47
|
+
// Class that can be used to keep track of the Shannon entropy on streamed data.
|
|
48
|
+
// As new symbols are pushed to the tracker, the entropy is automatically
|
|
49
|
+
// recomputed. The class also support recomputing the entropy without actually
|
|
50
|
+
// pushing the symbols to the tracker through the Peek() method.
|
|
51
|
+
class ShannonEntropyTracker {
|
|
52
|
+
public:
|
|
53
|
+
ShannonEntropyTracker();
|
|
54
|
+
|
|
55
|
+
// Struct for holding entropy data about the symbols added to the tracker.
|
|
56
|
+
// It can be used to compute the number of bits needed to store the data using
|
|
57
|
+
// the method:
|
|
58
|
+
// ShannonEntropyTracker::GetNumberOfDataBits(entropy_data);
|
|
59
|
+
// or to compute the approximate size of the frequency table needed by the
|
|
60
|
+
// rans coding using method:
|
|
61
|
+
// ShannonEntropyTracker::GetNumberOfRAnsTableBits(entropy_data);
|
|
62
|
+
struct EntropyData {
|
|
63
|
+
double entropy_norm;
|
|
64
|
+
int num_values;
|
|
65
|
+
int max_symbol;
|
|
66
|
+
int num_unique_symbols;
|
|
67
|
+
EntropyData()
|
|
68
|
+
: entropy_norm(0.0),
|
|
69
|
+
num_values(0),
|
|
70
|
+
max_symbol(0),
|
|
71
|
+
num_unique_symbols(0) {}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// Adds new symbols to the tracker and recomputes the entropy accordingly.
|
|
75
|
+
EntropyData Push(const uint32_t *symbols, int num_symbols);
|
|
76
|
+
|
|
77
|
+
// Returns new entropy data for the tracker as if |symbols| were added to the
|
|
78
|
+
// tracker without actually changing the status of the tracker.
|
|
79
|
+
EntropyData Peek(const uint32_t *symbols, int num_symbols);
|
|
80
|
+
|
|
81
|
+
// Gets the number of bits needed for encoding symbols added to the tracker.
|
|
82
|
+
int64_t GetNumberOfDataBits() const {
|
|
83
|
+
return GetNumberOfDataBits(entropy_data_);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Gets the number of bits needed for encoding frequency table using the rans
|
|
87
|
+
// encoder.
|
|
88
|
+
int64_t GetNumberOfRAnsTableBits() const {
|
|
89
|
+
return GetNumberOfRAnsTableBits(entropy_data_);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Gets the number of bits needed for encoding given |entropy_data|.
|
|
93
|
+
static int64_t GetNumberOfDataBits(const EntropyData &entropy_data);
|
|
94
|
+
|
|
95
|
+
// Gets the number of bits needed for encoding frequency table using the rans
|
|
96
|
+
// encoder for the given |entropy_data|.
|
|
97
|
+
static int64_t GetNumberOfRAnsTableBits(const EntropyData &entropy_data);
|
|
98
|
+
|
|
99
|
+
private:
|
|
100
|
+
EntropyData UpdateSymbols(const uint32_t *symbols, int num_symbols,
|
|
101
|
+
bool push_changes);
|
|
102
|
+
|
|
103
|
+
std::vector<int32_t> frequencies_;
|
|
104
|
+
|
|
105
|
+
EntropyData entropy_data_;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
} // namespace draco
|
|
109
|
+
|
|
110
|
+
#endif // DRACO_COMPRESSION_ENTROPY_SHANNON_ENTROPY_H_
|
|
@@ -0,0 +1,29 @@
|
|
|
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_ENTROPY_SYMBOL_DECODING_H_
|
|
16
|
+
#define DRACO_COMPRESSION_ENTROPY_SYMBOL_DECODING_H_
|
|
17
|
+
|
|
18
|
+
#include "draco/core/decoder_buffer.h"
|
|
19
|
+
|
|
20
|
+
namespace draco {
|
|
21
|
+
|
|
22
|
+
// Decodes an array of symbols that was previously encoded with an entropy code.
|
|
23
|
+
// Returns false on error.
|
|
24
|
+
bool DecodeSymbols(uint32_t num_values, int num_components,
|
|
25
|
+
DecoderBuffer *src_buffer, uint32_t *out_values);
|
|
26
|
+
|
|
27
|
+
} // namespace draco
|
|
28
|
+
|
|
29
|
+
#endif // DRACO_COMPRESSION_ENTROPY_SYMBOL_DECODING_H_
|
|
@@ -0,0 +1,47 @@
|
|
|
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_ENTROPY_SYMBOL_ENCODING_H_
|
|
16
|
+
#define DRACO_COMPRESSION_ENTROPY_SYMBOL_ENCODING_H_
|
|
17
|
+
|
|
18
|
+
#include "draco/compression/config/compression_shared.h"
|
|
19
|
+
#include "draco/core/encoder_buffer.h"
|
|
20
|
+
#include "draco/core/options.h"
|
|
21
|
+
|
|
22
|
+
namespace draco {
|
|
23
|
+
|
|
24
|
+
// Encodes an array of symbols using an entropy coding. This function
|
|
25
|
+
// automatically decides whether to encode the symbol values using bit
|
|
26
|
+
// length tags (see EncodeTaggedSymbols), or whether to encode them directly
|
|
27
|
+
// (see EncodeRawSymbols). The symbols can be grouped into separate components
|
|
28
|
+
// that can be used for better compression. |options| is an optional parameter
|
|
29
|
+
// that allows more direct control over various stages of the symbol encoding
|
|
30
|
+
// (see below for functions that are used to set valid options).
|
|
31
|
+
// Returns false on error.
|
|
32
|
+
bool EncodeSymbols(const uint32_t *symbols, int num_values, int num_components,
|
|
33
|
+
const Options *options, EncoderBuffer *target_buffer);
|
|
34
|
+
|
|
35
|
+
// Sets an option that forces symbol encoder to use the specified encoding
|
|
36
|
+
// method.
|
|
37
|
+
void SetSymbolEncodingMethod(Options *options, SymbolCodingMethod method);
|
|
38
|
+
|
|
39
|
+
// Sets the desired compression level for symbol encoding in range <0, 10> where
|
|
40
|
+
// 0 is the worst but fastest compression and 10 is the best but slowest
|
|
41
|
+
// compression. If the option is not set, default value of 7 is used.
|
|
42
|
+
// Returns false if an invalid level has been set.
|
|
43
|
+
bool SetSymbolEncodingCompressionLevel(Options *options, int compression_level);
|
|
44
|
+
|
|
45
|
+
} // namespace draco
|
|
46
|
+
|
|
47
|
+
#endif // DRACO_COMPRESSION_ENTROPY_SYMBOL_ENCODING_H_
|