| OLD | NEW |
| 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 |
| 11 #include <math.h> |
| 11 | 12 |
| 12 #include "vp9/common/vp9_common.h" | 13 #include "vp9/common/vp9_common.h" |
| 13 #include "vp9/encoder/vp9_encodemv.h" | |
| 14 #include "vp9/common/vp9_entropymode.h" | 14 #include "vp9/common/vp9_entropymode.h" |
| 15 #include "vp9/common/vp9_systemdependent.h" | 15 #include "vp9/common/vp9_systemdependent.h" |
| 16 #include "vp9/encoder/vp9_encodemv.h" |
| 16 | 17 |
| 17 #include <math.h> | |
| 18 | 18 |
| 19 #ifdef ENTROPY_STATS | 19 #ifdef ENTROPY_STATS |
| 20 extern unsigned int active_section; | 20 extern unsigned int active_section; |
| 21 #endif | 21 #endif |
| 22 | 22 |
| 23 static void encode_mv_component(vp9_writer* w, int comp, | 23 static void encode_mv_component(vp9_writer* w, int comp, |
| 24 const nmv_component* mvcomp, int usehp) { | 24 const nmv_component* mvcomp, int usehp) { |
| 25 int offset; | 25 int offset; |
| 26 const int sign = comp < 0; | 26 const int sign = comp < 0; |
| 27 const int mag = sign ? -comp : comp; | 27 const int mag = sign ? -comp : comp; |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 int mvc_flag_v, | 307 int mvc_flag_v, |
| 308 int mvc_flag_h) { | 308 int mvc_flag_h) { |
| 309 vp9_clear_system_state(); | 309 vp9_clear_system_state(); |
| 310 vp9_cost_tokens(mvjoint, mvctx->joints, vp9_mv_joint_tree); | 310 vp9_cost_tokens(mvjoint, mvctx->joints, vp9_mv_joint_tree); |
| 311 if (mvc_flag_v) | 311 if (mvc_flag_v) |
| 312 build_nmv_component_cost_table(mvcost[0], &mvctx->comps[0], usehp); | 312 build_nmv_component_cost_table(mvcost[0], &mvctx->comps[0], usehp); |
| 313 if (mvc_flag_h) | 313 if (mvc_flag_h) |
| 314 build_nmv_component_cost_table(mvcost[1], &mvctx->comps[1], usehp); | 314 build_nmv_component_cost_table(mvcost[1], &mvctx->comps[1], usehp); |
| 315 } | 315 } |
| 316 | 316 |
| 317 void vp9_update_nmv_count(VP9_COMP *cpi, MACROBLOCK *x, | 317 static void inc_mvs(int_mv mv[2], int_mv ref[2], int is_compound, |
| 318 int_mv *best_ref_mv, int_mv *second_best_ref_mv) { | 318 nmv_context_counts *counts) { |
| 319 int i; |
| 320 for (i = 0; i < 1 + is_compound; ++i) { |
| 321 const MV diff = { mv[i].as_mv.row - ref[i].as_mv.row, |
| 322 mv[i].as_mv.col - ref[i].as_mv.col }; |
| 323 vp9_inc_mv(&diff, counts); |
| 324 } |
| 325 } |
| 326 |
| 327 void vp9_update_mv_count(VP9_COMP *cpi, MACROBLOCK *x, int_mv best_ref_mv[2]) { |
| 319 MODE_INFO *mi = x->e_mbd.mi_8x8[0]; | 328 MODE_INFO *mi = x->e_mbd.mi_8x8[0]; |
| 320 MB_MODE_INFO *const mbmi = &mi->mbmi; | 329 MB_MODE_INFO *const mbmi = &mi->mbmi; |
| 321 MV diff; | 330 const int is_compound = has_second_ref(mbmi); |
| 322 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[mbmi->sb_type]; | |
| 323 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[mbmi->sb_type]; | |
| 324 int idx, idy; | |
| 325 | 331 |
| 326 if (mbmi->sb_type < BLOCK_8X8) { | 332 if (mbmi->sb_type < BLOCK_8X8) { |
| 327 PARTITION_INFO *pi = x->partition_info; | 333 const int num_4x4_w = num_4x4_blocks_wide_lookup[mbmi->sb_type]; |
| 328 for (idy = 0; idy < 2; idy += num_4x4_blocks_high) { | 334 const int num_4x4_h = num_4x4_blocks_high_lookup[mbmi->sb_type]; |
| 329 for (idx = 0; idx < 2; idx += num_4x4_blocks_wide) { | 335 int idx, idy; |
| 336 |
| 337 for (idy = 0; idy < 2; idy += num_4x4_h) { |
| 338 for (idx = 0; idx < 2; idx += num_4x4_w) { |
| 330 const int i = idy * 2 + idx; | 339 const int i = idy * 2 + idx; |
| 331 if (pi->bmi[i].mode == NEWMV) { | 340 if (mi->bmi[i].as_mode == NEWMV) |
| 332 diff.row = mi->bmi[i].as_mv[0].as_mv.row - best_ref_mv->as_mv.row; | 341 inc_mvs(mi->bmi[i].as_mv, best_ref_mv, is_compound, &cpi->NMVcount); |
| 333 diff.col = mi->bmi[i].as_mv[0].as_mv.col - best_ref_mv->as_mv.col; | |
| 334 vp9_inc_mv(&diff, &cpi->NMVcount); | |
| 335 | |
| 336 if (mi->mbmi.ref_frame[1] > INTRA_FRAME) { | |
| 337 diff.row = mi->bmi[i].as_mv[1].as_mv.row - | |
| 338 second_best_ref_mv->as_mv.row; | |
| 339 diff.col = mi->bmi[i].as_mv[1].as_mv.col - | |
| 340 second_best_ref_mv->as_mv.col; | |
| 341 vp9_inc_mv(&diff, &cpi->NMVcount); | |
| 342 } | |
| 343 } | |
| 344 } | 342 } |
| 345 } | 343 } |
| 346 } else if (mbmi->mode == NEWMV) { | 344 } else if (mbmi->mode == NEWMV) { |
| 347 diff.row = mbmi->mv[0].as_mv.row - best_ref_mv->as_mv.row; | 345 inc_mvs(mbmi->mv, best_ref_mv, is_compound, &cpi->NMVcount); |
| 348 diff.col = mbmi->mv[0].as_mv.col - best_ref_mv->as_mv.col; | |
| 349 vp9_inc_mv(&diff, &cpi->NMVcount); | |
| 350 | |
| 351 if (mbmi->ref_frame[1] > INTRA_FRAME) { | |
| 352 diff.row = mbmi->mv[1].as_mv.row - second_best_ref_mv->as_mv.row; | |
| 353 diff.col = mbmi->mv[1].as_mv.col - second_best_ref_mv->as_mv.col; | |
| 354 vp9_inc_mv(&diff, &cpi->NMVcount); | |
| 355 } | |
| 356 } | 346 } |
| 357 } | 347 } |
| OLD | NEW |