Merge "VP9: Eliminate up_available and left_available"
[aom.git] / vp8 / encoder / denoising.h
blob148ccdafe4e878808920122c6c5115321d85c595
1 /*
2 * Copyright (c) 2012 The WebM project authors. All Rights Reserved.
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 */
11 #ifndef VP8_ENCODER_DENOISING_H_
12 #define VP8_ENCODER_DENOISING_H_
14 #include "block.h"
15 #include "vp8/common/loopfilter.h"
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
21 #define SUM_DIFF_THRESHOLD 448
22 #define SUM_DIFF_THRESHOLD_HIGH 512
23 #define MOTION_MAGNITUDE_THRESHOLD (8*3)
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 * 8)
28 #define MOTION_MAGNITUDE_THRESHOLD_UV (8*3)
30 #define MAX_GF_ARF_DENOISE_RANGE (8)
32 enum vp8_denoiser_decision
34 COPY_BLOCK,
35 FILTER_BLOCK
38 enum vp8_denoiser_filter_state {
39 kNoFilter,
40 kFilterZeroMV,
41 kFilterNonZeroMV
44 enum vp8_denoiser_mode {
45 kDenoiserOff,
46 kDenoiserOnYOnly,
47 kDenoiserOnYUV,
48 kDenoiserOnYUVAggressive,
49 kDenoiserOnAdaptive
52 typedef struct {
53 // Scale factor on sse threshold above which no denoising is done.
54 unsigned int scale_sse_thresh;
55 // Scale factor on motion magnitude threshold above which no
56 // denoising is done.
57 unsigned int scale_motion_thresh;
58 // Scale factor on motion magnitude below which we increase the strength of
59 // the temporal filter (in function vp8_denoiser_filter).
60 unsigned int scale_increase_filter;
61 // Scale factor to bias to ZEROMV for denoising.
62 unsigned int denoise_mv_bias;
63 // Scale factor to bias to ZEROMV for coding mode selection.
64 unsigned int pickmode_mv_bias;
65 // Quantizer threshold below which we use the segmentation map to switch off
66 // loop filter for blocks that have been coded as ZEROMV-LAST a certain number
67 // (consec_zerolast) of consecutive frames. Note that the delta-QP is set to
68 // 0 when segmentation map is used for shutting off loop filter.
69 unsigned int qp_thresh;
70 // Threshold for number of consecutive frames for blocks coded as ZEROMV-LAST.
71 unsigned int consec_zerolast;
72 // Threshold for amount of spatial blur on Y channel. 0 means no spatial blur.
73 unsigned int spatial_blur;
74 } denoise_params;
76 typedef struct vp8_denoiser
78 YV12_BUFFER_CONFIG yv12_running_avg[MAX_REF_FRAMES];
79 YV12_BUFFER_CONFIG yv12_mc_running_avg;
80 // TODO(marpan): Should remove yv12_last_source and use vp8_lookahead_peak.
81 YV12_BUFFER_CONFIG yv12_last_source;
82 unsigned char* denoise_state;
83 int num_mb_cols;
84 int denoiser_mode;
85 int threshold_aggressive_mode;
86 int nmse_source_diff;
87 int nmse_source_diff_count;
88 int qp_avg;
89 int qp_threshold_up;
90 int qp_threshold_down;
91 int bitrate_threshold;
92 denoise_params denoise_pars;
93 } VP8_DENOISER;
95 int vp8_denoiser_allocate(VP8_DENOISER *denoiser, int width, int height,
96 int num_mb_rows, int num_mb_cols, int mode);
98 void vp8_denoiser_free(VP8_DENOISER *denoiser);
100 void vp8_denoiser_set_parameters(VP8_DENOISER *denoiser, int mode);
102 void vp8_denoiser_denoise_mb(VP8_DENOISER *denoiser,
103 MACROBLOCK *x,
104 unsigned int best_sse,
105 unsigned int zero_mv_sse,
106 int recon_yoffset,
107 int recon_uvoffset,
108 loop_filter_info_n *lfi_n,
109 int mb_row,
110 int mb_col,
111 int block_index);
113 #ifdef __cplusplus
114 } // extern "C"
115 #endif
117 #endif // VP8_ENCODER_DENOISING_H_