treewriter.h 1.91 KB
Newer Older
Jingning Han's avatar
Jingning Han committed
1
/*
Yaowu Xu's avatar
Yaowu Xu committed
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Jingning Han's avatar
Jingning Han committed
3
 *
Yaowu Xu's avatar
Yaowu Xu committed
4
5
6
7
8
9
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
Jingning Han's avatar
Jingning Han committed
10
11
 */

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

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

#ifdef __cplusplus
extern "C" {
#endif

Yaowu Xu's avatar
Yaowu Xu committed
29
30
31
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
32

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

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

Yaowu Xu's avatar
Yaowu Xu committed
40
41
42
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
43
44
  do {
    const int bit = (bits >> --len) & 1;
45
    tree_bit_write(w, bit, probs[i >> 1]);
Jingning Han's avatar
Jingning Han committed
46
47
48
49
    i = tree[i + bit];
  } while (len);
}

Yaowu Xu's avatar
Yaowu Xu committed
50
51
52
53
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
54
55
}

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

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