vp8: Code cleanup for control of denoiser mode.
Change-Id: Icb9918dd38d15061d62852e6a2d905e8ceb2c1ac
This commit is contained in:
		@@ -108,7 +108,7 @@ extern "C"
 | 
				
			|||||||
         * For temporal denoiser: noise_sensitivity = 0 means off,
 | 
					         * For temporal denoiser: noise_sensitivity = 0 means off,
 | 
				
			||||||
         * noise_sensitivity = 1 means temporal denoiser on for Y channel only,
 | 
					         * noise_sensitivity = 1 means temporal denoiser on for Y channel only,
 | 
				
			||||||
         * noise_sensitivity = 2 means temporal denoiser on for all channels.
 | 
					         * noise_sensitivity = 2 means temporal denoiser on for all channels.
 | 
				
			||||||
         * noise_sensitivity = 3 means aggressive denoising mode.
 | 
					         * noise_sensitivity >= 3 means aggressive denoising mode.
 | 
				
			||||||
         * Temporal denoiser is enabled via the configuration option:
 | 
					         * Temporal denoiser is enabled via the configuration option:
 | 
				
			||||||
         * CONFIG_TEMPORAL_DENOISING.
 | 
					         * CONFIG_TEMPORAL_DENOISING.
 | 
				
			||||||
         * For spatial denoiser: noise_sensitivity controls the amount of
 | 
					         * For spatial denoiser: noise_sensitivity controls the amount of
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -335,8 +335,16 @@ int vp8_denoiser_filter_uv_c(unsigned char *mc_running_avg_uv,
 | 
				
			|||||||
    return FILTER_BLOCK;
 | 
					    return FILTER_BLOCK;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void vp8_denoiser_set_parameters(VP8_DENOISER *denoiser) {
 | 
					void vp8_denoiser_set_parameters(VP8_DENOISER *denoiser, int mode) {
 | 
				
			||||||
  if (!denoiser->aggressive_mode) {
 | 
					  assert(mode > 0);  // Denoiser is allocated only if mode > 0.
 | 
				
			||||||
 | 
					  if (mode == 1) {
 | 
				
			||||||
 | 
					    denoiser->denoiser_mode = kDenoiserOnYOnly;
 | 
				
			||||||
 | 
					  } else if (mode == 2) {
 | 
				
			||||||
 | 
					    denoiser->denoiser_mode = kDenoiserOnYUV;
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    denoiser->denoiser_mode = kDenoiserOnYUVAggressive;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if (denoiser->denoiser_mode != kDenoiserOnYUVAggressive) {
 | 
				
			||||||
    denoiser->denoise_pars.scale_sse_thresh = 1;
 | 
					    denoiser->denoise_pars.scale_sse_thresh = 1;
 | 
				
			||||||
    denoiser->denoise_pars.scale_motion_thresh = 8;
 | 
					    denoiser->denoise_pars.scale_motion_thresh = 8;
 | 
				
			||||||
    denoiser->denoise_pars.scale_increase_filter = 0;
 | 
					    denoiser->denoise_pars.scale_increase_filter = 0;
 | 
				
			||||||
@@ -361,7 +369,6 @@ int vp8_denoiser_allocate(VP8_DENOISER *denoiser, int width, int height,
 | 
				
			|||||||
    int i;
 | 
					    int i;
 | 
				
			||||||
    assert(denoiser);
 | 
					    assert(denoiser);
 | 
				
			||||||
    denoiser->num_mb_cols = num_mb_cols;
 | 
					    denoiser->num_mb_cols = num_mb_cols;
 | 
				
			||||||
    denoiser->aggressive_mode = mode;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (i = 0; i < MAX_REF_FRAMES; i++)
 | 
					    for (i = 0; i < MAX_REF_FRAMES; i++)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@@ -392,7 +399,7 @@ int vp8_denoiser_allocate(VP8_DENOISER *denoiser, int width, int height,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    denoiser->denoise_state = vpx_calloc((num_mb_rows * num_mb_cols), 1);
 | 
					    denoiser->denoise_state = vpx_calloc((num_mb_rows * num_mb_cols), 1);
 | 
				
			||||||
    vpx_memset(denoiser->denoise_state, 0, (num_mb_rows * num_mb_cols));
 | 
					    vpx_memset(denoiser->denoise_state, 0, (num_mb_rows * num_mb_cols));
 | 
				
			||||||
    vp8_denoiser_set_parameters(denoiser);
 | 
					    vp8_denoiser_set_parameters(denoiser, mode);
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -420,8 +427,8 @@ void vp8_denoiser_denoise_mb(VP8_DENOISER *denoiser,
 | 
				
			|||||||
                             loop_filter_info_n *lfi_n,
 | 
					                             loop_filter_info_n *lfi_n,
 | 
				
			||||||
                             int mb_row,
 | 
					                             int mb_row,
 | 
				
			||||||
                             int mb_col,
 | 
					                             int mb_col,
 | 
				
			||||||
                             int block_index,
 | 
					                             int block_index)
 | 
				
			||||||
                             int uv_denoise)
 | 
					
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int mv_row;
 | 
					    int mv_row;
 | 
				
			||||||
    int mv_col;
 | 
					    int mv_col;
 | 
				
			||||||
@@ -558,7 +565,7 @@ void vp8_denoiser_denoise_mb(VP8_DENOISER *denoiser,
 | 
				
			|||||||
        denoiser->denoise_state[block_index] = motion_magnitude2 > 0 ?
 | 
					        denoiser->denoise_state[block_index] = motion_magnitude2 > 0 ?
 | 
				
			||||||
            kFilterNonZeroMV : kFilterZeroMV;
 | 
					            kFilterNonZeroMV : kFilterZeroMV;
 | 
				
			||||||
        // Only denoise UV for zero motion, and if y channel was denoised.
 | 
					        // Only denoise UV for zero motion, and if y channel was denoised.
 | 
				
			||||||
        if (uv_denoise &&
 | 
					        if (denoiser->denoiser_mode != kDenoiserOnYOnly &&
 | 
				
			||||||
            motion_magnitude2 == 0 &&
 | 
					            motion_magnitude2 == 0 &&
 | 
				
			||||||
            decision == FILTER_BLOCK) {
 | 
					            decision == FILTER_BLOCK) {
 | 
				
			||||||
          unsigned char *mc_running_avg_u =
 | 
					          unsigned char *mc_running_avg_u =
 | 
				
			||||||
@@ -595,7 +602,7 @@ void vp8_denoiser_denoise_mb(VP8_DENOISER *denoiser,
 | 
				
			|||||||
                denoiser->yv12_running_avg[INTRA_FRAME].y_stride);
 | 
					                denoiser->yv12_running_avg[INTRA_FRAME].y_stride);
 | 
				
			||||||
        denoiser->denoise_state[block_index] = kNoFilter;
 | 
					        denoiser->denoise_state[block_index] = kNoFilter;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (uv_denoise) {
 | 
					    if (denoiser->denoiser_mode != kDenoiserOnYOnly) {
 | 
				
			||||||
      if (decision_u == COPY_BLOCK) {
 | 
					      if (decision_u == COPY_BLOCK) {
 | 
				
			||||||
        vp8_copy_mem8x8(
 | 
					        vp8_copy_mem8x8(
 | 
				
			||||||
            x->block[16].src + *x->block[16].base_src, x->block[16].src_stride,
 | 
					            x->block[16].src + *x->block[16].base_src, x->block[16].src_stride,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -39,6 +39,13 @@ enum vp8_denoiser_filter_state {
 | 
				
			|||||||
  kFilterNonZeroMV
 | 
					  kFilterNonZeroMV
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					enum vp8_denoiser_mode {
 | 
				
			||||||
 | 
					  kDenoiserOff,
 | 
				
			||||||
 | 
					  kDenoiserOnYOnly,
 | 
				
			||||||
 | 
					  kDenoiserOnYUV,
 | 
				
			||||||
 | 
					  kDenoiserOnYUVAggressive
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct {
 | 
					typedef struct {
 | 
				
			||||||
  // Scale factor on sse threshold above which no denoising is done.
 | 
					  // Scale factor on sse threshold above which no denoising is done.
 | 
				
			||||||
  unsigned int scale_sse_thresh;
 | 
					  unsigned int scale_sse_thresh;
 | 
				
			||||||
@@ -67,7 +74,7 @@ typedef struct vp8_denoiser
 | 
				
			|||||||
    YV12_BUFFER_CONFIG yv12_mc_running_avg;
 | 
					    YV12_BUFFER_CONFIG yv12_mc_running_avg;
 | 
				
			||||||
    unsigned char* denoise_state;
 | 
					    unsigned char* denoise_state;
 | 
				
			||||||
    int num_mb_cols;
 | 
					    int num_mb_cols;
 | 
				
			||||||
    int aggressive_mode;
 | 
					    int denoiser_mode;
 | 
				
			||||||
    denoise_params denoise_pars;
 | 
					    denoise_params denoise_pars;
 | 
				
			||||||
} VP8_DENOISER;
 | 
					} VP8_DENOISER;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -85,8 +92,7 @@ void vp8_denoiser_denoise_mb(VP8_DENOISER *denoiser,
 | 
				
			|||||||
                             loop_filter_info_n *lfi_n,
 | 
					                             loop_filter_info_n *lfi_n,
 | 
				
			||||||
                             int mb_row,
 | 
					                             int mb_row,
 | 
				
			||||||
                             int mb_col,
 | 
					                             int mb_col,
 | 
				
			||||||
                             int block_index,
 | 
					                             int block_index);
 | 
				
			||||||
                             int uv_denoise);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __cplusplus
 | 
					#ifdef __cplusplus
 | 
				
			||||||
}  // extern "C"
 | 
					}  // extern "C"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -615,7 +615,7 @@ static void cyclic_background_refresh(VP8_COMP *cpi, int Q, int lf_adjustment)
 | 
				
			|||||||
        cpi->cyclic_refresh_mode_index = i;
 | 
					        cpi->cyclic_refresh_mode_index = i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if CONFIG_TEMPORAL_DENOISING
 | 
					#if CONFIG_TEMPORAL_DENOISING
 | 
				
			||||||
        if (cpi->denoiser.aggressive_mode != 0 &&
 | 
					        if (cpi->denoiser.denoiser_mode == kDenoiserOnYUVAggressive &&
 | 
				
			||||||
            Q < (int)cpi->denoiser.denoise_pars.qp_thresh) {
 | 
					            Q < (int)cpi->denoiser.denoise_pars.qp_thresh) {
 | 
				
			||||||
          // Under aggressive denoising mode, use segmentation to turn off loop
 | 
					          // Under aggressive denoising mode, use segmentation to turn off loop
 | 
				
			||||||
          // filter below some qp thresh. The loop filter is turned off for all
 | 
					          // filter below some qp thresh. The loop filter is turned off for all
 | 
				
			||||||
@@ -1283,8 +1283,7 @@ void vp8_alloc_compressor_data(VP8_COMP *cpi)
 | 
				
			|||||||
      vp8_denoiser_free(&cpi->denoiser);
 | 
					      vp8_denoiser_free(&cpi->denoiser);
 | 
				
			||||||
      vp8_denoiser_allocate(&cpi->denoiser, width, height,
 | 
					      vp8_denoiser_allocate(&cpi->denoiser, width, height,
 | 
				
			||||||
                            cm->mb_rows, cm->mb_cols,
 | 
					                            cm->mb_rows, cm->mb_cols,
 | 
				
			||||||
                            ((cpi->oxcf.noise_sensitivity == 3) ?
 | 
					                            cpi->oxcf.noise_sensitivity);
 | 
				
			||||||
                            1 : 0));
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -1781,7 +1780,7 @@ void vp8_change_config(VP8_COMP *cpi, VP8_CONFIG *oxcf)
 | 
				
			|||||||
        int height = (cpi->oxcf.Height + 15) & ~15;
 | 
					        int height = (cpi->oxcf.Height + 15) & ~15;
 | 
				
			||||||
        vp8_denoiser_allocate(&cpi->denoiser, width, height,
 | 
					        vp8_denoiser_allocate(&cpi->denoiser, width, height,
 | 
				
			||||||
                              cm->mb_rows, cm->mb_cols,
 | 
					                              cm->mb_rows, cm->mb_cols,
 | 
				
			||||||
                              ((cpi->oxcf.noise_sensitivity == 3) ? 1 : 0));
 | 
					                              cpi->oxcf.noise_sensitivity);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1174,7 +1174,6 @@ void vp8_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset,
 | 
				
			|||||||
#if CONFIG_TEMPORAL_DENOISING
 | 
					#if CONFIG_TEMPORAL_DENOISING
 | 
				
			||||||
    if (cpi->oxcf.noise_sensitivity)
 | 
					    if (cpi->oxcf.noise_sensitivity)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        int uv_denoise = (cpi->oxcf.noise_sensitivity >= 2) ? 1 : 0;
 | 
					 | 
				
			||||||
        int block_index = mb_row * cpi->common.mb_cols + mb_col;
 | 
					        int block_index = mb_row * cpi->common.mb_cols + mb_col;
 | 
				
			||||||
        if (x->best_sse_inter_mode == DC_PRED)
 | 
					        if (x->best_sse_inter_mode == DC_PRED)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
@@ -1189,8 +1188,7 @@ void vp8_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset,
 | 
				
			|||||||
        vp8_denoiser_denoise_mb(&cpi->denoiser, x, best_sse, zero_mv_sse,
 | 
					        vp8_denoiser_denoise_mb(&cpi->denoiser, x, best_sse, zero_mv_sse,
 | 
				
			||||||
                                recon_yoffset, recon_uvoffset,
 | 
					                                recon_yoffset, recon_uvoffset,
 | 
				
			||||||
                                &cpi->common.lf_info, mb_row, mb_col,
 | 
					                                &cpi->common.lf_info, mb_row, mb_col,
 | 
				
			||||||
                                block_index, uv_denoise);
 | 
					                                block_index);
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /* Reevaluate ZEROMV after denoising. */
 | 
					        /* Reevaluate ZEROMV after denoising. */
 | 
				
			||||||
        if (best_mbmode.ref_frame == INTRA_FRAME &&
 | 
					        if (best_mbmode.ref_frame == INTRA_FRAME &&
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2511,7 +2511,6 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset,
 | 
				
			|||||||
#if CONFIG_TEMPORAL_DENOISING
 | 
					#if CONFIG_TEMPORAL_DENOISING
 | 
				
			||||||
    if (cpi->oxcf.noise_sensitivity)
 | 
					    if (cpi->oxcf.noise_sensitivity)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        int uv_denoise = (cpi->oxcf.noise_sensitivity == 2) ? 1 : 0;
 | 
					 | 
				
			||||||
        int block_index = mb_row * cpi->common.mb_cols + mb_col;
 | 
					        int block_index = mb_row * cpi->common.mb_cols + mb_col;
 | 
				
			||||||
        if (x->best_sse_inter_mode == DC_PRED)
 | 
					        if (x->best_sse_inter_mode == DC_PRED)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
@@ -2525,8 +2524,7 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset,
 | 
				
			|||||||
        vp8_denoiser_denoise_mb(&cpi->denoiser, x, best_sse, zero_mv_sse,
 | 
					        vp8_denoiser_denoise_mb(&cpi->denoiser, x, best_sse, zero_mv_sse,
 | 
				
			||||||
                                recon_yoffset, recon_uvoffset,
 | 
					                                recon_yoffset, recon_uvoffset,
 | 
				
			||||||
                                &cpi->common.lf_info, mb_row, mb_col,
 | 
					                                &cpi->common.lf_info, mb_row, mb_col,
 | 
				
			||||||
                                block_index, uv_denoise);
 | 
					                                block_index);
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /* Reevaluate ZEROMV after denoising. */
 | 
					        /* Reevaluate ZEROMV after denoising. */
 | 
				
			||||||
        if (best_mode.mbmode.ref_frame == INTRA_FRAME &&
 | 
					        if (best_mode.mbmode.ref_frame == INTRA_FRAME &&
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user