shithub: libvpx

Download patch

ref: b8794de05bc91a9e27425f5d5564347f06c686af
parent: 12222936041712620ebadd6ce99d1a12f3cac51b
parent: 6db96a7f9ca9e569b87720af1c97a231049b2d11
author: Jingning Han <jingning@google.com>
date: Wed Mar 13 12:18:09 EDT 2019

Merge "Add normalization over frame level Wiener variance"

--- a/vp9/encoder/vp9_encoder.c
+++ b/vp9/encoder/vp9_encoder.c
@@ -4732,7 +4732,7 @@
   DECLARE_ALIGNED(16, int16_t, src_diff[32 * 32]);
   DECLARE_ALIGNED(16, tran_low_t, coeff[32 * 32]);
 
-  int mb_row, mb_col;
+  int mb_row, mb_col, count = 0;
   // Hard coded operating block size
   const int block_size = 16;
   const int coeff_count = block_size * block_size;
@@ -4749,6 +4749,8 @@
 
   memset(zero_pred, 0, sizeof(*zero_pred) * coeff_count);
 
+  cpi->norm_wiener_variance = 0;
+
   for (mb_row = 0; mb_row < cm->mb_rows; ++mb_row) {
     for (mb_col = 0; mb_col < cm->mb_cols; ++mb_col) {
       int idx, hist_count = 0;
@@ -4789,18 +4791,21 @@
 
       // Wiener filter
       for (idx = 1; idx < coeff_count; ++idx) {
-        int sign = coeff[idx] < 0;
         int64_t sqr_coeff = (int64_t)coeff[idx] * coeff[idx];
         coeff[idx] = (int16_t)((sqr_coeff * coeff[idx]) /
                                (sqr_coeff + (int64_t)median_val * median_val));
-        if (sign) coeff[idx] = -coeff[idx];
-
         wiener_variance += (int64_t)coeff[idx] * coeff[idx];
       }
       cpi->mb_wiener_variance[mb_row * cm->mb_cols + mb_col] =
           wiener_variance / coeff_count;
+      cpi->norm_wiener_variance +=
+          cpi->mb_wiener_variance[mb_row * cm->mb_cols + mb_col];
+      ++count;
     }
   }
+
+  if (count) cpi->norm_wiener_variance /= count;
+  cpi->norm_wiener_variance = VPXMAX(1, cpi->norm_wiener_variance);
 }
 
 static void encode_frame_to_data_rate(VP9_COMP *cpi, size_t *size,
--- a/vp9/encoder/vp9_encoder.h
+++ b/vp9/encoder/vp9_encoder.h
@@ -628,6 +628,7 @@
   int ext_refresh_frame_context_pending;
   int ext_refresh_frame_context;
 
+  int64_t norm_wiener_variance;
   int64_t *mb_wiener_variance;
   int *stack_rank_buffer;