Coverage Report

Created: 2025-08-03 06:57

/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
11.1G
static B_PREDICTION_MODE read_bmode(vp8_reader *bc, const vp8_prob *p) {
19
11.1G
  const int i = vp8_treed_read(bc, vp8_bmode_tree, p);
20
21
11.1G
  return (B_PREDICTION_MODE)i;
22
11.1G
}
23
24
51.7M
static MB_PREDICTION_MODE read_ymode(vp8_reader *bc, const vp8_prob *p) {
25
51.7M
  const int i = vp8_treed_read(bc, vp8_ymode_tree, p);
26
27
51.7M
  return (MB_PREDICTION_MODE)i;
28
51.7M
}
29
30
702M
static MB_PREDICTION_MODE read_kf_ymode(vp8_reader *bc, const vp8_prob *p) {
31
702M
  const int i = vp8_treed_read(bc, vp8_kf_ymode_tree, p);
32
33
702M
  return (MB_PREDICTION_MODE)i;
34
702M
}
35
36
754M
static MB_PREDICTION_MODE read_uv_mode(vp8_reader *bc, const vp8_prob *p) {
37
754M
  const int i = vp8_treed_read(bc, vp8_uv_mode_tree, p);
38
39
754M
  return (MB_PREDICTION_MODE)i;
40
754M
}
41
42
702M
static void read_kf_modes(VP8D_COMP *pbi, MODE_INFO *mi) {
43
702M
  vp8_reader *const bc = &pbi->mbc[8];
44
702M
  const int mis = pbi->common.mode_info_stride;
45
46
702M
  mi->mbmi.ref_frame = INTRA_FRAME;
47
702M
  mi->mbmi.mode = read_kf_ymode(bc, vp8_kf_ymode_prob);
48
49
702M
  if (mi->mbmi.mode == B_PRED) {
50
695M
    int i = 0;
51
695M
    mi->mbmi.is_4x4 = 1;
52
53
11.1G
    do {
54
11.1G
      const B_PREDICTION_MODE A = above_block_mode(mi, i, mis);
55
11.1G
      const B_PREDICTION_MODE L = left_block_mode(mi, i);
56
57
11.1G
      mi->bmi[i].as_mode = read_bmode(bc, vp8_kf_bmode_prob[A][L]);
58
11.1G
    } while (++i < 16);
59
695M
  }
60
61
702M
  mi->mbmi.uv_mode = read_uv_mode(bc, vp8_kf_uv_mode_prob);
62
702M
}
63
64
11.4M
static int read_mvcomponent(vp8_reader *r, const MV_CONTEXT *mvc) {
65
11.4M
  const vp8_prob *const p = (const vp8_prob *)mvc;
66
11.4M
  int x = 0;
67
68
11.4M
  if (vp8_read(r, p[mvpis_short])) { /* Large */
69
8.26M
    int i = 0;
70
71
24.7M
    do {
72
24.7M
      x += vp8_read(r, p[MVPbits + i]) << i;
73
24.7M
    } while (++i < 3);
74
75
8.26M
    i = mvlong_width - 1; /* Skip bit 3, which is sometimes implicit */
76
77
49.5M
    do {
78
49.5M
      x += vp8_read(r, p[MVPbits + i]) << i;
79
49.5M
    } while (--i > 3);
80
81
8.26M
    if (!(x & 0xFFF0) || vp8_read(r, p[MVPbits + 3])) x += 8;
82
8.26M
  } else { /* small */
83
3.15M
    x = vp8_treed_read(r, vp8_small_mvtree, p + MVPshort);
84
3.15M
  }
85
86
11.4M
  if (x && vp8_read(r, p[MVPsign])) x = -x;
87
88
11.4M
  return x;
89
11.4M
}
90
91
903k
static void read_mv(vp8_reader *r, MV *mv, const MV_CONTEXT *mvc) {
92
903k
  mv->row = (short)(read_mvcomponent(r, mvc) * 2);
93
903k
  mv->col = (short)(read_mvcomponent(r, ++mvc) * 2);
94
903k
}
95
96
48.7k
static void read_mvcontexts(vp8_reader *bc, MV_CONTEXT *mvc) {
97
48.7k
  int i = 0;
98
99
97.4k
  do {
100
97.4k
    const vp8_prob *up = vp8_mv_update_probs[i].prob;
101
97.4k
    vp8_prob *p = (vp8_prob *)(mvc + i);
102
97.4k
    vp8_prob *const pstop = p + MVPcount;
103
104
1.85M
    do {
105
1.85M
      if (vp8_read(bc, *up++)) {
106
31.3k
        const vp8_prob x = (vp8_prob)vp8_read_literal(bc, 7);
107
108
31.3k
        *p = x ? x << 1 : 1;
109
31.3k
      }
110
1.85M
    } while (++p < pstop);
111
97.4k
  } while (++i < 2);
112
48.7k
}
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
73.9k
static void mb_mode_mv_init(VP8D_COMP *pbi) {
123
73.9k
  vp8_reader *const bc = &pbi->mbc[8];
124
73.9k
  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
73.9k
  pbi->common.mb_no_coeff_skip = (int)vp8_read_bit(bc);
134
135
73.9k
  pbi->prob_skip_false = 0;
136
73.9k
  if (pbi->common.mb_no_coeff_skip) {
137
23.2k
    pbi->prob_skip_false = (vp8_prob)vp8_read_literal(bc, 8);
138
23.2k
  }
139
140
73.9k
  if (pbi->common.frame_type != KEY_FRAME) {
141
48.7k
    pbi->prob_intra = (vp8_prob)vp8_read_literal(bc, 8);
142
48.7k
    pbi->prob_last = (vp8_prob)vp8_read_literal(bc, 8);
143
48.7k
    pbi->prob_gf = (vp8_prob)vp8_read_literal(bc, 8);
144
145
48.7k
    if (vp8_read_bit(bc)) {
146
16.6k
      int i = 0;
147
148
66.6k
      do {
149
66.6k
        pbi->common.fc.ymode_prob[i] = (vp8_prob)vp8_read_literal(bc, 8);
150
66.6k
      } while (++i < 4);
151
16.6k
    }
152
153
48.7k
    if (vp8_read_bit(bc)) {
154
21.8k
      int i = 0;
155
156
65.4k
      do {
157
65.4k
        pbi->common.fc.uv_mode_prob[i] = (vp8_prob)vp8_read_literal(bc, 8);
158
65.4k
      } while (++i < 3);
159
21.8k
    }
160
161
48.7k
    read_mvcontexts(bc, mvc);
162
48.7k
  }
163
73.9k
}
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
11.9M
                                           const uint32_t above) {
178
11.9M
  int lez = (left == 0);
179
11.9M
  int aez = (above == 0);
180
11.9M
  int lea = (left == above);
181
11.9M
  const vp8_prob *prob;
182
183
11.9M
  prob = vp8_sub_mv_ref_prob3[(aez << 2) | (lez << 1) | (lea)];
184
185
11.9M
  return prob;
186
11.9M
}
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
2.69M
                            int mb_to_bottom_edge) {
194
2.69M
  int s; /* split configuration (16x8, 8x16, 8x8, 4x4) */
195
  /* number of partitions in the split configuration (see vp8_mbsplit_count) */
196
2.69M
  int num_p;
197
2.69M
  int j = 0;
198
199
2.69M
  s = 3;
200
2.69M
  num_p = 16;
201
2.69M
  if (vp8_read(bc, 110)) {
202
2.26M
    s = 2;
203
2.26M
    num_p = 4;
204
2.26M
    if (vp8_read(bc, 111)) {
205
2.01M
      s = vp8_read(bc, 150);
206
2.01M
      num_p = 2;
207
2.01M
    }
208
2.26M
  }
209
210
2.69M
  do /* for each subset j */
211
11.9M
  {
212
11.9M
    int_mv leftmv, abovemv;
213
11.9M
    int_mv blockmv;
214
11.9M
    int k; /* first block in subset j */
215
216
11.9M
    const vp8_prob *prob;
217
11.9M
    k = vp8_mbsplit_offset[s][j];
218
219
11.9M
    if (!(k & 3)) {
220
      /* On L edge, get from MB to left of us */
221
4.46M
      if (left_mb->mbmi.mode != SPLITMV) {
222
1.80M
        leftmv.as_int = left_mb->mbmi.mv.as_int;
223
2.66M
      } else {
224
2.66M
        leftmv.as_int = (left_mb->bmi + k + 4 - 1)->mv.as_int;
225
2.66M
      }
226
7.51M
    } else {
227
7.51M
      leftmv.as_int = (mi->bmi + k - 1)->mv.as_int;
228
7.51M
    }
229
230
11.9M
    if (!(k >> 2)) {
231
      /* On top edge, get from MB above us */
232
6.05M
      if (above_mb->mbmi.mode != SPLITMV) {
233
1.91M
        abovemv.as_int = above_mb->mbmi.mv.as_int;
234
4.13M
      } else {
235
4.13M
        abovemv.as_int = (above_mb->bmi + k + 16 - 4)->mv.as_int;
236
4.13M
      }
237
6.05M
    } else {
238
5.92M
      abovemv.as_int = (mi->bmi + k - 4)->mv.as_int;
239
5.92M
    }
240
241
11.9M
    prob = get_sub_mv_ref_prob(leftmv.as_int, abovemv.as_int);
242
243
11.9M
    if (vp8_read(bc, prob[0])) {
244
6.04M
      if (vp8_read(bc, prob[1])) {
245
4.90M
        blockmv.as_int = 0;
246
4.90M
        if (vp8_read(bc, prob[2])) {
247
4.80M
          blockmv.as_mv.row = read_mvcomponent(bc, &mvc[0]) * 2;
248
4.80M
          blockmv.as_mv.row += best_mv.as_mv.row;
249
4.80M
          blockmv.as_mv.col = read_mvcomponent(bc, &mvc[1]) * 2;
250
4.80M
          blockmv.as_mv.col += best_mv.as_mv.col;
251
4.80M
        }
252
4.90M
      } else {
253
1.14M
        blockmv.as_int = abovemv.as_int;
254
1.14M
      }
255
6.04M
    } else {
256
5.93M
      blockmv.as_int = leftmv.as_int;
257
5.93M
    }
258
259
11.9M
    mbmi->need_to_clamp_mvs |=
260
11.9M
        vp8_check_mv_bounds(&blockmv, mb_to_left_edge, mb_to_right_edge,
261
11.9M
                            mb_to_top_edge, mb_to_bottom_edge);
262
263
11.9M
    {
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
11.9M
      const unsigned char *fill_offset;
268
11.9M
      unsigned int fill_count = mbsplit_fill_count[s];
269
270
11.9M
      fill_offset =
271
11.9M
          &mbsplit_fill_offset[s][(unsigned char)j * mbsplit_fill_count[s]];
272
273
43.1M
      do {
274
43.1M
        mi->bmi[*fill_offset].mv.as_int = blockmv.as_int;
275
43.1M
        fill_offset++;
276
43.1M
      } while (--fill_count);
277
11.9M
    }
278
279
11.9M
  } while (++j < num_p);
280
281
2.69M
  mbmi->partitioning = s;
282
2.69M
}
283
284
static void read_mb_modes_mv(VP8D_COMP *pbi, MODE_INFO *mi,
285
60.5M
                             MB_MODE_INFO *mbmi) {
286
60.5M
  vp8_reader *const bc = &pbi->mbc[8];
287
60.5M
  mbmi->ref_frame = (MV_REFERENCE_FRAME)vp8_read(bc, pbi->prob_intra);
288
60.5M
  if (mbmi->ref_frame) { /* inter MB */
289
8.74M
    enum { CNT_INTRA, CNT_NEAREST, CNT_NEAR, CNT_SPLITMV };
290
8.74M
    int cnt[4];
291
8.74M
    int *cntx = cnt;
292
8.74M
    int_mv near_mvs[4];
293
8.74M
    int_mv *nmv = near_mvs;
294
8.74M
    const int mis = pbi->mb.mode_info_stride;
295
8.74M
    const MODE_INFO *above = mi - mis;
296
8.74M
    const MODE_INFO *left = mi - 1;
297
8.74M
    const MODE_INFO *aboveleft = above - 1;
298
8.74M
    int *ref_frame_sign_bias = pbi->common.ref_frame_sign_bias;
299
300
8.74M
    mbmi->need_to_clamp_mvs = 0;
301
302
8.74M
    if (vp8_read(bc, pbi->prob_last)) {
303
5.06M
      mbmi->ref_frame =
304
5.06M
          (MV_REFERENCE_FRAME)((int)(2 + vp8_read(bc, pbi->prob_gf)));
305
5.06M
    }
306
307
    /* Zero accumulators */
308
8.74M
    nmv[0].as_int = nmv[1].as_int = nmv[2].as_int = 0;
309
8.74M
    cnt[0] = cnt[1] = cnt[2] = cnt[3] = 0;
310
311
    /* Process above */
312
8.74M
    if (above->mbmi.ref_frame != INTRA_FRAME) {
313
8.05M
      if (above->mbmi.mv.as_int) {
314
4.57M
        (++nmv)->as_int = above->mbmi.mv.as_int;
315
4.57M
        mv_bias(ref_frame_sign_bias[above->mbmi.ref_frame], mbmi->ref_frame,
316
4.57M
                nmv, ref_frame_sign_bias);
317
4.57M
        ++cntx;
318
4.57M
      }
319
320
8.05M
      *cntx += 2;
321
8.05M
    }
322
323
    /* Process left */
324
8.74M
    if (left->mbmi.ref_frame != INTRA_FRAME) {
325
8.34M
      if (left->mbmi.mv.as_int) {
326
4.79M
        int_mv this_mv;
327
328
4.79M
        this_mv.as_int = left->mbmi.mv.as_int;
329
4.79M
        mv_bias(ref_frame_sign_bias[left->mbmi.ref_frame], mbmi->ref_frame,
330
4.79M
                &this_mv, ref_frame_sign_bias);
331
332
4.79M
        if (this_mv.as_int != nmv->as_int) {
333
4.20M
          (++nmv)->as_int = this_mv.as_int;
334
4.20M
          ++cntx;
335
4.20M
        }
336
337
4.79M
        *cntx += 2;
338
4.79M
      } else {
339
3.55M
        cnt[CNT_INTRA] += 2;
340
3.55M
      }
341
8.34M
    }
342
343
    /* Process above left */
344
8.74M
    if (aboveleft->mbmi.ref_frame != INTRA_FRAME) {
345
7.86M
      if (aboveleft->mbmi.mv.as_int) {
346
4.46M
        int_mv this_mv;
347
348
4.46M
        this_mv.as_int = aboveleft->mbmi.mv.as_int;
349
4.46M
        mv_bias(ref_frame_sign_bias[aboveleft->mbmi.ref_frame], mbmi->ref_frame,
350
4.46M
                &this_mv, ref_frame_sign_bias);
351
352
4.46M
        if (this_mv.as_int != nmv->as_int) {
353
3.23M
          (++nmv)->as_int = this_mv.as_int;
354
3.23M
          ++cntx;
355
3.23M
        }
356
357
4.46M
        *cntx += 1;
358
4.46M
      } else {
359
3.39M
        cnt[CNT_INTRA] += 1;
360
3.39M
      }
361
7.86M
    }
362
363
8.74M
    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
5.22M
      cnt[CNT_NEAREST] += ((cnt[CNT_SPLITMV] > 0) &
367
5.22M
                           (nmv->as_int == near_mvs[CNT_NEAREST].as_int));
368
369
      /* Swap near and nearest if necessary */
370
5.22M
      if (cnt[CNT_NEAR] > cnt[CNT_NEAREST]) {
371
415k
        int tmp;
372
415k
        tmp = cnt[CNT_NEAREST];
373
415k
        cnt[CNT_NEAREST] = cnt[CNT_NEAR];
374
415k
        cnt[CNT_NEAR] = tmp;
375
415k
        tmp = (int)near_mvs[CNT_NEAREST].as_int;
376
415k
        near_mvs[CNT_NEAREST].as_int = near_mvs[CNT_NEAR].as_int;
377
415k
        near_mvs[CNT_NEAR].as_int = (uint32_t)tmp;
378
415k
      }
379
380
5.22M
      if (vp8_read(bc, vp8_mode_contexts[cnt[CNT_NEAREST]][1])) {
381
3.97M
        if (vp8_read(bc, vp8_mode_contexts[cnt[CNT_NEAR]][2])) {
382
3.60M
          int mb_to_top_edge;
383
3.60M
          int mb_to_bottom_edge;
384
3.60M
          int mb_to_left_edge;
385
3.60M
          int mb_to_right_edge;
386
3.60M
          MV_CONTEXT *const mvc = pbi->common.fc.mvc;
387
3.60M
          int near_index;
388
389
3.60M
          mb_to_top_edge = pbi->mb.mb_to_top_edge;
390
3.60M
          mb_to_bottom_edge = pbi->mb.mb_to_bottom_edge;
391
3.60M
          mb_to_top_edge -= LEFT_TOP_MARGIN;
392
3.60M
          mb_to_bottom_edge += RIGHT_BOTTOM_MARGIN;
393
3.60M
          mb_to_right_edge = pbi->mb.mb_to_right_edge;
394
3.60M
          mb_to_right_edge += RIGHT_BOTTOM_MARGIN;
395
3.60M
          mb_to_left_edge = pbi->mb.mb_to_left_edge;
396
3.60M
          mb_to_left_edge -= LEFT_TOP_MARGIN;
397
398
          /* Use near_mvs[0] to store the "best" MV */
399
3.60M
          near_index = CNT_INTRA + (cnt[CNT_NEAREST] >= cnt[CNT_INTRA]);
400
401
3.60M
          vp8_clamp_mv2(&near_mvs[near_index], &pbi->mb);
402
403
3.60M
          cnt[CNT_SPLITMV] =
404
3.60M
              ((above->mbmi.mode == SPLITMV) + (left->mbmi.mode == SPLITMV)) *
405
3.60M
                  2 +
406
3.60M
              (aboveleft->mbmi.mode == SPLITMV);
407
408
3.60M
          if (vp8_read(bc, vp8_mode_contexts[cnt[CNT_SPLITMV]][3])) {
409
2.69M
            decode_split_mv(bc, mi, left, above, mbmi, near_mvs[near_index],
410
2.69M
                            mvc, mb_to_left_edge, mb_to_right_edge,
411
2.69M
                            mb_to_top_edge, mb_to_bottom_edge);
412
2.69M
            mbmi->mv.as_int = mi->bmi[15].mv.as_int;
413
2.69M
            mbmi->mode = SPLITMV;
414
2.69M
            mbmi->is_4x4 = 1;
415
2.69M
          } else {
416
903k
            int_mv *const mbmi_mv = &mbmi->mv;
417
903k
            read_mv(bc, &mbmi_mv->as_mv, (const MV_CONTEXT *)mvc);
418
903k
            mbmi_mv->as_mv.row += near_mvs[near_index].as_mv.row;
419
903k
            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
903k
            mbmi->need_to_clamp_mvs =
427
903k
                vp8_check_mv_bounds(mbmi_mv, mb_to_left_edge, mb_to_right_edge,
428
903k
                                    mb_to_top_edge, mb_to_bottom_edge);
429
903k
            mbmi->mode = NEWMV;
430
903k
          }
431
3.60M
        } else {
432
370k
          mbmi->mode = NEARMV;
433
370k
          mbmi->mv.as_int = near_mvs[CNT_NEAR].as_int;
434
370k
          vp8_clamp_mv2(&mbmi->mv, &pbi->mb);
435
370k
        }
436
3.97M
      } else {
437
1.25M
        mbmi->mode = NEARESTMV;
438
1.25M
        mbmi->mv.as_int = near_mvs[CNT_NEAREST].as_int;
439
1.25M
        vp8_clamp_mv2(&mbmi->mv, &pbi->mb);
440
1.25M
      }
441
5.22M
    } else {
442
3.52M
      mbmi->mode = ZEROMV;
443
3.52M
      mbmi->mv.as_int = 0;
444
3.52M
    }
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
51.7M
  } else {
459
    /* required for left and above block mv */
460
51.7M
    mbmi->mv.as_int = 0;
461
462
    /* MB is intra coded */
463
51.7M
    if ((mbmi->mode = read_ymode(bc, pbi->common.fc.ymode_prob)) == B_PRED) {
464
437k
      int j = 0;
465
437k
      mbmi->is_4x4 = 1;
466
7.00M
      do {
467
7.00M
        mi->bmi[j].as_mode = read_bmode(bc, pbi->common.fc.bmode_prob);
468
7.00M
      } while (++j < 16);
469
437k
    }
470
471
51.7M
    mbmi->uv_mode = read_uv_mode(bc, pbi->common.fc.uv_mode_prob);
472
51.7M
  }
