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
13static void cost(int *costs, vp9_tree tree, const vp9_prob *probs,
14                 int i, int c) {
15  const vp9_prob prob = probs[i / 2];
16  int b;
17
18  for (b = 0; b <= 1; ++b) {
19    const int cc = c + vp9_cost_bit(prob, b);
20    const vp9_tree_index ii = tree[i + b];
21
22    if (ii <= 0)
23      costs[-ii] = cc;
24    else
25      cost(costs, tree, probs, ii, cc);
26  }
27}
28
29void vp9_cost_tokens(int *costs, const vp9_prob *probs, vp9_tree tree) {
30  cost(costs, tree, probs, 0, 0);
31}
32
33void vp9_cost_tokens_skip(int *costs, const vp9_prob *probs, vp9_tree tree) {
34  assert(tree[0] <= 0 && tree[1] > 0);
35
36  costs[-tree[0]] = vp9_cost_bit(probs[0], 0);
37  cost(costs, tree, probs, 2, 0);
38}
39