treecoder.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 VP8_COMMON_TREECODER_H_
  11. #define 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. {
  36. int value;
  37. int Len;
  38. } vp8_token;
  39. /* Construct encoding array from tree. */
  40. void vp8_tokens_from_tree(struct vp8_token_struct *, vp8_tree);
  41. void vp8_tokens_from_tree_offset(struct vp8_token_struct *, vp8_tree,
  42. int offset);
  43. /* Convert array of token occurrence counts into a table of probabilities
  44. for the associated binary encoding tree. Also writes count of branches
  45. taken for each node on the tree; this facilitiates decisions as to
  46. probability updates. */
  47. void vp8_tree_probs_from_distribution(
  48. int n, /* n = size of alphabet */
  49. vp8_token tok [ /* n */ ],
  50. vp8_tree tree,
  51. vp8_prob probs [ /* n-1 */ ],
  52. unsigned int branch_ct [ /* n-1 */ ] [2],
  53. const unsigned int num_events[ /* n */ ],
  54. unsigned int Pfactor,
  55. int Round
  56. );
  57. /* Variant of above using coder spec rather than hardwired 8-bit probs. */
  58. void vp8bc_tree_probs_from_distribution(
  59. int n, /* n = size of alphabet */
  60. vp8_token tok [ /* n */ ],
  61. vp8_tree tree,
  62. vp8_prob probs [ /* n-1 */ ],
  63. unsigned int branch_ct [ /* n-1 */ ] [2],
  64. const unsigned int num_events[ /* n */ ],
  65. c_bool_coder_spec *s
  66. );
  67. #ifdef __cplusplus
  68. } // extern "C"
  69. #endif
  70. #endif // VP8_COMMON_TREECODER_H_