473
60.5M
}
474
475
444M
static void read_mb_features(vp8_reader *r, MB_MODE_INFO *mi, MACROBLOCKD *x) {
476
  /* Is segmentation enabled */
477
444M
  if (x->segmentation_enabled && x->update_mb_segmentation_map) {
478
    /* If so then read the segment id. */
479
444M
    if (vp8_read(r, x->mb_segment_tree_probs[0])) {
480
5.97M
      mi->segment_id =
481
5.97M
          (unsigned char)(2 + vp8_read(r, x->mb_segment_tree_probs[2]));
482
438M
    } else {
483
438M
      mi->segment_id =
484
438M
          (unsigned char)(vp8_read(r, x->mb_segment_tree_probs[1]));
485
438M
    }
486
444M
  }
487
444M
}
488
489
763M
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
763M
  if (pbi->mb.update_mb_segmentation_map) {
495
444M
    read_mb_features(&pbi->mbc[8], &mi->mbmi, &pbi->mb);
496
444M
  } else if (pbi->common.frame_type == KEY_FRAME) {
497
266M
    mi->mbmi.segment_id = 0;
498
266M
  }
499
500
  /* Read the macroblock coeff skip flag if this feature is in use,
501
   * else default to 0 */
502
763M
  if (pbi->common.mb_no_coeff_skip) {
503
100M
    mi->mbmi.mb_skip_coeff = vp8_read(&pbi->mbc[8], pbi->prob_skip_false);
504
662M
  } else {
505
662M
    mi->mbmi.mb_skip_coeff = 0;
506
662M
  }
