/src/woff2/brotli/c/dec/bit_reader.c
Line | Count | Source |
1 | | /* Copyright 2013 Google Inc. All Rights Reserved. |
2 | | |
3 | | Distributed under MIT license. |
4 | | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT |
5 | | */ |
6 | | |
7 | | /* Bit reading helpers */ |
8 | | |
9 | | #include "./bit_reader.h" |
10 | | |
11 | | #include "../common/platform.h" |
12 | | #include <brotli/types.h> |
13 | | |
14 | | #if defined(__cplusplus) || defined(c_plusplus) |
15 | | extern "C" { |
16 | | #endif |
17 | | |
18 | 11.1k | void BrotliInitBitReader(BrotliBitReader* const br) { |
19 | 11.1k | br->val_ = 0; |
20 | 11.1k | br->bit_pos_ = sizeof(br->val_) << 3; |
21 | 11.1k | } |
22 | | |
23 | 88.5k | BROTLI_BOOL BrotliWarmupBitReader(BrotliBitReader* const br) { |
24 | 88.5k | size_t aligned_read_mask = (sizeof(br->val_) >> 1) - 1; |
25 | | /* Fixing alignment after unaligned BrotliFillWindow would result accumulator |
26 | | overflow. If unalignment is caused by BrotliSafeReadBits, then there is |
27 | | enough space in accumulator to fix alignment. */ |
28 | 88.5k | if (!BROTLI_ALIGNED_READ) { |
29 | 88.5k | aligned_read_mask = 0; |
30 | 88.5k | } |
31 | 88.5k | if (BrotliGetAvailableBits(br) == 0) { |
32 | 23.2k | if (!BrotliPullByte(br)) { |
33 | 2.92k | return BROTLI_FALSE; |
34 | 2.92k | } |
35 | 23.2k | } |
36 | | |
37 | 85.6k | while ((((size_t)br->next_in) & aligned_read_mask) != 0) { |
38 | 0 | if (!BrotliPullByte(br)) { |
39 | | /* If we consumed all the input, we don't care about the alignment. */ |
40 | 0 | return BROTLI_TRUE; |
41 | 0 | } |
42 | 0 | } |
43 | 85.6k | return BROTLI_TRUE; |
44 | 85.6k | } |
45 | | |
46 | | #if defined(__cplusplus) || defined(c_plusplus) |
47 | | } /* extern "C" */ |
48 | | #endif |