]> granicus.if.org Git - libvpx/blob - vp9/common/vp9_pred_common.h
Merge "Substantial restructuring of AQ mode 2."
[libvpx] / vp9 / common / vp9_pred_common.h
1 /*
2  *  Copyright (c) 2012 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 VP9_COMMON_VP9_PRED_COMMON_H_
12 #define VP9_COMMON_VP9_PRED_COMMON_H_
13
14 #include "vp9/common/vp9_blockd.h"
15 #include "vp9/common/vp9_onyxc_int.h"
16
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20
21 int vp9_get_segment_id(const VP9_COMMON *cm, const uint8_t *segment_ids,
22                        BLOCK_SIZE bsize, int mi_row, int mi_col);
23
24 static INLINE int vp9_get_pred_context_seg_id(const MACROBLOCKD *xd) {
25   const MODE_INFO *const above_mi = xd->above_mi;
26   const MODE_INFO *const left_mi = xd->left_mi;
27   const int above_sip = (above_mi != NULL) ?
28                         above_mi->mbmi.seg_id_predicted : 0;
29   const int left_sip = (left_mi != NULL) ? left_mi->mbmi.seg_id_predicted : 0;
30
31   return above_sip + left_sip;
32 }
33
34 static INLINE vp9_prob vp9_get_pred_prob_seg_id(const struct segmentation *seg,
35                                                 const MACROBLOCKD *xd) {
36   return seg->pred_probs[vp9_get_pred_context_seg_id(xd)];
37 }
38
39 static INLINE int vp9_get_skip_context(const MACROBLOCKD *xd) {
40   const MODE_INFO *const above_mi = xd->above_mi;
41   const MODE_INFO *const left_mi = xd->left_mi;
42   const int above_skip = (above_mi != NULL) ? above_mi->mbmi.skip : 0;
43   const int left_skip = (left_mi != NULL) ? left_mi->mbmi.skip : 0;
44   return above_skip + left_skip;
45 }
46
47 static INLINE vp9_prob vp9_get_skip_prob(const VP9_COMMON *cm,
48                                          const MACROBLOCKD *xd) {
49   return cm->fc->skip_probs[vp9_get_skip_context(xd)];
50 }
51
52 int vp9_get_pred_context_switchable_interp(const MACROBLOCKD *xd);
53
54 int vp9_get_intra_inter_context(const MACROBLOCKD *xd);
55
56 static INLINE vp9_prob vp9_get_intra_inter_prob(const VP9_COMMON *cm,
57                                                 const MACROBLOCKD *xd) {
58   return cm->fc->intra_inter_prob[vp9_get_intra_inter_context(xd)];
59 }
60
61 int vp9_get_reference_mode_context(const VP9_COMMON *cm, const MACROBLOCKD *xd);
62
63 static INLINE vp9_prob vp9_get_reference_mode_prob(const VP9_COMMON *cm,
64                                                    const MACROBLOCKD *xd) {
65   return cm->fc->comp_inter_prob[vp9_get_reference_mode_context(cm, xd)];
66 }
67
68 int vp9_get_pred_context_comp_ref_p(const VP9_COMMON *cm,
69                                     const MACROBLOCKD *xd);
70
71 static INLINE vp9_prob vp9_get_pred_prob_comp_ref_p(const VP9_COMMON *cm,
72                                                     const MACROBLOCKD *xd) {
73   const int pred_context = vp9_get_pred_context_comp_ref_p(cm, xd);
74   return cm->fc->comp_ref_prob[pred_context];
75 }
76
77 int vp9_get_pred_context_single_ref_p1(const MACROBLOCKD *xd);
78
79 static INLINE vp9_prob vp9_get_pred_prob_single_ref_p1(const VP9_COMMON *cm,
80                                                        const MACROBLOCKD *xd) {
81   return cm->fc->single_ref_prob[vp9_get_pred_context_single_ref_p1(xd)][0];
82 }
83
84 int vp9_get_pred_context_single_ref_p2(const MACROBLOCKD *xd);
85
86 static INLINE vp9_prob vp9_get_pred_prob_single_ref_p2(const VP9_COMMON *cm,
87                                                        const MACROBLOCKD *xd) {
88   return cm->fc->single_ref_prob[vp9_get_pred_context_single_ref_p2(xd)][1];
89 }
90
91 int vp9_get_tx_size_context(const MACROBLOCKD *xd);
92
93 static INLINE const vp9_prob *get_tx_probs(TX_SIZE max_tx_size, int ctx,
94                                            const struct tx_probs *tx_probs) {
95   switch (max_tx_size) {
96     case TX_8X8:
97       return tx_probs->p8x8[ctx];
98     case TX_16X16:
99       return tx_probs->p16x16[ctx];
100     case TX_32X32:
101       return tx_probs->p32x32[ctx];
102     default:
103       assert(0 && "Invalid max_tx_size.");
104       return NULL;
105   }
106 }
107
108 static INLINE const vp9_prob *get_tx_probs2(TX_SIZE max_tx_size,
109                                             const MACROBLOCKD *xd,
110                                             const struct tx_probs *tx_probs) {
111   return get_tx_probs(max_tx_size, vp9_get_tx_size_context(xd), tx_probs);
112 }
113
114 static INLINE unsigned int *get_tx_counts(TX_SIZE max_tx_size, int ctx,
115                                           struct tx_counts *tx_counts) {
116   switch (max_tx_size) {
117     case TX_8X8:
118       return tx_counts->p8x8[ctx];
119     case TX_16X16:
120       return tx_counts->p16x16[ctx];
121     case TX_32X32:
122       return tx_counts->p32x32[ctx];
123     default:
124       assert(0 && "Invalid max_tx_size.");
125       return NULL;
126   }
127 }
128
129 #ifdef __cplusplus
130 }  // extern "C"
131 #endif
132
133 #endif  // VP9_COMMON_VP9_PRED_COMMON_H_