diff options
author | Jerome Jiang <jianj@google.com> | 2017-06-27 13:17:59 -0700 |
---|---|---|
committer | Jerome Jiang <jianj@google.com> | 2017-06-27 16:16:02 -0700 |
commit | a220b931f5b5fccf4ecc758649806dc48bea1b7c (patch) | |
tree | d428d02b422b210d23ea5978bb295f66d705536f /vp9/encoder/vp9_skin_detection.c | |
parent | e187b27438fbbcd07bc5b891ce30a39845d62711 (diff) | |
download | libvpx-a220b931f5b5fccf4ecc758649806dc48bea1b7c.tar libvpx-a220b931f5b5fccf4ecc758649806dc48bea1b7c.tar.gz libvpx-a220b931f5b5fccf4ecc758649806dc48bea1b7c.tar.bz2 libvpx-a220b931f5b5fccf4ecc758649806dc48bea1b7c.zip |
vp9: compute skinmap only once before encoding.
This could save some cycles since skin detection is used in multiple
places in vp9.
1~2% speed up on ARM.
Change-Id: I86b731945f85215bbb0976021cd0f2040ff2687c
Diffstat (limited to 'vp9/encoder/vp9_skin_detection.c')
-rw-r--r-- | vp9/encoder/vp9_skin_detection.c | 96 |
1 files changed, 58 insertions, 38 deletions
diff --git a/vp9/encoder/vp9_skin_detection.c b/vp9/encoder/vp9_skin_detection.c index 175503ed4..cf6b364fe 100644 --- a/vp9/encoder/vp9_skin_detection.c +++ b/vp9/encoder/vp9_skin_detection.c @@ -36,44 +36,31 @@ int vp9_compute_skin_block(const uint8_t *y, const uint8_t *u, const uint8_t *v, } } -#ifdef OUTPUT_YUV_SKINMAP -// For viewing skin map on input source. -void vp9_compute_skin_map(VP9_COMP *const cpi, FILE *yuv_skinmap_file) { - int i, j, mi_row, mi_col, num_bl; +void vp9_compute_skin_map(VP9_COMP *const cpi, BLOCK_SIZE bsize) { + int mi_row, mi_col, num_bl; VP9_COMMON *const cm = &cpi->common; - uint8_t *y; const uint8_t *src_y = cpi->Source->y_buffer; const uint8_t *src_u = cpi->Source->u_buffer; const uint8_t *src_v = cpi->Source->v_buffer; const int src_ystride = cpi->Source->y_stride; const int src_uvstride = cpi->Source->uv_stride; - int y_bsize = 16; // Use 8x8 or 16x16. - int uv_bsize = y_bsize >> 1; - int ypos = y_bsize >> 1; - int uvpos = uv_bsize >> 1; - int shy = (y_bsize == 8) ? 3 : 4; - int shuv = shy - 1; - int fac = y_bsize / 8; + const int y_bsize = 4 << b_width_log2_lookup[bsize]; + const int uv_bsize = y_bsize >> 1; + const int shy = (y_bsize == 8) ? 3 : 4; + const int shuv = shy - 1; + const int fac = y_bsize / 8; // Use center pixel or average of center 2x2 pixels. - int mode_filter = 0; - YV12_BUFFER_CONFIG skinmap; - memset(&skinmap, 0, sizeof(YV12_BUFFER_CONFIG)); - if (vpx_alloc_frame_buffer(&skinmap, cm->width, cm->height, cm->subsampling_x, - cm->subsampling_y, VP9_ENC_BORDER_IN_PIXELS, - cm->byte_alignment)) { - vpx_free_frame_buffer(&skinmap); - return; - } - memset(skinmap.buffer_alloc, 128, skinmap.frame_size); - y = skinmap.y_buffer; + const int mode_filter = 0; + // Loop through blocks and set skin map based on center pixel of block. - // Set y to white for skin block, otherwise set to source with gray scale. // Ignore rightmost/bottom boundary blocks. for (mi_row = 0; mi_row < cm->mi_rows - 1; mi_row += fac) { num_bl = 0; for (mi_col = 0; mi_col < cm->mi_cols - 1; mi_col += fac) { int is_skin = 0; if (mode_filter == 1) { + const int ypos = y_bsize >> 1; + const int uvpos = uv_bsize >> 1; // Use 2x2 average at center. uint8_t ysource = src_y[ypos * src_ystride + ypos]; uint8_t usource = src_u[uvpos * src_uvstride + uvpos]; @@ -92,13 +79,12 @@ void vp9_compute_skin_map(VP9_COMP *const cpi, FILE *yuv_skinmap_file) { vsource = (vsource + vsource2 + vsource3 + vsource4) >> 2; is_skin = vpx_skin_pixel(ysource, usource, vsource, 1); } else { - int block_size = BLOCK_8X8; int consec_zeromv = 0; int bl_index = mi_row * cm->mi_cols + mi_col; int bl_index1 = bl_index + 1; int bl_index2 = bl_index + cm->mi_cols; int bl_index3 = bl_index2 + 1; - if (y_bsize == 8) + if (bsize == BLOCK_8X8) consec_zeromv = cpi->consec_zero_mv[bl_index]; else consec_zeromv = @@ -106,29 +92,63 @@ void vp9_compute_skin_map(VP9_COMP *const cpi, FILE *yuv_skinmap_file) { VPXMIN(cpi->consec_zero_mv[bl_index1], VPXMIN(cpi->consec_zero_mv[bl_index2], cpi->consec_zero_mv[bl_index3]))); - if (y_bsize == 16) block_size = BLOCK_16X16; - is_skin = - vp9_compute_skin_block(src_y, src_u, src_v, src_ystride, - src_uvstride, block_size, consec_zeromv, 0); + is_skin = vp9_compute_skin_block(src_y, src_u, src_v, src_ystride, + src_uvstride, bsize, consec_zeromv, 0); } + cpi->skin_map[mi_row * cm->mi_cols + mi_col] = is_skin; + num_bl++; + src_y += y_bsize; + src_u += uv_bsize; + src_v += uv_bsize; + } + src_y += (src_ystride << shy) - (num_bl << shy); + src_u += (src_uvstride << shuv) - (num_bl << shuv); + src_v += (src_uvstride << shuv) - (num_bl << shuv); + } +} + +#ifdef OUTPUT_YUV_SKINMAP +// For viewing skin map on input source. +void vp9_output_skin_map(VP9_COMP *const cpi, FILE *yuv_skinmap_file) { + int i, j, mi_row, mi_col, num_bl; + VP9_COMMON *const cm = &cpi->common; + uint8_t *y; + const uint8_t *src_y = cpi->Source->y_buffer; + const int src_ystride = cpi->Source->y_stride; + + const int y_bsize = 16; // Use 8x8 or 16x16. + const int shy = (y_bsize == 8) ? 3 : 4; + const int fac = y_bsize / 8; + + YV12_BUFFER_CONFIG skinmap; + memset(&skinmap, 0, sizeof(YV12_BUFFER_CONFIG)); + if (vpx_alloc_frame_buffer(&skinmap, cm->width, cm->height, cm->subsampling_x, + cm->subsampling_y, VP9_ENC_BORDER_IN_PIXELS, + cm->byte_alignment)) { + vpx_free_frame_buffer(&skinmap); + return; + } + memset(skinmap.buffer_alloc, 128, skinmap.frame_size); + y = skinmap.y_buffer; + // Loop through blocks and set skin map based on center pixel of block. + // Set y to white for skin block, otherwise set to source with gray scale. + // Ignore rightmost/bottom boundary blocks. + for (mi_row = 0; mi_row < cm->mi_rows - 1; mi_row += fac) { + num_bl = 0; + for (mi_col = 0; mi_col < cm->mi_cols - 1; mi_col += fac) { + const int block_index = mi_row * cm->mi_cols + mi_col; + const int is_skin = cpi->skin_map[block_index]; for (i = 0; i < y_bsize; i++) { for (j = 0; j < y_bsize; j++) { - if (is_skin) - y[i * src_ystride + j] = 255; - else - y[i * src_ystride + j] = src_y[i * src_ystride + j]; + y[i * src_ystride + j] = is_skin ? 255 : src_y[i * src_ystride + j]; } } num_bl++; y += y_bsize; src_y += y_bsize; - src_u += uv_bsize; - src_v += uv_bsize; } y += (src_ystride << shy) - (num_bl << shy); src_y += (src_ystride << shy) - (num_bl << shy); - src_u += (src_uvstride << shuv) - (num_bl << shuv); - src_v += (src_uvstride << shuv) - (num_bl << shuv); } vpx_write_yuv_frame(yuv_skinmap_file, &skinmap); vpx_free_frame_buffer(&skinmap); |