]> granicus.if.org Git - libvpx/commitdiff
Add an in-loop deringing experiment
authorJohn Koleszar <jkoleszar@google.com>
Wed, 20 Mar 2013 17:22:20 +0000 (10:22 -0700)
committerJohn Koleszar <jkoleszar@google.com>
Tue, 26 Mar 2013 15:23:24 +0000 (08:23 -0700)
Adds a per-frame, strength adjustable, in loop deringing filter. Uses
the existing vp9_post_proc_down_and_across 5 tap thresholded blur
code, with a brute force search for the threshold.

Results almost strictly positive on the YT HD set, either having no
effect or helping PSNR in the range of 1-3% (overall average 0.8%).
Results more mixed for the CIF set, (-0.5 min, 1.4 max, 0.1 avg).
This has an almost strictly negative impact to SSIM, so examining a
different filter or a more balanced search heuristic is in order.

Other test set results pending.

Change-Id: I5ca6ee8fe292dfa3f2eab7f65332423fa1710b58

configure
vp9/common/vp9_loopfilter.c
vp9/common/vp9_loopfilter.h
vp9/common/vp9_onyxc_int.h
vp9/decoder/vp9_decodframe.c
vp9/decoder/vp9_onyxd_if.c
vp9/encoder/vp9_bitstream.c
vp9/encoder/vp9_onyx_if.c
vp9/encoder/vp9_picklpf.c

index 519707919be910504b7e56873bc979d984c979c1..a791ae5418ead591330366ff35f10bfe775241ca 100755 (executable)
--- a/configure
+++ b/configure
@@ -248,6 +248,7 @@ EXPERIMENT_LIST="
     code_nonzerocount
     useselectrefmv
     modelcoefprob
+    loop_dering
 "
 CONFIG_LIST="
     external_build
index 9ce5a6378ed2d7cc96473ed0c344973199ebdffa..d23f6f596e04744025442dc6d835be1d3cb11251 100644 (file)
@@ -209,7 +209,8 @@ static int sb_mb_lf_skip(const MODE_INFO *const mip0,
 void vp9_loop_filter_frame(VP9_COMMON *cm,
                            MACROBLOCKD *xd,
                            int frame_filter_level,
-                           int y_only) {
+                           int y_only,
+                           int dering) {
   YV12_BUFFER_CONFIG *post = cm->frame_to_show;
   loop_filter_info_n *lfi_n = &cm->lf_info;
   struct loop_filter_info lfi;
@@ -302,6 +303,62 @@ void vp9_loop_filter_frame(VP9_COMMON *cm,
                                  post->uv_stride, &lfi);
             }
           }
