From ab8bfb077b804e0a3eaa9dfabdcef5d7d61ebdcb Mon Sep 17 00:00:00 2001 From: Tim Kopp Date: Thu, 5 Jun 2014 14:00:08 -0700 Subject: [PATCH] Added skeleton for VP9 denoiser Change-Id: Iccf6ede4c4f85646b0f8daec47050ce93e267c90 --- configure | 1 + vp9/encoder/vp9_denoiser.c | 49 ++++++++++++++++++++++++++++++++++++ vp9/encoder/vp9_denoiser.h | 51 ++++++++++++++++++++++++++++++++++++++ vp9/encoder/vp9_encoder.c | 16 ++++++++++++ vp9/encoder/vp9_encoder.h | 7 ++++++ vp9/encoder/vp9_pickmode.c | 9 +++++++ vp9/vp9cx.mk | 2 ++ 7 files changed, 135 insertions(+) create mode 100644 vp9/encoder/vp9_denoiser.c create mode 100644 vp9/encoder/vp9_denoiser.h diff --git a/configure b/configure index 800553eb4..9a7de73b1 100755 --- a/configure +++ b/configure @@ -272,6 +272,7 @@ EXPERIMENT_LIST=" alpha multiple_arf spatial_svc + denoising " CONFIG_LIST=" external_build diff --git a/vp9/encoder/vp9_denoiser.c b/vp9/encoder/vp9_denoiser.c new file mode 100644 index 000000000..687b4c2b2 --- /dev/null +++ b/vp9/encoder/vp9_denoiser.c @@ -0,0 +1,49 @@ +/* + * 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. + */ + +#include +#include +#include "vp9/encoder/vp9_denoiser.h" +#include "vpx_scale/yv12config.h" + +static const int widths[] = {4, 4, 8, 8, 8, 16, 16, 16, 32, 32, 32, 64, 64}; +static const int heights[] = {4, 8, 4, 8, 16, 8, 16, 32, 16, 32, 64, 32, 64}; + +int vp9_denoiser_filter() { + return 0; +} + +void vp9_denoiser_denoise(VP9_DENOISER *denoiser, + MACROBLOCK *mb, MODE_INFO **grid, + int mi_row, int mi_col, BLOCK_SIZE bs) { + return; +} + +void vp9_denoiser_update_frame_info(VP9_DENOISER *denoiser, + FRAME_TYPE frame_type, + int refresh_alt_ref_frame, + int refresh_golden_frame, + int refresh_last_frame) { + return; +} + +void vp9_denoiser_update_frame_stats() { + return; +} + +int vp9_denoiser_alloc(VP9_DENOISER *denoiser, int width, int height, + int border) { + return 0; +} + +void vp9_denoiser_free(VP9_DENOISER *denoiser) { + return; +} + diff --git a/vp9/encoder/vp9_denoiser.h b/vp9/encoder/vp9_denoiser.h new file mode 100644 index 000000000..a7a8d9329 --- /dev/null +++ b/vp9/encoder/vp9_denoiser.h @@ -0,0 +1,51 @@ +/* + * 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" + +#ifdef __cplusplus +extern "C" { +#endif + +enum vp9_denoiser_decision { + COPY_BLOCK, + FILTER_BLOCK +}; + +typedef struct vp9_denoiser { + struct buf_2d running_avg_y; + struct buf_2d mc_running_avg_y; +} VP9_DENOISER; + +void vp9_denoiser_update_frame_info(VP9_DENOISER *denoiser, + FRAME_TYPE frame_type, + int refresh_alt_ref_frame, + int refresh_golden_frame, + int refresh_last_frame); + +void vp9_denoiser_denoise(VP9_DENOISER *denoiser, + MACROBLOCK *mb, MODE_INFO **grid, + int mi_row, int mi_col, BLOCK_SIZE bs); + +void vp9_denoiser_update_frame_stats(); + +int vp9_denoiser_alloc(VP9_DENOISER *denoiser, int width, int height, + int border); + +void vp9_denoiser_free(VP9_DENOISER *denoiser); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // VP9_ENCODER_DENOISER_H_ diff --git a/vp9/encoder/vp9_encoder.c b/vp9/encoder/vp9_encoder.c index aa7a91dc1..eeee1f04f 100644 --- a/vp9/encoder/vp9_encoder.c +++ b/vp9/encoder/vp9_encoder.c @@ -680,6 +680,11 @@ void vp9_change_config(struct VP9_COMP *cpi, const VP9EncoderConfig *oxcf) { cpi->ext_refresh_frame_flags_pending = 0; cpi->ext_refresh_frame_context_pending = 0; + +#if CONFIG_DENOISING + vp9_denoiser_alloc(&(cpi->denoiser), cm->width, cm->height, + VP9_ENC_BORDER_IN_PIXELS); +#endif } #ifndef M_LOG2_E @@ -1085,6 +1090,10 @@ void vp9_remove_compressor(VP9_COMP *cpi) { #endif } +#if CONFIG_DENOISING + vp9_denoiser_free(&(cpi->denoiser)); +#endif + dealloc_compressor_data(cpi); vpx_free(cpi->tok); @@ -1547,6 +1556,13 @@ void vp9_update_reference_frames(VP9_COMP *cpi) { ref_cnt_fb(cm->frame_bufs, &cm->ref_frame_map[cpi->lst_fb_idx], cm->new_fb_idx); } +#if CONFIG_DENOISING + vp9_denoiser_update_frame_info(&cpi->denoiser, + cpi->common.frame_type, + cpi->refresh_alt_ref_frame, + cpi->refresh_golden_frame, + cpi->refresh_last_frame); +#endif } static void loopfilter_frame(VP9_COMP *cpi, VP9_COMMON *cm) { diff --git a/vp9/encoder/vp9_encoder.h b/vp9/encoder/vp9_encoder.h index 6b0e228ca..4364939b1 100644 --- a/vp9/encoder/vp9_encoder.h +++ b/vp9/encoder/vp9_encoder.h @@ -36,6 +36,9 @@ #include "vp9/encoder/vp9_svc_layercontext.h" #include "vp9/encoder/vp9_tokenize.h" #include "vp9/encoder/vp9_variance.h" +#if CONFIG_DENOISING +#include "vp9/encoder/vp9_denoiser.h" +#endif #ifdef __cplusplus extern "C" { @@ -526,6 +529,10 @@ typedef struct VP9_COMP { int this_frame_weight; int max_arf_level; #endif + +#if CONFIG_DENOISING + VP9_DENOISER denoiser; +#endif } VP9_COMP; void vp9_initialize_enc(); diff --git a/vp9/encoder/vp9_pickmode.c b/vp9/encoder/vp9_pickmode.c index 4b0b85ad4..e3f9d3bf1 100644 --- a/vp9/encoder/vp9_pickmode.c +++ b/vp9/encoder/vp9_pickmode.c @@ -438,6 +438,10 @@ int64_t vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, } } +#if CONFIG_DENOISING + vp9_denoiser_update_frame_stats(); +#endif + if (this_rd < best_rd || x->skip) { best_rd = this_rd; *returnrate = rate; @@ -453,6 +457,7 @@ int64_t vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, } } + mbmi->mode = best_mode; mbmi->interp_filter = best_pred_filter; mbmi->ref_frame[0] = best_ref_frame; @@ -488,6 +493,10 @@ int64_t vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, } } } +#if CONFIG_DENOISING + vp9_denoiser_denoise(&cpi->denoiser, x, cpi->common.mi_grid_visible, mi_row, + mi_col, bsize); +#endif return INT64_MAX; } diff --git a/vp9/vp9cx.mk b/vp9/vp9cx.mk index a44ffc1ca..9dbb67810 100644 --- a/vp9/vp9cx.mk +++ b/vp9/vp9cx.mk @@ -23,6 +23,8 @@ VP9_CX_SRCS-yes += encoder/vp9_context_tree.h VP9_CX_SRCS-yes += encoder/vp9_cost.h VP9_CX_SRCS-yes += encoder/vp9_cost.c VP9_CX_SRCS-yes += encoder/vp9_dct.c +VP9_CX_SRCS-$(CONFIG_DENOISING) += encoder/vp9_denoiser.c +VP9_CX_SRCS-$(CONFIG_DENOISING) += encoder/vp9_denoiser.h VP9_CX_SRCS-yes += encoder/vp9_encodeframe.c VP9_CX_SRCS-yes += encoder/vp9_encodeframe.h VP9_CX_SRCS-yes += encoder/vp9_encodemb.c