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 VPX_VP9_COMMON_VP9_ENTROPYMODE_H_
12 #define VPX_VP9_COMMON_VP9_ENTROPYMODE_H_
13 
14 #define INLINE __inline
15 
16 #include <stdint.h>
17 #include "vp9_enums.h"
18 #include "vp9_entropy.h"
19 #include "vp9_entropymv.h"
20 #include "vp9_filter.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 #define BLOCK_SIZE_GROUPS 4
27 
28 #define TX_SIZE_CONTEXTS 2
29 
30 #define INTER_OFFSET(mode) ((mode)-NEARESTMV)
31 
32 struct VP9Common;
33 
34 struct tx_probs {
35   vpx_prob p32x32[TX_SIZE_CONTEXTS][TX_SIZES - 1];
36   vpx_prob p16x16[TX_SIZE_CONTEXTS][TX_SIZES - 2];
37   vpx_prob p8x8[TX_SIZE_CONTEXTS][TX_SIZES - 3];
38 };
39 
40 struct tx_counts {
41   unsigned int p32x32[TX_SIZE_CONTEXTS][TX_SIZES];
42   unsigned int p16x16[TX_SIZE_CONTEXTS][TX_SIZES - 1];
43   unsigned int p8x8[TX_SIZE_CONTEXTS][TX_SIZES - 2];
44   unsigned int tx_totals[TX_SIZES];
45 };
46 
47 typedef struct frame_contexts {
48   vpx_prob y_mode_prob[BLOCK_SIZE_GROUPS][INTRA_MODES - 1];
49   vpx_prob uv_mode_prob[INTRA_MODES][INTRA_MODES - 1];
50   vpx_prob partition_prob[PARTITION_CONTEXTS][PARTITION_TYPES - 1];
51   vp9_coeff_probs_model coef_probs[TX_SIZES][PLANE_TYPES];
52   vpx_prob switchable_interp_prob[SWITCHABLE_FILTER_CONTEXTS]
53                                  [SWITCHABLE_FILTERS - 1];
54   vpx_prob inter_mode_probs[INTER_MODE_CONTEXTS][INTER_MODES - 1];
55   vpx_prob intra_inter_prob[INTRA_INTER_CONTEXTS];
56   vpx_prob comp_inter_prob[COMP_INTER_CONTEXTS];
57   vpx_prob single_ref_prob[REF_CONTEXTS][2];
58   vpx_prob comp_ref_prob[REF_CONTEXTS];
59   struct tx_probs tx_probs;
60   vpx_prob skip_probs[SKIP_CONTEXTS];
61   nmv_context nmvc;
62   int initialized;
63 } FRAME_CONTEXT;
64 
65 typedef struct FRAME_COUNTS {
66   unsigned int y_mode[BLOCK_SIZE_GROUPS][INTRA_MODES];
67   unsigned int uv_mode[INTRA_MODES][INTRA_MODES];
68   unsigned int partition[PARTITION_CONTEXTS][PARTITION_TYPES];
69   vp9_coeff_count_model coef[TX_SIZES][PLANE_TYPES];
70   unsigned int eob_branch[TX_SIZES][PLANE_TYPES][REF_TYPES][COEF_BANDS]
71                          [COEFF_CONTEXTS];
72   unsigned int switchable_interp[SWITCHABLE_FILTER_CONTEXTS]
73                                 [SWITCHABLE_FILTERS];
74   unsigned int inter_mode[INTER_MODE_CONTEXTS][INTER_MODES];
75   unsigned int intra_inter[INTRA_INTER_CONTEXTS][2];
76   unsigned int comp_inter[COMP_INTER_CONTEXTS][2];
77   unsigned int single_ref[REF_CONTEXTS][2][2];
78   unsigned int comp_ref[REF_CONTEXTS][2];
79   struct tx_counts tx;
80   unsigned int skip[SKIP_CONTEXTS][2];
81   nmv_context_counts mv;
82 } FRAME_COUNTS;
83 
84 extern const vpx_prob eb_vp9_kf_uv_mode_prob[INTRA_MODES][INTRA_MODES - 1];
85 extern const vpx_prob eb_vp9_kf_y_mode_prob[INTRA_MODES][INTRA_MODES]
86                                         [INTRA_MODES - 1];
87 extern const vpx_prob eb_vp9_kf_partition_probs[PARTITION_CONTEXTS]
88                                             [PARTITION_TYPES - 1];
89 extern const vpx_tree_index eb_vp9_intra_mode_tree[TREE_SIZE(INTRA_MODES)];
90 extern const vpx_tree_index eb_vp9_inter_mode_tree[TREE_SIZE(INTER_MODES)];
91 extern const vpx_tree_index eb_vp9_partition_tree[TREE_SIZE(PARTITION_TYPES)];
92 extern const vpx_tree_index eb_vp9_switchable_interp_tree[TREE_SIZE(SWITCHABLE_FILTERS)];
93 
94 void eb_vp9_setup_past_independence(struct VP9Common *cm);
95 
96 void eb_vp9_adapt_mode_probs(struct VP9Common *cm);
97 
98 void eb_vp9_tx_counts_to_branch_counts_32x32(const unsigned int *tx_count_32x32p,
99                                       unsigned int (*ct_32x32p)[2]);
100 void eb_vp9_tx_counts_to_branch_counts_16x16(const unsigned int *tx_count_16x16p,
101                                       unsigned int (*ct_16x16p)[2]);
102 void eb_vp9_tx_counts_to_branch_counts_8x8(const unsigned int *tx_count_8x8p,
103                                     unsigned int (*ct_8x8p)[2]);
104 void eb_vp9_init_mode_probs(FRAME_CONTEXT *fc);
105 
106 #ifdef __cplusplus
107 }  // extern "C"
108 #endif
109 
110 #endif  // VPX_VP9_COMMON_VP9_ENTROPYMODE_H_
111