• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2011 Google Inc.
2 //
3 // This code is licensed under the same terms as WebM:
4 //  Software License Agreement:  http://www.webmproject.org/license/software/
5 //  Additional IP Rights Grant:  http://www.webmproject.org/license/additional/
6 // -----------------------------------------------------------------------------
7 //
8 // Bit writing and boolean coder
9 //
10 // Author: Skal (pascal.massimino@gmail.com)
11 
12 #ifndef WEBP_ENC_BIT_WRITER_H_
13 #define WEBP_ENC_BIT_WRITER_H_
14 
15 #include "vp8enci.h"
16 
17 #if defined(__cplusplus) || defined(c_plusplus)
18 extern "C" {
19 #endif
20 
21 //-----------------------------------------------------------------------------
22 // Bit-writing
23 
24 typedef struct VP8BitWriter VP8BitWriter;
25 struct VP8BitWriter {
26   int32_t  range_;      // range-1
27   int32_t  value_;
28   int      run_;        // number of outstanding bits
29   int      nb_bits_;    // number of pending bits
30   uint8_t* buf_;
31   size_t   pos_;
32   size_t   max_pos_;
33   int      error_;      // true in case of error
34 };
35 
36 int VP8BitWriterInit(VP8BitWriter* const bw, size_t expected_size);
37 uint8_t* VP8BitWriterFinish(VP8BitWriter* const bw);
38 int VP8PutBit(VP8BitWriter* const bw, int bit, int prob);
39 int VP8PutBitUniform(VP8BitWriter* const bw, int bit);
40 void VP8PutValue(VP8BitWriter* const bw, int value, int nb_bits);
41 void VP8PutSignedValue(VP8BitWriter* const bw, int value, int nb_bits);
42 int VP8BitWriterAppend(VP8BitWriter* const bw,
43                        const uint8_t* data, size_t size);
44 
45 // return approximate write position (in bits)
VP8BitWriterPos(const VP8BitWriter * const bw)46 static inline uint64_t VP8BitWriterPos(const VP8BitWriter* const bw) {
47   return (uint64_t)(bw->pos_ + bw->run_) * 8 + 8 + bw->nb_bits_;
48 }
49 
VP8BitWriterBuf(const VP8BitWriter * const bw)50 static inline uint8_t* VP8BitWriterBuf(const VP8BitWriter* const bw) {
51   return bw->buf_;
52 }
VP8BitWriterSize(const VP8BitWriter * const bw)53 static inline size_t VP8BitWriterSize(const VP8BitWriter* const bw) {
54   return bw->pos_;
55 }
56 
57 //-----------------------------------------------------------------------------
58 
59 #if defined(__cplusplus) || defined(c_plusplus)
60 }    // extern "C"
61 #endif
62 
63 #endif  // WEBP_ENC_BIT_WRITER_H_
64