entropymode.h 10.2 KB
Newer Older
Jingning Han's avatar
Jingning Han committed
1 2 3 4 5 6 7 8 9 10
/*
 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

11 12
#ifndef VP10_COMMON_ENTROPYMODE_H_
#define VP10_COMMON_ENTROPYMODE_H_
Jingning Han's avatar
Jingning Han committed
13

14 15 16 17 18
#include "av1/common/entropy.h"
#include "av1/common/entropymv.h"
#include "av1/common/filter.h"
#include "av1/common/seg_common.h"
#include "aom_dsp/vpx_filter.h"
Jingning Han's avatar
Jingning Han committed
19 20 21 22 23 24 25 26 27

#ifdef __cplusplus
extern "C" {
#endif

#define BLOCK_SIZE_GROUPS 4

#define TX_SIZE_CONTEXTS 2

clang-format's avatar
clang-format committed
28
#define INTER_OFFSET(mode) ((mode)-NEARESTMV)
29
#if CONFIG_EXT_INTER
clang-format's avatar
clang-format committed
30
#define INTER_COMPOUND_OFFSET(mode) ((mode)-NEAREST_NEARESTMV)
31
#endif  // CONFIG_EXT_INTER
Jingning Han's avatar
Jingning Han committed
32

hui su's avatar
hui su committed
33 34
#define PALETTE_COLOR_CONTEXTS 16
#define PALETTE_MAX_SIZE 8
35
#define PALETTE_BLOCK_SIZES (BLOCK_LARGEST - BLOCK_8X8 + 1)
hui su's avatar
hui su committed
36
#define PALETTE_Y_MODE_CONTEXTS 3
37
#define PALETTE_MAX_BLOCK_SIZE (64 * 64)
hui su's avatar
hui su committed
38

Yaowu Xu's avatar
Yaowu Xu committed
39
struct VP10Common;
Jingning Han's avatar
Jingning Han committed
40

41 42 43 44 45 46
struct seg_counts {
  unsigned int tree_total[MAX_SEGMENTS];
  unsigned int tree_mispred[MAX_SEGMENTS];
  unsigned int pred[PREDICTION_PROBS][2];
};

Jingning Han's avatar
Jingning Han committed
47 48 49
typedef struct frame_contexts {
  vpx_prob y_mode_prob[BLOCK_SIZE_GROUPS][INTRA_MODES - 1];
  vpx_prob uv_mode_prob[INTRA_MODES][INTRA_MODES - 1];
50 51 52
#if CONFIG_EXT_PARTITION_TYPES
  vpx_prob partition_prob[PARTITION_CONTEXTS][EXT_PARTITION_TYPES - 1];
#else
Jingning Han's avatar
Jingning Han committed
53
  vpx_prob partition_prob[PARTITION_CONTEXTS][PARTITION_TYPES - 1];
54
#endif
Jingning Han's avatar
Jingning Han committed
55
  vp10_coeff_probs_model coef_probs[TX_SIZES][PLANE_TYPES];
56 57 58
#if CONFIG_ANS
  coeff_cdf_model coef_cdfs[TX_SIZES][PLANE_TYPES];
#endif
clang-format's avatar
clang-format committed
59 60 61
  vpx_prob
      switchable_interp_prob[SWITCHABLE_FILTER_CONTEXTS][SWITCHABLE_FILTERS -
                                                         1];
62 63 64 65 66

#if CONFIG_REF_MV
  vpx_prob newmv_prob[NEWMV_MODE_CONTEXTS];
  vpx_prob zeromv_prob[ZEROMV_MODE_CONTEXTS];
  vpx_prob refmv_prob[REFMV_MODE_CONTEXTS];
67
  vpx_prob drl_prob[DRL_MODE_CONTEXTS];
68

Yue Chen's avatar
Yue Chen committed
69 70 71
#if CONFIG_EXT_INTER
  vpx_prob new2mv_prob;
#endif  // CONFIG_EXT_INTER
72
#endif  // CONFIG_REF_MV
73

Jingning Han's avatar
Jingning Han committed
74
  vpx_prob inter_mode_probs[INTER_MODE_CONTEXTS][INTER_MODES - 1];
75
#if CONFIG_EXT_INTER
clang-format's avatar
clang-format committed
76 77
  vpx_prob
      inter_compound_mode_probs[INTER_MODE_CONTEXTS][INTER_COMPOUND_MODES - 1];
78
  vpx_prob interintra_prob[BLOCK_SIZE_GROUPS];
79
  vpx_prob interintra_mode_prob[BLOCK_SIZE_GROUPS][INTERINTRA_MODES - 1];
80 81
  vpx_prob wedge_interintra_prob[BLOCK_SIZES];
  vpx_prob wedge_interinter_prob[BLOCK_SIZES];
82
#endif  // CONFIG_EXT_INTER
83 84 85
#if CONFIG_OBMC || CONFIG_WARPED_MOTION
  vpx_prob motvar_prob[BLOCK_SIZES][MOTION_VARIATIONS - 1];
#endif  // CONFIG_OBMC || CONFIG_WARPED_MOTION
Jingning Han's avatar
Jingning Han committed
86 87
  vpx_prob intra_inter_prob[INTRA_INTER_CONTEXTS];
  vpx_prob comp_inter_prob[COMP_INTER_CONTEXTS];
clang-format's avatar
clang-format committed
88
  vpx_prob single_ref_prob[REF_CONTEXTS][SINGLE_REFS - 1];
89
#if CONFIG_EXT_REFS
clang-format's avatar
clang-format committed
90 91
  vpx_prob comp_ref_prob[REF_CONTEXTS][FWD_REFS - 1];
  vpx_prob comp_bwdref_prob[REF_CONTEXTS][BWD_REFS - 1];
92
#else
clang-format's avatar
clang-format committed
93
  vpx_prob comp_ref_prob[REF_CONTEXTS][COMP_REFS - 1];
94
#endif  // CONFIG_EXT_REFS
95
  vpx_prob tx_size_probs[TX_SIZES - 1][TX_SIZE_CONTEXTS][TX_SIZES - 1];
96 97 98
#if CONFIG_VAR_TX
  vpx_prob txfm_partition_prob[TXFM_PARTITION_CONTEXTS];
#endif
Jingning Han's avatar
Jingning Han committed
99
  vpx_prob skip_probs[SKIP_CONTEXTS];
100 101 102
#if CONFIG_REF_MV
  nmv_context nmvc[NMV_CONTEXTS];
#else
Jingning Han's avatar
Jingning Han committed
103
  nmv_context nmvc;
104
#endif
hui su's avatar
hui su committed
105
  int initialized;
106
#if CONFIG_EXT_TX
107
  vpx_prob inter_ext_tx_prob[EXT_TX_SETS_INTER][EXT_TX_SIZES][TX_TYPES - 1];
clang-format's avatar
clang-format committed
108 109 110
  vpx_prob
      intra_ext_tx_prob[EXT_TX_SETS_INTRA][EXT_TX_SIZES][INTRA_MODES][TX_TYPES -
                                                                      1];
111
#else
112 113
  vpx_prob intra_ext_tx_prob[EXT_TX_SIZES][TX_TYPES][TX_TYPES - 1];
  vpx_prob inter_ext_tx_prob[EXT_TX_SIZES][TX_TYPES - 1];
114
#endif  // CONFIG_EXT_TX
115 116 117
#if CONFIG_SUPERTX
  vpx_prob supertx_prob[PARTITION_SUPERTX_CONTEXTS][TX_SIZES];
#endif  // CONFIG_SUPERTX
118
  struct segmentation_probs seg;
hui su's avatar
hui su committed
119 120
#if CONFIG_EXT_INTRA
  vpx_prob ext_intra_probs[PLANE_TYPES];
121
  vpx_prob intra_filter_probs[INTRA_FILTERS + 1][INTRA_FILTERS - 1];
hui su's avatar
hui su committed
122
#endif  // CONFIG_EXT_INTRA
123 124 125
#if CONFIG_GLOBAL_MOTION
  vpx_prob global_motion_types_prob[GLOBAL_MOTION_TYPES - 1];
#endif  // CONFIG_GLOBAL_MOTION
Jingning Han's avatar
Jingning Han committed
126 127 128
} FRAME_CONTEXT;

typedef struct FRAME_COUNTS {
129 130
  // Note: This structure should only contain 'unsigned int' fields, or
  // aggregates built solely from 'unsigned int' fields/elements
131
  unsigned int kf_y_mode[INTRA_MODES][INTRA_MODES][INTRA_MODES];
Jingning Han's avatar
Jingning Han committed
132 133
  unsigned int y_mode[BLOCK_SIZE_GROUPS][INTRA_MODES];
  unsigned int uv_mode[INTRA_MODES][INTRA_MODES];
134 135 136
#if CONFIG_EXT_PARTITION_TYPES
  unsigned int partition[PARTITION_CONTEXTS][EXT_PARTITION_TYPES];
#else
Jingning Han's avatar
Jingning Han committed
137
  unsigned int partition[PARTITION_CONTEXTS][PARTITION_TYPES];
138
#endif
Jingning Han's avatar
Jingning Han committed
139
  vp10_coeff_count_model coef[TX_SIZES][PLANE_TYPES];
clang-format's avatar
clang-format committed
140 141 142 143
  unsigned int
      eob_branch[TX_SIZES][PLANE_TYPES][REF_TYPES][COEF_BANDS][COEFF_CONTEXTS];
  unsigned int
      switchable_interp[SWITCHABLE_FILTER_CONTEXTS][SWITCHABLE_FILTERS];
144 145 146 147
#if CONFIG_REF_MV
  unsigned int newmv_mode[NEWMV_MODE_CONTEXTS][2];
  unsigned int zeromv_mode[ZEROMV_MODE_CONTEXTS][2];
  unsigned int refmv_mode[REFMV_MODE_CONTEXTS][2];
148
  unsigned int drl_mode[DRL_MODE_CONTEXTS][2];
Yue Chen's avatar
Yue Chen committed
149 150 151
#if CONFIG_EXT_INTER
  unsigned int new2mv_mode[2];
#endif  // CONFIG_EXT_INTER
152 153
#endif

Jingning Han's avatar
Jingning Han committed
154
  unsigned int inter_mode[INTER_MODE_CONTEXTS][INTER_MODES];
155 156
#if CONFIG_EXT_INTER
  unsigned int inter_compound_mode[INTER_MODE_CONTEXTS][INTER_COMPOUND_MODES];
157
  unsigned int interintra[BLOCK_SIZE_GROUPS][2];
158
  unsigned int interintra_mode[BLOCK_SIZE_GROUPS][INTERINTRA_MODES];
159 160
  unsigned int wedge_interintra[BLOCK_SIZES][2];
  unsigned int wedge_interinter[BLOCK_SIZES][2];
161
#endif  // CONFIG_EXT_INTER
162 163 164
#if CONFIG_OBMC || CONFIG_WARPED_MOTION
  unsigned int motvar[BLOCK_SIZES][MOTION_VARIATIONS];
#endif  // CONFIG_OBMC || CONFIG_WARPED_MOTION
Jingning Han's avatar
Jingning Han committed
165 166
  unsigned int intra_inter[INTRA_INTER_CONTEXTS][2];
  unsigned int comp_inter[COMP_INTER_CONTEXTS][2];
clang-format's avatar
clang-format committed
167
  unsigned int single_ref[REF_CONTEXTS][SINGLE_REFS - 1][2];
168
#if CONFIG_EXT_REFS
clang-format's avatar
clang-format committed
169 170
  unsigned int comp_ref[REF_CONTEXTS][FWD_REFS - 1][2];
  unsigned int comp_bwdref[REF_CONTEXTS][BWD_REFS - 1][2];
171
#else
clang-format's avatar
clang-format committed
172
  unsigned int comp_ref[REF_CONTEXTS][COMP_REFS - 1][2];
173
#endif  // CONFIG_EXT_REFS
174 175 176
  // TODO(any): tx_size_totals is only used by the encoder to decide whether
  // to use forward updates for the coeff probs, and as such it does not really
  // belong into this structure.
177 178
  unsigned int tx_size_totals[TX_SIZES];
  unsigned int tx_size[TX_SIZES - 1][TX_SIZE_CONTEXTS][TX_SIZES];
179 180 181
#if CONFIG_VAR_TX
  unsigned int txfm_partition[TXFM_PARTITION_CONTEXTS][2];
#endif
Jingning Han's avatar
Jingning Han committed
182
  unsigned int skip[SKIP_CONTEXTS][2];
183 184 185
#if CONFIG_REF_MV
  nmv_context_counts mv[NMV_CONTEXTS];
#else
Jingning Han's avatar
Jingning Han committed
186
  nmv_context_counts mv;
187
#endif
188
#if CONFIG_EXT_TX
Debargha Mukherjee's avatar
Debargha Mukherjee committed
189 190 191
#if CONFIG_RECT_TX
  unsigned int tx_size_implied[TX_SIZES][TX_SIZES];
#endif  // CONFIG_RECT_TX
192
  unsigned int inter_ext_tx[EXT_TX_SETS_INTER][EXT_TX_SIZES][TX_TYPES];
clang-format's avatar
clang-format committed
193 194
  unsigned int
      intra_ext_tx[EXT_TX_SETS_INTRA][EXT_TX_SIZES][INTRA_MODES][TX_TYPES];
195
#else
196 197
  unsigned int intra_ext_tx[EXT_TX_SIZES][TX_TYPES][TX_TYPES];
  unsigned int inter_ext_tx[EXT_TX_SIZES][TX_TYPES];
198
#endif  // CONFIG_EXT_TX
199 200 201 202
#if CONFIG_SUPERTX
  unsigned int supertx[PARTITION_SUPERTX_CONTEXTS][TX_SIZES][2];
  unsigned int supertx_size[TX_SIZES];
#endif  // CONFIG_SUPERTX
203
  struct seg_counts seg;
hui su's avatar
hui su committed
204 205
#if CONFIG_EXT_INTRA
  unsigned int ext_intra[PLANE_TYPES][2];
206
  unsigned int intra_filter[INTRA_FILTERS + 1][INTRA_FILTERS];
hui su's avatar
hui su committed
207
#endif  // CONFIG_EXT_INTRA
Jingning Han's avatar
Jingning Han committed
208 209
} FRAME_COUNTS;

hui su's avatar
hui su committed
210
extern const vpx_prob
clang-format's avatar
clang-format committed
211 212 213
    vp10_kf_y_mode_prob[INTRA_MODES][INTRA_MODES][INTRA_MODES - 1];
extern const vpx_prob vp10_default_palette_y_mode_prob[PALETTE_BLOCK_SIZES]
                                                      [PALETTE_Y_MODE_CONTEXTS];
214
extern const vpx_prob vp10_default_palette_uv_mode_prob[2];
hui su's avatar
hui su committed
215
extern const vpx_prob
clang-format's avatar
clang-format committed
216
    vp10_default_palette_y_size_prob[PALETTE_BLOCK_SIZES][PALETTE_SIZES - 1];
hui su's avatar
hui su committed
217
extern const vpx_prob
clang-format's avatar
clang-format committed
218
    vp10_default_palette_uv_size_prob[PALETTE_BLOCK_SIZES][PALETTE_SIZES - 1];
hui su's avatar
hui su committed
219
extern const vpx_prob vp10_default_palette_y_color_prob
clang-format's avatar
clang-format committed
220
    [PALETTE_MAX_SIZE - 1][PALETTE_COLOR_CONTEXTS][PALETTE_COLORS - 1];
hui su's avatar
hui su committed
221
extern const vpx_prob vp10_default_palette_uv_color_prob
clang-format's avatar
clang-format committed
222
    [PALETTE_MAX_SIZE - 1][PALETTE_COLOR_CONTEXTS][PALETTE_COLORS - 1];
hui su's avatar
hui su committed
223

Jingning Han's avatar
Jingning Han committed
224 225
extern const vpx_tree_index vp10_intra_mode_tree[TREE_SIZE(INTRA_MODES)];
extern const vpx_tree_index vp10_inter_mode_tree[TREE_SIZE(INTER_MODES)];
226
#if CONFIG_EXT_INTER
clang-format's avatar
clang-format committed
227 228 229 230
extern const vpx_tree_index
    vp10_interintra_mode_tree[TREE_SIZE(INTERINTRA_MODES)];
extern const vpx_tree_index
    vp10_inter_compound_mode_tree[TREE_SIZE(INTER_COMPOUND_MODES)];
231
#endif  // CONFIG_EXT_INTER
Jingning Han's avatar
Jingning Han committed
232
extern const vpx_tree_index vp10_partition_tree[TREE_SIZE(PARTITION_TYPES)];
233
#if CONFIG_EXT_PARTITION_TYPES
clang-format's avatar
clang-format committed
234 235
extern const vpx_tree_index
    vp10_ext_partition_tree[TREE_SIZE(EXT_PARTITION_TYPES)];
236
#endif
clang-format's avatar
clang-format committed
237 238
extern const vpx_tree_index
    vp10_switchable_interp_tree[TREE_SIZE(SWITCHABLE_FILTERS)];
hui su's avatar
hui su committed
239 240
extern const vpx_tree_index vp10_palette_size_tree[TREE_SIZE(PALETTE_SIZES)];
extern const vpx_tree_index
clang-format's avatar
clang-format committed
241
    vp10_palette_color_tree[PALETTE_MAX_SIZE - 1][TREE_SIZE(PALETTE_COLORS)];
242
extern const vpx_tree_index
clang-format's avatar
clang-format committed
243
    vp10_tx_size_tree[TX_SIZES - 1][TREE_SIZE(TX_SIZES)];
244 245 246 247 248 249 250 251 252
#if CONFIG_EXT_INTRA
extern const vpx_tree_index vp10_intra_filter_tree[TREE_SIZE(INTRA_FILTERS)];
#endif  // CONFIG_EXT_INTRA
#if CONFIG_EXT_TX
extern const vpx_tree_index
    vp10_ext_tx_inter_tree[EXT_TX_SETS_INTER][TREE_SIZE(TX_TYPES)];
extern const vpx_tree_index
    vp10_ext_tx_intra_tree[EXT_TX_SETS_INTRA][TREE_SIZE(TX_TYPES)];
#else
clang-format's avatar
clang-format committed
253
extern const vpx_tree_index vp10_ext_tx_tree[TREE_SIZE(TX_TYPES)];
254
#endif  // CONFIG_EXT_TX
255 256 257
#if CONFIG_OBMC || CONFIG_WARPED_MOTION
extern const vpx_tree_index vp10_motvar_tree[TREE_SIZE(MOTION_VARIATIONS)];
#endif  // CONFIG_OBMC || CONFIG_WARPED_MOTION
Jingning Han's avatar
Jingning Han committed
258

Yaowu Xu's avatar
Yaowu Xu committed
259
void vp10_setup_past_independence(struct VP10Common *cm);
Jingning Han's avatar
Jingning Han committed
260

261 262
void vp10_adapt_intra_frame_probs(struct VP10Common *cm);
void vp10_adapt_inter_frame_probs(struct VP10Common *cm);
Jingning Han's avatar
Jingning Han committed
263

hui su's avatar
hui su committed
264 265 266 267 268 269 270 271 272
static INLINE int vp10_ceil_log2(int n) {
  int i = 1, p = 2;
  while (p < n) {
    i++;
    p = p << 1;
  }
  return i;
}

clang-format's avatar
clang-format committed
273 274
int vp10_get_palette_color_context(const uint8_t *color_map, int cols, int r,
                                   int c, int n, int *color_order);
hui su's avatar
hui su committed
275

Jingning Han's avatar
Jingning Han committed
276 277 278 279
#ifdef __cplusplus
}  // extern "C"
#endif

280
#endif  // VP10_COMMON_ENTROPYMODE_H_