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 VP9_ENCODER_DENOISER_H_
12 #define VP9_ENCODER_DENOISER_H_
13
14 #include "vp9/encoder/vp9_block.h"
15 #include "vp9/encoder/vp9_skin_detection.h"
16 #include "vpx_scale/yv12config.h"
17
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21
22 #define MOTION_MAGNITUDE_THRESHOLD (8 * 3)
23
24 typedef enum vp9_denoiser_decision {
25 COPY_BLOCK,
26 FILTER_BLOCK,
27 FILTER_ZEROMV_BLOCK
28 } VP9_DENOISER_DECISION;
29
30 typedef enum vp9_denoiser_level {
31 kDenLowLow,
32 kDenLow,
33 kDenMedium,
34 kDenHigh
35 } VP9_DENOISER_LEVEL;
36
37 typedef struct vp9_denoiser {
38 YV12_BUFFER_CONFIG running_avg_y[MAX_REF_FRAMES];
39 YV12_BUFFER_CONFIG mc_running_avg_y;
40 YV12_BUFFER_CONFIG last_source;
41 int frame_buffer_initialized;
42 int reset;
43 VP9_DENOISER_LEVEL denoising_level;
44 VP9_DENOISER_LEVEL prev_denoising_level;
45 } VP9_DENOISER;
46
47 typedef struct {
48 int64_t zero_last_cost_orig;
49 int *ref_frame_cost;
50 int_mv (*frame_mv)[MAX_REF_FRAMES];
51 int reuse_inter_pred;
52 TX_SIZE best_tx_size;
53 PREDICTION_MODE best_mode;
54 MV_REFERENCE_FRAME best_ref_frame;
55 INTERP_FILTER best_pred_filter;
56 uint8_t best_mode_skip_txfm;
57 } VP9_PICKMODE_CTX_DEN;
58
59 struct VP9_COMP;
60
61 void vp9_denoiser_update_frame_info(
62 VP9_DENOISER *denoiser, YV12_BUFFER_CONFIG src, FRAME_TYPE frame_type,
63 int refresh_alt_ref_frame, int refresh_golden_frame, int refresh_last_frame,
64 int resized, int svc_base_is_key);
65
66 void vp9_denoiser_denoise(struct VP9_COMP *cpi, MACROBLOCK *mb, int mi_row,
67 int mi_col, BLOCK_SIZE bs, PICK_MODE_CONTEXT *ctx,
68 VP9_DENOISER_DECISION *denoiser_decision);
69
70 void vp9_denoiser_reset_frame_stats(PICK_MODE_CONTEXT *ctx);
71
72 void vp9_denoiser_update_frame_stats(MODE_INFO *mi, unsigned int sse,
73 PREDICTION_MODE mode,
74 PICK_MODE_CONTEXT *ctx);
75
76 int vp9_denoiser_alloc(VP9_DENOISER *denoiser, int width, int height, int ssx,
77 int ssy,
78 #if CONFIG_VP9_HIGHBITDEPTH
79 int use_highbitdepth,
80 #endif
81 int border);
82
83 #if CONFIG_VP9_TEMPORAL_DENOISING
84 // This function is used by both c and sse2 denoiser implementations.
85 // Define it as a static function within the scope where vp9_denoiser.h
86 // is referenced.
total_adj_strong_thresh(BLOCK_SIZE bs,int increase_denoising)87 static INLINE int total_adj_strong_thresh(BLOCK_SIZE bs,
88 int increase_denoising) {
89 return (1 << num_pels_log2_lookup[bs]) * (increase_denoising ? 3 : 2);
90 }
91 #endif
92
93 void vp9_denoiser_free(VP9_DENOISER *denoiser);
94
95 void vp9_denoiser_set_noise_level(VP9_DENOISER *denoiser, int noise_level);
96
97 int64_t vp9_scale_part_thresh(int64_t threshold, VP9_DENOISER_LEVEL noise_level,
98 int content_state, int temporal_layer_id);
99
100 int64_t vp9_scale_acskip_thresh(int64_t threshold,
101 VP9_DENOISER_LEVEL noise_level, int abs_sumdiff,
102 int temporal_layer_id);
103
104 #ifdef __cplusplus
105 } // extern "C"
106 #endif
107
108 #endif // VP9_ENCODER_DENOISER_H_
109