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 // Denoiser is used in non svc real-time mode which does not use alt-ref, so no 25 // need to allocate for it, and hence we need MAX_REF_FRAME - 1 26 #define NONSVC_REF_FRAMES MAX_REF_FRAMES - 1 27 28 // Number of frame buffers when SVC is used. [0] for current denoised buffer and 29 // [1..8] for REF_FRAMES 30 #define SVC_REF_FRAMES 9 31 32 typedef enum vp9_denoiser_decision { 33 COPY_BLOCK, 34 FILTER_BLOCK, 35 FILTER_ZEROMV_BLOCK 36 } VP9_DENOISER_DECISION; 37 38 typedef enum vp9_denoiser_level { 39 kDenLowLow, 40 kDenLow, 41 kDenMedium, 42 kDenHigh 43 } VP9_DENOISER_LEVEL; 44 45 typedef struct vp9_denoiser { 46 YV12_BUFFER_CONFIG *running_avg_y; 47 YV12_BUFFER_CONFIG *mc_running_avg_y; 48 YV12_BUFFER_CONFIG last_source; 49 int frame_buffer_initialized; 50 int reset; 51 int num_ref_frames; 52 int num_layers; 53 VP9_DENOISER_LEVEL denoising_level; 54 VP9_DENOISER_LEVEL prev_denoising_level; 55 } VP9_DENOISER; 56 57 typedef struct { 58 int64_t zero_last_cost_orig; 59 int *ref_frame_cost; 60 int_mv (*frame_mv)[MAX_REF_FRAMES]; 61 int reuse_inter_pred; 62 TX_SIZE best_tx_size; 63 PREDICTION_MODE best_mode; 64 MV_REFERENCE_FRAME best_ref_frame; 65 INTERP_FILTER best_pred_filter; 66 uint8_t best_mode_skip_txfm; 67 } VP9_PICKMODE_CTX_DEN; 68 69 struct VP9_COMP; 70 struct SVC; 71 72 void vp9_denoiser_update_frame_info( 73 VP9_DENOISER *denoiser, YV12_BUFFER_CONFIG src, FRAME_TYPE frame_type, 74 int refresh_alt_ref_frame, int refresh_golden_frame, int refresh_last_frame, 75 int alt_fb_idx, int gld_fb_idx, int lst_fb_idx, int resized, 76 int svc_base_is_key, int second_spatial_layer); 77 78 void vp9_denoiser_denoise(struct VP9_COMP *cpi, MACROBLOCK *mb, int mi_row, 79 int mi_col, BLOCK_SIZE bs, PICK_MODE_CONTEXT *ctx, 80 VP9_DENOISER_DECISION *denoiser_decision); 81 82 void vp9_denoiser_reset_frame_stats(PICK_MODE_CONTEXT *ctx); 83 84 void vp9_denoiser_update_frame_stats(MODE_INFO *mi, unsigned int sse, 85 PREDICTION_MODE mode, 86 PICK_MODE_CONTEXT *ctx); 87 88 int vp9_denoiser_realloc_svc(VP9_COMMON *cm, VP9_DENOISER *denoiser, 89 int svc_buf_shift, int refresh_alt, 90 int refresh_gld, int refresh_lst, int alt_fb_idx, 91 int gld_fb_idx, int lst_fb_idx); 92 93 int vp9_denoiser_alloc(VP9_COMMON *cm, struct SVC *svc, VP9_DENOISER *denoiser, 94 int use_svc, int noise_sen, int width, int height, 95 int ssx, int ssy, 96 #if CONFIG_VP9_HIGHBITDEPTH 97 int use_highbitdepth, 98 #endif 99 int border); 100 101 #if CONFIG_VP9_TEMPORAL_DENOISING 102 // This function is used by both c and sse2 denoiser implementations. 103 // Define it as a static function within the scope where vp9_denoiser.h 104 // is referenced. 105 static INLINE int total_adj_strong_thresh(BLOCK_SIZE bs, 106 int increase_denoising) { 107 return (1 << num_pels_log2_lookup[bs]) * (increase_denoising ? 3 : 2); 108 } 109 #endif 110 111 void vp9_denoiser_free(VP9_DENOISER *denoiser); 112 113 void vp9_denoiser_set_noise_level(VP9_DENOISER *denoiser, int noise_level); 114 115 int64_t vp9_scale_part_thresh(int64_t threshold, VP9_DENOISER_LEVEL noise_level, 116 int content_state, int temporal_layer_id); 117 118 int64_t vp9_scale_acskip_thresh(int64_t threshold, 119 VP9_DENOISER_LEVEL noise_level, int abs_sumdiff, 120 int temporal_layer_id); 121 122 #ifdef __cplusplus 123 } // extern "C" 124 #endif 125 126 #endif // VP9_ENCODER_DENOISER_H_ 127