Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright (c) 2013 The WebM project authors. All Rights Reserved. |
michael@0 | 3 | * |
michael@0 | 4 | * Use of this source code is governed by a BSD-style license |
michael@0 | 5 | * that can be found in the LICENSE file in the root of the source |
michael@0 | 6 | * tree. An additional intellectual property rights grant can be found |
michael@0 | 7 | * in the file PATENTS. All contributing project authors may |
michael@0 | 8 | * be found in the AUTHORS file in the root of the source tree. |
michael@0 | 9 | */ |
michael@0 | 10 | |
michael@0 | 11 | #ifndef VP9_BIT_WRITE_BUFFER_H_ |
michael@0 | 12 | #define VP9_BIT_WRITE_BUFFER_H_ |
michael@0 | 13 | |
michael@0 | 14 | #include <limits.h> |
michael@0 | 15 | |
michael@0 | 16 | #include "vpx/vpx_integer.h" |
michael@0 | 17 | |
michael@0 | 18 | struct vp9_write_bit_buffer { |
michael@0 | 19 | uint8_t *bit_buffer; |
michael@0 | 20 | size_t bit_offset; |
michael@0 | 21 | }; |
michael@0 | 22 | |
michael@0 | 23 | static size_t vp9_rb_bytes_written(struct vp9_write_bit_buffer *wb) { |
michael@0 | 24 | return wb->bit_offset / CHAR_BIT + (wb->bit_offset % CHAR_BIT > 0); |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | static void vp9_wb_write_bit(struct vp9_write_bit_buffer *wb, int bit) { |
michael@0 | 28 | const int off = wb->bit_offset; |
michael@0 | 29 | const int p = off / CHAR_BIT; |
michael@0 | 30 | const int q = CHAR_BIT - 1 - off % CHAR_BIT; |
michael@0 | 31 | if (q == CHAR_BIT -1) { |
michael@0 | 32 | wb->bit_buffer[p] = bit << q; |
michael@0 | 33 | } else { |
michael@0 | 34 | wb->bit_buffer[p] &= ~(1 << q); |
michael@0 | 35 | wb->bit_buffer[p] |= bit << q; |
michael@0 | 36 | } |
michael@0 | 37 | wb->bit_offset = off + 1; |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | static void vp9_wb_write_literal(struct vp9_write_bit_buffer *wb, |
michael@0 | 41 | int data, int bits) { |
michael@0 | 42 | int bit; |
michael@0 | 43 | for (bit = bits - 1; bit >= 0; bit--) |
michael@0 | 44 | vp9_wb_write_bit(wb, (data >> bit) & 1); |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | |
michael@0 | 48 | #endif // VP9_BIT_WRITE_BUFFER_H_ |