GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
folded_integer_bit_decoder.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 direct encoding of bits with arithmetic encoder interface.
16#ifndef DRACO_COMPRESSION_BIT_CODERS_FOLDED_INTEGER_BIT_DECODER_H_
17#define DRACO_COMPRESSION_BIT_CODERS_FOLDED_INTEGER_BIT_DECODER_H_
18
19#include <vector>
20
22
23namespace draco {
24
25// See FoldedBit32Encoder for more details.
26template <class BitDecoderT>
28 public:
31
32 // Sets |source_buffer| as the buffer to decode bits from.
33 bool StartDecoding(DecoderBuffer *source_buffer) {
34 for (int i = 0; i < 32; i++) {
35 if (!folded_number_decoders_[i].StartDecoding(source_buffer)) {
36 return false;
37 }
38 }
39 return bit_decoder_.StartDecoding(source_buffer);
40 }
41
42 // Decode one bit. Returns true if the bit is a 1, otherwise false.
43 bool DecodeNextBit() { return bit_decoder_.DecodeNextBit(); }
44
45 // Decode the next |nbits| and return the sequence in |value|. |nbits| must be
46 // > 0 and <= 32.
47 void DecodeLeastSignificantBits32(int nbits, uint32_t *value) {
48 uint32_t result = 0;
49 for (int i = 0; i < nbits; ++i) {
50 const bool bit = folded_number_decoders_[i].DecodeNextBit();
51 result = (result << 1) + bit;
52 }
53 *value = result;
54 }
55
56 void EndDecoding() {
57 for (int i = 0; i < 32; i++) {
58 folded_number_decoders_[i].EndDecoding();
59 }
60 bit_decoder_.EndDecoding();
61 }
62
63 private:
64 void Clear() {
65 for (int i = 0; i < 32; i++) {
66 folded_number_decoders_[i].Clear();
67 }
68 bit_decoder_.Clear();
69 }
70
71 std::array<BitDecoderT, 32> folded_number_decoders_;
72 BitDecoderT bit_decoder_;
73};
74
75} // namespace draco
76
77#endif // DRACO_COMPRESSION_BIT_CODERS_FOLDED_INTEGER_BIT_DECODER_H_
Definition decoder_buffer.h:30
bool DecodeNextBit()
Definition folded_integer_bit_decoder.h:43
void DecodeLeastSignificantBits32(int nbits, uint32_t *value)
Definition folded_integer_bit_decoder.h:47
~FoldedBit32Decoder()
Definition folded_integer_bit_decoder.h:30
FoldedBit32Decoder()
Definition folded_integer_bit_decoder.h:29
void EndDecoding()
Definition folded_integer_bit_decoder.h:56
bool StartDecoding(DecoderBuffer *source_buffer)
Definition folded_integer_bit_decoder.h:33
Definition attribute_octahedron_transform.cc:21