vp9_pred_common.h 5.17 KB
Newer Older
1
/*
Paul Wilkins's avatar
Paul Wilkins committed
2
 *  Copyright (c) 2012 The WebM project authors. All Rights Reserved.
3
4
5
6
7
8
9
10
 *
 *  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 VP9_COMMON_VP9_PRED_COMMON_H_
#define VP9_COMMON_VP9_PRED_COMMON_H_
13

Dmitry Kovalev's avatar
Dmitry Kovalev committed
14
15
#include "vp9/common/vp9_blockd.h"
#include "vp9/common/vp9_onyxc_int.h"
16

17
int vp9_get_segment_id(VP9_COMMON *cm, const uint8_t *segment_ids,
18
                       BLOCK_SIZE bsize, int mi_row, int mi_col);
19

20

21
static INLINE int vp9_get_pred_context_seg_id(const MACROBLOCKD *xd) {
22
23
24
25
  const MODE_INFO * const above_mi = xd->mi_8x8[-xd->mode_info_stride];
  const MODE_INFO * const left_mi = xd->mi_8x8[-1];
  const int above_sip = above_mi ? above_mi->mbmi.seg_id_predicted : 0;
  const int left_sip = left_mi ? left_mi->mbmi.seg_id_predicted : 0;
26

27
  return above_sip + (xd->left_available ? left_sip : 0);
28
}
29

30
31
32
static INLINE vp9_prob vp9_get_pred_prob_seg_id(struct segmentation *seg,
                                                const MACROBLOCKD *xd) {
  return seg->pred_probs[vp9_get_pred_context_seg_id(xd)];
33
34
}

35
void vp9_set_pred_flag_seg_id(MACROBLOCKD *xd, uint8_t pred_flag);
36
37

static INLINE int vp9_get_pred_context_mbskip(const MACROBLOCKD *xd) {
38
39
40
41
  const MODE_INFO * const above_mi = xd->mi_8x8[-xd->mode_info_stride];
  const MODE_INFO * const left_mi = xd->mi_8x8[-1];
  const int above_skip_coeff = above_mi ? above_mi->mbmi.skip_coeff : 0;
  const int left_skip_coeff = left_mi ? left_mi->mbmi.skip_coeff : 0;
42

43
  return above_skip_coeff + (xd->left_available ? left_skip_coeff : 0);
44
}
45

46
47
static INLINE vp9_prob vp9_get_pred_prob_mbskip(const VP9_COMMON *cm,
                                                const MACROBLOCKD *xd) {
48
  return cm->fc.mbskip_probs[vp9_get_pred_context_mbskip(xd)];
49
}
50
51

static INLINE unsigned char vp9_get_pred_flag_mbskip(const MACROBLOCKD *xd) {
52
  return xd->this_mi->mbmi.skip_coeff;
53
}
54

55
56
void vp9_set_pred_flag_mbskip(MACROBLOCKD *xd, BLOCK_SIZE bsize,
                              uint8_t pred_flag);
57

58
unsigned char vp9_get_pred_context_switchable_interp(const MACROBLOCKD *xd);
59

60
unsigned char vp9_get_pred_context_intra_inter(const MACROBLOCKD *xd);
61

62
63
static INLINE vp9_prob vp9_get_pred_prob_intra_inter(const VP9_COMMON *cm,
                                                     const MACROBLOCKD *xd) {
64
  const int pred_context = vp9_get_pred_context_intra_inter(xd);
65
66
67
68
69
70
71
  return cm->fc.intra_inter_prob[pred_context];
}

unsigned char vp9_get_pred_context_comp_inter_inter(const VP9_COMMON *cm,
                                                    const MACROBLOCKD *xd);


72
73
74
static INLINE
vp9_prob vp9_get_pred_prob_comp_inter_inter(const VP9_COMMON *cm,
                                            const MACROBLOCKD *xd) {
75
76
77
78
79
80
81
82
83
84
85
86
87
  const int pred_context = vp9_get_pred_context_comp_inter_inter(cm, xd);
  return cm->fc.comp_inter_prob[pred_context];
}

unsigned char vp9_get_pred_context_comp_ref_p(const VP9_COMMON *cm,
                                              const MACROBLOCKD *xd);

static INLINE vp9_prob vp9_get_pred_prob_comp_ref_p(const VP9_COMMON *cm,
                                                    const MACROBLOCKD *xd) {
  const int pred_context = vp9_get_pred_context_comp_ref_p(cm, xd);
  return cm->fc.comp_ref_prob[pred_context];
}

88
unsigned char vp9_get_pred_context_single_ref_p1(const MACROBLOCKD *xd);
89
90
91

static INLINE vp9_prob vp9_get_pred_prob_single_ref_p1(const VP9_COMMON *cm,
                                                       const MACROBLOCKD *xd) {
92
  const int pred_context = vp9_get_pred_context_single_ref_p1(xd);
93
94
95
  return cm->fc.single_ref_prob[pred_context][0];
}

96
unsigned char vp9_get_pred_context_single_ref_p2(const MACROBLOCKD *xd);
97
98
99

static INLINE vp9_prob vp9_get_pred_prob_single_ref_p2(const VP9_COMMON *cm,
                                                       const MACROBLOCKD *xd) {
100
  const int pred_context = vp9_get_pred_context_single_ref_p2(xd);
101
102
103
  return cm->fc.single_ref_prob[pred_context][1];
}

104
unsigned char vp9_get_pred_context_tx_size(const MACROBLOCKD *xd);
105

106
static const vp9_prob *get_tx_probs(BLOCK_SIZE bsize, uint8_t context,
107
                                    const struct tx_probs *tx_probs) {
108
  if (bsize < BLOCK_16X16)
109
    return tx_probs->p8x8[context];
110
  else if (bsize < BLOCK_32X32)
111
112
113
114
115
116
    return tx_probs->p16x16[context];
  else
    return tx_probs->p32x32[context];
}

static const vp9_prob *get_tx_probs2(const MACROBLOCKD *xd,
117
118
119
                                     const struct tx_probs *tx_probs,
                                     const MODE_INFO *m) {
  const BLOCK_SIZE bsize = m->mbmi.sb_type;
120
121
122
123
  const int context = vp9_get_pred_context_tx_size(xd);
  return get_tx_probs(bsize, context, tx_probs);
}

124
static void update_tx_counts(BLOCK_SIZE bsize, uint8_t context,
125
                             TX_SIZE tx_size, struct tx_counts *tx_counts) {
126
  if (bsize >= BLOCK_32X32)
127
    tx_counts->p32x32[context][tx_size]++;
128
  else if (bsize >= BLOCK_16X16)
129
    tx_counts->p16x16[context][tx_size]++;
130
  else
131
    tx_counts->p8x8[context][tx_size]++;
132
133
}

134
#endif  // VP9_COMMON_VP9_PRED_COMMON_H_