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 |
(...skipping 3352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3363 dst += 16 * skip * ystride; | 3363 dst += 16 * skip * ystride; |
3364 } | 3364 } |
3365 total = total * fac_framerate / 100; | 3365 total = total * fac_framerate / 100; |
3366 | 3366 |
3367 // Only consider this frame as valid sample if we have computed nmse over | 3367 // Only consider this frame as valid sample if we have computed nmse over |
3368 // at least ~1/16 blocks, and Total > 0 (Total == 0 can happen if the | 3368 // at least ~1/16 blocks, and Total > 0 (Total == 0 can happen if the |
3369 // application inputs duplicate frames, or contrast is all zero). | 3369 // application inputs duplicate frames, or contrast is all zero). |
3370 if (total > 0 && | 3370 if (total > 0 && |
3371 (num_blocks > (tot_num_blocks >> 4))) { | 3371 (num_blocks > (tot_num_blocks >> 4))) { |
3372 // Update the recursive mean square source_diff. | 3372 // Update the recursive mean square source_diff. |
3373 if (cpi->denoiser.nmse_source_diff_count == 0) | 3373 if (cpi->denoiser.nmse_source_diff_count == 0) { |
3374 // First sample in new interval. | 3374 // First sample in new interval. |
3375 cpi->denoiser.nmse_source_diff = total; | 3375 cpi->denoiser.nmse_source_diff = total; |
3376 else | 3376 cpi->denoiser.qp_avg = cm->base_qindex; |
| 3377 } else { |
3377 // For subsequent samples, use average with weight ~1/4 for new sample. | 3378 // For subsequent samples, use average with weight ~1/4 for new sample. |
3378 cpi->denoiser.nmse_source_diff = (int)((total >> 2) + | 3379 cpi->denoiser.nmse_source_diff = (int)((total >> 2) + |
3379 3 * (cpi->denoiser.nmse_source_diff >> 2)); | 3380 3 * (cpi->denoiser.nmse_source_diff >> 2)); |
| 3381 cpi->denoiser.qp_avg = (int)((cm->base_qindex >> 2) + |
| 3382 3 * (cpi->denoiser.qp_avg >> 2)); |
| 3383 } |
3380 cpi->denoiser.nmse_source_diff_count++; | 3384 cpi->denoiser.nmse_source_diff_count++; |
3381 } | 3385 } |
3382 // Check for changing the denoiser mode, when we have obtained #samples = | 3386 // Check for changing the denoiser mode, when we have obtained #samples = |
3383 // num_mode_change. | 3387 // num_mode_change. Condition the change also on the bitrate and QP. |
3384 if (cpi->denoiser.nmse_source_diff_count == num_mode_change) { | 3388 if (cpi->denoiser.nmse_source_diff_count == num_mode_change) { |
3385 // Check for going up: from normal to aggressive mode. | 3389 // Check for going up: from normal to aggressive mode. |
3386 if ((cpi->denoiser.denoiser_mode == kDenoiserOnYUV) && | 3390 if ((cpi->denoiser.denoiser_mode == kDenoiserOnYUV) && |
3387 (cpi->denoiser.nmse_source_diff > | 3391 (cpi->denoiser.nmse_source_diff > |
3388 cpi->denoiser.threshold_aggressive_mode)) { | 3392 cpi->denoiser.threshold_aggressive_mode) && |
| 3393 (cpi->denoiser.qp_avg < cpi->denoiser.qp_threshold_up && |
| 3394 cpi->target_bandwidth > cpi->denoiser.bitrate_threshold)) { |
3389 vp8_denoiser_set_parameters(&cpi->denoiser, kDenoiserOnYUVAggressive); | 3395 vp8_denoiser_set_parameters(&cpi->denoiser, kDenoiserOnYUVAggressive); |
3390 } else { | 3396 } else { |
3391 // Check for going down: from aggressive to normal mode. | 3397 // Check for going down: from aggressive to normal mode. |
3392 if ((cpi->denoiser.denoiser_mode == kDenoiserOnYUVAggressive) && | 3398 if (((cpi->denoiser.denoiser_mode == kDenoiserOnYUVAggressive) && |
3393 (cpi->denoiser.nmse_source_diff < | 3399 (cpi->denoiser.nmse_source_diff < |
3394 cpi->denoiser.threshold_aggressive_mode)) { | 3400 cpi->denoiser.threshold_aggressive_mode)) || |
| 3401 ((cpi->denoiser.denoiser_mode == kDenoiserOnYUVAggressive) && |
| 3402 (cpi->denoiser.qp_avg > cpi->denoiser.qp_threshold_down || |
| 3403 cpi->target_bandwidth < cpi->denoiser.bitrate_threshold))) { |
3395 vp8_denoiser_set_parameters(&cpi->denoiser, kDenoiserOnYUV); | 3404 vp8_denoiser_set_parameters(&cpi->denoiser, kDenoiserOnYUV); |
3396 } | 3405 } |
3397 } | 3406 } |
3398 // Reset metric and counter for next interval. | 3407 // Reset metric and counter for next interval. |
3399 cpi->denoiser.nmse_source_diff = 0; | 3408 cpi->denoiser.nmse_source_diff = 0; |
| 3409 cpi->denoiser.qp_avg = 0; |
3400 cpi->denoiser.nmse_source_diff_count = 0; | 3410 cpi->denoiser.nmse_source_diff_count = 0; |
3401 } | 3411 } |
3402 } | 3412 } |
3403 #endif | 3413 #endif |
3404 | 3414 |
3405 void vp8_loopfilter_frame(VP8_COMP *cpi, VP8_COMMON *cm) | 3415 void vp8_loopfilter_frame(VP8_COMP *cpi, VP8_COMMON *cm) |
3406 { | 3416 { |
3407 const FRAME_TYPE frame_type = cm->frame_type; | 3417 const FRAME_TYPE frame_type = cm->frame_type; |
3408 | 3418 |
3409 if (cm->no_lpf) | 3419 if (cm->no_lpf) |
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4006 q_low = cpi->active_best_quality; | 4016 q_low = cpi->active_best_quality; |
4007 q_high = cpi->active_worst_quality; | 4017 q_high = cpi->active_worst_quality; |
4008 #endif | 4018 #endif |
4009 | 4019 |
4010 vp8_save_coding_context(cpi); | 4020 vp8_save_coding_context(cpi); |
4011 | 4021 |
4012 loop_count = 0; | 4022 loop_count = 0; |
4013 | 4023 |
4014 scale_and_extend_source(cpi->un_scaled_source, cpi); | 4024 scale_and_extend_source(cpi->un_scaled_source, cpi); |
4015 | 4025 |
| 4026 #if CONFIG_TEMPORAL_DENOISING && CONFIG_POSTPROC |
| 4027 // Option to apply spatial blur under the aggressive or adaptive |
| 4028 // (temporal denoising) mode. |
| 4029 if (cpi->oxcf.noise_sensitivity >= 3) { |
| 4030 if (cpi->denoiser.denoise_pars.spatial_blur != 0) { |
| 4031 vp8_de_noise(cm, cpi->Source, cpi->Source, |
| 4032 cpi->denoiser.denoise_pars.spatial_blur, 1, 0, 0); |
| 4033 } |
| 4034 } |
| 4035 #endif |
| 4036 |
4016 #if !(CONFIG_REALTIME_ONLY) && CONFIG_POSTPROC && !(CONFIG_TEMPORAL_DENOISING) | 4037 #if !(CONFIG_REALTIME_ONLY) && CONFIG_POSTPROC && !(CONFIG_TEMPORAL_DENOISING) |
4017 | 4038 |
4018 if (cpi->oxcf.noise_sensitivity > 0) | 4039 if (cpi->oxcf.noise_sensitivity > 0) |
4019 { | 4040 { |
4020 unsigned char *src; | 4041 unsigned char *src; |
4021 int l = 0; | 4042 int l = 0; |
4022 | 4043 |
4023 switch (cpi->oxcf.noise_sensitivity) | 4044 switch (cpi->oxcf.noise_sensitivity) |
4024 { | 4045 { |
4025 case 1: | 4046 case 1: |
(...skipping 12 matching lines...) Expand all Loading... |
4038 l = 100; | 4059 l = 100; |
4039 break; | 4060 break; |
4040 case 6: | 4061 case 6: |
4041 l = 150; | 4062 l = 150; |
4042 break; | 4063 break; |
4043 } | 4064 } |
4044 | 4065 |
4045 | 4066 |
4046 if (cm->frame_type == KEY_FRAME) | 4067 if (cm->frame_type == KEY_FRAME) |
4047 { | 4068 { |
4048 vp8_de_noise(cm, cpi->Source, cpi->Source, l , 1, 0); | 4069 vp8_de_noise(cm, cpi->Source, cpi->Source, l , 1, 0, 1); |
4049 } | 4070 } |
4050 else | 4071 else |
4051 { | 4072 { |
4052 vp8_de_noise(cm, cpi->Source, cpi->Source, l , 1, 0); | 4073 vp8_de_noise(cm, cpi->Source, cpi->Source, l , 1, 0, 1); |
4053 | 4074 |
4054 src = cpi->Source->y_buffer; | 4075 src = cpi->Source->y_buffer; |
4055 | 4076 |
4056 if (cpi->Source->y_stride < 0) | 4077 if (cpi->Source->y_stride < 0) |
4057 { | 4078 { |
4058 src += cpi->Source->y_stride * (cpi->Source->y_height - 1); | 4079 src += cpi->Source->y_stride * (cpi->Source->y_height - 1); |
4059 } | 4080 } |
4060 } | 4081 } |
4061 } | 4082 } |
4062 | 4083 |
(...skipping 1669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5732 } | 5753 } |
5733 | 5754 |
5734 return Total; | 5755 return Total; |
5735 } | 5756 } |
5736 | 5757 |
5737 | 5758 |
5738 int vp8_get_quantizer(VP8_COMP *cpi) | 5759 int vp8_get_quantizer(VP8_COMP *cpi) |
5739 { | 5760 { |
5740 return cpi->common.base_qindex; | 5761 return cpi->common.base_qindex; |
5741 } | 5762 } |
OLD | NEW |