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

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

Issue 111463005: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 7 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
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_tokenize.c ('k') | source/libvpx/vp9/encoder/vp9_treewriter.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11
12 #ifndef VP9_ENCODER_VP9_TREEWRITER_H_ 11 #ifndef VP9_ENCODER_VP9_TREEWRITER_H_
13 #define VP9_ENCODER_VP9_TREEWRITER_H_ 12 #define VP9_ENCODER_VP9_TREEWRITER_H_
14 13
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" 14 #include "vp9/common/vp9_treecoder.h"
19
20 #include "vp9/encoder/vp9_boolhuff.h" /* for now */ 15 #include "vp9/encoder/vp9_boolhuff.h" /* for now */
21 16
17 #define vp9_cost_zero(prob) (vp9_prob_cost[prob])
22 18
23 #define vp9_write_prob(w, v) vp9_write_literal((w), (v), 8) 19 #define vp9_cost_one(prob) vp9_cost_zero(vp9_complement(prob))
24 20
25 /* Approximate length of an encoded bool in 256ths of a bit at given prob */ 21 #define vp9_cost_bit(prob, bit) vp9_cost_zero((bit) ? vp9_complement(prob) \
22 : (prob))
26 23
27 #define vp9_cost_zero(x) (vp9_prob_cost[x])
28 #define vp9_cost_one(x) vp9_cost_zero(vp9_complement(x))
29
30 #define vp9_cost_bit(x, b) vp9_cost_zero((b) ? vp9_complement(x) : (x))
31
32 /* VP8BC version is scaled by 2^20 rather than 2^8; see bool_coder.h */
33
34
35 /* Both of these return bits, not scaled bits. */
36 static INLINE unsigned int cost_branch256(const unsigned int ct[2], 24 static INLINE unsigned int cost_branch256(const unsigned int ct[2],
37 vp9_prob p) { 25 vp9_prob p) {
38 return ct[0] * vp9_cost_zero(p) + ct[1] * vp9_cost_one(p); 26 return ct[0] * vp9_cost_zero(p) + ct[1] * vp9_cost_one(p);
39 } 27 }
40 28
41 static INLINE unsigned int cost_branch(const unsigned int ct[2],
42 vp9_prob p) {
43 return cost_branch256(ct, p) >> 8;
44 }
45
46
47 static INLINE void treed_write(vp9_writer *w,
48 vp9_tree tree, const vp9_prob *probs,
49 int bits, int len) {
50 vp9_tree_index i = 0;
51
52 do {
53 const int bit = (bits >> --len) & 1;
54 vp9_write(w, bit, probs[i >> 1]);
55 i = tree[i + bit];
56 } while (len);
57 }
58
59 static INLINE void write_token(vp9_writer *w, vp9_tree tree,
60 const vp9_prob *probs,
61 const struct vp9_token *token) {
62 treed_write(w, tree, probs, token->value, token->len);
63 }
64
65 static INLINE int treed_cost(vp9_tree tree, const vp9_prob *probs, 29 static INLINE int treed_cost(vp9_tree tree, const vp9_prob *probs,
66 int bits, int len) { 30 int bits, int len) {
67 int cost = 0; 31 int cost = 0;
68 vp9_tree_index i = 0; 32 vp9_tree_index i = 0;
69 33
70 do { 34 do {
71 const int bit = (bits >> --len) & 1; 35 const int bit = (bits >> --len) & 1;
72 cost += vp9_cost_bit(probs[i >> 1], bit); 36 cost += vp9_cost_bit(probs[i >> 1], bit);
73 i = tree[i + bit]; 37 i = tree[i + bit];
74 } while (len); 38 } while (len);
75 39
76 return cost; 40 return cost;
77 } 41 }
78 42
79 static INLINE int cost_token(vp9_tree tree, const vp9_prob *probs,
80 const struct vp9_token *token) {
81 return treed_cost(tree, probs, token->value, token->len);
82 }
83
84 void vp9_cost_tokens(int *costs, const vp9_prob *probs, vp9_tree tree); 43 void vp9_cost_tokens(int *costs, const vp9_prob *probs, vp9_tree tree);
85 void vp9_cost_tokens_skip(int *costs, const vp9_prob *probs, vp9_tree tree); 44 void vp9_cost_tokens_skip(int *costs, const vp9_prob *probs, vp9_tree tree);
86 45
46 void vp9_tree_probs_from_distribution(vp9_tree tree,
47 unsigned int branch_ct[ /* n - 1 */ ][2],
48 const unsigned int num_events[ /* n */ ]);
49
50 struct vp9_token {
51 int value;
52 int len;
53 };
54
55 void vp9_tokens_from_tree(struct vp9_token*, const vp9_tree_index *);
56
57 static INLINE void vp9_write_tree(vp9_writer *w, const vp9_tree_index *tree,
58 const vp9_prob *probs, int bits, int len,
59 vp9_tree_index i) {
60 do {
61 const int bit = (bits >> --len) & 1;
62 vp9_write(w, bit, probs[i >> 1]);
63 i = tree[i + bit];
64 } while (len);
65 }
66
67 static INLINE void vp9_write_token(vp9_writer *w, const vp9_tree_index *tree,
68 const vp9_prob *probs,
69 const struct vp9_token *token) {
70 vp9_write_tree(w, tree, probs, token->value, token->len, 0);
71 }
72
87 #endif // VP9_ENCODER_VP9_TREEWRITER_H_ 73 #endif // VP9_ENCODER_VP9_TREEWRITER_H_
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_tokenize.c ('k') | source/libvpx/vp9/encoder/vp9_treewriter.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698