507
508
763M
  mi->mbmi.is_4x4 = 0;
509
763M
  if (pbi->common.frame_type == KEY_FRAME) {
510
702M
    read_kf_modes(pbi, mi);
511
702M
  } else {
512
60.5M
    read_mb_modes_mv(pbi, mi, &mi->mbmi);
513
60.5M
  }
514
763M
}
515
516
73.9k
void vp8_decode_mode_mvs(VP8D_COMP *pbi) {
517
73.9k
  MODE_INFO *mi = pbi->common.mi;
518
73.9k
  int mb_row = -1;
519
73.9k
  int mb_to_right_edge_start;
520
521
73.9k
  mb_mode_mv_init(pbi);
522
523
73.9k
  pbi->mb.mb_to_top_edge = 0;
524
73.9k
  pbi->mb.mb_to_bottom_edge = ((pbi->common.mb_rows - 1) * 16) << 3;
525
73.9k
  mb_to_right_edge_start = ((pbi->common.mb_cols - 1) * 16) << 3;
526
527
4.82M
  while (++mb_row < pbi->common.mb_rows) {
528
4.75M
    int mb_col = -1;
529
530
4.75M
    pbi->mb.mb_to_left_edge = 0;
531
4.75M
    pbi->mb.mb_to_right_edge = mb_to_right_edge_start;
532
533
768M
    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
763M
      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
763M
      pbi->mb.mb_to_left_edge -= (16 << 3);
554
763M
      pbi->mb.mb_to_right_edge -= (16 << 3);
555
763M
      mi++; /* next macroblock */
556
763M
    }
557
4.75M
    pbi->mb.mb_to_top_edge -= (16 << 3);
558
4.75M
    pbi->mb.mb_to_bottom_edge -= (16 << 3);
559
560
4.75M
    mi++; /* skip left predictor each row */
561
4.75M
  }
562
73.9k
}