vp9_entropymv.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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_COMMON_VP9_ENTROPYMV_H_
  11. #define VP9_COMMON_VP9_ENTROPYMV_H_
  12. #include "./vpx_config.h"
  13. #include "vpx_dsp/prob.h"
  14. #include "vp9/common/vp9_mv.h"
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. struct VP9Common;
  19. void vp9_init_mv_probs(struct VP9Common *cm);
  20. void vp9_adapt_mv_probs(struct VP9Common *cm, int usehp);
  21. // Integer pel reference mv threshold for use of high-precision 1/8 mv
  22. #define COMPANDED_MVREF_THRESH 8
  23. static INLINE int use_mv_hp(const MV *ref) {
  24. return (abs(ref->row) >> 3) < COMPANDED_MVREF_THRESH &&
  25. (abs(ref->col) >> 3) < COMPANDED_MVREF_THRESH;
  26. }
  27. #define MV_UPDATE_PROB 252
  28. /* Symbols for coding which components are zero jointly */
  29. #define MV_JOINTS 4
  30. typedef enum {
  31. MV_JOINT_ZERO = 0, /* Zero vector */
  32. MV_JOINT_HNZVZ = 1, /* Vert zero, hor nonzero */
  33. MV_JOINT_HZVNZ = 2, /* Hor zero, vert nonzero */
  34. MV_JOINT_HNZVNZ = 3, /* Both components nonzero */
  35. } MV_JOINT_TYPE;
  36. static INLINE int mv_joint_vertical(MV_JOINT_TYPE type) {
  37. return type == MV_JOINT_HZVNZ || type == MV_JOINT_HNZVNZ;
  38. }
  39. static INLINE int mv_joint_horizontal(MV_JOINT_TYPE type) {
  40. return type == MV_JOINT_HNZVZ || type == MV_JOINT_HNZVNZ;
  41. }
  42. /* Symbols for coding magnitude class of nonzero components */
  43. #define MV_CLASSES 11
  44. typedef enum {
  45. MV_CLASS_0 = 0, /* (0, 2] integer pel */
  46. MV_CLASS_1 = 1, /* (2, 4] integer pel */
  47. MV_CLASS_2 = 2, /* (4, 8] integer pel */
  48. MV_CLASS_3 = 3, /* (8, 16] integer pel */
  49. MV_CLASS_4 = 4, /* (16, 32] integer pel */
  50. MV_CLASS_5 = 5, /* (32, 64] integer pel */
  51. MV_CLASS_6 = 6, /* (64, 128] integer pel */
  52. MV_CLASS_7 = 7, /* (128, 256] integer pel */
  53. MV_CLASS_8 = 8, /* (256, 512] integer pel */
  54. MV_CLASS_9 = 9, /* (512, 1024] integer pel */
  55. MV_CLASS_10 = 10, /* (1024,2048] integer pel */
  56. } MV_CLASS_TYPE;
  57. #define CLASS0_BITS 1 /* bits at integer precision for class 0 */
  58. #define CLASS0_SIZE (1 << CLASS0_BITS)
  59. #define MV_OFFSET_BITS (MV_CLASSES + CLASS0_BITS - 2)
  60. #define MV_FP_SIZE 4
  61. #define MV_MAX_BITS (MV_CLASSES + CLASS0_BITS + 2)
  62. #define MV_MAX ((1 << MV_MAX_BITS) - 1)
  63. #define MV_VALS ((MV_MAX << 1) + 1)
  64. #define MV_IN_USE_BITS 14
  65. #define MV_UPP ((1 << MV_IN_USE_BITS) - 1)
  66. #define MV_LOW (-(1 << MV_IN_USE_BITS))
  67. extern const vpx_tree_index vp9_mv_joint_tree[];
  68. extern const vpx_tree_index vp9_mv_class_tree[];
  69. extern const vpx_tree_index vp9_mv_class0_tree[];
  70. extern const vpx_tree_index vp9_mv_fp_tree[];
  71. typedef struct {
  72. vpx_prob sign;
  73. vpx_prob classes[MV_CLASSES - 1];
  74. vpx_prob class0[CLASS0_SIZE - 1];
  75. vpx_prob bits[MV_OFFSET_BITS];
  76. vpx_prob class0_fp[CLASS0_SIZE][MV_FP_SIZE - 1];
  77. vpx_prob fp[MV_FP_SIZE - 1];
  78. vpx_prob class0_hp;
  79. vpx_prob hp;
  80. } nmv_component;
  81. typedef struct {
  82. vpx_prob joints[MV_JOINTS - 1];
  83. nmv_component comps[2];
  84. } nmv_context;
  85. static INLINE MV_JOINT_TYPE vp9_get_mv_joint(const MV *mv) {
  86. if (mv->row == 0) {
  87. return mv->col == 0 ? MV_JOINT_ZERO : MV_JOINT_HNZVZ;
  88. } else {
  89. return mv->col == 0 ? MV_JOINT_HZVNZ : MV_JOINT_HNZVNZ;
  90. }
  91. }
  92. MV_CLASS_TYPE vp9_get_mv_class(int z, int *offset);
  93. typedef struct {
  94. unsigned int sign[2];
  95. unsigned int classes[MV_CLASSES];
  96. unsigned int class0[CLASS0_SIZE];
  97. unsigned int bits[MV_OFFSET_BITS][2];
  98. unsigned int class0_fp[CLASS0_SIZE][MV_FP_SIZE];
  99. unsigned int fp[MV_FP_SIZE];
  100. unsigned int class0_hp[2];
  101. unsigned int hp[2];
  102. } nmv_component_counts;
  103. typedef struct {
  104. unsigned int joints[MV_JOINTS];
  105. nmv_component_counts comps[2];
  106. } nmv_context_counts;
  107. void vp9_inc_mv(const MV *mv, nmv_context_counts *mvctx);
  108. #ifdef __cplusplus
  109. } // extern "C"
  110. #endif
  111. #endif // VP9_COMMON_VP9_ENTROPYMV_H_