vp9_treewriter.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. #ifndef VP9_ENCODER_VP9_TREEWRITER_H_
  11. #define VP9_ENCODER_VP9_TREEWRITER_H_
  12. #include "vpx_dsp/bitwriter.h"
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. void vp9_tree_probs_from_distribution(vpx_tree tree,
  17. unsigned int branch_ct[/* n - 1 */][2],
  18. const unsigned int num_events[/* n */]);
  19. struct vp9_token {
  20. int value;
  21. int len;
  22. };
  23. void vp9_tokens_from_tree(struct vp9_token *, const vpx_tree_index *);
  24. static INLINE void vp9_write_tree(vpx_writer *w, const vpx_tree_index *tree,
  25. const vpx_prob *probs, int bits, int len,
  26. vpx_tree_index i) {
  27. do {
  28. const int bit = (bits >> --len) & 1;
  29. vpx_write(w, bit, probs[i >> 1]);
  30. i = tree[i + bit];
  31. } while (len);
  32. }
  33. static INLINE void vp9_write_token(vpx_writer *w, const vpx_tree_index *tree,
  34. const vpx_prob *probs,
  35. const struct vp9_token *token) {
  36. vp9_write_tree(w, tree, probs, token->value, token->len, 0);
  37. }
  38. #ifdef __cplusplus
  39. } // extern "C"
  40. #endif
  41. #endif // VP9_ENCODER_VP9_TREEWRITER_H_