Change-Id: Iee43c34909deec9787b29c1c33672213b9f049df
This commit is contained in:
hkuang 2014-12-12 13:54:40 -08:00
Родитель f925e5ce0f
Коммит 3cecce916b
1 изменённых файлов: 8 добавлений и 8 удалений

Просмотреть файл

@ -10,20 +10,20 @@
#include "vp9/decoder/vp9_read_bit_buffer.h" #include "vp9/decoder/vp9_read_bit_buffer.h"
size_t vp9_rb_bytes_read(struct vp9_read_bit_buffer *rb) { size_t vp9_rb_bytes_read(struct vp9_read_bit_buffer *rb) {
return (rb->bit_offset + CHAR_BIT - 1) / CHAR_BIT; return (rb->bit_offset + 7) >> 3;
} }
int vp9_rb_read_bit(struct vp9_read_bit_buffer *rb) { int vp9_rb_read_bit(struct vp9_read_bit_buffer *rb) {
const size_t off = rb->bit_offset; const size_t off = rb->bit_offset;
const size_t p = off / CHAR_BIT; const size_t p = off >> 3;
const int q = CHAR_BIT - 1 - (int)off % CHAR_BIT; const int q = 7 - (int)(off & 0x7);
if (rb->bit_buffer + p >= rb->bit_buffer_end) { if (rb->bit_buffer + p < rb->bit_buffer_end) {
rb->error_handler(rb->error_handler_data); const int bit = (rb->bit_buffer[p] >> q) & 1;
return 0;
} else {
const int bit = (rb->bit_buffer[p] & (1 << q)) >> q;
rb->bit_offset = off + 1; rb->bit_offset = off + 1;
return bit; return bit;
} else {
rb->error_handler(rb->error_handler_data);
return 0;
} }
} }