From: Ronald S. Bultje Date: Wed, 10 Apr 2013 23:50:01 +0000 (-0700) Subject: Make usage of sb_type independent of literal values. X-Git-Tag: v1.3.0~1106^2~283 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8fb5be48a600bc75ee0e0b720c3ffe680d11db53;p=platform%2Fupstream%2Flibvpx.git Make usage of sb_type independent of literal values. Change-Id: I0d12f9ef9d960df0172a1377f8e5236eb6d90492 --- diff --git a/vp9/common/vp9_findnearmv.c b/vp9/common/vp9_findnearmv.c index f6d6932..0538958 100644 --- a/vp9/common/vp9_findnearmv.c +++ b/vp9/common/vp9_findnearmv.c @@ -197,12 +197,13 @@ void vp9_find_best_ref_mvs(MACROBLOCKD *xd, #else if (xd->up_available && xd->left_available) { #endif + const int bwl = mb_width_log2(xd->mode_info_context->mbmi.sb_type); vp9_sub_pixel_variance16x2(above_ref + offset, ref_y_stride, SP(this_mv.as_mv.col), SP(this_mv.as_mv.row), above_src, xd->dst.y_stride, &sse); score += sse; - if (xd->mode_info_context->mbmi.sb_type >= BLOCK_SIZE_SB32X32) { + if (bwl >= 1) { vp9_sub_pixel_variance16x2(above_ref + offset + 16, ref_y_stride, SP(this_mv.as_mv.col), @@ -210,7 +211,7 @@ void vp9_find_best_ref_mvs(MACROBLOCKD *xd, above_src + 16, xd->dst.y_stride, &sse); score += sse; } - if (xd->mode_info_context->mbmi.sb_type >= BLOCK_SIZE_SB64X64) { + if (bwl >= 2) { vp9_sub_pixel_variance16x2(above_ref + offset + 32, ref_y_stride, SP(this_mv.as_mv.col), @@ -227,12 +228,13 @@ void vp9_find_best_ref_mvs(MACROBLOCKD *xd, } #if !CONFIG_ABOVESPREFMV if (xd->left_available) { + const int bhl = mb_height_log2(xd->mode_info_context->mbmi.sb_type); vp9_sub_pixel_variance2x16_c(left_ref + offset, ref_y_stride, SP(this_mv.as_mv.col), SP(this_mv.as_mv.row), left_src, xd->dst.y_stride, &sse); score += sse; - if (xd->mode_info_context->mbmi.sb_type >= BLOCK_SIZE_SB32X32) { + if (bhl >= 1) { vp9_sub_pixel_variance2x16_c(left_ref + offset + ref_y_stride * 16, ref_y_stride, SP(this_mv.as_mv.col), @@ -241,7 +243,7 @@ void vp9_find_best_ref_mvs(MACROBLOCKD *xd, xd->dst.y_stride, &sse); score += sse; } - if (xd->mode_info_context->mbmi.sb_type >= BLOCK_SIZE_SB64X64) { + if (bhl >= 2) { vp9_sub_pixel_variance2x16_c(left_ref + offset + ref_y_stride * 32, ref_y_stride, SP(this_mv.as_mv.col), diff --git a/vp9/common/vp9_mvref_common.c b/vp9/common/vp9_mvref_common.c index 8d376ad..e1a12e4 100644 --- a/vp9/common/vp9_mvref_common.c +++ b/vp9/common/vp9_mvref_common.c @@ -262,7 +262,7 @@ void vp9_find_mv_refs(VP9_COMMON *cm, MACROBLOCKD *xd, MODE_INFO *here, if (mbmi->sb_type == BLOCK_SIZE_SB64X64) { mv_ref_search = sb64_mv_ref_search; ref_distance_weight = sb64_ref_distance_weight; - } else if (mbmi->sb_type == BLOCK_SIZE_SB32X32) { + } else if (mbmi->sb_type >= BLOCK_SIZE_SB32X32) { mv_ref_search = sb_mv_ref_search; ref_distance_weight = sb_ref_distance_weight; } else { diff --git a/vp9/common/vp9_pred_common.c b/vp9/common/vp9_pred_common.c index 9fe66fc..ffdfa67 100644 --- a/vp9/common/vp9_pred_common.c +++ b/vp9/common/vp9_pred_common.c @@ -179,54 +179,37 @@ void vp9_set_pred_flag(MACROBLOCKD *const xd, PRED_ID pred_id, unsigned char pred_flag) { const int mis = xd->mode_info_stride; + BLOCK_SIZE_TYPE bsize = xd->mode_info_context->mbmi.sb_type; + const int bh = 1 << mb_height_log2(bsize); + const int bw = 1 << mb_width_log2(bsize); +#define sub(a, b) (b) < 0 ? (a) + (b) : (a) + const int x_mbs = sub(bw, xd->mb_to_right_edge >> 7); + const int y_mbs = sub(bh, xd->mb_to_bottom_edge >> 7); +#undef sub + int x, y; switch (pred_id) { case PRED_SEG_ID: - xd->mode_info_context->mbmi.seg_id_predicted = pred_flag; - if (xd->mode_info_context->mbmi.sb_type) { -#define sub(a, b) (b) < 0 ? (a) + (b) : (a) - const int n_mbs = 1 << xd->mode_info_context->mbmi.sb_type; - const int x_mbs = sub(n_mbs, xd->mb_to_right_edge >> 7); - const int y_mbs = sub(n_mbs, xd->mb_to_bottom_edge >> 7); - int x, y; - - for (y = 0; y < y_mbs; y++) { - for (x = !y; x < x_mbs; x++) { - xd->mode_info_context[y * mis + x].mbmi.seg_id_predicted = - pred_flag; - } + for (y = 0; y < y_mbs; y++) { + for (x = 0; x < x_mbs; x++) { + xd->mode_info_context[y * mis + x].mbmi.seg_id_predicted = + pred_flag; } } break; case PRED_REF: - xd->mode_info_context->mbmi.ref_predicted = pred_flag; - if (xd->mode_info_context->mbmi.sb_type) { - const int n_mbs = 1 << xd->mode_info_context->mbmi.sb_type; - const int x_mbs = sub(n_mbs, xd->mb_to_right_edge >> 7); - const int y_mbs = sub(n_mbs, xd->mb_to_bottom_edge >> 7); - int x, y; - - for (y = 0; y < y_mbs; y++) { - for (x = !y; x < x_mbs; x++) { - xd->mode_info_context[y * mis + x].mbmi.ref_predicted = pred_flag; - } + for (y = 0; y < y_mbs; y++) { + for (x = 0; x < x_mbs; x++) { + xd->mode_info_context[y * mis + x].mbmi.ref_predicted = pred_flag; } } break; case PRED_MBSKIP: - xd->mode_info_context->mbmi.mb_skip_coeff = pred_flag; - if (xd->mode_info_context->mbmi.sb_type) { - const int n_mbs = 1 << xd->mode_info_context->mbmi.sb_type; - const int x_mbs = sub(n_mbs, xd->mb_to_right_edge >> 7); - const int y_mbs = sub(n_mbs, xd->mb_to_bottom_edge >> 7); - int x, y; - - for (y = 0; y < y_mbs; y++) { - for (x = !y; x < x_mbs; x++) { - xd->mode_info_context[y * mis + x].mbmi.mb_skip_coeff = pred_flag; - } + for (y = 0; y < y_mbs; y++) { + for (x = 0; x < x_mbs; x++) { + xd->mode_info_context[y * mis + x].mbmi.mb_skip_coeff = pred_flag; } } break; @@ -249,11 +232,13 @@ unsigned char vp9_get_pred_mb_segid(const VP9_COMMON *const cm, if (!xd->mode_info_context->mbmi.sb_type) { return cm->last_frame_seg_map[MbIndex]; } else { - const int n_mbs = 1 << xd->mode_info_context->mbmi.sb_type; + BLOCK_SIZE_TYPE bsize = xd->mode_info_context->mbmi.sb_type; + const int bh = 1 << mb_height_log2(bsize); + const int bw = 1 << mb_width_log2(bsize); const int mb_col = MbIndex % cm->mb_cols; const int mb_row = MbIndex / cm->mb_cols; - const int x_mbs = MIN(n_mbs, cm->mb_cols - mb_col); - const int y_mbs = MIN(n_mbs, cm->mb_rows - mb_row); + const int x_mbs = MIN(bw, cm->mb_cols - mb_col); + const int y_mbs = MIN(bh, cm->mb_rows - mb_row); int x, y; unsigned seg_id = -1; diff --git a/vp9/decoder/vp9_decodemv.c b/vp9/decoder/vp9_decodemv.c index f081e71..27cd6a9 100644 --- a/vp9/decoder/vp9_decodemv.c +++ b/vp9/decoder/vp9_decodemv.c @@ -136,9 +136,10 @@ static void kfread_modes(VP9D_COMP *pbi, if (pbi->mb.update_mb_segmentation_map) { read_mb_segid(bc, &m->mbmi, &pbi->mb); if (m->mbmi.sb_type) { - const int nmbs = 1 << m->mbmi.sb_type; - const int ymbs = MIN(cm->mb_rows - mb_row, nmbs); - const int xmbs = MIN(cm->mb_cols - mb_col, nmbs); + const int bw = 1 << mb_width_log2(m->mbmi.sb_type); + const int bh = 1 << mb_height_log2(m->mbmi.sb_type); + const int ymbs = MIN(cm->mb_rows - mb_row, bh); + const int xmbs = MIN(cm->mb_cols - mb_col, bw); int x, y; for (y = 0; y < ymbs; y++) { @@ -205,10 +206,11 @@ static void kfread_modes(VP9D_COMP *pbi, m->mbmi.txfm_size = vp9_read(bc, cm->prob_tx[0]); if (m->mbmi.txfm_size != TX_4X4 && m->mbmi.mode != I8X8_PRED) { m->mbmi.txfm_size += vp9_read(bc, cm->prob_tx[1]); - if (m->mbmi.txfm_size != TX_8X8 && m->mbmi.sb_type) + if (m->mbmi.txfm_size != TX_8X8 && m->mbmi.sb_type >= BLOCK_SIZE_SB32X32) m->mbmi.txfm_size += vp9_read(bc, cm->prob_tx[2]); } - } else if (cm->txfm_mode >= ALLOW_32X32 && m->mbmi.sb_type) { + } else if (cm->txfm_mode >= ALLOW_32X32 && + m->mbmi.sb_type >= BLOCK_SIZE_SB32X32) { m->mbmi.txfm_size = TX_32X32; } else if (cm->txfm_mode >= ALLOW_16X16 && m->mbmi.mode <= TM_PRED) { m->mbmi.txfm_size = TX_16X16; @@ -589,9 +591,10 @@ static void read_mb_segment_id(VP9D_COMP *pbi, } if (mbmi->sb_type) { - const int nmbs = 1 << mbmi->sb_type; - const int ymbs = MIN(cm->mb_rows - mb_row, nmbs); - const int xmbs = MIN(cm->mb_cols - mb_col, nmbs); + const int bw = 1 << mb_width_log2(mbmi->sb_type); + const int bh = 1 << mb_height_log2(mbmi->sb_type); + const int ymbs = MIN(cm->mb_rows - mb_row, bh); + const int xmbs = MIN(cm->mb_cols - mb_col, bw); int x, y; for (y = 0; y < ymbs; y++) { @@ -605,9 +608,10 @@ static void read_mb_segment_id(VP9D_COMP *pbi, } } else { if (mbmi->sb_type) { - const int nmbs = 1 << mbmi->sb_type; - const int ymbs = MIN(cm->mb_rows - mb_row, nmbs); - const int xmbs = MIN(cm->mb_cols - mb_col, nmbs); + const int bw = 1 << mb_width_log2(mbmi->sb_type); + const int bh = 1 << mb_height_log2(mbmi->sb_type); + const int ymbs = MIN(cm->mb_rows - mb_row, bh); + const int xmbs = MIN(cm->mb_cols - mb_col, bw); unsigned segment_id = -1; int x, y; @@ -669,7 +673,8 @@ static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi, MACROBLOCKD *const xd = &pbi->mb; int_mv *const mv = &mbmi->mv[0]; - const int mb_size = 1 << mi->mbmi.sb_type; + const int bw = 1 << mb_width_log2(mi->mbmi.sb_type); + const int bh = 1 << mb_height_log2(mi->mbmi.sb_type); const int use_prev_in_find_mv_refs = cm->width == cm->last_width && cm->height == cm->last_height && @@ -689,8 +694,8 @@ static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi, // Distance of Mb to the various image edges. // These specified to 8th pel as they are always compared to MV values // that are in 1/8th pel units - set_mb_row(cm, xd, mb_row, mb_size); - set_mb_col(cm, xd, mb_col, mb_size); + set_mb_row(cm, xd, mb_row, bh); + set_mb_col(cm, xd, mb_col, bw); mb_to_top_edge = xd->mb_to_top_edge - LEFT_TOP_MARGIN; mb_to_bottom_edge = xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN; @@ -1104,10 +1109,11 @@ static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi, if (mbmi->txfm_size != TX_4X4 && mbmi->mode != I8X8_PRED && mbmi->mode != SPLITMV) { mbmi->txfm_size += vp9_read(bc, cm->prob_tx[1]); - if (mbmi->sb_type && mbmi->txfm_size != TX_8X8) + if (mbmi->sb_type >= BLOCK_SIZE_SB32X32 && mbmi->txfm_size != TX_8X8) mbmi->txfm_size += vp9_read(bc, cm->prob_tx[2]); } - } else if (mbmi->sb_type && cm->txfm_mode >= ALLOW_32X32) { + } else if (mbmi->sb_type >= BLOCK_SIZE_SB32X32 && + cm->txfm_mode >= ALLOW_32X32) { mbmi->txfm_size = TX_32X32; } else if (cm->txfm_mode >= ALLOW_16X16 && ((mbmi->ref_frame == INTRA_FRAME && mbmi->mode <= TM_PRED) || @@ -1417,9 +1423,10 @@ void vp9_decode_mb_mode_mv(VP9D_COMP* const pbi, #endif // CONFIG_CODE_NONZEROCOUNT if (mbmi->sb_type) { - const int n_mbs = 1 << mbmi->sb_type; - const int y_mbs = MIN(n_mbs, cm->mb_rows - mb_row); - const int x_mbs = MIN(n_mbs, cm->mb_cols - mb_col); + const int bw = 1 << mb_width_log2(mbmi->sb_type); + const int bh = 1 << mb_height_log2(mbmi->sb_type); + const int y_mbs = MIN(bh, cm->mb_rows - mb_row); + const int x_mbs = MIN(bw, cm->mb_cols - mb_col); const int mis = cm->mode_info_stride; int x, y; diff --git a/vp9/decoder/vp9_detokenize.c b/vp9/decoder/vp9_detokenize.c index f9e9da9..457c739 100644 --- a/vp9/decoder/vp9_detokenize.c +++ b/vp9/decoder/vp9_detokenize.c @@ -157,7 +157,8 @@ static int decode_coefs(VP9D_COMP *dx, const MACROBLOCKD *xd, } case TX_8X8: { const BLOCK_SIZE_TYPE sb_type = xd->mode_info_context->mbmi.sb_type; - const int sz = 3 + sb_type, x = block_idx & ((1 << sz) - 1); + const int sz = 3 + mb_width_log2(sb_type); + const int x = block_idx & ((1 << sz) - 1); const int y = block_idx - x; const TX_TYPE tx_type = (type == PLANE_TYPE_Y_WITH_DC) ? get_tx_type_8x8(xd, y + (x >> 1)) : DCT_DCT; @@ -181,7 +182,8 @@ static int decode_coefs(VP9D_COMP *dx, const MACROBLOCKD *xd, } case TX_16X16: { const BLOCK_SIZE_TYPE sb_type = xd->mode_info_context->mbmi.sb_type; - const int sz = 4 + sb_type, x = block_idx & ((1 << sz) - 1); + const int sz = 4 + mb_width_log2(sb_type); + const int x = block_idx & ((1 << sz) - 1); const int y = block_idx - x; const TX_TYPE tx_type = (type == PLANE_TYPE_Y_WITH_DC) ? get_tx_type_16x16(xd, y + (x >> 2)) : DCT_DCT; diff --git a/vp9/encoder/vp9_bitstream.c b/vp9/encoder/vp9_bitstream.c index 7fc33c0..b432884 100644 --- a/vp9/encoder/vp9_bitstream.c +++ b/vp9/encoder/vp9_bitstream.c @@ -763,7 +763,8 @@ static void pack_inter_mode_mvs(VP9_COMP *cpi, MODE_INFO *m, const MV_REFERENCE_FRAME rf = mi->ref_frame; const MB_PREDICTION_MODE mode = mi->mode; const int segment_id = mi->segment_id; - const int mb_size = 1 << mi->sb_type; + const int bw = 1 << mb_width_log2(mi->sb_type); + const int bh = 1 << mb_height_log2(mi->sb_type); int skip_coeff; int mb_row = pc->mb_rows - mb_rows_left; @@ -775,8 +776,8 @@ static void pack_inter_mode_mvs(VP9_COMP *cpi, MODE_INFO *m, // These specified to 8th pel as they are always compared to MV // values that are in 1/8th pel units - set_mb_row(pc, xd, mb_row, mb_size); - set_mb_col(pc, xd, mb_col, mb_size); + set_mb_row(pc, xd, mb_row, bh); + set_mb_col(pc, xd, mb_col, bw); #ifdef ENTROPY_STATS active_section = 9; @@ -1002,7 +1003,7 @@ static void pack_inter_mode_mvs(VP9_COMP *cpi, MODE_INFO *m, vp9_write(bc, sz != TX_4X4, pc->prob_tx[0]); if (sz != TX_4X4 && mode != I8X8_PRED && mode != SPLITMV) { vp9_write(bc, sz != TX_8X8, pc->prob_tx[1]); - if (mi->sb_type && sz != TX_8X8) + if (mi->sb_type >= BLOCK_SIZE_SB32X32 && sz != TX_8X8) vp9_write(bc, sz != TX_16X16, pc->prob_tx[2]); } } @@ -1080,7 +1081,7 @@ static void write_mb_modes_kf(const VP9_COMP *cpi, vp9_write(bc, sz != TX_4X4, c->prob_tx[0]); if (sz != TX_4X4 && ym <= TM_PRED) { vp9_write(bc, sz != TX_8X8, c->prob_tx[1]); - if (m->mbmi.sb_type && sz != TX_8X8) + if (m->mbmi.sb_type >= BLOCK_SIZE_SB32X32 && sz != TX_8X8) vp9_write(bc, sz != TX_16X16, c->prob_tx[2]); } } @@ -1649,8 +1650,8 @@ static void write_modes_b(VP9_COMP *cpi, MODE_INFO *m, vp9_writer *bc, MACROBLOCKD *const xd = &cpi->mb.e_mbd; xd->mode_info_context = m; - set_mb_row(&cpi->common, xd, mb_row, (1 << m->mbmi.sb_type)); - set_mb_col(&cpi->common, xd, mb_col, (1 << m->mbmi.sb_type)); + set_mb_row(&cpi->common, xd, mb_row, 1 << mb_height_log2(m->mbmi.sb_type)); + set_mb_col(&cpi->common, xd, mb_col, 1 << mb_width_log2(m->mbmi.sb_type)); if (cm->frame_type == KEY_FRAME) { write_mb_modes_kf(cpi, m, bc, cm->mb_rows - mb_row, cm->mb_cols - mb_col); diff --git a/vp9/encoder/vp9_encodemb.c b/vp9/encoder/vp9_encodemb.c index 75db660..0b13405 100644 --- a/vp9/encoder/vp9_encodemb.c +++ b/vp9/encoder/vp9_encodemb.c @@ -501,7 +501,8 @@ static void optimize_b(VP9_COMMON *const cm, } case TX_8X8: { const BLOCK_SIZE_TYPE sb_type = xd->mode_info_context->mbmi.sb_type; - const int sz = 3 + sb_type, x = ib & ((1 << sz) - 1), y = ib - x; + const int sz = 3 + mb_width_log2(sb_type); + const int x = ib & ((1 << sz) - 1), y = ib - x; const TX_TYPE tx_type = get_tx_type_8x8(xd, y + (x >> 1)); if (tx_type == DCT_ADST) { scan = vp9_col_scan_8x8; @@ -518,7 +519,8 @@ static void optimize_b(VP9_COMMON *const cm, } case TX_16X16: { const BLOCK_SIZE_TYPE sb_type = xd->mode_info_context->mbmi.sb_type; - const int sz = 4 + sb_type, x = ib & ((1 << sz) - 1), y = ib - x; + const int sz = 4 + mb_width_log2(sb_type); + const int x = ib & ((1 << sz) - 1), y = ib - x; const TX_TYPE tx_type = get_tx_type_16x16(xd, y + (x >> 2)); if (tx_type == DCT_ADST) { scan = vp9_col_scan_16x16; diff --git a/vp9/encoder/vp9_rdopt.c b/vp9/encoder/vp9_rdopt.c index 82592f3..49cbd4e 100644 --- a/vp9/encoder/vp9_rdopt.c +++ b/vp9/encoder/vp9_rdopt.c @@ -458,7 +458,8 @@ static INLINE int cost_coeffs(VP9_COMMON *const cm, MACROBLOCK *mb, } case TX_8X8: { const BLOCK_SIZE_TYPE sb_type = xd->mode_info_context->mbmi.sb_type; - const int sz = 3 + sb_type, x = ib & ((1 << sz) - 1), y = ib - x; + const int sz = 3 + mb_width_log2(sb_type); + const int x = ib & ((1 << sz) - 1), y = ib - x; const TX_TYPE tx_type = (type == PLANE_TYPE_Y_WITH_DC) ? get_tx_type_8x8(xd, y + (x >> 1)) : DCT_DCT; a_ec = (a[0] + a[1]) != 0; @@ -479,7 +480,8 @@ static INLINE int cost_coeffs(VP9_COMMON *const cm, MACROBLOCK *mb, } case TX_16X16: { const BLOCK_SIZE_TYPE sb_type = xd->mode_info_context->mbmi.sb_type; - const int sz = 4 + sb_type, x = ib & ((1 << sz) - 1), y = ib - x; + const int sz = 4 + mb_width_log2(sb_type); + const int x = ib & ((1 << sz) - 1), y = ib - x; const TX_TYPE tx_type = (type == PLANE_TYPE_Y_WITH_DC) ? get_tx_type_16x16(xd, y + (x >> 2)) : DCT_DCT; if (tx_type == ADST_DCT) { diff --git a/vp9/encoder/vp9_tokenize.c b/vp9/encoder/vp9_tokenize.c index 58b7412..e85f851 100644 --- a/vp9/encoder/vp9_tokenize.c +++ b/vp9/encoder/vp9_tokenize.c @@ -187,7 +187,8 @@ static void tokenize_b(VP9_COMP *cpi, break; } case TX_8X8: { - const int sz = 3 + sb_type, x = ib & ((1 << sz) - 1), y = ib - x; + const int sz = 3 + mb_width_log2(sb_type); + const int x = ib & ((1 << sz) - 1), y = ib - x; const TX_TYPE tx_type = (type == PLANE_TYPE_Y_WITH_DC) ? get_tx_type_8x8(xd, y + (x >> 1)) : DCT_DCT; a_ec = (a[0] + a[1]) != 0; @@ -206,7 +207,8 @@ static void tokenize_b(VP9_COMP *cpi, break; } case TX_16X16: { - const int sz = 4 + sb_type, x = ib & ((1 << sz) - 1), y = ib - x; + const int sz = 4 + mb_width_log2(sb_type); + const int x = ib & ((1 << sz) - 1), y = ib - x; const TX_TYPE tx_type = (type == PLANE_TYPE_Y_WITH_DC) ? get_tx_type_16x16(xd, y + (x >> 2)) : DCT_DCT; if (type != PLANE_TYPE_UV) { @@ -787,7 +789,7 @@ static void stuff_b(VP9_COMP *cpi, const int nzc_used = get_nzc_used(tx_size); #endif - if (sb_type == BLOCK_SIZE_SB32X32) { + if (sb_type == BLOCK_SIZE_SB64X64) { a = (ENTROPY_CONTEXT *)xd->above_context + vp9_block2above_sb64[tx_size][ib]; l = (ENTROPY_CONTEXT *)xd->left_context + vp9_block2left_sb64[tx_size][ib];