treewriter.h 1.65 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

15
#include "aom_dsp/bitwriter.h"
Jingning Han's avatar
Jingning Han committed
16
17
18
19
20

#ifdef __cplusplus
extern "C" {
#endif

Yaowu Xu's avatar
Yaowu Xu committed
21
22
23
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
24

Yaowu Xu's avatar
Yaowu Xu committed
25
struct av1_token {
Jingning Han's avatar
Jingning Han committed
26
27
28
29
  int value;
  int len;
};

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

32
static INLINE void av1_write_tree(aom_writer *w, const aom_tree_index *tree,
Yaowu Xu's avatar
Yaowu Xu committed
33
34
                                  const aom_prob *probs, int bits, int len,
                                  aom_tree_index i) {
Jingning Han's avatar
Jingning Han committed
35
36
  do {
    const int bit = (bits >> --len) & 1;
37
    aom_write(w, bit, probs[i >> 1]);
Jingning Han's avatar
Jingning Han committed
38
39
40
41
    i = tree[i + bit];
  } while (len);
}

42
static INLINE void av1_write_token(aom_writer *w, const aom_tree_index *tree,
Yaowu Xu's avatar
Yaowu Xu committed
43
44
45
                                   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
46
47
48
49
50
51
}

#ifdef __cplusplus
}  // extern "C"
#endif

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