vp9_tokenize.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 VP9_ENCODER_VP9_TOKENIZE_H_
  11. #define VP9_ENCODER_VP9_TOKENIZE_H_
  12. #include "vp9/common/vp9_entropy.h"
  13. #include "vp9/encoder/vp9_block.h"
  14. #include "vp9/encoder/vp9_treewriter.h"
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #define EOSB_TOKEN 127 // Not signalled, encoder only
  19. #if CONFIG_VP9_HIGHBITDEPTH
  20. typedef int32_t EXTRABIT;
  21. #else
  22. typedef int16_t EXTRABIT;
  23. #endif
  24. typedef struct {
  25. int16_t token;
  26. EXTRABIT extra;
  27. } TOKENVALUE;
  28. typedef struct {
  29. const vpx_prob *context_tree;
  30. int16_t token;
  31. EXTRABIT extra;
  32. } TOKENEXTRA;
  33. extern const vpx_tree_index vp9_coef_tree[];
  34. extern const vpx_tree_index vp9_coef_con_tree[];
  35. extern const struct vp9_token vp9_coef_encodings[];
  36. int vp9_is_skippable_in_plane(MACROBLOCK *x, BLOCK_SIZE bsize, int plane);
  37. int vp9_has_high_freq_in_plane(MACROBLOCK *x, BLOCK_SIZE bsize, int plane);
  38. struct VP9_COMP;
  39. struct ThreadData;
  40. void vp9_tokenize_sb(struct VP9_COMP *cpi, struct ThreadData *td,
  41. TOKENEXTRA **t, int dry_run, int seg_skip,
  42. BLOCK_SIZE bsize);
  43. typedef struct {
  44. const vpx_prob *prob;
  45. int len;
  46. int base_val;
  47. const int16_t *cost;
  48. } vp9_extra_bit;
  49. // indexed by token value
  50. extern const vp9_extra_bit vp9_extra_bits[ENTROPY_TOKENS];
  51. #if CONFIG_VP9_HIGHBITDEPTH
  52. extern const vp9_extra_bit vp9_extra_bits_high10[ENTROPY_TOKENS];
  53. extern const vp9_extra_bit vp9_extra_bits_high12[ENTROPY_TOKENS];
  54. #endif // CONFIG_VP9_HIGHBITDEPTH
  55. extern const int16_t *vp9_dct_value_cost_ptr;
  56. /* TODO: The Token field should be broken out into a separate char array to
  57. * improve cache locality, since it's needed for costing when the rest of the
  58. * fields are not.
  59. */
  60. extern const TOKENVALUE *vp9_dct_value_tokens_ptr;
  61. extern const TOKENVALUE *vp9_dct_cat_lt_10_value_tokens;
  62. extern const int *vp9_dct_cat_lt_10_value_cost;
  63. extern const int16_t vp9_cat6_low_cost[256];
  64. extern const int vp9_cat6_high_cost[64];
  65. extern const int vp9_cat6_high10_high_cost[256];
  66. extern const int vp9_cat6_high12_high_cost[1024];
  67. static INLINE int vp9_get_cost(int16_t token, EXTRABIT extrabits,
  68. const int *cat6_high_table) {
  69. if (token != CATEGORY6_TOKEN)
  70. return vp9_extra_bits[token].cost[extrabits >> 1];
  71. return vp9_cat6_low_cost[(extrabits >> 1) & 0xff] +
  72. cat6_high_table[extrabits >> 9];
  73. }
  74. #if CONFIG_VP9_HIGHBITDEPTH
  75. static INLINE const int *vp9_get_high_cost_table(int bit_depth) {
  76. return bit_depth == 8 ? vp9_cat6_high_cost
  77. : (bit_depth == 10 ? vp9_cat6_high10_high_cost
  78. : vp9_cat6_high12_high_cost);
  79. }
  80. #else
  81. static INLINE const int *vp9_get_high_cost_table(int bit_depth) {
  82. (void)bit_depth;
  83. return vp9_cat6_high_cost;
  84. }
  85. #endif // CONFIG_VP9_HIGHBITDEPTH
  86. static INLINE void vp9_get_token_extra(int v, int16_t *token, EXTRABIT *extra) {
  87. if (v >= CAT6_MIN_VAL || v <= -CAT6_MIN_VAL) {
  88. *token = CATEGORY6_TOKEN;
  89. if (v >= CAT6_MIN_VAL)
  90. *extra = 2 * v - 2 * CAT6_MIN_VAL;
  91. else
  92. *extra = -2 * v - 2 * CAT6_MIN_VAL + 1;
  93. return;
  94. }
  95. *token = vp9_dct_cat_lt_10_value_tokens[v].token;
  96. *extra = vp9_dct_cat_lt_10_value_tokens[v].extra;
  97. }
  98. static INLINE int16_t vp9_get_token(int v) {
  99. if (v >= CAT6_MIN_VAL || v <= -CAT6_MIN_VAL) return 10;
  100. return vp9_dct_cat_lt_10_value_tokens[v].token;
  101. }
  102. static INLINE int vp9_get_token_cost(int v, int16_t *token,
  103. const int *cat6_high_table) {
  104. if (v >= CAT6_MIN_VAL || v <= -CAT6_MIN_VAL) {
  105. EXTRABIT extrabits;
  106. *token = CATEGORY6_TOKEN;
  107. extrabits = abs(v) - CAT6_MIN_VAL;
  108. return vp9_cat6_low_cost[extrabits & 0xff] +
  109. cat6_high_table[extrabits >> 8];
  110. }
  111. *token = vp9_dct_cat_lt_10_value_tokens[v].token;
  112. return vp9_dct_cat_lt_10_value_cost[v];
  113. }
  114. #ifdef __cplusplus
  115. } // extern "C"
  116. #endif
  117. #endif // VP9_ENCODER_VP9_TOKENIZE_H_