shithub: libvpx

Download patch

ref: 905b8ec27f0e9cff4042d69d9b59764ebba159e1
parent: 1c666465afc6f9cf470d54bf595a05f9101332fa
parent: 56d95b77f558c57ca3b04f727d51b2c70cce1503
author: Jerome Jiang <jianj@google.com>
date: Thu Jul 27 16:24:08 EDT 2017

Merge "vp8: Remove isolated skin & non skin blocks."

--- a/vp8/encoder/onyx_if.c
+++ b/vp8/encoder/onyx_if.c
@@ -628,16 +628,15 @@
 
   const SKIN_DETECTION_BLOCK_SIZE bsize =
       (cm->Width * cm->Height <= 352 * 288) ? SKIN_8X8 : SKIN_16X16;
-  int offset = 0;
+
   for (mb_row = 0; mb_row < cm->mb_rows; mb_row++) {
     num_bl = 0;
     for (mb_col = 0; mb_col < cm->mb_cols; mb_col++) {
       const int bl_index = mb_row * cm->mb_cols + mb_col;
-      cpi->skin_map[offset] =
+      cpi->skin_map[bl_index] =
           vp8_compute_skin_block(src_y, src_u, src_v, src_ystride, src_uvstride,
                                  bsize, cpi->consec_zero_last[bl_index], 0);
       num_bl++;
-      offset++;
       src_y += 16;
       src_u += 8;
       src_v += 8;
@@ -645,6 +644,29 @@
     src_y += (src_ystride << 4) - (num_bl << 4);
     src_u += (src_uvstride << 3) - (num_bl << 3);
     src_v += (src_uvstride << 3) - (num_bl << 3);
+  }
+
+  // Remove isolated skin blocks (none of its neighbors are skin) and isolated
+  // non-skin blocks (all of its neighbors are skin). Skip the boundary.
+  for (mb_row = 1; mb_row < cm->mb_rows - 1; mb_row++) {
+    for (mb_col = 1; mb_col < cm->mb_cols - 1; mb_col++) {
+      const int bl_index = mb_row * cm->mb_cols + mb_col;
+      int num_neighbor = 0;
+      int mi, mj;
+      int non_skin_threshold = 8;
+
+      for (mi = -1; mi <= 1; mi += 1) {
+        for (mj = -1; mj <= 1; mj += 1) {
+          int bl_neighbor_index = (mb_row + mi) * cm->mb_cols + mb_col + mj;
+          if (cpi->skin_map[bl_neighbor_index]) num_neighbor++;
+        }
+      }
+
+      if (cpi->skin_map[bl_index] && num_neighbor < 2)
+        cpi->skin_map[bl_index] = 0;
+      if (!cpi->skin_map[bl_index] && num_neighbor == non_skin_threshold)
+        cpi->skin_map[bl_index] = 1;
+    }
   }
 }