Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(410)

Side by Side Diff: source/libvpx/vp9/common/vp9_entropymode.c

Issue 11974002: libvpx: Pull from upstream (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « source/libvpx/vp9/common/vp9_entropymode.h ('k') | source/libvpx/vp9/common/vp9_entropymv.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 -PARTITIONING_16X8, -PARTITIONING_8X16, 265 -PARTITIONING_16X8, -PARTITIONING_8X16,
266 }; 266 };
267 267
268 const vp9_tree_index vp9_mv_ref_tree[8] = { 268 const vp9_tree_index vp9_mv_ref_tree[8] = {
269 -ZEROMV, 2, 269 -ZEROMV, 2,
270 -NEARESTMV, 4, 270 -NEARESTMV, 4,
271 -NEARMV, 6, 271 -NEARMV, 6,
272 -NEWMV, -SPLITMV 272 -NEWMV, -SPLITMV
273 }; 273 };
274 274
275 #if CONFIG_SUPERBLOCKS
276 const vp9_tree_index vp9_sb_mv_ref_tree[6] = { 275 const vp9_tree_index vp9_sb_mv_ref_tree[6] = {
277 -ZEROMV, 2, 276 -ZEROMV, 2,
278 -NEARESTMV, 4, 277 -NEARESTMV, 4,
279 -NEARMV, -NEWMV 278 -NEARMV, -NEWMV
280 }; 279 };
281 #endif
282 280
283 const vp9_tree_index vp9_sub_mv_ref_tree[6] = { 281 const vp9_tree_index vp9_sub_mv_ref_tree[6] = {
284 -LEFT4X4, 2, 282 -LEFT4X4, 2,
285 -ABOVE4X4, 4, 283 -ABOVE4X4, 4,
286 -ZERO4X4, -NEW4X4 284 -ZERO4X4, -NEW4X4
287 }; 285 };
288 286
289 struct vp9_token_struct vp9_bmode_encodings[VP9_NKF_BINTRAMODES]; 287 struct vp9_token_struct vp9_bmode_encodings[VP9_NKF_BINTRAMODES];
290 struct vp9_token_struct vp9_kf_bmode_encodings[VP9_KF_BINTRAMODES]; 288 struct vp9_token_struct vp9_kf_bmode_encodings[VP9_KF_BINTRAMODES];
291 struct vp9_token_struct vp9_ymode_encodings[VP9_YMODES]; 289 struct vp9_token_struct vp9_ymode_encodings[VP9_YMODES];
292 #if CONFIG_SUPERBLOCKS
293 struct vp9_token_struct vp9_sb_ymode_encodings[VP9_I32X32_MODES]; 290 struct vp9_token_struct vp9_sb_ymode_encodings[VP9_I32X32_MODES];
294 struct vp9_token_struct vp9_sb_kf_ymode_encodings[VP9_I32X32_MODES]; 291 struct vp9_token_struct vp9_sb_kf_ymode_encodings[VP9_I32X32_MODES];
295 #endif
296 struct vp9_token_struct vp9_kf_ymode_encodings[VP9_YMODES]; 292 struct vp9_token_struct vp9_kf_ymode_encodings[VP9_YMODES];
297 struct vp9_token_struct vp9_uv_mode_encodings[VP9_UV_MODES]; 293 struct vp9_token_struct vp9_uv_mode_encodings[VP9_UV_MODES];
298 struct vp9_token_struct vp9_i8x8_mode_encodings[VP9_I8X8_MODES]; 294 struct vp9_token_struct vp9_i8x8_mode_encodings[VP9_I8X8_MODES];
299 struct vp9_token_struct vp9_mbsplit_encodings[VP9_NUMMBSPLITS]; 295 struct vp9_token_struct vp9_mbsplit_encodings[VP9_NUMMBSPLITS];
300 296
301 struct vp9_token_struct vp9_mv_ref_encoding_array[VP9_MVREFS]; 297 struct vp9_token_struct vp9_mv_ref_encoding_array[VP9_MVREFS];
302 #if CONFIG_SUPERBLOCKS
303 struct vp9_token_struct vp9_sb_mv_ref_encoding_array[VP9_MVREFS]; 298 struct vp9_token_struct vp9_sb_mv_ref_encoding_array[VP9_MVREFS];
304 #endif
305 struct vp9_token_struct vp9_sub_mv_ref_encoding_array[VP9_SUBMVREFS]; 299 struct vp9_token_struct vp9_sub_mv_ref_encoding_array[VP9_SUBMVREFS];
306 300
307 void vp9_init_mbmode_probs(VP9_COMMON *x) { 301 void vp9_init_mbmode_probs(VP9_COMMON *x) {
308 unsigned int bct [VP9_YMODES] [2]; /* num Ymodes > num UV modes */ 302 unsigned int bct [VP9_YMODES] [2]; /* num Ymodes > num UV modes */
309 303
310 vp9_tree_probs_from_distribution(VP9_YMODES, vp9_ymode_encodings, 304 vp9_tree_probs_from_distribution(VP9_YMODES, vp9_ymode_encodings,
311 vp9_ymode_tree, x->fc.ymode_prob, 305 vp9_ymode_tree, x->fc.ymode_prob,
312 bct, y_mode_cts, 256, 1); 306 bct, y_mode_cts);
313 #if CONFIG_SUPERBLOCKS
314 vp9_tree_probs_from_distribution(VP9_I32X32_MODES, vp9_sb_ymode_encodings, 307 vp9_tree_probs_from_distribution(VP9_I32X32_MODES, vp9_sb_ymode_encodings,
315 vp9_sb_ymode_tree, x->fc.sb_ymode_prob, 308 vp9_sb_ymode_tree, x->fc.sb_ymode_prob,
316 bct, y_mode_cts, 256, 1); 309 bct, y_mode_cts);
317 #endif
318 { 310 {
319 int i; 311 int i;
320 for (i = 0; i < 8; i++) { 312 for (i = 0; i < 8; i++) {
321 vp9_tree_probs_from_distribution(VP9_YMODES, vp9_kf_ymode_encodings, 313 vp9_tree_probs_from_distribution(VP9_YMODES, vp9_kf_ymode_encodings,
322 vp9_kf_ymode_tree, x->kf_ymode_prob[i], 314 vp9_kf_ymode_tree, x->kf_ymode_prob[i],
323 bct, kf_y_mode_cts[i], 256, 1); 315 bct, kf_y_mode_cts[i]);
324 #if CONFIG_SUPERBLOCKS
325 vp9_tree_probs_from_distribution(VP9_I32X32_MODES, 316 vp9_tree_probs_from_distribution(VP9_I32X32_MODES,
326 vp9_sb_kf_ymode_encodings, 317 vp9_sb_kf_ymode_encodings,
327 vp9_sb_kf_ymode_tree, 318 vp9_sb_kf_ymode_tree,
328 x->sb_kf_ymode_prob[i], bct, 319 x->sb_kf_ymode_prob[i], bct,
329 kf_y_mode_cts[i], 256, 1); 320 kf_y_mode_cts[i]);
330 #endif
331 } 321 }
332 } 322 }
333 { 323 {
334 int i; 324 int i;
335 for (i = 0; i < VP9_YMODES; i++) { 325 for (i = 0; i < VP9_YMODES; i++) {
336 vp9_tree_probs_from_distribution(VP9_UV_MODES, vp9_uv_mode_encodings, 326 vp9_tree_probs_from_distribution(VP9_UV_MODES, vp9_uv_mode_encodings,
337 vp9_uv_mode_tree, x->kf_uv_mode_prob[i], 327 vp9_uv_mode_tree, x->kf_uv_mode_prob[i],
338 bct, kf_uv_mode_cts[i], 256, 1); 328 bct, kf_uv_mode_cts[i]);
339 vp9_tree_probs_from_distribution(VP9_UV_MODES, vp9_uv_mode_encodings, 329 vp9_tree_probs_from_distribution(VP9_UV_MODES, vp9_uv_mode_encodings,
340 vp9_uv_mode_tree, x->fc.uv_mode_prob[i], 330 vp9_uv_mode_tree, x->fc.uv_mode_prob[i],
341 bct, uv_mode_cts[i], 256, 1); 331 bct, uv_mode_cts[i]);
342 } 332 }
343 } 333 }
344 334
345 vp9_tree_probs_from_distribution(VP9_I8X8_MODES, vp9_i8x8_mode_encodings, 335 vp9_tree_probs_from_distribution(VP9_I8X8_MODES, vp9_i8x8_mode_encodings,
346 vp9_i8x8_mode_tree, x->fc.i8x8_mode_prob, 336 vp9_i8x8_mode_tree, x->fc.i8x8_mode_prob,
347 bct, i8x8_mode_cts, 256, 1); 337 bct, i8x8_mode_cts);
348 338
349 vpx_memcpy(x->fc.sub_mv_ref_prob, vp9_sub_mv_ref_prob2, 339 vpx_memcpy(x->fc.sub_mv_ref_prob, vp9_sub_mv_ref_prob2,
350 sizeof(vp9_sub_mv_ref_prob2)); 340 sizeof(vp9_sub_mv_ref_prob2));
351 vpx_memcpy(x->fc.mbsplit_prob, vp9_mbsplit_probs, sizeof(vp9_mbsplit_probs)); 341 vpx_memcpy(x->fc.mbsplit_prob, vp9_mbsplit_probs, sizeof(vp9_mbsplit_probs));
352 vpx_memcpy(x->fc.switchable_interp_prob, vp9_switchable_interp_prob, 342 vpx_memcpy(x->fc.switchable_interp_prob, vp9_switchable_interp_prob,
353 sizeof(vp9_switchable_interp_prob)); 343 sizeof(vp9_switchable_interp_prob));
354 #if CONFIG_COMP_INTERINTRA_PRED 344 #if CONFIG_COMP_INTERINTRA_PRED
355 x->fc.interintra_prob = VP9_DEF_INTERINTRA_PROB; 345 x->fc.interintra_prob = VP9_DEF_INTERINTRA_PROB;
356 #endif 346 #endif
357 } 347 }
358 348
359 349
360 static void intra_bmode_probs_from_distribution( 350 static void intra_bmode_probs_from_distribution(
361 vp9_prob p[VP9_NKF_BINTRAMODES - 1], 351 vp9_prob p[VP9_NKF_BINTRAMODES - 1],
362 unsigned int branch_ct[VP9_NKF_BINTRAMODES - 1][2], 352 unsigned int branch_ct[VP9_NKF_BINTRAMODES - 1][2],
363 const unsigned int events[VP9_NKF_BINTRAMODES]) { 353 const unsigned int events[VP9_NKF_BINTRAMODES]) {
364 vp9_tree_probs_from_distribution(VP9_NKF_BINTRAMODES, vp9_bmode_encodings, 354 vp9_tree_probs_from_distribution(VP9_NKF_BINTRAMODES, vp9_bmode_encodings,
365 vp9_bmode_tree, p, branch_ct, events, 256, 1); 355 vp9_bmode_tree, p, branch_ct, events);
366 } 356 }
367 357
368 void vp9_default_bmode_probs(vp9_prob p[VP9_NKF_BINTRAMODES - 1]) { 358 void vp9_default_bmode_probs(vp9_prob p[VP9_NKF_BINTRAMODES - 1]) {
369 unsigned int branch_ct[VP9_NKF_BINTRAMODES - 1][2]; 359 unsigned int branch_ct[VP9_NKF_BINTRAMODES - 1][2];
370 intra_bmode_probs_from_distribution(p, branch_ct, bmode_cts); 360 intra_bmode_probs_from_distribution(p, branch_ct, bmode_cts);
371 } 361 }
372 362
373 static void intra_kf_bmode_probs_from_distribution( 363 static void intra_kf_bmode_probs_from_distribution(
374 vp9_prob p[VP9_KF_BINTRAMODES - 1], 364 vp9_prob p[VP9_KF_BINTRAMODES - 1],
375 unsigned int branch_ct[VP9_KF_BINTRAMODES - 1][2], 365 unsigned int branch_ct[VP9_KF_BINTRAMODES - 1][2],
376 const unsigned int events[VP9_KF_BINTRAMODES]) { 366 const unsigned int events[VP9_KF_BINTRAMODES]) {
377 vp9_tree_probs_from_distribution(VP9_KF_BINTRAMODES, vp9_kf_bmode_encodings, 367 vp9_tree_probs_from_distribution(VP9_KF_BINTRAMODES, vp9_kf_bmode_encodings,
378 vp9_kf_bmode_tree, p, branch_ct, events, 256, 1); 368 vp9_kf_bmode_tree, p, branch_ct, events);
379 } 369 }
380 370
381 void vp9_kf_default_bmode_probs(vp9_prob p[VP9_KF_BINTRAMODES] 371 void vp9_kf_default_bmode_probs(vp9_prob p[VP9_KF_BINTRAMODES]
382 [VP9_KF_BINTRAMODES] 372 [VP9_KF_BINTRAMODES]
383 [VP9_KF_BINTRAMODES - 1]) { 373 [VP9_KF_BINTRAMODES - 1]) {
384 unsigned int branch_ct[VP9_KF_BINTRAMODES - 1][2]; 374 unsigned int branch_ct[VP9_KF_BINTRAMODES - 1][2];
385 int i, j; 375 int i, j;
386 376
387 for (i = 0; i < VP9_KF_BINTRAMODES; ++i) { 377 for (i = 0; i < VP9_KF_BINTRAMODES; ++i) {
388 for (j = 0; j < VP9_KF_BINTRAMODES; ++j) { 378 for (j = 0; j < VP9_KF_BINTRAMODES; ++j) {
389 intra_kf_bmode_probs_from_distribution( 379 intra_kf_bmode_probs_from_distribution(
390 p[i][j], branch_ct, vp9_kf_default_bmode_counts[i][j]); 380 p[i][j], branch_ct, vp9_kf_default_bmode_counts[i][j]);
391 } 381 }
392 } 382 }
393 } 383 }
394 384
395 #if VP9_SWITCHABLE_FILTERS == 3 385 #if VP9_SWITCHABLE_FILTERS == 3
396 const vp9_tree_index vp9_switchable_interp_tree[VP9_SWITCHABLE_FILTERS*2-2] = { 386 const vp9_tree_index vp9_switchable_interp_tree[VP9_SWITCHABLE_FILTERS*2-2] = {
397 -0, 2, 387 -0, 2,
398 -1, -2 388 -1, -2
399 }; 389 };
400 struct vp9_token_struct vp9_switchable_interp_encodings[VP9_SWITCHABLE_FILTERS]; 390 struct vp9_token_struct vp9_switchable_interp_encodings[VP9_SWITCHABLE_FILTERS];
391 #if CONFIG_ENABLE_6TAP
401 const INTERPOLATIONFILTERTYPE vp9_switchable_interp[VP9_SWITCHABLE_FILTERS] = { 392 const INTERPOLATIONFILTERTYPE vp9_switchable_interp[VP9_SWITCHABLE_FILTERS] = {
402 EIGHTTAP, SIXTAP, EIGHTTAP_SHARP}; 393 SIXTAP, EIGHTTAP, EIGHTTAP_SHARP};
403 const int vp9_switchable_interp_map[SWITCHABLE+1] = {1, -1, 0, 2, -1}; 394 const int vp9_switchable_interp_map[SWITCHABLE+1] = {0, -1, 1, 2, -1, -1};
395 #else
396 const INTERPOLATIONFILTERTYPE vp9_switchable_interp[VP9_SWITCHABLE_FILTERS] = {
397 EIGHTTAP, EIGHTTAP_SMOOTH, EIGHTTAP_SHARP};
398 const int vp9_switchable_interp_map[SWITCHABLE+1] = {1, 0, 2, -1, -1};
399 #endif
404 const vp9_prob vp9_switchable_interp_prob [VP9_SWITCHABLE_FILTERS+1] 400 const vp9_prob vp9_switchable_interp_prob [VP9_SWITCHABLE_FILTERS+1]
405 [VP9_SWITCHABLE_FILTERS-1] = { 401 [VP9_SWITCHABLE_FILTERS-1] = {
406 {248, 192}, { 32, 248}, { 32, 32}, {192, 160} 402 {248, 192}, { 32, 248}, { 32, 32}, {192, 160}
407 }; 403 };
408 #elif VP9_SWITCHABLE_FILTERS == 2 404 #elif VP9_SWITCHABLE_FILTERS == 2
409 const vp9_tree_index vp9_switchable_interp_tree[VP9_SWITCHABLE_FILTERS*2-2] = { 405 const vp9_tree_index vp9_switchable_interp_tree[VP9_SWITCHABLE_FILTERS*2-2] = {
410 -0, -1, 406 -0, -1,
411 }; 407 };
412 struct vp9_token_struct vp9_switchable_interp_encodings[VP9_SWITCHABLE_FILTERS]; 408 struct vp9_token_struct vp9_switchable_interp_encodings[VP9_SWITCHABLE_FILTERS];
413 const vp9_prob vp9_switchable_interp_prob [VP9_SWITCHABLE_FILTERS+1] 409 const vp9_prob vp9_switchable_interp_prob [VP9_SWITCHABLE_FILTERS+1]
414 [VP9_SWITCHABLE_FILTERS-1] = { 410 [VP9_SWITCHABLE_FILTERS-1] = {
415 {248}, 411 {248},
416 { 64}, 412 { 64},
417 {192}, 413 {192},
418 }; 414 };
419 const INTERPOLATIONFILTERTYPE vp9_switchable_interp[VP9_SWITCHABLE_FILTERS] = { 415 const INTERPOLATIONFILTERTYPE vp9_switchable_interp[VP9_SWITCHABLE_FILTERS] = {
420 EIGHTTAP, EIGHTTAP_SHARP}; 416 EIGHTTAP, EIGHTTAP_SHARP};
421 const int vp9_switchable_interp_map[SWITCHABLE+1] = {-1, -1, 0, 1, -1}; //8, 8s 417 #if CONFIG_ENABLE_6TAP
418 const int vp9_switchable_interp_map[SWITCHABLE+1] = {-1, -1, 0, 1, -1, -1};
419 #else
420 const int vp9_switchable_interp_map[SWITCHABLE+1] = {-1, 0, 1, -1, -1};
421 #endif
422 #endif 422 #endif
423 423
424 void vp9_entropy_mode_init() { 424 void vp9_entropy_mode_init() {
425 vp9_tokens_from_tree(vp9_kf_bmode_encodings, vp9_kf_bmode_tree); 425 vp9_tokens_from_tree(vp9_kf_bmode_encodings, vp9_kf_bmode_tree);
426 vp9_tokens_from_tree(vp9_bmode_encodings, vp9_bmode_tree); 426 vp9_tokens_from_tree(vp9_bmode_encodings, vp9_bmode_tree);
427 vp9_tokens_from_tree(vp9_ymode_encodings, vp9_ymode_tree); 427 vp9_tokens_from_tree(vp9_ymode_encodings, vp9_ymode_tree);
428 vp9_tokens_from_tree(vp9_kf_ymode_encodings, vp9_kf_ymode_tree); 428 vp9_tokens_from_tree(vp9_kf_ymode_encodings, vp9_kf_ymode_tree);
429 #if CONFIG_SUPERBLOCKS
430 vp9_tokens_from_tree(vp9_sb_ymode_encodings, vp9_sb_ymode_tree); 429 vp9_tokens_from_tree(vp9_sb_ymode_encodings, vp9_sb_ymode_tree);
431 vp9_tokens_from_tree(vp9_sb_kf_ymode_encodings, vp9_sb_kf_ymode_tree); 430 vp9_tokens_from_tree(vp9_sb_kf_ymode_encodings, vp9_sb_kf_ymode_tree);
432 #endif
433 vp9_tokens_from_tree(vp9_uv_mode_encodings, vp9_uv_mode_tree); 431 vp9_tokens_from_tree(vp9_uv_mode_encodings, vp9_uv_mode_tree);
434 vp9_tokens_from_tree(vp9_i8x8_mode_encodings, vp9_i8x8_mode_tree); 432 vp9_tokens_from_tree(vp9_i8x8_mode_encodings, vp9_i8x8_mode_tree);
435 vp9_tokens_from_tree(vp9_mbsplit_encodings, vp9_mbsplit_tree); 433 vp9_tokens_from_tree(vp9_mbsplit_encodings, vp9_mbsplit_tree);
436 vp9_tokens_from_tree(vp9_switchable_interp_encodings, 434 vp9_tokens_from_tree(vp9_switchable_interp_encodings,
437 vp9_switchable_interp_tree); 435 vp9_switchable_interp_tree);
438 436
439 vp9_tokens_from_tree_offset(vp9_mv_ref_encoding_array, 437 vp9_tokens_from_tree_offset(vp9_mv_ref_encoding_array,
440 vp9_mv_ref_tree, NEARESTMV); 438 vp9_mv_ref_tree, NEARESTMV);
441 #if CONFIG_SUPERBLOCKS
442 vp9_tokens_from_tree_offset(vp9_sb_mv_ref_encoding_array, 439 vp9_tokens_from_tree_offset(vp9_sb_mv_ref_encoding_array,
443 vp9_sb_mv_ref_tree, NEARESTMV); 440 vp9_sb_mv_ref_tree, NEARESTMV);
444 #endif
445 vp9_tokens_from_tree_offset(vp9_sub_mv_ref_encoding_array, 441 vp9_tokens_from_tree_offset(vp9_sub_mv_ref_encoding_array,
446 vp9_sub_mv_ref_tree, LEFT4X4); 442 vp9_sub_mv_ref_tree, LEFT4X4);
447 } 443 }
448 444
449 void vp9_init_mode_contexts(VP9_COMMON *pc) { 445 void vp9_init_mode_contexts(VP9_COMMON *pc) {
450 vpx_memset(pc->fc.mv_ref_ct, 0, sizeof(pc->fc.mv_ref_ct)); 446 vpx_memset(pc->fc.mv_ref_ct, 0, sizeof(pc->fc.mv_ref_ct));
451 vpx_memcpy(pc->fc.vp9_mode_contexts, 447 vpx_memcpy(pc->fc.vp9_mode_contexts,
452 vp9_default_mode_contexts, 448 vp9_default_mode_contexts,
453 sizeof(vp9_default_mode_contexts)); 449 sizeof(vp9_default_mode_contexts));
454 } 450 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 int i, j; 484 int i, j;
489 unsigned int (*mv_ref_ct)[4][2]; 485 unsigned int (*mv_ref_ct)[4][2];
490 int (*mode_context)[4]; 486 int (*mode_context)[4];
491 487
492 mode_context = pc->fc.vp9_mode_contexts; 488 mode_context = pc->fc.vp9_mode_contexts;
493 489
494 mv_ref_ct = pc->fc.mv_ref_ct; 490 mv_ref_ct = pc->fc.mv_ref_ct;
495 491
496 for (j = 0; j < INTER_MODE_CONTEXTS; j++) { 492 for (j = 0; j < INTER_MODE_CONTEXTS; j++) {
497 for (i = 0; i < 4; i++) { 493 for (i = 0; i < 4; i++) {
498 int this_prob; 494 int count = mv_ref_ct[j][i][0] + mv_ref_ct[j][i][1], factor;
499 int count = mv_ref_ct[j][i][0] + mv_ref_ct[j][i][1]; 495
500 int factor; 496 count = count > MVREF_COUNT_SAT ? MVREF_COUNT_SAT : count;
501 { 497 factor = (MVREF_MAX_UPDATE_FACTOR * count / MVREF_COUNT_SAT);
502 this_prob = count > 0 ? 256 * mv_ref_ct[j][i][0] / count : 128; 498 mode_context[j][i] = weighted_prob(pc->fc.vp9_mode_contexts[j][i],
503 count = count > MVREF_COUNT_SAT ? MVREF_COUNT_SAT : count; 499 get_binary_prob(mv_ref_ct[j][i][0],
504 factor = (MVREF_MAX_UPDATE_FACTOR * count / MVREF_COUNT_SAT); 500 mv_ref_ct[j][i][1]),
505 this_prob = (pc->fc.vp9_mode_contexts[j][i] * (256 - factor) + 501 factor);
506 this_prob * factor + 128) >> 8;
507 mode_context[j][i] = clip_prob(this_prob);
508 }
509 } 502 }
510 } 503 }
511 } 504 }
512 505
513 #ifdef MODE_STATS 506 #ifdef MODE_STATS
514 #include "vp9/common/vp9_modecont.h" 507 #include "vp9/common/vp9_modecont.h"
515 void print_mode_contexts(VP9_COMMON *pc) { 508 void print_mode_contexts(VP9_COMMON *pc) {
516 int j, i; 509 int j, i;
517 printf("\n====================\n"); 510 printf("\n====================\n");
518 for (j = 0; j < INTER_MODE_CONTEXTS; j++) { 511 for (j = 0; j < INTER_MODE_CONTEXTS; j++) {
519 for (i = 0; i < 4; i++) { 512 for (i = 0; i < 4; i++) {
520 printf("%4d ", pc->fc.mode_context[j][i]); 513 printf("%4d ", pc->fc.mode_context[j][i]);
521 } 514 }
522 printf("\n"); 515 printf("\n");
523 } 516 }
524 printf("====================\n"); 517 printf("====================\n");
525 for (j = 0; j < INTER_MODE_CONTEXTS; j++) { 518 for (j = 0; j < INTER_MODE_CONTEXTS; j++) {
526 for (i = 0; i < 4; i++) { 519 for (i = 0; i < 4; i++) {
527 printf("%4d ", pc->fc.mode_context_a[j][i]); 520 printf("%4d ", pc->fc.mode_context_a[j][i]);
528 } 521 }
529 printf("\n"); 522 printf("\n");
530 } 523 }
531 } 524 }
532 #endif 525 #endif
533 526
534 // #define MODE_COUNT_TESTING
535 #define MODE_COUNT_SAT 20 527 #define MODE_COUNT_SAT 20
536 #define MODE_MAX_UPDATE_FACTOR 144 528 #define MODE_MAX_UPDATE_FACTOR 144
529 static void update_mode_probs(int n_modes, struct vp9_token_struct *encoding,
530 const vp9_tree_index *tree, unsigned int *cnt,
531 vp9_prob *pre_probs, vp9_prob *dst_probs) {
532 #define MAX_PROBS 32
533 vp9_prob probs[MAX_PROBS];
534 unsigned int branch_ct[MAX_PROBS][2];
535 int t, count, factor;
536
537 assert(n_modes - 1 < MAX_PROBS);
538 vp9_tree_probs_from_distribution(n_modes, encoding, tree, probs,
539 branch_ct, cnt);
540 for (t = 0; t < n_modes - 1; ++t) {
541 count = branch_ct[t][0] + branch_ct[t][1];
542 count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count;
543 factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_COUNT_SAT);
544 dst_probs[t] = weighted_prob(pre_probs[t], probs[t], factor);
545 }
546 }
547
548 // #define MODE_COUNT_TESTING
537 void vp9_adapt_mode_probs(VP9_COMMON *cm) { 549 void vp9_adapt_mode_probs(VP9_COMMON *cm) {
538 int i, t, count, factor; 550 int i;
539 unsigned int branch_ct[32][2];
540 vp9_prob ymode_probs[VP9_YMODES - 1];
541 #if CONFIG_SUPERBLOCKS
542 vp9_prob sb_ymode_probs[VP9_I32X32_MODES - 1];
543 #endif
544 vp9_prob uvmode_probs[VP9_UV_MODES - 1];
545 vp9_prob bmode_probs[VP9_NKF_BINTRAMODES - 1];
546 vp9_prob i8x8_mode_probs[VP9_I8X8_MODES - 1];
547 vp9_prob sub_mv_ref_probs[VP9_SUBMVREFS - 1];
548 vp9_prob mbsplit_probs[VP9_NUMMBSPLITS - 1];
549 #if CONFIG_COMP_INTERINTRA_PRED
550 vp9_prob interintra_prob;
551 #endif
552 #ifdef MODE_COUNT_TESTING 551 #ifdef MODE_COUNT_TESTING
552 int t;
553
553 printf("static const unsigned int\nymode_counts" 554 printf("static const unsigned int\nymode_counts"
554 "[VP9_YMODES] = {\n"); 555 "[VP9_YMODES] = {\n");
555 for (t = 0; t < VP9_YMODES; ++t) printf("%d, ", cm->fc.ymode_counts[t]); 556 for (t = 0; t < VP9_YMODES; ++t) printf("%d, ", cm->fc.ymode_counts[t]);
556 printf("};\n"); 557 printf("};\n");
557 printf("static const unsigned int\nuv_mode_counts" 558 printf("static const unsigned int\nuv_mode_counts"
558 "[VP9_YMODES] [VP9_UV_MODES] = {\n"); 559 "[VP9_YMODES] [VP9_UV_MODES] = {\n");
559 for (i = 0; i < VP9_YMODES; ++i) { 560 for (i = 0; i < VP9_YMODES; ++i) {
560 printf(" {"); 561 printf(" {");
561 for (t = 0; t < VP9_UV_MODES; ++t) printf("%d, ", cm->fc.uv_mode_counts[i][t ]); 562 for (t = 0; t < VP9_UV_MODES; ++t) printf("%d, ", cm->fc.uv_mode_counts[i][t ]);
562 printf("},\n"); 563 printf("},\n");
(...skipping 20 matching lines...) Expand all
583 "[VP9_NUMMBSPLITS] = {\n"); 584 "[VP9_NUMMBSPLITS] = {\n");
584 for (t = 0; t < VP9_NUMMBSPLITS; ++t) printf("%d, ", cm->fc.mbsplit_counts[t]) ; 585 for (t = 0; t < VP9_NUMMBSPLITS; ++t) printf("%d, ", cm->fc.mbsplit_counts[t]) ;
585 printf("};\n"); 586 printf("};\n");
586 #if CONFIG_COMP_INTERINTRA_PRED 587 #if CONFIG_COMP_INTERINTRA_PRED
587 printf("static const unsigned int\ninterintra_counts" 588 printf("static const unsigned int\ninterintra_counts"
588 "[2] = {\n"); 589 "[2] = {\n");
589 for (t = 0; t < 2; ++t) printf("%d, ", cm->fc.interintra_counts[t]); 590 for (t = 0; t < 2; ++t) printf("%d, ", cm->fc.interintra_counts[t]);
590 printf("};\n"); 591 printf("};\n");
591 #endif 592 #endif
592 #endif 593 #endif
593 vp9_tree_probs_from_distribution( 594
594 VP9_YMODES, vp9_ymode_encodings, vp9_ymode_tree, 595 update_mode_probs(VP9_YMODES, vp9_ymode_encodings, vp9_ymode_tree,
595 ymode_probs, branch_ct, cm->fc.ymode_counts, 596 cm->fc.ymode_counts, cm->fc.pre_ymode_prob,
596 256, 1); 597 cm->fc.ymode_prob);
597 for (t = 0; t < VP9_YMODES - 1; ++t) { 598 update_mode_probs(VP9_I32X32_MODES, vp9_sb_ymode_encodings, vp9_sb_ymode_tree,
598 int prob; 599 cm->fc.sb_ymode_counts, cm->fc.pre_sb_ymode_prob,
599 count = branch_ct[t][0] + branch_ct[t][1]; 600 cm->fc.sb_ymode_prob);
600 count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count; 601 for (i = 0; i < VP9_YMODES; ++i) {
601 factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_COUNT_SAT); 602 update_mode_probs(VP9_UV_MODES, vp9_uv_mode_encodings, vp9_uv_mode_tree,
602 prob = ((int)cm->fc.pre_ymode_prob[t] * (256 - factor) + 603 cm->fc.uv_mode_counts[i], cm->fc.pre_uv_mode_prob[i],
603 (int)ymode_probs[t] * factor + 128) >> 8; 604 cm->fc.uv_mode_prob[i]);
604 cm->fc.ymode_prob[t] = clip_prob(prob);
605 } 605 }
606 #if CONFIG_SUPERBLOCKS 606 update_mode_probs(VP9_NKF_BINTRAMODES, vp9_bmode_encodings, vp9_bmode_tree,
607 vp9_tree_probs_from_distribution(VP9_I32X32_MODES, 607 cm->fc.bmode_counts, cm->fc.pre_bmode_prob,
608 vp9_sb_ymode_encodings, vp9_sb_ymode_tree, 608 cm->fc.bmode_prob);
609 sb_ymode_probs, branch_ct, 609 update_mode_probs(VP9_I8X8_MODES, vp9_i8x8_mode_encodings,
610 cm->fc.sb_ymode_counts, 610 vp9_i8x8_mode_tree, cm->fc.i8x8_mode_counts,
611 256, 1); 611 cm->fc.pre_i8x8_mode_prob, cm->fc.i8x8_mode_prob);
612 for (t = 0; t < VP9_I32X32_MODES - 1; ++t) { 612 for (i = 0; i < SUBMVREF_COUNT; ++i) {
613 int prob; 613 update_mode_probs(VP9_SUBMVREFS, vp9_sub_mv_ref_encoding_array,
614 count = branch_ct[t][0] + branch_ct[t][1]; 614 vp9_sub_mv_ref_tree, cm->fc.sub_mv_ref_counts[i],
615 count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count; 615 cm->fc.pre_sub_mv_ref_prob[i], cm->fc.sub_mv_ref_prob[i]);
616 factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_COUNT_SAT);
617 prob = ((int)cm->fc.pre_sb_ymode_prob[t] * (256 - factor) +
618 (int)sb_ymode_probs[t] * factor + 128) >> 8;
619 cm->fc.sb_ymode_prob[t] = clip_prob(prob);
620 } 616 }
621 #endif 617 update_mode_probs(VP9_NUMMBSPLITS, vp9_mbsplit_encodings, vp9_mbsplit_tree,
622 for (i = 0; i < VP9_YMODES; ++i) { 618 cm->fc.mbsplit_counts, cm->fc.pre_mbsplit_prob,
623 vp9_tree_probs_from_distribution(VP9_UV_MODES, vp9_uv_mode_encodings, 619 cm->fc.mbsplit_prob);
624 vp9_uv_mode_tree, uvmode_probs, branch_ct,
625 cm->fc.uv_mode_counts[i], 256, 1);
626 for (t = 0; t < VP9_UV_MODES - 1; ++t) {
627 int prob;
628 count = branch_ct[t][0] + branch_ct[t][1];
629 count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count;
630 factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_COUNT_SAT);
631 prob = ((int)cm->fc.pre_uv_mode_prob[i][t] * (256 - factor) +
632 (int)uvmode_probs[t] * factor + 128) >> 8;
633 cm->fc.uv_mode_prob[i][t] = clip_prob(prob);
634 }
635 }
636 vp9_tree_probs_from_distribution(VP9_NKF_BINTRAMODES, vp9_bmode_encodings,
637 vp9_bmode_tree, bmode_probs, branch_ct,
638 cm->fc.bmode_counts, 256, 1);
639 for (t = 0; t < VP9_NKF_BINTRAMODES - 1; ++t) {
640 int prob;
641 count = branch_ct[t][0] + branch_ct[t][1];
642 count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count;
643 factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_COUNT_SAT);
644 prob = ((int)cm->fc.pre_bmode_prob[t] * (256 - factor) +
645 (int)bmode_probs[t] * factor + 128) >> 8;
646 cm->fc.bmode_prob[t] = clip_prob(prob);
647 }
648 vp9_tree_probs_from_distribution(VP9_I8X8_MODES, vp9_i8x8_mode_encodings,
649 vp9_i8x8_mode_tree, i8x8_mode_probs,
650 branch_ct, cm->fc.i8x8_mode_counts, 256, 1);
651 for (t = 0; t < VP9_I8X8_MODES - 1; ++t) {
652 int prob;
653 count = branch_ct[t][0] + branch_ct[t][1];
654 count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count;
655 factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_COUNT_SAT);
656 prob = ((int)cm->fc.pre_i8x8_mode_prob[t] * (256 - factor) +
657 (int)i8x8_mode_probs[t] * factor + 128) >> 8;
658 cm->fc.i8x8_mode_prob[t] = clip_prob(prob);
659 }
660 for (i = 0; i < SUBMVREF_COUNT; ++i) {
661 vp9_tree_probs_from_distribution(VP9_SUBMVREFS,
662 vp9_sub_mv_ref_encoding_array,
663 vp9_sub_mv_ref_tree, sub_mv_ref_probs,
664 branch_ct, cm->fc.sub_mv_ref_counts[i],
665 256, 1);
666 for (t = 0; t < VP9_SUBMVREFS - 1; ++t) {
667 int prob;
668 count = branch_ct[t][0] + branch_ct[t][1];
669 count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count;
670 factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_COUNT_SAT);
671 prob = ((int)cm->fc.pre_sub_mv_ref_prob[i][t] * (256 - factor) +
672 (int)sub_mv_ref_probs[t] * factor + 128) >> 8;
673 cm->fc.sub_mv_ref_prob[i][t] = clip_prob(prob);
674 }
675 }
676 vp9_tree_probs_from_distribution(VP9_NUMMBSPLITS, vp9_mbsplit_encodings,
677 vp9_mbsplit_tree, mbsplit_probs, branch_ct,
678 cm->fc.mbsplit_counts, 256, 1);
679 for (t = 0; t < VP9_NUMMBSPLITS - 1; ++t) {
680 int prob;
681 count = branch_ct[t][0] + branch_ct[t][1];
682 count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count;
683 factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_COUNT_SAT);
684 prob = ((int)cm->fc.pre_mbsplit_prob[t] * (256 - factor) +
685 (int)mbsplit_probs[t] * factor + 128) >> 8;
686 cm->fc.mbsplit_prob[t] = clip_prob(prob);
687 }
688 #if CONFIG_COMP_INTERINTRA_PRED 620 #if CONFIG_COMP_INTERINTRA_PRED
689 if (cm->use_interintra) { 621 if (cm->use_interintra) {
690 int prob; 622 int factor, interintra_prob, count;
691 interintra_prob = vp9_bin_prob_from_distribution(cm->fc.interintra_counts); 623
624 interintra_prob = get_binary_prob(cm->fc.interintra_counts[0],
625 cm->fc.interintra_counts[1]);
692 count = cm->fc.interintra_counts[0] + cm->fc.interintra_counts[1]; 626 count = cm->fc.interintra_counts[0] + cm->fc.interintra_counts[1];
693 count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count; 627 count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count;
694 factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_COUNT_SAT); 628 factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_COUNT_SAT);
695 prob = ((int)cm->fc.pre_interintra_prob * (256 - factor) + 629 cm->fc.interintra_prob = weighted_prob(cm->fc.pre_interintra_prob,
696 (int)interintra_prob * factor + 128) >> 8; 630 interintra_prob, factor);
697 if (prob <= 0)
698 cm->fc.interintra_prob = 1;
699 else if (prob > 255)
700 cm->fc.interintra_prob = 255;
701 else
702 cm->fc.interintra_prob = prob;
703 } 631 }
704 #endif 632 #endif
705 } 633 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/common/vp9_entropymode.h ('k') | source/libvpx/vp9/common/vp9_entropymv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698