Coverage Report

Created: 2026-08-13 07:43

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