media/libvpx/vp9/common/vp9_pred_common.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1
michael@0 2 /*
michael@0 3 * Copyright (c) 2012 The WebM project authors. All Rights Reserved.
michael@0 4 *
michael@0 5 * Use of this source code is governed by a BSD-style license
michael@0 6 * that can be found in the LICENSE file in the root of the source
michael@0 7 * tree. An additional intellectual property rights grant can be found
michael@0 8 * in the file PATENTS. All contributing project authors may
michael@0 9 * be found in the AUTHORS file in the root of the source tree.
michael@0 10 */
michael@0 11
michael@0 12 #include <limits.h>
michael@0 13
michael@0 14 #include "vp9/common/vp9_common.h"
michael@0 15 #include "vp9/common/vp9_pred_common.h"
michael@0 16 #include "vp9/common/vp9_seg_common.h"
michael@0 17 #include "vp9/common/vp9_treecoder.h"
michael@0 18
michael@0 19 static INLINE const MB_MODE_INFO *get_above_mbmi(const MODE_INFO *const above) {
michael@0 20 return (above != NULL) ? &above->mbmi : NULL;
michael@0 21 }
michael@0 22
michael@0 23 static INLINE const MB_MODE_INFO *get_left_mbmi(const MODE_INFO *const left) {
michael@0 24 return (left != NULL) ? &left->mbmi : NULL;
michael@0 25 }
michael@0 26
michael@0 27 // Returns a context number for the given MB prediction signal
michael@0 28 unsigned char vp9_get_pred_context_switchable_interp(const MACROBLOCKD *xd) {
michael@0 29 const MODE_INFO *const above_mi = get_above_mi(xd);
michael@0 30 const MODE_INFO *const left_mi = get_left_mi(xd);
michael@0 31 const int above_in_image = above_mi != NULL;
michael@0 32 const int left_in_image = left_mi != NULL;
michael@0 33 // Note:
michael@0 34 // The mode info data structure has a one element border above and to the
michael@0 35 // left of the entries correpsonding to real macroblocks.
michael@0 36 // The prediction flags in these dummy entries are initialised to 0.
michael@0 37 // left
michael@0 38 const int left_mv_pred = left_in_image ? is_inter_block(&left_mi->mbmi)
michael@0 39 : 0;
michael@0 40 const int left_interp = left_in_image && left_mv_pred
michael@0 41 ? left_mi->mbmi.interp_filter
michael@0 42 : SWITCHABLE_FILTERS;
michael@0 43
michael@0 44 // above
michael@0 45 const int above_mv_pred = above_in_image ? is_inter_block(&above_mi->mbmi)
michael@0 46 : 0;
michael@0 47 const int above_interp = above_in_image && above_mv_pred
michael@0 48 ? above_mi->mbmi.interp_filter
michael@0 49 : SWITCHABLE_FILTERS;
michael@0 50
michael@0 51 if (left_interp == above_interp)
michael@0 52 return left_interp;
michael@0 53 else if (left_interp == SWITCHABLE_FILTERS &&
michael@0 54 above_interp != SWITCHABLE_FILTERS)
michael@0 55 return above_interp;
michael@0 56 else if (left_interp != SWITCHABLE_FILTERS &&
michael@0 57 above_interp == SWITCHABLE_FILTERS)
michael@0 58 return left_interp;
michael@0 59 else
michael@0 60 return SWITCHABLE_FILTERS;
michael@0 61 }
michael@0 62 // Returns a context number for the given MB prediction signal
michael@0 63 unsigned char vp9_get_pred_context_intra_inter(const MACROBLOCKD *xd) {
michael@0 64 const MODE_INFO *const above_mi = get_above_mi(xd);
michael@0 65 const MODE_INFO *const left_mi = get_left_mi(xd);
michael@0 66 const MB_MODE_INFO *const above_mbmi = get_above_mbmi(above_mi);
michael@0 67 const MB_MODE_INFO *const left_mbmi = get_left_mbmi(left_mi);
michael@0 68 const int above_in_image = above_mi != NULL;
michael@0 69 const int left_in_image = left_mi != NULL;
michael@0 70 const int above_intra = above_in_image ? !is_inter_block(above_mbmi) : 1;
michael@0 71 const int left_intra = left_in_image ? !is_inter_block(left_mbmi) : 1;
michael@0 72
michael@0 73 // The mode info data structure has a one element border above and to the
michael@0 74 // left of the entries corresponding to real macroblocks.
michael@0 75 // The prediction flags in these dummy entries are initialized to 0.
michael@0 76 // 0 - inter/inter, inter/--, --/inter, --/--
michael@0 77 // 1 - intra/inter, inter/intra
michael@0 78 // 2 - intra/--, --/intra
michael@0 79 // 3 - intra/intra
michael@0 80 if (above_in_image && left_in_image) // both edges available
michael@0 81 return left_intra && above_intra ? 3
michael@0 82 : left_intra || above_intra;
michael@0 83 else if (above_in_image || left_in_image) // one edge available
michael@0 84 return 2 * (above_in_image ? above_intra : left_intra);
michael@0 85 else
michael@0 86 return 0;
michael@0 87 }
michael@0 88 // Returns a context number for the given MB prediction signal
michael@0 89 unsigned char vp9_get_pred_context_comp_inter_inter(const VP9_COMMON *cm,
michael@0 90 const MACROBLOCKD *xd) {
michael@0 91 int pred_context;
michael@0 92 const MODE_INFO *const above_mi = get_above_mi(xd);
michael@0 93 const MODE_INFO *const left_mi = get_left_mi(xd);
michael@0 94 const MB_MODE_INFO *const above_mbmi = get_above_mbmi(above_mi);
michael@0 95 const MB_MODE_INFO *const left_mbmi = get_left_mbmi(left_mi);
michael@0 96 const int above_in_image = above_mi != NULL;
michael@0 97 const int left_in_image = left_mi != NULL;
michael@0 98 // Note:
michael@0 99 // The mode info data structure has a one element border above and to the
michael@0 100 // left of the entries correpsonding to real macroblocks.
michael@0 101 // The prediction flags in these dummy entries are initialised to 0.
michael@0 102 if (above_in_image && left_in_image) { // both edges available
michael@0 103 if (!has_second_ref(above_mbmi) && !has_second_ref(left_mbmi))
michael@0 104 // neither edge uses comp pred (0/1)
michael@0 105 pred_context = (above_mbmi->ref_frame[0] == cm->comp_fixed_ref) ^
michael@0 106 (left_mbmi->ref_frame[0] == cm->comp_fixed_ref);
michael@0 107 else if (!has_second_ref(above_mbmi))
michael@0 108 // one of two edges uses comp pred (2/3)
michael@0 109 pred_context = 2 + (above_mbmi->ref_frame[0] == cm->comp_fixed_ref ||
michael@0 110 !is_inter_block(above_mbmi));
michael@0 111 else if (!has_second_ref(left_mbmi))
michael@0 112 // one of two edges uses comp pred (2/3)
michael@0 113 pred_context = 2 + (left_mbmi->ref_frame[0] == cm->comp_fixed_ref ||
michael@0 114 !is_inter_block(left_mbmi));
michael@0 115 else // both edges use comp pred (4)
michael@0 116 pred_context = 4;
michael@0 117 } else if (above_in_image || left_in_image) { // one edge available
michael@0 118 const MB_MODE_INFO *edge_mbmi = above_in_image ? above_mbmi : left_mbmi;
michael@0 119
michael@0 120 if (!has_second_ref(edge_mbmi))
michael@0 121 // edge does not use comp pred (0/1)
michael@0 122 pred_context = edge_mbmi->ref_frame[0] == cm->comp_fixed_ref;
michael@0 123 else
michael@0 124 // edge uses comp pred (3)
michael@0 125 pred_context = 3;
michael@0 126 } else { // no edges available (1)
michael@0 127 pred_context = 1;
michael@0 128 }
michael@0 129 assert(pred_context >= 0 && pred_context < COMP_INTER_CONTEXTS);
michael@0 130 return pred_context;
michael@0 131 }
michael@0 132
michael@0 133 // Returns a context number for the given MB prediction signal
michael@0 134 unsigned char vp9_get_pred_context_comp_ref_p(const VP9_COMMON *cm,
michael@0 135 const MACROBLOCKD *xd) {
michael@0 136 int pred_context;
michael@0 137 const MODE_INFO *const above_mi = get_above_mi(xd);
michael@0 138 const MODE_INFO *const left_mi = get_left_mi(xd);
michael@0 139 const MB_MODE_INFO *const above_mbmi = get_above_mbmi(above_mi);
michael@0 140 const MB_MODE_INFO *const left_mbmi = get_left_mbmi(left_mi);
michael@0 141 const int above_in_image = above_mi != NULL;
michael@0 142 const int left_in_image = left_mi != NULL;
michael@0 143 const int above_intra = above_in_image ? !is_inter_block(above_mbmi) : 1;
michael@0 144 const int left_intra = left_in_image ? !is_inter_block(left_mbmi) : 1;
michael@0 145 // Note:
michael@0 146 // The mode info data structure has a one element border above and to the
michael@0 147 // left of the entries correpsonding to real macroblocks.
michael@0 148 // The prediction flags in these dummy entries are initialised to 0.
michael@0 149 const int fix_ref_idx = cm->ref_frame_sign_bias[cm->comp_fixed_ref];
michael@0 150 const int var_ref_idx = !fix_ref_idx;
michael@0 151
michael@0 152 if (above_in_image && left_in_image) { // both edges available
michael@0 153 if (above_intra && left_intra) { // intra/intra (2)
michael@0 154 pred_context = 2;
michael@0 155 } else if (above_intra || left_intra) { // intra/inter
michael@0 156 const MB_MODE_INFO *edge_mbmi = above_intra ? left_mbmi : above_mbmi;
michael@0 157
michael@0 158 if (!has_second_ref(edge_mbmi)) // single pred (1/3)
michael@0 159 pred_context = 1 + 2 * (edge_mbmi->ref_frame[0] != cm->comp_var_ref[1]);
michael@0 160 else // comp pred (1/3)
michael@0 161 pred_context = 1 + 2 * (edge_mbmi->ref_frame[var_ref_idx]
michael@0 162 != cm->comp_var_ref[1]);
michael@0 163 } else { // inter/inter
michael@0 164 const int l_sg = !has_second_ref(left_mbmi);
michael@0 165 const int a_sg = !has_second_ref(above_mbmi);
michael@0 166 MV_REFERENCE_FRAME vrfa = a_sg ? above_mbmi->ref_frame[0]
michael@0 167 : above_mbmi->ref_frame[var_ref_idx];
michael@0 168 MV_REFERENCE_FRAME vrfl = l_sg ? left_mbmi->ref_frame[0]
michael@0 169 : left_mbmi->ref_frame[var_ref_idx];
michael@0 170
michael@0 171 if (vrfa == vrfl && cm->comp_var_ref[1] == vrfa) {
michael@0 172 pred_context = 0;
michael@0 173 } else if (l_sg && a_sg) { // single/single
michael@0 174 if ((vrfa == cm->comp_fixed_ref && vrfl == cm->comp_var_ref[0]) ||
michael@0 175 (vrfl == cm->comp_fixed_ref && vrfa == cm->comp_var_ref[0]))
michael@0 176 pred_context = 4;
michael@0 177 else if (vrfa == vrfl)
michael@0 178 pred_context = 3;
michael@0 179 else
michael@0 180 pred_context = 1;
michael@0 181 } else if (l_sg || a_sg) { // single/comp
michael@0 182 MV_REFERENCE_FRAME vrfc = l_sg ? vrfa : vrfl;
michael@0 183 MV_REFERENCE_FRAME rfs = a_sg ? vrfa : vrfl;
michael@0 184 if (vrfc == cm->comp_var_ref[1] && rfs != cm->comp_var_ref[1])
michael@0 185 pred_context = 1;
michael@0 186 else if (rfs == cm->comp_var_ref[1] && vrfc != cm->comp_var_ref[1])
michael@0 187 pred_context = 2;
michael@0 188 else
michael@0 189 pred_context = 4;
michael@0 190 } else if (vrfa == vrfl) { // comp/comp
michael@0 191 pred_context = 4;
michael@0 192 } else {
michael@0 193 pred_context = 2;
michael@0 194 }
michael@0 195 }
michael@0 196 } else if (above_in_image || left_in_image) { // one edge available
michael@0 197 const MB_MODE_INFO *edge_mbmi = above_in_image ? above_mbmi : left_mbmi;
michael@0 198
michael@0 199 if (!is_inter_block(edge_mbmi)) {
michael@0 200 pred_context = 2;
michael@0 201 } else {
michael@0 202 if (has_second_ref(edge_mbmi))
michael@0 203 pred_context = 4 * (edge_mbmi->ref_frame[var_ref_idx]
michael@0 204 != cm->comp_var_ref[1]);
michael@0 205 else
michael@0 206 pred_context = 3 * (edge_mbmi->ref_frame[0] != cm->comp_var_ref[1]);
michael@0 207 }
michael@0 208 } else { // no edges available (2)
michael@0 209 pred_context = 2;
michael@0 210 }
michael@0 211 assert(pred_context >= 0 && pred_context < REF_CONTEXTS);
michael@0 212
michael@0 213 return pred_context;
michael@0 214 }
michael@0 215 unsigned char vp9_get_pred_context_single_ref_p1(const MACROBLOCKD *xd) {
michael@0 216 int pred_context;
michael@0 217 const MODE_INFO *const above_mi = get_above_mi(xd);
michael@0 218 const MODE_INFO *const left_mi = get_left_mi(xd);
michael@0 219 const MB_MODE_INFO *const above_mbmi = get_above_mbmi(above_mi);
michael@0 220 const MB_MODE_INFO *const left_mbmi = get_left_mbmi(left_mi);
michael@0 221 const int above_in_image = above_mi != NULL;
michael@0 222 const int left_in_image = left_mi != NULL;
michael@0 223 const int above_intra = above_in_image ? !is_inter_block(above_mbmi) : 1;
michael@0 224 const int left_intra = left_in_image ? !is_inter_block(left_mbmi) : 1;
michael@0 225 // Note:
michael@0 226 // The mode info data structure has a one element border above and to the
michael@0 227 // left of the entries correpsonding to real macroblocks.
michael@0 228 // The prediction flags in these dummy entries are initialised to 0.
michael@0 229 if (above_in_image && left_in_image) { // both edges available
michael@0 230 if (above_intra && left_intra) { // intra/intra
michael@0 231 pred_context = 2;
michael@0 232 } else if (above_intra || left_intra) { // intra/inter or inter/intra
michael@0 233 const MB_MODE_INFO *edge_mbmi = above_intra ? left_mbmi : above_mbmi;
michael@0 234 if (!has_second_ref(edge_mbmi))
michael@0 235 pred_context = 4 * (edge_mbmi->ref_frame[0] == LAST_FRAME);
michael@0 236 else
michael@0 237 pred_context = 1 + (edge_mbmi->ref_frame[0] == LAST_FRAME ||
michael@0 238 edge_mbmi->ref_frame[1] == LAST_FRAME);
michael@0 239 } else { // inter/inter
michael@0 240 if (!has_second_ref(above_mbmi) && !has_second_ref(left_mbmi)) {
michael@0 241 pred_context = 2 * (above_mbmi->ref_frame[0] == LAST_FRAME) +
michael@0 242 2 * (left_mbmi->ref_frame[0] == LAST_FRAME);
michael@0 243 } else if (has_second_ref(above_mbmi) && has_second_ref(left_mbmi)) {
michael@0 244 pred_context = 1 + (above_mbmi->ref_frame[0] == LAST_FRAME ||
michael@0 245 above_mbmi->ref_frame[1] == LAST_FRAME ||
michael@0 246 left_mbmi->ref_frame[0] == LAST_FRAME ||
michael@0 247 left_mbmi->ref_frame[1] == LAST_FRAME);
michael@0 248 } else {
michael@0 249 const MV_REFERENCE_FRAME rfs = !has_second_ref(above_mbmi) ?
michael@0 250 above_mbmi->ref_frame[0] : left_mbmi->ref_frame[0];
michael@0 251 const MV_REFERENCE_FRAME crf1 = has_second_ref(above_mbmi) ?
michael@0 252 above_mbmi->ref_frame[0] : left_mbmi->ref_frame[0];
michael@0 253 const MV_REFERENCE_FRAME crf2 = has_second_ref(above_mbmi) ?
michael@0 254 above_mbmi->ref_frame[1] : left_mbmi->ref_frame[1];
michael@0 255
michael@0 256 if (rfs == LAST_FRAME)
michael@0 257 pred_context = 3 + (crf1 == LAST_FRAME || crf2 == LAST_FRAME);
michael@0 258 else
michael@0 259 pred_context = crf1 == LAST_FRAME || crf2 == LAST_FRAME;
michael@0 260 }
michael@0 261 }
michael@0 262 } else if (above_in_image || left_in_image) { // one edge available
michael@0 263 const MB_MODE_INFO *edge_mbmi = above_in_image ? above_mbmi : left_mbmi;
michael@0 264 if (!is_inter_block(edge_mbmi)) { // intra
michael@0 265 pred_context = 2;
michael@0 266 } else { // inter
michael@0 267 if (!has_second_ref(edge_mbmi))
michael@0 268 pred_context = 4 * (edge_mbmi->ref_frame[0] == LAST_FRAME);
michael@0 269 else
michael@0 270 pred_context = 1 + (edge_mbmi->ref_frame[0] == LAST_FRAME ||
michael@0 271 edge_mbmi->ref_frame[1] == LAST_FRAME);
michael@0 272 }
michael@0 273 } else { // no edges available
michael@0 274 pred_context = 2;
michael@0 275 }
michael@0 276
michael@0 277 assert(pred_context >= 0 && pred_context < REF_CONTEXTS);
michael@0 278 return pred_context;
michael@0 279 }
michael@0 280
michael@0 281 unsigned char vp9_get_pred_context_single_ref_p2(const MACROBLOCKD *xd) {
michael@0 282 int pred_context;
michael@0 283 const MODE_INFO *const above_mi = get_above_mi(xd);
michael@0 284 const MODE_INFO *const left_mi = get_left_mi(xd);
michael@0 285 const MB_MODE_INFO *const above_mbmi = get_above_mbmi(above_mi);
michael@0 286 const MB_MODE_INFO *const left_mbmi = get_left_mbmi(left_mi);
michael@0 287 const int above_in_image = above_mi != NULL;
michael@0 288 const int left_in_image = left_mi != NULL;
michael@0 289 const int above_intra = above_in_image ? !is_inter_block(above_mbmi) : 1;
michael@0 290 const int left_intra = left_in_image ? !is_inter_block(left_mbmi) : 1;
michael@0 291
michael@0 292 // Note:
michael@0 293 // The mode info data structure has a one element border above and to the
michael@0 294 // left of the entries correpsonding to real macroblocks.
michael@0 295 // The prediction flags in these dummy entries are initialised to 0.
michael@0 296 if (above_in_image && left_in_image) { // both edges available
michael@0 297 if (above_intra && left_intra) { // intra/intra
michael@0 298 pred_context = 2;
michael@0 299 } else if (above_intra || left_intra) { // intra/inter or inter/intra
michael@0 300 const MB_MODE_INFO *edge_mbmi = above_intra ? left_mbmi : above_mbmi;
michael@0 301 if (!has_second_ref(edge_mbmi)) {
michael@0 302 if (edge_mbmi->ref_frame[0] == LAST_FRAME)
michael@0 303 pred_context = 3;
michael@0 304 else
michael@0 305 pred_context = 4 * (edge_mbmi->ref_frame[0] == GOLDEN_FRAME);
michael@0 306 } else {
michael@0 307 pred_context = 1 + 2 * (edge_mbmi->ref_frame[0] == GOLDEN_FRAME ||
michael@0 308 edge_mbmi->ref_frame[1] == GOLDEN_FRAME);
michael@0 309 }
michael@0 310 } else { // inter/inter
michael@0 311 if (!has_second_ref(above_mbmi) && !has_second_ref(left_mbmi)) {
michael@0 312 if (above_mbmi->ref_frame[0] == LAST_FRAME &&
michael@0 313 left_mbmi->ref_frame[0] == LAST_FRAME) {
michael@0 314 pred_context = 3;
michael@0 315 } else if (above_mbmi->ref_frame[0] == LAST_FRAME ||
michael@0 316 left_mbmi->ref_frame[0] == LAST_FRAME) {
michael@0 317 const MB_MODE_INFO *edge_mbmi =
michael@0 318 above_mbmi->ref_frame[0] == LAST_FRAME ? left_mbmi : above_mbmi;
michael@0 319
michael@0 320 pred_context = 4 * (edge_mbmi->ref_frame[0] == GOLDEN_FRAME);
michael@0 321 } else {
michael@0 322 pred_context = 2 * (above_mbmi->ref_frame[0] == GOLDEN_FRAME) +
michael@0 323 2 * (left_mbmi->ref_frame[0] == GOLDEN_FRAME);
michael@0 324 }
michael@0 325 } else if (has_second_ref(above_mbmi) && has_second_ref(left_mbmi)) {
michael@0 326 if (above_mbmi->ref_frame[0] == left_mbmi->ref_frame[0] &&
michael@0 327 above_mbmi->ref_frame[1] == left_mbmi->ref_frame[1])
michael@0 328 pred_context = 3 * (above_mbmi->ref_frame[0] == GOLDEN_FRAME ||
michael@0 329 above_mbmi->ref_frame[1] == GOLDEN_FRAME ||
michael@0 330 left_mbmi->ref_frame[0] == GOLDEN_FRAME ||
michael@0 331 left_mbmi->ref_frame[1] == GOLDEN_FRAME);
michael@0 332 else
michael@0 333 pred_context = 2;
michael@0 334 } else {
michael@0 335 const MV_REFERENCE_FRAME rfs = !has_second_ref(above_mbmi) ?
michael@0 336 above_mbmi->ref_frame[0] : left_mbmi->ref_frame[0];
michael@0 337 const MV_REFERENCE_FRAME crf1 = has_second_ref(above_mbmi) ?
michael@0 338 above_mbmi->ref_frame[0] : left_mbmi->ref_frame[0];
michael@0 339 const MV_REFERENCE_FRAME crf2 = has_second_ref(above_mbmi) ?
michael@0 340 above_mbmi->ref_frame[1] : left_mbmi->ref_frame[1];
michael@0 341
michael@0 342 if (rfs == GOLDEN_FRAME)
michael@0 343 pred_context = 3 + (crf1 == GOLDEN_FRAME || crf2 == GOLDEN_FRAME);
michael@0 344 else if (rfs == ALTREF_FRAME)
michael@0 345 pred_context = crf1 == GOLDEN_FRAME || crf2 == GOLDEN_FRAME;
michael@0 346 else
michael@0 347 pred_context = 1 + 2 * (crf1 == GOLDEN_FRAME || crf2 == GOLDEN_FRAME);
michael@0 348 }
michael@0 349 }
michael@0 350 } else if (above_in_image || left_in_image) { // one edge available
michael@0 351 const MB_MODE_INFO *edge_mbmi = above_in_image ? above_mbmi : left_mbmi;
michael@0 352
michael@0 353 if (!is_inter_block(edge_mbmi) ||
michael@0 354 (edge_mbmi->ref_frame[0] == LAST_FRAME && !has_second_ref(edge_mbmi)))
michael@0 355 pred_context = 2;
michael@0 356 else if (!has_second_ref(edge_mbmi))
michael@0 357 pred_context = 4 * (edge_mbmi->ref_frame[0] == GOLDEN_FRAME);
michael@0 358 else
michael@0 359 pred_context = 3 * (edge_mbmi->ref_frame[0] == GOLDEN_FRAME ||
michael@0 360 edge_mbmi->ref_frame[1] == GOLDEN_FRAME);
michael@0 361 } else { // no edges available (2)
michael@0 362 pred_context = 2;
michael@0 363 }
michael@0 364 assert(pred_context >= 0 && pred_context < REF_CONTEXTS);
michael@0 365 return pred_context;
michael@0 366 }
michael@0 367 // Returns a context number for the given MB prediction signal
michael@0 368 // The mode info data structure has a one element border above and to the
michael@0 369 // left of the entries corresponding to real blocks.
michael@0 370 // The prediction flags in these dummy entries are initialized to 0.
michael@0 371 unsigned char vp9_get_pred_context_tx_size(const MACROBLOCKD *xd) {
michael@0 372 const MODE_INFO *const above_mi = get_above_mi(xd);
michael@0 373 const MODE_INFO *const left_mi = get_left_mi(xd);
michael@0 374 const MB_MODE_INFO *const above_mbmi = get_above_mbmi(above_mi);
michael@0 375 const MB_MODE_INFO *const left_mbmi = get_left_mbmi(left_mi);
michael@0 376 const int above_in_image = above_mi != NULL;
michael@0 377 const int left_in_image = left_mi != NULL;
michael@0 378 const int max_tx_size = max_txsize_lookup[xd->mi_8x8[0]->mbmi.sb_type];
michael@0 379 int above_context = max_tx_size;
michael@0 380 int left_context = max_tx_size;
michael@0 381
michael@0 382 if (above_in_image)
michael@0 383 above_context = above_mbmi->skip_coeff ? max_tx_size
michael@0 384 : above_mbmi->tx_size;
michael@0 385
michael@0 386 if (left_in_image)
michael@0 387 left_context = left_mbmi->skip_coeff ? max_tx_size
michael@0 388 : left_mbmi->tx_size;
michael@0 389
michael@0 390 if (!left_in_image)
michael@0 391 left_context = above_context;
michael@0 392
michael@0 393 if (!above_in_image)
michael@0 394 above_context = left_context;
michael@0 395
michael@0 396 return above_context + left_context > max_tx_size;
michael@0 397 }
michael@0 398
michael@0 399 void vp9_set_pred_flag_seg_id(MACROBLOCKD *xd, uint8_t pred_flag) {
michael@0 400 xd->mi_8x8[0]->mbmi.seg_id_predicted = pred_flag;
michael@0 401 }
michael@0 402
michael@0 403 int vp9_get_segment_id(VP9_COMMON *cm, const uint8_t *segment_ids,
michael@0 404 BLOCK_SIZE bsize, int mi_row, int mi_col) {
michael@0 405 const int mi_offset = mi_row * cm->mi_cols + mi_col;
michael@0 406 const int bw = num_8x8_blocks_wide_lookup[bsize];
michael@0 407 const int bh = num_8x8_blocks_high_lookup[bsize];
michael@0 408 const int xmis = MIN(cm->mi_cols - mi_col, bw);
michael@0 409 const int ymis = MIN(cm->mi_rows - mi_row, bh);
michael@0 410 int x, y, segment_id = INT_MAX;
michael@0 411
michael@0 412 for (y = 0; y < ymis; y++)
michael@0 413 for (x = 0; x < xmis; x++)
michael@0 414 segment_id = MIN(segment_id,
michael@0 415 segment_ids[mi_offset + y * cm->mi_cols + x]);
michael@0 416
michael@0 417 assert(segment_id >= 0 && segment_id < MAX_SEGMENTS);
michael@0 418 return segment_id;
michael@0 419 }

mercurial