/media/libvpx/vp8/common/treecoder.h

http://github.com/zpao/v8monkey · C Header · 90 lines · 43 code · 26 blank · 21 comment · 0 complexity · a3c0c492651d3d54e9d345f4b7915077 MD5 · raw file

  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 __INC_TREECODER_H
  11. #define __INC_TREECODER_H
  12. typedef unsigned char vp8bc_index_t; /* probability index */
  13. typedef unsigned char vp8_prob;
  14. #define vp8_prob_half ( (vp8_prob) 128)
  15. typedef signed char vp8_tree_index;
  16. struct bool_coder_spec;
  17. typedef struct bool_coder_spec bool_coder_spec;
  18. typedef struct bool_writer bool_writer;
  19. typedef struct bool_reader bool_reader;
  20. typedef const bool_coder_spec c_bool_coder_spec;
  21. typedef const bool_writer c_bool_writer;
  22. typedef const bool_reader c_bool_reader;
  23. # define vp8_complement( x) (255 - x)
  24. /* We build coding trees compactly in arrays.
  25. Each node of the tree is a pair of vp8_tree_indices.
  26. Array index often references a corresponding probability table.
  27. Index <= 0 means done encoding/decoding and value = -Index,
  28. Index > 0 means need another bit, specification at index.
  29. Nonnegative indices are always even; processing begins at node 0. */
  30. typedef const vp8_tree_index vp8_tree[], *vp8_tree_p;
  31. typedef const struct vp8_token_struct
  32. {
  33. int value;
  34. int Len;
  35. } vp8_token;
  36. /* Construct encoding array from tree. */
  37. void vp8_tokens_from_tree(struct vp8_token_struct *, vp8_tree);
  38. void vp8_tokens_from_tree_offset(struct vp8_token_struct *, vp8_tree,
  39. int offset);
  40. /* Convert array of token occurrence counts into a table of probabilities
  41. for the associated binary encoding tree. Also writes count of branches
  42. taken for each node on the tree; this facilitiates decisions as to
  43. probability updates. */
  44. void vp8_tree_probs_from_distribution(
  45. int n, /* n = size of alphabet */
  46. vp8_token tok [ /* n */ ],
  47. vp8_tree tree,
  48. vp8_prob probs [ /* n-1 */ ],
  49. unsigned int branch_ct [ /* n-1 */ ] [2],
  50. const unsigned int num_events[ /* n */ ],
  51. unsigned int Pfactor,
  52. int Round
  53. );
  54. /* Variant of above using coder spec rather than hardwired 8-bit probs. */
  55. void vp8bc_tree_probs_from_distribution(
  56. int n, /* n = size of alphabet */
  57. vp8_token tok [ /* n */ ],
  58. vp8_tree tree,
  59. vp8_prob probs [ /* n-1 */ ],
  60. unsigned int branch_ct [ /* n-1 */ ] [2],
  61. const unsigned int num_events[ /* n */ ],
  62. c_bool_coder_spec *s
  63. );
  64. #endif