vp9_denoiser.h 3.96 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 *  Copyright (c) 2012 The WebM project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#ifndef VP9_ENCODER_DENOISER_H_
#define VP9_ENCODER_DENOISER_H_

#include "vp9/encoder/vp9_block.h"
15
#include "vp9/encoder/vp9_skin_detection.h"
16
#include "vpx_scale/yv12config.h"
17 18 19 20 21

#ifdef __cplusplus
extern "C" {
#endif

22
#define MOTION_MAGNITUDE_THRESHOLD (8 * 3)
23

24 25 26
// Denoiser is used in non svc real-time mode which does not use alt-ref, so no
// need to allocate for it, and hence we need MAX_REF_FRAME - 1
#define NONSVC_REF_FRAMES MAX_REF_FRAMES - 1
27

28 29 30 31
// Number of frame buffers when SVC is used. [0] for current denoised buffer and
// [1..8] for REF_FRAMES
#define SVC_REF_FRAMES 9

32
typedef enum vp9_denoiser_decision {
33
  COPY_BLOCK,
34 35
  FILTER_BLOCK,
  FILTER_ZEROMV_BLOCK
36
} VP9_DENOISER_DECISION;
37

Marco's avatar
Marco committed
38
typedef enum vp9_denoiser_level {
39
  kDenLowLow,
40 41 42
  kDenLow,
  kDenMedium,
  kDenHigh
Marco's avatar
Marco committed
43 44
} VP9_DENOISER_LEVEL;

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;
Marco's avatar
Marco committed
52
  VP9_DENOISER_LEVEL denoising_level;
53
  VP9_DENOISER_LEVEL prev_denoising_level;
54 55
} VP9_DENOISER;

56 57 58 59 60 61 62 63 64 65 66 67
typedef struct {
  int64_t zero_last_cost_orig;
  int *ref_frame_cost;
  int_mv (*frame_mv)[MAX_REF_FRAMES];
  int reuse_inter_pred;
  TX_SIZE best_tx_size;
  PREDICTION_MODE best_mode;
  MV_REFERENCE_FRAME best_ref_frame;
  INTERP_FILTER best_pred_filter;
  uint8_t best_mode_skip_txfm;
} VP9_PICKMODE_CTX_DEN;

68 69
struct VP9_COMP;

70 71 72
void vp9_denoiser_update_frame_info(
    VP9_DENOISER *denoiser, YV12_BUFFER_CONFIG src, FRAME_TYPE frame_type,
    int refresh_alt_ref_frame, int refresh_golden_frame, int refresh_last_frame,
73 74
    int alt_fb_idx, int gld_fb_idx, int lst_fb_idx, int resized,
    int svc_base_is_key);
75

76 77
void vp9_denoiser_denoise(struct VP9_COMP *cpi, MACROBLOCK *mb, int mi_row,
                          int mi_col, BLOCK_SIZE bs, PICK_MODE_CONTEXT *ctx,
78
                          VP9_DENOISER_DECISION *denoiser_decision);
79

80
void vp9_denoiser_reset_frame_stats(PICK_MODE_CONTEXT *ctx);
81

82 83
void vp9_denoiser_update_frame_stats(MODE_INFO *mi, unsigned int sse,
                                     PREDICTION_MODE mode,
84
                                     PICK_MODE_CONTEXT *ctx);
85

86 87 88 89
int vp9_denoiser_realloc_svc(VP9_COMMON *cm, VP9_DENOISER *denoiser,
                             int refresh_alt, int refresh_gld, int refresh_lst,
                             int alt_fb_idx, int gld_fb_idx, int lst_fb_idx);

90 91
int vp9_denoiser_alloc(VP9_COMMON *cm, int use_svc, VP9_DENOISER *denoiser,
                       int width, int height, int ssx, int ssy,
92 93 94 95
#if CONFIG_VP9_HIGHBITDEPTH
                       int use_highbitdepth,
#endif
                       int border);
96

97
#if CONFIG_VP9_TEMPORAL_DENOISING
98 99 100
// This function is used by both c and sse2 denoiser implementations.
// Define it as a static function within the scope where vp9_denoiser.h
// is referenced.
101 102
static INLINE int total_adj_strong_thresh(BLOCK_SIZE bs,
                                          int increase_denoising) {
103 104
  return (1 << num_pels_log2_lookup[bs]) * (increase_denoising ? 3 : 2);
}
105 106
#endif

107 108
void vp9_denoiser_free(VP9_DENOISER *denoiser);

109
void vp9_denoiser_set_noise_level(VP9_DENOISER *denoiser, int noise_level);
110

111
int64_t vp9_scale_part_thresh(int64_t threshold, VP9_DENOISER_LEVEL noise_level,
112
                              int content_state, int temporal_layer_id);
113 114

int64_t vp9_scale_acskip_thresh(int64_t threshold,
115 116
                                VP9_DENOISER_LEVEL noise_level, int abs_sumdiff,
                                int temporal_layer_id);
117

118 119 120 121 122
#ifdef __cplusplus
}  // extern "C"
#endif

#endif  // VP9_ENCODER_DENOISER_H_