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/vp8dx.h"
20 #include "vpx/vpx_integer.h"
22 #include "vp9/common/vp9_prob.h"
28 typedef size_t BD_VALUE;
30 #define BD_VALUE_SIZE ((int)sizeof(BD_VALUE) * CHAR_BIT)
33 const uint8_t *buffer_end;
34 const uint8_t *buffer;
35 uint8_t clear_buffer[sizeof(BD_VALUE) + 1];
39 vpx_decrypt_cb decrypt_cb;
43 int vp9_reader_init(vp9_reader *r,
44 const uint8_t *buffer,
46 vpx_decrypt_cb decrypt_cb,
49 void vp9_reader_fill(vp9_reader *r);
51 int vp9_reader_has_error(vp9_reader *r);
53 const uint8_t *vp9_reader_find_end(vp9_reader *r);
55 static int vp9_read(vp9_reader *r, int prob) {
61 unsigned int split = (r->range * prob + (256 - prob)) >> CHAR_BIT;
69 bigsplit = (BD_VALUE)split << (BD_VALUE_SIZE - CHAR_BIT);
73 if (value >= bigsplit) {
74 range = r->range - split;
75 value = value - bigsplit;
80 register unsigned int shift = vp9_norm[range];
92 static int vp9_read_bit(vp9_reader *r) {
93 return vp9_read(r, 128); // vp9_prob_half
96 static int vp9_read_literal(vp9_reader *r, int bits) {
99 for (bit = bits - 1; bit >= 0; bit--)
100 literal |= vp9_read_bit(r) << bit;
105 static int vp9_read_tree(vp9_reader *r, const vp9_tree_index *tree,
106 const vp9_prob *probs) {
107 vp9_tree_index i = 0;
109 while ((i = tree[i + vp9_read(r, probs[i >> 1])]) > 0)
119 #endif // VP9_DECODER_VP9_READER_H_