Welcome to mirror list, hosted at ThFree Co, Russian Federation.

symbol_bit_encoder.h « bit_coders « compression « draco « src « dracoenc « draco « extern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7f1570c1a7c3d3409cd83e9b6a87c737e76f9f5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#ifndef DRACO_COMPRESSION_BIT_CODERS_SYMBOL_BIT_ENCODER_H_
#define DRACO_COMPRESSION_BIT_CODERS_SYMBOL_BIT_ENCODER_H_

#include <algorithm>
#include <vector>

#include "draco/core/encoder_buffer.h"

namespace draco {

// Class for encoding bits using the symbol entropy encoding. Wraps
// |EncodeSymbols|. Note that this uses a symbol-based encoding scheme for
// encoding bits.
class SymbolBitEncoder {
 public:
  // Must be called before any Encode* function is called.
  void StartEncoding() { Clear(); }

  // Encode one bit. If |bit| is true encode a 1, otherwise encode a 0.
  void EncodeBit(bool bit) { EncodeLeastSignificantBits32(1, bit ? 1 : 0); }

  // Encode |nbits| LSBs of |value| as a symbol. |nbits| must be > 0 and <= 32.
  void EncodeLeastSignificantBits32(int nbits, uint32_t value);

  // Ends the bit encoding and stores the result into the target_buffer.
  void EndEncoding(EncoderBuffer *target_buffer);

 private:
  void Clear();

  std::vector<uint32_t> symbols_;
};

}  // namespace draco

#endif  // DRACO_COMPRESSION_BIT_CODERS_SYMBOL_BIT_ENCODER_H_