1 /* 2 * Copyright (c) 2012 The WebM project authors. All Rights Reserved. 3 * 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 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef VP8_ENCODER_DENOISING_H_ 12 #define VP8_ENCODER_DENOISING_H_ 13 14 #include "block.h" 15 #include "vp8/common/loopfilter.h" 16 17 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 21 #define SUM_DIFF_THRESHOLD (16 * 16 * 2) 22 #define SUM_DIFF_THRESHOLD_HIGH (16 * 16 * 3) 23 #define MOTION_MAGNITUDE_THRESHOLD (8*3) 24 25 #define SUM_DIFF_THRESHOLD_UV (96) // (8 * 8 * 1.5) 26 #define SUM_DIFF_THRESHOLD_HIGH_UV (8 * 8 * 2) 27 #define SUM_DIFF_FROM_AVG_THRESH_UV (8 * 8 * 4) 28 #define MOTION_MAGNITUDE_THRESHOLD_UV (8*3) 29 30 enum vp8_denoiser_decision 31 { 32 COPY_BLOCK, 33 FILTER_BLOCK 34 }; 35 36 enum vp8_denoiser_filter_state { 37 kNoFilter, 38 kFilterZeroMV, 39 kFilterNonZeroMV 40 }; 41 42 enum vp8_denoiser_mode { 43 kDenoiserOff, 44 kDenoiserOnYOnly, 45 kDenoiserOnYUV, 46 kDenoiserOnYUVAggressive 47 }; 48 49 typedef struct { 50 // Scale factor on sse threshold above which no denoising is done. 51 unsigned int scale_sse_thresh; 52 // Scale factor on motion magnitude threshold above which no 53 // denoising is done. 54 unsigned int scale_motion_thresh; 55 // Scale factor on motion magnitude below which we increase the strength of 56 // the temporal filter (in function vp8_denoiser_filter). 57 unsigned int scale_increase_filter; 58 // Scale factor to bias to ZEROMV for denoising. 59 unsigned int denoise_mv_bias; 60 // Scale factor to bias to ZEROMV for coding mode selection. 61 unsigned int pickmode_mv_bias; 62 // Quantizer threshold below which we use the segmentation map to switch off 63 // loop filter for blocks that have been coded as ZEROMV-LAST a certain number 64 // (consec_zerolast) of consecutive frames. Note that the delta-QP is set to 65 // 0 when segmentation map is used for shutting off loop filter. 66 unsigned int qp_thresh; 67 // Threshold for number of consecutive frames for blocks coded as ZEROMV-LAST. 68 unsigned int consec_zerolast; 69 } denoise_params; 70 71 typedef struct vp8_denoiser 72 { 73 YV12_BUFFER_CONFIG yv12_running_avg[MAX_REF_FRAMES]; 74 YV12_BUFFER_CONFIG yv12_mc_running_avg; 75 unsigned char* denoise_state; 76 int num_mb_cols; 77 int denoiser_mode; 78 denoise_params denoise_pars; 79 } VP8_DENOISER; 80 81 int vp8_denoiser_allocate(VP8_DENOISER *denoiser, int width, int height, 82 int num_mb_rows, int num_mb_cols, int mode); 83 84 void vp8_denoiser_free(VP8_DENOISER *denoiser); 85 86 void vp8_denoiser_denoise_mb(VP8_DENOISER *denoiser, 87 MACROBLOCK *x, 88 unsigned int best_sse, 89 unsigned int zero_mv_sse, 90 int recon_yoffset, 91 int recon_uvoffset, 92 loop_filter_info_n *lfi_n, 93 int mb_row, 94 int mb_col, 95 int block_index); 96 97 #ifdef __cplusplus 98 } // extern "C" 99 #endif 100 101 #endif // VP8_ENCODER_DENOISING_H_ 102