michael@0: /* michael@0: * Copyright (c) 2010 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: michael@0: #include "treereader.h" michael@0: #include "vp8/common/entropymv.h" michael@0: #include "vp8/common/entropymode.h" michael@0: #include "onyxd_int.h" michael@0: #include "vp8/common/findnearmv.h" michael@0: michael@0: #if CONFIG_DEBUG michael@0: #include michael@0: #endif michael@0: static B_PREDICTION_MODE read_bmode(vp8_reader *bc, const vp8_prob *p) michael@0: { michael@0: const int i = vp8_treed_read(bc, vp8_bmode_tree, p); michael@0: michael@0: return (B_PREDICTION_MODE)i; michael@0: } michael@0: michael@0: static MB_PREDICTION_MODE read_ymode(vp8_reader *bc, const vp8_prob *p) michael@0: { michael@0: const int i = vp8_treed_read(bc, vp8_ymode_tree, p); michael@0: michael@0: return (MB_PREDICTION_MODE)i; michael@0: } michael@0: michael@0: static MB_PREDICTION_MODE read_kf_ymode(vp8_reader *bc, const vp8_prob *p) michael@0: { michael@0: const int i = vp8_treed_read(bc, vp8_kf_ymode_tree, p); michael@0: michael@0: return (MB_PREDICTION_MODE)i; michael@0: } michael@0: michael@0: static MB_PREDICTION_MODE read_uv_mode(vp8_reader *bc, const vp8_prob *p) michael@0: { michael@0: const int i = vp8_treed_read(bc, vp8_uv_mode_tree, p); michael@0: michael@0: return (MB_PREDICTION_MODE)i; michael@0: } michael@0: michael@0: static void read_kf_modes(VP8D_COMP *pbi, MODE_INFO *mi) michael@0: { michael@0: vp8_reader *const bc = & pbi->mbc[8]; michael@0: const int mis = pbi->common.mode_info_stride; michael@0: michael@0: mi->mbmi.ref_frame = INTRA_FRAME; michael@0: mi->mbmi.mode = read_kf_ymode(bc, vp8_kf_ymode_prob); michael@0: michael@0: if (mi->mbmi.mode == B_PRED) michael@0: { michael@0: int i = 0; michael@0: mi->mbmi.is_4x4 = 1; michael@0: michael@0: do michael@0: { michael@0: const B_PREDICTION_MODE A = above_block_mode(mi, i, mis); michael@0: const B_PREDICTION_MODE L = left_block_mode(mi, i); michael@0: michael@0: mi->bmi[i].as_mode = michael@0: read_bmode(bc, vp8_kf_bmode_prob [A] [L]); michael@0: } michael@0: while (++i < 16); michael@0: } michael@0: michael@0: mi->mbmi.uv_mode = read_uv_mode(bc, vp8_kf_uv_mode_prob); michael@0: } michael@0: michael@0: static int read_mvcomponent(vp8_reader *r, const MV_CONTEXT *mvc) michael@0: { michael@0: const vp8_prob *const p = (const vp8_prob *) mvc; michael@0: int x = 0; michael@0: michael@0: if (vp8_read(r, p [mvpis_short])) /* Large */ michael@0: { michael@0: int i = 0; michael@0: michael@0: do michael@0: { michael@0: x += vp8_read(r, p [MVPbits + i]) << i; michael@0: } michael@0: while (++i < 3); michael@0: michael@0: i = mvlong_width - 1; /* Skip bit 3, which is sometimes implicit */ michael@0: michael@0: do michael@0: { michael@0: x += vp8_read(r, p [MVPbits + i]) << i; michael@0: } michael@0: while (--i > 3); michael@0: michael@0: if (!(x & 0xFFF0) || vp8_read(r, p [MVPbits + 3])) michael@0: x += 8; michael@0: } michael@0: else /* small */ michael@0: x = vp8_treed_read(r, vp8_small_mvtree, p + MVPshort); michael@0: michael@0: if (x && vp8_read(r, p [MVPsign])) michael@0: x = -x; michael@0: michael@0: return x; michael@0: } michael@0: michael@0: static void read_mv(vp8_reader *r, MV *mv, const MV_CONTEXT *mvc) michael@0: { michael@0: mv->row = (short)(read_mvcomponent(r, mvc) * 2); michael@0: mv->col = (short)(read_mvcomponent(r, ++mvc) * 2); michael@0: } michael@0: michael@0: michael@0: static void read_mvcontexts(vp8_reader *bc, MV_CONTEXT *mvc) michael@0: { michael@0: int i = 0; michael@0: michael@0: do michael@0: { michael@0: const vp8_prob *up = vp8_mv_update_probs[i].prob; michael@0: vp8_prob *p = (vp8_prob *)(mvc + i); michael@0: vp8_prob *const pstop = p + MVPcount; michael@0: michael@0: do michael@0: { michael@0: if (vp8_read(bc, *up++)) michael@0: { michael@0: const vp8_prob x = (vp8_prob)vp8_read_literal(bc, 7); michael@0: michael@0: *p = x ? x << 1 : 1; michael@0: } michael@0: } michael@0: while (++p < pstop); michael@0: } michael@0: while (++i < 2); michael@0: } michael@0: michael@0: static const unsigned char mbsplit_fill_count[4] = {8, 8, 4, 1}; michael@0: static const unsigned char mbsplit_fill_offset[4][16] = { michael@0: { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, michael@0: { 0, 1, 4, 5, 8, 9, 12, 13, 2, 3, 6, 7, 10, 11, 14, 15}, michael@0: { 0, 1, 4, 5, 2, 3, 6, 7, 8, 9, 12, 13, 10, 11, 14, 15}, michael@0: { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15} michael@0: }; michael@0: michael@0: michael@0: static void mb_mode_mv_init(VP8D_COMP *pbi) michael@0: { michael@0: vp8_reader *const bc = & pbi->mbc[8]; michael@0: MV_CONTEXT *const mvc = pbi->common.fc.mvc; michael@0: michael@0: #if CONFIG_ERROR_CONCEALMENT michael@0: /* Default is that no macroblock is corrupt, therefore we initialize michael@0: * mvs_corrupt_from_mb to something very big, which we can be sure is michael@0: * outside the frame. */ michael@0: pbi->mvs_corrupt_from_mb = UINT_MAX; michael@0: #endif michael@0: /* Read the mb_no_coeff_skip flag */ michael@0: pbi->common.mb_no_coeff_skip = (int)vp8_read_bit(bc); michael@0: michael@0: pbi->prob_skip_false = 0; michael@0: if (pbi->common.mb_no_coeff_skip) michael@0: pbi->prob_skip_false = (vp8_prob)vp8_read_literal(bc, 8); michael@0: michael@0: if(pbi->common.frame_type != KEY_FRAME) michael@0: { michael@0: pbi->prob_intra = (vp8_prob)vp8_read_literal(bc, 8); michael@0: pbi->prob_last = (vp8_prob)vp8_read_literal(bc, 8); michael@0: pbi->prob_gf = (vp8_prob)vp8_read_literal(bc, 8); michael@0: michael@0: if (vp8_read_bit(bc)) michael@0: { michael@0: int i = 0; michael@0: michael@0: do michael@0: { michael@0: pbi->common.fc.ymode_prob[i] = michael@0: (vp8_prob) vp8_read_literal(bc, 8); michael@0: } michael@0: while (++i < 4); michael@0: } michael@0: michael@0: if (vp8_read_bit(bc)) michael@0: { michael@0: int i = 0; michael@0: michael@0: do michael@0: { michael@0: pbi->common.fc.uv_mode_prob[i] = michael@0: (vp8_prob) vp8_read_literal(bc, 8); michael@0: } michael@0: while (++i < 3); michael@0: } michael@0: michael@0: read_mvcontexts(bc, mvc); michael@0: } michael@0: } michael@0: michael@0: const vp8_prob vp8_sub_mv_ref_prob3 [8][VP8_SUBMVREFS-1] = michael@0: { michael@0: { 147, 136, 18 }, /* SUBMVREF_NORMAL */ michael@0: { 223, 1 , 34 }, /* SUBMVREF_LEFT_ABOVE_SAME */ michael@0: { 106, 145, 1 }, /* SUBMVREF_LEFT_ZED */ michael@0: { 208, 1 , 1 }, /* SUBMVREF_LEFT_ABOVE_ZED */ michael@0: { 179, 121, 1 }, /* SUBMVREF_ABOVE_ZED */ michael@0: { 223, 1 , 34 }, /* SUBMVREF_LEFT_ABOVE_SAME */ michael@0: { 179, 121, 1 }, /* SUBMVREF_ABOVE_ZED */ michael@0: { 208, 1 , 1 } /* SUBMVREF_LEFT_ABOVE_ZED */ michael@0: }; michael@0: michael@0: static michael@0: const vp8_prob * get_sub_mv_ref_prob(const int left, const int above) michael@0: { michael@0: int lez = (left == 0); michael@0: int aez = (above == 0); michael@0: int lea = (left == above); michael@0: const vp8_prob * prob; michael@0: michael@0: prob = vp8_sub_mv_ref_prob3[(aez << 2) | michael@0: (lez << 1) | michael@0: (lea)]; michael@0: michael@0: return prob; michael@0: } michael@0: michael@0: static void decode_split_mv(vp8_reader *const bc, MODE_INFO *mi, michael@0: const MODE_INFO *left_mb, const MODE_INFO *above_mb, michael@0: MB_MODE_INFO *mbmi, int_mv best_mv, michael@0: MV_CONTEXT *const mvc, int mb_to_left_edge, michael@0: int mb_to_right_edge, int mb_to_top_edge, michael@0: int mb_to_bottom_edge) michael@0: { michael@0: int s; /* split configuration (16x8, 8x16, 8x8, 4x4) */ michael@0: int num_p; /* number of partitions in the split configuration michael@0: (see vp8_mbsplit_count) */ michael@0: int j = 0; michael@0: michael@0: s = 3; michael@0: num_p = 16; michael@0: if( vp8_read(bc, 110) ) michael@0: { michael@0: s = 2; michael@0: num_p = 4; michael@0: if( vp8_read(bc, 111) ) michael@0: { michael@0: s = vp8_read(bc, 150); michael@0: num_p = 2; michael@0: } michael@0: } michael@0: michael@0: do /* for each subset j */ michael@0: { michael@0: int_mv leftmv, abovemv; michael@0: int_mv blockmv; michael@0: int k; /* first block in subset j */ michael@0: michael@0: const vp8_prob *prob; michael@0: k = vp8_mbsplit_offset[s][j]; michael@0: michael@0: if (!(k & 3)) michael@0: { michael@0: /* On L edge, get from MB to left of us */ michael@0: if(left_mb->mbmi.mode != SPLITMV) michael@0: leftmv.as_int = left_mb->mbmi.mv.as_int; michael@0: else michael@0: leftmv.as_int = (left_mb->bmi + k + 4 - 1)->mv.as_int; michael@0: } michael@0: else michael@0: leftmv.as_int = (mi->bmi + k - 1)->mv.as_int; michael@0: michael@0: if (!(k >> 2)) michael@0: { michael@0: /* On top edge, get from MB above us */ michael@0: if(above_mb->mbmi.mode != SPLITMV) michael@0: abovemv.as_int = above_mb->mbmi.mv.as_int; michael@0: else michael@0: abovemv.as_int = (above_mb->bmi + k + 16 - 4)->mv.as_int; michael@0: } michael@0: else michael@0: abovemv.as_int = (mi->bmi + k - 4)->mv.as_int; michael@0: michael@0: prob = get_sub_mv_ref_prob(leftmv.as_int, abovemv.as_int); michael@0: michael@0: if( vp8_read(bc, prob[0]) ) michael@0: { michael@0: if( vp8_read(bc, prob[1]) ) michael@0: { michael@0: blockmv.as_int = 0; michael@0: if( vp8_read(bc, prob[2]) ) michael@0: { michael@0: blockmv.as_mv.row = read_mvcomponent(bc, &mvc[0]) * 2; michael@0: blockmv.as_mv.row += best_mv.as_mv.row; michael@0: blockmv.as_mv.col = read_mvcomponent(bc, &mvc[1]) * 2; michael@0: blockmv.as_mv.col += best_mv.as_mv.col; michael@0: } michael@0: } michael@0: else michael@0: { michael@0: blockmv.as_int = abovemv.as_int; michael@0: } michael@0: } michael@0: else michael@0: { michael@0: blockmv.as_int = leftmv.as_int; michael@0: } michael@0: michael@0: mbmi->need_to_clamp_mvs |= vp8_check_mv_bounds(&blockmv, michael@0: mb_to_left_edge, michael@0: mb_to_right_edge, michael@0: mb_to_top_edge, michael@0: mb_to_bottom_edge); michael@0: michael@0: { michael@0: /* Fill (uniform) modes, mvs of jth subset. michael@0: Must do it here because ensuing subsets can michael@0: refer back to us via "left" or "above". */ michael@0: const unsigned char *fill_offset; michael@0: unsigned int fill_count = mbsplit_fill_count[s]; michael@0: michael@0: fill_offset = &mbsplit_fill_offset[s] michael@0: [(unsigned char)j * mbsplit_fill_count[s]]; michael@0: michael@0: do { michael@0: mi->bmi[ *fill_offset].mv.as_int = blockmv.as_int; michael@0: fill_offset++; michael@0: }while (--fill_count); michael@0: } michael@0: michael@0: } michael@0: while (++j < num_p); michael@0: michael@0: mbmi->partitioning = s; michael@0: } michael@0: michael@0: static void read_mb_modes_mv(VP8D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi) michael@0: { michael@0: vp8_reader *const bc = & pbi->mbc[8]; michael@0: mbmi->ref_frame = (MV_REFERENCE_FRAME) vp8_read(bc, pbi->prob_intra); michael@0: if (mbmi->ref_frame) /* inter MB */ michael@0: { michael@0: enum {CNT_INTRA, CNT_NEAREST, CNT_NEAR, CNT_SPLITMV}; michael@0: int cnt[4]; michael@0: int *cntx = cnt; michael@0: int_mv near_mvs[4]; michael@0: int_mv *nmv = near_mvs; michael@0: const int mis = pbi->mb.mode_info_stride; michael@0: const MODE_INFO *above = mi - mis; michael@0: const MODE_INFO *left = mi - 1; michael@0: const MODE_INFO *aboveleft = above - 1; michael@0: int *ref_frame_sign_bias = pbi->common.ref_frame_sign_bias; michael@0: michael@0: mbmi->need_to_clamp_mvs = 0; michael@0: michael@0: if (vp8_read(bc, pbi->prob_last)) michael@0: { michael@0: mbmi->ref_frame = michael@0: (MV_REFERENCE_FRAME)((int)(2 + vp8_read(bc, pbi->prob_gf))); michael@0: } michael@0: michael@0: /* Zero accumulators */ michael@0: nmv[0].as_int = nmv[1].as_int = nmv[2].as_int = 0; michael@0: cnt[0] = cnt[1] = cnt[2] = cnt[3] = 0; michael@0: michael@0: /* Process above */ michael@0: if (above->mbmi.ref_frame != INTRA_FRAME) michael@0: { michael@0: if (above->mbmi.mv.as_int) michael@0: { michael@0: (++nmv)->as_int = above->mbmi.mv.as_int; michael@0: mv_bias(ref_frame_sign_bias[above->mbmi.ref_frame], michael@0: mbmi->ref_frame, nmv, ref_frame_sign_bias); michael@0: ++cntx; michael@0: } michael@0: michael@0: *cntx += 2; michael@0: } michael@0: michael@0: /* Process left */ michael@0: if (left->mbmi.ref_frame != INTRA_FRAME) michael@0: { michael@0: if (left->mbmi.mv.as_int) michael@0: { michael@0: int_mv this_mv; michael@0: michael@0: this_mv.as_int = left->mbmi.mv.as_int; michael@0: mv_bias(ref_frame_sign_bias[left->mbmi.ref_frame], michael@0: mbmi->ref_frame, &this_mv, ref_frame_sign_bias); michael@0: michael@0: if (this_mv.as_int != nmv->as_int) michael@0: { michael@0: (++nmv)->as_int = this_mv.as_int; michael@0: ++cntx; michael@0: } michael@0: michael@0: *cntx += 2; michael@0: } michael@0: else michael@0: cnt[CNT_INTRA] += 2; michael@0: } michael@0: michael@0: /* Process above left */ michael@0: if (aboveleft->mbmi.ref_frame != INTRA_FRAME) michael@0: { michael@0: if (aboveleft->mbmi.mv.as_int) michael@0: { michael@0: int_mv this_mv; michael@0: michael@0: this_mv.as_int = aboveleft->mbmi.mv.as_int; michael@0: mv_bias(ref_frame_sign_bias[aboveleft->mbmi.ref_frame], michael@0: mbmi->ref_frame, &this_mv, ref_frame_sign_bias); michael@0: michael@0: if (this_mv.as_int != nmv->as_int) michael@0: { michael@0: (++nmv)->as_int = this_mv.as_int; michael@0: ++cntx; michael@0: } michael@0: michael@0: *cntx += 1; michael@0: } michael@0: else michael@0: cnt[CNT_INTRA] += 1; michael@0: } michael@0: michael@0: if( vp8_read(bc, vp8_mode_contexts [cnt[CNT_INTRA]] [0]) ) michael@0: { michael@0: michael@0: /* If we have three distinct MV's ... */ michael@0: /* See if above-left MV can be merged with NEAREST */ michael@0: cnt[CNT_NEAREST] += ( (cnt[CNT_SPLITMV] > 0) & michael@0: (nmv->as_int == near_mvs[CNT_NEAREST].as_int)); michael@0: michael@0: /* Swap near and nearest if necessary */ michael@0: if (cnt[CNT_NEAR] > cnt[CNT_NEAREST]) michael@0: { michael@0: int tmp; michael@0: tmp = cnt[CNT_NEAREST]; michael@0: cnt[CNT_NEAREST] = cnt[CNT_NEAR]; michael@0: cnt[CNT_NEAR] = tmp; michael@0: tmp = near_mvs[CNT_NEAREST].as_int; michael@0: near_mvs[CNT_NEAREST].as_int = near_mvs[CNT_NEAR].as_int; michael@0: near_mvs[CNT_NEAR].as_int = tmp; michael@0: } michael@0: michael@0: if( vp8_read(bc, vp8_mode_contexts [cnt[CNT_NEAREST]] [1]) ) michael@0: { michael@0: michael@0: if( vp8_read(bc, vp8_mode_contexts [cnt[CNT_NEAR]] [2]) ) michael@0: { michael@0: int mb_to_top_edge; michael@0: int mb_to_bottom_edge; michael@0: int mb_to_left_edge; michael@0: int mb_to_right_edge; michael@0: MV_CONTEXT *const mvc = pbi->common.fc.mvc; michael@0: int near_index; michael@0: michael@0: mb_to_top_edge = pbi->mb.mb_to_top_edge; michael@0: mb_to_bottom_edge = pbi->mb.mb_to_bottom_edge; michael@0: mb_to_top_edge -= LEFT_TOP_MARGIN; michael@0: mb_to_bottom_edge += RIGHT_BOTTOM_MARGIN; michael@0: mb_to_right_edge = pbi->mb.mb_to_right_edge; michael@0: mb_to_right_edge += RIGHT_BOTTOM_MARGIN; michael@0: mb_to_left_edge = pbi->mb.mb_to_left_edge; michael@0: mb_to_left_edge -= LEFT_TOP_MARGIN; michael@0: michael@0: /* Use near_mvs[0] to store the "best" MV */ michael@0: near_index = CNT_INTRA + michael@0: (cnt[CNT_NEAREST] >= cnt[CNT_INTRA]); michael@0: michael@0: vp8_clamp_mv2(&near_mvs[near_index], &pbi->mb); michael@0: michael@0: cnt[CNT_SPLITMV] = ((above->mbmi.mode == SPLITMV) michael@0: + (left->mbmi.mode == SPLITMV)) * 2 michael@0: + (aboveleft->mbmi.mode == SPLITMV); michael@0: michael@0: if( vp8_read(bc, vp8_mode_contexts [cnt[CNT_SPLITMV]] [3]) ) michael@0: { michael@0: decode_split_mv(bc, mi, left, above, michael@0: mbmi, michael@0: near_mvs[near_index], michael@0: mvc, mb_to_left_edge, michael@0: mb_to_right_edge, michael@0: mb_to_top_edge, michael@0: mb_to_bottom_edge); michael@0: mbmi->mv.as_int = mi->bmi[15].mv.as_int; michael@0: mbmi->mode = SPLITMV; michael@0: mbmi->is_4x4 = 1; michael@0: } michael@0: else michael@0: { michael@0: int_mv *const mbmi_mv = & mbmi->mv; michael@0: read_mv(bc, &mbmi_mv->as_mv, (const MV_CONTEXT *) mvc); michael@0: mbmi_mv->as_mv.row += near_mvs[near_index].as_mv.row; michael@0: mbmi_mv->as_mv.col += near_mvs[near_index].as_mv.col; michael@0: michael@0: /* Don't need to check this on NEARMV and NEARESTMV michael@0: * modes since those modes clamp the MV. The NEWMV mode michael@0: * does not, so signal to the prediction stage whether michael@0: * special handling may be required. michael@0: */ michael@0: mbmi->need_to_clamp_mvs = michael@0: vp8_check_mv_bounds(mbmi_mv, mb_to_left_edge, michael@0: mb_to_right_edge, michael@0: mb_to_top_edge, michael@0: mb_to_bottom_edge); michael@0: mbmi->mode = NEWMV; michael@0: } michael@0: } michael@0: else michael@0: { michael@0: mbmi->mode = NEARMV; michael@0: mbmi->mv.as_int = near_mvs[CNT_NEAR].as_int; michael@0: vp8_clamp_mv2(&mbmi->mv, &pbi->mb); michael@0: } michael@0: } michael@0: else michael@0: { michael@0: mbmi->mode = NEARESTMV; michael@0: mbmi->mv.as_int = near_mvs[CNT_NEAREST].as_int; michael@0: vp8_clamp_mv2(&mbmi->mv, &pbi->mb); michael@0: } michael@0: } michael@0: else michael@0: { michael@0: mbmi->mode = ZEROMV; michael@0: mbmi->mv.as_int = 0; michael@0: } michael@0: michael@0: #if CONFIG_ERROR_CONCEALMENT michael@0: if(pbi->ec_enabled && (mbmi->mode != SPLITMV)) michael@0: { michael@0: mi->bmi[ 0].mv.as_int = michael@0: mi->bmi[ 1].mv.as_int = michael@0: mi->bmi[ 2].mv.as_int = michael@0: mi->bmi[ 3].mv.as_int = michael@0: mi->bmi[ 4].mv.as_int = michael@0: mi->bmi[ 5].mv.as_int = michael@0: mi->bmi[ 6].mv.as_int = michael@0: mi->bmi[ 7].mv.as_int = michael@0: mi->bmi[ 8].mv.as_int = michael@0: mi->bmi[ 9].mv.as_int = michael@0: mi->bmi[10].mv.as_int = michael@0: mi->bmi[11].mv.as_int = michael@0: mi->bmi[12].mv.as_int = michael@0: mi->bmi[13].mv.as_int = michael@0: mi->bmi[14].mv.as_int = michael@0: mi->bmi[15].mv.as_int = mbmi->mv.as_int; michael@0: } michael@0: #endif michael@0: } michael@0: else michael@0: { michael@0: /* required for left and above block mv */ michael@0: mbmi->mv.as_int = 0; michael@0: michael@0: /* MB is intra coded */ michael@0: if ((mbmi->mode = read_ymode(bc, pbi->common.fc.ymode_prob)) == B_PRED) michael@0: { michael@0: int j = 0; michael@0: mbmi->is_4x4 = 1; michael@0: do michael@0: { michael@0: mi->bmi[j].as_mode = read_bmode(bc, pbi->common.fc.bmode_prob); michael@0: } michael@0: while (++j < 16); michael@0: } michael@0: michael@0: mbmi->uv_mode = read_uv_mode(bc, pbi->common.fc.uv_mode_prob); michael@0: } michael@0: michael@0: } michael@0: michael@0: static void read_mb_features(vp8_reader *r, MB_MODE_INFO *mi, MACROBLOCKD *x) michael@0: { michael@0: /* Is segmentation enabled */ michael@0: if (x->segmentation_enabled && x->update_mb_segmentation_map) michael@0: { michael@0: /* If so then read the segment id. */ michael@0: if (vp8_read(r, x->mb_segment_tree_probs[0])) michael@0: mi->segment_id = michael@0: (unsigned char)(2 + vp8_read(r, x->mb_segment_tree_probs[2])); michael@0: else michael@0: mi->segment_id = michael@0: (unsigned char)(vp8_read(r, x->mb_segment_tree_probs[1])); michael@0: } michael@0: } michael@0: michael@0: static void decode_mb_mode_mvs(VP8D_COMP *pbi, MODE_INFO *mi, michael@0: MB_MODE_INFO *mbmi) michael@0: { michael@0: /* Read the Macroblock segmentation map if it is being updated explicitly michael@0: * this frame (reset to 0 above by default) michael@0: * By default on a key frame reset all MBs to segment 0 michael@0: */ michael@0: if (pbi->mb.update_mb_segmentation_map) michael@0: read_mb_features(&pbi->mbc[8], &mi->mbmi, &pbi->mb); michael@0: else if(pbi->common.frame_type == KEY_FRAME) michael@0: mi->mbmi.segment_id = 0; michael@0: michael@0: /* Read the macroblock coeff skip flag if this feature is in use, michael@0: * else default to 0 */ michael@0: if (pbi->common.mb_no_coeff_skip) michael@0: mi->mbmi.mb_skip_coeff = vp8_read(&pbi->mbc[8], pbi->prob_skip_false); michael@0: else michael@0: mi->mbmi.mb_skip_coeff = 0; michael@0: michael@0: mi->mbmi.is_4x4 = 0; michael@0: if(pbi->common.frame_type == KEY_FRAME) michael@0: read_kf_modes(pbi, mi); michael@0: else michael@0: read_mb_modes_mv(pbi, mi, &mi->mbmi); michael@0: michael@0: } michael@0: michael@0: void vp8_decode_mode_mvs(VP8D_COMP *pbi) michael@0: { michael@0: MODE_INFO *mi = pbi->common.mi; michael@0: int mb_row = -1; michael@0: int mb_to_right_edge_start; michael@0: michael@0: mb_mode_mv_init(pbi); michael@0: michael@0: pbi->mb.mb_to_top_edge = 0; michael@0: pbi->mb.mb_to_bottom_edge = ((pbi->common.mb_rows - 1) * 16) << 3; michael@0: mb_to_right_edge_start = ((pbi->common.mb_cols - 1) * 16) << 3; michael@0: michael@0: while (++mb_row < pbi->common.mb_rows) michael@0: { michael@0: int mb_col = -1; michael@0: michael@0: pbi->mb.mb_to_left_edge = 0; michael@0: pbi->mb.mb_to_right_edge = mb_to_right_edge_start; michael@0: michael@0: while (++mb_col < pbi->common.mb_cols) michael@0: { michael@0: #if CONFIG_ERROR_CONCEALMENT michael@0: int mb_num = mb_row * pbi->common.mb_cols + mb_col; michael@0: #endif michael@0: michael@0: decode_mb_mode_mvs(pbi, mi, &mi->mbmi); michael@0: michael@0: #if CONFIG_ERROR_CONCEALMENT michael@0: /* look for corruption. set mvs_corrupt_from_mb to the current michael@0: * mb_num if the frame is corrupt from this macroblock. */ michael@0: if (vp8dx_bool_error(&pbi->mbc[8]) && mb_num < michael@0: (int)pbi->mvs_corrupt_from_mb) michael@0: { michael@0: pbi->mvs_corrupt_from_mb = mb_num; michael@0: /* no need to continue since the partition is corrupt from michael@0: * here on. michael@0: */ michael@0: return; michael@0: } michael@0: #endif michael@0: michael@0: pbi->mb.mb_to_left_edge -= (16 << 3); michael@0: pbi->mb.mb_to_right_edge -= (16 << 3); michael@0: mi++; /* next macroblock */ michael@0: } michael@0: pbi->mb.mb_to_top_edge -= (16 << 3); michael@0: pbi->mb.mb_to_bottom_edge -= (16 << 3); michael@0: michael@0: mi++; /* skip left predictor each row */ michael@0: } michael@0: }