Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(422)

Side by Side Diff: source/libvpx/vp9/encoder/vp9_treewriter.h

Issue 11555023: libvpx: Add VP9 decoder. (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 *
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.
9 */
10
11
12 #ifndef VP9_ENCODER_VP9_TREEWRITER_H_
13 #define VP9_ENCODER_VP9_TREEWRITER_H_
14
15 /* Trees map alphabets into huffman-like codes suitable for an arithmetic
16 bit coder. Timothy S Murphy 11 October 2004 */
17
18 #include "vp9/common/vp9_treecoder.h"
19
20 #include "vp9/encoder/vp9_boolhuff.h" /* for now */
21
22 typedef BOOL_CODER vp9_writer;
23
24 #define vp9_write encode_bool
25 #define vp9_write_literal vp9_encode_value
26 #define vp9_write_bit(W, V) vp9_write(W, V, vp9_prob_half)
27
28 /* Approximate length of an encoded bool in 256ths of a bit at given prob */
29
30 #define vp9_cost_zero(x) (vp9_prob_cost[x])
31 #define vp9_cost_one(x) vp9_cost_zero(vp9_complement(x))
32
33 #define vp9_cost_bit(x, b) vp9_cost_zero((b) ? vp9_complement(x) : (x))
34
35 /* VP8BC version is scaled by 2^20 rather than 2^8; see bool_coder.h */
36
37
38 /* Both of these return bits, not scaled bits. */
39
40 static __inline unsigned int cost_branch(const unsigned int ct[2],
41 vp9_prob p) {
42 /* Imitate existing calculation */
43 return ((ct[0] * vp9_cost_zero(p))
44 + (ct[1] * vp9_cost_one(p))) >> 8;
45 }
46
47 static __inline unsigned int cost_branch256(const unsigned int ct[2],
48 vp9_prob p) {
49 /* Imitate existing calculation */
50 return ((ct[0] * vp9_cost_zero(p))
51 + (ct[1] * vp9_cost_one(p)));
52 }
53
54 /* Small functions to write explicit values and tokens, as well as
55 estimate their lengths. */
56
57 static __inline void treed_write(vp9_writer *const w,
58 vp9_tree t,
59 const vp9_prob *const p,
60 int v,
61 /* number of bits in v, assumed nonzero */
62 int n) {
63 vp9_tree_index i = 0;
64
65 do {
66 const int b = (v >> --n) & 1;
67 vp9_write(w, b, p[i >> 1]);
68 i = t[i + b];
69 } while (n);
70 }
71
72 static __inline void write_token(vp9_writer *const w,
73 vp9_tree t,
74 const vp9_prob *const p,
75 vp9_token *const x) {
76 treed_write(w, t, p, x->value, x->Len);
77 }
78
79 static __inline int treed_cost(vp9_tree t,
80 const vp9_prob *const p,
81 int v,
82 /* number of bits in v, assumed nonzero */
83 int n) {
84 int c = 0;
85 vp9_tree_index i = 0;
86
87 do {
88 const int b = (v >> --n) & 1;
89 c += vp9_cost_bit(p[i >> 1], b);
90 i = t[i + b];
91 } while (n);
92
93 return c;
94 }
95
96 static __inline int cost_token(vp9_tree t,
97 const vp9_prob *const p,
98 vp9_token *const x) {
99 return treed_cost(t, p, x->value, x->Len);
100 }
101
102 /* Fill array of costs for all possible token values. */
103
104 void vp9_cost_tokens(int *Costs, const vp9_prob *, vp9_tree);
105
106 void vp9_cost_tokens_skip(int *c, const vp9_prob *p, vp9_tree t);
107
108 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698