vp9_denoiser.h 4.4 KB

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