vp9_pred_common.c 18.9 KB
Newer Older
Ronald S. Bultje's avatar
Ronald S. Bultje committed
1

2
/*
Paul Wilkins's avatar
Paul Wilkins committed
3
 *  Copyright (c) 2012 The WebM project authors. All Rights Reserved.
4
5
6
7
8
9
10
11
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

12
13
#include <limits.h>

Ronald S. Bultje's avatar
Ronald S. Bultje committed
14
#include "vp9/common/vp9_common.h"
15
16
#include "vp9/common/vp9_pred_common.h"
#include "vp9/common/vp9_seg_common.h"
17
#include "vp9/common/vp9_treecoder.h"
18

19
// Returns a context number for the given MB prediction signal
20
unsigned char vp9_get_pred_context_switchable_interp(const MACROBLOCKD *xd) {
21
  const MODE_INFO *const mi = xd->mode_info_context;
22
  const MB_MODE_INFO *const above_mbmi = &mi[-xd->mode_info_stride].mbmi;
23
  const MB_MODE_INFO *const left_mbmi = &mi[-1].mbmi;
Paul Wilkins's avatar
Paul Wilkins committed
24
25
  const int left_in_image = xd->left_available && left_mbmi->in_image;
  const int above_in_image = xd->up_available && above_mbmi->in_image;
26
27
28
29
30
  // Note:
  // The mode info data structure has a one element border above and to the
  // left of the entries correpsonding to real macroblocks.
  // The prediction flags in these dummy entries are initialised to 0.
  // left
31
  const int left_mv_pred = is_inter_mode(left_mbmi->mode);
32
33
  const int left_interp = left_in_image && left_mv_pred
                              ? left_mbmi->interp_filter
34
                              : SWITCHABLE_FILTERS;
35
36

  // above
37
  const int above_mv_pred = is_inter_mode(above_mbmi->mode);
38
39
  const int above_interp = above_in_image && above_mv_pred
                               ? above_mbmi->interp_filter
40
                               : SWITCHABLE_FILTERS;
41
42
43


  if (left_interp == above_interp)
44
    return left_interp;
45
46
  else if (left_interp == SWITCHABLE_FILTERS &&
           above_interp != SWITCHABLE_FILTERS)
47
    return above_interp;
48
49
  else if (left_interp != SWITCHABLE_FILTERS &&
           above_interp == SWITCHABLE_FILTERS)
50
    return left_interp;
51
  else
52
    return SWITCHABLE_FILTERS;
53
}
54
// Returns a context number for the given MB prediction signal
55
unsigned char vp9_get_pred_context_intra_inter(const MACROBLOCKD *xd) {
56
  const MODE_INFO *const mi = xd->mode_info_context;
57
  const MB_MODE_INFO *const above_mbmi = &mi[-xd->mode_info_stride].mbmi;
58
  const MB_MODE_INFO *const left_mbmi = &mi[-1].mbmi;
Paul Wilkins's avatar
Paul Wilkins committed
59
60
  const int left_in_image = xd->left_available && left_mbmi->in_image;
  const int above_in_image = xd->up_available && above_mbmi->in_image;
61
62
  const int left_intra = !is_inter_block(left_mbmi);
  const int above_intra = !is_inter_block(above_mbmi);
63

64
65
66
67
68
69
70
71
72
73
74
75
76
77
  // The mode info data structure has a one element border above and to the
  // left of the entries corresponding to real macroblocks.
  // The prediction flags in these dummy entries are initialized to 0.
  // 0 - inter/inter, inter/--, --/inter, --/--
  // 1 - intra/inter, inter/intra
  // 2 - intra/--, --/intra
  // 3 - intra/intra
  if (above_in_image && left_in_image)  // both edges available
    return left_intra && above_intra ? 3
                                     : left_intra || above_intra;
  else if (above_in_image || left_in_image)  // one edge available
    return 2 * (above_in_image ? above_intra : left_intra);
  else
    return 0;
78
79
80
81
82
83
}
// Returns a context number for the given MB prediction signal
unsigned char vp9_get_pred_context_comp_inter_inter(const VP9_COMMON *cm,
                                                    const MACROBLOCKD *xd) {
  int pred_context;
  const MODE_INFO *const mi = xd->mode_info_context;
84
85
  const MB_MODE_INFO *const above_mbmi = &mi[-cm->mode_info_stride].mbmi;
  const MB_MODE_INFO *const left_mbmi = &mi[-1].mbmi;
Paul Wilkins's avatar
Paul Wilkins committed
86
87
  const int left_in_image = xd->left_available && left_mbmi->in_image;
  const int above_in_image = xd->up_available && above_mbmi->in_image;
88
89
90
91
92
  // Note:
  // The mode info data structure has a one element border above and to the
  // left of the entries correpsonding to real macroblocks.
  // The prediction flags in these dummy entries are initialised to 0.
  if (above_in_image && left_in_image) {  // both edges available
93
94
    if (above_mbmi->ref_frame[1] <= INTRA_FRAME &&
        left_mbmi->ref_frame[1] <= INTRA_FRAME)
95
      // neither edge uses comp pred (0/1)
96
97
98
      pred_context = (above_mbmi->ref_frame[0] == cm->comp_fixed_ref) ^
                     (left_mbmi->ref_frame[0] == cm->comp_fixed_ref);
    else if (above_mbmi->ref_frame[1] <= INTRA_FRAME)
99
      // one of two edges uses comp pred (2/3)
100
101
102
      pred_context = 2 + (above_mbmi->ref_frame[0] == cm->comp_fixed_ref ||
                          above_mbmi->ref_frame[0] == INTRA_FRAME);
    else if (left_mbmi->ref_frame[1] <= INTRA_FRAME)
103
      // one of two edges uses comp pred (2/3)
104
105
106
      pred_context = 2 + (left_mbmi->ref_frame[0] == cm->comp_fixed_ref ||
                          left_mbmi->ref_frame[0] == INTRA_FRAME);
    else  // both edges use comp pred (4)
107
108
      pred_context = 4;
  } else if (above_in_image || left_in_image) {  // one edge available
109
    const MB_MODE_INFO *edge_mbmi = above_in_image ? above_mbmi : left_mbmi;
110

111
    if (edge_mbmi->ref_frame[1] <= INTRA_FRAME)
112
      // edge does not use comp pred (0/1)
113
114
115
      pred_context = edge_mbmi->ref_frame[0] == cm->comp_fixed_ref;
    else
      // edge uses comp pred (3)
116
117
118
119
120
121
122
      pred_context = 3;
  } else {  // no edges available (1)
    pred_context = 1;
  }
  assert(pred_context >= 0 && pred_context < COMP_INTER_CONTEXTS);
  return pred_context;
}
Ronald S. Bultje's avatar
Ronald S. Bultje committed
123

124
125
126
127
128
// Returns a context number for the given MB prediction signal
unsigned char vp9_get_pred_context_comp_ref_p(const VP9_COMMON *cm,
                                              const MACROBLOCKD *xd) {
  int pred_context;
  const MODE_INFO *const mi = xd->mode_info_context;
129
130
  const MB_MODE_INFO *const above_mbmi = &mi[-cm->mode_info_stride].mbmi;
  const MB_MODE_INFO *const left_mbmi = &mi[-1].mbmi;
Paul Wilkins's avatar
Paul Wilkins committed
131
132
  const int left_in_image = xd->left_available && left_mbmi->in_image;
  const int above_in_image = xd->up_available && above_mbmi->in_image;
133
134
135
  const int left_intra = !is_inter_block(left_mbmi);
  const int above_intra = !is_inter_block(above_mbmi);

136
137
138
139
140
141
142
143
  // Note:
  // The mode info data structure has a one element border above and to the
  // left of the entries correpsonding to real macroblocks.
  // The prediction flags in these dummy entries are initialised to 0.
  const int fix_ref_idx = cm->ref_frame_sign_bias[cm->comp_fixed_ref];
  const int var_ref_idx = !fix_ref_idx;

  if (above_in_image && left_in_image) {  // both edges available
144
    if (above_intra && left_intra) {  // intra/intra (2)
145
      pred_context = 2;
146
147
    } else if (above_intra || left_intra) {  // intra/inter
      const MB_MODE_INFO *edge_mbmi = above_intra ? left_mbmi : above_mbmi;
148

149
      if (edge_mbmi->ref_frame[1] <= INTRA_FRAME)  // single pred (1/3)
150
        pred_context = 1 + 2 * (edge_mbmi->ref_frame[0] != cm->comp_var_ref[1]);
151
      else  // comp pred (1/3)
152
153
        pred_context = 1 + 2 * (edge_mbmi->ref_frame[var_ref_idx]
                                    != cm->comp_var_ref[1]);
154
    } else {  // inter/inter
155
156
157
158
159
160
      int l_sg = left_mbmi->ref_frame[1] <= INTRA_FRAME;
      int a_sg = above_mbmi->ref_frame[1] <= INTRA_FRAME;
      MV_REFERENCE_FRAME vrfa = a_sg ? above_mbmi->ref_frame[0]
                                     : above_mbmi->ref_frame[var_ref_idx];
      MV_REFERENCE_FRAME vrfl = l_sg ? left_mbmi->ref_frame[0]
                                     : left_mbmi->ref_frame[var_ref_idx];
Ronald S. Bultje's avatar
Ronald S. Bultje committed
161

162
163
164
      if (vrfa == vrfl && cm->comp_var_ref[1] == vrfa) {
        pred_context = 0;
      } else if (l_sg && a_sg) {  // single/single
165
166
        if ((vrfa == cm->comp_fixed_ref && vrfl == cm->comp_var_ref[0]) ||
            (vrfl == cm->comp_fixed_ref && vrfa == cm->comp_var_ref[0]))
Ronald S. Bultje's avatar
Ronald S. Bultje committed
167
          pred_context = 4;
168
        else if (vrfa == vrfl)
Ronald S. Bultje's avatar
Ronald S. Bultje committed
169
          pred_context = 3;
170
        else
171
172
173
174
          pred_context = 1;
      } else if (l_sg || a_sg) {  // single/comp
        MV_REFERENCE_FRAME vrfc = l_sg ? vrfa : vrfl;
        MV_REFERENCE_FRAME rfs = a_sg ? vrfa : vrfl;
175
        if (vrfc == cm->comp_var_ref[1] && rfs != cm->comp_var_ref[1])
176
          pred_context = 1;
177
        else if (rfs == cm->comp_var_ref[1] && vrfc != cm->comp_var_ref[1])
Ronald S. Bultje's avatar
Ronald S. Bultje committed
178
          pred_context = 2;
179
        else
180
181
182
183
          pred_context = 4;
      } else if (vrfa == vrfl) {  // comp/comp
        pred_context = 4;
      } else {
Ronald S. Bultje's avatar
Ronald S. Bultje committed
184
185
186
        pred_context = 2;
      }
    }
187
  } else if (above_in_image || left_in_image) {  // one edge available
188
    const MB_MODE_INFO *edge_mbmi = above_in_image ? above_mbmi : left_mbmi;
189

190
    if (edge_mbmi->ref_frame[0] == INTRA_FRAME)
191
      pred_context = 2;
192
    else if (edge_mbmi->ref_frame[1] > INTRA_FRAME)
193
194
      pred_context = 4 * (edge_mbmi->ref_frame[var_ref_idx]
                              != cm->comp_var_ref[1]);
195
    else
196
      pred_context = 3 * (edge_mbmi->ref_frame[0] != cm->comp_var_ref[1]);
197
198
199
200
  } else {  // no edges available (2)
    pred_context = 2;
  }
  assert(pred_context >= 0 && pred_context < REF_CONTEXTS);
Ronald S. Bultje's avatar
Ronald S. Bultje committed
201

202
203
  return pred_context;
}
204
unsigned char vp9_get_pred_context_single_ref_p1(const MACROBLOCKD *xd) {
205
206
  int pred_context;
  const MODE_INFO *const mi = xd->mode_info_context;
207
  const MB_MODE_INFO *const above_mbmi = &mi[-xd->mode_info_stride].mbmi;
208
  const MB_MODE_INFO *const left_mbmi = &mi[-1].mbmi;
Paul Wilkins's avatar
Paul Wilkins committed
209
210
  const int left_in_image = xd->left_available && left_mbmi->in_image;
  const int above_in_image = xd->up_available && above_mbmi->in_image;
211
212
213
  const int left_intra = !is_inter_block(left_mbmi);
  const int above_intra = !is_inter_block(above_mbmi);

214
215
216
217
218
  // Note:
  // The mode info data structure has a one element border above and to the
  // left of the entries correpsonding to real macroblocks.
  // The prediction flags in these dummy entries are initialised to 0.
  if (above_in_image && left_in_image) {  // both edges available
219
    if (above_intra && left_intra) {  // intra/intra
220
      pred_context = 2;
221
    } else if (above_intra || left_intra) {  // intra/inter or inter/intra
222
      const MB_MODE_INFO *edge_mbmi = above_intra ? left_mbmi : above_mbmi;
223
      if (!has_second_ref(edge_mbmi))
224
225
226
227
        pred_context = 4 * (edge_mbmi->ref_frame[0] == LAST_FRAME);
      else
        pred_context = 1 + (edge_mbmi->ref_frame[0] == LAST_FRAME ||
                            edge_mbmi->ref_frame[1] == LAST_FRAME);
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
    } else {  // inter/inter
      if (!has_second_ref(above_mbmi) && !has_second_ref(left_mbmi)) {
        pred_context = 2 * (above_mbmi->ref_frame[0] == LAST_FRAME) +
                       2 * (left_mbmi->ref_frame[0] == LAST_FRAME);
      } else if (has_second_ref(above_mbmi) && has_second_ref(left_mbmi)) {
        pred_context = 1 + (above_mbmi->ref_frame[0] == LAST_FRAME ||
                            above_mbmi->ref_frame[1] == LAST_FRAME ||
                            left_mbmi->ref_frame[0] == LAST_FRAME ||
                            left_mbmi->ref_frame[1] == LAST_FRAME);
      } else {
        const MV_REFERENCE_FRAME rfs = !has_second_ref(above_mbmi) ?
                  above_mbmi->ref_frame[0] : left_mbmi->ref_frame[0];
        const MV_REFERENCE_FRAME crf1 = has_second_ref(above_mbmi) ?
                  above_mbmi->ref_frame[0] : left_mbmi->ref_frame[0];
        const MV_REFERENCE_FRAME crf2 = has_second_ref(above_mbmi) ?
                  above_mbmi->ref_frame[1] : left_mbmi->ref_frame[1];
Ronald S. Bultje's avatar
Ronald S. Bultje committed
244

245
246
247
248
249
        if (rfs == LAST_FRAME)
          pred_context = 3 + (crf1 == LAST_FRAME || crf2 == LAST_FRAME);
        else
          pred_context = crf1 == LAST_FRAME || crf2 == LAST_FRAME;
      }
250
251
    }
  } else if (above_in_image || left_in_image) {  // one edge available
252
    const MB_MODE_INFO *edge_mbmi = above_in_image ? above_mbmi : left_mbmi;
253
    if (!is_inter_block(edge_mbmi)) {  // intra
254
      pred_context = 2;
255
256
257
258
259
260
261
262
    } else {  // inter
      if (!has_second_ref(edge_mbmi))
        pred_context = 4 * (edge_mbmi->ref_frame[0] == LAST_FRAME);
      else
        pred_context = 1 + (edge_mbmi->ref_frame[0] == LAST_FRAME ||
                            edge_mbmi->ref_frame[1] == LAST_FRAME);
    }
  } else {  // no edges available
263
264
    pred_context = 2;
  }
265

266
267
268
  assert(pred_context >= 0 && pred_context < REF_CONTEXTS);
  return pred_context;
}
Ronald S. Bultje's avatar
Ronald S. Bultje committed
269

270
unsigned char vp9_get_pred_context_single_ref_p2(const MACROBLOCKD *xd) {
271
272
  int pred_context;
  const MODE_INFO *const mi = xd->mode_info_context;
273
  const MB_MODE_INFO *const above_mbmi = &mi[-xd->mode_info_stride].mbmi;
274
  const MB_MODE_INFO *const left_mbmi = &mi[-1].mbmi;
Paul Wilkins's avatar
Paul Wilkins committed
275
276
  const int left_in_image = xd->left_available && left_mbmi->in_image;
  const int above_in_image = xd->up_available && above_mbmi->in_image;
277
278
  const int left_intra = !is_inter_block(left_mbmi);
  const int above_intra = !is_inter_block(above_mbmi);
279

280
281
282
283
284
  // Note:
  // The mode info data structure has a one element border above and to the
  // left of the entries correpsonding to real macroblocks.
  // The prediction flags in these dummy entries are initialised to 0.
  if (above_in_image && left_in_image) {  // both edges available
285
    if (above_intra && left_intra) {  // intra/intra
286
      pred_context = 2;
287
    } else if (above_intra || left_intra) {  // intra/inter or inter/intra
288
      const MB_MODE_INFO *edge_mbmi = above_intra ? left_mbmi : above_mbmi;
289
      if (!has_second_ref(edge_mbmi)) {
290
        if (edge_mbmi->ref_frame[0] == LAST_FRAME)
291
          pred_context = 3;
292
293
        else
          pred_context = 4 * (edge_mbmi->ref_frame[0] == GOLDEN_FRAME);
294
      } else {
295
296
        pred_context = 1 + 2 * (edge_mbmi->ref_frame[0] == GOLDEN_FRAME ||
                                edge_mbmi->ref_frame[1] == GOLDEN_FRAME);
297
      }
298
299
300
301
302
303
304
305
306
    } else {  // inter/inter
      if (!has_second_ref(above_mbmi) && !has_second_ref(left_mbmi)) {
        if (above_mbmi->ref_frame[0] == LAST_FRAME &&
            left_mbmi->ref_frame[0] == LAST_FRAME) {
          pred_context = 3;
        } else if (above_mbmi->ref_frame[0] == LAST_FRAME ||
                   left_mbmi->ref_frame[0] == LAST_FRAME) {
          const MB_MODE_INFO *edge_mbmi =
              above_mbmi->ref_frame[0] == LAST_FRAME ? left_mbmi : above_mbmi;
307

308
309
310
311
312
313
314
315
316
317
318
319
320
321
          pred_context = 4 * (edge_mbmi->ref_frame[0] == GOLDEN_FRAME);
        } else {
          pred_context = 2 * (above_mbmi->ref_frame[0] == GOLDEN_FRAME) +
                         2 * (left_mbmi->ref_frame[0] == GOLDEN_FRAME);
        }
      } else if (has_second_ref(above_mbmi) && has_second_ref(left_mbmi)) {
        if (above_mbmi->ref_frame[0] == left_mbmi->ref_frame[0] &&
            above_mbmi->ref_frame[1] == left_mbmi->ref_frame[1])
          pred_context = 3 * (above_mbmi->ref_frame[0] == GOLDEN_FRAME ||
                              above_mbmi->ref_frame[1] == GOLDEN_FRAME ||
                              left_mbmi->ref_frame[0] == GOLDEN_FRAME ||
                              left_mbmi->ref_frame[1] == GOLDEN_FRAME);
        else
          pred_context = 2;
322
      } else {
323
324
325
326
327
328
        const MV_REFERENCE_FRAME rfs = !has_second_ref(above_mbmi) ?
                  above_mbmi->ref_frame[0] : left_mbmi->ref_frame[0];
        const MV_REFERENCE_FRAME crf1 = has_second_ref(above_mbmi) ?
                  above_mbmi->ref_frame[0] : left_mbmi->ref_frame[0];
        const MV_REFERENCE_FRAME crf2 = has_second_ref(above_mbmi) ?
                  above_mbmi->ref_frame[1] : left_mbmi->ref_frame[1];
Ronald S. Bultje's avatar
Ronald S. Bultje committed
329

330
331
332
333
334
335
336
        if (rfs == GOLDEN_FRAME)
          pred_context = 3 + (crf1 == GOLDEN_FRAME || crf2 == GOLDEN_FRAME);
        else if (rfs == ALTREF_FRAME)
          pred_context = crf1 == GOLDEN_FRAME || crf2 == GOLDEN_FRAME;
        else
          pred_context = 1 + 2 * (crf1 == GOLDEN_FRAME || crf2 == GOLDEN_FRAME);
      }
Ronald S. Bultje's avatar
Ronald S. Bultje committed
337
    }
338
  } else if (above_in_image || left_in_image) {  // one edge available
339
    const MB_MODE_INFO *edge_mbmi = above_in_image ? above_mbmi : left_mbmi;
340

341
342
    if (!is_inter_block(edge_mbmi) ||
        (edge_mbmi->ref_frame[0] == LAST_FRAME && !has_second_ref(edge_mbmi)))
343
      pred_context = 2;
344
    else if (!has_second_ref(edge_mbmi))
345
346
347
348
      pred_context = 4 * (edge_mbmi->ref_frame[0] == GOLDEN_FRAME);
    else
      pred_context = 3 * (edge_mbmi->ref_frame[0] == GOLDEN_FRAME ||
                          edge_mbmi->ref_frame[1] == GOLDEN_FRAME);
349
350
  } else {  // no edges available (2)
    pred_context = 2;
John Koleszar's avatar
John Koleszar committed
351
  }
352
  assert(pred_context >= 0 && pred_context < REF_CONTEXTS);
John Koleszar's avatar
John Koleszar committed
353
  return pred_context;
354
}
355
// Returns a context number for the given MB prediction signal
356
357
358
// The mode info data structure has a one element border above and to the
// left of the entries corresponding to real blocks.
// The prediction flags in these dummy entries are initialized to 0.
359
unsigned char vp9_get_pred_context_tx_size(const MACROBLOCKD *xd) {
360
  const MODE_INFO *const mi = xd->mode_info_context;
361
362
  const MB_MODE_INFO *const above_mbmi = &mi[-xd->mode_info_stride].mbmi;
  const MB_MODE_INFO *const left_mbmi = &mi[-1].mbmi;
Paul Wilkins's avatar
Paul Wilkins committed
363
364
  const int left_in_image = xd->left_available && left_mbmi->in_image;
  const int above_in_image = xd->up_available && above_mbmi->in_image;
365
366
367
  const int max_tx_size = max_txsize_lookup[mi->mbmi.sb_type];
  int above_context = max_tx_size;
  int left_context = max_tx_size;
368
369

  if (above_in_image)
Paul Wilkins's avatar
Paul Wilkins committed
370
    above_context = above_mbmi->skip_coeff ? max_tx_size
371
                                              : above_mbmi->txfm_size;
372
373

  if (left_in_image)
Paul Wilkins's avatar
Paul Wilkins committed
374
    left_context = left_mbmi->skip_coeff ? max_tx_size
375
                                            : left_mbmi->txfm_size;
376
377

  if (!left_in_image)
378
    left_context = above_context;
379
380

  if (!above_in_image)
381
382
    above_context = left_context;

383
  return above_context + left_context > max_tx_size;
384
385
}

386
void vp9_set_pred_flag_seg_id(VP9_COMMON *cm, BLOCK_SIZE bsize,
387
388
389
                              int mi_row, int mi_col, uint8_t pred_flag) {
  MODE_INFO *mi = &cm->mi[mi_row * cm->mode_info_stride + mi_col];
  const int bw = 1 << mi_width_log2(bsize);
390
  const int bh = 1 << mi_height_log2(bsize);
391
392
393
394
395
396
397
398
399
  const int xmis = MIN(cm->mi_cols - mi_col, bw);
  const int ymis = MIN(cm->mi_rows - mi_row, bh);
  int x, y;

  for (y = 0; y < ymis; y++)
    for (x = 0; x < xmis; x++)
      mi[y * cm->mode_info_stride + x].mbmi.seg_id_predicted = pred_flag;
}

400
void vp9_set_pred_flag_mbskip(VP9_COMMON *cm, BLOCK_SIZE bsize,
401
402
                              int mi_row, int mi_col, uint8_t pred_flag) {
  MODE_INFO *mi = &cm->mi[mi_row * cm->mode_info_stride + mi_col];
403
  const int bw = 1 << mi_width_log2(bsize);
404
405
406
  const int bh = 1 << mi_height_log2(bsize);
  const int xmis = MIN(cm->mi_cols - mi_col, bw);
  const int ymis = MIN(cm->mi_rows - mi_row, bh);
407
  int x, y;
Ronald S. Bultje's avatar
Ronald S. Bultje committed
408

409
410
  for (y = 0; y < ymis; y++)
    for (x = 0; x < xmis; x++)
Paul Wilkins's avatar
Paul Wilkins committed
411
      mi[y * cm->mode_info_stride + x].mbmi.skip_coeff = pred_flag;
412
413
}

414
int vp9_get_segment_id(VP9_COMMON *cm, const uint8_t *segment_ids,
415
                       BLOCK_SIZE bsize, int mi_row, int mi_col) {
416
417
418
  const int mi_offset = mi_row * cm->mi_cols + mi_col;
  const int bw = 1 << mi_width_log2(bsize);
  const int bh = 1 << mi_height_log2(bsize);
419
  const int xmis = MIN(cm->mi_cols - mi_col, bw);
420
421
  const int ymis = MIN(cm->mi_rows - mi_row, bh);
  int x, y, segment_id = INT_MAX;
422

423
424
425
426
427
  for (y = 0; y < ymis; y++)
    for (x = 0; x < xmis; x++)
      segment_id = MIN(segment_id,
                       segment_ids[mi_offset + y * cm->mi_cols + x]);

Paul Wilkins's avatar
Paul Wilkins committed
428
  assert(segment_id >= 0 && segment_id < MAX_SEGMENTS);
429
  return segment_id;
430
}