shithub: libvpx

Download patch

ref: bf41a982b4e36c92cb8f8932e5231151f7506aa3
parent: 038522e4a0dbc78a5956cc65479895fcde8e9014
parent: a36017e007e0822366ebb1bb530b5bf9189e2f3c
author: Jerome Jiang <[email protected]>
date: Mon Jun 19 12:42:10 EDT 2017

Merge "Enable 8x8 skin detection for vp8."

--- a/vp8/common/vp8_skin_detection.c
+++ b/vp8/common/vp8_skin_detection.c
@@ -14,8 +14,20 @@
 #include "vpx_mem/vpx_mem.h"
 #include "vpx_util/vpx_write_yuv_frame.h"
 
+static int avg_2x2(const uint8_t *s, int p) {
+  int i, j;
+  int sum = 0;
+  for (i = 0; i < 2; ++i, s += p) {
+    for (j = 0; j < 2; ++j) {
+      sum += s[j];
+    }
+  }
+  return (sum + 2) >> 2;
+}
+
 int vp8_compute_skin_block(const uint8_t *y, const uint8_t *u, const uint8_t *v,
-                           int stride, int strideuv, int consec_zeromv,
+                           int stride, int strideuv,
+                           SKIN_DETECTION_BLOCK_SIZE bsize, int consec_zeromv,
                            int curr_motion_magn) {
   // No skin if block has been zero/small motion for long consecutive time.
   if (consec_zeromv > 60 && curr_motion_magn == 0) {
@@ -22,18 +34,35 @@
     return 0;
   } else {
     int motion = 1;
-    // Take the average of center 2x2 pixels.
-    const int ysource = (y[7 * stride + 7] + y[7 * stride + 8] +
-                         y[8 * stride + 7] + y[8 * stride + 8]) >>
-                        2;
-    const int usource = (u[3 * strideuv + 3] + u[3 * strideuv + 4] +
-                         u[4 * strideuv + 3] + u[4 * strideuv + 4]) >>
-                        2;
-    const int vsource = (v[3 * strideuv + 3] + v[3 * strideuv + 4] +
-                         v[4 * strideuv + 3] + v[4 * strideuv + 4]) >>
-                        2;
     if (consec_zeromv > 25 && curr_motion_magn == 0) motion = 0;
-    return vpx_skin_pixel(ysource, usource, vsource, motion);
+    if (bsize == SKIN_16X16) {
+      // Take the average of center 2x2 pixels.
+      const int ysource = avg_2x2(y + 7 * stride + 7, stride);
+      const int usource = avg_2x2(u + 3 * strideuv + 3, strideuv);
+      const int vsource = avg_2x2(v + 3 * strideuv + 3, strideuv);
+      return vpx_skin_pixel(ysource, usource, vsource, motion);
+    } else {
+      int num_skin = 0;
+      int i, j;
+      for (i = 0; i < 2; i++) {
+        for (j = 0; j < 2; j++) {
+          // Take the average of center 2x2 pixels.
+          const int ysource = avg_2x2(y + 3 * stride + 3, stride);
+          const int usource = avg_2x2(u + strideuv + 1, strideuv);
+          const int vsource = avg_2x2(v + strideuv + 1, strideuv);
+          num_skin += vpx_skin_pixel(ysource, usource, vsource, motion);
+          if (num_skin >= 2) return 1;
+          y += 8;
+          u += 4;
+          v += 4;
+        }
+        y += (stride << 3) - 16;
+        u += (strideuv << 2) - 8;
+        v += (strideuv << 2) - 8;
+      }
+
+      return 0;
+    }
   }
 }
 
@@ -74,8 +103,9 @@
                              VPXMIN(cpi->consec_zero_last[bl_index1],
                                     VPXMIN(cpi->consec_zero_last[bl_index2],
                                            cpi->consec_zero_last[bl_index3])));
-      is_skin = vp8_compute_skin_block(src_y, src_u, src_v, src_ystride,
-                                       src_uvstride, consec_zeromv, 0);
+      is_skin =
+          vp8_compute_skin_block(src_y, src_u, src_v, src_ystride, src_uvstride,
+                                 SKIN_8X8, consec_zeromv, 0);
       for (i = 0; i < 16; i++) {
         for (j = 0; j < 16; j++) {
           if (is_skin)
--- a/vp8/common/vp8_skin_detection.h
+++ b/vp8/common/vp8_skin_detection.h
@@ -22,8 +22,17 @@
 
 struct VP8_COMP;
 
+typedef enum {
+  // Skin detection based on 8x8 block. If two of them are identified as skin,
+  // the macroblock is marked as skin.
+  SKIN_8X8,
+  // Skin detection based on 16x16 block.
+  SKIN_16X16
+} SKIN_DETECTION_BLOCK_SIZE;
+
 int vp8_compute_skin_block(const uint8_t *y, const uint8_t *u, const uint8_t *v,
-                           int stride, int strideuv, int consec_zeromv,
+                           int stride, int strideuv,
+                           SKIN_DETECTION_BLOCK_SIZE bsize, int consec_zeromv,
                            int curr_motion_magn);
 
 #ifdef OUTPUT_YUV_SKINMAP
--- a/vp8/encoder/pickinter.c
+++ b/vp8/encoder/pickinter.c
@@ -693,7 +693,7 @@
     int block_index = mb_row * cpi->common.mb_cols + mb_col;
     x->is_skin = vp8_compute_skin_block(
         x->src.y_buffer, x->src.u_buffer, x->src.v_buffer, x->src.y_stride,
-        x->src.uv_stride, cpi->consec_zero_last[block_index], 0);
+        x->src.uv_stride, SKIN_16X16, cpi->consec_zero_last[block_index], 0);
   }
 #if CONFIG_TEMPORAL_DENOISING
   if (cpi->oxcf.noise_sensitivity) {