michael@0: /* michael@0: * Copyright (c) 2012 The WebM project authors. All Rights Reserved. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license michael@0: * that can be found in the LICENSE file in the root of the source michael@0: * tree. An additional intellectual property rights grant can be found michael@0: * in the file PATENTS. All contributing project authors may michael@0: * be found in the AUTHORS file in the root of the source tree. michael@0: */ michael@0: michael@0: #ifndef VP9_COMMON_VP9_PRED_COMMON_H_ michael@0: #define VP9_COMMON_VP9_PRED_COMMON_H_ michael@0: michael@0: #include "vp9/common/vp9_blockd.h" michael@0: #include "vp9/common/vp9_onyxc_int.h" michael@0: michael@0: static INLINE const MODE_INFO *get_above_mi(const MACROBLOCKD *const xd) { michael@0: return xd->up_available ? xd->mi_8x8[-xd->mode_info_stride] : NULL; michael@0: } michael@0: michael@0: static INLINE const MODE_INFO *get_left_mi(const MACROBLOCKD *const xd) { michael@0: return xd->left_available ? xd->mi_8x8[-1] : NULL; michael@0: } michael@0: michael@0: int vp9_get_segment_id(VP9_COMMON *cm, const uint8_t *segment_ids, michael@0: BLOCK_SIZE bsize, int mi_row, int mi_col); michael@0: michael@0: static INLINE int vp9_get_pred_context_seg_id(const MACROBLOCKD *xd) { michael@0: const MODE_INFO *const above_mi = get_above_mi(xd); michael@0: const MODE_INFO *const left_mi = get_left_mi(xd); michael@0: const int above_sip = (above_mi != NULL) ? michael@0: above_mi->mbmi.seg_id_predicted : 0; michael@0: const int left_sip = (left_mi != NULL) ? left_mi->mbmi.seg_id_predicted : 0; michael@0: michael@0: return above_sip + left_sip; michael@0: } michael@0: michael@0: static INLINE vp9_prob vp9_get_pred_prob_seg_id(struct segmentation *seg, michael@0: const MACROBLOCKD *xd) { michael@0: return seg->pred_probs[vp9_get_pred_context_seg_id(xd)]; michael@0: } michael@0: michael@0: void vp9_set_pred_flag_seg_id(MACROBLOCKD *xd, uint8_t pred_flag); michael@0: michael@0: static INLINE int vp9_get_pred_context_mbskip(const MACROBLOCKD *xd) { michael@0: const MODE_INFO *const above_mi = get_above_mi(xd); michael@0: const MODE_INFO *const left_mi = get_left_mi(xd); michael@0: const int above_skip_coeff = (above_mi != NULL) ? michael@0: above_mi->mbmi.skip_coeff : 0; michael@0: const int left_skip_coeff = (left_mi != NULL) ? left_mi->mbmi.skip_coeff : 0; michael@0: michael@0: return above_skip_coeff + left_skip_coeff; michael@0: } michael@0: michael@0: static INLINE vp9_prob vp9_get_pred_prob_mbskip(const VP9_COMMON *cm, michael@0: const MACROBLOCKD *xd) { michael@0: return cm->fc.mbskip_probs[vp9_get_pred_context_mbskip(xd)]; michael@0: } michael@0: michael@0: static INLINE unsigned char vp9_get_pred_flag_mbskip(const MACROBLOCKD *xd) { michael@0: return xd->mi_8x8[0]->mbmi.skip_coeff; michael@0: } michael@0: michael@0: unsigned char vp9_get_pred_context_switchable_interp(const MACROBLOCKD *xd); michael@0: michael@0: unsigned char vp9_get_pred_context_intra_inter(const MACROBLOCKD *xd); michael@0: michael@0: static INLINE vp9_prob vp9_get_pred_prob_intra_inter(const VP9_COMMON *cm, michael@0: const MACROBLOCKD *xd) { michael@0: const int pred_context = vp9_get_pred_context_intra_inter(xd); michael@0: return cm->fc.intra_inter_prob[pred_context]; michael@0: } michael@0: michael@0: unsigned char vp9_get_pred_context_comp_inter_inter(const VP9_COMMON *cm, michael@0: const MACROBLOCKD *xd); michael@0: michael@0: michael@0: static INLINE michael@0: vp9_prob vp9_get_pred_prob_comp_inter_inter(const VP9_COMMON *cm, michael@0: const MACROBLOCKD *xd) { michael@0: const int pred_context = vp9_get_pred_context_comp_inter_inter(cm, xd); michael@0: return cm->fc.comp_inter_prob[pred_context]; michael@0: } michael@0: michael@0: unsigned char vp9_get_pred_context_comp_ref_p(const VP9_COMMON *cm, michael@0: const MACROBLOCKD *xd); michael@0: michael@0: static INLINE vp9_prob vp9_get_pred_prob_comp_ref_p(const VP9_COMMON *cm, michael@0: const MACROBLOCKD *xd) { michael@0: const int pred_context = vp9_get_pred_context_comp_ref_p(cm, xd); michael@0: return cm->fc.comp_ref_prob[pred_context]; michael@0: } michael@0: michael@0: unsigned char vp9_get_pred_context_single_ref_p1(const MACROBLOCKD *xd); michael@0: michael@0: static INLINE vp9_prob vp9_get_pred_prob_single_ref_p1(const VP9_COMMON *cm, michael@0: const MACROBLOCKD *xd) { michael@0: const int pred_context = vp9_get_pred_context_single_ref_p1(xd); michael@0: return cm->fc.single_ref_prob[pred_context][0]; michael@0: } michael@0: michael@0: unsigned char vp9_get_pred_context_single_ref_p2(const MACROBLOCKD *xd); michael@0: michael@0: static INLINE vp9_prob vp9_get_pred_prob_single_ref_p2(const VP9_COMMON *cm, michael@0: const MACROBLOCKD *xd) { michael@0: const int pred_context = vp9_get_pred_context_single_ref_p2(xd); michael@0: return cm->fc.single_ref_prob[pred_context][1]; michael@0: } michael@0: michael@0: unsigned char vp9_get_pred_context_tx_size(const MACROBLOCKD *xd); michael@0: michael@0: static const vp9_prob *get_tx_probs(TX_SIZE max_tx_size, int ctx, michael@0: const struct tx_probs *tx_probs) { michael@0: switch (max_tx_size) { michael@0: case TX_8X8: michael@0: return tx_probs->p8x8[ctx]; michael@0: case TX_16X16: michael@0: return tx_probs->p16x16[ctx]; michael@0: case TX_32X32: michael@0: return tx_probs->p32x32[ctx]; michael@0: default: michael@0: assert(!"Invalid max_tx_size."); michael@0: return NULL; michael@0: } michael@0: } michael@0: michael@0: static const vp9_prob *get_tx_probs2(TX_SIZE max_tx_size, const MACROBLOCKD *xd, michael@0: const struct tx_probs *tx_probs) { michael@0: const int ctx = vp9_get_pred_context_tx_size(xd); michael@0: return get_tx_probs(max_tx_size, ctx, tx_probs); michael@0: } michael@0: michael@0: static unsigned int *get_tx_counts(TX_SIZE max_tx_size, int ctx, michael@0: struct tx_counts *tx_counts) { michael@0: switch (max_tx_size) { michael@0: case TX_8X8: michael@0: return tx_counts->p8x8[ctx]; michael@0: case TX_16X16: michael@0: return tx_counts->p16x16[ctx]; michael@0: case TX_32X32: michael@0: return tx_counts->p32x32[ctx]; michael@0: default: michael@0: assert(!"Invalid max_tx_size."); michael@0: return NULL; michael@0: } michael@0: } michael@0: michael@0: #endif // VP9_COMMON_VP9_PRED_COMMON_H_