]> granicus.if.org Git - libvpx/blob - vp10/common/entropymode.h
vp10: make segmentation probs use generic probability model.
[libvpx] / vp10 / common / entropymode.h
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 #ifndef VP10_COMMON_ENTROPYMODE_H_
12 #define VP10_COMMON_ENTROPYMODE_H_
13
14 #include "vp10/common/entropy.h"
15 #include "vp10/common/entropymv.h"
16 #include "vp10/common/filter.h"
17 #include "vp10/common/seg_common.h"
18 #include "vpx_dsp/vpx_filter.h"
19
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23
24 #define BLOCK_SIZE_GROUPS 4
25
26 #define TX_SIZE_CONTEXTS 2
27
28 #define INTER_OFFSET(mode) ((mode) - NEARESTMV)
29
30 #define PALETTE_COLOR_CONTEXTS 16
31 #define PALETTE_MAX_SIZE 8
32 #define PALETTE_BLOCK_SIZES (BLOCK_64X64 - BLOCK_8X8 + 1)
33 #define PALETTE_Y_MODE_CONTEXTS 3
34
35
36 struct VP10Common;
37
38 struct tx_probs {
39   vpx_prob p32x32[TX_SIZE_CONTEXTS][TX_SIZES - 1];
40   vpx_prob p16x16[TX_SIZE_CONTEXTS][TX_SIZES - 2];
41   vpx_prob p8x8[TX_SIZE_CONTEXTS][TX_SIZES - 3];
42 };
43
44 struct tx_counts {
45   unsigned int p32x32[TX_SIZE_CONTEXTS][TX_SIZES];
46   unsigned int p16x16[TX_SIZE_CONTEXTS][TX_SIZES - 1];
47   unsigned int p8x8[TX_SIZE_CONTEXTS][TX_SIZES - 2];
48   unsigned int tx_totals[TX_SIZES];
49 };
50
51 struct seg_counts {
52   unsigned int tree_total[MAX_SEGMENTS];
53   unsigned int tree_mispred[MAX_SEGMENTS];
54   unsigned int pred[PREDICTION_PROBS][2];
55 };
56
57 typedef struct frame_contexts {
58   vpx_prob y_mode_prob[BLOCK_SIZE_GROUPS][INTRA_MODES - 1];
59   vpx_prob uv_mode_prob[INTRA_MODES][INTRA_MODES - 1];
60   vpx_prob partition_prob[PARTITION_CONTEXTS][PARTITION_TYPES - 1];
61   vp10_coeff_probs_model coef_probs[TX_SIZES][PLANE_TYPES];
62   vpx_prob switchable_interp_prob[SWITCHABLE_FILTER_CONTEXTS]
63                                  [SWITCHABLE_FILTERS - 1];
64   vpx_prob inter_mode_probs[INTER_MODE_CONTEXTS][INTER_MODES - 1];
65   vpx_prob intra_inter_prob[INTRA_INTER_CONTEXTS];
66   vpx_prob comp_inter_prob[COMP_INTER_CONTEXTS];
67   vpx_prob single_ref_prob[REF_CONTEXTS][2];
68   vpx_prob comp_ref_prob[REF_CONTEXTS];
69   struct tx_probs tx_probs;
70   vpx_prob skip_probs[SKIP_CONTEXTS];
71   nmv_context nmvc;
72 #if CONFIG_MISC_FIXES
73   struct segmentation_probs seg;
74 #endif
75   int initialized;
76 } FRAME_CONTEXT;
77
78 typedef struct FRAME_COUNTS {
79   unsigned int y_mode[BLOCK_SIZE_GROUPS][INTRA_MODES];
80   unsigned int uv_mode[INTRA_MODES][INTRA_MODES];
81   unsigned int partition[PARTITION_CONTEXTS][PARTITION_TYPES];
82   vp10_coeff_count_model coef[TX_SIZES][PLANE_TYPES];
83   unsigned int eob_branch[TX_SIZES][PLANE_TYPES][REF_TYPES]
84                          [COEF_BANDS][COEFF_CONTEXTS];
85   unsigned int switchable_interp[SWITCHABLE_FILTER_CONTEXTS]
86                                 [SWITCHABLE_FILTERS];
87   unsigned int inter_mode[INTER_MODE_CONTEXTS][INTER_MODES];
88   unsigned int intra_inter[INTRA_INTER_CONTEXTS][2];
89   unsigned int comp_inter[COMP_INTER_CONTEXTS][2];
90   unsigned int single_ref[REF_CONTEXTS][2][2];
91   unsigned int comp_ref[REF_CONTEXTS][2];
92   struct tx_counts tx;
93   unsigned int skip[SKIP_CONTEXTS][2];
94   nmv_context_counts mv;
95 #if CONFIG_MISC_FIXES
96   struct seg_counts seg;
97 #endif
98 } FRAME_COUNTS;
99
100 extern const vpx_prob vp10_kf_uv_mode_prob[INTRA_MODES][INTRA_MODES - 1];
101 extern const vpx_prob vp10_kf_y_mode_prob[INTRA_MODES][INTRA_MODES]
102                                         [INTRA_MODES - 1];
103 extern const vpx_prob vp10_kf_partition_probs[PARTITION_CONTEXTS]
104                                             [PARTITION_TYPES - 1];
105 extern const vpx_prob
106 vp10_default_palette_y_mode_prob[PALETTE_BLOCK_SIZES][PALETTE_Y_MODE_CONTEXTS];
107 extern const vpx_prob
108 vp10_default_palette_y_size_prob[PALETTE_BLOCK_SIZES][PALETTE_SIZES - 1];
109 extern const vpx_prob
110 vp10_default_palette_uv_size_prob[PALETTE_BLOCK_SIZES][PALETTE_SIZES - 1];
111 extern const vpx_prob vp10_default_palette_y_color_prob
112 [PALETTE_MAX_SIZE - 1][PALETTE_COLOR_CONTEXTS][PALETTE_COLORS - 1];
113 extern const vpx_prob vp10_default_palette_uv_color_prob
114 [PALETTE_MAX_SIZE - 1][PALETTE_COLOR_CONTEXTS][PALETTE_COLORS - 1];
115
116 extern const vpx_tree_index vp10_intra_mode_tree[TREE_SIZE(INTRA_MODES)];
117 extern const vpx_tree_index vp10_inter_mode_tree[TREE_SIZE(INTER_MODES)];
118 extern const vpx_tree_index vp10_partition_tree[TREE_SIZE(PARTITION_TYPES)];
119 extern const vpx_tree_index vp10_switchable_interp_tree
120                                 [TREE_SIZE(SWITCHABLE_FILTERS)];
121 extern const vpx_tree_index vp10_palette_size_tree[TREE_SIZE(PALETTE_SIZES)];
122 extern const vpx_tree_index
123 vp10_palette_color_tree[PALETTE_MAX_SIZE - 1][TREE_SIZE(PALETTE_COLORS)];
124
125
126 void vp10_setup_past_independence(struct VP10Common *cm);
127
128 void vp10_adapt_intra_frame_probs(struct VP10Common *cm);
129 void vp10_adapt_inter_frame_probs(struct VP10Common *cm);
130
131 void vp10_tx_counts_to_branch_counts_32x32(const unsigned int *tx_count_32x32p,
132                                       unsigned int (*ct_32x32p)[2]);
133 void vp10_tx_counts_to_branch_counts_16x16(const unsigned int *tx_count_16x16p,
134                                       unsigned int (*ct_16x16p)[2]);
135 void vp10_tx_counts_to_branch_counts_8x8(const unsigned int *tx_count_8x8p,
136                                     unsigned int (*ct_8x8p)[2]);
137
138 static INLINE int vp10_ceil_log2(int n) {
139   int i = 1, p = 2;
140   while (p < n) {
141     i++;
142     p = p << 1;
143   }
144   return i;
145 }
146
147 int vp10_get_palette_color_context(const uint8_t *color_map, int cols,
148                                    int r, int c, int n, int *color_order);
149
150 #ifdef __cplusplus
151 }  // extern "C"
152 #endif
153
154 #endif  // VP10_COMMON_ENTROPYMODE_H_