entropy.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 "entropy.h"
  11. #include "blockd.h"
  12. #include "onyxc_int.h"
  13. #include "vpx_mem/vpx_mem.h"
  14. #include "coefupdateprobs.h"
  15. DECLARE_ALIGNED(16, const unsigned char, vp8_norm[256]) = {
  16. 0, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  17. 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  18. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  19. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  20. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0,
  21. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  22. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  23. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  24. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  25. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  26. };
  27. DECLARE_ALIGNED(16, const unsigned char, vp8_coef_bands[16]) = {
  28. 0, 1, 2, 3, 6, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7
  29. };
  30. DECLARE_ALIGNED(16, const unsigned char,
  31. vp8_prev_token_class[MAX_ENTROPY_TOKENS]) = {
  32. 0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0
  33. };
  34. DECLARE_ALIGNED(16, const int, vp8_default_zig_zag1d[16]) = {
  35. 0, 1, 4, 8, 5, 2, 3, 6, 9, 12, 13, 10, 7, 11, 14, 15,
  36. };
  37. DECLARE_ALIGNED(16, const short, vp8_default_inv_zig_zag[16]) = {
  38. 1, 2, 6, 7, 3, 5, 8, 13, 4, 9, 12, 14, 10, 11, 15, 16
  39. };
  40. /* vp8_default_zig_zag_mask generated with:
  41. void vp8_init_scan_order_mask()
  42. {
  43. int i;
  44. for (i = 0; i < 16; ++i)
  45. {
  46. vp8_default_zig_zag_mask[vp8_default_zig_zag1d[i]] = 1 << i;
  47. }
  48. }
  49. */
  50. DECLARE_ALIGNED(16, const short, vp8_default_zig_zag_mask[16]) = {
  51. 1, 2, 32, 64, 4, 16, 128, 4096, 8, 256, 2048, 8192, 512, 1024, 16384, -32768
  52. };
  53. const int vp8_mb_feature_data_bits[MB_LVL_MAX] = { 7, 6 };
  54. /* Array indices are identical to previously-existing CONTEXT_NODE indices */
  55. /* corresponding _CONTEXT_NODEs */
  56. /* clang-format off */
  57. const vp8_tree_index vp8_coef_tree[22] = {
  58. -DCT_EOB_TOKEN, 2, /* 0 = EOB */
  59. -ZERO_TOKEN, 4, /* 1 = ZERO */
  60. -ONE_TOKEN, 6, /* 2 = ONE */
  61. 8, 12, /* 3 = LOW_VAL */
  62. -TWO_TOKEN, 10, /* 4 = TWO */
  63. -THREE_TOKEN, -FOUR_TOKEN, /* 5 = THREE */
  64. 14, 16, /* 6 = HIGH_LOW */
  65. -DCT_VAL_CATEGORY1, -DCT_VAL_CATEGORY2, /* 7 = CAT_ONE */
  66. 18, 20, /* 8 = CAT_THREEFOUR */
  67. -DCT_VAL_CATEGORY3, -DCT_VAL_CATEGORY4, /* 9 = CAT_THREE */
  68. -DCT_VAL_CATEGORY5, -DCT_VAL_CATEGORY6 /* 10 = CAT_FIVE */
  69. };
  70. /* clang-format on */
  71. /* vp8_coef_encodings generated with:
  72. vp8_tokens_from_tree(vp8_coef_encodings, vp8_coef_tree);
  73. */
  74. vp8_token vp8_coef_encodings[MAX_ENTROPY_TOKENS] = {
  75. { 2, 2 }, { 6, 3 }, { 28, 5 }, { 58, 6 }, { 59, 6 }, { 60, 6 },
  76. { 61, 6 }, { 124, 7 }, { 125, 7 }, { 126, 7 }, { 127, 7 }, { 0, 1 }
  77. };
  78. /* Trees for extra bits. Probabilities are constant and
  79. do not depend on previously encoded bits */
  80. static const vp8_prob Pcat1[] = { 159 };
  81. static const vp8_prob Pcat2[] = { 165, 145 };
  82. static const vp8_prob Pcat3[] = { 173, 148, 140 };
  83. static const vp8_prob Pcat4[] = { 176, 155, 140, 135 };
  84. static const vp8_prob Pcat5[] = { 180, 157, 141, 134, 130 };
  85. static const vp8_prob Pcat6[] = { 254, 254, 243, 230, 196, 177,
  86. 153, 140, 133, 130, 129 };
  87. /* tree index tables generated with:
  88. void init_bit_tree(vp8_tree_index *p, int n) {
  89. int i = 0;
  90. while (++i < n) {
  91. p[0] = p[1] = i << 1;
  92. p += 2;
  93. }
  94. p[0] = p[1] = 0;
  95. }
  96. void init_bit_trees() {
  97. init_bit_tree(cat1, 1);
  98. init_bit_tree(cat2, 2);
  99. init_bit_tree(cat3, 3);
  100. init_bit_tree(cat4, 4);
  101. init_bit_tree(cat5, 5);
  102. init_bit_tree(cat6, 11);
  103. }
  104. */
  105. static const vp8_tree_index cat1[2] = { 0, 0 };
  106. static const vp8_tree_index cat2[4] = { 2, 2, 0, 0 };
  107. static const vp8_tree_index cat3[6] = { 2, 2, 4, 4, 0, 0 };
  108. static const vp8_tree_index cat4[8] = { 2, 2, 4, 4, 6, 6, 0, 0 };
  109. static const vp8_tree_index cat5[10] = { 2, 2, 4, 4, 6, 6, 8, 8, 0, 0 };
  110. static const vp8_tree_index cat6[22] = {
  111. 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14, 16, 16, 18, 18, 20, 20, 0, 0
  112. };
  113. const vp8_extra_bit_struct vp8_extra_bits[12] = {
  114. { 0, 0, 0, 0 }, { 0, 0, 0, 1 }, { 0, 0, 0, 2 },
  115. { 0, 0, 0, 3 }, { 0, 0, 0, 4 }, { cat1, Pcat1, 1, 5 },
  116. { cat2, Pcat2, 2, 7 }, { cat3, Pcat3, 3, 11 }, { cat4, Pcat4, 4, 19 },
  117. { cat5, Pcat5, 5, 35 }, { cat6, Pcat6, 11, 67 }, { 0, 0, 0, 0 }
  118. };
  119. #include "default_coef_probs.h"
  120. void vp8_default_coef_probs(VP8_COMMON *pc) {
  121. memcpy(pc->fc.coef_probs, default_coef_probs, sizeof(default_coef_probs));
  122. }