2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
11 #ifndef VP9_DECODER_VP9_READER_H_
12 #define VP9_DECODER_VP9_READER_H_
17 #include "./vpx_config.h"
18 #include "vpx_ports/mem.h"
19 #include "vpx/vpx_integer.h"
21 #include "vp9/common/vp9_prob.h"
27 typedef size_t BD_VALUE;
29 #define BD_VALUE_SIZE ((int)sizeof(BD_VALUE) * CHAR_BIT)
32 const uint8_t *buffer_end;
33 const uint8_t *buffer;
39 int vp9_reader_init(vp9_reader *r, const uint8_t *buffer, size_t size);
41 void vp9_reader_fill(vp9_reader *r);
43 int vp9_reader_has_error(vp9_reader *r);
45 const uint8_t *vp9_reader_find_end(vp9_reader *r);
47 static int vp9_read(vp9_reader *r, int prob) {
53 unsigned int split = (r->range * prob + (256 - prob)) >> CHAR_BIT;
61 bigsplit = (BD_VALUE)split << (BD_VALUE_SIZE - CHAR_BIT);
65 if (value >= bigsplit) {
66 range = r->range - split;
67 value = value - bigsplit;
72 register unsigned int shift = vp9_norm[range];
84 static int vp9_read_bit(vp9_reader *r) {
85 return vp9_read(r, 128); // vp9_prob_half
88 static int vp9_read_literal(vp9_reader *r, int bits) {
91 for (bit = bits - 1; bit >= 0; bit--)
92 literal |= vp9_read_bit(r) << bit;
97 static int vp9_read_tree(vp9_reader *r, const vp9_tree_index *tree,
98 const vp9_prob *probs) {
101 while ((i = tree[i + vp9_read(r, probs[i >> 1])]) > 0)
111 #endif // VP9_DECODER_VP9_READER_H_