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 decoding.
16 #ifndef DRACO_COMPRESSION_BIT_CODERS_ADAPTIVE_RANS_BIT_DECODER_H_
17 #define DRACO_COMPRESSION_BIT_CODERS_ADAPTIVE_RANS_BIT_DECODER_H_
18 
19 #include <vector>
20 
21 #include "draco/compression/entropy/ans.h"
22 #include "draco/core/decoder_buffer.h"
23 
24 namespace draco {
25 
26 // Class for decoding a sequence of bits that were encoded with
27 // AdaptiveRAnsBitEncoder.
28 class AdaptiveRAnsBitDecoder {
29  public:
30   AdaptiveRAnsBitDecoder();
31   ~AdaptiveRAnsBitDecoder();
32 
33   // Sets |source_buffer| as the buffer to decode bits from.
34   bool StartDecoding(DecoderBuffer *source_buffer);
35 
36   // Decode one bit. Returns true if the bit is a 1, otherwise false.
37   bool DecodeNextBit();
38 
39   // Decode the next |nbits| and return the sequence in |value|. |nbits| must be
40   // > 0 and <= 32.
41   void DecodeLeastSignificantBits32(int nbits, uint32_t *value);
42 
EndDecoding()43   void EndDecoding() {}
44 
45  private:
46   void Clear();
47 
48   AnsDecoder ans_decoder_;
49   double p0_f_;
50 };
51 
52 }  // namespace draco
53 
54 #endif  // DRACO_COMPRESSION_BIT_CODERS_ADAPTIVE_RANS_BIT_DECODER_H_
55