Coverage Report

Created: 2026-09-01 06:54

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libvpx/vp8/decoder/decodemv.c
Line
Count
Source
1
/*
2
 *  Copyright (c) 2010 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
#include "decodemv.h"
12
#include "treereader.h"
13
#include "vp8/common/entropymv.h"
14
#include "vp8/common/entropymode.h"
15
#include "onyxd_int.h"
16
#include "vp8/common/findnearmv.h"
17
18
3.22G
static B_PREDICTION_MODE read_bmode(vp8_reader *bc, const vp8_prob *p) {
19
3.22G
  const int i = vp8_treed_read(bc, vp8_bmode_tree, p);
20
21
3.22G
  return (B_PREDICTION_MODE)i;
22
3.22G
}
23
24
8.15M
static MB_PREDICTION_MODE read_ymode(vp8_reader *bc, const vp8_prob *p) {
25
8.15M
  const int i = vp8_treed_read(bc, vp8_ymode_tree, p);
26
27
8.15M
  return (MB_PREDICTION_MODE)i;
28
8.15M
}
29
30
205M
static MB_PREDICTION_MODE read_kf_ymode(vp8_reader *bc, const vp8_prob *p) {
31
205M
  const int i = vp8_treed_read(bc, vp8_kf_ymode_tree, p);
32
33
205M
  return (MB_PREDICTION_MODE)i;
34
205M
}
35
36
213M
static MB_PREDICTION_MODE read_uv_mode(vp8_reader *bc, const vp8_prob *p) {
37
213M
  const int i = vp8_treed_read(bc, vp8_uv_mode_tree, p);
38
39
213M
  return (MB_PREDICTION_MODE)i;
40
213M
}
41
42
205M
static void read_kf_modes(VP8D_COMP *pbi, MODE_INFO *mi) {
43
205M
  vp8_reader *const bc = &pbi->mbc[8];
44
205M
  const int mis = pbi->common.mode_info_stride;
45
46
205M
  mi->mbmi.ref_frame = INTRA_FRAME;
47
205M
  mi->mbmi.mode = read_kf_ymode(bc, vp8_kf_ymode_prob);
48
49
205M
  if (mi->mbmi.mode == B_PRED) {
50
201M
    int i = 0;
51
201M
    mi->mbmi.is_4x4 = 1;
52
53
3.22G
    do {
54
3.22G
      const B_PREDICTION_MODE A = above_block_mode(mi, i, mis);
55
3.22G
      const B_PREDICTION_MODE L = left_block_mode(mi, i);
56
57
3.22G
      mi->bmi[i].as_mode = read_bmode(bc, vp8_kf_bmode_prob[A][L]);
58
3.22G
    } while (++i < 16);
59
201M
  }
60
61
205M
  mi->mbmi.uv_mode = read_uv_mode(bc, vp8_kf_uv_mode_prob);
62
205M
}
63
64
3.25M
static int read_mvcomponent(vp8_reader *r, const MV_CONTEXT *mvc) {
65
3.25M
  const vp8_prob *const p = (const vp8_prob *)mvc;
66
3.25M
  int x = 0;
67
68
3.25M
  if (vp8_read(r, p[mvpis_short])) { /* Large */
69
1.25M
    int i = 0;
70
71
3.75M
    do {
72
3.75M
      x += vp8_read(r, p[MVPbits + i]) << i;
73
3.75M
    } while (++i < 3);
74
75
1.25M
    i = mvlong_width - 1; /* Skip bit 3, which is sometimes implicit */
76
77
7.50M
    do {
78
7.50M
      x += vp8_read(r, p[MVPbits + i]) << i;
79
7.50M
    } while (--i > 3);
80
81
1.25M
    if (!(x & 0xFFF0) || vp8_read(r, p[MVPbits + 3])) x += 8;
82
2.00M
  } else { /* small */
83
2.00M
    x = vp8_treed_read(r, vp8_small_mvtree, p + MVPshort);
84
2.00M
  }
85
86
3.25M
  if (x && vp8_read(r, p[MVPsign])) x = -x;
87
88
3.25M
  return x;
