vp9_tokenize.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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_VP9_ENCODER_VP9_TOKENIZE_H_
  11. #define VPX_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 uint16_t vp9_cat6_high_cost[64];
  65. extern const uint16_t vp9_cat6_high10_high_cost[256];
  66. extern const uint16_t vp9_cat6_high12_high_cost[1024];
  67. #if CONFIG_VP9_HIGHBITDEPTH
  68. static INLINE const uint16_t *vp9_get_high_cost_table(int bit_depth) {
  69. return bit_depth == 8 ? vp9_cat6_high_cost
  70. : (bit_depth == 10 ? vp9_cat6_high10_high_cost
  71. : vp9_cat6_high12_high_cost);
  72. }
  73. #else
  74. static INLINE const uint16_t *vp9_get_high_cost_table(int bit_depth) {
  75. (void)bit_depth;
  76. return vp9_cat6_high_cost;
  77. }
  78. #endif // CONFIG_VP9_HIGHBITDEPTH
  79. static INLINE void vp9_get_token_extra(int v, int16_t *token, EXTRABIT *extra) {
  80. if (v >= CAT6_MIN_VAL || v <= -CAT6_MIN_VAL) {
  81. *token = CATEGORY6_TOKEN;
  82. if (v >= CAT6_MIN_VAL)
  83. *extra = 2 * v - 2 * CAT6_MIN_VAL;
  84. else
  85. *extra = -2 * v - 2 * CAT6_MIN_VAL + 1;
  86. return;
  87. }
  88. *token = vp9_dct_cat_lt_10_value_tokens[v].token;
  89. *extra = vp9_dct_cat_lt_10_value_tokens[v].extra;
  90. }
  91. static INLINE int16_t vp9_get_token(int v) {
  92. if (v >= CAT6_MIN_VAL || v <= -CAT6_MIN_VAL) return 10;
  93. return vp9_dct_cat_lt_10_value_tokens[v].token;
  94. }
  95. static INLINE int vp9_get_token_cost(int v, int16_t *token,
  96. const uint16_t *cat6_high_table) {
  97. if (v >= CAT6_MIN_VAL || v <= -CAT6_MIN_VAL) {
  98. EXTRABIT extrabits;
  99. *token = CATEGORY6_TOKEN;
  100. extrabits = abs(v) - CAT6_MIN_VAL;
  101. return vp9_cat6_low_cost[extrabits & 0xff] +
  102. cat6_high_table[extrabits >> 8];
  103. }
  104. *token = vp9_dct_cat_lt_10_value_tokens[v].token;
  105. return vp9_dct_cat_lt_10_value_cost[v];
  106. }
  107. #ifdef __cplusplus
  108. } // extern "C"
  109. #endif
  110. #endif // VPX_VP9_ENCODER_VP9_TOKENIZE_H_