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