Coverage Report

Created: 2024-09-06 07:53

/src/libvpx/vp9/encoder/vp9_treewriter.c
Line
Count
Source
1
/*
2
 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3
 *
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
6
 *  tree. An additional intellectual property rights grant can be found
7
 *  in the file PATENTS.  All contributing project authors may
8
 *  be found in the AUTHORS file in the root of the source tree.
9
 */
10
11
#include "vp9/encoder/vp9_treewriter.h"
12
13
static void tree2tok(struct vp9_token *tokens, const vpx_tree_index *tree,
14
16
                     int i, int v, int l) {
15
16
  v += v;
16
16
  ++l;
17
18
32
  do {
19
32
    const vpx_tree_index j = tree[i++];
20
32
    if (j <= 0) {
21
19
      tokens[-j].value = v;
22
19
      tokens[-j].len = l;
23
19
    } else {
24
13
      tree2tok(tokens, tree, j, v, l);
25
13
    }
26
32
  } while (++v & 1);
27
16
}
28
29
void vp9_tokens_from_tree(struct vp9_token *tokens,
30
3
                          const vpx_tree_index *tree) {
31
3
  tree2tok(tokens, tree, 0, 0, 0);
32
3
}
33
34
static unsigned int convert_distribution(unsigned int i, vpx_tree tree,
35
                                         unsigned int branch_ct[][2],
36
57.5M
                                         const unsigned int num_events[]) {
37
57.5M
  unsigned int left, right;
38
39
57.5M
  if (tree[i] <= 0)
40
42.9M
    left = num_events[-tree[i]];
41
14.6M
  else
42
14.6M
    left = convert_distribution(tree[i], tree, branch_ct, num_events);
43
44
57.5M
  if (tree[i + 1] <= 0)
45
20.7M
    right = num_events[-tree[i + 1]];
46
36.8M
  else
47
36.8M
    right = convert_distribution(tree[i + 1], tree, branch_ct, num_events);
48
49
57.5M
  branch_ct[i >> 1][0] = left;
50
57.5M
  branch_ct[i >> 1][1] = right;
51
57.5M
  return left + right;
52
57.5M
}
53
54
void vp9_tree_probs_from_distribution(vpx_tree tree,
55
                                      unsigned int branch_ct[/* n-1 */][2],
56
6.11M
                                      const unsigned int num_events[/* n */]) {
57
6.11M
  convert_distribution(0, tree, branch_ct, num_events);
58
6.11M
}