GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
adaptive_rans_bit_encoder.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 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
23
24namespace draco {
25
26// Class for adaptive encoding a sequence of bits using rANS.
28 public:
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_
void StartEncoding()
Definition adaptive_rans_bit_encoder.cc:27
void EncodeLeastSignificantBits32(int nbits, uint32_t value)
Definition adaptive_rans_bit_encoder.h:40
void EndEncoding(EncoderBuffer *target_buffer)
Definition adaptive_rans_bit_encoder.cc:29
AdaptiveRAnsBitEncoder()
Definition adaptive_rans_bit_encoder.cc:23
void EncodeBit(bool bit)
Definition adaptive_rans_bit_encoder.h:36
~AdaptiveRAnsBitEncoder()
Definition adaptive_rans_bit_encoder.cc:25
Definition encoder_buffer.h:29
#define DRACO_DCHECK_EQ(a, b)
Definition macros.h:81
Definition attribute_octahedron_transform.cc:21