| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 static int delta_thresh(BLOCK_SIZE bs, int increase_denoising) { | 39 static int delta_thresh(BLOCK_SIZE bs, int increase_denoising) { |
| 40 (void)bs; | 40 (void)bs; |
| 41 (void)increase_denoising; | 41 (void)increase_denoising; |
| 42 return 4; | 42 return 4; |
| 43 } | 43 } |
| 44 | 44 |
| 45 static int noise_motion_thresh(BLOCK_SIZE bs, int increase_denoising) { | 45 static int noise_motion_thresh(BLOCK_SIZE bs, int increase_denoising) { |
| 46 (void)bs; | 46 (void)bs; |
| 47 (void)increase_denoising; | 47 (void)increase_denoising; |
| 48 return 25 * 25; | 48 return 625; |
| 49 } | 49 } |
| 50 | 50 |
| 51 static unsigned int sse_thresh(BLOCK_SIZE bs, int increase_denoising) { | 51 static unsigned int sse_thresh(BLOCK_SIZE bs, int increase_denoising) { |
| 52 return (1 << num_pels_log2_lookup[bs]) * (increase_denoising ? 60 : 40); | 52 return (1 << num_pels_log2_lookup[bs]) * (increase_denoising ? 60 : 40); |
| 53 } | 53 } |
| 54 | 54 |
| 55 static int sse_diff_thresh(BLOCK_SIZE bs, int increase_denoising, | 55 static int sse_diff_thresh(BLOCK_SIZE bs, int increase_denoising, |
| 56 int mv_row, int mv_col) { | 56 int motion_magnitude) { |
| 57 if (mv_row * mv_row + mv_col * mv_col > | 57 if (motion_magnitude > |
| 58 noise_motion_thresh(bs, increase_denoising)) { | 58 noise_motion_thresh(bs, increase_denoising)) { |
| 59 return 0; | 59 return 0; |
| 60 } else { | 60 } else { |
| 61 return (1 << num_pels_log2_lookup[bs]) * 20; | 61 return (1 << num_pels_log2_lookup[bs]) * 20; |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 | 64 |
| 65 int total_adj_strong_thresh(BLOCK_SIZE bs, int increase_denoising) { | 65 int total_adj_strong_thresh(BLOCK_SIZE bs, int increase_denoising) { |
| 66 return (1 << num_pels_log2_lookup[bs]) * (increase_denoising ? 3 : 2); | 66 return (1 << num_pels_log2_lookup[bs]) * (increase_denoising ? 3 : 2); |
| 67 } | 67 } |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 mv_col = ctx->best_sse_mv.as_mv.col; | 212 mv_col = ctx->best_sse_mv.as_mv.col; |
| 213 mv_row = ctx->best_sse_mv.as_mv.row; | 213 mv_row = ctx->best_sse_mv.as_mv.row; |
| 214 *motion_magnitude = mv_row * mv_row + mv_col * mv_col; | 214 *motion_magnitude = mv_row * mv_row + mv_col * mv_col; |
| 215 frame = ctx->best_reference_frame; | 215 frame = ctx->best_reference_frame; |
| 216 | 216 |
| 217 saved_mbmi = *mbmi; | 217 saved_mbmi = *mbmi; |
| 218 | 218 |
| 219 // If the best reference frame uses inter-prediction and there is enough of a | 219 // If the best reference frame uses inter-prediction and there is enough of a |
| 220 // difference in sum-squared-error, use it. | 220 // difference in sum-squared-error, use it. |
| 221 if (frame != INTRA_FRAME && | 221 if (frame != INTRA_FRAME && |
| 222 sse_diff > sse_diff_thresh(bs, increase_denoising, mv_row, mv_col)) { | 222 sse_diff > sse_diff_thresh(bs, increase_denoising, *motion_magnitude)) { |
| 223 mbmi->ref_frame[0] = ctx->best_reference_frame; | 223 mbmi->ref_frame[0] = ctx->best_reference_frame; |
| 224 mbmi->mode = ctx->best_sse_inter_mode; | 224 mbmi->mode = ctx->best_sse_inter_mode; |
| 225 mbmi->mv[0] = ctx->best_sse_mv; | 225 mbmi->mv[0] = ctx->best_sse_mv; |
| 226 } else { | 226 } else { |
| 227 // Otherwise, use the zero reference frame. | 227 // Otherwise, use the zero reference frame. |
| 228 frame = ctx->best_zeromv_reference_frame; | 228 frame = ctx->best_zeromv_reference_frame; |
| 229 | 229 |
| 230 mbmi->ref_frame[0] = ctx->best_zeromv_reference_frame; | 230 mbmi->ref_frame[0] = ctx->best_zeromv_reference_frame; |
| 231 mbmi->mode = ZEROMV; | 231 mbmi->mode = ZEROMV; |
| 232 mbmi->mv[0].as_int = 0; | 232 mbmi->mv[0].as_int = 0; |
| 233 | 233 |
| 234 ctx->best_sse_inter_mode = ZEROMV; | 234 ctx->best_sse_inter_mode = ZEROMV; |
| 235 ctx->best_sse_mv.as_int = 0; | 235 ctx->best_sse_mv.as_int = 0; |
| 236 ctx->newmv_sse = ctx->zeromv_sse; | 236 ctx->newmv_sse = ctx->zeromv_sse; |
| 237 } | 237 } |
| 238 | 238 |
| 239 if (ctx->newmv_sse > sse_thresh(bs, increase_denoising)) { | 239 if (ctx->newmv_sse > sse_thresh(bs, increase_denoising)) { |
| 240 // Restore everything to its original state | 240 // Restore everything to its original state |
| 241 *mbmi = saved_mbmi; | 241 *mbmi = saved_mbmi; |
| 242 return COPY_BLOCK; | 242 return COPY_BLOCK; |
| 243 } | 243 } |
| 244 if (mv_row * mv_row + mv_col * mv_col > | 244 if (*motion_magnitude > |
| 245 8 * noise_motion_thresh(bs, increase_denoising)) { | 245 (noise_motion_thresh(bs, increase_denoising) << 3)) { |
| 246 // Restore everything to its original state | 246 // Restore everything to its original state |
| 247 *mbmi = saved_mbmi; | 247 *mbmi = saved_mbmi; |
| 248 return COPY_BLOCK; | 248 return COPY_BLOCK; |
| 249 } | 249 } |
| 250 | 250 |
| 251 // We will restore these after motion compensation. | 251 // We will restore these after motion compensation. |
| 252 for (i = 0; i < MAX_MB_PLANE; ++i) { | 252 for (i = 0; i < MAX_MB_PLANE; ++i) { |
| 253 for (j = 0; j < 2; ++j) { | 253 for (j = 0; j < 2; ++j) { |
| 254 saved_pre[i][j] = filter_mbd->plane[i].pre[j]; | 254 saved_pre[i][j] = filter_mbd->plane[i].pre[j]; |
| 255 } | 255 } |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 &denoiser->running_avg_y[INTRA_FRAME]); | 396 &denoiser->running_avg_y[INTRA_FRAME]); |
| 397 } | 397 } |
| 398 if (refresh_last_frame) { | 398 if (refresh_last_frame) { |
| 399 swap_frame_buffer(&denoiser->running_avg_y[LAST_FRAME], | 399 swap_frame_buffer(&denoiser->running_avg_y[LAST_FRAME], |
| 400 &denoiser->running_avg_y[INTRA_FRAME]); | 400 &denoiser->running_avg_y[INTRA_FRAME]); |
| 401 } | 401 } |
| 402 } | 402 } |
| 403 | 403 |
| 404 void vp9_denoiser_reset_frame_stats(PICK_MODE_CONTEXT *ctx) { | 404 void vp9_denoiser_reset_frame_stats(PICK_MODE_CONTEXT *ctx) { |
| 405 ctx->zeromv_sse = UINT_MAX; | 405 ctx->zeromv_sse = UINT_MAX; |
| 406 // This should be initialized as zero since mode search stage might skip | 406 ctx->newmv_sse = UINT_MAX; |
| 407 // NEWMV mode if inferred motion vector modes provide sufficiently good | |
| 408 // prediction quality. | |
| 409 ctx->newmv_sse = 0; | |
| 410 } | 407 } |
| 411 | 408 |
| 412 void vp9_denoiser_update_frame_stats(MB_MODE_INFO *mbmi, unsigned int sse, | 409 void vp9_denoiser_update_frame_stats(MB_MODE_INFO *mbmi, unsigned int sse, |
| 413 PREDICTION_MODE mode, | 410 PREDICTION_MODE mode, |
| 414 PICK_MODE_CONTEXT *ctx) { | 411 PICK_MODE_CONTEXT *ctx) { |
| 415 // TODO(tkopp): Use both MVs if possible | 412 // TODO(tkopp): Use both MVs if possible |
| 416 if (mbmi->mv[0].as_int == 0 && sse < ctx->zeromv_sse) { | 413 if (mbmi->mv[0].as_int == 0 && sse < ctx->zeromv_sse) { |
| 417 ctx->zeromv_sse = sse; | 414 ctx->zeromv_sse = sse; |
| 418 ctx->best_zeromv_reference_frame = mbmi->ref_frame[0]; | 415 ctx->best_zeromv_reference_frame = mbmi->ref_frame[0]; |
| 419 } | 416 } |
| 420 | 417 |
| 421 if (mode == NEWMV) { | 418 if (mbmi->mv[0].as_int != 0 && sse < ctx->newmv_sse) { |
| 422 ctx->newmv_sse = sse; | 419 ctx->newmv_sse = sse; |
| 423 ctx->best_sse_inter_mode = mode; | 420 ctx->best_sse_inter_mode = mode; |
| 424 ctx->best_sse_mv = mbmi->mv[0]; | 421 ctx->best_sse_mv = mbmi->mv[0]; |
| 425 ctx->best_reference_frame = mbmi->ref_frame[0]; | 422 ctx->best_reference_frame = mbmi->ref_frame[0]; |
| 426 } | 423 } |
| 427 } | 424 } |
| 428 | 425 |
| 429 int vp9_denoiser_alloc(VP9_DENOISER *denoiser, int width, int height, | 426 int vp9_denoiser_alloc(VP9_DENOISER *denoiser, int width, int height, |
| 430 int ssx, int ssy, | 427 int ssx, int ssy, |
| 431 #if CONFIG_VP9_HIGHBITDEPTH | 428 #if CONFIG_VP9_HIGHBITDEPTH |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 for (r = 0; r < yuv->uv_height; ++r) { | 489 for (r = 0; r < yuv->uv_height; ++r) { |
| 493 for (c = 0; c < yuv->uv_width; ++c) { | 490 for (c = 0; c < yuv->uv_width; ++c) { |
| 494 u[c] = UINT8_MAX / 2; | 491 u[c] = UINT8_MAX / 2; |
| 495 v[c] = UINT8_MAX / 2; | 492 v[c] = UINT8_MAX / 2; |
| 496 } | 493 } |
| 497 u += yuv->uv_stride; | 494 u += yuv->uv_stride; |
| 498 v += yuv->uv_stride; | 495 v += yuv->uv_stride; |
| 499 } | 496 } |
| 500 } | 497 } |
| 501 #endif | 498 #endif |
| OLD | NEW |