vp9_entropymv.h 3.9 KB
Newer Older
John Koleszar's avatar
John Koleszar committed
1
/*
2
 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
John Koleszar's avatar
John Koleszar committed
3
 *
4
 *  Use of this source code is governed by a BSD-style license
5
6
 *  that can be found in the LICENSE file in the root of the source
 *  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.
John Koleszar's avatar
John Koleszar committed
9
10
11
 */


12
13
#ifndef VP9_COMMON_VP9_ENTROPYMV_H_
#define VP9_COMMON_VP9_ENTROPYMV_H_
John Koleszar's avatar
John Koleszar committed
14

Jim Bankoski's avatar
Jim Bankoski committed
15
#include "./vpx_config.h"
16
17
18

#include "vp9/common/vp9_mv.h"
#include "vp9/common/vp9_prob.h"
19

20
21
22
23
#ifdef __cplusplus
extern "C" {
#endif

24
struct VP9Common;
25

26
void vp9_init_mv_probs(struct VP9Common *cm);
27

28
29
void vp9_adapt_mv_probs(struct VP9Common *cm, int usehp);
int vp9_use_mv_hp(const MV *ref);
30

31
#define MV_UPDATE_PROB 252
32
33
34
35
36
37
38
39
40
41

/* Symbols for coding which components are zero jointly */
#define MV_JOINTS     4
typedef enum {
  MV_JOINT_ZERO = 0,             /* Zero vector */
  MV_JOINT_HNZVZ = 1,            /* Vert zero, hor nonzero */
  MV_JOINT_HZVNZ = 2,            /* Hor zero, vert nonzero */
  MV_JOINT_HNZVNZ = 3,           /* Both components nonzero */
} MV_JOINT_TYPE;

42
43
44
45
46
47
48
49
static INLINE int mv_joint_vertical(MV_JOINT_TYPE type) {
  return type == MV_JOINT_HZVNZ || type == MV_JOINT_HNZVNZ;
}

static INLINE int mv_joint_horizontal(MV_JOINT_TYPE type) {
  return type == MV_JOINT_HNZVZ || type == MV_JOINT_HNZVNZ;
}

50
/* Symbols for coding magnitude class of nonzero components */
51
#define MV_CLASSES     11
52
53
54
55
56
57
58
59
60
typedef enum {
  MV_CLASS_0 = 0,      /* (0, 2]     integer pel */
  MV_CLASS_1 = 1,      /* (2, 4]     integer pel */
  MV_CLASS_2 = 2,      /* (4, 8]     integer pel */
  MV_CLASS_3 = 3,      /* (8, 16]    integer pel */
  MV_CLASS_4 = 4,      /* (16, 32]   integer pel */
  MV_CLASS_5 = 5,      /* (32, 64]   integer pel */
  MV_CLASS_6 = 6,      /* (64, 128]  integer pel */
  MV_CLASS_7 = 7,      /* (128, 256] integer pel */
61
62
  MV_CLASS_8 = 8,      /* (256, 512] integer pel */
  MV_CLASS_9 = 9,      /* (512, 1024] integer pel */
63
  MV_CLASS_10 = 10,    /* (1024,2048] integer pel */
64
65
66
67
68
} MV_CLASS_TYPE;

#define CLASS0_BITS    1  /* bits at integer precision for class 0 */
#define CLASS0_SIZE    (1 << CLASS0_BITS)
#define MV_OFFSET_BITS (MV_CLASSES + CLASS0_BITS - 2)
Dmitry Kovalev's avatar
Dmitry Kovalev committed
69
#define MV_FP_SIZE 4
70
71
72
73
74

#define MV_MAX_BITS    (MV_CLASSES + CLASS0_BITS + 2)
#define MV_MAX         ((1 << MV_MAX_BITS) - 1)
#define MV_VALS        ((MV_MAX << 1) + 1)

75
76
77
78
#define MV_IN_USE_BITS 14
#define MV_UPP   ((1 << MV_IN_USE_BITS) - 1)
#define MV_LOW   (-(1 << MV_IN_USE_BITS))

79
80
81
82
extern const vp9_tree_index vp9_mv_joint_tree[];
extern const vp9_tree_index vp9_mv_class_tree[];
extern const vp9_tree_index vp9_mv_class0_tree[];
extern const vp9_tree_index vp9_mv_fp_tree[];
83
84

typedef struct {
85
86
87
88
  vp9_prob sign;
  vp9_prob classes[MV_CLASSES - 1];
  vp9_prob class0[CLASS0_SIZE - 1];
  vp9_prob bits[MV_OFFSET_BITS];
Dmitry Kovalev's avatar
Dmitry Kovalev committed
89
90
  vp9_prob class0_fp[CLASS0_SIZE][MV_FP_SIZE - 1];
  vp9_prob fp[MV_FP_SIZE - 1];
91
92
  vp9_prob class0_hp;
  vp9_prob hp;
93
94
95
} nmv_component;

typedef struct {
96
  vp9_prob joints[MV_JOINTS - 1];
97
98
99
  nmv_component comps[2];
} nmv_context;

Ronald S. Bultje's avatar
Ronald S. Bultje committed
100
101
102
103
104
105
106
107
static INLINE MV_JOINT_TYPE vp9_get_mv_joint(const MV *mv) {
  if (mv->row == 0) {
    return mv->col == 0 ? MV_JOINT_ZERO : MV_JOINT_HNZVZ;
  } else {
    return mv->col == 0 ? MV_JOINT_HZVNZ : MV_JOINT_HNZVNZ;
  }
}

108
109
MV_CLASS_TYPE vp9_get_mv_class(int z, int *offset);
int vp9_get_mv_mag(MV_CLASS_TYPE c, int offset);
110
111
112
113
114
115
116


typedef struct {
  unsigned int sign[2];
  unsigned int classes[MV_CLASSES];
  unsigned int class0[CLASS0_SIZE];
  unsigned int bits[MV_OFFSET_BITS][2];
Dmitry Kovalev's avatar
Dmitry Kovalev committed
117
118
  unsigned int class0_fp[CLASS0_SIZE][MV_FP_SIZE];
  unsigned int fp[MV_FP_SIZE];
119
120
121
122
123
124
125
126
127
  unsigned int class0_hp[2];
  unsigned int hp[2];
} nmv_component_counts;

typedef struct {
  unsigned int joints[MV_JOINTS];
  nmv_component_counts comps[2];
} nmv_context_counts;

128
void vp9_inc_mv(const MV *mv, nmv_context_counts *mvctx);
129

130
131
132
133
#ifdef __cplusplus
}  // extern "C"
#endif

134
#endif  // VP9_COMMON_VP9_ENTROPYMV_H_