1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libvpx/vp9/common/vp9_pred_common.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,419 @@ 1.4 + 1.5 +/* 1.6 + * Copyright (c) 2012 The WebM project authors. All Rights Reserved. 1.7 + * 1.8 + * Use of this source code is governed by a BSD-style license 1.9 + * that can be found in the LICENSE file in the root of the source 1.10 + * tree. An additional intellectual property rights grant can be found 1.11 + * in the file PATENTS. All contributing project authors may 1.12 + * be found in the AUTHORS file in the root of the source tree. 1.13 + */ 1.14 + 1.15 +#include <limits.h> 1.16 + 1.17 +#include "vp9/common/vp9_common.h" 1.18 +#include "vp9/common/vp9_pred_common.h" 1.19 +#include "vp9/common/vp9_seg_common.h" 1.20 +#include "vp9/common/vp9_treecoder.h" 1.21 + 1.22 +static INLINE const MB_MODE_INFO *get_above_mbmi(const MODE_INFO *const above) { 1.23 + return (above != NULL) ? &above->mbmi : NULL; 1.24 +} 1.25 + 1.26 +static INLINE const MB_MODE_INFO *get_left_mbmi(const MODE_INFO *const left) { 1.27 + return (left != NULL) ? &left->mbmi : NULL; 1.28 +} 1.29 + 1.30 +// Returns a context number for the given MB prediction signal 1.31 +unsigned char vp9_get_pred_context_switchable_interp(const MACROBLOCKD *xd) { 1.32 + const MODE_INFO *const above_mi = get_above_mi(xd); 1.33 + const MODE_INFO *const left_mi = get_left_mi(xd); 1.34 + const int above_in_image = above_mi != NULL; 1.35 + const int left_in_image = left_mi != NULL; 1.36 + // Note: 1.37 + // The mode info data structure has a one element border above and to the 1.38 + // left of the entries correpsonding to real macroblocks. 1.39 + // The prediction flags in these dummy entries are initialised to 0. 1.40 + // left 1.41 + const int left_mv_pred = left_in_image ? is_inter_block(&left_mi->mbmi) 1.42 + : 0; 1.43 + const int left_interp = left_in_image && left_mv_pred 1.44 + ? left_mi->mbmi.interp_filter 1.45 + : SWITCHABLE_FILTERS; 1.46 + 1.47 + // above 1.48 + const int above_mv_pred = above_in_image ? is_inter_block(&above_mi->mbmi) 1.49 + : 0; 1.50 + const int above_interp = above_in_image && above_mv_pred 1.51 + ? above_mi->mbmi.interp_filter 1.52 + : SWITCHABLE_FILTERS; 1.53 + 1.54 + if (left_interp == above_interp) 1.55 + return left_interp; 1.56 + else if (left_interp == SWITCHABLE_FILTERS && 1.57 + above_interp != SWITCHABLE_FILTERS) 1.58 + return above_interp; 1.59 + else if (left_interp != SWITCHABLE_FILTERS && 1.60 + above_interp == SWITCHABLE_FILTERS) 1.61 + return left_interp; 1.62 + else 1.63 + return SWITCHABLE_FILTERS; 1.64 +} 1.65 +// Returns a context number for the given MB prediction signal 1.66 +unsigned char vp9_get_pred_context_intra_inter(const MACROBLOCKD *xd) { 1.67 + const MODE_INFO *const above_mi = get_above_mi(xd); 1.68 + const MODE_INFO *const left_mi = get_left_mi(xd); 1.69 + const MB_MODE_INFO *const above_mbmi = get_above_mbmi(above_mi); 1.70 + const MB_MODE_INFO *const left_mbmi = get_left_mbmi(left_mi); 1.71 + const int above_in_image = above_mi != NULL; 1.72 + const int left_in_image = left_mi != NULL; 1.73 + const int above_intra = above_in_image ? !is_inter_block(above_mbmi) : 1; 1.74 + const int left_intra = left_in_image ? !is_inter_block(left_mbmi) : 1; 1.75 + 1.76 + // The mode info data structure has a one element border above and to the 1.77 + // left of the entries corresponding to real macroblocks. 1.78 + // The prediction flags in these dummy entries are initialized to 0. 1.79 + // 0 - inter/inter, inter/--, --/inter, --/-- 1.80 + // 1 - intra/inter, inter/intra 1.81 + // 2 - intra/--, --/intra 1.82 + // 3 - intra/intra 1.83 + if (above_in_image && left_in_image) // both edges available 1.84 + return left_intra && above_intra ? 3 1.85 + : left_intra || above_intra; 1.86 + else if (above_in_image || left_in_image) // one edge available 1.87 + return 2 * (above_in_image ? above_intra : left_intra); 1.88 + else 1.89 + return 0; 1.90 +} 1.91 +// Returns a context number for the given MB prediction signal 1.92 +unsigned char vp9_get_pred_context_comp_inter_inter(const VP9_COMMON *cm, 1.93 + const MACROBLOCKD *xd) { 1.94 + int pred_context; 1.95 + const MODE_INFO *const above_mi = get_above_mi(xd); 1.96 + const MODE_INFO *const left_mi = get_left_mi(xd); 1.97 + const MB_MODE_INFO *const above_mbmi = get_above_mbmi(above_mi); 1.98 + const MB_MODE_INFO *const left_mbmi = get_left_mbmi(left_mi); 1.99 + const int above_in_image = above_mi != NULL; 1.100 + const int left_in_image = left_mi != NULL; 1.101 + // Note: 1.102 + // The mode info data structure has a one element border above and to the 1.103 + // left of the entries correpsonding to real macroblocks. 1.104 + // The prediction flags in these dummy entries are initialised to 0. 1.105 + if (above_in_image && left_in_image) { // both edges available 1.106 + if (!has_second_ref(above_mbmi) && !has_second_ref(left_mbmi)) 1.107 + // neither edge uses comp pred (0/1) 1.108 + pred_context = (above_mbmi->ref_frame[0] == cm->comp_fixed_ref) ^ 1.109 + (left_mbmi->ref_frame[0] == cm->comp_fixed_ref); 1.110 + else if (!has_second_ref(above_mbmi)) 1.111 + // one of two edges uses comp pred (2/3) 1.112 + pred_context = 2 + (above_mbmi->ref_frame[0] == cm->comp_fixed_ref || 1.113 + !is_inter_block(above_mbmi)); 1.114 + else if (!has_second_ref(left_mbmi)) 1.115 + // one of two edges uses comp pred (2/3) 1.116 + pred_context = 2 + (left_mbmi->ref_frame[0] == cm->comp_fixed_ref || 1.117 + !is_inter_block(left_mbmi)); 1.118 + else // both edges use comp pred (4) 1.119 + pred_context = 4; 1.120 + } else if (above_in_image || left_in_image) { // one edge available 1.121 + const MB_MODE_INFO *edge_mbmi = above_in_image ? above_mbmi : left_mbmi; 1.122 + 1.123 + if (!has_second_ref(edge_mbmi)) 1.124 + // edge does not use comp pred (0/1) 1.125 + pred_context = edge_mbmi->ref_frame[0] == cm->comp_fixed_ref; 1.126 + else 1.127 + // edge uses comp pred (3) 1.128 + pred_context = 3; 1.129 + } else { // no edges available (1) 1.130 + pred_context = 1; 1.131 + } 1.132 + assert(pred_context >= 0 && pred_context < COMP_INTER_CONTEXTS); 1.133 + return pred_context; 1.134 +} 1.135 + 1.136 +// Returns a context number for the given MB prediction signal 1.137 +unsigned char vp9_get_pred_context_comp_ref_p(const VP9_COMMON *cm, 1.138 + const MACROBLOCKD *xd) { 1.139 + int pred_context; 1.140 + const MODE_INFO *const above_mi = get_above_mi(xd); 1.141 + const MODE_INFO *const left_mi = get_left_mi(xd); 1.142 + const MB_MODE_INFO *const above_mbmi = get_above_mbmi(above_mi); 1.143 + const MB_MODE_INFO *const left_mbmi = get_left_mbmi(left_mi); 1.144 + const int above_in_image = above_mi != NULL; 1.145 + const int left_in_image = left_mi != NULL; 1.146 + const int above_intra = above_in_image ? !is_inter_block(above_mbmi) : 1; 1.147 + const int left_intra = left_in_image ? !is_inter_block(left_mbmi) : 1; 1.148 + // Note: 1.149 + // The mode info data structure has a one element border above and to the 1.150 + // left of the entries correpsonding to real macroblocks. 1.151 + // The prediction flags in these dummy entries are initialised to 0. 1.152 + const int fix_ref_idx = cm->ref_frame_sign_bias[cm->comp_fixed_ref]; 1.153 + const int var_ref_idx = !fix_ref_idx; 1.154 + 1.155 + if (above_in_image && left_in_image) { // both edges available 1.156 + if (above_intra && left_intra) { // intra/intra (2) 1.157 + pred_context = 2; 1.158 + } else if (above_intra || left_intra) { // intra/inter 1.159 + const MB_MODE_INFO *edge_mbmi = above_intra ? left_mbmi : above_mbmi; 1.160 + 1.161 + if (!has_second_ref(edge_mbmi)) // single pred (1/3) 1.162 + pred_context = 1 + 2 * (edge_mbmi->ref_frame[0] != cm->comp_var_ref[1]); 1.163 + else // comp pred (1/3) 1.164 + pred_context = 1 + 2 * (edge_mbmi->ref_frame[var_ref_idx] 1.165 + != cm->comp_var_ref[1]); 1.166 + } else { // inter/inter 1.167 + const int l_sg = !has_second_ref(left_mbmi); 1.168 + const int a_sg = !has_second_ref(above_mbmi); 1.169 + MV_REFERENCE_FRAME vrfa = a_sg ? above_mbmi->ref_frame[0] 1.170 + : above_mbmi->ref_frame[var_ref_idx]; 1.171 + MV_REFERENCE_FRAME vrfl = l_sg ? left_mbmi->ref_frame[0] 1.172 + : left_mbmi->ref_frame[var_ref_idx]; 1.173 + 1.174 + if (vrfa == vrfl && cm->comp_var_ref[1] == vrfa) { 1.175 + pred_context = 0; 1.176 + } else if (l_sg && a_sg) { // single/single 1.177 + if ((vrfa == cm->comp_fixed_ref && vrfl == cm->comp_var_ref[0]) || 1.178 + (vrfl == cm->comp_fixed_ref && vrfa == cm->comp_var_ref[0])) 1.179 + pred_context = 4; 1.180 + else if (vrfa == vrfl) 1.181 + pred_context = 3; 1.182 + else 1.183 + pred_context = 1; 1.184 + } else if (l_sg || a_sg) { // single/comp 1.185 + MV_REFERENCE_FRAME vrfc = l_sg ? vrfa : vrfl; 1.186 + MV_REFERENCE_FRAME rfs = a_sg ? vrfa : vrfl; 1.187 + if (vrfc == cm->comp_var_ref[1] && rfs != cm->comp_var_ref[1]) 1.188 + pred_context = 1; 1.189 + else if (rfs == cm->comp_var_ref[1] && vrfc != cm->comp_var_ref[1]) 1.190 + pred_context = 2; 1.191 + else 1.192 + pred_context = 4; 1.193 + } else if (vrfa == vrfl) { // comp/comp 1.194 + pred_context = 4; 1.195 + } else { 1.196 + pred_context = 2; 1.197 + } 1.198 + } 1.199 + } else if (above_in_image || left_in_image) { // one edge available 1.200 + const MB_MODE_INFO *edge_mbmi = above_in_image ? above_mbmi : left_mbmi; 1.201 + 1.202 + if (!is_inter_block(edge_mbmi)) { 1.203 + pred_context = 2; 1.204 + } else { 1.205 + if (has_second_ref(edge_mbmi)) 1.206 + pred_context = 4 * (edge_mbmi->ref_frame[var_ref_idx] 1.207 + != cm->comp_var_ref[1]); 1.208 + else 1.209 + pred_context = 3 * (edge_mbmi->ref_frame[0] != cm->comp_var_ref[1]); 1.210 + } 1.211 + } else { // no edges available (2) 1.212 + pred_context = 2; 1.213 + } 1.214 + assert(pred_context >= 0 && pred_context < REF_CONTEXTS); 1.215 + 1.216 + return pred_context; 1.217 +} 1.218 +unsigned char vp9_get_pred_context_single_ref_p1(const MACROBLOCKD *xd) { 1.219 + int pred_context; 1.220 + const MODE_INFO *const above_mi = get_above_mi(xd); 1.221 + const MODE_INFO *const left_mi = get_left_mi(xd); 1.222 + const MB_MODE_INFO *const above_mbmi = get_above_mbmi(above_mi); 1.223 + const MB_MODE_INFO *const left_mbmi = get_left_mbmi(left_mi); 1.224 + const int above_in_image = above_mi != NULL; 1.225 + const int left_in_image = left_mi != NULL; 1.226 + const int above_intra = above_in_image ? !is_inter_block(above_mbmi) : 1; 1.227 + const int left_intra = left_in_image ? !is_inter_block(left_mbmi) : 1; 1.228 + // Note: 1.229 + // The mode info data structure has a one element border above and to the 1.230 + // left of the entries correpsonding to real macroblocks. 1.231 + // The prediction flags in these dummy entries are initialised to 0. 1.232 + if (above_in_image && left_in_image) { // both edges available 1.233 + if (above_intra && left_intra) { // intra/intra 1.234 + pred_context = 2; 1.235 + } else if (above_intra || left_intra) { // intra/inter or inter/intra 1.236 + const MB_MODE_INFO *edge_mbmi = above_intra ? left_mbmi : above_mbmi; 1.237 + if (!has_second_ref(edge_mbmi)) 1.238 + pred_context = 4 * (edge_mbmi->ref_frame[0] == LAST_FRAME); 1.239 + else 1.240 + pred_context = 1 + (edge_mbmi->ref_frame[0] == LAST_FRAME || 1.241 + edge_mbmi->ref_frame[1] == LAST_FRAME); 1.242 + } else { // inter/inter 1.243 + if (!has_second_ref(above_mbmi) && !has_second_ref(left_mbmi)) { 1.244 + pred_context = 2 * (above_mbmi->ref_frame[0] == LAST_FRAME) + 1.245 + 2 * (left_mbmi->ref_frame[0] == LAST_FRAME); 1.246 + } else if (has_second_ref(above_mbmi) && has_second_ref(left_mbmi)) { 1.247 + pred_context = 1 + (above_mbmi->ref_frame[0] == LAST_FRAME || 1.248 + above_mbmi->ref_frame[1] == LAST_FRAME || 1.249 + left_mbmi->ref_frame[0] == LAST_FRAME || 1.250 + left_mbmi->ref_frame[1] == LAST_FRAME); 1.251 + } else { 1.252 + const MV_REFERENCE_FRAME rfs = !has_second_ref(above_mbmi) ? 1.253 + above_mbmi->ref_frame[0] : left_mbmi->ref_frame[0]; 1.254 + const MV_REFERENCE_FRAME crf1 = has_second_ref(above_mbmi) ? 1.255 + above_mbmi->ref_frame[0] : left_mbmi->ref_frame[0]; 1.256 + const MV_REFERENCE_FRAME crf2 = has_second_ref(above_mbmi) ? 1.257 + above_mbmi->ref_frame[1] : left_mbmi->ref_frame[1]; 1.258 + 1.259 + if (rfs == LAST_FRAME) 1.260 + pred_context = 3 + (crf1 == LAST_FRAME || crf2 == LAST_FRAME); 1.261 + else 1.262 + pred_context = crf1 == LAST_FRAME || crf2 == LAST_FRAME; 1.263 + } 1.264 + } 1.265 + } else if (above_in_image || left_in_image) { // one edge available 1.266 + const MB_MODE_INFO *edge_mbmi = above_in_image ? above_mbmi : left_mbmi; 1.267 + if (!is_inter_block(edge_mbmi)) { // intra 1.268 + pred_context = 2; 1.269 + } else { // inter 1.270 + if (!has_second_ref(edge_mbmi)) 1.271 + pred_context = 4 * (edge_mbmi->ref_frame[0] == LAST_FRAME); 1.272 + else 1.273 + pred_context = 1 + (edge_mbmi->ref_frame[0] == LAST_FRAME || 1.274 + edge_mbmi->ref_frame[1] == LAST_FRAME); 1.275 + } 1.276 + } else { // no edges available 1.277 + pred_context = 2; 1.278 + } 1.279 + 1.280 + assert(pred_context >= 0 && pred_context < REF_CONTEXTS); 1.281 + return pred_context; 1.282 +} 1.283 + 1.284 +unsigned char vp9_get_pred_context_single_ref_p2(const MACROBLOCKD *xd) { 1.285 + int pred_context; 1.286 + const MODE_INFO *const above_mi = get_above_mi(xd); 1.287 + const MODE_INFO *const left_mi = get_left_mi(xd); 1.288 + const MB_MODE_INFO *const above_mbmi = get_above_mbmi(above_mi); 1.289 + const MB_MODE_INFO *const left_mbmi = get_left_mbmi(left_mi); 1.290 + const int above_in_image = above_mi != NULL; 1.291 + const int left_in_image = left_mi != NULL; 1.292 + const int above_intra = above_in_image ? !is_inter_block(above_mbmi) : 1; 1.293 + const int left_intra = left_in_image ? !is_inter_block(left_mbmi) : 1; 1.294 + 1.295 + // Note: 1.296 + // The mode info data structure has a one element border above and to the 1.297 + // left of the entries correpsonding to real macroblocks. 1.298 + // The prediction flags in these dummy entries are initialised to 0. 1.299 + if (above_in_image && left_in_image) { // both edges available 1.300 + if (above_intra && left_intra) { // intra/intra 1.301 + pred_context = 2; 1.302 + } else if (above_intra || left_intra) { // intra/inter or inter/intra 1.303 + const MB_MODE_INFO *edge_mbmi = above_intra ? left_mbmi : above_mbmi; 1.304 + if (!has_second_ref(edge_mbmi)) { 1.305 + if (edge_mbmi->ref_frame[0] == LAST_FRAME) 1.306 + pred_context = 3; 1.307 + else 1.308 + pred_context = 4 * (edge_mbmi->ref_frame[0] == GOLDEN_FRAME); 1.309 + } else { 1.310 + pred_context = 1 + 2 * (edge_mbmi->ref_frame[0] == GOLDEN_FRAME || 1.311 + edge_mbmi->ref_frame[1] == GOLDEN_FRAME); 1.312 + } 1.313 + } else { // inter/inter 1.314 + if (!has_second_ref(above_mbmi) && !has_second_ref(left_mbmi)) { 1.315 + if (above_mbmi->ref_frame[0] == LAST_FRAME && 1.316 + left_mbmi->ref_frame[0] == LAST_FRAME) { 1.317 + pred_context = 3; 1.318 + } else if (above_mbmi->ref_frame[0] == LAST_FRAME || 1.319 + left_mbmi->ref_frame[0] == LAST_FRAME) { 1.320 + const MB_MODE_INFO *edge_mbmi = 1.321 + above_mbmi->ref_frame[0] == LAST_FRAME ? left_mbmi : above_mbmi; 1.322 + 1.323 + pred_context = 4 * (edge_mbmi->ref_frame[0] == GOLDEN_FRAME); 1.324 + } else { 1.325 + pred_context = 2 * (above_mbmi->ref_frame[0] == GOLDEN_FRAME) + 1.326 + 2 * (left_mbmi->ref_frame[0] == GOLDEN_FRAME); 1.327 + } 1.328 + } else if (has_second_ref(above_mbmi) && has_second_ref(left_mbmi)) { 1.329 + if (above_mbmi->ref_frame[0] == left_mbmi->ref_frame[0] && 1.330 + above_mbmi->ref_frame[1] == left_mbmi->ref_frame[1]) 1.331 + pred_context = 3 * (above_mbmi->ref_frame[0] == GOLDEN_FRAME || 1.332 + above_mbmi->ref_frame[1] == GOLDEN_FRAME || 1.333 + left_mbmi->ref_frame[0] == GOLDEN_FRAME || 1.334 + left_mbmi->ref_frame[1] == GOLDEN_FRAME); 1.335 + else 1.336 + pred_context = 2; 1.337 + } else { 1.338 + const MV_REFERENCE_FRAME rfs = !has_second_ref(above_mbmi) ? 1.339 + above_mbmi->ref_frame[0] : left_mbmi->ref_frame[0]; 1.340 + const MV_REFERENCE_FRAME crf1 = has_second_ref(above_mbmi) ? 1.341 + above_mbmi->ref_frame[0] : left_mbmi->ref_frame[0]; 1.342 + const MV_REFERENCE_FRAME crf2 = has_second_ref(above_mbmi) ? 1.343 + above_mbmi->ref_frame[1] : left_mbmi->ref_frame[1]; 1.344 + 1.345 + if (rfs == GOLDEN_FRAME) 1.346 + pred_context = 3 + (crf1 == GOLDEN_FRAME || crf2 == GOLDEN_FRAME); 1.347 + else if (rfs == ALTREF_FRAME) 1.348 + pred_context = crf1 == GOLDEN_FRAME || crf2 == GOLDEN_FRAME; 1.349 + else 1.350 + pred_context = 1 + 2 * (crf1 == GOLDEN_FRAME || crf2 == GOLDEN_FRAME); 1.351 + } 1.352 + } 1.353 + } else if (above_in_image || left_in_image) { // one edge available 1.354 + const MB_MODE_INFO *edge_mbmi = above_in_image ? above_mbmi : left_mbmi; 1.355 + 1.356 + if (!is_inter_block(edge_mbmi) || 1.357 + (edge_mbmi->ref_frame[0] == LAST_FRAME && !has_second_ref(edge_mbmi))) 1.358 + pred_context = 2; 1.359 + else if (!has_second_ref(edge_mbmi)) 1.360 + pred_context = 4 * (edge_mbmi->ref_frame[0] == GOLDEN_FRAME); 1.361 + else 1.362 + pred_context = 3 * (edge_mbmi->ref_frame[0] == GOLDEN_FRAME || 1.363 + edge_mbmi->ref_frame[1] == GOLDEN_FRAME); 1.364 + } else { // no edges available (2) 1.365 + pred_context = 2; 1.366 + } 1.367 + assert(pred_context >= 0 && pred_context < REF_CONTEXTS); 1.368 + return pred_context; 1.369 +} 1.370 +// Returns a context number for the given MB prediction signal 1.371 +// The mode info data structure has a one element border above and to the 1.372 +// left of the entries corresponding to real blocks. 1.373 +// The prediction flags in these dummy entries are initialized to 0. 1.374 +unsigned char vp9_get_pred_context_tx_size(const MACROBLOCKD *xd) { 1.375 + const MODE_INFO *const above_mi = get_above_mi(xd); 1.376 + const MODE_INFO *const left_mi = get_left_mi(xd); 1.377 + const MB_MODE_INFO *const above_mbmi = get_above_mbmi(above_mi); 1.378 + const MB_MODE_INFO *const left_mbmi = get_left_mbmi(left_mi); 1.379 + const int above_in_image = above_mi != NULL; 1.380 + const int left_in_image = left_mi != NULL; 1.381 + const int max_tx_size = max_txsize_lookup[xd->mi_8x8[0]->mbmi.sb_type]; 1.382 + int above_context = max_tx_size; 1.383 + int left_context = max_tx_size; 1.384 + 1.385 + if (above_in_image) 1.386 + above_context = above_mbmi->skip_coeff ? max_tx_size 1.387 + : above_mbmi->tx_size; 1.388 + 1.389 + if (left_in_image) 1.390 + left_context = left_mbmi->skip_coeff ? max_tx_size 1.391 + : left_mbmi->tx_size; 1.392 + 1.393 + if (!left_in_image) 1.394 + left_context = above_context; 1.395 + 1.396 + if (!above_in_image) 1.397 + above_context = left_context; 1.398 + 1.399 + return above_context + left_context > max_tx_size; 1.400 +} 1.401 + 1.402 +void vp9_set_pred_flag_seg_id(MACROBLOCKD *xd, uint8_t pred_flag) { 1.403 + xd->mi_8x8[0]->mbmi.seg_id_predicted = pred_flag; 1.404 +} 1.405 + 1.406 +int vp9_get_segment_id(VP9_COMMON *cm, const uint8_t *segment_ids, 1.407 + BLOCK_SIZE bsize, int mi_row, int mi_col) { 1.408 + const int mi_offset = mi_row * cm->mi_cols + mi_col; 1.409 + const int bw = num_8x8_blocks_wide_lookup[bsize]; 1.410 + const int bh = num_8x8_blocks_high_lookup[bsize]; 1.411 + const int xmis = MIN(cm->mi_cols - mi_col, bw); 1.412 + const int ymis = MIN(cm->mi_rows - mi_row, bh); 1.413 + int x, y, segment_id = INT_MAX; 1.414 + 1.415 + for (y = 0; y < ymis; y++) 1.416 + for (x = 0; x < xmis; x++) 1.417 + segment_id = MIN(segment_id, 1.418 + segment_ids[mi_offset + y * cm->mi_cols + x]); 1.419 + 1.420 + assert(segment_id >= 0 && segment_id < MAX_SEGMENTS); 1.421 + return segment_id; 1.422 +}