treewriter.h 1.79 KB
Newer Older
Jingning Han's avatar
Jingning Han committed
1
2
3
4
5
6
7
8
9
10
/*
 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

Yaowu Xu's avatar
Yaowu Xu committed
11
12
#ifndef AV1_ENCODER_TREEWRITER_H_
#define AV1_ENCODER_TREEWRITER_H_
Jingning Han's avatar
Jingning Han committed
13

Yaowu Xu's avatar
Yaowu Xu committed
14
#ifdef AV1_FORCE_AOMBOOL_TREEWRITER
15
#include "aom_dsp/bitwriter.h"
Yaowu Xu's avatar
Yaowu Xu committed
16
17
#define tree_writer aom_writer
#define tree_bit_write aom_write
18
#else
19
#include "av1/encoder/bitwriter.h"
Yaowu Xu's avatar
Yaowu Xu committed
20
21
#define tree_writer aom_writer
#define tree_bit_write aom_write
22
#endif
Jingning Han's avatar
Jingning Han committed
23
24
25
26
27

#ifdef __cplusplus
extern "C" {
#endif

Yaowu Xu's avatar
Yaowu Xu committed
28
29
30
void av1_tree_probs_from_distribution(aom_tree tree,
                                      unsigned int branch_ct[/* n - 1 */][2],
                                      const unsigned int num_events[/* n */]);
Jingning Han's avatar
Jingning Han committed
31

Yaowu Xu's avatar
Yaowu Xu committed
32
struct av1_token {
Jingning Han's avatar
Jingning Han committed
33
34
35
36
  int value;
  int len;
};

Yaowu Xu's avatar
Yaowu Xu committed
37
void av1_tokens_from_tree(struct av1_token *, const aom_tree_index *);
Jingning Han's avatar
Jingning Han committed
38

Yaowu Xu's avatar
Yaowu Xu committed
39
40
41
static INLINE void av1_write_tree(tree_writer *w, const aom_tree_index *tree,
                                  const aom_prob *probs, int bits, int len,
                                  aom_tree_index i) {
Jingning Han's avatar
Jingning Han committed
42
43
  do {
    const int bit = (bits >> --len) & 1;
44
    tree_bit_write(w, bit, probs[i >> 1]);
Jingning Han's avatar
Jingning Han committed
45
46
47
48
    i = tree[i + bit];
  } while (len);
}

Yaowu Xu's avatar
Yaowu Xu committed
49
50
51
52
static INLINE void av1_write_token(tree_writer *w, const aom_tree_index *tree,
                                   const aom_prob *probs,
                                   const struct av1_token *token) {
  av1_write_tree(w, tree, probs, token->value, token->len, 0);
Jingning Han's avatar
Jingning Han committed
53
54
}

55
56
#undef tree_writer
#undef tree_bit_write
Jingning Han's avatar
Jingning Han committed
57
58
59
60
#ifdef __cplusplus
}  // extern "C"
#endif

Yaowu Xu's avatar
Yaowu Xu committed
61
#endif  // AV1_ENCODER_TREEWRITER_H_