denoising.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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_VP8_ENCODER_DENOISING_H_
  11. #define VPX_VP8_ENCODER_DENOISING_H_
  12. #include "block.h"
  13. #include "vp8/common/loopfilter.h"
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. #define SUM_DIFF_THRESHOLD 512
  18. #define SUM_DIFF_THRESHOLD_HIGH 600
  19. #define MOTION_MAGNITUDE_THRESHOLD (8 * 3)
  20. #define SUM_DIFF_THRESHOLD_UV (96) // (8 * 8 * 1.5)
  21. #define SUM_DIFF_THRESHOLD_HIGH_UV (8 * 8 * 2)
  22. #define SUM_DIFF_FROM_AVG_THRESH_UV (8 * 8 * 8)
  23. #define MOTION_MAGNITUDE_THRESHOLD_UV (8 * 3)
  24. #define MAX_GF_ARF_DENOISE_RANGE (8)
  25. enum vp8_denoiser_decision { COPY_BLOCK, FILTER_BLOCK };
  26. enum vp8_denoiser_filter_state { kNoFilter, kFilterZeroMV, kFilterNonZeroMV };
  27. enum vp8_denoiser_mode {
  28. kDenoiserOff,
  29. kDenoiserOnYOnly,
  30. kDenoiserOnYUV,
  31. kDenoiserOnYUVAggressive,
  32. kDenoiserOnAdaptive
  33. };
  34. typedef struct {
  35. // Scale factor on sse threshold above which no denoising is done.
  36. unsigned int scale_sse_thresh;
  37. // Scale factor on motion magnitude threshold above which no
  38. // denoising is done.
  39. unsigned int scale_motion_thresh;
  40. // Scale factor on motion magnitude below which we increase the strength of
  41. // the temporal filter (in function vp8_denoiser_filter).
  42. unsigned int scale_increase_filter;
  43. // Scale factor to bias to ZEROMV for denoising.
  44. unsigned int denoise_mv_bias;
  45. // Scale factor to bias to ZEROMV for coding mode selection.
  46. unsigned int pickmode_mv_bias;
  47. // Quantizer threshold below which we use the segmentation map to switch off
  48. // loop filter for blocks that have been coded as ZEROMV-LAST a certain number
  49. // (consec_zerolast) of consecutive frames. Note that the delta-QP is set to
  50. // 0 when segmentation map is used for shutting off loop filter.
  51. unsigned int qp_thresh;
  52. // Threshold for number of consecutive frames for blocks coded as ZEROMV-LAST.
  53. unsigned int consec_zerolast;
  54. // Threshold for amount of spatial blur on Y channel. 0 means no spatial blur.
  55. unsigned int spatial_blur;
  56. } denoise_params;
  57. typedef struct vp8_denoiser {
  58. YV12_BUFFER_CONFIG yv12_running_avg[MAX_REF_FRAMES];
  59. YV12_BUFFER_CONFIG yv12_mc_running_avg;
  60. // TODO(marpan): Should remove yv12_last_source and use vp8_lookahead_peak.
  61. YV12_BUFFER_CONFIG yv12_last_source;
  62. unsigned char *denoise_state;
  63. int num_mb_cols;
  64. int denoiser_mode;
  65. int threshold_aggressive_mode;
  66. int nmse_source_diff;
  67. int nmse_source_diff_count;
  68. int qp_avg;
  69. int qp_threshold_up;
  70. int qp_threshold_down;
  71. int bitrate_threshold;
  72. denoise_params denoise_pars;
  73. } VP8_DENOISER;
  74. int vp8_denoiser_allocate(VP8_DENOISER *denoiser, int width, int height,
  75. int num_mb_rows, int num_mb_cols, int mode);
  76. void vp8_denoiser_free(VP8_DENOISER *denoiser);
  77. void vp8_denoiser_set_parameters(VP8_DENOISER *denoiser, int mode);
  78. void vp8_denoiser_denoise_mb(VP8_DENOISER *denoiser, MACROBLOCK *x,
  79. unsigned int best_sse, unsigned int zero_mv_sse,
  80. int recon_yoffset, int recon_uvoffset,
  81. loop_filter_info_n *lfi_n, int mb_row, int mb_col,
  82. int block_index, int consec_zero_last);
  83. #ifdef __cplusplus
  84. } // extern "C"
  85. #endif
  86. #endif // VPX_VP8_ENCODER_DENOISING_H_