1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libvpx/vp9/encoder/vp9_treewriter.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,87 @@ 1.4 +/* 1.5 + * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license 1.8 + * that can be found in the LICENSE file in the root of the source 1.9 + * tree. An additional intellectual property rights grant can be found 1.10 + * in the file PATENTS. All contributing project authors may 1.11 + * be found in the AUTHORS file in the root of the source tree. 1.12 + */ 1.13 + 1.14 + 1.15 +#ifndef VP9_ENCODER_VP9_TREEWRITER_H_ 1.16 +#define VP9_ENCODER_VP9_TREEWRITER_H_ 1.17 + 1.18 +/* Trees map alphabets into huffman-like codes suitable for an arithmetic 1.19 + bit coder. Timothy S Murphy 11 October 2004 */ 1.20 + 1.21 +#include "vp9/common/vp9_treecoder.h" 1.22 + 1.23 +#include "vp9/encoder/vp9_boolhuff.h" /* for now */ 1.24 + 1.25 + 1.26 +#define vp9_write_prob(w, v) vp9_write_literal((w), (v), 8) 1.27 + 1.28 +/* Approximate length of an encoded bool in 256ths of a bit at given prob */ 1.29 + 1.30 +#define vp9_cost_zero(x) (vp9_prob_cost[x]) 1.31 +#define vp9_cost_one(x) vp9_cost_zero(vp9_complement(x)) 1.32 + 1.33 +#define vp9_cost_bit(x, b) vp9_cost_zero((b) ? vp9_complement(x) : (x)) 1.34 + 1.35 +/* VP8BC version is scaled by 2^20 rather than 2^8; see bool_coder.h */ 1.36 + 1.37 + 1.38 +/* Both of these return bits, not scaled bits. */ 1.39 +static INLINE unsigned int cost_branch256(const unsigned int ct[2], 1.40 + vp9_prob p) { 1.41 + return ct[0] * vp9_cost_zero(p) + ct[1] * vp9_cost_one(p); 1.42 +} 1.43 + 1.44 +static INLINE unsigned int cost_branch(const unsigned int ct[2], 1.45 + vp9_prob p) { 1.46 + return cost_branch256(ct, p) >> 8; 1.47 +} 1.48 + 1.49 + 1.50 +static INLINE void treed_write(vp9_writer *w, 1.51 + vp9_tree tree, const vp9_prob *probs, 1.52 + int bits, int len) { 1.53 + vp9_tree_index i = 0; 1.54 + 1.55 + do { 1.56 + const int bit = (bits >> --len) & 1; 1.57 + vp9_write(w, bit, probs[i >> 1]); 1.58 + i = tree[i + bit]; 1.59 + } while (len); 1.60 +} 1.61 + 1.62 +static INLINE void write_token(vp9_writer *w, vp9_tree tree, 1.63 + const vp9_prob *probs, 1.64 + const struct vp9_token *token) { 1.65 + treed_write(w, tree, probs, token->value, token->len); 1.66 +} 1.67 + 1.68 +static INLINE int treed_cost(vp9_tree tree, const vp9_prob *probs, 1.69 + int bits, int len) { 1.70 + int cost = 0; 1.71 + vp9_tree_index i = 0; 1.72 + 1.73 + do { 1.74 + const int bit = (bits >> --len) & 1; 1.75 + cost += vp9_cost_bit(probs[i >> 1], bit); 1.76 + i = tree[i + bit]; 1.77 + } while (len); 1.78 + 1.79 + return cost; 1.80 +} 1.81 + 1.82 +static INLINE int cost_token(vp9_tree tree, const vp9_prob *probs, 1.83 + const struct vp9_token *token) { 1.84 + return treed_cost(tree, probs, token->value, token->len); 1.85 +} 1.86 + 1.87 +void vp9_cost_tokens(int *costs, const vp9_prob *probs, vp9_tree tree); 1.88 +void vp9_cost_tokens_skip(int *costs, const vp9_prob *probs, vp9_tree tree); 1.89 + 1.90 +#endif // VP9_ENCODER_VP9_TREEWRITER_H_