193a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org/*
293a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org *  Copyright (c) 2014 The WebM project authors. All Rights Reserved.
393a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org *
493a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org *  Use of this source code is governed by a BSD-style license
593a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org *  that can be found in the LICENSE file in the root of the source
693a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org *  tree. An additional intellectual property rights grant can be found
793a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org *  in the file PATENTS.  All contributing project authors may
893a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org *  be found in the AUTHORS file in the root of the source tree.
993a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org */
1093a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
1193a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org#ifndef VP9_ENCODER_VP9_COST_H_
1293a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org#define VP9_ENCODER_VP9_COST_H_
1393a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
1493a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org#include "vp9/common/vp9_prob.h"
1593a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
1693a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org#ifdef __cplusplus
1793a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orgextern "C" {
1893a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org#endif
1993a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
2093a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orgextern const unsigned int vp9_prob_cost[256];
2193a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
2293a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org#define vp9_cost_zero(prob) (vp9_prob_cost[prob])
2393a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
2493a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org#define vp9_cost_one(prob) vp9_cost_zero(vp9_complement(prob))
2593a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
2693a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org#define vp9_cost_bit(prob, bit) vp9_cost_zero((bit) ? vp9_complement(prob) \
2793a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org                                                    : (prob))
2893a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
2993a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orgstatic INLINE unsigned int cost_branch256(const unsigned int ct[2],
3093a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org                                          vp9_prob p) {
3193a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  return ct[0] * vp9_cost_zero(p) + ct[1] * vp9_cost_one(p);
3293a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org}
3393a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
3493a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orgstatic INLINE int treed_cost(vp9_tree tree, const vp9_prob *probs,
3593a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org                             int bits, int len) {
3693a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  int cost = 0;
3793a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  vp9_tree_index i = 0;
3893a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
3993a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  do {
4093a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org    const int bit = (bits >> --len) & 1;
4193a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org    cost += vp9_cost_bit(probs[i >> 1], bit);
4293a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org    i = tree[i + bit];
4393a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  } while (len);
4493a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
4593a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  return cost;
4693a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org}
4793a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
4893a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orgvoid vp9_cost_tokens(int *costs, const vp9_prob *probs, vp9_tree tree);
4993a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orgvoid vp9_cost_tokens_skip(int *costs, const vp9_prob *probs, vp9_tree tree);
5093a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
5193a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org#ifdef __cplusplus
5293a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org}  // extern "C"
5393a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org#endif
5493a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
5593a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org#endif  // VP9_ENCODER_VP9_COST_H_
56