OLD | NEW |
(Empty) | |
| 1 // Copyright 2010 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 // Boolean decoder |
| 9 // |
| 10 // Author: Skal (pascal.massimino@gmail.com) |
| 11 |
| 12 #include "bits.h" |
| 13 |
| 14 #if defined(__cplusplus) || defined(c_plusplus) |
| 15 extern "C" { |
| 16 #endif |
| 17 |
| 18 //----------------------------------------------------------------------------- |
| 19 // VP8BitReader |
| 20 |
| 21 int VP8Init(VP8BitReader* const br, const uint8_t* buf, uint32_t size) { |
| 22 if (!br || !buf || size < 2) { |
| 23 return 0; |
| 24 } |
| 25 br->buf_ = buf + 2; |
| 26 br->buf_end_ = buf + size; |
| 27 br->left_ = -8; |
| 28 br->value_ = (buf[0] << 8) | buf[1]; |
| 29 br->range_ = 255 - 1; |
| 30 return 1; |
| 31 } |
| 32 |
| 33 const uint8_t kVP8Log2Range[128] = { |
| 34 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, |
| 35 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, |
| 36 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 37 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 38 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 39 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 40 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 41 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 42 0 |
| 43 }; |
| 44 |
| 45 // range = ((range + 1) << kVP8Log2Range[range]) - 1 |
| 46 const uint8_t kVP8NewRange[128] = { |
| 47 127, 127, 191, 127, 159, 191, 223, 127, 143, 159, 175, 191, 207, 223, 239, |
| 48 127, 135, 143, 151, 159, 167, 175, 183, 191, 199, 207, 215, 223, 231, 239, |
| 49 247, 127, 131, 135, 139, 143, 147, 151, 155, 159, 163, 167, 171, 175, 179, |
| 50 183, 187, 191, 195, 199, 203, 207, 211, 215, 219, 223, 227, 231, 235, 239, |
| 51 243, 247, 251, 127, 129, 131, 133, 135, 137, 139, 141, 143, 145, 147, 149, |
| 52 151, 153, 155, 157, 159, 161, 163, 165, 167, 169, 171, 173, 175, 177, 179, |
| 53 181, 183, 185, 187, 189, 191, 193, 195, 197, 199, 201, 203, 205, 207, 209, |
| 54 211, 213, 215, 217, 219, 221, 223, 225, 227, 229, 231, 233, 235, 237, 239, |
| 55 241, 243, 245, 247, 249, 251, 253, 127 |
| 56 }; |
| 57 |
| 58 //----------------------------------------------------------------------------- |
| 59 // Higher-level calls |
| 60 |
| 61 uint32_t VP8GetValue(VP8BitReader* const br, int bits) { |
| 62 uint32_t v = 0; |
| 63 while (bits-- > 0) { |
| 64 v |= VP8GetBit(br, 0x80) << bits; |
| 65 } |
| 66 return v; |
| 67 } |
| 68 |
| 69 int32_t VP8GetSignedValue(VP8BitReader* const br, int bits) { |
| 70 const int value = (bits > 0) ? VP8GetValue(br, bits) : 0; |
| 71 return VP8Get(br) ? -value : value; |
| 72 } |
| 73 |
| 74 //----------------------------------------------------------------------------- |
| 75 |
| 76 #if defined(__cplusplus) || defined(c_plusplus) |
| 77 } // extern "C" |
| 78 #endif |
OLD | NEW |