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