89
3.25M
}
90
91
712k
static void read_mv(vp8_reader *r, MV *mv, const MV_CONTEXT *mvc) {
92
712k
  mv->row = (short)(read_mvcomponent(r, mvc) * 2);
93
712k
  mv->col = (short)(read_mvcomponent(r, ++mvc) * 2);
94
712k
}
95
96
153k
static void read_mvcontexts(vp8_reader *bc, MV_CONTEXT *mvc) {
97
153k
  int i = 0;
98
99
306k
  do {
100
306k
    const vp8_prob *up = vp8_mv_update_probs[i].prob;
101
306k
    vp8_prob *p = (vp8_prob *)(mvc + i);
102
306k
    vp8_prob *const pstop = p + MVPcount;
103
104
5.81M
    do {
105
5.81M
      if (vp8_read(bc, *up++)) {
106
85.7k
        const vp8_prob x = (vp8_prob)vp8_read_literal(bc, 7);
107
108
85.7k
        *p = x ? x << 1 : 1;
109
85.7k
      }
110
5.81M
    } while (++p < pstop);
111
306k
  } while (++i < 2);
112
153k
}
113
114
static const unsigned char mbsplit_fill_count[4] = { 8, 8, 4, 1 };
115
static const unsigned char mbsplit_fill_offset[4][16] = {
116
  { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
117
  { 0, 1, 4, 5, 8, 9, 12, 13, 2, 3, 6, 7, 10, 11, 14, 15 },
118
  { 0, 1, 4, 5, 2, 3, 6, 7, 8, 9, 12, 13, 10, 11, 14, 15 },
119
  { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }
120
};
121
122
193k
static void mb_mode_mv_init(VP8D_COMP *pbi) {
123
193k
  vp8_reader *const bc = &pbi->mbc[8];
124
193k
  MV_CONTEXT *const mvc = pbi->common.fc.mvc;
125
126
#if CONFIG_ERROR_CONCEALMENT
127
  /* Default is that no macroblock is corrupt, therefore we initialize
128
   * mvs_corrupt_from_mb to something very big, which we can be sure is
129
   * outside the frame. */
130
  pbi->mvs_corrupt_from_mb = UINT_MAX;
131
#endif
132
  /* Read the mb_no_coeff_skip flag */
133
193k
  pbi->common.mb_no_coeff_skip = (int)vp8_read_bit(bc);
134
135
193k
  pbi->prob_skip_false = 0;
136
193k
  if (pbi->common.mb_no_coeff_skip) {
137
60.4k
    pbi->prob_skip_false = (vp8_prob)vp8_read_literal(bc, 8);
138
60.4k
  }
139
140
193k
  if (pbi->common.frame_type != KEY_FRAME) {
141
153k
    pbi->prob_intra = (vp8_prob)vp8_read_literal(bc, 8);
142
153k
    pbi->prob_last = (vp8_prob)vp8_read_literal(bc, 8);
143
153k
    pbi->prob_gf = (vp8_prob)vp8_read_literal(bc, 8);
144
145
153k
    if (vp8_read_bit(bc)) {
146
60.4k
      int i = 0;
147
148
241k
      do {
149
241k
        pbi->common.fc.ymode_prob[i] = (vp8_prob)vp8_read_literal(bc, 8);
150
241k
      } while (++i < 4);
151
60.4k
    }
152
153
153k
    if (vp8_read_bit(bc)) {
154
52.9k
      int i = 0;
155
156
158k
      do {
157
158k
        pbi->common.fc.uv_mode_prob[i] = (vp8_prob)vp8_read_literal(bc, 8);
158
158k
      } while (++i < 3);
159
52.9k
    }
160
161
153k
    read_mvcontexts(bc, mvc);
162
153k
  }
163
193k
}
164
165
const vp8_prob vp8_sub_mv_ref_prob3[8][VP8_SUBMVREFS - 1] = {
166
  { 147, 136, 18 }, /* SUBMVREF_NORMAL          */
167
  { 223, 1, 34 },   /* SUBMVREF_LEFT_ABOVE_SAME */
168
  { 106, 145, 1 },  /* SUBMVREF_LEFT_ZED        */
169
  { 208, 1, 1 },    /* SUBMVREF_LEFT_ABOVE_ZED  */
170
  { 179, 121, 1 },  /* SUBMVREF_ABOVE_ZED       */
171
  { 223, 1, 34 },   /* SUBMVREF_LEFT_ABOVE_SAME */
172
  { 179, 121, 1 },  /* SUBMVREF_ABOVE_ZED       */
173
  { 208, 1, 1 }     /* SUBMVREF_LEFT_ABOVE_ZED  */
174
};
175
176
static const vp8_prob *get_sub_mv_ref_prob(const uint32_t left,
177
4.70M
                                           const uint32_t above) {
178
4.70M
  int lez = (left == 0);
179
4.70M
  int aez = (above == 0);
180
4.70M
  int lea = (left == above);
181
4.70M
  const vp8_prob *prob;
182
183
4.70M
  prob = vp8_sub_mv_ref_prob3[(aez << 2) | (lez << 1) | (lea)];
184
185
4.70M
  return prob;
186
4.70M
}
187
188
static void decode_split_mv(vp8_reader *const bc, MODE_INFO *mi,
189
                            const MODE_INFO *left_mb, const MODE_INFO *above_mb,
190
                            MB_MODE_INFO *mbmi, int_mv best_mv,
191
                            MV_CONTEXT *const mvc, int mb_to_left_edge,
192
                            int mb_to_right_edge, int mb_to_top_edge,
193
618k
                            int mb_to_bottom_edge) {
194
618k
  int s; /* split configuration (16x8, 8x16, 8x8, 4x4) */
195
  /* number of partitions in the split configuration (see vp8_mbsplit_count) */
196
618k
  int num_p;
197
618k
  int j = 0;
198
199
618k
  s = 3;
200
618k
  num_p = 16;
201
618k
  if (vp8_read(bc, 110)) {
202
392k
    s = 2;
203
392k
    num_p = 4;
204
392k
    if (vp8_read(bc, 111)) {
205
244k
      s = vp8_read(bc, 150);
206
244k
      num_p = 2;
207
244k
    }
208
392k
  }
209
210
618k
  do /* for each subset j */
211
4.70M
  {
212
4.70M
    int_mv leftmv, abovemv;
213
4.70M
    int_mv blockmv;
214
4.70M
    int k; /* first block in subset j */
215
216
4.70M
    const vp8_prob *prob;
217
4.70M
    k = vp8_mbsplit_offset[s][j];
218
219
4.70M
    if (!(k & 3)) {
220
      /* On L edge, get from MB to left of us */
221
1.58M
      if (left_mb->mbmi.mode != SPLITMV) {
222
1.14M
        leftmv.as_int = left_mb->mbmi.mv.as_int;
223
1.14M
      } else {
224
432k
        leftmv.as_int = (left_mb->bmi + k + 4 - 1)->mv.as_int;
225
432k
      }
226
3.11M
    } else {
227
3.11M
      leftmv.as_int = (mi->bmi + k - 1)->mv.as_int;
228
3.11M
    }
229
230
4.70M
    if (!(k >> 2)) {
231
      /* On top edge, get from MB above us */
232
1.55M
      if (above_mb->mbmi.mode != SPLITMV) {
233
1.09M
        abovemv.as_int = above_mb->mbmi.mv.as_int;
234
1.09M
      } else {
235
462k
        abovemv.as_int = (above_mb->bmi + k + 16 - 4)->mv.as_int;
236
462k
      }
237
3.14M
    } else {
238
3.14M
      abovemv.as_int = (mi->bmi + k - 4)->mv.as_int;
239
3.14M
    }
240
241
4.70M
    prob = get_sub_mv_ref_prob(leftmv.as_int, abovemv.as_int);
242
243
4.70M
    if (vp8_read(bc, prob[0])) {
244
1.53M
      if (vp8_read(bc, prob[1])) {
245
954k
        blockmv.as_int = 0;
246
954k
        if (vp8_read(bc, prob[2])) {
247
916k
          blockmv.as_mv.row = read_mvcomponent(bc, &mvc[0]) * 2;
248
916k
          blockmv.as_mv.row += best_mv.as_mv.row;
249
916k
          blockmv.as_mv.col = read_mvcomponent(bc, &mvc[1]) * 2;
250
916k
          blockmv.as_mv.col += best_mv.as_mv.col;
251
916k
        }
252
954k
      } else {
253
585k
        blockmv.as_int = abovemv.as_int;
254
585k
      }
255
3.16M
    } else {
256
3.16M
      blockmv.as_int = leftmv.as_int;
257
3.16M
    }
258
259
4.70M
    mbmi->need_to_clamp_mvs |=
260
4.70M
        vp8_check_mv_bounds(&blockmv, mb_to_left_edge, mb_to_right_edge,
261
4.70M
                            mb_to_top_edge, mb_to_bottom_edge);
262
263
4.70M
    {
264
      /* Fill (uniform) modes, mvs of jth subset.
265
       Must do it here because ensuing subsets can
266
       refer back to us via "left" or "above". */
267
4.70M
      const unsigned char *fill_offset;
268
4.70M
      unsigned int fill_count = mbsplit_fill_count[s];
269
270
4.70M
      fill_offset =
271
4.70M
          &mbsplit_fill_offset[s][(unsigned char)j * mbsplit_fill_count[s]];
272
273
9.89M
      do {
274
9.89M
        mi->bmi[*fill_offset].mv.as_int = blockmv.as_int;
275
9.89M
        fill_offset++;
276
9.89M
      } while (--fill_count);
277
4.70M
    }
278
279
4.70M
  } while (++j < num_p);
280
281
618k
  mbmi->partitioning = s;
282
618k
}
283
284
static void read_mb_modes_mv(VP8D_COMP *pbi, MODE_INFO *mi,
285
14.0M
                             MB_MODE_INFO *mbmi) {
286
14.0M
  vp8_reader *const bc = &pbi->mbc[8];
287
14.0M
  mbmi->ref_frame = (MV_REFERENCE_FRAME)vp8_read(bc, pbi->prob_intra);
288
14.0M
  if (mbmi->ref_frame) { /* inter MB */
289
5.89M
    enum { CNT_INTRA, CNT_NEAREST, CNT_NEAR, CNT_SPLITMV };
290
5.89M
    int cnt[4];
291
5.89M
    int *cntx = cnt;
292
5.89M
    int_mv near_mvs[4];
293
5.89M
    int_mv *nmv = near_mvs;
294
5.89M
    const int mis = pbi->mb.mode_info_stride;
295
5.89M
    const MODE_INFO *above = mi - mis;
296
5.89M
    const MODE_INFO *left = mi - 1;
297
5.89M
    const MODE_INFO *aboveleft = above - 1;
298
5.89M
    int *ref_frame_sign_bias = pbi->common.ref_frame_sign_bias;
299
300
5.89M
    mbmi->need_to_clamp_mvs = 0;
301
302
5.89M
    if (vp8_read(bc, pbi->prob_last)) {
303
1.77M
      mbmi->ref_frame =
304
1.77M
          (MV_REFERENCE_FRAME)((int)(2 + vp8_read(bc, pbi->prob_gf)));
305
1.77M
    }
306
307
    /* Zero accumulators */
308
5.89M
    nmv[0].as_int = nmv[1].as_int = nmv[2].as_int = 0;
309
5.89M
    cnt[0] = cnt[1] = cnt[2] = cnt[3] = 0;
310
311
    /* Process above */
312
5.89M
    if (above->mbmi.ref_frame != INTRA_FRAME) {
313
5.26M
      if (above->mbmi.mv.as_int) {
314
1.94M
        (++nmv)->as_int = above->mbmi.mv.as_int;
315
1.94M
        mv_bias(ref_frame_sign_bias[above->mbmi.ref_frame], mbmi->ref_frame,
316
1.94M
                nmv, ref_frame_sign_bias);
317
1.94M
        ++cntx;
318
1.94M
      }
319
320
5.26M
      *cntx += 2;
321
5.26M
    }
322
323
    /* Process left */
324
5.89M
    if (left->mbmi.ref_frame != INTRA_FRAME) {
325
5.22M
      if (left->mbmi.mv.as_int) {
326
1.90M
        int_mv this_mv;
327
328
1.90M
        this_mv.as_int = left->mbmi.mv.as_int;
329
1.90M
        mv_bias(ref_frame_sign_bias[left->mbmi.ref_frame], mbmi->ref_frame,
330
1.90M
                &this_mv, ref_frame_sign_bias);
331
332
1.90M
        if (this_mv.as_int != nmv->as_int) {
333
1.42M
          (++nmv)->as_int = this_mv.as_int;
334
1.42M
          ++cntx;
335
1.42M
        }
336
337
1.90M
        *cntx += 2;
338
3.31M
      } else {
339
3.31M
        cnt[CNT_INTRA] += 2;
340
3.31M
      }
341
5.22M
    }
342
343
    /* Process above left */
344
5.89M
    if (aboveleft->mbmi.ref_frame != INTRA_FRAME) {
345
4.85M
      if (aboveleft->mbmi.mv.as_int) {
346
1.68M
        int_mv this_mv;
347
348
1.68M
        this_mv.as_int = aboveleft->mbmi.mv.as_int;
349
1.68M
        mv_bias(ref_frame_sign_bias[aboveleft->mbmi.ref_frame], mbmi->ref_frame,
350
1.68M
                &this_mv, ref_frame_sign_bias);
351
352
1.68M
        if (this_mv.as_int != nmv->as_int) {
353
859k
          (++nmv)->as_int = this_mv.as_int;
354
859k
          ++cntx;
355
859k
        }
356
357
1.68M
        *cntx += 1;
358
3.17M
      } else {
359
3.17M
        cnt[CNT_INTRA] += 1;
360
3.17M
      }
361
4.85M
    }
362
363
5.89M
    if (vp8_read(bc, vp8_mode_contexts[cnt[CNT_INTRA]][0])) {
364
      /* If we have three distinct MV's ... */
365
      /* See if above-left MV can be merged with NEAREST */
366
2.50M
      cnt[CNT_NEAREST] += ((cnt[CNT_SPLITMV] > 0) &
367
2.50M
                           (nmv->as_int == near_mvs[CNT_NEAREST].as_int));
368
369
      /* Swap near and nearest if necessary */
370
2.50M
      if (cnt[CNT_NEAR] > cnt[CNT_NEAREST]) {
371
248k
        int tmp;
372
248k
        tmp = cnt[CNT_NEAREST];
373
248k
        cnt[CNT_NEAREST] = cnt[CNT_NEAR];
374
248k
        cnt[CNT_NEAR] = tmp;
375
248k
        tmp = (int)near_mvs[CNT_NEAREST].as_int;
376
248k
        near_mvs[CNT_NEAREST].as_int = near_mvs[CNT_NEAR].as_int;
377
248k
        near_mvs[CNT_NEAR].as_int = (uint32_t)tmp;
378
248k
      }
379
380
2.50M
      if (vp8_read(bc, vp8_mode_contexts[cnt[CNT_NEAREST]][1])) {
381
1.58M
        if (vp8_read(bc, vp8_mode_contexts[cnt[CNT_NEAR]][2])) {
382
1.33M
          int mb_to_top_edge;
383
1.33M
          int mb_to_bottom_edge;
384
1.33M
          int mb_to_left_edge;
385
1.33M
          int mb_to_right_edge;
386
1.33M
          MV_CONTEXT *const mvc = pbi->common.fc.mvc;
387
1.33M
          int near_index;
388
389
1.33M
          mb_to_top_edge = pbi->mb.mb_to_top_edge;
390
1.33M
          mb_to_bottom_edge = pbi->mb.mb_to_bottom_edge;
391
1.33M
          mb_to_top_edge -= LEFT_TOP_MARGIN;
392
1.33M
          mb_to_bottom_edge += RIGHT_BOTTOM_MARGIN;
393
1.33M
          mb_to_right_edge = pbi->mb.mb_to_right_edge;
394
1.33M
          mb_to_right_edge += RIGHT_BOTTOM_MARGIN;
395
1.33M
          mb_to_left_edge = pbi->mb.mb_to_left_edge;
396
1.33M
          mb_to_left_edge -= LEFT_TOP_MARGIN;
397
398
          /* Use near_mvs[0] to store the "best" MV */
399
1.33M
          near_index = CNT_INTRA + (cnt[CNT_NEAREST] >= cnt[CNT_INTRA]);
400
401
1.33M
          vp8_clamp_mv2(&near_mvs[near_index], &pbi->mb);
402
403
1.33M
          cnt[CNT_SPLITMV] =
404
1.33M
              ((above->mbmi.mode == SPLITMV) + (left->mbmi.mode == SPLITMV)) *
405
1.33M
                  2 +
406
1.33M
              (aboveleft->mbmi.mode == SPLITMV);
407
408
1.33M
          if (vp8_read(bc, vp8_mode_contexts[cnt[CNT_SPLITMV]][3])) {
409
618k
            decode_split_mv(bc, mi, left, above, mbmi, near_mvs[near_index],
410
618k
                            mvc, mb_to_left_edge, mb_to_right_edge,
411
618k
                            mb_to_top_edge, mb_to_bottom_edge);
412
618k
            mbmi->mv.as_int = mi->bmi[15].mv.as_int;
413
618k
            mbmi->mode = SPLITMV;
414
618k
            mbmi->is_4x4 = 1;
415
712k
          } else {
416
712k
            int_mv *const mbmi_mv = &mbmi->mv;
417
712k
            read_mv(bc, &mbmi_mv->as_mv, (const MV_CONTEXT *)mvc);
418
712k
            mbmi_mv->as_mv.row += near_mvs[near_index].as_mv.row;
419
712k
            mbmi_mv->as_mv.col += near_mvs[near_index].as_mv.col;
420
421
            /* Don't need to check this on NEARMV and NEARESTMV
422
             * modes since those modes clamp the MV. The NEWMV mode
423
             * does not, so signal to the prediction stage whether
424
             * special handling may be required.
425
             */
426
712k
            mbmi->need_to_clamp_mvs =
427
712k
                vp8_check_mv_bounds(mbmi_mv, mb_to_left_edge, mb_to_right_edge,
428
712k
                                    mb_to_top_edge, mb_to_bottom_edge);
429
712k
            mbmi->mode = NEWMV;
430
712k
          }
431
1.33M
        } else {
432
250k
          mbmi->mode = NEARMV;
433
250k
          mbmi->mv.as_int = near_mvs[CNT_NEAR].as_int;
434
250k
          vp8_clamp_mv2(&mbmi->mv, &pbi->mb);
435
250k
        }
436
1.58M
      } else {
437
922k
        mbmi->mode = NEARESTMV;
438
922k
        mbmi->mv.as_int = near_mvs[CNT_NEAREST].as_int;
439
922k
        vp8_clamp_mv2(&mbmi->mv, &pbi->mb);
440
922k
      }
441
3.39M
    } else {
442
3.39M
      mbmi->mode = ZEROMV;
443
3.39M
      mbmi->mv.as_int = 0;
444
3.39M
    }
445
446
#if CONFIG_ERROR_CONCEALMENT
447
    if (pbi->ec_enabled && (mbmi->mode != SPLITMV)) {
448
      mi->bmi[0].mv.as_int = mi->bmi[1].mv.as_int = mi->bmi[2].mv.as_int =
449
          mi->bmi[3].mv.as_int = mi->bmi[4].mv.as_int = mi->bmi[5].mv.as_int =
450
              mi->bmi[6].mv.as_int = mi->bmi[7].mv.as_int =
451
                  mi->bmi[8].mv.as_int = mi->bmi[9].mv.as_int =
452
                      mi->bmi[10].mv.as_int = mi->bmi[11].mv.as_int =
453
                          mi->bmi[12].mv.as_int = mi->bmi[13].mv.as_int =
454
                              mi->bmi[14].mv.as_int = mi->bmi[15].mv.as_int =
455
                                  mbmi->mv.as_int;
456
    }
457
#endif
458
8.15M
  } else {
459
    /* required for left and above block mv */
460
8.15M
    mbmi->mv.as_int = 0;
461
462
    /* MB is intra coded */
463
8.15M
    if ((mbmi->mode = read_ymode(bc, pbi->common.fc.ymode_prob)) == B_PRED) {
464
89.1k
      int j = 0;
465
89.1k
      mbmi->is_4x4 = 1;
466
1.42M
      do {
467
1.42M
        mi->bmi[j].as_mode = read_bmode(bc, pbi->common.fc.bmode_prob);
468
1.42M
      } while (++j < 16);
469
89.1k
    }
470
471
8.15M
    mbmi->uv_mode = read_uv_mode(bc, pbi->common.fc.uv_mode_prob);
472
8.15M
  }
473
14.0M
}
474
475
105M
static void read_mb_features(vp8_reader *r, MB_MODE_INFO *mi, MACROBLOCKD *x) {
476
  /* Is segmentation enabled */
477
105M
  if (x->segmentation_enabled && x->update_mb_segmentation_map) {
478
    /* If so then read the segment id. */
479
105M
    if (vp8_read(r, x->mb_segment_tree_probs[0])) {
480
2.25M
      mi->segment_id =
481
2.25M
          (unsigned char)(2 + vp8_read(r, x->mb_segment_tree_probs[2]));
482
102M
    } else {
483
102M
      mi->segment_id =
484
102M
          (unsigned char)(vp8_read(r, x->mb_segment_tree_probs[1]));
485
102M
    }
486
105M
  }
487
105M
}
488
489
219M
static void decode_mb_mode_mvs(VP8D_COMP *pbi, MODE_INFO *mi) {
490
  /* Read the Macroblock segmentation map if it is being updated explicitly
491
   * this frame (reset to 0 above by default)
492
   * By default on a key frame reset all MBs to segment 0
493
   */
494
219M
  if (pbi->mb.update_mb_segmentation_map) {
495
105M
    read_mb_features(&pbi->mbc[8], &mi->mbmi, &pbi->mb);
496
114M
  } else if (pbi->common.frame_type == KEY_FRAME) {
497
103M
    mi->mbmi.segment_id = 0;
498
103M
  }
499
500
  /* Read the macroblock coeff skip flag if this feature is in use,
501
   * else default to 0 */
502
219M
  if (pbi->common.mb_no_coeff_skip) {
503
28.6M
    mi->mbmi.mb_skip_coeff = vp8_read(&pbi->mbc[8], pbi->prob_skip_false);
504
190M
  } else {
505
190M
    mi->mbmi.mb_skip_coeff = 0;
506
190M
  }
507
508
219M
  mi->mbmi.is_4x4 = 0;
509
219M
  if (pbi->common.frame_type == KEY_FRAME) {
510
205M
    read_kf_modes(pbi, mi);
511
205M
  } else {
512
14.0M
    read_mb_modes_mv(pbi, mi, &mi->mbmi);
513
14.0M
  }
514
219M
}
515
516
193k
void vp8_decode_mode_mvs(VP8D_COMP *pbi) {
517
193k
  MODE_INFO *mi = pbi->common.mi;
518
193k
  int mb_row = -1;
519
193k
  int mb_to_right_edge_start;
520
521
193k
  mb_mode_mv_init(pbi);
522
523
193k
  pbi->mb.mb_to_top_edge = 0;
524
193k
  pbi->mb.mb_to_bottom_edge = ((pbi->common.mb_rows - 1) * 16) << 3;
525
193k
  mb_to_right_edge_start = ((pbi->common.mb_cols - 1) * 16) << 3;
526
527
5.47M
  while (++mb_row < pbi->common.mb_rows) {
528
5.28M
    int mb_col = -1;
529
530
5.28M
    pbi->mb.mb_to_left_edge = 0;
531
5.28M
    pbi->mb.mb_to_right_edge = mb_to_right_edge_start;
532
533
224M
    while (++mb_col < pbi->common.mb_cols) {
534
#if CONFIG_ERROR_CONCEALMENT
535
      int mb_num = mb_row * pbi->common.mb_cols + mb_col;
536
#endif
537
538
219M
      decode_mb_mode_mvs(pbi, mi);
539
540
#if CONFIG_ERROR_CONCEALMENT
541
      /* look for corruption. set mvs_corrupt_from_mb to the current
542
       * mb_num if the frame is corrupt from this macroblock. */
543
      if (vp8dx_bool_error(&pbi->mbc[8]) &&
544
          mb_num < (int)pbi->mvs_corrupt_from_mb) {
545
        pbi->mvs_corrupt_from_mb = mb_num;
546
        /* no need to continue since the partition is corrupt from
547
         * here on.
548
         */
549
        return;
550
      }
551
#endif
552
553
219M
      pbi->mb.mb_to_left_edge -= (16 << 3);
554
219M
      pbi->mb.mb_to_right_edge -= (16 << 3);
555
219M
      mi++; /* next macroblock */
556
219M
    }
557
5.28M
    pbi->mb.mb_to_top_edge -= (16 << 3);
558
5.28M
    pbi->mb.mb_to_bottom_edge -= (16 << 3);
559
560
5.28M
    mi++; /* skip left predictor each row */
561
5.28M
  }
562
193k
}