2
0

treecoder.h 3.0 KB

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