GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
rans_symbol_coding.h
Go to the documentation of this file.
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 providing shared functionality for RAnsSymbolEncoder and
16// RAnsSymbolDecoder (see rans_symbol_encoder.h / rans_symbol_decoder.h).
17#ifndef DRACO_COMPRESSION_ENTROPY_RANS_SYMBOL_CODING_H_
18#define DRACO_COMPRESSION_ENTROPY_RANS_SYMBOL_CODING_H_
19
21
22namespace draco {
23
24// Computes the desired precision of the rANS method for the specified number of
25// unique symbols the input data (defined by their bit_length).
26constexpr int ComputeRAnsUnclampedPrecision(int symbols_bit_length) {
27 return (3 * symbols_bit_length) / 2;
28}
29
30// Computes the desired precision clamped to guarantee a valid functionality of
31// our rANS library (which is between 12 to 20 bits).
33 int symbols_bit_length) {
34 return ComputeRAnsUnclampedPrecision(symbols_bit_length) < 12 ? 12
35 : ComputeRAnsUnclampedPrecision(symbols_bit_length) > 20
36 ? 20
37 : ComputeRAnsUnclampedPrecision(symbols_bit_length);
38}
39
40// Compute approximate frequency table size needed for storing the provided
41// symbols.
42static inline int64_t ApproximateRAnsFrequencyTableBits(
43 int32_t max_value, int num_unique_symbols) {
44 // Approximate number of bits for storing zero frequency entries using the
45 // run length encoding (with max length of 64).
46 const int64_t table_zero_frequency_bits =
47 8 * (num_unique_symbols + (max_value - num_unique_symbols) / 64);
48 return 8 * num_unique_symbols + table_zero_frequency_bits;
49}
50
51} // namespace draco
52
53#endif // DRACO_COMPRESSION_ENTROPY_RANS_SYMBOL_CODING_H_
Definition attribute_octahedron_transform.cc:21
constexpr int ComputeRAnsUnclampedPrecision(int symbols_bit_length)
Definition rans_symbol_coding.h:26
constexpr int ComputeRAnsPrecisionFromUniqueSymbolsBitLength(int symbols_bit_length)
Definition rans_symbol_coding.h:32