michael@0: /* michael@0: * Copyright (c) 2010 The WebM project authors. All Rights Reserved. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license michael@0: * that can be found in the LICENSE file in the root of the source michael@0: * tree. An additional intellectual property rights grant can be found michael@0: * in the file PATENTS. All contributing project authors may michael@0: * be found in the AUTHORS file in the root of the source tree. michael@0: */ michael@0: michael@0: #include "vp9/encoder/vp9_treewriter.h" michael@0: michael@0: static void cost(int *costs, vp9_tree tree, const vp9_prob *probs, michael@0: int i, int c) { michael@0: const vp9_prob prob = probs[i / 2]; michael@0: int b; michael@0: michael@0: for (b = 0; b <= 1; ++b) { michael@0: const int cc = c + vp9_cost_bit(prob, b); michael@0: const vp9_tree_index ii = tree[i + b]; michael@0: michael@0: if (ii <= 0) michael@0: costs[-ii] = cc; michael@0: else michael@0: cost(costs, tree, probs, ii, cc); michael@0: } michael@0: } michael@0: michael@0: void vp9_cost_tokens(int *costs, const vp9_prob *probs, vp9_tree tree) { michael@0: cost(costs, tree, probs, 0, 0); michael@0: } michael@0: michael@0: void vp9_cost_tokens_skip(int *costs, const vp9_prob *probs, vp9_tree tree) { michael@0: assert(tree[0] <= 0 && tree[1] > 0); michael@0: michael@0: costs[-tree[0]] = vp9_cost_bit(probs[0], 0); michael@0: cost(costs, tree, probs, 2, 0); michael@0: }