GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
adaptive_rans_bit_coding_shared.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 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
21namespace draco {
22
23// Clamp the probability p to a uint8_t in the range [1,255].
24inline 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.
34inline 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_
#define DRACO_DCHECK_LE(a, b)
Definition macros.h:85
Definition attribute_octahedron_transform.cc:21
double update_probability(double old_p, bool bit)
Definition adaptive_rans_bit_coding_shared.h:34
uint8_t clamp_probability(double p)
Definition adaptive_rans_bit_coding_shared.h:24