+#if CONFIG_LOOP_DERING
+          if (dering) {
+            if (mb_row && mb_row < cm->mb_rows - 1 &&
+                mb_col && mb_col < cm->mb_cols - 1) {
+              vp9_post_proc_down_and_across(y_ptr, y_ptr,
+                                            post->y_stride, post->y_stride,
+                                            16, 16, dering);
+              if (!y_only) {
+                vp9_post_proc_down_and_across(u_ptr, u_ptr,
+                                              post->uv_stride, post->uv_stride,
+                                              8, 8, dering);
+                vp9_post_proc_down_and_across(v_ptr, v_ptr,
+                                              post->uv_stride, post->uv_stride,
+                                              8, 8, dering);
+              }
+            } else {
+              // Adjust the filter so that no out-of-frame data is used.
+              uint8_t *dr_y = y_ptr, *dr_u = u_ptr, *dr_v = v_ptr;
+              int w_adjust = 0;
+              int h_adjust = 0;
+
+              if (mb_col == 0) {
+                dr_y += 2;
+                dr_u += 2;
+                dr_v += 2;
+                w_adjust += 2;
+              }
+              if (mb_col == cm->mb_cols - 1)
+                w_adjust += 2;
+              if (mb_row == 0) {
+                dr_y += 2 * post->y_stride;
+                dr_u += 2 * post->uv_stride;
+                dr_v += 2 * post->uv_stride;
+                h_adjust += 2;
+              }
+              if (mb_row == cm->mb_rows - 1)
+                h_adjust += 2;
+              vp9_post_proc_down_and_across_c(dr_y, dr_y,
+                                              post->y_stride, post->y_stride,
+                                              16 - w_adjust, 16 - h_adjust,
+                                              dering);
+              if (!y_only) {
+                vp9_post_proc_down_and_across_c(dr_u, dr_u,
+                                                post->uv_stride,
+                                                post->uv_stride,
+                                                8 - w_adjust, 8 - h_adjust,
+                                                dering);
+                vp9_post_proc_down_and_across_c(dr_v, dr_v,
+                                                post->uv_stride,
+                                                post->uv_stride,
+                                                8 - w_adjust, 8 - h_adjust,
+                                                dering);
+              }
+            }
+          }
+#endif
         } else {
           // FIXME: Not 8x8 aware
           if (mb_col > 0 &&
index 53ec336a454a4307bb95ac97b03de4afb1811ffd..458afc50bc76676b2d00dbf265c97eff81b3813f 100644 (file)
@@ -83,7 +83,8 @@ void vp9_loop_filter_frame_init(struct VP9Common *cm,
 void vp9_loop_filter_frame(struct VP9Common *cm,
                            struct macroblockd *mbd,
                            int filter_level,
-                           int y_only);
+                           int y_only,
+                           int dering);
 
 void vp9_loop_filter_partial_frame(struct VP9Common *cm,
                                    struct macroblockd *mbd,
index c42e941405d2093620eb3f0ede1fb08249972742..a76f4c557a3edaebe85e9792930f82ca89fd3b4b 100644 (file)
@@ -244,6 +244,7 @@ typedef struct VP9Common {
   int filter_level;
   int last_sharpness_level;
   int sharpness_level;
+  int dering_enabled;
 
   int refresh_entropy_probs;    /* Two state 0 = NO, 1 = YES */
 
index 16ed9a737368cf2d50aca58b501bb2c69d5e1aaf..cb6421f6396ef287e54b6dbdfa11ad0f3d5073a9 100644 (file)
@@ -1508,6 +1508,12 @@ int vp9_decode_frame(VP9D_COMP *pbi, const unsigned char **p_data_end) {
   pc->filter_type = (LOOPFILTERTYPE) vp9_read_bit(&header_bc);
   pc->filter_level = vp9_read_literal(&header_bc, 6);
   pc->sharpness_level = vp9_read_literal(&header_bc, 3);
+#if CONFIG_LOOP_DERING
+  if (vp9_read_bit(&header_bc))
+    pc->dering_enabled = 1 + vp9_read_literal(&header_bc, 4);
+  else
+    pc->dering_enabled = 0;
+#endif
 
   /* Read in loop filter deltas applied at the MB level based on mode or ref frame. */
   xd->mode_ref_lf_delta_update = 0;
index a243f41fd146f2b3ce47e8b22c8bf03b36dfc540..bcb5897e66c1823a4e0bd081edb1b44874bafeb3 100644 (file)
@@ -356,7 +356,8 @@ int vp9_receive_compressed_data(VP9D_PTR ptr, unsigned long size,
 
     if (cm->filter_level) {
       /* Apply the loop filter if appropriate. */
-      vp9_loop_filter_frame(cm, &pbi->mb, cm->filter_level, 0);
+      vp9_loop_filter_frame(cm, &pbi->mb, cm->filter_level, 0,
+                            cm->dering_enabled);
     }
     vp8_yv12_extend_frame_borders(cm->frame_to_show);
   }
index 25df76736f2a07cd8d6119ef01ebc115155ca195..c0ae5ba362d62ea282a173cc7502d49e24433e7e 100644 (file)
@@ -2515,6 +2515,14 @@ void vp9_pack_bitstream(VP9_COMP *cpi, unsigned char *dest,
   vp9_write_bit(&header_bc, pc->filter_type);
   vp9_write_literal(&header_bc, pc->filter_level, 6);
   vp9_write_literal(&header_bc, pc->sharpness_level, 3);
+#if CONFIG_LOOP_DERING
+  if (pc->dering_enabled) {
+    vp9_write_bit(&header_bc, 1);
+    vp9_write_literal(&header_bc, pc->dering_enabled - 1, 4);
+  } else {
+    vp9_write_bit(&header_bc, 0);
+  }
+#endif
 
   // Write out loop filter deltas applied at the MB level based on mode or ref frame (if they are enabled).
   vp9_write_bit(&header_bc, (xd->mode_ref_lf_delta_enabled) ? 1 : 0);
index 0fb5c56d45bd477ccf0cbf03f5ea9ccf1888b026..490a63954ef02641b8894fa5776da537a3bcf473 100644 (file)
@@ -2526,7 +2526,8 @@ static void loopfilter_frame(VP9_COMP *cpi, VP9_COMMON *cm) {
 
   if (cm->filter_level > 0) {
     vp9_set_alt_lf_level(cpi, cm->filter_level);
-    vp9_loop_filter_frame(cm, &cpi->mb.e_mbd, cm->filter_level, 0);
+    vp9_loop_filter_frame(cm, &cpi->mb.e_mbd, cm->filter_level, 0,
+                          cm->dering_enabled);
   }
 
   vp8_yv12_extend_frame_borders(cm->frame_to_show);
index d80ea02c13a8daf8ff66e9ac6bdd6db118a36b24..645d66b258e0453a374cc0b57876b3035654429b 100644 (file)
@@ -9,6 +9,7 @@
  */
 
 #include <assert.h>
+#include <limits.h>
 #include "vp9/common/vp9_onyxc_int.h"
 #include "vp9/encoder/vp9_onyx_int.h"
 #include "vp9/encoder/vp9_picklpf.h"
@@ -267,7 +268,7 @@ void vp9_pick_filter_level(YV12_BUFFER_CONFIG *sd, VP9_COMP *cpi) {
 
   // Get baseline error score
   vp9_set_alt_lf_level(cpi, filt_mid);
-  vp9_loop_filter_frame(cm, &cpi->mb.e_mbd, filt_mid, 1);
+  vp9_loop_filter_frame(cm, &cpi->mb.e_mbd, filt_mid, 1, 0);
 
   best_err = vp9_calc_ss_err(sd, cm->frame_to_show);
   filt_best = filt_mid;
@@ -292,7 +293,7 @@ void vp9_pick_filter_level(YV12_BUFFER_CONFIG *sd, VP9_COMP *cpi) {
     if ((filt_direction <= 0) && (filt_low != filt_mid)) {
       // Get Low filter error score
       vp9_set_alt_lf_level(cpi, filt_low);
-      vp9_loop_filter_frame(cm, &cpi->mb.e_mbd, filt_low, 1);
+      vp9_loop_filter_frame(cm, &cpi->mb.e_mbd, filt_low, 1, 0);
 
       filt_err = vp9_calc_ss_err(sd, cm->frame_to_show);
 
@@ -312,7 +313,7 @@ void vp9_pick_filter_level(YV12_BUFFER_CONFIG *sd, VP9_COMP *cpi) {
     // Now look at filt_high
     if ((filt_direction >= 0) && (filt_high != filt_mid)) {
       vp9_set_alt_lf_level(cpi, filt_high);
-      vp9_loop_filter_frame(cm, &cpi->mb.e_mbd, filt_high, 1);
+      vp9_loop_filter_frame(cm, &cpi->mb.e_mbd, filt_high, 1, 0);
 
       filt_err = vp9_calc_ss_err(sd, cm->frame_to_show);
 
@@ -337,4 +338,30 @@ void vp9_pick_filter_level(YV12_BUFFER_CONFIG *sd, VP9_COMP *cpi) {
   }
 
   cm->filter_level = filt_best;
+
+#if CONFIG_LOOP_DERING
+  /* Decide whether to turn on deringing filter */
+  {  // NOLINT
+    int best_dering = 0;
+    int this_dering;
+    int last_err_diff = INT_MAX;
+
+    for (this_dering = 1; this_dering <= 16; this_dering++) {
+      vp9_set_alt_lf_level(cpi, filt_best);
+      vp9_loop_filter_frame(cm, &cpi->mb.e_mbd, filt_high, 1, this_dering);
+      filt_err = vp9_calc_ss_err(sd, cm->frame_to_show);
+      vp8_yv12_copy_y(&cpi->last_frame_uf, cm->frame_to_show);
+      if (filt_err < best_err) {
+        best_err = filt_err;
+        best_dering = this_dering;
+        last_err_diff = INT_MAX;
+      } else {
+        if (filt_err - best_err > last_err_diff)
+          break;
+        last_err_diff = filt_err - best_err;
+      }
+    }
+    cm->dering_enabled = best_dering;
+  }
+#endif
 }