vp9_treewriter.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. #include "vp9/encoder/vp9_treewriter.h"
  11. static void tree2tok(struct vp9_token *tokens, const vp9_tree_index *tree,
  12. int i, int v, int l) {
  13. v += v;
  14. ++l;
  15. do {
  16. const vp9_tree_index j = tree[i++];
  17. if (j <= 0) {
  18. tokens[-j].value = v;
  19. tokens[-j].len = l;
  20. } else {
  21. tree2tok(tokens, tree, j, v, l);
  22. }
  23. } while (++v & 1);
  24. }
  25. void vp9_tokens_from_tree(struct vp9_token *tokens,
  26. const vp9_tree_index *tree) {
  27. tree2tok(tokens, tree, 0, 0, 0);
  28. }
  29. static unsigned int convert_distribution(unsigned int i, vp9_tree tree,
  30. unsigned int branch_ct[][2],
  31. const unsigned int num_events[]) {
  32. unsigned int left, right;
  33. if (tree[i] <= 0)
  34. left = num_events[-tree[i]];
  35. else
  36. left = convert_distribution(tree[i], tree, branch_ct, num_events);
  37. if (tree[i + 1] <= 0)
  38. right = num_events[-tree[i + 1]];
  39. else
  40. right = convert_distribution(tree[i + 1], tree, branch_ct, num_events);
  41. branch_ct[i >> 1][0] = left;
  42. branch_ct[i >> 1][1] = right;
  43. return left + right;
  44. }
  45. void vp9_tree_probs_from_distribution(vp9_tree tree,
  46. unsigned int branch_ct[/* n-1 */][2],
  47. const unsigned int num_events[/* n */]) {
  48. convert_distribution(0, tree, branch_ct, num_events);
  49. }