Line data Source code
1 : /*
2 : * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3 : *
4 : * This source code is subject to the terms of the BSD 2 Clause License and
5 : * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 : * was not distributed with this source code in the LICENSE file, you can
7 : * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 : * Media Patent License 1.0 was not distributed with this source code in the
9 : * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10 : */
11 : #include "./aom_config.h"
12 : #include "./bitreader_buffer.h"
13 :
14 0 : size_t aom_rb_bytes_read(struct aom_read_bit_buffer *rb) {
15 0 : return (rb->bit_offset + 7) >> 3;
16 : }
17 :
18 0 : int aom_rb_read_bit(struct aom_read_bit_buffer *rb) {
19 0 : const uint32_t off = rb->bit_offset;
20 0 : const uint32_t p = off >> 3;
21 0 : const int q = 7 - (int)(off & 0x7);
22 0 : if (rb->bit_buffer + p < rb->bit_buffer_end) {
23 0 : const int bit = (rb->bit_buffer[p] >> q) & 1;
24 0 : rb->bit_offset = off + 1;
25 0 : return bit;
26 : } else {
27 0 : if (rb->error_handler) rb->error_handler(rb->error_handler_data);
28 0 : return 0;
29 : }
30 : }
31 :
32 0 : int aom_rb_read_literal(struct aom_read_bit_buffer *rb, int bits) {
33 0 : int value = 0, bit;
34 0 : for (bit = bits - 1; bit >= 0; bit--) value |= aom_rb_read_bit(rb) << bit;
35 0 : return value;
36 : }
37 :
38 0 : int aom_rb_read_signed_literal(struct aom_read_bit_buffer *rb, int bits) {
39 0 : const int value = aom_rb_read_literal(rb, bits);
40 0 : return aom_rb_read_bit(rb) ? -value : value;
41 : }
42 :
43 0 : int aom_rb_read_inv_signed_literal(struct aom_read_bit_buffer *rb, int bits) {
44 0 : const int nbits = sizeof(unsigned) * 8 - bits - 1;
45 0 : const unsigned value = (unsigned)aom_rb_read_literal(rb, bits + 1) << nbits;
46 0 : return ((int)value) >> nbits;
47 : }
|