vp9_cost.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (c) 2014 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. #ifndef VPX_VP9_ENCODER_VP9_COST_H_
  11. #define VPX_VP9_ENCODER_VP9_COST_H_
  12. #include "vpx_dsp/prob.h"
  13. #include "vpx/vpx_integer.h"
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. extern const uint16_t vp9_prob_cost[256];
  18. // The factor to scale from cost in bits to cost in vp9_prob_cost units.
  19. #define VP9_PROB_COST_SHIFT 9
  20. #define vp9_cost_zero(prob) (vp9_prob_cost[prob])
  21. #define vp9_cost_one(prob) vp9_cost_zero(256 - (prob))
  22. #define vp9_cost_bit(prob, bit) vp9_cost_zero((bit) ? 256 - (prob) : (prob))
  23. static INLINE unsigned int cost_branch256(const unsigned int ct[2],
  24. vpx_prob p) {
  25. return ct[0] * vp9_cost_zero(p) + ct[1] * vp9_cost_one(p);
  26. }
  27. static INLINE int treed_cost(vpx_tree tree, const vpx_prob *probs, int bits,
  28. int len) {
  29. int cost = 0;
  30. vpx_tree_index i = 0;
  31. do {
  32. const int bit = (bits >> --len) & 1;
  33. cost += vp9_cost_bit(probs[i >> 1], bit);
  34. i = tree[i + bit];
  35. } while (len);
  36. return cost;
  37. }
  38. void vp9_cost_tokens(int *costs, const vpx_prob *probs, vpx_tree tree);
  39. void vp9_cost_tokens_skip(int *costs, const vpx_prob *probs, vpx_tree tree);
  40. #ifdef __cplusplus
  41. } // extern "C"
  42. #endif
  43. #endif // VPX_VP9_ENCODER_VP9_COST_H_