OLD | NEW |
| (Empty) |
1 /* Copyright 2013 Google Inc. All Rights Reserved. | |
2 | |
3 Licensed under the Apache License, Version 2.0 (the "License"); | |
4 you may not use this file except in compliance with the License. | |
5 You may obtain a copy of the License at | |
6 | |
7 http://www.apache.org/licenses/LICENSE-2.0 | |
8 | |
9 Unless required by applicable law or agreed to in writing, software | |
10 distributed under the License is distributed on an "AS IS" BASIS, | |
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 See the License for the specific language governing permissions and | |
13 limitations under the License. | |
14 | |
15 Bit reading helpers | |
16 */ | |
17 | |
18 #include <assert.h> | |
19 #include <stdlib.h> | |
20 | |
21 #include "./bit_reader.h" | |
22 | |
23 #if defined(__cplusplus) || defined(c_plusplus) | |
24 extern "C" { | |
25 #endif | |
26 | |
27 int BrotliInitBitReader(BrotliBitReader* const br, BrotliInput input) { | |
28 size_t i; | |
29 assert(br != NULL); | |
30 | |
31 br->buf_ptr_ = br->buf_; | |
32 br->input_ = input; | |
33 br->val_ = 0; | |
34 br->pos_ = 0; | |
35 br->bit_pos_ = 0; | |
36 br->bit_end_pos_ = 0; | |
37 br->eos_ = 0; | |
38 if (!BrotliReadMoreInput(br)) { | |
39 return 0; | |
40 } | |
41 for (i = 0; i < sizeof(br->val_); ++i) { | |
42 br->val_ |= ((uint64_t)br->buf_[br->pos_]) << (8 * i); | |
43 ++br->pos_; | |
44 } | |
45 return (br->bit_end_pos_ > 0); | |
46 } | |
47 | |
48 #if defined(__cplusplus) || defined(c_plusplus) | |
49 } /* extern "C" */ | |
50 #endif | |
OLD | NEW |