vp9_denoiser.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 VP9_ENCODER_DENOISER_H_
  11. #define VP9_ENCODER_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. VP9_DENOISER_LEVEL denoising_level;
  44. VP9_DENOISER_LEVEL prev_denoising_level;
  45. } VP9_DENOISER;
  46. typedef struct {
  47. int64_t zero_last_cost_orig;
  48. int *ref_frame_cost;
  49. int_mv (*frame_mv)[MAX_REF_FRAMES];
  50. int reuse_inter_pred;
  51. TX_SIZE best_tx_size;
  52. PREDICTION_MODE best_mode;
  53. MV_REFERENCE_FRAME best_ref_frame;
  54. INTERP_FILTER best_pred_filter;
  55. uint8_t best_mode_skip_txfm;
  56. } VP9_PICKMODE_CTX_DEN;
  57. struct VP9_COMP;
  58. void vp9_denoiser_update_frame_info(
  59. VP9_DENOISER *denoiser, YV12_BUFFER_CONFIG src, FRAME_TYPE frame_type,
  60. int refresh_alt_ref_frame, int refresh_golden_frame, int refresh_last_frame,
  61. int alt_fb_idx, int gld_fb_idx, int lst_fb_idx, int resized,
  62. int svc_base_is_key);
  63. void vp9_denoiser_denoise(struct VP9_COMP *cpi, MACROBLOCK *mb, int mi_row,
  64. int mi_col, BLOCK_SIZE bs, PICK_MODE_CONTEXT *ctx,
  65. VP9_DENOISER_DECISION *denoiser_decision);
  66. void vp9_denoiser_reset_frame_stats(PICK_MODE_CONTEXT *ctx);
  67. void vp9_denoiser_update_frame_stats(MODE_INFO *mi, unsigned int sse,
  68. PREDICTION_MODE mode,
  69. PICK_MODE_CONTEXT *ctx);
  70. int vp9_denoiser_realloc_svc(VP9_COMMON *cm, VP9_DENOISER *denoiser,
  71. int refresh_alt, int refresh_gld, int refresh_lst,
  72. int alt_fb_idx, int gld_fb_idx, int lst_fb_idx);
  73. int vp9_denoiser_alloc(VP9_COMMON *cm, int use_svc, VP9_DENOISER *denoiser,
  74. int width, int height, int ssx, int ssy,
  75. #if CONFIG_VP9_HIGHBITDEPTH
  76. int use_highbitdepth,
  77. #endif
  78. int border);
  79. #if CONFIG_VP9_TEMPORAL_DENOISING
  80. // This function is used by both c and sse2 denoiser implementations.
  81. // Define it as a static function within the scope where vp9_denoiser.h
  82. // is referenced.
  83. static INLINE int total_adj_strong_thresh(BLOCK_SIZE bs,
  84. int increase_denoising) {
  85. return (1 << num_pels_log2_lookup[bs]) * (increase_denoising ? 3 : 2);
  86. }
  87. #endif
  88. void vp9_denoiser_free(VP9_DENOISER *denoiser);
  89. void vp9_denoiser_set_noise_level(VP9_DENOISER *denoiser, int noise_level);
  90. int64_t vp9_scale_part_thresh(int64_t threshold, VP9_DENOISER_LEVEL noise_level,
  91. int content_state, int temporal_layer_id);
  92. int64_t vp9_scale_acskip_thresh(int64_t threshold,
  93. VP9_DENOISER_LEVEL noise_level, int abs_sumdiff,
  94. int temporal_layer_id);
  95. #ifdef __cplusplus
  96. } // extern "C"
  97. #endif
  98. #endif // VP9_ENCODER_DENOISER_H_